Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef __ITGA_H__
00017 #define __ITGA_H__
00018
00019 #include "imagen.h"
00020
00021 #ifdef IMAGEN_TGA
00022
00023 #include "iAbstractImage.h"
00024 #include "iLinkedList.h"
00025
00026 namespace imagen
00027 {
00029
00063 class iTGA : public iAbstractImage
00064 {
00065 private:
00066 #pragma pack(1)
00067
00068 struct TGA_HEADER
00069 {
00070 TGA_HEADER();
00071 void clear();
00072
00073 iBYTE IDLength;
00074 iBYTE ColorMapType;
00075 iBYTE ImageType;
00076 iWORD CMapStart;
00077 iWORD CMapLength;
00078 iBYTE CMapDepth;
00079 iWORD XOffset;
00080 iWORD YOffset;
00081 iWORD Width;
00082 iWORD Height;
00083 iBYTE PixelDepth;
00084 iBYTE ImageDescriptor;
00085 };
00086
00088 struct TGA_FOOTER
00089 {
00090 TGA_FOOTER();
00091 void clear();
00092
00093 iDWORD ExtensionOffset;
00094 iDWORD DeveloperOffset;
00095 iCHAR Signature[16];
00096 iCHAR ReservedChar;
00097 iCHAR StringTerminator;
00098 };
00099
00101 struct TGA_EXTENSION
00102 {
00103 TGA_EXTENSION();
00104 void clear();
00105
00106 iWORD Size;
00107 iCHAR AuthorName[41];
00108 iCHAR AuthorComment[324];
00109 iWORD StampMonth;
00110 iWORD StampDay;
00111 iWORD StampYear;
00112 iWORD StampHour;
00113 iWORD StampMinute;
00114 iWORD StampSecond;
00115 iCHAR JobName[41];
00116 iWORD JobHour;
00117 iWORD JobMinute;
00118 iWORD JobSecond;
00119 iCHAR SoftwareId[41];
00120 iWORD VersionNumber;
00121 iBYTE VersionLetter;
00122 iDWORD KeyColor;
00123 iWORD PixelNumerator;
00124 iWORD PixelDenominator;
00125 iWORD GammaNumerator;
00126 iWORD GammaDenominator;
00127 iDWORD ColorOffset;
00128 iDWORD StampOffset;
00129 iDWORD ScanOffset;
00130 iBYTE AttributesType;
00131 };
00132
00134 struct TGA_DEVTAG
00135 {
00136 iWORD TagNumber;
00137 iDWORD DataOffset;
00138 iDWORD DataSize;
00139 };
00140 #pragma pack()
00141
00142 public:
00144 struct TargaDevField
00145 {
00147 TargaDevField() : data(NULL), size(0), tagID(0) {};
00148
00150
00153 TargaDevField( Iubyte *d, int sz, int id ) : data(d), size(sz), tagID(id) {};
00154
00155 Iubyte *data;
00156 int tagID;
00157 int size;
00158 };
00159
00160 enum TargaType
00161 {
00162 NoData = 0,
00163 ColMap = 1,
00164 TrueCol = 2,
00165 BW = 3,
00166 RLE_ColMap = 9,
00167 RLE_TrueCol = 10,
00168 RLE_BW = 11
00169 };
00170
00171 enum TargaOrigin
00172 {
00173 OriginBL = 0,
00174 OriginBR = 1,
00175 OriginUL = 2,
00176 OriginUR = 3
00177 };
00178
00179 enum TargaVersion
00180 {
00181 v1_0 = 1,
00182 v2_0 = 2
00183 };
00184
00185 public:
00187 iTGA();
00188
00190
00191 iTGA( const iTGA &img );
00192
00194 iTGA( const iAbstractImage &img );
00195
00197
00201 iTGA( int w, int h, iImageFormat f );
00202
00204
00206 iTGA( Iubyte *d, int w, int h, iImageFormat f, int b );
00207
00209
00210 iTGA( const char *filename );
00211
00213
00214 iTGA( Iubyte *buf, int len );
00215
00217
00218 iTGA( iDataStream *s );
00219
00221 ~iTGA();
00222
00223 void clear();
00224
00225 bool isFormatSupported( iImageFormat fmt ) const;
00226
00227 static bool isValid( iDataStream *s );
00228
00230 void setImageID( const char id[255] );
00231
00233 const char *getImageID() const { return imageID; }
00234
00236
00238 void setTargaVersion( TargaVersion ver ) { tgaVer = ver; }
00239
00241 TargaVersion getTargaVersion() const { return tgaVer; }
00242
00244
00246 void addDevField( const TargaDevField &field ) { devField.append(field); }
00247
00249
00250 void setJobName( const char *name ) { jobName = name; }
00251
00253
00254 const char *getJobName() const { return jobName; }
00255
00257
00258 void enableRLE( bool brle ) { useRle = brle; }
00259
00261
00262 void enableExtension( bool bext ) { useExt = bext; }
00263
00265
00266 void enableDevArea( bool bdev ) { useDev = bdev; }
00267
00268 iTGA &operator=( const iTGA &img );
00269
00270 iTGA &operator=( const iAbstractImage &img );
00271
00272 protected:
00273 void init();
00274 bool loadImage();
00275 bool saveImage();
00276
00277 private:
00278 bool readHeader();
00279 bool readFooter();
00280 bool readDevArea();
00281 bool readExtension();
00282 bool readImageID();
00283 bool readColMapData();
00284 bool validateHeader();
00285 bool readImageData();
00286 bool readRaw();
00287 bool readRLE();
00288
00289 bool writeHeader();
00290 bool writeFooter();
00291 bool writeDevArea();
00292 bool writeExtension();
00293 bool writeImageID();
00294 bool writeColMapData();
00295 bool writeImageData();
00296 bool writeRaw( Iubyte *buf );
00297 bool writeRLE( Iubyte *buf );
00298
00299 int compressRLELine( Iubyte *in, Iuint n, Iubyte *out );
00300 int countDiffPixels( Iubyte *buf, Iuint count );
00301 int countSamePixels( Iubyte *buf, Iuint count );
00302
00303 Iuint getDevAreaSize();
00304 Iuint getTargaSize();
00305
00306 iImageOrigin TargaOrigin2iImageOrigin( TargaOrigin org );
00307 TargaOrigin iImageOrigin2TargaOrigin( iImageOrigin org );
00308
00309 private:
00310 TGA_HEADER header;
00311 TGA_FOOTER footer;
00312 TGA_EXTENSION extension;
00313 char imageID[255];
00314 TargaVersion tgaVer;
00315 int alphabits;
00316 const char *jobName;
00317
00318 iLinkedList<TargaDevField> devField;
00319
00320
00321 bool useRle;
00322 bool useExt;
00323 bool useDev;
00324 };
00325 }
00326
00327 #endif // IMAGEN_TGA
00328
00329 #endif // __ITGA_H__