00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00074
00075 #ifndef __FK_IMAGE_HEADER__
00076 #define __FK_IMAGE_HEADER__
00077
00078 #include <FK/Base.h>
00079 #include <FK/Material.h>
00080 #include <vector>
00081 #include <string>
00082
00083 #ifndef FK_DOXYGEN_USER_PROCESS
00084
00085 #ifdef NO_GL_LIBRARY
00086 typedef unsigned char fk_ImType;
00087 typedef unsigned int fk_TexID;
00088 #else
00089 #include <FK/OpenGL.H>
00090 typedef GLubyte fk_ImType;
00091 typedef GLuint fk_TexID;
00092 #endif
00093
00094
00095 enum fk_ImageStatus {
00096 FK_IMAGE_OK,
00097 FK_IMAGE_OPENERROR,
00098 FK_IMAGE_DATAERROR,
00099 FK_IMAGE_READERROR
00100 };
00101
00102 enum fk_ImageFix {
00103 FK_FIX_LARGE,
00104 FK_FIX_SMALL,
00105 FK_FIX_64,
00106 FK_FIX_128,
00107 FK_FIX_256,
00108 FK_FIX_512,
00109 FK_FIX_1024,
00110 FK_FIX_2048,
00111 FK_FIX_4096,
00112 FK_FIX_8192,
00113 FK_FIX_16384,
00114 FK_FIX_32768,
00115 FK_FIX_65536
00116 };
00117
00118 #endif
00119
00121 enum fk_ImageType {
00122 FK_IMAGE_BMP,
00123 FK_IMAGE_PNG,
00124 FK_IMAGE_JPG
00125 };
00126
00128 enum fk_SnapProcMode {
00129 FK_SNAP_GL_FRONT,
00130 FK_SNAP_GL_BACK,
00131 FK_SNAP_WIN32_GDI,
00132 FK_SNAP_D3D_WINDOW,
00133 FK_SNAP_D3D_FULL
00134 };
00135
00137
00141 class fk_Dimension {
00142 public:
00143 int w;
00144 int h;
00145
00147
00151 fk_Dimension(int w = 0, int h = 0);
00152
00154 fk_Dimension(const fk_Dimension &);
00155
00157
00161 void set(int w, int h);
00162 };
00163
00165
00171 class fk_Rect {
00172 public:
00173 int x;
00174 int y;
00175 int w;
00176 int h;
00177
00179
00185 fk_Rect(int x = 0, int y = 0, int w = 0, int h = 0);
00186
00188 fk_Rect(const fk_Rect &);
00189
00191
00197 void set(int x, int y, int w, int h);
00198
00200
00204 void setPos(int x, int y);
00205
00207
00211 void setSize(int w, int h);
00212
00214
00217 fk_Dimension getSize(void);
00218 };
00219
00221
00235 class fk_Image : public fk_BaseObject {
00236
00237 friend class fk_Texture;
00238
00239 private:
00240
00241 fk_Dimension imageSize, bufSize;
00242 std::vector<fk_ImType> imageBuf;
00243 fk_TexID texID;
00244 bool initFlag;
00245
00246 fk_Rect updateRect;
00247
00248 unsigned int ChgUInt(fk_ImType *, int) const;
00249 unsigned int ChgUShort(fk_ImType *, int) const;
00250
00251 int GetOffset(int, int) const;
00252 fk_ImType RoundVal(int) const;
00253 fk_ImageStatus CreateImg(const std::string);
00254 fk_ImageStatus CreateImg(fk_ImType *);
00255 void CreateBuffer(bool = true);
00256 void CreateBuffer(int, int, bool = true);
00257 void CreateBuffer(const fk_Dimension, bool = true);
00258 bool IsPixelStatus(int, int) const;
00259 int GetOneBufferSize(int, int);
00260 int GetFixVal(fk_ImageFix, int) const;
00261
00262 void SetLong2Byte(long, fk_ImType *, int);
00263 void SetInt2Byte(int, fk_ImType *, int);
00264
00265 bool GetInitFlag(void);
00266 void SetInitFlag(bool);
00267 void SetTexID(const fk_TexID);
00268
00269 bool IsBmpFile(const std::string) const;
00270 bool IsBmpData(fk_ImType *) const;
00271 fk_ImageStatus LoadBmpFile(const std::string);
00272 fk_ImageStatus LoadBmpData(fk_ImType *);
00273 void SetRGBA4Bmp(int, int, fk_ImType *,
00274 int, std::vector<fk_ImType> &);
00275
00276 bool GetBmpFileHeader(FILE *, fk_ImType *);
00277 bool GetBmpInfoHeader(FILE *, fk_ImType *);
00278 fk_Dimension GetBmpSize(fk_ImType *);
00279
00280 fk_ImageStatus SaveBmpFile(std::string, bool);
00281 void MakeBmpFileHeader(int, int, int,
00282 std::vector<fk_ImType> &);
00283 void MakeBmpInfoHeader(int, int, int,
00284 std::vector<fk_ImType> &);
00285 void MakeBmpBuffer(int, int, bool, fk_ImType *);
00286
00287 bool IsPngFile(const std::string) const;
00288 bool IsPngData(fk_ImType *) const;
00289 fk_ImageStatus LoadPngFile(const std::string);
00290 fk_ImageStatus LoadPngData(fk_ImType *);
00291
00292 public:
00293
00295
00299 fk_Image(int w = 0, int h = 0);
00300
00302 ~fk_Image();
00303
00305 fk_Image(const fk_Image &);
00306
00308
00312 void init();
00313
00315
00322 bool readBMP(const std::string fileName);
00323
00325
00334 bool readBMPData(fk_ImType *buf);
00335
00337
00344 bool readPNG(const std::string fileName);
00345
00347
00356 bool readPNGData(fk_ImType *buf);
00357
00359
00364 bool readJPG(const std::string fileName);
00365
00367
00380 bool writeBMP(const std::string fileName,
00381 const bool transFlg = false);
00382
00384
00393 bool writePNG(const std::string fileName,
00394 const bool transFlg = true);
00395
00397
00410 bool writeJPG(const std::string fileName,
00411 int quality = 80);
00412
00414
00425 void newImage(int w, int h, bool initFlg = true);
00426
00428
00434 void copyImage(const fk_Image *image);
00435
00437
00448 void copyImage(const fk_Image *image, int x, int y);
00449
00451
00462 bool subImage(const fk_Image *image,
00463 int x, int y, int w, int h);
00464
00466
00469 int getWidth(void) const;
00470
00472
00475 int getHeight(void) const;
00476
00478
00481 const fk_Dimension * getImageSize(void);
00482
00484
00506 const fk_Dimension * getBufferSize(void);
00507
00509
00519 int getR(int x, int y) const;
00520
00522
00532 int getG(int x, int y) const;
00533
00535
00545 int getB(int x, int y) const;
00546
00548
00558 int getA(int x, int y) const;
00559
00561
00571 fk_Color getColor(int x, int y) const;
00572
00574
00591 bool setRGBA(int x, int y, int r, int g, int b, int a);
00592
00594
00610 bool setRGB(int x, int y, int r, int g, int b);
00611
00613
00627 bool setR(int x, int y, int r);
00628
00630
00644 bool setG(int x, int y, int g);
00645
00647
00661 bool setB(int x, int y, int b);
00662
00664
00678 bool setA(int x, int y, int a);
00679
00681
00692 bool setColor(int x, int y, const fk_Color &col);
00693
00695
00702 void fillColor(const fk_Color &col);
00703
00705
00715 void fillColor(int r, int g, int b, int a = 0);
00716
00718
00731 const fk_ImType * getBufPointer(void) const;
00732
00733 #ifndef FK_DOXYGEN_USER_PROCESS
00734
00735 fk_TexID GetTexID(void);
00736 void ClearUpdateArea(void);
00737 void SetUpdateArea(void);
00738 void SetUpdateArea(int, int, int, int);
00739 fk_Rect GetUpdateArea(void);
00740
00741 #endif
00742
00743 };
00744
00745 #endif // __FK_IMAGE_HEADER__