71 bool Set(
size_t size, LPCVOID pData)
74 const char* contents =
static_cast<const char*
>(pData);
75 const char* lpszText = contents;
78 bool isFinishied =
false;
79 while ( ! isFinishied )
81 const char* p = lpszText;
93 else if ( *p == 0x0D || *p == 0x0A )
108 char c = contents[ind];
109 if ( c ==
'#' || c == 0 )
113 else if ( c < 0x20 && c >
'P' )
119 params.
Add(TParam(ind, len));
122 pa.
SetFromLeft(&contents[params[0].index], params[0].size);
124 if ( pa ==
"P4" && params.
GetSize() >= 2 )
128 if ( (pa ==
"P5" || pa ==
"P6") && params.
GetSize() >= 3 )
134 lpszText += p - lpszText;
146 a.
SetFromLeft(&contents[params[1].index], params[1].size);
147 while ( a.
Replace(
"\t",
" ") != 0 );
148 while ( a.
Replace(
" ",
" ") != 0 );
154 sz.cx = va[0].ToInt();
155 sz.cy = va[1].ToInt();
156 if ( sz.cx == 0 || sz.cy == 0 )
161 if ( pa ==
"P2" || pa ==
"P3" || pa ==
"P5" || pa ==
"P6" )
168 const char * pp = &contents[params[2].index];
171 if ( pa ==
"P1" || pa ==
"P2" || pa ==
"P3" )
174 int ex = (pa ==
"P1") ? 2 : 3;
178 a.
SetFromLeft(&contents[params[i + ex].index], params[i + ex].size);
179 while ( a.
Replace(
"\t",
" ") != 0 );
180 while ( a.
Replace(
" ",
" ") != 0 );
190 if (
size_t(sz.cx * sz.cy) > bm.
GetSize() )
194 m_bmp.
Set(sz.cx, sz.cy, RGB(0, 0, 0));
202 if ( bm[m + x] == 0 )
214 else if ( pa ==
"P2" )
217 if (
size_t(sz.cx * sz.cy) > bm.
GetSize() )
221 m_bmp.
Set(sz.cx, sz.cy, RGB(0, 0, 0));
229 BYTE c =
static_cast<BYTE
>(bm[m + x] * 255 / colorDips);
242 if (
size_t(sz.cx * sz.cy * 3) > bm.
GetSize() )
246 m_bmp.
Set(sz.cx, sz.cy, RGB(0, 0, 0));
251 int m = y * sz.cx * 3;
254 p->rgbRed =
static_cast<BYTE
>(bm[m + x * 3 + 0] * 255 / colorDips);
255 p->rgbGreen =
static_cast<BYTE
>(bm[m + x * 3 + 1] * 255 / colorDips);
256 p->rgbBlue =
static_cast<BYTE
>(bm[m + x * 3 + 2] * 255 / colorDips);
264 else if ( pa ==
"P4" || pa ==
"P5" || pa ==
"P6" )
266 int ex = (pa ==
"P4") ? 1 : 2;
267 const char* q0 = &contents[params[ex].index + params[ex].size];
268 size_t len = size - (params[ex].index + params[ex].size);
269 if ( *q0 == 0x0D || *q0 == 0x0A )
279 const BYTE* q =
reinterpret_cast<const BYTE*
>(q0);
283 if (
size_t(((sz.cx + 7 ) / 8) * sz.cy) > len )
287 m_bmp.
Set(sz.cx, sz.cy, RGB(0, 0, 0));
292 int m = y * ((sz.cx + 7) / 8);
295 if ( (q[m + (x / 8)] &
_BIT(7 - (x & 7))) == 0 )
307 else if ( pa ==
"P5" )
310 if (
size_t(sz.cx * sz.cy) > len )
314 m_bmp.
Set(sz.cx, sz.cy, RGB(0, 0, 0));
322 BYTE c =
static_cast<BYTE
>(q[m + x] * 255 / colorDips);
335 if (
size_t(sz.cx * sz.cy * 3) > len )
339 m_bmp.
Set(sz.cx, sz.cy, RGB(0, 0, 0));
344 int m = y * sz.cx * 3;
347 p->rgbRed =
static_cast<BYTE
>(q[m + x * 3 + 0] * 255 / colorDips);
348 p->rgbGreen =
static_cast<BYTE
>(q[m + x * 3 + 1] * 255 / colorDips);
349 p->rgbBlue =
static_cast<BYTE
>(q[m + x * 3 + 2] * 255 / colorDips);
371 bool Load(LPCTSTR lpszFileName)
374 if ( rr.
Open(lpszFileName) )
396 asz.
Format(
"%d %d\n", sz.cx, sz.cy);
397 if ( lpszComment != NULL )
399 asz.
Format(
"#%s\n%d %d\n",
CAscii(lpszComment), sz.cx, sz.cy);
403 asz.
Format(
"%d %d\n", sz.cx, sz.cy);
417 if ( p->rgbRed < prm )
447 int q = p->rgbRed * prm / 255;
470 int r = p->rgbRed * prm / 255;
471 int g = p->rgbGreen * prm / 255;
472 int b = p->rgbBlue * prm / 255;
497 int yyy = (sz.cx + 7) / 8;
504 BYTE& b = v.
Ref((y * yyy) + (x / 8));
505 if ( p->rgbRed < prm )
507 b |=
_BIT(7 - (x & 7));
511 b &= ~(
_BIT(7 - (x & 7)));
529 int q = p->rgbRed * prm / 255;
530 vb.
Add(
static_cast<BYTE
>(q));
545 int r = p->rgbRed * prm / 255;
546 int g = p->rgbGreen * prm / 255;
547 int b = p->rgbBlue * prm / 255;
548 vb.
Add(
static_cast<BYTE
>(r));
549 vb.
Add(
static_cast<BYTE
>(g));
550 vb.
Add(
static_cast<BYTE
>(b));
571 bool Save(LPCTSTR lpszFileName,
EDescriptor desc, DWORD prm, LPCTSTR lpszComment = NULL)
const
597 TParam(INDEX i = 0,
size_t s = 0) : index(i), size(s)
#define loop(VAR, CNT)
loop構文.
bool IsEmpty(void) const
[確認] Empty状態確認.
RGBQUAD * GetRgbDataPtr(INT_PTR y=-1)
[取得] RGBデータアドレス取得.
CBitmapImage CreateGrayscaleBitmap(void) const
[作成] グレイスケール画像作成.
const SIZE & GetSize(void) const
[取得] イメージサイズ取得.
bool Set(int cx, int cy, COLORREF color=CLR_INVALID)
[設定] イメージ設定.
bool ToHaveRgbData(void)
[設定] RGBデータ準備.
virtual size_t GetSize(void) const
[取得] 要素数取得.
virtual INDEX Add(const TYP &t)
[追加] 要素一つ追加.
bool Open(LPCTSTR lpszName, bool boIsShare=true, bool boDummy=false)
[操作] オープン
static bool NewFile(LPCTSTR lpszFileName, size_t size, LPCVOID P, CFileWriter &fw=CFileWriter())
[保存] ファイル作成.
static CVectorT< CStrT< TYP > > SeparatePeriod(const TYP *lpsz, const TYP *lpszMark, bool isCheckDc=true)
[取得] トークン区切取得
bool IsEmpty(void) const
[確認] 空チェック
const TYP * ReferBuffer(void) const
[取得] バッファ参照.
size_t GetLength(void) const
[取得] 文字列長
static CStrT Fmt(const char *lpszFormat,...)
[作成] 書式付き文字列作成
CStrT & TrimRight(TYP t=' ')
[処理] 末尾から文字をトリム.
CStrT & SetFromLeft(const TYP *lpText, size_t iLen)
[代入] 文字数制限代入.
int Replace(TYP tOld, TYP tNew)
[処理] 文字置換.
void Format(const TYP *lpszFormat,...)
[代入] 書式付き文字列代入.
virtual size_t GetSize(void) const
[取得] サイズ取得
virtual bool SetSize(size_t size)
[操作] サイズ指定
virtual TYP & Ref(INDEX index)
[取得] 要素の参照取得.
virtual size_t AddElements(size_t size, const TYP *P=NULL)
[追加] 複数要素追加.
virtual const TYP * ReferBuffer(void) const
[取得] データアドレス取得
virtual INDEX Add(const TYP &t)
[追加] 要素一つ追加.
int GetCharSize(char c)
[取得] 文字のサイズ(ASCII/SJIS用)
TNB::CStrT< char > CAscii
ASCII文字列クラス
int ToInt(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
void ReadExactly(size_t size, LPVOID _P) const
[取得] 読み込み.