Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef __IABSTRACTIMAGE_H__
00017 #define __IABSTRACTIMAGE_H__
00018
00019 #include "imagen.h"
00020
00021 #include "iPalette.h"
00022 #include "iColor.h"
00023 #include "iDateTime.h"
00024 #include "iDataStream.h"
00025
00026 namespace imagen
00027 {
00029 class iSharedData
00030 {
00031 public:
00033
00034 iSharedData();
00035
00037
00038 iSharedData( const iSharedData &d );
00039
00041
00044 iSharedData( Iubyte *d, int length );
00045
00047 iSharedData( int length );
00048
00050 ~iSharedData();
00051
00053 void attach();
00054
00056
00057 void detach();
00058
00060
00061 iSharedData *unalias();
00062
00063 public:
00064 Iubyte *data;
00065 int len;
00066
00067 private:
00068 int refCount;
00069 bool delData;
00070 };
00071
00072 class iAbstractImage;
00073
00074 typedef void (*iReadCallback)( int numRows, int curRow, Iubyte *data );
00075 typedef void (*iWriteCallback)( int numRows, int curRow );
00076
00078
00084 class iAbstractImage
00085 {
00086 public:
00088 iAbstractImage();
00089
00091
00092 iAbstractImage( const iAbstractImage &img );
00093
00095
00099 iAbstractImage( int w, int h, iImageFormat f );
00100
00102
00104 iAbstractImage( Iubyte *d, int w, int h, iImageFormat f, int b );
00105
00107
00109 virtual ~iAbstractImage();
00110
00112
00114 bool load( const char *filename );
00115
00117
00120 bool load( Iubyte *buf, int len );
00121
00123
00126 bool load( iDataStream *s );
00127
00129
00131 bool save( const char *filename );
00132
00134
00137 bool save( Iubyte *buf, int len );
00138
00140
00143 bool save( iDataStream *s );
00144
00146
00152 void loadData( Iubyte *d, int w, int h, iImageFormat f, int b );
00153
00155 virtual void clear();
00156
00158
00159 void detachData();
00160
00162 void flipVertical();
00163
00165 void flipHorizontal();
00166
00168
00169 void rotateLeft();
00170
00172
00173 void rotateRight();
00174
00176 void rotate180();
00177
00179 void fill( const iColor &col );
00180
00182
00183 bool pad( int top, int left, int bottom, int right, iWrapMode mode );
00184
00186
00194 bool resize( int w, int h, int x, int y );
00195
00197 void swapRGB();
00198
00200
00205 void convertFormat( iImageFormat fmt, int alpha = 255 );
00206
00208 int imageSize() const { return width*height*bpp; }
00209
00211 bool isNull() const;
00212
00214
00215 virtual bool isFormatSupported( iImageFormat fmt ) const = 0;
00216
00218 Iubyte *getData() { return data->data; }
00219
00221 const Iubyte *getData() const { return data->data; }
00222
00224 int getWidth() const { return width; }
00225
00227 int getHeight() const { return height; }
00228
00230 iImageFormat getFormat() const { return format; }
00231
00233 int getBpp() const { return bpp; }
00234
00236 iImageType getType() const { return type; }
00237
00239 void setXOffset( int x ) { xoffset = x; }
00240
00242 void setYOffset( int y ) { yoffset = y; }
00243
00245 int getXOffset() const { return xoffset; }
00246
00248 int getYOffset() const { return yoffset; }
00249
00251 void setUnitType( iUnitType unit ) { unitType = unit; }
00252
00254 iUnitType getUnitType() const { return unitType; }
00255
00257 void setXRes( int x ) { XResolution = x; }
00258
00260 void setYRes( int y ) { YResolution = y; }
00261
00263 int getXRes() const { return XResolution; }
00264
00266 int getYRes() const { return YResolution; }
00267
00269 void setOrigin( iImageOrigin org ) { origin = org; }
00270
00272 iImageOrigin getOrigin() const { return origin; }
00273
00275 void setWriteOrigin( iImageOrigin org ) { worigin = org; }
00276
00278 iImageOrigin getWriteOrigin() const { return worigin; }
00279
00281 void setCreationTime( const iDateTime &dt ) { createTime = dt; }
00282
00284 iDateTime getCreationTime() const { return createTime; }
00285
00287
00293 void updateCreationTime( bool bup ) { updateTime = bup; }
00294
00296 void setJobTime( const iJobTime &jt ) { jobTime = jt; }
00297
00299 iJobTime getJobTime() const { return jobTime; }
00300
00302 void setAuthor( const char *name ) { author = name; }
00303
00305 const char *getAuthor() const { return author; }
00306
00308 void setComment( const char *comm ) { comment = comm; }
00309
00311 const char *getComment() const { return comment; }
00312
00314
00316 void setClearCol( iColor col ) { clrcol = col; }
00317
00319 iColor getClearCol() const { return clrcol; }
00320
00322 bool hasPalette() const;
00323
00325 iPalette setPalette( const iPalette &pal ) { palette = pal; }
00326
00328 iPalette getPalette() const { return palette; }
00329
00331 bool hasAlpha() const;
00332
00334 iColor getPixel( int x, int y ) const;
00335
00337 iColor getPixel( int index ) const;
00338
00340 void setPixel( int x, int y, const iColor &col );
00341
00343 void setPixel( int index, const iColor &col );
00344
00346 int getPixelIndex( int x, int y ) const;
00347
00349 void setReadFunc( iReadCallback func ) { readFunc = func; }
00350
00352 void setWriteFunc( iWriteCallback func ) { writeFunc = func; }
00353
00354 iAbstractImage &operator=( const iAbstractImage &img );
00355
00356 protected:
00357 void init();
00358 virtual bool loadImage() = 0;
00359 virtual bool saveImage() = 0;
00360
00361 protected:
00362 iSharedData *data;
00363 int width;
00364 int height;
00365 iImageFormat format;
00366 int bpp;
00367
00368 int xoffset;
00369 int yoffset;
00370
00371 iColor clrcol;
00372
00373 iImageType type;
00374 iImageOrigin origin;
00375 iImageOrigin worigin;
00376 iPalette palette;
00377
00378 iUnitType unitType;
00379 int XResolution;
00380 int YResolution;
00381
00382 iDateTime createTime;
00383 bool updateTime;
00384
00385 iJobTime jobTime;
00386
00387 const char *author;
00388 const char *comment;
00389
00390 iDataStream *stream;
00391
00392 iReadCallback readFunc;
00393 iWriteCallback writeFunc;
00394 };
00395 }
00396
00397 #endif // __IABSTRACTIMAGE_H__