isle/LEGO1/omni/src/video/mxbitmap.cpp

518 lines
9.1 KiB
C++
Raw Normal View History

#include "mxbitmap.h"
2023-10-24 19:38:27 -04:00
Some MxBitmap vtable functions (#89) * Match MxBitmap::vtable+40 (CopyColorData) It's basically a call to StretchDIBits, which copies color data for a rectangle * Name a ternary raster op * Name variable m_unk18 (m_bmiColorsProvided) Since this variable is passed to StretchDIBits, we can see what its supposed to mean. We dont have DX5 docs, but we have docs of the current day, and this as its 'iUsage': "Specifies whether the bmiColors member of the BITMAPINFO structure was provided and, if so, whether bmiColors contains explicit red, green, blue (RGB) values or indexes." The second part (about what the bmiColors contains) seems redundant, since we know this is a boolean. Source: https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-stretchdibits * MxBitmap::CreatePalette is now up to 60% * Add progress on MxBitmap::LoadFile, add the global bitmap signature, add Clone call in CreatePalette * getting closer * Implement MxBitmap::vtable18 * Got vtable18 into a better state It's progress doesn't affect the status of CopyColorData, which is back at 100%, as it makes sense the loop is a memcpy * if you want to do more of vtable18 have fun * Cleanup MxBitmap::LoadFile * Begin work on FUN_100bd450 (ImportColorsToPalette) This took a lot of time, finally I got a good understanding of it. Primarily what's left now is the loop https://hackmd.io/@KsNMFSBHTO2gxDyRIPRQ1g/H1LCVQXon * Don’t include class name in method declaration * yolo vtable38 (I can't test the build atm) I moved up ImportColorsToPalette so other functions, including this one can use it * Cleanup while i keep getting bored of matching these functions that wont match * likely malloc is an operator new * A few things for MxBitmap * new struct MxBITMAPINFO * vtable18 and ImportPalette 100% * ImportColorsToPalette improvement * Match vtable1c and vtable3c * use MxResult return types * CreatePalette - Use MxResult to track success * Define types for the bit depth That boolean is not really a boolean, its just a variable to store the bit depth as some DWORD. 0 = 256 color, 1 = High Color (16-bit). * Match MxBitmap::CreatePalette * Match LoadFile YEGYEEHEEHEHEHEHEHE3 YES THIS IS FINALLY DONE OMFG * Reorder variable placement in CreatePalette * Start vtable14 * Match MxBitmap vtable14, down to reg swap. Maybe some import function? * Name MxBitmap vtable functions --------- Co-authored-by: disinvite <disinvite@users.noreply.github.com> Co-authored-by: Christian Semmler <mail@csemmler.com>
2023-08-28 06:04:39 -04:00
#include "decomp.h"
#include "mxpalette.h"
#include "mxutilities.h"
Some MxBitmap vtable functions (#89) * Match MxBitmap::vtable+40 (CopyColorData) It's basically a call to StretchDIBits, which copies color data for a rectangle * Name a ternary raster op * Name variable m_unk18 (m_bmiColorsProvided) Since this variable is passed to StretchDIBits, we can see what its supposed to mean. We dont have DX5 docs, but we have docs of the current day, and this as its 'iUsage': "Specifies whether the bmiColors member of the BITMAPINFO structure was provided and, if so, whether bmiColors contains explicit red, green, blue (RGB) values or indexes." The second part (about what the bmiColors contains) seems redundant, since we know this is a boolean. Source: https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-stretchdibits * MxBitmap::CreatePalette is now up to 60% * Add progress on MxBitmap::LoadFile, add the global bitmap signature, add Clone call in CreatePalette * getting closer * Implement MxBitmap::vtable18 * Got vtable18 into a better state It's progress doesn't affect the status of CopyColorData, which is back at 100%, as it makes sense the loop is a memcpy * if you want to do more of vtable18 have fun * Cleanup MxBitmap::LoadFile * Begin work on FUN_100bd450 (ImportColorsToPalette) This took a lot of time, finally I got a good understanding of it. Primarily what's left now is the loop https://hackmd.io/@KsNMFSBHTO2gxDyRIPRQ1g/H1LCVQXon * Don’t include class name in method declaration * yolo vtable38 (I can't test the build atm) I moved up ImportColorsToPalette so other functions, including this one can use it * Cleanup while i keep getting bored of matching these functions that wont match * likely malloc is an operator new * A few things for MxBitmap * new struct MxBITMAPINFO * vtable18 and ImportPalette 100% * ImportColorsToPalette improvement * Match vtable1c and vtable3c * use MxResult return types * CreatePalette - Use MxResult to track success * Define types for the bit depth That boolean is not really a boolean, its just a variable to store the bit depth as some DWORD. 0 = 256 color, 1 = High Color (16-bit). * Match MxBitmap::CreatePalette * Match LoadFile YEGYEEHEEHEHEHEHEHE3 YES THIS IS FINALLY DONE OMFG * Reorder variable placement in CreatePalette * Start vtable14 * Match MxBitmap vtable14, down to reg swap. Maybe some import function? * Name MxBitmap vtable functions --------- Co-authored-by: disinvite <disinvite@users.noreply.github.com> Co-authored-by: Christian Semmler <mail@csemmler.com>
2023-08-28 06:04:39 -04:00
DECOMP_SIZE_ASSERT(MxBitmap, 0x20);
DECOMP_SIZE_ASSERT(MxBITMAPINFO, 0x428);
Some MxBitmap vtable functions (#89) * Match MxBitmap::vtable+40 (CopyColorData) It's basically a call to StretchDIBits, which copies color data for a rectangle * Name a ternary raster op * Name variable m_unk18 (m_bmiColorsProvided) Since this variable is passed to StretchDIBits, we can see what its supposed to mean. We dont have DX5 docs, but we have docs of the current day, and this as its 'iUsage': "Specifies whether the bmiColors member of the BITMAPINFO structure was provided and, if so, whether bmiColors contains explicit red, green, blue (RGB) values or indexes." The second part (about what the bmiColors contains) seems redundant, since we know this is a boolean. Source: https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-stretchdibits * MxBitmap::CreatePalette is now up to 60% * Add progress on MxBitmap::LoadFile, add the global bitmap signature, add Clone call in CreatePalette * getting closer * Implement MxBitmap::vtable18 * Got vtable18 into a better state It's progress doesn't affect the status of CopyColorData, which is back at 100%, as it makes sense the loop is a memcpy * if you want to do more of vtable18 have fun * Cleanup MxBitmap::LoadFile * Begin work on FUN_100bd450 (ImportColorsToPalette) This took a lot of time, finally I got a good understanding of it. Primarily what's left now is the loop https://hackmd.io/@KsNMFSBHTO2gxDyRIPRQ1g/H1LCVQXon * Don’t include class name in method declaration * yolo vtable38 (I can't test the build atm) I moved up ImportColorsToPalette so other functions, including this one can use it * Cleanup while i keep getting bored of matching these functions that wont match * likely malloc is an operator new * A few things for MxBitmap * new struct MxBITMAPINFO * vtable18 and ImportPalette 100% * ImportColorsToPalette improvement * Match vtable1c and vtable3c * use MxResult return types * CreatePalette - Use MxResult to track success * Define types for the bit depth That boolean is not really a boolean, its just a variable to store the bit depth as some DWORD. 0 = 256 color, 1 = High Color (16-bit). * Match MxBitmap::CreatePalette * Match LoadFile YEGYEEHEEHEHEHEHEHE3 YES THIS IS FINALLY DONE OMFG * Reorder variable placement in CreatePalette * Start vtable14 * Match MxBitmap vtable14, down to reg swap. Maybe some import function? * Name MxBitmap vtable functions --------- Co-authored-by: disinvite <disinvite@users.noreply.github.com> Co-authored-by: Christian Semmler <mail@csemmler.com>
2023-08-28 06:04:39 -04:00
// GLOBAL: LEGO1 0x10102184
// GLOBAL: BETA10 0x10203030
MxU16 g_bitmapSignature = TWOCC('B', 'M');
(Proposal) Adjustments to "decomp" language (#308) * Adjustments to "decomp" language * Fix a comment * Fix accidental clang-formatting * Fix order * Fix order * Remove junk * Fix OFFSET * Adjustments based on new suggestions * Annotate globals * Globals in ISLE * More globals * Merge from parser2 branch * Allow prepending space for exact marker match * To eliminate noise, require the 0x prefix on offset for marker match * fix test from previous * Count tab stops for indented functions to reduce MISSED_END_OF_FUNCTION noise * FUNCTION to SYNTHETIC where needed * Missed marker conversion on SetAtomId * pylint cleanup, remove unused code * Fix unexpected function end, add more unit tests * Be more strict about synthetic name syntax * Revert "Missed marker conversion on SetAtomId" This reverts commit d87d665127fae7dd6e5bd48d9af14a0a829bf9e2. * Revert "FUNCTION to SYNTHETIC where needed" This reverts commit 8c815418d261ba8c5f67a9a2cae349fe4ac92db8. * Implicit lookup by name for functions * Fix VTABLE SYNTHETIC and other decomp markers * Get vtable class name * Vtable marker should identify struct * No colon for SIZE comment * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update CONTRIBUTING.md * Fix destructor/annotation * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md --------- Co-authored-by: disinvite <disinvite@users.noreply.github.com>
2023-12-06 07:10:45 -05:00
// FUNCTION: LEGO1 0x100bc980
// FUNCTION: BETA10 0x1013cab0
MxBitmap::MxBitmap()
{
m_info = NULL;
m_bmiHeader = NULL;
m_paletteData = NULL;
m_data = NULL;
m_isHighColor = FALSE;
m_palette = NULL;
}
(Proposal) Adjustments to "decomp" language (#308) * Adjustments to "decomp" language * Fix a comment * Fix accidental clang-formatting * Fix order * Fix order * Remove junk * Fix OFFSET * Adjustments based on new suggestions * Annotate globals * Globals in ISLE * More globals * Merge from parser2 branch * Allow prepending space for exact marker match * To eliminate noise, require the 0x prefix on offset for marker match * fix test from previous * Count tab stops for indented functions to reduce MISSED_END_OF_FUNCTION noise * FUNCTION to SYNTHETIC where needed * Missed marker conversion on SetAtomId * pylint cleanup, remove unused code * Fix unexpected function end, add more unit tests * Be more strict about synthetic name syntax * Revert "Missed marker conversion on SetAtomId" This reverts commit d87d665127fae7dd6e5bd48d9af14a0a829bf9e2. * Revert "FUNCTION to SYNTHETIC where needed" This reverts commit 8c815418d261ba8c5f67a9a2cae349fe4ac92db8. * Implicit lookup by name for functions * Fix VTABLE SYNTHETIC and other decomp markers * Get vtable class name * Vtable marker should identify struct * No colon for SIZE comment * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update CONTRIBUTING.md * Fix destructor/annotation * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md --------- Co-authored-by: disinvite <disinvite@users.noreply.github.com>
2023-12-06 07:10:45 -05:00
// FUNCTION: LEGO1 0x100bca10
// FUNCTION: BETA10 0x1013cb58
MxBitmap::~MxBitmap()
{
if (m_info) {
2023-10-24 19:38:27 -04:00
delete m_info;
}
if (m_data) {
2023-10-24 19:38:27 -04:00
delete m_data;
}
if (m_palette) {
2023-10-24 19:38:27 -04:00
delete m_palette;
}
}
(Proposal) Adjustments to "decomp" language (#308) * Adjustments to "decomp" language * Fix a comment * Fix accidental clang-formatting * Fix order * Fix order * Remove junk * Fix OFFSET * Adjustments based on new suggestions * Annotate globals * Globals in ISLE * More globals * Merge from parser2 branch * Allow prepending space for exact marker match * To eliminate noise, require the 0x prefix on offset for marker match * fix test from previous * Count tab stops for indented functions to reduce MISSED_END_OF_FUNCTION noise * FUNCTION to SYNTHETIC where needed * Missed marker conversion on SetAtomId * pylint cleanup, remove unused code * Fix unexpected function end, add more unit tests * Be more strict about synthetic name syntax * Revert "Missed marker conversion on SetAtomId" This reverts commit d87d665127fae7dd6e5bd48d9af14a0a829bf9e2. * Revert "FUNCTION to SYNTHETIC where needed" This reverts commit 8c815418d261ba8c5f67a9a2cae349fe4ac92db8. * Implicit lookup by name for functions * Fix VTABLE SYNTHETIC and other decomp markers * Get vtable class name * Vtable marker should identify struct * No colon for SIZE comment * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update CONTRIBUTING.md * Fix destructor/annotation * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md --------- Co-authored-by: disinvite <disinvite@users.noreply.github.com>
2023-12-06 07:10:45 -05:00
// FUNCTION: LEGO1 0x100bcaa0
// FUNCTION: BETA10 0x1013cc47
MxResult MxBitmap::SetSize(MxS32 p_width, MxS32 p_height, MxPalette* p_palette, MxBool p_isHighColor)
{
MxResult ret = FAILURE;
MxLong size = AlignToFourByte(p_width) * p_height;
m_info = (MxBITMAPINFO*) new MxU8[MxBitmapInfoSize()];
if (!m_info) {
goto done;
}
m_data = new MxU8[size];
if (!m_data) {
goto done;
2023-10-24 19:38:27 -04:00
}
m_bmiHeader = &m_info->m_bmiHeader;
m_paletteData = m_info->m_bmiColors;
memset(m_bmiHeader, 0, sizeof(m_info->m_bmiHeader));
m_bmiHeader->biSize = sizeof(*m_bmiHeader); // should be 40 bytes
m_bmiHeader->biWidth = p_width;
m_bmiHeader->biHeight = p_height;
m_bmiHeader->biPlanes = 1;
m_bmiHeader->biBitCount = 8;
m_bmiHeader->biCompression = 0;
m_bmiHeader->biSizeImage = size;
if (ImportColorsToPalette(m_paletteData, p_palette)) {
goto done;
}
if (SetBitDepth(p_isHighColor)) {
goto done;
}
ret = SUCCESS;
done:
if (ret) {
if (m_info) {
delete[] m_info;
m_info = NULL;
2023-10-24 19:38:27 -04:00
}
if (m_data) {
delete[] m_data;
m_data = NULL;
2023-10-24 19:38:27 -04:00
}
}
return ret;
Some MxBitmap vtable functions (#89) * Match MxBitmap::vtable+40 (CopyColorData) It's basically a call to StretchDIBits, which copies color data for a rectangle * Name a ternary raster op * Name variable m_unk18 (m_bmiColorsProvided) Since this variable is passed to StretchDIBits, we can see what its supposed to mean. We dont have DX5 docs, but we have docs of the current day, and this as its 'iUsage': "Specifies whether the bmiColors member of the BITMAPINFO structure was provided and, if so, whether bmiColors contains explicit red, green, blue (RGB) values or indexes." The second part (about what the bmiColors contains) seems redundant, since we know this is a boolean. Source: https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-stretchdibits * MxBitmap::CreatePalette is now up to 60% * Add progress on MxBitmap::LoadFile, add the global bitmap signature, add Clone call in CreatePalette * getting closer * Implement MxBitmap::vtable18 * Got vtable18 into a better state It's progress doesn't affect the status of CopyColorData, which is back at 100%, as it makes sense the loop is a memcpy * if you want to do more of vtable18 have fun * Cleanup MxBitmap::LoadFile * Begin work on FUN_100bd450 (ImportColorsToPalette) This took a lot of time, finally I got a good understanding of it. Primarily what's left now is the loop https://hackmd.io/@KsNMFSBHTO2gxDyRIPRQ1g/H1LCVQXon * Don’t include class name in method declaration * yolo vtable38 (I can't test the build atm) I moved up ImportColorsToPalette so other functions, including this one can use it * Cleanup while i keep getting bored of matching these functions that wont match * likely malloc is an operator new * A few things for MxBitmap * new struct MxBITMAPINFO * vtable18 and ImportPalette 100% * ImportColorsToPalette improvement * Match vtable1c and vtable3c * use MxResult return types * CreatePalette - Use MxResult to track success * Define types for the bit depth That boolean is not really a boolean, its just a variable to store the bit depth as some DWORD. 0 = 256 color, 1 = High Color (16-bit). * Match MxBitmap::CreatePalette * Match LoadFile YEGYEEHEEHEHEHEHEHE3 YES THIS IS FINALLY DONE OMFG * Reorder variable placement in CreatePalette * Start vtable14 * Match MxBitmap vtable14, down to reg swap. Maybe some import function? * Name MxBitmap vtable functions --------- Co-authored-by: disinvite <disinvite@users.noreply.github.com> Co-authored-by: Christian Semmler <mail@csemmler.com>
2023-08-28 06:04:39 -04:00
}
(Proposal) Adjustments to "decomp" language (#308) * Adjustments to "decomp" language * Fix a comment * Fix accidental clang-formatting * Fix order * Fix order * Remove junk * Fix OFFSET * Adjustments based on new suggestions * Annotate globals * Globals in ISLE * More globals * Merge from parser2 branch * Allow prepending space for exact marker match * To eliminate noise, require the 0x prefix on offset for marker match * fix test from previous * Count tab stops for indented functions to reduce MISSED_END_OF_FUNCTION noise * FUNCTION to SYNTHETIC where needed * Missed marker conversion on SetAtomId * pylint cleanup, remove unused code * Fix unexpected function end, add more unit tests * Be more strict about synthetic name syntax * Revert "Missed marker conversion on SetAtomId" This reverts commit d87d665127fae7dd6e5bd48d9af14a0a829bf9e2. * Revert "FUNCTION to SYNTHETIC where needed" This reverts commit 8c815418d261ba8c5f67a9a2cae349fe4ac92db8. * Implicit lookup by name for functions * Fix VTABLE SYNTHETIC and other decomp markers * Get vtable class name * Vtable marker should identify struct * No colon for SIZE comment * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update CONTRIBUTING.md * Fix destructor/annotation * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md --------- Co-authored-by: disinvite <disinvite@users.noreply.github.com>
2023-12-06 07:10:45 -05:00
// FUNCTION: LEGO1 0x100bcba0
// FUNCTION: BETA10 0x1013ce25
2023-10-24 19:38:27 -04:00
MxResult MxBitmap::ImportBitmapInfo(MxBITMAPINFO* p_info)
Some MxBitmap vtable functions (#89) * Match MxBitmap::vtable+40 (CopyColorData) It's basically a call to StretchDIBits, which copies color data for a rectangle * Name a ternary raster op * Name variable m_unk18 (m_bmiColorsProvided) Since this variable is passed to StretchDIBits, we can see what its supposed to mean. We dont have DX5 docs, but we have docs of the current day, and this as its 'iUsage': "Specifies whether the bmiColors member of the BITMAPINFO structure was provided and, if so, whether bmiColors contains explicit red, green, blue (RGB) values or indexes." The second part (about what the bmiColors contains) seems redundant, since we know this is a boolean. Source: https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-stretchdibits * MxBitmap::CreatePalette is now up to 60% * Add progress on MxBitmap::LoadFile, add the global bitmap signature, add Clone call in CreatePalette * getting closer * Implement MxBitmap::vtable18 * Got vtable18 into a better state It's progress doesn't affect the status of CopyColorData, which is back at 100%, as it makes sense the loop is a memcpy * if you want to do more of vtable18 have fun * Cleanup MxBitmap::LoadFile * Begin work on FUN_100bd450 (ImportColorsToPalette) This took a lot of time, finally I got a good understanding of it. Primarily what's left now is the loop https://hackmd.io/@KsNMFSBHTO2gxDyRIPRQ1g/H1LCVQXon * Don’t include class name in method declaration * yolo vtable38 (I can't test the build atm) I moved up ImportColorsToPalette so other functions, including this one can use it * Cleanup while i keep getting bored of matching these functions that wont match * likely malloc is an operator new * A few things for MxBitmap * new struct MxBITMAPINFO * vtable18 and ImportPalette 100% * ImportColorsToPalette improvement * Match vtable1c and vtable3c * use MxResult return types * CreatePalette - Use MxResult to track success * Define types for the bit depth That boolean is not really a boolean, its just a variable to store the bit depth as some DWORD. 0 = 256 color, 1 = High Color (16-bit). * Match MxBitmap::CreatePalette * Match LoadFile YEGYEEHEEHEHEHEHEHE3 YES THIS IS FINALLY DONE OMFG * Reorder variable placement in CreatePalette * Start vtable14 * Match MxBitmap vtable14, down to reg swap. Maybe some import function? * Name MxBitmap vtable functions --------- Co-authored-by: disinvite <disinvite@users.noreply.github.com> Co-authored-by: Christian Semmler <mail@csemmler.com>
2023-08-28 06:04:39 -04:00
{
2023-10-24 19:38:27 -04:00
MxResult result = FAILURE;
MxLong size = AlignToFourByte(p_info->m_bmiHeader.biWidth) * p_info->m_bmiHeader.biHeight;
m_info = (MxBITMAPINFO*) new MxU8[MxBitmapInfoSize()];
if (!m_info) {
goto done;
}
m_data = new MxU8[size];
if (!m_data) {
goto done;
2023-10-24 19:38:27 -04:00
}
memcpy(m_info, p_info, MxBitmapInfoSize());
m_bmiHeader = &m_info->m_bmiHeader;
m_paletteData = m_info->m_bmiColors;
result = SUCCESS;
done:
2023-10-24 19:38:27 -04:00
if (result != SUCCESS) {
if (m_info) {
delete[] m_info;
m_info = NULL;
2023-10-24 19:38:27 -04:00
}
if (m_data) {
delete[] m_data;
m_data = NULL;
2023-10-24 19:38:27 -04:00
}
}
return result;
}
(Proposal) Adjustments to "decomp" language (#308) * Adjustments to "decomp" language * Fix a comment * Fix accidental clang-formatting * Fix order * Fix order * Remove junk * Fix OFFSET * Adjustments based on new suggestions * Annotate globals * Globals in ISLE * More globals * Merge from parser2 branch * Allow prepending space for exact marker match * To eliminate noise, require the 0x prefix on offset for marker match * fix test from previous * Count tab stops for indented functions to reduce MISSED_END_OF_FUNCTION noise * FUNCTION to SYNTHETIC where needed * Missed marker conversion on SetAtomId * pylint cleanup, remove unused code * Fix unexpected function end, add more unit tests * Be more strict about synthetic name syntax * Revert "Missed marker conversion on SetAtomId" This reverts commit d87d665127fae7dd6e5bd48d9af14a0a829bf9e2. * Revert "FUNCTION to SYNTHETIC where needed" This reverts commit 8c815418d261ba8c5f67a9a2cae349fe4ac92db8. * Implicit lookup by name for functions * Fix VTABLE SYNTHETIC and other decomp markers * Get vtable class name * Vtable marker should identify struct * No colon for SIZE comment * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update CONTRIBUTING.md * Fix destructor/annotation * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md --------- Co-authored-by: disinvite <disinvite@users.noreply.github.com>
2023-12-06 07:10:45 -05:00
// FUNCTION: LEGO1 0x100bcc40
// FUNCTION: BETA10 0x1013cf6d
MxResult MxBitmap::ImportBitmap(MxBitmap* p_bitmap)
{
MxResult result = FAILURE;
2023-10-24 19:38:27 -04:00
m_info = (MxBITMAPINFO*) new MxU8[p_bitmap->MxBitmapInfoSize()];
if (!m_info) {
goto done;
}
m_data = new MxU8[p_bitmap->GetDataSize()];
if (!m_data) {
goto done;
2023-10-24 19:38:27 -04:00
}
memcpy(m_info, p_bitmap->GetBitmapInfo(), p_bitmap->MxBitmapInfoSize());
memcpy(m_data, p_bitmap->GetImage(), p_bitmap->GetDataSize());
m_bmiHeader = &m_info->m_bmiHeader;
m_paletteData = m_info->m_bmiColors;
result = SUCCESS;
done:
if (result != SUCCESS) {
if (m_info) {
delete[] m_info;
m_info = NULL;
}
if (m_data) {
delete[] m_data;
m_data = NULL;
}
2023-10-24 19:38:27 -04:00
}
return result;
}
(Proposal) Adjustments to "decomp" language (#308) * Adjustments to "decomp" language * Fix a comment * Fix accidental clang-formatting * Fix order * Fix order * Remove junk * Fix OFFSET * Adjustments based on new suggestions * Annotate globals * Globals in ISLE * More globals * Merge from parser2 branch * Allow prepending space for exact marker match * To eliminate noise, require the 0x prefix on offset for marker match * fix test from previous * Count tab stops for indented functions to reduce MISSED_END_OF_FUNCTION noise * FUNCTION to SYNTHETIC where needed * Missed marker conversion on SetAtomId * pylint cleanup, remove unused code * Fix unexpected function end, add more unit tests * Be more strict about synthetic name syntax * Revert "Missed marker conversion on SetAtomId" This reverts commit d87d665127fae7dd6e5bd48d9af14a0a829bf9e2. * Revert "FUNCTION to SYNTHETIC where needed" This reverts commit 8c815418d261ba8c5f67a9a2cae349fe4ac92db8. * Implicit lookup by name for functions * Fix VTABLE SYNTHETIC and other decomp markers * Get vtable class name * Vtable marker should identify struct * No colon for SIZE comment * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update CONTRIBUTING.md * Fix destructor/annotation * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md --------- Co-authored-by: disinvite <disinvite@users.noreply.github.com>
2023-12-06 07:10:45 -05:00
// FUNCTION: LEGO1 0x100bcd10
// FUNCTION: BETA10 0x1013d0c7
MxLong MxBitmap::Read(const char* p_filename)
{
MxResult result = FAILURE;
HANDLE handle = 0;
2023-10-24 19:38:27 -04:00
handle = CreateFileA(p_filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (handle == INVALID_HANDLE_VALUE) {
goto done;
}
if (LoadFile(handle)) {
goto done;
}
2023-10-24 19:38:27 -04:00
result = SUCCESS;
done:
if (handle) {
CloseHandle(handle);
}
2023-10-24 19:38:27 -04:00
return result;
}
(Proposal) Adjustments to "decomp" language (#308) * Adjustments to "decomp" language * Fix a comment * Fix accidental clang-formatting * Fix order * Fix order * Remove junk * Fix OFFSET * Adjustments based on new suggestions * Annotate globals * Globals in ISLE * More globals * Merge from parser2 branch * Allow prepending space for exact marker match * To eliminate noise, require the 0x prefix on offset for marker match * fix test from previous * Count tab stops for indented functions to reduce MISSED_END_OF_FUNCTION noise * FUNCTION to SYNTHETIC where needed * Missed marker conversion on SetAtomId * pylint cleanup, remove unused code * Fix unexpected function end, add more unit tests * Be more strict about synthetic name syntax * Revert "Missed marker conversion on SetAtomId" This reverts commit d87d665127fae7dd6e5bd48d9af14a0a829bf9e2. * Revert "FUNCTION to SYNTHETIC where needed" This reverts commit 8c815418d261ba8c5f67a9a2cae349fe4ac92db8. * Implicit lookup by name for functions * Fix VTABLE SYNTHETIC and other decomp markers * Get vtable class name * Vtable marker should identify struct * No colon for SIZE comment * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update CONTRIBUTING.md * Fix destructor/annotation * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md --------- Co-authored-by: disinvite <disinvite@users.noreply.github.com>
2023-12-06 07:10:45 -05:00
// FUNCTION: LEGO1 0x100bcd60
// FUNCTION: BETA10 0x1013d169
MxResult MxBitmap::LoadFile(HANDLE p_handle)
{
2023-10-24 19:38:27 -04:00
MxResult result = FAILURE;
MxLong unused = 0;
MxLong size;
2023-10-24 19:38:27 -04:00
DWORD bytesRead;
BITMAPFILEHEADER hdr;
if (!ReadFile(p_handle, &hdr, sizeof(hdr), &bytesRead, NULL)) {
goto done;
}
2023-10-24 19:38:27 -04:00
if (hdr.bfType != g_bitmapSignature) {
goto done;
}
m_info = (MxBITMAPINFO*) new MxU8[MxBitmapInfoSize()];
if (!m_info) {
goto done;
}
if (!ReadFile(p_handle, m_info, MxBitmapInfoSize(), &bytesRead, NULL)) {
goto done;
}
if (m_info->m_bmiHeader.biBitCount != 8) {
goto done;
2023-10-24 19:38:27 -04:00
}
size = hdr.bfSize - sizeof(BITMAPFILEHEADER) - MxBitmapInfoSize();
m_data = new MxU8[size];
if (!m_data) {
goto done;
}
if (!ReadFile(p_handle, m_data, size, &bytesRead, NULL)) {
goto done;
}
m_bmiHeader = &m_info->m_bmiHeader;
m_paletteData = m_info->m_bmiColors;
if (m_info->m_bmiHeader.biSizeImage == 0) {
m_info->m_bmiHeader.biSizeImage = GetDataSize();
}
result = SUCCESS;
done:
2023-10-24 19:38:27 -04:00
if (result != SUCCESS) {
if (m_info) {
delete[] m_info;
m_info = NULL;
2023-10-24 19:38:27 -04:00
}
if (m_data) {
delete[] m_data;
m_data = NULL;
2023-10-24 19:38:27 -04:00
}
}
return result;
}
// FUNCTION: LEGO1 0x100bce70
// FUNCTION: BETA10 0x1013d399
void MxBitmap::BitBlt(
MxBitmap* p_src,
MxS32 p_srcLeft,
MxS32 p_srcTop,
MxS32 p_dstLeft,
MxS32 p_dstTop,
MxS32 p_width,
MxS32 p_height
)
{
if (!GetRectIntersection(
p_src->GetBmiWidth(),
p_src->GetBmiHeightAbs(),
GetBmiWidth(),
GetBmiHeightAbs(),
&p_srcLeft,
&p_srcTop,
&p_dstLeft,
&p_dstTop,
&p_width,
&p_height
)) {
return;
}
MxU8* srcStart = p_src->GetStart(p_srcLeft, p_srcTop);
MxU8* dstStart = GetStart(p_dstLeft, p_dstTop);
MxLong srcStride = GetAdjustedStride(p_src);
MxLong dstStride = GetAdjustedStride(this);
while (p_height--) {
memcpy(dstStart, srcStart, p_width);
dstStart += dstStride;
srcStart += srcStride;
}
}
// FUNCTION: LEGO1 0x100bd020
// FUNCTION: BETA10 0x1013d4ea
void MxBitmap::BitBltTransparent(
MxBitmap* p_src,
MxS32 p_srcLeft,
MxS32 p_srcTop,
MxS32 p_dstLeft,
MxS32 p_dstTop,
MxS32 p_width,
MxS32 p_height
)
{
if (!GetRectIntersection(
p_src->GetBmiWidth(),
p_src->GetBmiHeightAbs(),
GetBmiWidth(),
GetBmiHeightAbs(),
&p_srcLeft,
&p_srcTop,
&p_dstLeft,
&p_dstTop,
&p_width,
&p_height
)) {
return;
}
MxU8* srcStart = p_src->GetStart(p_srcLeft, p_srcTop);
MxU8* dstStart = GetStart(p_dstLeft, p_dstTop);
MxLong srcStride = -p_width + GetAdjustedStride(p_src);
MxLong dstStride = -p_width + GetAdjustedStride(this);
for (MxS32 h = 0; h < p_height; h++) {
for (MxS32 w = 0; w < p_width; w++) {
if (*srcStart) {
*dstStart = *srcStart;
}
srcStart++;
dstStart++;
}
srcStart += srcStride;
dstStart += dstStride;
}
}
(Proposal) Adjustments to "decomp" language (#308) * Adjustments to "decomp" language * Fix a comment * Fix accidental clang-formatting * Fix order * Fix order * Remove junk * Fix OFFSET * Adjustments based on new suggestions * Annotate globals * Globals in ISLE * More globals * Merge from parser2 branch * Allow prepending space for exact marker match * To eliminate noise, require the 0x prefix on offset for marker match * fix test from previous * Count tab stops for indented functions to reduce MISSED_END_OF_FUNCTION noise * FUNCTION to SYNTHETIC where needed * Missed marker conversion on SetAtomId * pylint cleanup, remove unused code * Fix unexpected function end, add more unit tests * Be more strict about synthetic name syntax * Revert "Missed marker conversion on SetAtomId" This reverts commit d87d665127fae7dd6e5bd48d9af14a0a829bf9e2. * Revert "FUNCTION to SYNTHETIC where needed" This reverts commit 8c815418d261ba8c5f67a9a2cae349fe4ac92db8. * Implicit lookup by name for functions * Fix VTABLE SYNTHETIC and other decomp markers * Get vtable class name * Vtable marker should identify struct * No colon for SIZE comment * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update CONTRIBUTING.md * Fix destructor/annotation * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md --------- Co-authored-by: disinvite <disinvite@users.noreply.github.com>
2023-12-06 07:10:45 -05:00
// FUNCTION: LEGO1 0x100bd1c0
// FUNCTION: BETA10 0x1013d684
2023-10-24 19:38:27 -04:00
MxPalette* MxBitmap::CreatePalette()
{
2023-10-24 19:38:27 -04:00
MxBool success = FALSE;
MxPalette* palette = NULL;
switch (m_isHighColor) {
2023-10-24 19:38:27 -04:00
case FALSE:
if (!(palette = new MxPalette(m_paletteData))) {
2023-12-25 21:16:14 -05:00
goto done;
}
2023-12-25 21:16:14 -05:00
break;
2023-10-24 19:38:27 -04:00
case TRUE:
if (!(palette = m_palette->Clone())) {
2023-12-25 21:16:14 -05:00
goto done;
}
2023-12-25 21:16:14 -05:00
2023-10-24 19:38:27 -04:00
break;
2023-12-25 21:16:14 -05:00
default:
goto done;
2023-10-24 19:38:27 -04:00
}
2023-12-25 21:16:14 -05:00
success = TRUE;
done:
2023-10-24 19:38:27 -04:00
if (!success && palette) {
delete palette;
palette = NULL;
}
return palette;
}
(Proposal) Adjustments to "decomp" language (#308) * Adjustments to "decomp" language * Fix a comment * Fix accidental clang-formatting * Fix order * Fix order * Remove junk * Fix OFFSET * Adjustments based on new suggestions * Annotate globals * Globals in ISLE * More globals * Merge from parser2 branch * Allow prepending space for exact marker match * To eliminate noise, require the 0x prefix on offset for marker match * fix test from previous * Count tab stops for indented functions to reduce MISSED_END_OF_FUNCTION noise * FUNCTION to SYNTHETIC where needed * Missed marker conversion on SetAtomId * pylint cleanup, remove unused code * Fix unexpected function end, add more unit tests * Be more strict about synthetic name syntax * Revert "Missed marker conversion on SetAtomId" This reverts commit d87d665127fae7dd6e5bd48d9af14a0a829bf9e2. * Revert "FUNCTION to SYNTHETIC where needed" This reverts commit 8c815418d261ba8c5f67a9a2cae349fe4ac92db8. * Implicit lookup by name for functions * Fix VTABLE SYNTHETIC and other decomp markers * Get vtable class name * Vtable marker should identify struct * No colon for SIZE comment * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update CONTRIBUTING.md * Fix destructor/annotation * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md --------- Co-authored-by: disinvite <disinvite@users.noreply.github.com>
2023-12-06 07:10:45 -05:00
// FUNCTION: LEGO1 0x100bd280
// FUNCTION: BETA10 0x1013d80e
Some MxBitmap vtable functions (#89) * Match MxBitmap::vtable+40 (CopyColorData) It's basically a call to StretchDIBits, which copies color data for a rectangle * Name a ternary raster op * Name variable m_unk18 (m_bmiColorsProvided) Since this variable is passed to StretchDIBits, we can see what its supposed to mean. We dont have DX5 docs, but we have docs of the current day, and this as its 'iUsage': "Specifies whether the bmiColors member of the BITMAPINFO structure was provided and, if so, whether bmiColors contains explicit red, green, blue (RGB) values or indexes." The second part (about what the bmiColors contains) seems redundant, since we know this is a boolean. Source: https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-stretchdibits * MxBitmap::CreatePalette is now up to 60% * Add progress on MxBitmap::LoadFile, add the global bitmap signature, add Clone call in CreatePalette * getting closer * Implement MxBitmap::vtable18 * Got vtable18 into a better state It's progress doesn't affect the status of CopyColorData, which is back at 100%, as it makes sense the loop is a memcpy * if you want to do more of vtable18 have fun * Cleanup MxBitmap::LoadFile * Begin work on FUN_100bd450 (ImportColorsToPalette) This took a lot of time, finally I got a good understanding of it. Primarily what's left now is the loop https://hackmd.io/@KsNMFSBHTO2gxDyRIPRQ1g/H1LCVQXon * Don’t include class name in method declaration * yolo vtable38 (I can't test the build atm) I moved up ImportColorsToPalette so other functions, including this one can use it * Cleanup while i keep getting bored of matching these functions that wont match * likely malloc is an operator new * A few things for MxBitmap * new struct MxBITMAPINFO * vtable18 and ImportPalette 100% * ImportColorsToPalette improvement * Match vtable1c and vtable3c * use MxResult return types * CreatePalette - Use MxResult to track success * Define types for the bit depth That boolean is not really a boolean, its just a variable to store the bit depth as some DWORD. 0 = 256 color, 1 = High Color (16-bit). * Match MxBitmap::CreatePalette * Match LoadFile YEGYEEHEEHEHEHEHEHE3 YES THIS IS FINALLY DONE OMFG * Reorder variable placement in CreatePalette * Start vtable14 * Match MxBitmap vtable14, down to reg swap. Maybe some import function? * Name MxBitmap vtable functions --------- Co-authored-by: disinvite <disinvite@users.noreply.github.com> Co-authored-by: Christian Semmler <mail@csemmler.com>
2023-08-28 06:04:39 -04:00
void MxBitmap::ImportPalette(MxPalette* p_palette)
{
2023-10-24 19:38:27 -04:00
// Odd to use a switch on a boolean, but it matches.
switch (m_isHighColor) {
2023-10-24 19:38:27 -04:00
case FALSE:
ImportColorsToPalette(m_paletteData, p_palette);
2023-10-24 19:38:27 -04:00
break;
case TRUE:
delete m_palette;
m_palette = p_palette->Clone();
2023-10-24 19:38:27 -04:00
break;
}
}
(Proposal) Adjustments to "decomp" language (#308) * Adjustments to "decomp" language * Fix a comment * Fix accidental clang-formatting * Fix order * Fix order * Remove junk * Fix OFFSET * Adjustments based on new suggestions * Annotate globals * Globals in ISLE * More globals * Merge from parser2 branch * Allow prepending space for exact marker match * To eliminate noise, require the 0x prefix on offset for marker match * fix test from previous * Count tab stops for indented functions to reduce MISSED_END_OF_FUNCTION noise * FUNCTION to SYNTHETIC where needed * Missed marker conversion on SetAtomId * pylint cleanup, remove unused code * Fix unexpected function end, add more unit tests * Be more strict about synthetic name syntax * Revert "Missed marker conversion on SetAtomId" This reverts commit d87d665127fae7dd6e5bd48d9af14a0a829bf9e2. * Revert "FUNCTION to SYNTHETIC where needed" This reverts commit 8c815418d261ba8c5f67a9a2cae349fe4ac92db8. * Implicit lookup by name for functions * Fix VTABLE SYNTHETIC and other decomp markers * Get vtable class name * Vtable marker should identify struct * No colon for SIZE comment * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update CONTRIBUTING.md * Fix destructor/annotation * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md --------- Co-authored-by: disinvite <disinvite@users.noreply.github.com>
2023-12-06 07:10:45 -05:00
// FUNCTION: LEGO1 0x100bd2d0
// FUNCTION: BETA10 0x1013d8a9
MxResult MxBitmap::SetBitDepth(MxBool p_isHighColor)
{
2023-10-24 19:38:27 -04:00
MxResult ret = FAILURE;
MxPalette* pal = NULL;
if (m_isHighColor == p_isHighColor) {
// no change: do nothing.
ret = SUCCESS;
2023-12-25 20:54:44 -05:00
goto done;
2023-10-24 19:38:27 -04:00
}
2023-12-25 20:54:44 -05:00
switch (p_isHighColor) {
case FALSE:
ImportColorsToPalette(m_paletteData, m_palette);
delete m_palette;
2023-12-25 20:54:44 -05:00
m_palette = NULL;
break;
case TRUE: {
if (!(pal = new MxPalette(m_paletteData))) {
2023-12-25 20:54:44 -05:00
goto done;
}
2023-12-25 20:54:44 -05:00
m_palette = pal;
// TODO: what is this? zeroing out top half of palette?
MxU16* buf = (MxU16*) m_paletteData;
for (MxU16 i = 0; i < 256; i++) {
buf[i] = i;
2023-10-24 19:38:27 -04:00
}
2023-12-25 20:54:44 -05:00
break;
2023-10-24 19:38:27 -04:00
}
2023-12-25 20:54:44 -05:00
default:
goto done;
}
m_isHighColor = p_isHighColor;
ret = SUCCESS;
2023-10-24 19:38:27 -04:00
2023-12-25 20:54:44 -05:00
done:
2023-10-24 19:38:27 -04:00
// If we were unsuccessful overall but did manage to alloc
// the MxPalette, free it.
if (ret && pal) {
2023-10-24 19:38:27 -04:00
delete pal;
}
2023-10-24 19:38:27 -04:00
return ret;
}
(Proposal) Adjustments to "decomp" language (#308) * Adjustments to "decomp" language * Fix a comment * Fix accidental clang-formatting * Fix order * Fix order * Remove junk * Fix OFFSET * Adjustments based on new suggestions * Annotate globals * Globals in ISLE * More globals * Merge from parser2 branch * Allow prepending space for exact marker match * To eliminate noise, require the 0x prefix on offset for marker match * fix test from previous * Count tab stops for indented functions to reduce MISSED_END_OF_FUNCTION noise * FUNCTION to SYNTHETIC where needed * Missed marker conversion on SetAtomId * pylint cleanup, remove unused code * Fix unexpected function end, add more unit tests * Be more strict about synthetic name syntax * Revert "Missed marker conversion on SetAtomId" This reverts commit d87d665127fae7dd6e5bd48d9af14a0a829bf9e2. * Revert "FUNCTION to SYNTHETIC where needed" This reverts commit 8c815418d261ba8c5f67a9a2cae349fe4ac92db8. * Implicit lookup by name for functions * Fix VTABLE SYNTHETIC and other decomp markers * Get vtable class name * Vtable marker should identify struct * No colon for SIZE comment * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update CONTRIBUTING.md * Fix destructor/annotation * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md --------- Co-authored-by: disinvite <disinvite@users.noreply.github.com>
2023-12-06 07:10:45 -05:00
// FUNCTION: LEGO1 0x100bd3e0
// FUNCTION: BETA10 0x1013dad2
2023-10-24 19:38:27 -04:00
MxResult MxBitmap::StretchBits(
HDC p_hdc,
MxS32 p_xSrc,
MxS32 p_ySrc,
MxS32 p_xDest,
MxS32 p_yDest,
MxS32 p_destWidth,
MxS32 p_destHeight
)
{
2023-10-24 19:38:27 -04:00
// Compression fix?
if (IsBottomUp()) {
p_ySrc = GetBmiHeightAbs() - p_ySrc - p_destHeight;
2023-10-24 19:38:27 -04:00
}
return StretchDIBits(
p_hdc,
p_xDest,
p_yDest,
p_destWidth,
p_destHeight,
p_xSrc,
p_ySrc,
p_destWidth,
p_destHeight,
m_data,
(BITMAPINFO*) m_info,
m_isHighColor,
2023-10-24 19:38:27 -04:00
SRCCOPY
);
}
(Proposal) Adjustments to "decomp" language (#308) * Adjustments to "decomp" language * Fix a comment * Fix accidental clang-formatting * Fix order * Fix order * Remove junk * Fix OFFSET * Adjustments based on new suggestions * Annotate globals * Globals in ISLE * More globals * Merge from parser2 branch * Allow prepending space for exact marker match * To eliminate noise, require the 0x prefix on offset for marker match * fix test from previous * Count tab stops for indented functions to reduce MISSED_END_OF_FUNCTION noise * FUNCTION to SYNTHETIC where needed * Missed marker conversion on SetAtomId * pylint cleanup, remove unused code * Fix unexpected function end, add more unit tests * Be more strict about synthetic name syntax * Revert "Missed marker conversion on SetAtomId" This reverts commit d87d665127fae7dd6e5bd48d9af14a0a829bf9e2. * Revert "FUNCTION to SYNTHETIC where needed" This reverts commit 8c815418d261ba8c5f67a9a2cae349fe4ac92db8. * Implicit lookup by name for functions * Fix VTABLE SYNTHETIC and other decomp markers * Get vtable class name * Vtable marker should identify struct * No colon for SIZE comment * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update README.md * Update CONTRIBUTING.md * Update README.md * Update CONTRIBUTING.md * Fix destructor/annotation * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md --------- Co-authored-by: disinvite <disinvite@users.noreply.github.com>
2023-12-06 07:10:45 -05:00
// FUNCTION: LEGO1 0x100bd450
// FUNCTION: BETA10 0x1013db55
MxResult MxBitmap::ImportColorsToPalette(RGBQUAD* p_rgbquad, MxPalette* p_palette)
{
MxResult ret = FAILURE;
PALETTEENTRY entries[256];
if (p_palette) {
if (p_palette->GetEntries(entries)) {
2023-12-06 08:29:24 -05:00
goto done;
}
}
else {
MxPalette palette;
if (palette.GetEntries(entries)) {
2023-12-06 08:29:24 -05:00
goto done;
}
}
2023-12-06 08:29:24 -05:00
MxS32 i;
for (i = 0; i < 256; i++) {
p_rgbquad[i].rgbRed = entries[i].peRed;
p_rgbquad[i].rgbGreen = entries[i].peGreen;
p_rgbquad[i].rgbBlue = entries[i].peBlue;
p_rgbquad[i].rgbReserved = 0;
}
ret = SUCCESS;
2023-12-06 08:29:24 -05:00
done:
return ret;
}