summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2BitImage.cpp
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2023-07-01 02:43:29 +0100
committerAsh Wolf <ninji@wuffs.org>2023-07-01 02:43:29 +0100
commit5c6a48b2ff362a70416a6a00fda7d06e0f276f2d (patch)
tree62cf542c68d91aa6f7a4e3bfa9eddca4ab352970 /src/T2DLL/T2BitImage.cpp
parentc0c336500955a23e344651e5412c9d9d441ef4ee (diff)
downloadt2win-5c6a48b2ff362a70416a6a00fda7d06e0f276f2d.tar.gz
t2win-5c6a48b2ff362a70416a6a00fda7d06e0f276f2d.zip
i am in hell
Diffstat (limited to '')
-rw-r--r--src/T2DLL/T2BitImage.cpp98
1 files changed, 57 insertions, 41 deletions
diff --git a/src/T2DLL/T2BitImage.cpp b/src/T2DLL/T2BitImage.cpp
index ea00253..93bd6f8 100644
--- a/src/T2DLL/T2BitImage.cpp
+++ b/src/T2DLL/T2BitImage.cpp
@@ -1,6 +1,12 @@
#include "GlobalFunc.h"
#include "T2BitImage.h"
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
#define ALIGN_ROW_SIZE(s) ((((s) + 3) / 4) * 4)
T2BitImage::T2BitImage(const char* path, unsigned int id, BOOL flip) {
@@ -12,15 +18,15 @@ T2BitImage::T2BitImage(const char* path, unsigned int id, BOOL flip) {
CString idStr;
idStr.Format("%d", id);
- CString err = "T2BitImage::T2BitImage ERROR : " + idStr + " @" + path + "\n";
- OutputDebugString(err);
+ CString error = "T2BitImage::T2BitImage ERROR : " + idStr + " @" + path + "\n";
+ OutputDebugString(error);
throw 0;
}
- void *data = malloc(fsEntry.spfse_mC);
- file->Read(data, fsEntry.spfse_mC);
- SetupBitmap((BITMAPINFO *) data, flip);
- free(data);
+ void *buffer = malloc(fsEntry.spfse_mC);
+ file->Read(buffer, fsEntry.spfse_mC);
+ SetupBitmap((BITMAPINFO *) buffer, flip);
+ free(buffer);
file->Close();
delete file;
@@ -29,21 +35,21 @@ T2BitImage::T2BitImage(const char* path, unsigned int id, BOOL flip) {
T2BitImage::T2BitImage(HINSTANCE instance, unsigned int id, BOOL flip) {
mMemHandle = NULL;
- HRSRC rsrc = FindResource(instance, MAKEINTRESOURCE(id), MAKEINTRESOURCE(2));
- if (!rsrc) {
+ HRSRC theRsrc = FindResource(instance, MAKEINTRESOURCE(id), MAKEINTRESOURCE(2));
+ if (!theRsrc) {
CString idStr;
idStr.Format("%d", id);
- CString err = "T2BitImage::T2BitImage ERROR : " + idStr + " @" + GetModuleName(instance) + "\n";
- OutputDebugString(err);
+ CString error = "T2BitImage::T2BitImage ERROR : " + idStr + " @" + GetModuleName(instance) + "\n";
+ OutputDebugString(error);
throw 0;
}
- HGLOBAL h = LoadResource(instance, rsrc);
- void *data = LockResource(h);
- SetupBitmap((BITMAPINFO *) data, flip);
- UnlockResource(h);
- FreeResource(rsrc);
+ HGLOBAL theHandle = LoadResource(instance, theRsrc);
+ void *buffer = LockResource(theHandle);
+ SetupBitmap((BITMAPINFO *) buffer, flip);
+ UnlockResource(theHandle);
+ FreeResource(theHandle);
}
void T2BitImage::SetupBitmap(BITMAPINFO* info, BOOL flip) {
@@ -63,13 +69,13 @@ void T2BitImage::SetupBitmap(BITMAPINFO* info, BOOL flip) {
memcpy(mData, info->bmiColors + colorCount, dataSize);
if (flip) {
- int rowSize = ALIGN_ROW_SIZE(mBitmap.header.biWidth);
- void *tmp = malloc(rowSize);
+ int stride = ALIGN_ROW_SIZE(mBitmap.header.biWidth);
+ void *tmp = malloc(stride);
for (int y = 0; y < mBitmap.header.biHeight / 2; y++) {
int otherY = mBitmap.header.biHeight - y - 1;
- memcpy(tmp, mData + y * rowSize, rowSize);
- memcpy(mData + y * rowSize, mData + otherY * rowSize, rowSize);
- memcpy(mData + otherY * rowSize, tmp, rowSize);
+ memcpy(tmp, mData + y * stride, stride);
+ memcpy(mData + y * stride, mData + otherY * stride, stride);
+ memcpy(mData + otherY * stride, tmp, stride);
}
free(tmp);
}
@@ -83,16 +89,16 @@ void T2BitImage::SetupBitmap(BITMAPINFO* info, BOOL flip) {
}
T2BitImage::T2BitImage(const RECT& rect) {
- int w = rect.right - rect.left;
- int h = rect.bottom - rect.top;
+ int theRectW = rect.right - rect.left;
+ int theRectH = rect.bottom - rect.top;
memset(&mBitmap.header, 0, sizeof(mBitmap.header));
mBitmap.header.biSize = sizeof(mBitmap.header);
- mBitmap.header.biWidth = w;
- mBitmap.header.biHeight = h;
+ mBitmap.header.biWidth = theRectW;
+ mBitmap.header.biHeight = theRectH;
mBitmap.header.biPlanes = 1;
mBitmap.header.biBitCount = 8;
- mBitmap.header.biSizeImage = ALIGN_ROW_SIZE(w) * h;
+ mBitmap.header.biSizeImage = ALIGN_ROW_SIZE(theRectW) * theRectH;
mBitmap.header.biClrUsed = 256;
for (int i = 0; i < 256; i++)
@@ -124,6 +130,7 @@ void T2BitImage::EndDrawing() {
}
void T2BitImage::CopyImage(T2BitImage& destImg, const RECT& inSrc, const RECT& inDest, int, CRgn* rgn) {
+#pragma var_order(rect2, backGndColor, yAdjust, foreGndColor, clipDest, width, destY, clipSrc, destX, xAdjust, halftoneMode, height, srcX, dest, destRowSize, srcY, align, srcP, destP, srcRowSize, src)
RECT src;
src.top = inSrc.top;
src.left = inSrc.left;
@@ -158,7 +165,9 @@ void T2BitImage::CopyImage(T2BitImage& destImg, const RECT& inSrc, const RECT& i
align = 16; // Y scale *4
} else {
CString err;
- err.Format("sȊgk\nSrc(%d,%d),Dest(%d,%d)", dest.top, dest.bottom, src.top, src.bottom);
+ // "不正な拡大縮小率\nSrc(%d,%d),Dest(%d,%d)"
+ // Incorrect scaling factor
+ err.Format("\x95\x73\x90\xB3\x82\xC8\x8A\x67\x91\xE5\x8F\x6B\x8F\xAC\x97\xA6\n\x53\x72\x63\x28\x25\x64\x2C\x25\x64\x29\x2C\x44\x65\x73\x74\x28\x25\x64\x2C\x25\x64\x29", dest.top, dest.bottom, src.top, src.bottom);
#line 183
__Rep0(__FILE__, __LINE__, err);
}
@@ -168,7 +177,9 @@ void T2BitImage::CopyImage(T2BitImage& destImg, const RECT& inSrc, const RECT& i
((src.bottom - src.top) != (((dest.bottom - dest.top) * align) / 4))
) {
CString err;
- err.Format("sȊgk\nSrc(%d,%d),Dest(%d,%d)", dest.top, dest.bottom, src.top, src.bottom);
+ // "不正な拡大縮小率\nSrc(%d,%d),Dest(%d,%d)"
+ // Incorrect scaling factor
+ err.Format("\x95\x73\x90\xB3\x82\xC8\x8A\x67\x91\xE5\x8F\x6B\x8F\xAC\x97\xA6\n\x53\x72\x63\x28\x25\x64\x2C\x25\x64\x29\x2C\x44\x65\x73\x74\x28\x25\x64\x2C\x25\x64\x29", dest.top, dest.bottom, src.top, src.bottom);
#line 190
__Rep0(__FILE__, __LINE__, err);
}
@@ -402,7 +413,7 @@ void T2BitImage::CopyImage(T2BitImage& destImg, const RECT& inSrc, const RECT& i
jle simple8_rowDone
mov al, [esi]
mov [edi], al
- add esi, 4
+ add esi, 2
inc edi
dec edx
jmp simple8_innerLoop
@@ -863,6 +874,7 @@ void T2BitImage::CopyImage(T2BitImage& destImg, const RECT& inSrc, const RECT& i
}
void T2BitImage::CopyImage(CDC* dc, const RECT& inSrc, const RECT& inDest, int, CRgn*) {
+#pragma var_order(tmp, bmp, dest, diffY, diffX, src)
RECT src;
src.top = inSrc.top;
src.left = inSrc.left;
@@ -886,8 +898,8 @@ void T2BitImage::CopyImage(CDC* dc, const RECT& inSrc, const RECT& inDest, int,
RECT tmp;
tmp.top = 0;
tmp.left = 0;
- tmp.right = mBitmap.header.biWidth;
tmp.bottom = mBitmap.header.biHeight;
+ tmp.right = mBitmap.header.biWidth;
if (tmp.top > tmp.bottom) {
int save = tmp.top;
@@ -994,6 +1006,7 @@ void T2BitImage::DrawFocusLine(int x1, int y1, int x2, int y2) {
y2 = tmp;
}
+#pragma var_order(p, rowSize, counter)
int rowSize = ALIGN_ROW_SIZE(mBitmap.header.biWidth);
int counter = 0;
unsigned char *p = mData + y1 * rowSize + x1;
@@ -1033,6 +1046,7 @@ void T2BitImage::FillMesh(RECT rect, int c) {
IntersectRect(&rect, &rect, &bitmapRect);
if (!IsRectEmpty(&rect)) {
+#pragma var_order(cByte, width, rowSize, p, height, parity)
unsigned char parity = rect.left + rect.top;
int rowSize = ALIGN_ROW_SIZE(mBitmap.header.biWidth);
unsigned char *p = mData + rect.top * rowSize + rect.left;
@@ -1085,6 +1099,7 @@ void T2BitImage::FillRect(RECT rect, int c) {
IntersectRect(&rect, &rect, &bitmapRect);
if (!IsRectEmpty(&rect)) {
+#pragma var_order(cByte, width, rowSize, p, height)
int rowSize = ALIGN_ROW_SIZE(mBitmap.header.biWidth);
unsigned char *p = mData + rect.top * rowSize + rect.left;
int width = rect.right - rect.left;
@@ -1136,7 +1151,7 @@ int T2BitImage::GetPixel(const POINT& pt) {
void T2BitImage::DrawFrameRect(RECT rect, int c) {
OffsetRect(&rect, -mOrigin.x, -mOrigin.y);
- RECT bitmapRect;
+ RECT intersectRect, bitmapRect;
SetRect(&bitmapRect, 0, 0, mBitmap.header.biWidth, mBitmap.header.biHeight);
if (mHasClipRect) {
@@ -1145,17 +1160,16 @@ void T2BitImage::DrawFrameRect(RECT rect, int c) {
IntersectRect(&bitmapRect, &bitmapRect, &clipRect);
}
- RECT frameRect;
- IntersectRect(&frameRect, &rect, &bitmapRect);
- if (!IsRectEmpty(&frameRect)) {
- if (frameRect.top == rect.top)
- DrawFrameLine(frameRect.left, frameRect.top, frameRect.right, frameRect.top, c);
- if (frameRect.left == rect.left)
- DrawFrameLine(frameRect.left, frameRect.top, frameRect.left, frameRect.bottom, c);
- if (frameRect.bottom == rect.bottom)
- DrawFrameLine(frameRect.left, frameRect.bottom - 1, frameRect.right, frameRect.bottom - 1, c);
- if (frameRect.right == rect.right)
- DrawFrameLine(frameRect.right - 1, frameRect.top, frameRect.right - 1, frameRect.bottom, c);
+ IntersectRect(&intersectRect, &rect, &bitmapRect);
+ if (!IsRectEmpty(&intersectRect)) {
+ if (intersectRect.top == rect.top)
+ DrawFrameLine(intersectRect.left, intersectRect.top, intersectRect.right, intersectRect.top, c);
+ if (intersectRect.left == rect.left)
+ DrawFrameLine(intersectRect.left, intersectRect.top, intersectRect.left, intersectRect.bottom, c);
+ if (intersectRect.bottom == rect.bottom)
+ DrawFrameLine(intersectRect.left, intersectRect.bottom - 1, intersectRect.right, intersectRect.bottom - 1, c);
+ if (intersectRect.right == rect.right)
+ DrawFrameLine(intersectRect.right - 1, intersectRect.top, intersectRect.right - 1, intersectRect.bottom, c);
}
}
@@ -1168,6 +1182,7 @@ void T2BitImage::DrawFrameLine(int x1, int y1, int x2, int y2, int c) {
y2 = tmp;
}
+#pragma var_order(cByte, rowSize, p, count)
int rowSize = ALIGN_ROW_SIZE(mBitmap.header.biWidth);
unsigned char *p = mData + y1 * rowSize + x1;
int count = y2 - y1;
@@ -1199,6 +1214,7 @@ void T2BitImage::DrawFrameLine(int x1, int y1, int x2, int y2, int c) {
x2 = tmp;
}
+#pragma var_order(cByte, count, rowSize, p)
int rowSize = ALIGN_ROW_SIZE(mBitmap.header.biWidth);
unsigned char *p = mData + y1 * rowSize + x1;
int count = x2 - x1;