iJPEG.h
Go to the documentation of this file.
00001 /*
00002 imagen - Simple object-oriented imaging library
00003 Copyright (C) 2012 Mark D. Procarione
00004 
00005 imagen is free software: you can redistribute it and/or
00006 modify it under the terms of the GNU Lesser General Public
00007 License as published by the Free Software Foundation, either
00008 version 3 of the License, or (at your option) any later version.
00009 
00010 imagen is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 GNU General Public License for more details.
00014 */
00015 
00016 #ifndef __IJPEG_H__
00017 #define __IJPEG_H__
00018 
00019 #include "imagen.h"
00020 
00021 #ifdef IMAGEN_JPEG
00022 
00023 #include "iAbstractImage.h"
00024 
00025 #include <csetjmp>
00026 
00027 namespace imagen
00028 {
00030 
00046     class iJPEG : public iAbstractImage
00047     {
00048         public:
00050             enum JpegDCTMethod
00051             {
00052                 DCTInteger,
00053                 DCTFastInteger,
00054                 DCTFloat
00055             };
00056 
00058             enum JpegSubsampling
00059             {
00060                 SubSample444, 
00061                 SubSample422, 
00062                 SubSample411  
00063             };
00064 
00065         public:
00067             iJPEG();
00068 
00070 
00071             iJPEG( const iJPEG &img );
00072 
00074             iJPEG( const iAbstractImage &img );
00075 
00077 
00081             iJPEG( int w, int h, iImageFormat f );
00082 
00084 
00086             iJPEG( Iubyte *d, int w, int h, iImageFormat f, int b );
00087 
00089 
00090             iJPEG( const char *filename );
00091 
00093 
00094             iJPEG( Iubyte *buf, int len );
00095 
00097 
00098             iJPEG( iDataStream *s );
00099 
00101             ~iJPEG();
00102 
00103             void clear();
00104 
00105             bool isFormatSupported( iImageFormat fmt ) const;
00106 
00107             static bool isValid( iDataStream *s );
00108 
00110 
00112             void setQuality( int q );
00113 
00115             int getQuality() const { return jqual; }
00116 
00118 
00120             void setSmoothing( int sm );
00121 
00123             int getSmoothing() const { return jsmooth; }
00124 
00126 
00127             void setDCTMethod( JpegDCTMethod dct ) { jdct = dct; }
00128 
00130             JpegDCTMethod getDCTMethod() const { return jdct; }
00131 
00133 
00134             void setSubsampling( JpegSubsampling ss ) { jsubsamp = ss; }
00135 
00137             JpegSubsampling getSubsampling() const { return jsubsamp; }
00138 
00140 
00141             void enableProgression( bool bprg ) { usePrg = bprg; }
00142 
00144 
00146             void enableOptimization( bool bopt ) { useOpt = bopt; }
00147 
00149 
00152             void enableChromaDownsampling( bool bdown ) { useDownSamp = bdown; }
00153 
00155             void saveExif( bool bexif ) { doSaveExif = bexif; }
00156 
00158             void saveThumbnail( bool bthumb ) { doSaveThumb = bthumb; }
00159 
00160             iJPEG &operator=( const iJPEG &img );
00161 
00162             iJPEG &operator=( const iAbstractImage &img );
00163 
00164         protected:
00165             void init();
00166             bool loadImage();
00167             bool saveImage();
00168 
00169         private:
00170             bool checkHeader();
00171             bool readImageData();
00172             bool writeImageData();
00173 
00174         private:
00175             static iDataStream *jpgstream;
00176 
00177             int jqual;
00178             int jsmooth;
00179             JpegDCTMethod jdct;
00180             JpegSubsampling jsubsamp;
00181 
00182             bool usePrg;
00183             bool useOpt;
00184             bool useDownSamp;
00185 
00186             bool doSaveExif;
00187             bool doSaveThumb;
00188 
00189             static jmp_buf jpgJmpBuf;
00190     };
00191 }
00192 
00193 #endif // IMAGEN_JPEG
00194 
00195 #endif // __IJPEG_H__