Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually translated comments #242

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 24 additions & 39 deletions src/engine/N3Base/BitMapFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,50 +21,43 @@ CBitMapFile::~CBitMapFile() {
void CBitMapFile::Release() {
memset(&m_bmfHeader, 0, sizeof(m_bmfHeader));
memset(&m_bmInfoHeader, 0, sizeof(m_bmInfoHeader));
::GlobalFree(m_pPixels); // ���� �ȼ� ������
::GlobalFree(m_pPixels);
m_pPixels = NULL;
}

bool CBitMapFile::Load(HANDLE hFile) {
this->Release(); // �ϴ� �� �����ϰ�..
this->Release();

DWORD dwRWC = 0;

// ���� ��� �б�
ReadFile(hFile, &m_bmfHeader, sizeof(m_bmfHeader), &dwRWC, NULL);

// bmp �������� ��Ÿ���� "BM"��Ŀ Ȯ��
// bmp instead of bm
if (m_bmfHeader.bfType != 0x4D42) {
MessageBox(::GetActiveWindow(), "���� ������ bitmap������ �ƴմϴ�.", "error", MB_OK);
MessageBox(::GetActiveWindow(), "What bitmap?", "error", MB_OK);
return FALSE;
}

// BITMAPINFOHEADER ���
ReadFile(hFile, &m_bmInfoHeader, sizeof(m_bmInfoHeader), &dwRWC, NULL);

// �ȼ��� ��Ʈ �� Ȯ��
WORD wBitCount = m_bmInfoHeader.biBitCount;
if (24 != wBitCount || m_bmInfoHeader.biWidth <= 0 ||
m_bmInfoHeader.biHeight <= 0) // 24��Ʈ bmp�� �ƴϸ� return�� ������.
{
MessageBox(::GetActiveWindow(), "���� bitmap�� �ʺ�, ���̿� �̻��� �ְų� 24bit������ �ƴմϴ�.", "error",
NULL);
if (24 != wBitCount || m_bmInfoHeader.biWidth <= 0 || m_bmInfoHeader.biHeight <= 0) {
MessageBox(::GetActiveWindow(), "my bitmap, 24 bit.", "error", NULL);
return FALSE;
}

// ���� �̹����� �޸𸮻� ���� ���� ���� (24bit)
// 24 bit
int iRealWidth = ((int)((m_bmInfoHeader.biWidth * 3 + 3) / 4)) * 4;

// ���� ���� �̹��� �޸� �Ҵ�
// why?
int iDIBSize = iRealWidth * m_bmInfoHeader.biHeight;

if ((m_pPixels = ::GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, iDIBSize)) == NULL) {
MessageBox(::GetActiveWindow(), "�޸𸮸� �Ҵ����� ���߽��ϴ�.", "error", MB_OK);
MessageBox(::GetActiveWindow(), "What is it?", "error", MB_OK);
return FALSE;
}

// �ȼ��� �д´�..
for (int y = m_bmInfoHeader.biHeight - 1; y >= 0; y--) // ��Ʈ���� ���Ʒ��� �Ųٷ� �ִ�..
for (int y = m_bmInfoHeader.biHeight - 1; y >= 0; y--) // What is it?
{
ReadFile(hFile, (BYTE *)m_pPixels + y * iRealWidth, iRealWidth, &dwRWC, NULL);
}
Expand All @@ -85,18 +78,13 @@ void * CBitMapFile::Pixels(int x, int y) {
bool CBitMapFile::Save(HANDLE hFile) {
DWORD dwRWC = 0;

// ���� ��� ����
WriteFile(hFile, &m_bmfHeader, sizeof(m_bmfHeader), &dwRWC, NULL);

// BITMAPINFOHEADER ����
WriteFile(hFile, &m_bmInfoHeader, sizeof(m_bmInfoHeader), &dwRWC, NULL);

// ���� �̹����� �޸𸮻� ���� ���� ���� (24bit)
int iRealWidth = this->Pitch();

// �ȼ��� �����Ѵ�...
for (int y = m_bmInfoHeader.biHeight - 1; y >= 0; y--) // ��Ʈ���� ���Ʒ��� �Ųٷ� �ִ�..
{
for (int y = m_bmInfoHeader.biHeight - 1; y >= 0; y--) {
WriteFile(hFile, (BYTE *)m_pPixels + y * iRealWidth, iRealWidth, &dwRWC, NULL);
}

Expand Down Expand Up @@ -131,48 +119,45 @@ bool CBitMapFile::SaveRectToFile(const std::string & szFN, RECT rc) {
int nHeight = rc.bottom - rc.top;

if (nWidth <= 0 || nHeight <= 0) {
MessageBox(::GetActiveWindow(), "���� ���ΰ� 0������ bitmap���� �����Ҽ� �����ϴ�.", "error", MB_OK);
MessageBox(::GetActiveWindow(), "Bitmap width and height.", "error", MB_OK);
return FALSE;
}

DWORD dwRWC = 0;
HANDLE hFile = ::CreateFile(szFN.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

// ���� ���� ���� ����
// Contacted or reached
if (INVALID_HANDLE_VALUE == hFile) {
MessageBox(::GetActiveWindow(), "���� bitmap�� �� �� �����ϴ�.", "error", MB_OK);
MessageBox(::GetActiveWindow(), "What a bitmap.", "error", MB_OK);
return false;
}

// ���� �̹����� �޸𸮻� ���� ���� ���� (24bit)
// 24 bit
int iRealWidthDest = ((int)((nWidth * 3 + 3) / 4)) * 4;
int iDestDIBSize = sizeof(BITMAPINFOHEADER) + iRealWidthDest * nHeight;

// ���� ���� �̹��� file header ���� ä���
// What is the name of the file header?
BITMAPFILEHEADER bmfHeaderDest = m_bmfHeader;
bmfHeaderDest.bfType = 0x4D42; // "BM"
bmfHeaderDest.bfSize = sizeof(bmfHeaderDest) + iDestDIBSize;
bmfHeaderDest.bfOffBits = sizeof(bmfHeaderDest) + sizeof(BITMAPINFOHEADER);

// ���� ���� �̹��� bitmap info header ���� ä���
// bitmap info header ?
BITMAPINFOHEADER bmInfoHeaderDest = m_bmInfoHeader;
bmInfoHeaderDest.biSize = sizeof(bmInfoHeaderDest);
bmInfoHeaderDest.biWidth = nWidth;
bmInfoHeaderDest.biHeight = nHeight;
bmInfoHeaderDest.biPlanes = 1;
bmInfoHeaderDest.biSizeImage = iRealWidthDest * nHeight;

// ���� ��� ����
WriteFile(hFile, &bmfHeaderDest, sizeof(bmfHeaderDest), &dwRWC, NULL);

// BITMAPINFOHEADER ����
WriteFile(hFile, &bmInfoHeaderDest, sizeof(bmInfoHeaderDest), &dwRWC, NULL);

// �ȼ��� �����Ѵ�...
int iRealWidth = ((int)((m_bmInfoHeader.biWidth * 3 + 3) / 4)) * 4;
for (int y = rc.bottom - 1; y >= rc.top; y--) {
void * pPixelDest = ((uint8_t *)m_pPixels) + iRealWidth * y + (rc.left * 3);
WriteFile(hFile, pPixelDest, iRealWidthDest, &dwRWC, NULL); // ���� ����..
WriteFile(hFile, pPixelDest, iRealWidthDest, &dwRWC, NULL);
}

CloseHandle(hFile);
Expand Down Expand Up @@ -220,28 +205,28 @@ bool CBitMapFile::Create(int nWidth, int nHeight, int nBPP) {
if (nWidth <= 0 || nHeight <= 0) {
return false;
}
this->Release(); // �ϴ� �� �����ϰ�..
this->Release();

if (24 != nBPP) {
return FALSE;
}

int iRealWidth = ((nWidth * 3 + 3) / 4) * 4; // ���� �̹����� �޸𸮻� ���� ���� ���� (24bit)
int iDIBSize = iRealWidth * nHeight; // ���� ���� �̹��� �޸� �Ҵ�
int iRealWidth = ((nWidth * 3 + 3) / 4) * 4;
int iDIBSize = iRealWidth * nHeight;

if ((m_pPixels = ::GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, iDIBSize)) == NULL) {
MessageBox(::GetActiveWindow(), "�޸𸮸� �Ҵ����� ���߽��ϴ�.", "error", MB_OK);
MessageBox(::GetActiveWindow(), "What is it?", "error", MB_OK);
return FALSE;
}

memset(m_pPixels, 0, iDIBSize);

// ���� ���� �̹��� file header ���� ä���
// What is the name of the file header?
m_bmfHeader.bfType = 0x4D42; // "BM"
m_bmfHeader.bfSize = sizeof(m_bmfHeader) + iDIBSize;
m_bmfHeader.bfOffBits = sizeof(m_bmfHeader) + sizeof(BITMAPINFOHEADER);

// ���� ���� �̹��� bitmap info header ���� ä���
// bitmap info header ?
m_bmInfoHeader.biSize = sizeof(m_bmInfoHeader);
m_bmInfoHeader.biWidth = nWidth;
m_bmInfoHeader.biHeight = nHeight;
Expand Down
10 changes: 5 additions & 5 deletions src/engine/N3Base/BitMapFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class CBitMapFile {
BITMAPINFOHEADER m_bmInfoHeader;

public:
void * m_pPixels; // ���� �ȼ� ������
int Pitch() { return ((int)((m_bmInfoHeader.biWidth * 3 + 3) / 4)) * 4; } // ��Ʈ���� ���� �ʺ�(byte ����)..
bool Create(int nWidth, int nHeight, int nBPP = 24);
bool SaveRectToFile(const std::string & szFN, RECT rc);
void * Pixels(int x = 0, int y = 0);
void * m_pPixels; // actual pixel data
int Pitch() { return ((int)((m_bmInfoHeader.biWidth * 3 + 3) / 4)) * 4; } // Actual width of the bitmap (byte unit).
bool Create(int nWidth, int nHeight, int nBPP = 24);
bool SaveRectToFile(const std::string & szFN, RECT rc);
void * Pixels(int x = 0, int y = 0);
BITMAPINFOHEADER * GetBitmapInfoHeader() { return &m_bmInfoHeader; }
BITMAPFILEHEADER * GetBitmapFileHeader() { return &m_bmfHeader; }
bool Load(HANDLE hFile);
Expand Down
Loading