FineKernelToolKit  2.9.0
 全て クラス ネームスペース ファイル 関数 変数 型定義 列挙型 列挙型の値 フレンド マクロ定義 ページ
Image.h
説明を見る。
1 /****************************************************************************
2  *
3  * Copyright (c) 1999-2014, Fine Kernel Project, All rights reserved.
4  *
5  * Redistribution and use in source and binary forms,
6  * with or without modification, are permitted provided that the
7  * following conditions are met:
8  *
9  * - Redistributions of source code must retain the above
10  * copyright notice, this list of conditions and the
11  * following disclaimer.
12  *
13  * - Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the
15  * following disclaimer in the documentation and/or
16  * other materials provided with the distribution.
17  *
18  * - Neither the name of the copyright holders nor the names
19  * of its contributors may be used to endorse or promote
20  * products derived from this software without specific
21  * prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
33  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  ****************************************************************************/
37 /****************************************************************************
38  *
39  * Copyright (c) 1999-2014, Fine Kernel Project, All rights reserved.
40  *
41  * 本ソフトウェアおよびソースコードのライセンスは、基本的に
42  * 「修正 BSD ライセンス」に従います。以下にその詳細を記します。
43  *
44  * ソースコード形式かバイナリ形式か、変更するかしないかを問わず、
45  * 以下の条件を満たす場合に限り、再頒布および使用が許可されます。
46  *
47  * - ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、
48  * および下記免責条項を含めること。
49  *
50  * - バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の
51  * 資料に、上記の著作権表示、本条件一覧、および下記免責条項を
52  * 含めること。
53  *
54  * - 書面による特別の許可なしに、本ソフトウェアから派生した製品の
55  * 宣伝または販売促進に、本ソフトウェアの著作権者の名前または
56  * コントリビューターの名前を使用してはならない。
57  *
58  * 本ソフトウェアは、著作権者およびコントリビューターによって「現
59  * 状のまま」提供されており、明示黙示を問わず、商業的な使用可能性、
60  * および特定の目的に対する適合性に関す暗黙の保証も含め、またそれ
61  * に限定されない、いかなる保証もないものとします。著作権者もコン
62  * トリビューターも、事由のいかんを問わず、損害発生の原因いかんを
63  * 問わず、かつ責任の根拠が契約であるか厳格責任であるか(過失その
64  * 他の)不法行為であるかを問わず、仮にそのような損害が発生する可
65  * 能性を知らされていたとしても、本ソフトウェアの使用によって発生
66  * した(代替品または代用サービスの調達、使用の喪失、データの喪失、
67  * 利益の喪失、業務の中断も含め、またそれに限定されない)直接損害、
68  * 間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害に
69  * ついて、一切責任を負わないものとします。
70  *
71  ****************************************************************************/
72 
74 
75 #ifndef __FK_IMAGE_HEADER__
76 #define __FK_IMAGE_HEADER__
77 
78 #include <FK/Base.h>
79 #include <FK/Material.h>
80 #include <vector>
81 #include <string>
82 
83 #ifndef FK_DOXYGEN_USER_PROCESS
84 
85 #ifdef NO_GL_LIBRARY
86 typedef unsigned char fk_ImType;
87 typedef unsigned int fk_TexID;
88 #else
89 #include <FK/OpenGL.H>
90 typedef GLubyte fk_ImType;
91 typedef GLuint fk_TexID;
92 #endif
93 
94 
95 enum fk_ImageStatus {
96  FK_IMAGE_OK,
97  FK_IMAGE_OPENERROR,
98  FK_IMAGE_DATAERROR,
99  FK_IMAGE_READERROR
100 };
101 
102 enum fk_ImageFix {
103  FK_FIX_LARGE,
104  FK_FIX_SMALL,
105  FK_FIX_64,
106  FK_FIX_128,
107  FK_FIX_256,
108  FK_FIX_512,
109  FK_FIX_1024,
110  FK_FIX_2048,
111  FK_FIX_4096,
112  FK_FIX_8192,
113  FK_FIX_16384,
114  FK_FIX_32768,
115  FK_FIX_65536
116 };
117 
118 #endif
119 
125 };
126 
134 };
135 
137 
142  public:
143  int w;
144  int h;
145 
147 
151  fk_Dimension(int w = 0, int h = 0);
152 
154  fk_Dimension(const fk_Dimension &);
155 
157 
161  void set(int w, int h);
162 };
163 
165 
171 class fk_Rect {
172  public:
173  int x;
174  int y;
175  int w;
176  int h;
177 
179 
185  fk_Rect(int x = 0, int y = 0, int w = 0, int h = 0);
186 
188  fk_Rect(const fk_Rect &);
189 
191 
197  void set(int x, int y, int w, int h);
198 
200 
204  void setPos(int x, int y);
205 
207 
211  void setSize(int w, int h);
212 
214 
217  fk_Dimension getSize(void);
218 };
219 
221 
235 class fk_Image : public fk_BaseObject {
236 
237  friend class fk_Texture;
238 
239  private:
240 
241  fk_Dimension imageSize, bufSize;
242  std::vector<fk_ImType> imageBuf;
243  fk_ImType *bufPointer;
244  fk_TexID texID;
245  bool initFlag;
246  // テクスチャの部分更新用情報
247  fk_Rect updateRect;
248 
249  unsigned int ChgUInt(fk_ImType *, int) const;
250  unsigned int ChgUShort(fk_ImType *, int) const;
251 
252  int GetOffset(int, int) const;
253  fk_ImType RoundVal(int) const;
254  fk_ImageStatus CreateImg(const std::string);
255  fk_ImageStatus CreateImg(fk_ImType *);
256  void CreateBuffer(bool = true);
257  void CreateBuffer(int, int, bool = true);
258  void CreateBuffer(const fk_Dimension, bool = true);
259  bool IsPixelStatus(int, int) const;
260  int GetOneBufferSize(int, int);
261  int GetFixVal(fk_ImageFix, int) const;
262 
263  void SetLong2Byte(long, fk_ImType *, int);
264  void SetInt2Byte(int, fk_ImType *, int);
265 
266  bool GetInitFlag(void);
267  void SetInitFlag(bool);
268  void SetTexID(const fk_TexID);
269 
270  bool IsBmpFile(const std::string) const;
271  bool IsBmpData(fk_ImType *) const;
272  fk_ImageStatus LoadBmpFile(const std::string);
273  fk_ImageStatus LoadBmpData(fk_ImType *);
274  void SetRGBA4Bmp(int, int, fk_ImType *,
275  int, std::vector<fk_ImType> &);
276 
277  bool GetBmpFileHeader(FILE *, fk_ImType *);
278  bool GetBmpInfoHeader(FILE *, fk_ImType *);
279  fk_Dimension GetBmpSize(fk_ImType *);
280 
281  fk_ImageStatus SaveBmpFile(std::string, bool);
282  void MakeBmpFileHeader(int, int, int,
283  std::vector<fk_ImType> &);
284  void MakeBmpInfoHeader(int, int, int,
285  std::vector<fk_ImType> &);
286  void MakeBmpBuffer(int, int, bool, fk_ImType *);
287 
288  bool IsPngFile(const std::string) const;
289  bool IsPngData(fk_ImType *) const;
290  fk_ImageStatus LoadPngFile(const std::string);
291  fk_ImageStatus LoadPngData(fk_ImType *);
292 
293  public:
294 
296 
300  fk_Image(int w = 0, int h = 0);
301 
303  virtual ~fk_Image();
304 
306  fk_Image(const fk_Image &);
307 
309 
313  void init();
314 
316 
323  bool readBMP(const std::string fileName);
324 
326 
335  bool readBMPData(fk_ImType *buf);
336 
338 
345  bool readPNG(const std::string fileName);
346 
348 
357  bool readPNGData(fk_ImType *buf);
358 
360 
365  bool readJPG(const std::string fileName);
366 
368 
381  bool writeBMP(const std::string fileName,
382  const bool transFlg = false);
383 
385 
394  bool writePNG(const std::string fileName,
395  const bool transFlg = true);
396 
398 
411  bool writeJPG(const std::string fileName,
412  int quality = 80);
413 
415 
426  void newImage(int w, int h, bool initFlg = true);
427 
429 
435  void copyImage(const fk_Image *image);
436 
438 
449  void copyImage(const fk_Image *image, int x, int y);
450 
452 
463  bool subImage(const fk_Image *image,
464  int x, int y, int w, int h);
465 
467 
470  int getWidth(void) const;
471 
473 
476  int getHeight(void) const;
477 
479 
482  const fk_Dimension * getImageSize(void);
483 
485 
507  const fk_Dimension * getBufferSize(void);
508 
510 
520  int getR(int x, int y) const;
521 
523 
533  int getG(int x, int y) const;
534 
536 
546  int getB(int x, int y) const;
547 
549 
559  int getA(int x, int y) const;
560 
562 
572  fk_Color getColor(int x, int y) const;
573 
575 
592  bool setRGBA(int x, int y, int r, int g, int b, int a);
593 
595 
611  bool setRGB(int x, int y, int r, int g, int b);
612 
614 
628  bool setR(int x, int y, int r);
629 
631 
645  bool setG(int x, int y, int g);
646 
648 
662  bool setB(int x, int y, int b);
663 
665 
679  bool setA(int x, int y, int a);
680 
682 
693  bool setColor(int x, int y, const fk_Color &col);
694 
696 
703  void fillColor(const fk_Color &col);
704 
706 
716  void fillColor(int r, int g, int b, int a = 0);
717 
719 
732  const fk_ImType * getBufPointer(void) const;
733 
734 #ifndef FK_DOXYGEN_USER_PROCESS
735 
736  fk_TexID GetTexID(void);
737  void ClearUpdateArea(void);
738  void SetUpdateArea(void);
739  void SetUpdateArea(int, int, int, int);
740  fk_Rect GetUpdateArea(void);
741 
742 #endif
743 
744 };
745 
746 #endif // __FK_IMAGE_HEADER__
int x
領域左上の x 座標
Definition: Image.h:173
virtual ~fk_Image()
デストラクタ
fk_Color getColor(int x, int y) const
ピクセル色要素取得関数
int y
領域左上の y 座標
Definition: Image.h:174
const fk_ImType * getBufPointer(void) const
画像データ配列先頭アドレス取得関数
bool writeBMP(const std::string fileName, const bool transFlg=false)
BMP ファイル出力関数
int getR(int x, int y) const
ピクセルR要素取得関数
bool setA(int x, int y, int a)
ピクセル A 値設定関数
fk_Dimension getSize(void)
領域サイズ参照関数
PNG 形式
Definition: Image.h:123
void newImage(int w, int h, bool initFlg=true)
画像領域生成関数
bool writeJPG(const std::string fileName, int quality=80)
JPEG ファイル出力関数
int h
画像の縦幅
Definition: Image.h:144
fk_SnapProcMode
画像取り込み方法を表す列挙型
Definition: Image.h:128
int getA(int x, int y) const
ピクセルA要素取得関数
int getWidth(void) const
画像横幅取得関数
int w
領域の横幅
Definition: Image.h:175
int w
画像の横幅
Definition: Image.h:143
bool readPNG(const std::string fileName)
PNG ファイル入力関数
RGB色を管理するクラス
Definition: Material.h:92
void setPos(int x, int y)
領域位置設定関数
void setSize(int w, int h)
領域サイズ設定関数
bool writePNG(const std::string fileName, const bool transFlg=true)
PNG ファイル出力関数
Windows Bitmap (BMP) 形式
Definition: Image.h:122
void set(int x, int y, int w, int h)
領域設定関数
OpenGL バックバッファ
Definition: Image.h:130
画像中の矩形領域を表すクラス
Definition: Image.h:171
int getG(int x, int y) const
ピクセルG要素取得関数
fk_Dimension(int w=0, int h=0)
コンストラクタ
void set(int w, int h)
画像サイズ設定関数
FK の各クラスの基盤となる基本クラス
Definition: Base.h:212
テクスチャ用基底クラス
Definition: Texture.h:160
bool readPNGData(fk_ImType *buf)
PNG データ入力用関数
bool subImage(const fk_Image *image, int x, int y, int w, int h)
画像データ部分抽出関数
const fk_Dimension * getImageSize(void)
画像サイズ取得関数
bool setRGBA(int x, int y, int r, int g, int b, int a)
ピクセル RGBA 値設定関数
const fk_Dimension * getBufferSize(void)
画像バッファサイズ取得関数
bool setColor(int x, int y, const fk_Color &col)
ピクセル色値設定関数
fk_ImageType
画像フォーマットを表す列挙型
Definition: Image.h:121
画像を生成、管理するクラス
Definition: Image.h:235
bool setRGB(int x, int y, int r, int g, int b)
ピクセル RGB 値設定関数
bool setR(int x, int y, int r)
ピクセル R 値設定関数
void copyImage(const fk_Image *image)
画像データコピー関数1
JPEG 形式
Definition: Image.h:124
bool readBMPData(fk_ImType *buf)
BMP バッファ入力関数
int h
領域の縦幅
Definition: Image.h:176
画像サイズを表すクラス
Definition: Image.h:141
bool setB(int x, int y, int b)
ピクセル B 値設定関数
fk_Rect(int x=0, int y=0, int w=0, int h=0)
コンストラクタ
void init()
初期化関数
int getHeight(void) const
画像縦幅取得関数
OpenGL フロントバッファ
Definition: Image.h:129
void fillColor(const fk_Color &col)
バッファ全体初期化関数1
bool setG(int x, int y, int g)
ピクセル G 値設定関数
fk_Image(int w=0, int h=0)
コンストラクタ
Win32 GDI (Windows プラットフォームのみ対応)
Definition: Image.h:131
Direct3D フルスクリーンバッファ (Direct3D版のみ対応)
Definition: Image.h:133
Direct3D ウィンドウバッファ (Direct3D版のみ対応)
Definition: Image.h:132
bool readJPG(const std::string fileName)
JPEG ファイル入力関数
int getB(int x, int y) const
ピクセルB要素取得関数
bool readBMP(const std::string fileName)
BMP ファイル入力関数