FineKernelToolKit 4.2.13
読み取り中…
検索中…
一致する文字列を見つけられません
Image.h
[詳解]
1#if !defined(__FK_IMAGE_HEADER__)
2#define __FK_IMAGE_HEADER__
3
4#include <FK/Base.h>
5#include <FK/Material.h>
6#include <vector>
7#include <string>
8#include <functional>
9
10#if !defined(FK_DOXYGEN_USER_PROCESS)
11#if defined(NO_GL_LIBRARY)
12using fk_ImType = unsigned char;
13using fk_TexID = unsigned int;
14#else
15#include <FK/OpenGL.hh>
16using fk_ImType = GLubyte;
17using fk_TexID = GLuint;
18#endif
19#endif
20
21namespace FK {
22
23#if !defined(FK_DOXYGEN_USER_PROCESS)
24 enum class fk_ImageStatus {
25 OK,
26 OPENERROR,
27 DATAERROR,
28 READERROR
29 };
30
31 enum class fk_ImageFix {
32 FIX_LARGE,
33 FIX_SMALL,
34 FIX_64,
35 FIX_128,
36 FIX_256,
37 FIX_512,
38 FIX_1024,
39 FIX_2048,
40 FIX_4096,
41 FIX_8192,
42 FIX_16384,
43 FIX_32768,
44 FIX_65536
45 };
46#endif
47
49 enum class fk_ImageType {
50 BMP,
51 PNG,
52 JPG
53 };
54
56 enum class fk_SnapProcMode {
57 FRONT,
58 BACK,
60 };
61
63
68 public:
69 int w;
70 int h;
71
73
77 fk_Dimension(int w = 0, int h = 0);
78
81
84
86 fk_Dimension & operator -(void) const;
88
91
93 bool operator ==(const fk_Dimension &) const;
94
96 bool operator !=(const fk_Dimension &) const;
97
99
107 bool operator >(const fk_Dimension &) const;
108
110
118 bool operator <(const fk_Dimension &) const;
119
121
124 bool operator >=(const fk_Dimension &) const;
125
127
130 bool operator <=(const fk_Dimension &) const;
131
133
136
139
142
145
148
151
153
156
162
164
166
170 void set(int w, int h);
171 };
172
175
178
181
184
187
189
196 class fk_Rect {
197 public:
198 int x;
199 int y;
200 int w;
201 int h;
202
204
210 fk_Rect(int x = 0, int y = 0, int w = 0, int h = 0);
211
213 fk_Rect(const fk_Rect &);
214
216
222 void set(int x, int y, int w, int h);
223
225
229 void setPos(int x, int y);
230
232
236 void setSize(int w, int h);
237
239
243 };
244
246
260 class fk_Image : public fk_BaseObject {
261
262 friend class fk_Texture;
263
264#if !defined(FK_DOXYGEN_USER_PROCESS)
265 class Member {
266 public:
267 fk_Dimension imageSize, bufSize;
268 std::vector<fk_ImType> imageBuf;
269 fk_ImType *bufPointer;
270 fk_TexID texID;
271 bool updateFlg;
272
273 Member(void);
274 };
275#endif
276
277 public:
278
280
284 fk_Image(int w = 0, int h = 0);
285
287 virtual ~fk_Image();
288
291
293
297 void init();
298
300
307 bool readBMP(const std::string fileName);
308
310
319 bool readBMPData(fk_ImType *buf);
320
322
329 bool readPNG(const std::string fileName);
330
332
341 bool readPNGData(fk_ImType *buf);
342
344
351 bool readJPG(const std::string fileName);
352
354
368 bool writeBMP(const std::string fileName, const bool transFlg = false);
369
371
381 bool writePNG(const std::string fileName, const bool transFlg = true);
382
384
398 bool writeJPG(const std::string fileName, int quality = 80);
399
401
412 void newImage(int w, int h, bool initFlg = true);
413
415
421 void copyImage(const fk_Image *image);
422
424
435 void copyImage(const fk_Image *image, int x, int y);
436
438
449 bool subImage(const fk_Image *image, int x, int y, int w, int h);
450
452
455 int getWidth(void) const;
456
458
461 int getHeight(void) const;
462
464
468
470
493
495
506 int getR(int x, int y) const;
507
509
520 int getG(int x, int y) const;
521
523
534 int getB(int x, int y) const;
535
537
548 int getA(int x, int y) const;
549
551
562 fk_Color getColor(int x, int y) const;
563
565
583 bool setRGBA(int x, int y, int r, int g, int b, int a);
584
586
603 bool setRGB(int x, int y, int r, int g, int b);
604
606
620 bool setR(int x, int y, int r);
621
623
637 bool setG(int x, int y, int g);
638
640
654 bool setB(int x, int y, int b);
655
657
671 bool setA(int x, int y, int a);
672
674
685 bool setColor(int x, int y, const fk_Color &col);
686
688
695 void fillColor(const fk_Color &col);
696
698
708 void fillColor(int r, int g, int b, int a = 0);
709
711
724 const fk_ImType * getBufPointer(void) const;
725
726#if !defined(FK_DOXYGEN_USER_PROCESS)
727 fk_TexID GetTexID(void);
728 bool GetUpdate(void);
729 void SetUpdate(bool);
730#endif
731
732 private:
733 std::unique_ptr<Member> _m;
734
735 unsigned int ChgUInt(unsigned char *, int) const;
736 unsigned int ChgUShort(fk_ImType *, int) const;
737
738 int GetOffset(int, int) const;
739 fk_ImType RoundVal(int) const;
740 fk_ImageStatus CreateImg(const std::string);
741 fk_ImageStatus CreateImg(fk_ImType *);
742 void CreateBuffer(bool = true);
743 void CreateBuffer(int, int, bool = true);
744 void CreateBuffer(const fk_Dimension, bool = true);
745 bool IsPixelStatus(int, int) const;
746 int GetOneBufferSize(int, int);
747 int GetFixVal(fk_ImageFix, int) const;
748
749 void SetLong2Byte(long, fk_ImType *, int);
750 void SetInt2Byte(int, fk_ImType *, int);
751
752 void SetTexID(const fk_TexID);
753
754 bool IsBmpFile(const std::string) const;
755 bool IsBmpData(fk_ImType *) const;
756 fk_ImageStatus LoadBmpFile(const std::string);
757 fk_ImageStatus LoadBmpData(fk_ImType *);
758 void SetRGBA4Bmp(int, int, fk_ImType *,
759 int, std::vector<fk_ImType> &);
760
761 bool GetBmpFileHeader(std::ifstream &, fk_ImType *);
762 bool GetBmpInfoHeader(std::ifstream &, fk_ImType *);
763 fk_Dimension GetBmpSize(fk_ImType *);
764
765 fk_ImageStatus SaveBmpFile(std::string, bool);
766 void MakeBmpFileHeader(int, int, int,
767 std::vector<fk_ImType> &);
768 void MakeBmpInfoHeader(int, int, int,
769 std::vector<fk_ImType> &);
770 void MakeBmpBuffer(int, int, bool, fk_ImType *);
771
772 bool IsPngFile(const std::string) const;
773 fk_ImageStatus LoadPngFile(const std::string);
774 fk_ImageStatus LoadPngData(fk_ImType *);
775 void ReleaseTexture(void);
776 };
777}
778#endif // __FK_IMAGE_HEADER__
779
780/****************************************************************************
781 *
782 * Copyright (c) 1999-2024, Fine Kernel Project, All rights reserved.
783 *
784 * Redistribution and use in source and binary forms,
785 * with or without modification, are permitted provided that the
786 * following conditions are met:
787 *
788 * - Redistributions of source code must retain the above
789 * copyright notice, this list of conditions and the
790 * following disclaimer.
791 *
792 * - Redistributions in binary form must reproduce the above
793 * copyright notice, this list of conditions and the
794 * following disclaimer in the documentation and/or
795 * other materials provided with the distribution.
796 *
797 * - Neither the name of the copyright holders nor the names
798 * of its contributors may be used to endorse or promote
799 * products derived from this software without specific
800 * prior written permission.
801 *
802 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
803 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
804 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
805 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
806 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
807 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
808 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
809 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
810 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
811 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
812 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
813 * POSSIBILITY OF SUCH DAMAGE.
814 *
815 ****************************************************************************/
816/****************************************************************************
817 *
818 * Copyright (c) 1999-2024, Fine Kernel Project, All rights reserved.
819 *
820 * 本ソフトウェアおよびソースコードのライセンスは、基本的に
821 * 「修正 BSD ライセンス」に従います。以下にその詳細を記します。
822 *
823 * ソースコード形式かバイナリ形式か、変更するかしないかを問わず、
824 * 以下の条件を満たす場合に限り、再頒布および使用が許可されます。
825 *
826 * - ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、
827 * および下記免責条項を含めること。
828 *
829 * - バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の
830 * 資料に、上記の著作権表示、本条件一覧、および下記免責条項を
831 * 含めること。
832 *
833 * - 書面による特別の許可なしに、本ソフトウェアから派生した製品の
834 * 宣伝または販売促進に、本ソフトウェアの著作権者の名前または
835 * コントリビューターの名前を使用してはならない。
836 *
837 * 本ソフトウェアは、著作権者およびコントリビューターによって「現
838 * 状のまま」提供されており、明示黙示を問わず、商業的な使用可能性、
839 * および特定の目的に対する適合性に関す暗黙の保証も含め、またそれ
840 * に限定されない、いかなる保証もないものとします。著作権者もコン
841 * トリビューターも、事由のいかんを問わず、損害発生の原因いかんを
842 * 問わず、かつ責任の根拠が契約であるか厳格責任であるか(過失その
843 * 他の)不法行為であるかを問わず、仮にそのような損害が発生する可
844 * 能性を知らされていたとしても、本ソフトウェアの使用によって発生
845 * した(代替品または代用サービスの調達、使用の喪失、データの喪失、
846 * 利益の喪失、業務の中断も含め、またそれに限定されない)直接損害、
847 * 間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害に
848 * ついて、一切責任を負わないものとします。
849 *
850 ****************************************************************************/
FK の各クラスの基盤となる基本クラス
Definition Base.h:113
RGB色を管理するクラス
Definition Color.h:21
画像サイズを表すクラス
Definition Image.h:67
fk_Dimension & operator*=(int)
実数積代入演算子
void set(int w, int h)
画像サイズ設定関数
friend fk_Dimension operator/(const fk_Dimension &, int)
整数値ベクトル商演算二項演算子
friend fk_Dimension operator+(const fk_Dimension &, const fk_Dimension &)
整数値ベクトル和二項演算子
fk_Dimension & operator=(const fk_Dimension &)
単純代入演算子
fk_Dimension(int w=0, int h=0)
コンストラクタ
int w
画像の横幅
Definition Image.h:69
bool operator>=(const fk_Dimension &) const
等価右不等号演算子
bool operator<=(const fk_Dimension &) const
等価左不等号演算子
int h
画像の縦幅
Definition Image.h:70
friend fk_Dimension operator*(const fk_Dimension &, int)
整数値ベクトル倍演算二項演算子1
bool operator==(const fk_Dimension &) const
同値比較演算子
bool operator>(const fk_Dimension &) const
右不等号演算子
fk_Dimension(const fk_Dimension &)
コピーコンストラクタ
bool operator!=(const fk_Dimension &) const
異値比較演算子
fk_Dimension & operator-(void) const
単項マイナス演算子
fk_Dimension & operator-=(const fk_Dimension &)
単項差代入演算子
fk_Dimension & operator/=(int)
実数商代入演算子
bool operator<(const fk_Dimension &) const
左不等号演算子
fk_Dimension & operator+=(const fk_Dimension &)
単項和代入演算子
画像を生成、管理するクラス
Definition Image.h:260
void copyImage(const fk_Image *image)
画像データコピー関数1
int getA(int x, int y) const
ピクセルA要素取得関数
bool writeJPG(const std::string fileName, int quality=80)
JPEG ファイル出力関数
bool setG(int x, int y, int g)
ピクセル G 値設定関数
const fk_ImType * getBufPointer(void) const
画像データ配列先頭アドレス取得関数
bool writeBMP(const std::string fileName, const bool transFlg=false)
BMP ファイル出力関数
bool subImage(const fk_Image *image, int x, int y, int w, int h)
画像データ部分抽出関数
bool setRGB(int x, int y, int r, int g, int b)
ピクセル RGB 値設定関数
void init()
初期化関数
void newImage(int w, int h, bool initFlg=true)
画像領域生成関数
fk_Image(const fk_Image &)
コピーコンストラクタ
void fillColor(const fk_Color &col)
バッファ全体初期化関数1
bool readPNGData(fk_ImType *buf)
PNG データ入力用関数
bool readBMPData(fk_ImType *buf)
BMP バッファ入力関数
bool setR(int x, int y, int r)
ピクセル R 値設定関数
int getR(int x, int y) const
ピクセルR要素取得関数
fk_Image(int w=0, int h=0)
コンストラクタ
bool setB(int x, int y, int b)
ピクセル B 値設定関数
void fillColor(int r, int g, int b, int a=0)
バッファ全体初期化関数2
bool readPNG(const std::string fileName)
PNG ファイル入力関数
bool setA(int x, int y, int a)
ピクセル A 値設定関数
bool setColor(int x, int y, const fk_Color &col)
ピクセル色値設定関数
fk_Color getColor(int x, int y) const
ピクセル色要素取得関数
const fk_Dimension * getBufferSize(void)
画像バッファサイズ取得関数
int getWidth(void) const
画像横幅取得関数
const fk_Dimension * getImageSize(void)
画像サイズ取得関数
int getG(int x, int y) const
ピクセルG要素取得関数
void copyImage(const fk_Image *image, int x, int y)
画像データコピー関数2
bool readJPG(const std::string fileName)
JPEG ファイル入力関数
bool writePNG(const std::string fileName, const bool transFlg=true)
PNG ファイル出力関数
int getB(int x, int y) const
ピクセルB要素取得関数
int getHeight(void) const
画像縦幅取得関数
bool setRGBA(int x, int y, int r, int g, int b, int a)
ピクセル RGBA 値設定関数
bool readBMP(const std::string fileName)
BMP ファイル入力関数
virtual ~fk_Image()
デストラクタ
画像中の矩形領域を表すクラス
Definition Image.h:196
fk_Rect(const fk_Rect &)
コピーコンストラクタ
void set(int x, int y, int w, int h)
領域設定関数
int y
領域左上の y 座標
Definition Image.h:199
int h
領域の縦幅
Definition Image.h:201
int w
領域の横幅
Definition Image.h:200
fk_Dimension getSize(void)
領域サイズ参照関数
void setSize(int w, int h)
領域サイズ設定関数
fk_Rect(int x=0, int y=0, int w=0, int h=0)
コンストラクタ
void setPos(int x, int y)
領域位置設定関数
int x
領域左上の x 座標
Definition Image.h:198
テクスチャ用基底クラス
Definition Texture.h:45
Fine Kernel Toolkit 名前空間
Definition Angle.h:6
fk_Color operator+(const fk_Color &, const fk_Color &)
色要素和二項演算子
fk_Color operator/(const fk_Color &, double)
実数商二項演算子
@ BACK
目標ノードから開始
fk_SnapProcMode
画像取り込み方法を表す列挙型
Definition Image.h:56
@ WIN32_GDI
Win32 GDI (Windows プラットフォームのみ対応)
@ FRONT
OpenGL フロントバッファ
fk_ImageType
画像フォーマットを表す列挙型
Definition Image.h:49
@ PNG
PNG 形式
@ JPG
JPEG 形式
@ BMP
Windows Bitmap (BMP) 形式
fk_Color operator-(const fk_Color &, const fk_Color &)
色要素差二項演算子
fk_Color operator*(const fk_Color &, double)
実数倍二項演算子1