diff options
author | Constantin Kaplinsky <const@tightvnc.com> | 2007-07-24 12:10:16 +0000 |
---|---|---|
committer | Constantin Kaplinsky <const@tightvnc.com> | 2007-07-24 12:10:16 +0000 |
commit | 71a32f0dc858823782eee0fcc3dd52b55c1a8a27 (patch) | |
tree | 7b621849c00a07f00c0b4454dfbc8050e5c17373 /common/rfb/JpegCompressor.h | |
parent | 344c3fe719400587a72534cd2e531b31f9dd856a (diff) | |
download | tigervnc-71a32f0dc858823782eee0fcc3dd52b55c1a8a27.tar.gz tigervnc-71a32f0dc858823782eee0fcc3dd52b55c1a8a27.zip |
Added JpegCompressor abstract class and two implementations -- one cross-platform and another IRIX-specific.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2320 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'common/rfb/JpegCompressor.h')
-rw-r--r-- | common/rfb/JpegCompressor.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/common/rfb/JpegCompressor.h b/common/rfb/JpegCompressor.h new file mode 100644 index 00000000..93fdc7bf --- /dev/null +++ b/common/rfb/JpegCompressor.h @@ -0,0 +1,82 @@ +#ifndef __JPEGCOMPRESSOR_H__ +#define __JPEGCOMPRESSOR_H__ + +#include <stdio.h> +#include <sys/types.h> +extern "C" { +#include <jpeg/jpeglib.h> +} + +#include <rdr/types.h> +#include <rfb/PixelFormat.h> + +namespace rfb { + + // + // An abstract interface for performing JPEG compression. + // + + class JpegCompressor + { + public: + virtual ~JpegCompressor() {} + + // Set JPEG quality level (0..100) + virtual void setQuality(int level) = 0; + + // Actually compress an image. + virtual void compress(const rdr::U32 *buf, const PixelFormat *fmt, + int w, int h, int stride) = 0; + + // Access results of the compression. + virtual size_t getDataLength() = 0; + virtual const char *getDataPtr() = 0; + }; + + // + // A C++ class for performing JPEG compression via the + // Independent JPEG Group's software (free JPEG library). + // + + class StandardJpegCompressor : public JpegCompressor + { + public: + StandardJpegCompressor(); + virtual ~StandardJpegCompressor(); + + // Set JPEG quality level (0..100) + virtual void setQuality(int level); + + // Actually compress the image. + virtual void compress(const rdr::U32 *buf, const PixelFormat *fmt, + int w, int h, int stride); + + // Access results of the compression. + virtual size_t getDataLength() { return m_cdata_ready; } + virtual const char *getDataPtr() { return (const char *)m_cdata; } + + public: + // Our implementation of JPEG destination manager. These three + // functions should never be called directly. They are made public + // because they should be accessible from C-compatible functions + // called by the JPEG library. + void initDestination(); + bool emptyOutputBuffer(); + void termDestination(); + + protected: + static const int ALLOC_CHUNK_SIZE; + static const int DEFAULT_QUALITY; + + struct jpeg_compress_struct m_cinfo; + struct jpeg_error_mgr m_jerr; + + unsigned char *m_cdata; + size_t m_cdata_allocated; + size_t m_cdata_ready; + }; + +} + +#endif // __JPEGCOMPRESSOR_H__ + |