iPNG.h
Go to the documentation of this file.
00001 /*
00002 imagen - Simple object-oriented imaging library
00003 Copyright (C) 2011-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 __IPNG_H__
00017 #define __IPNG_H__
00018 
00019 #include "imagen.h"
00020 
00021 #ifdef IMAGEN_PNG
00022 
00023 #include "iAbstractImage.h"
00024 
00025 namespace imagen
00026 {
00028 
00043     class iPNG : public iAbstractImage
00044     {
00045         public:
00047             enum PNGInterlaceType
00048             {
00049                 InterlaceNone,
00050                 InterlaceAdam7
00051             };
00052 
00053         public:
00055             iPNG();
00056 
00058 
00059             iPNG( const iPNG &img );
00060 
00062             iPNG( const iAbstractImage &img );
00063 
00065 
00069             iPNG( int w, int h, iImageFormat f );
00070 
00072 
00074             iPNG( Iubyte *d, int w, int h, iImageFormat f, int b );
00075 
00077 
00078             iPNG( const char *filename );
00079 
00081 
00082             iPNG( Iubyte *buf, int len );
00083 
00085 
00086             iPNG( iDataStream *s );
00087 
00089             ~iPNG();
00090 
00091             void clear();
00092 
00093             bool isFormatSupported( iImageFormat fmt ) const;
00094 
00095             static bool isValid( iDataStream *s );
00096 
00098 
00102             void setCompressLevel( int lvl );
00103 
00105             int getCompressLevel() const { return compLvl; }
00106 
00108             void setInterlaceType( PNGInterlaceType type ) { intType = type; }
00109 
00111             PNGInterlaceType getInterlaceType() const { return intType; }
00112 
00113             iPNG &operator=( const iPNG &img );
00114 
00115             iPNG &operator=( const iAbstractImage &img );
00116 
00117         protected:
00118             void init();
00119             bool loadImage();
00120             bool saveImage();
00121 
00122         private:
00123             bool checkSignature();
00124             bool readImageInfo();
00125             bool readImageData();
00126 
00127             bool readInit();
00128             bool writeInit();
00129             void readClean();
00130             void writeClean();
00131 
00132             bool writeImageInfo();
00133             bool writeImageData();
00134 
00135             void getPNGPalette();
00136             void setPNGPalette();
00137 
00138             void getPNGText();
00139             void setPNGText();
00140 
00141         private:
00142             PNGInterlaceType intType;
00143             int compLvl;
00144     };
00145 }
00146 
00147 #endif // IMAGEN_PNG
00148 
00149 #endif // __IPNG_H__