| 1 |
#ifndef CPIXELBIT_H_INCLUDED |
| 2 |
#define CPIXELBIT_H_INCLUDED |
| 3 |
|
| 4 |
#include <windows.h> |
| 5 |
|
| 6 |
//#define ENABLE_SPECIFIC_STAMP // 特殊スタンプを使う |
| 7 |
//#define ENABLE_RECT_BOUNDARY // 領域制限を使う |
| 8 |
|
| 9 |
/* |
| 10 |
* DIB ビットマップ管理クラス |
| 11 |
*/ |
| 12 |
class CPixelbit{ |
| 13 |
private: |
| 14 |
static HMODULE ms_hMSIMG32; |
| 15 |
static BOOL (WINAPI *ms_TransBlt)(HDC, int, int, int, int, HDC, int, int, int, int, UINT); |
| 16 |
int m_Width; // 幅 |
| 17 |
int m_Height; // 高さ |
| 18 |
#ifdef ENABLE_RECT_BOUNDARY |
| 19 |
int m_BoundLeft; // 描画制限領域左 X (内) |
| 20 |
int m_BoundTop; // 描画制限領域上 Y (内) |
| 21 |
int m_BoundRight; // 描画制限領域右 X (外) |
| 22 |
int m_BoundBottom; // 描画制限領域下 Y (外) |
| 23 |
#endif |
| 24 |
DWORD m_BitsPerPixel; // ピクセル当たりビット数 |
| 25 |
DWORD m_BytesPerPixel; // ピクセル当たりバイト数 |
| 26 |
DWORD m_BytesPerLine; // 1行あたりバイト数 |
| 27 |
DWORD m_DwordsPerLine; // 1行あたりDWORD数 |
| 28 |
DWORD m_ColorKey; // 透過色 |
| 29 |
HBITMAP m_BmpHnd; // ビットマップハンドル |
| 30 |
HBITMAP m_BmpHndOld; // ビットマップハンドル |
| 31 |
HDC m_BmpHdc; // デバイスコンテキスト |
| 32 |
BITMAPINFO m_BmpInfo; // ビットマップヘッダ |
| 33 |
PDWORD m_PixelAdr; // 画像データのアドレス |
| 34 |
public: |
| 35 |
static BOOL InitExtFunc(); |
| 36 |
static void FreeExtFunc(); |
| 37 |
CPixelbit(); |
| 38 |
CPixelbit(int, int); |
| 39 |
~CPixelbit(); |
| 40 |
|
| 41 |
LPBITMAPINFO GetBmpInfo(){ return &m_BmpInfo; } |
| 42 |
|
| 43 |
BOOL Clear(int w, int h, int sbit = 32); |
| 44 |
int Load(char *); |
| 45 |
BOOL Save(char *, int); |
| 46 |
int PasteFromClipboard(HWND); |
| 47 |
BOOL CopyToClipboard(HWND, int); |
| 48 |
BOOL Assign(PBYTE); |
| 49 |
void Set4PAL1(int, int, PBYTE); |
| 50 |
void Set4PAL4(int, int, PBYTE); |
| 51 |
void Set4PAL8(int, int, PBYTE); |
| 52 |
void Set4BGR24(int, int, PBYTE); |
| 53 |
void Set4BGR32(int, int, PBYTE); |
| 54 |
void PrepareDIB(PBYTE, int, int); |
| 55 |
|
| 56 |
// CPixelbitPNG.cpp |
| 57 |
int LoadPNG(char *, double *, bool *); |
| 58 |
BOOL SavePNG(char *, int, double); |
| 59 |
|
| 60 |
// inline |
| 61 |
DWORD GetBytesPerPixel() const { return m_BytesPerPixel; } |
| 62 |
DWORD GetBytesPerLine() const { return m_BytesPerLine; } |
| 63 |
int GetWidth() const { return m_Width; } |
| 64 |
int GetHeight() const { return m_Height; } |
| 65 |
int Index(int x, int y) const { return x+y*m_Width; } // for 32bit only |
| 66 |
HDC GetHDC(){ return m_BmpHdc; } |
| 67 |
BOOL CheckSize(CPixelbit *img){ |
| 68 |
return m_Width==img->m_Width && m_Height==img->m_Height; |
| 69 |
} |
| 70 |
BOOL CheckSize(int w, int h){ |
| 71 |
return m_Width==w && m_Height==h; |
| 72 |
} |
| 73 |
BOOL CheckRect(int x, int y){ |
| 74 |
return 0<=x && x<m_Width && 0<=y && y<m_Height; |
| 75 |
} |
| 76 |
DWORD GetPixel(int x, int y){ // for 32bit only |
| 77 |
return m_PixelAdr[Index(x, y)]; |
| 78 |
} |
| 79 |
void SetPixel(int x, int y, DWORD color){ // for 32bit only |
| 80 |
m_PixelAdr[Index(x, y)] = color; |
| 81 |
} |
| 82 |
PBYTE GetByteAdr(int x, int y){ // for 32bit only |
| 83 |
return (PBYTE)(&m_PixelAdr[Index(x, y)]); |
| 84 |
} |
| 85 |
PDWORD GetScanLine(int y){ |
| 86 |
return m_PixelAdr+m_DwordsPerLine*y; |
| 87 |
} |
| 88 |
DWORD GetColorKey(){ |
| 89 |
return m_ColorKey; |
| 90 |
} |
| 91 |
void SetColorKey(DWORD col){ |
| 92 |
m_ColorKey = col; |
| 93 |
} |
| 94 |
|
| 95 |
// CPixelbitStamp.cpp |
| 96 |
#ifdef ENABLE_RECT_BOUNDARY |
| 97 |
void ResetBoundary(); |
| 98 |
void SetBoundary(int, int, int, int); |
| 99 |
#endif |
| 100 |
void ResetAlphaChannel(BYTE); |
| 101 |
BOOL FixLocation(CPixelbit *, int *, int *, int *, int *, int *, int *); |
| 102 |
BOOL WindowStamp(HDC hdcDst, int, int, int, int, int, int); |
| 103 |
BOOL PlainStamp(CPixelbit *, int, int, int, int, int, int); |
| 104 |
BOOL PlainStamp32(CPixelbit *, int, int, int, int, int, int); |
| 105 |
BOOL AlphaBlendStamp(CPixelbit *, int, int, int, int, int, int); |
| 106 |
BOOL StretchStamp(CPixelbit *, int, int, int, int, int, int, int, int, int); |
| 107 |
BOOL BilinearStamp(CPixelbit *, int, int, int, int, int, int, int, int); |
| 108 |
BOOL NearestStamp(CPixelbit *, int, int, int, int, int, int, int, int); |
| 109 |
#ifdef ENABLE_SPECIFIC_STAMP |
| 110 |
BOOL DarkStamp(CPixelbit *, int, int, int, int, int, int); |
| 111 |
BOOL LightStamp(CPixelbit *, int, int, int, int, int, int); |
| 112 |
BOOL HalfStamp(CPixelbit *, int, int, int, int, int, int); |
| 113 |
BOOL DarkHalfStamp(CPixelbit *, int, int, int, int, int, int); |
| 114 |
BOOL LightHalfStamp(CPixelbit *, int, int, int, int, int, int); |
| 115 |
BOOL RedStamp(CPixelbit *, int, int, int, int, int, int); |
| 116 |
BOOL GreenStamp(CPixelbit *, int, int, int, int, int, int); |
| 117 |
BOOL BlueStamp(CPixelbit *, int, int, int, int, int, int); |
| 118 |
BOOL ColorStamp(CPixelbit *, int, int, int, int, int, int, DWORD); |
| 119 |
BOOL AlphaStamp(CPixelbit *, int, int, int, int, int, int, int); |
| 120 |
BOOL AlphaColorStamp(CPixelbit *, int, int, int, int, int, int, DWORD, int); |
| 121 |
BOOL AddStamp(CPixelbit *, int, int, int, int, int, int, int); |
| 122 |
BOOL AddColorStamp(CPixelbit *, int, int, int, int, int, int, DWORD, int); |
| 123 |
BOOL SubStamp(CPixelbit *, int, int, int, int, int, int, int); |
| 124 |
BOOL SubColorStamp(CPixelbit *, int, int, int, int, int, int, DWORD, int); |
| 125 |
#endif |
| 126 |
|
| 127 |
// CPixelbitDraw.cpp |
| 128 |
void DrawRect(int, int, int, int, DWORD); |
| 129 |
void FillRect(int, int, int, int, DWORD); |
| 130 |
void DrawLine(int, int, int, int, DWORD); |
| 131 |
void BoldLine(int, int, int, int, DWORD); |
| 132 |
BOOL CreateAAText(int, int, char *, HFONT, DWORD, int); |
| 133 |
void GradRectH(int, int, int, int, DWORD, DWORD); |
| 134 |
void GradRectV(int, int, int, int, DWORD, DWORD); |
| 135 |
|
| 136 |
// CPixelbitEffect.cpp |
| 137 |
void Nega(); |
| 138 |
void Monotone(DWORD); |
| 139 |
void Darkness(int); |
| 140 |
void Lightness(int); |
| 141 |
|
| 142 |
// CPixelbitCrypt.cpp |
| 143 |
static unsigned int EncodePassword(char *); |
| 144 |
void Encode(char *); |
| 145 |
void Decode(char *); |
| 146 |
}; |
| 147 |
|
| 148 |
// 関数宣言 |
| 149 |
POINT MakePoint(int, int); |
| 150 |
RECT MakeRect(int, int, int, int); |
| 151 |
void RGBtoHSV(BYTE, BYTE, BYTE, int *, int *, int *); |
| 152 |
|
| 153 |
/* |
| 154 |
* 輝度値をk 0〜255 で丸める |
| 155 |
*/ |
| 156 |
inline BYTE FixCV(int v){ return v<0 ? 0 : (v>255 ? 255 : v); } |
| 157 |
|
| 158 |
/* |
| 159 |
* DWORD に RGB をまとめる |
| 160 |
* |
| 161 |
* 戻り値: 色 |
| 162 |
*/ |
| 163 |
inline DWORD MakePixel( |
| 164 |
BYTE r, BYTE g, BYTE b // RGB 色 |
| 165 |
){ |
| 166 |
return (r<<16)|(g<<8)|b; |
| 167 |
} |
| 168 |
|
| 169 |
/* |
| 170 |
* DWORD に RGB をまとめる |
| 171 |
* |
| 172 |
* 戻り値: 色 |
| 173 |
*/ |
| 174 |
inline DWORD MakePixelA( |
| 175 |
BYTE a, BYTE r, BYTE g, BYTE b // RGB 色 |
| 176 |
){ |
| 177 |
return (a<<24)|(r<<16)|(g<<8)|b; |
| 178 |
} |
| 179 |
|
| 180 |
/* |
| 181 |
* R と B を入れ替える |
| 182 |
* |
| 183 |
* 戻り値: 色 |
| 184 |
*/ |
| 185 |
inline DWORD RGBtoBGR( |
| 186 |
DWORD c // 色 |
| 187 |
){ |
| 188 |
return (c&0xff00ff00)|((c&0x00ff0000)>>16)|((c&0x000000ff)<<16); |
| 189 |
} |
| 190 |
|
| 191 |
/* |
| 192 |
* DWORD を RGB に分解 |
| 193 |
*/ |
| 194 |
inline void SplitColor( |
| 195 |
DWORD c, // 分解する色 |
| 196 |
int *r, int *g, int *b // 代入先 |
| 197 |
){ |
| 198 |
*r = (c&0x00ff0000)>>16; |
| 199 |
*g = (c&0x0000ff00)>>8; |
| 200 |
*b = c&0x000000ff; |
| 201 |
} |
| 202 |
|
| 203 |
/* |
| 204 |
* DWORD を ARGB に分解 |
| 205 |
*/ |
| 206 |
inline void SplitColorA( |
| 207 |
DWORD c, // 分解する色 |
| 208 |
int *a, int *r, int *g, int *b // 代入先 |
| 209 |
){ |
| 210 |
*a = (c&0xff000000)>>24; |
| 211 |
*r = (c&0x00ff0000)>>16; |
| 212 |
*g = (c&0x0000ff00)>>8; |
| 213 |
*b = c&0x000000ff; |
| 214 |
} |
| 215 |
|
| 216 |
/* |
| 217 |
* RGB を Y に変換 (RGB 入力) |
| 218 |
* |
| 219 |
* 戻り値: Y 値 |
| 220 |
*/ |
| 221 |
inline int BlackScale(BYTE r, BYTE g, BYTE b){ |
| 222 |
return (int)(r*0.298912f+g*0.586610f+b*0.114478f); |
| 223 |
} |
| 224 |
|
| 225 |
/* |
| 226 |
* RGB を Y に変換 (DWORD 入力) |
| 227 |
* |
| 228 |
* 戻り値: Y 値 |
| 229 |
*/ |
| 230 |
inline int BlackScale(DWORD c){ |
| 231 |
return (int)(((c&0x00ff0000)>>16)*0.298912f |
| 232 |
+((c&0x0000ff00)>>8)*0.586610f+(c&0x000000ff)*0.114478f); |
| 233 |
} |
| 234 |
|
| 235 |
/* |
| 236 |
* RGB を Y に変換 |
| 237 |
* |
| 238 |
* 戻り値: Y 値 (最大値 256) |
| 239 |
*/ |
| 240 |
inline int BlackScale256(DWORD c){ |
| 241 |
return (int)(((c&0x00ff0000)>>16)*0.300084f |
| 242 |
+((c&0x0000ff00)>>8)*0.5889104f+(c&0x000000ff)*0.114927f); |
| 243 |
} |
| 244 |
|
| 245 |
#ifndef ENABLE_RECT_BOUNDARY |
| 246 |
#define m_BoundLeft 0 |
| 247 |
#define m_BoundTop 0 |
| 248 |
#define m_BoundRight m_Width |
| 249 |
#define m_BoundBottom m_Height |
| 250 |
#endif |
| 251 |
|
| 252 |
#endif |