]> Creatis software - clitk.git/blobdiff - utilities/CxImage/ximajpg.h
cosmetic
[clitk.git] / utilities / CxImage / ximajpg.h
index 899c6bc123beb2fd3e268809850736faa8b9b7d4..de7835a6d84476a889fb0561d95f8930d71787f5 100644 (file)
-/*\r
- * File:       ximajpg.h\r
- * Purpose:    JPG Image Class Loader and Writer\r
- */\r
-/* ==========================================================\r
- * CxImageJPG (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it\r
- * For conditions of distribution and use, see copyright notice in ximage.h\r
- *\r
- * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes\r
- *\r
- * Special thanks to Chris Shearer Cooper for CxFileJpg tips & code\r
- *\r
- * EXIF support based on jhead-1.8 by Matthias Wandel <mwandel(at)rim(dot)net>\r
- *\r
- * original CImageJPG  and CImageIterator implementation are:\r
- * Copyright:  (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx>\r
- *\r
- * This software is based in part on the work of the Independent JPEG Group.\r
- * Copyright (C) 1991-1998, Thomas G. Lane.\r
- * ==========================================================\r
- */\r
-#if !defined(__ximaJPEG_h)\r
-#define __ximaJPEG_h\r
-\r
-#include "ximage.h"\r
-\r
-#if CXIMAGE_SUPPORT_JPG\r
-\r
-#define CXIMAGEJPG_SUPPORT_EXIF 1\r
-\r
-extern "C" {\r
- #include "../jpeg/jpeglib.h"\r
- #include "../jpeg/jerror.h"\r
-}\r
-\r
-class DLL_EXP CxImageJPG: public CxImage\r
-{\r
-public:\r
-       CxImageJPG();\r
-       ~CxImageJPG();\r
-\r
-//     bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_JPG);}\r
-//     bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_JPG);}\r
-       bool Decode(CxFile * hFile);\r
-       bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }\r
-\r
-#if CXIMAGE_SUPPORT_ENCODE\r
-       bool Encode(CxFile * hFile);\r
-       bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }\r
-#endif // CXIMAGE_SUPPORT_ENCODE\r
-\r
-/*\r
- * EXIF support based on jhead-1.8 by Matthias Wandel <mwandel(at)rim(dot)net>\r
- */\r
-\r
-#if CXIMAGEJPG_SUPPORT_EXIF\r
-\r
-#define MAX_COMMENT 1000\r
-#define MAX_SECTIONS 20\r
-\r
-typedef struct tag_ExifInfo {\r
-       char  Version      [5];\r
-    char  CameraMake   [32];\r
-    char  CameraModel  [40];\r
-    char  DateTime     [20];\r
-    int   Height, Width;\r
-    int   Orientation;\r
-    int   IsColor;\r
-    int   Process;\r
-    int   FlashUsed;\r
-    float FocalLength;\r
-    float ExposureTime;\r
-    float ApertureFNumber;\r
-    float Distance;\r
-    float CCDWidth;\r
-    float ExposureBias;\r
-    int   Whitebalance;\r
-    int   MeteringMode;\r
-    int   ExposureProgram;\r
-    int   ISOequivalent;\r
-    int   CompressionLevel;\r
-       float FocalplaneXRes;\r
-       float FocalplaneYRes;\r
-       float FocalplaneUnits;\r
-       float Xresolution;\r
-       float Yresolution;\r
-       float ResolutionUnit;\r
-       float Brightness;\r
-    char  Comments[MAX_COMMENT];\r
-\r
-    unsigned char * ThumbnailPointer;  /* Pointer at the thumbnail */\r
-    unsigned ThumbnailSize;     /* Size of thumbnail. */\r
-\r
-       bool  IsExif;\r
-} EXIFINFO;\r
-\r
-//--------------------------------------------------------------------------\r
-// JPEG markers consist of one or more 0xFF bytes, followed by a marker\r
-// code byte (which is not an FF).  Here are the marker codes of interest\r
-// in this program.  (See jdmarker.c for a more complete list.)\r
-//--------------------------------------------------------------------------\r
-\r
-#define M_SOF0  0xC0            // Start Of Frame N\r
-#define M_SOF1  0xC1            // N indicates which compression process\r
-#define M_SOF2  0xC2            // Only SOF0-SOF2 are now in common use\r
-#define M_SOF3  0xC3\r
-#define M_SOF5  0xC5            // NB: codes C4 and CC are NOT SOF markers\r
-#define M_SOF6  0xC6\r
-#define M_SOF7  0xC7\r
-#define M_SOF9  0xC9\r
-#define M_SOF10 0xCA\r
-#define M_SOF11 0xCB\r
-#define M_SOF13 0xCD\r
-#define M_SOF14 0xCE\r
-#define M_SOF15 0xCF\r
-#define M_SOI   0xD8            // Start Of Image (beginning of datastream)\r
-#define M_EOI   0xD9            // End Of Image (end of datastream)\r
-#define M_SOS   0xDA            // Start Of Scan (begins compressed data)\r
-#define M_JFIF  0xE0            // Jfif marker\r
-#define M_EXIF  0xE1            // Exif marker\r
-#define M_COM   0xFE            // COMment \r
-\r
-#define PSEUDO_IMAGE_MARKER 0x123; // Extra value.\r
-\r
-#define EXIF_READ_EXIF  0x01\r
-#define EXIF_READ_IMAGE 0x02\r
-#define EXIF_READ_ALL   0x03\r
-\r
-class DLL_EXP CxExifInfo\r
-{\r
-\r
-typedef struct tag_Section_t{\r
-    BYTE*    Data;\r
-    int      Type;\r
-    unsigned Size;\r
-} Section_t;\r
-\r
-public:\r
-       EXIFINFO* m_exifinfo;\r
-       char m_szLastError[256];\r
-       CxExifInfo(EXIFINFO* info = NULL);\r
-       ~CxExifInfo();\r
-       bool DecodeExif(CxFile * hFile, int nReadMode = EXIF_READ_EXIF);\r
-       bool EncodeExif(CxFile * hFile);\r
-       void DiscardAllButExif();\r
-protected:\r
-       bool process_EXIF(unsigned char * CharBuf, unsigned int length);\r
-       void process_COM (const BYTE * Data, int length);\r
-       void process_SOFn (const BYTE * Data, int marker);\r
-       int Get16u(void * Short);\r
-       int Get16m(void * Short);\r
-       long Get32s(void * Long);\r
-       unsigned long Get32u(void * Long);\r
-       double ConvertAnyFormat(void * ValuePtr, int Format);\r
-       void* FindSection(int SectionType);\r
-       bool ProcessExifDir(unsigned char * DirStart, unsigned char * OffsetBase, unsigned ExifLength,\r
-                           EXIFINFO * const pInfo, unsigned char ** const LastExifRefdP, int NestingLevel=0);\r
-       int ExifImageWidth;\r
-       int MotorolaOrder;\r
-       Section_t Sections[MAX_SECTIONS];\r
-       int SectionsRead;\r
-       bool freeinfo;\r
-};\r
-\r
-       CxExifInfo* m_exif;\r
-       EXIFINFO m_exifinfo;\r
-       bool DecodeExif(CxFile * hFile);\r
-       bool DecodeExif(FILE * hFile) { CxIOFile file(hFile); return DecodeExif(&file); }\r
-\r
-#endif //CXIMAGEJPG_SUPPORT_EXIF\r
-\r
-////////////////////////////////////////////////////////////////////////////////////////\r
-//////////////////////        C x F i l e J p g         ////////////////////////////////\r
-////////////////////////////////////////////////////////////////////////////////////////\r
-\r
-// thanks to Chris Shearer Cooper <cscooper(at)frii(dot)com>\r
-class CxFileJpg : public jpeg_destination_mgr, public jpeg_source_mgr\r
-       {\r
-public:\r
-       enum { eBufSize = 4096 };\r
-\r
-       CxFileJpg(CxFile* pFile)\r
-       {\r
-        m_pFile = pFile;\r
-\r
-               init_destination = InitDestination;\r
-               empty_output_buffer = EmptyOutputBuffer;\r
-               term_destination = TermDestination;\r
-\r
-               init_source = InitSource;\r
-               fill_input_buffer = FillInputBuffer;\r
-               skip_input_data = SkipInputData;\r
-               resync_to_restart = jpeg_resync_to_restart; // use default method\r
-               term_source = TermSource;\r
-               next_input_byte = NULL; //* => next byte to read from buffer \r
-               bytes_in_buffer = 0;    //* # of bytes remaining in buffer \r
-\r
-               m_pBuffer = new unsigned char[eBufSize];\r
-       }\r
-       ~CxFileJpg()\r
-       {\r
-               delete [] m_pBuffer;\r
-       }\r
-\r
-       static void InitDestination(j_compress_ptr cinfo)\r
-       {\r
-               CxFileJpg* pDest = (CxFileJpg*)cinfo->dest;\r
-               pDest->next_output_byte = pDest->m_pBuffer;\r
-               pDest->free_in_buffer = eBufSize;\r
-       }\r
-\r
-       static boolean EmptyOutputBuffer(j_compress_ptr cinfo)\r
-       {\r
-               CxFileJpg* pDest = (CxFileJpg*)cinfo->dest;\r
-               if (pDest->m_pFile->Write(pDest->m_pBuffer,1,eBufSize)!=(size_t)eBufSize)\r
-                       ERREXIT(cinfo, JERR_FILE_WRITE);\r
-               pDest->next_output_byte = pDest->m_pBuffer;\r
-               pDest->free_in_buffer = eBufSize;\r
-               return TRUE;\r
-       }\r
-\r
-       static void TermDestination(j_compress_ptr cinfo)\r
-       {\r
-               CxFileJpg* pDest = (CxFileJpg*)cinfo->dest;\r
-               size_t datacount = eBufSize - pDest->free_in_buffer;\r
-               /* Write any data remaining in the buffer */\r
-               if (datacount > 0) {\r
-                       if (!pDest->m_pFile->Write(pDest->m_pBuffer,1,datacount))\r
-                               ERREXIT(cinfo, JERR_FILE_WRITE);\r
-               }\r
-               pDest->m_pFile->Flush();\r
-               /* Make sure we wrote the output file OK */\r
-               if (pDest->m_pFile->Error()) ERREXIT(cinfo, JERR_FILE_WRITE);\r
-               return;\r
-       }\r
-\r
-       static void InitSource(j_decompress_ptr cinfo)\r
-       {\r
-               CxFileJpg* pSource = (CxFileJpg*)cinfo->src;\r
-               pSource->m_bStartOfFile = TRUE;\r
-       }\r
-\r
-       static boolean FillInputBuffer(j_decompress_ptr cinfo)\r
-       {\r
-               size_t nbytes;\r
-               CxFileJpg* pSource = (CxFileJpg*)cinfo->src;\r
-               nbytes = pSource->m_pFile->Read(pSource->m_pBuffer,1,eBufSize);\r
-               if (nbytes <= 0){\r
-                       if (pSource->m_bStartOfFile)    //* Treat empty input file as fatal error \r
-                               ERREXIT(cinfo, JERR_INPUT_EMPTY);\r
-                       WARNMS(cinfo, JWRN_JPEG_EOF);\r
-                       // Insert a fake EOI marker \r
-                       pSource->m_pBuffer[0] = (JOCTET) 0xFF;\r
-                       pSource->m_pBuffer[1] = (JOCTET) JPEG_EOI;\r
-                       nbytes = 2;\r
-               }\r
-               pSource->next_input_byte = pSource->m_pBuffer;\r
-               pSource->bytes_in_buffer = nbytes;\r
-               pSource->m_bStartOfFile = FALSE;\r
-               return TRUE;\r
-       }\r
-\r
-       static void SkipInputData(j_decompress_ptr cinfo, long num_bytes)\r
-       {\r
-               CxFileJpg* pSource = (CxFileJpg*)cinfo->src;\r
-               if (num_bytes > 0){\r
-                       while (num_bytes > (long)pSource->bytes_in_buffer){\r
-                               num_bytes -= (long)pSource->bytes_in_buffer;\r
-                               FillInputBuffer(cinfo);\r
-                               // note we assume that fill_input_buffer will never return FALSE,\r
-                               // so suspension need not be handled.\r
-                       }\r
-                       pSource->next_input_byte += (size_t) num_bytes;\r
-                       pSource->bytes_in_buffer -= (size_t) num_bytes;\r
-               }\r
-       }\r
-\r
-       static void TermSource(j_decompress_ptr /*cinfo*/)\r
-       {\r
-               return;\r
-       }\r
-protected:\r
-    CxFile  *m_pFile;\r
-       unsigned char *m_pBuffer;\r
-       bool m_bStartOfFile;\r
-};\r
-\r
-public:\r
-       enum CODEC_OPTION\r
-       {\r
-               ENCODE_BASELINE = 0x1,\r
-               ENCODE_ARITHMETIC = 0x2,\r
-               ENCODE_GRAYSCALE = 0x4,\r
-               ENCODE_OPTIMIZE = 0x8,\r
-               ENCODE_PROGRESSIVE = 0x10,\r
-               ENCODE_LOSSLESS = 0x20,\r
-               ENCODE_SMOOTHING = 0x40,\r
-               DECODE_GRAYSCALE = 0x80,\r
-               DECODE_QUANTIZE = 0x100,\r
-               DECODE_DITHER = 0x200,\r
-               DECODE_ONEPASS = 0x400,\r
-               DECODE_NOSMOOTH = 0x800,\r
-               ENCODE_SUBSAMPLE_422 = 0x1000,\r
-               ENCODE_SUBSAMPLE_444 = 0x2000\r
-       }; \r
-\r
-       int m_nPredictor;\r
-       int m_nPointTransform;\r
-       int m_nSmoothing;\r
-       int m_nQuantize;\r
-       J_DITHER_MODE m_nDither;\r
-\r
-};\r
-\r
-#endif\r
-\r
-#endif\r
+/*
+ * File:       ximajpg.h
+ * Purpose:    JPG Image Class Loader and Writer
+ */
+/* ==========================================================
+ * CxImageJPG (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it
+ * For conditions of distribution and use, see copyright notice in ximage.h
+ *
+ * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes
+ *
+ * Special thanks to Chris Shearer Cooper for CxFileJpg tips & code
+ *
+ * EXIF support based on jhead-1.8 by Matthias Wandel <mwandel(at)rim(dot)net>
+ *
+ * original CImageJPG  and CImageIterator implementation are:
+ * Copyright:  (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx>
+ *
+ * This software is based in part on the work of the Independent JPEG Group.
+ * Copyright (C) 1991-1998, Thomas G. Lane.
+ * ==========================================================
+ */
+#if !defined(__ximaJPEG_h)
+#define __ximaJPEG_h
+
+#include "ximage.h"
+
+#if CXIMAGE_SUPPORT_JPG
+
+#define CXIMAGEJPG_SUPPORT_EXIF 1
+
+extern "C" {
+ #include "../jpeg/jpeglib.h"
+ #include "../jpeg/jerror.h"
+}
+
+class DLL_EXP CxImageJPG: public CxImage
+{
+public:
+       CxImageJPG();
+       ~CxImageJPG();
+
+//     bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_JPG);}
+//     bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_JPG);}
+       bool Decode(CxFile * hFile);
+       bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
+
+#if CXIMAGE_SUPPORT_ENCODE
+       bool Encode(CxFile * hFile);
+       bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
+#endif // CXIMAGE_SUPPORT_ENCODE
+
+/*
+ * EXIF support based on jhead-1.8 by Matthias Wandel <mwandel(at)rim(dot)net>
+ */
+
+#if CXIMAGEJPG_SUPPORT_EXIF
+
+#define MAX_COMMENT 1000
+#define MAX_SECTIONS 20
+
+typedef struct tag_ExifInfo {
+       char  Version      [5];
+    char  CameraMake   [32];
+    char  CameraModel  [40];
+    char  DateTime     [20];
+    int   Height, Width;
+    int   Orientation;
+    int   IsColor;
+    int   Process;
+    int   FlashUsed;
+    float FocalLength;
+    float ExposureTime;
+    float ApertureFNumber;
+    float Distance;
+    float CCDWidth;
+    float ExposureBias;
+    int   Whitebalance;
+    int   MeteringMode;
+    int   ExposureProgram;
+    int   ISOequivalent;
+    int   CompressionLevel;
+       float FocalplaneXRes;
+       float FocalplaneYRes;
+       float FocalplaneUnits;
+       float Xresolution;
+       float Yresolution;
+       float ResolutionUnit;
+       float Brightness;
+    char  Comments[MAX_COMMENT];
+
+    unsigned char * ThumbnailPointer;  /* Pointer at the thumbnail */
+    unsigned ThumbnailSize;     /* Size of thumbnail. */
+
+       bool  IsExif;
+} EXIFINFO;
+
+//--------------------------------------------------------------------------
+// JPEG markers consist of one or more 0xFF bytes, followed by a marker
+// code byte (which is not an FF).  Here are the marker codes of interest
+// in this program.  (See jdmarker.c for a more complete list.)
+//--------------------------------------------------------------------------
+
+#define M_SOF0  0xC0            // Start Of Frame N
+#define M_SOF1  0xC1            // N indicates which compression process
+#define M_SOF2  0xC2            // Only SOF0-SOF2 are now in common use
+#define M_SOF3  0xC3
+#define M_SOF5  0xC5            // NB: codes C4 and CC are NOT SOF markers
+#define M_SOF6  0xC6
+#define M_SOF7  0xC7
+#define M_SOF9  0xC9
+#define M_SOF10 0xCA
+#define M_SOF11 0xCB
+#define M_SOF13 0xCD
+#define M_SOF14 0xCE
+#define M_SOF15 0xCF
+#define M_SOI   0xD8            // Start Of Image (beginning of datastream)
+#define M_EOI   0xD9            // End Of Image (end of datastream)
+#define M_SOS   0xDA            // Start Of Scan (begins compressed data)
+#define M_JFIF  0xE0            // Jfif marker
+#define M_EXIF  0xE1            // Exif marker
+#define M_COM   0xFE            // COMment 
+
+#define PSEUDO_IMAGE_MARKER 0x123; // Extra value.
+
+#define EXIF_READ_EXIF  0x01
+#define EXIF_READ_IMAGE 0x02
+#define EXIF_READ_ALL   0x03
+
+class DLL_EXP CxExifInfo
+{
+
+typedef struct tag_Section_t{
+    BYTE*    Data;
+    int      Type;
+    unsigned Size;
+} Section_t;
+
+public:
+       EXIFINFO* m_exifinfo;
+       char m_szLastError[256];
+       CxExifInfo(EXIFINFO* info = NULL);
+       ~CxExifInfo();
+       bool DecodeExif(CxFile * hFile, int nReadMode = EXIF_READ_EXIF);
+       bool EncodeExif(CxFile * hFile);
+       void DiscardAllButExif();
+protected:
+       bool process_EXIF(unsigned char * CharBuf, unsigned int length);
+       void process_COM (const BYTE * Data, int length);
+       void process_SOFn (const BYTE * Data, int marker);
+       int Get16u(void * Short);
+       int Get16m(void * Short);
+       long Get32s(void * Long);
+       unsigned long Get32u(void * Long);
+       double ConvertAnyFormat(void * ValuePtr, int Format);
+       void* FindSection(int SectionType);
+       bool ProcessExifDir(unsigned char * DirStart, unsigned char * OffsetBase, unsigned ExifLength,
+                           EXIFINFO * const pInfo, unsigned char ** const LastExifRefdP, int NestingLevel=0);
+       int ExifImageWidth;
+       int MotorolaOrder;
+       Section_t Sections[MAX_SECTIONS];
+       int SectionsRead;
+       bool freeinfo;
+};
+
+       CxExifInfo* m_exif;
+       EXIFINFO m_exifinfo;
+       bool DecodeExif(CxFile * hFile);
+       bool DecodeExif(FILE * hFile) { CxIOFile file(hFile); return DecodeExif(&file); }
+
+#endif //CXIMAGEJPG_SUPPORT_EXIF
+
+////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////        C x F i l e J p g         ////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////
+
+// thanks to Chris Shearer Cooper <cscooper(at)frii(dot)com>
+class CxFileJpg : public jpeg_destination_mgr, public jpeg_source_mgr
+       {
+public:
+       enum { eBufSize = 4096 };
+
+       CxFileJpg(CxFile* pFile)
+       {
+        m_pFile = pFile;
+
+               init_destination = InitDestination;
+               empty_output_buffer = EmptyOutputBuffer;
+               term_destination = TermDestination;
+
+               init_source = InitSource;
+               fill_input_buffer = FillInputBuffer;
+               skip_input_data = SkipInputData;
+               resync_to_restart = jpeg_resync_to_restart; // use default method
+               term_source = TermSource;
+               next_input_byte = NULL; //* => next byte to read from buffer 
+               bytes_in_buffer = 0;    //* # of bytes remaining in buffer 
+
+               m_pBuffer = new unsigned char[eBufSize];
+       }
+       ~CxFileJpg()
+       {
+               delete [] m_pBuffer;
+       }
+
+       static void InitDestination(j_compress_ptr cinfo)
+       {
+               CxFileJpg* pDest = (CxFileJpg*)cinfo->dest;
+               pDest->next_output_byte = pDest->m_pBuffer;
+               pDest->free_in_buffer = eBufSize;
+       }
+
+       static boolean EmptyOutputBuffer(j_compress_ptr cinfo)
+       {
+               CxFileJpg* pDest = (CxFileJpg*)cinfo->dest;
+               if (pDest->m_pFile->Write(pDest->m_pBuffer,1,eBufSize)!=(size_t)eBufSize)
+                       ERREXIT(cinfo, JERR_FILE_WRITE);
+               pDest->next_output_byte = pDest->m_pBuffer;
+               pDest->free_in_buffer = eBufSize;
+               return TRUE;
+       }
+
+       static void TermDestination(j_compress_ptr cinfo)
+       {
+               CxFileJpg* pDest = (CxFileJpg*)cinfo->dest;
+               size_t datacount = eBufSize - pDest->free_in_buffer;
+               /* Write any data remaining in the buffer */
+               if (datacount > 0) {
+                       if (!pDest->m_pFile->Write(pDest->m_pBuffer,1,datacount))
+                               ERREXIT(cinfo, JERR_FILE_WRITE);
+               }
+               pDest->m_pFile->Flush();
+               /* Make sure we wrote the output file OK */
+               if (pDest->m_pFile->Error()) ERREXIT(cinfo, JERR_FILE_WRITE);
+               return;
+       }
+
+       static void InitSource(j_decompress_ptr cinfo)
+       {
+               CxFileJpg* pSource = (CxFileJpg*)cinfo->src;
+               pSource->m_bStartOfFile = TRUE;
+       }
+
+       static boolean FillInputBuffer(j_decompress_ptr cinfo)
+       {
+               size_t nbytes;
+               CxFileJpg* pSource = (CxFileJpg*)cinfo->src;
+               nbytes = pSource->m_pFile->Read(pSource->m_pBuffer,1,eBufSize);
+               if (nbytes <= 0){
+                       if (pSource->m_bStartOfFile)    //* Treat empty input file as fatal error 
+                               ERREXIT(cinfo, JERR_INPUT_EMPTY);
+                       WARNMS(cinfo, JWRN_JPEG_EOF);
+                       // Insert a fake EOI marker 
+                       pSource->m_pBuffer[0] = (JOCTET) 0xFF;
+                       pSource->m_pBuffer[1] = (JOCTET) JPEG_EOI;
+                       nbytes = 2;
+               }
+               pSource->next_input_byte = pSource->m_pBuffer;
+               pSource->bytes_in_buffer = nbytes;
+               pSource->m_bStartOfFile = FALSE;
+               return TRUE;
+       }
+
+       static void SkipInputData(j_decompress_ptr cinfo, long num_bytes)
+       {
+               CxFileJpg* pSource = (CxFileJpg*)cinfo->src;
+               if (num_bytes > 0){
+                       while (num_bytes > (long)pSource->bytes_in_buffer){
+                               num_bytes -= (long)pSource->bytes_in_buffer;
+                               FillInputBuffer(cinfo);
+                               // note we assume that fill_input_buffer will never return FALSE,
+                               // so suspension need not be handled.
+                       }
+                       pSource->next_input_byte += (size_t) num_bytes;
+                       pSource->bytes_in_buffer -= (size_t) num_bytes;
+               }
+       }
+
+       static void TermSource(j_decompress_ptr /*cinfo*/)
+       {
+               return;
+       }
+protected:
+    CxFile  *m_pFile;
+       unsigned char *m_pBuffer;
+       bool m_bStartOfFile;
+};
+
+public:
+       enum CODEC_OPTION
+       {
+               ENCODE_BASELINE = 0x1,
+               ENCODE_ARITHMETIC = 0x2,
+               ENCODE_GRAYSCALE = 0x4,
+               ENCODE_OPTIMIZE = 0x8,
+               ENCODE_PROGRESSIVE = 0x10,
+               ENCODE_LOSSLESS = 0x20,
+               ENCODE_SMOOTHING = 0x40,
+               DECODE_GRAYSCALE = 0x80,
+               DECODE_QUANTIZE = 0x100,
+               DECODE_DITHER = 0x200,
+               DECODE_ONEPASS = 0x400,
+               DECODE_NOSMOOTH = 0x800,
+               ENCODE_SUBSAMPLE_422 = 0x1000,
+               ENCODE_SUBSAMPLE_444 = 0x2000
+       }; 
+
+       int m_nPredictor;
+       int m_nPointTransform;
+       int m_nSmoothing;
+       int m_nQuantize;
+       J_DITHER_MODE m_nDither;
+
+};
+
+#endif
+
+#endif