FineKernelToolKit
2.8.10
|
00001 /**************************************************************************** 00002 * 00003 * Copyright (c) 1999-2011, Fine Kernel Project, All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, 00006 * with or without modification, are permitted provided that the 00007 * following conditions are met: 00008 * 00009 * - Redistributions of source code must retain the above 00010 * copyright notice, this list of conditions and the 00011 * following disclaimer. 00012 * 00013 * - Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the 00015 * following disclaimer in the documentation and/or 00016 * other materials provided with the distribution. 00017 * 00018 * - Neither the name of the copyright holders nor the names 00019 * of its contributors may be used to endorse or promote 00020 * products derived from this software without specific 00021 * prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00029 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00031 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00032 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00033 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 ****************************************************************************/ 00037 /**************************************************************************** 00038 * 00039 * Copyright (c) 1999-2011, Fine Kernel Project, All rights reserved. 00040 * 00041 * 本ソフトウェアおよびソースコードのライセンスは、基本的に 00042 * 「修正 BSD ライセンス」に従います。以下にその詳細を記します。 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_ImType *bufPointer; 00244 fk_TexID texID; 00245 bool initFlag; 00246 // テクスチャの部分更新用情報 00247 fk_Rect updateRect; 00248 00249 unsigned int ChgUInt(fk_ImType *, int) const; 00250 unsigned int ChgUShort(fk_ImType *, int) const; 00251 00252 int GetOffset(int, int) const; 00253 fk_ImType RoundVal(int) const; 00254 fk_ImageStatus CreateImg(const std::string); 00255 fk_ImageStatus CreateImg(fk_ImType *); 00256 void CreateBuffer(bool = true); 00257 void CreateBuffer(int, int, bool = true); 00258 void CreateBuffer(const fk_Dimension, bool = true); 00259 bool IsPixelStatus(int, int) const; 00260 int GetOneBufferSize(int, int); 00261 int GetFixVal(fk_ImageFix, int) const; 00262 00263 void SetLong2Byte(long, fk_ImType *, int); 00264 void SetInt2Byte(int, fk_ImType *, int); 00265 00266 bool GetInitFlag(void); 00267 void SetInitFlag(bool); 00268 void SetTexID(const fk_TexID); 00269 00270 bool IsBmpFile(const std::string) const; 00271 bool IsBmpData(fk_ImType *) const; 00272 fk_ImageStatus LoadBmpFile(const std::string); 00273 fk_ImageStatus LoadBmpData(fk_ImType *); 00274 void SetRGBA4Bmp(int, int, fk_ImType *, 00275 int, std::vector<fk_ImType> &); 00276 00277 bool GetBmpFileHeader(FILE *, fk_ImType *); 00278 bool GetBmpInfoHeader(FILE *, fk_ImType *); 00279 fk_Dimension GetBmpSize(fk_ImType *); 00280 00281 fk_ImageStatus SaveBmpFile(std::string, bool); 00282 void MakeBmpFileHeader(int, int, int, 00283 std::vector<fk_ImType> &); 00284 void MakeBmpInfoHeader(int, int, int, 00285 std::vector<fk_ImType> &); 00286 void MakeBmpBuffer(int, int, bool, fk_ImType *); 00287 00288 bool IsPngFile(const std::string) const; 00289 bool IsPngData(fk_ImType *) const; 00290 fk_ImageStatus LoadPngFile(const std::string); 00291 fk_ImageStatus LoadPngData(fk_ImType *); 00292 00293 public: 00294 00296 00300 fk_Image(int w = 0, int h = 0); 00301 00303 virtual ~fk_Image(); 00304 00306 fk_Image(const fk_Image &); 00307 00309 00313 void init(); 00314 00316 00323 bool readBMP(const std::string fileName); 00324 00326 00335 bool readBMPData(fk_ImType *buf); 00336 00338 00345 bool readPNG(const std::string fileName); 00346 00348 00357 bool readPNGData(fk_ImType *buf); 00358 00360 00365 bool readJPG(const std::string fileName); 00366 00368 00381 bool writeBMP(const std::string fileName, 00382 const bool transFlg = false); 00383 00385 00394 bool writePNG(const std::string fileName, 00395 const bool transFlg = true); 00396 00398 00411 bool writeJPG(const std::string fileName, 00412 int quality = 80); 00413 00415 00426 void newImage(int w, int h, bool initFlg = true); 00427 00429 00435 void copyImage(const fk_Image *image); 00436 00438 00449 void copyImage(const fk_Image *image, int x, int y); 00450 00452 00463 bool subImage(const fk_Image *image, 00464 int x, int y, int w, int h); 00465 00467 00470 int getWidth(void) const; 00471 00473 00476 int getHeight(void) const; 00477 00479 00482 const fk_Dimension * getImageSize(void); 00483 00485 00507 const fk_Dimension * getBufferSize(void); 00508 00510 00520 int getR(int x, int y) const; 00521 00523 00533 int getG(int x, int y) const; 00534 00536 00546 int getB(int x, int y) const; 00547 00549 00559 int getA(int x, int y) const; 00560 00562 00572 fk_Color getColor(int x, int y) const; 00573 00575 00592 bool setRGBA(int x, int y, int r, int g, int b, int a); 00593 00595 00611 bool setRGB(int x, int y, int r, int g, int b); 00612 00614 00628 bool setR(int x, int y, int r); 00629 00631 00645 bool setG(int x, int y, int g); 00646 00648 00662 bool setB(int x, int y, int b); 00663 00665 00679 bool setA(int x, int y, int a); 00680 00682 00693 bool setColor(int x, int y, const fk_Color &col); 00694 00696 00703 void fillColor(const fk_Color &col); 00704 00706 00716 void fillColor(int r, int g, int b, int a = 0); 00717 00719 00732 const fk_ImType * getBufPointer(void) const; 00733 00734 #ifndef FK_DOXYGEN_USER_PROCESS 00735 00736 fk_TexID GetTexID(void); 00737 void ClearUpdateArea(void); 00738 void SetUpdateArea(void); 00739 void SetUpdateArea(int, int, int, int); 00740 fk_Rect GetUpdateArea(void); 00741 00742 #endif 00743 00744 }; 00745 00746 #endif // __FK_IMAGE_HEADER__