Refactor MxBitmap inline functions, match ImportBitmap

This commit is contained in:
Christian Semmler 2023-12-25 21:58:39 -05:00
parent c507454dd1
commit 17522b98d4
No known key found for this signature in database
GPG key ID: 086DAA1360BEEE5C
2 changed files with 23 additions and 26 deletions

View file

@ -10,22 +10,6 @@ DECOMP_SIZE_ASSERT(MxBITMAPINFO, 0x428);
// (1998) GLOBAL: LEGO1 0x10102184
MxU16 g_bitmapSignature = TWOCC('B', 'M');
// Bit mask trick to round up to the nearest multiple of four.
// Pixel data may be stored with padding.
// https://learn.microsoft.com/en-us/windows/win32/medfound/image-stride
inline MxLong AlignToFourByte(MxLong p_value)
{
return (p_value + 3) & -4;
}
// Same as the one from legoutil.h, but flipped the other way
// TODO: While it's not outside the realm of possibility that they
// reimplemented Abs for only this file, that seems odd, right?
inline MxLong AbsFlipped(MxLong p_value)
{
return p_value > 0 ? p_value : -p_value;
}
// FUNCTION: LEGO1 0x1004e0d0
int MxBitmap::VTable0x28(int)
{
@ -140,16 +124,14 @@ MxResult MxBitmap::ImportBitmap(MxBitmap* p_bitmap)
this->m_info = new MxBITMAPINFO;
if (this->m_info) {
MxLong height = AbsFlipped(p_bitmap->m_bmiHeader->biHeight);
this->m_data = new MxU8[AlignToFourByte(p_bitmap->m_bmiHeader->biWidth) * height];
this->m_data = new MxU8[p_bitmap->GetDataSize()];
if (this->m_data) {
memcpy(this->m_info, p_bitmap->m_info, sizeof(*this->m_info));
height = AbsFlipped(p_bitmap->m_bmiHeader->biHeight);
memcpy(this->m_data, p_bitmap->m_data, AlignToFourByte(p_bitmap->m_bmiHeader->biWidth) * height);
memcpy(this->m_info, p_bitmap->GetBitmapInfo(), MxBITMAPINFO::Size());
memcpy(this->m_data, p_bitmap->GetBitmapData(), p_bitmap->GetDataSize());
result = SUCCESS;
this->m_bmiHeader = &this->m_info->m_bmiHeader;
this->m_paletteData = this->m_info->m_bmiColors;
result = SUCCESS;
}
}

View file

@ -19,6 +19,8 @@
struct MxBITMAPINFO {
BITMAPINFOHEADER m_bmiHeader;
RGBQUAD m_bmiColors[256];
static MxU32 Size() { return sizeof(MxBITMAPINFO); }
};
// Non-standard value for biCompression in the BITMAPINFOHEADER struct.
@ -56,16 +58,29 @@ class MxBitmap : public MxCore {
MxS32 p_destHeight
); // vtable+40
// Bit mask trick to round up to the nearest multiple of four.
// Pixel data may be stored with padding.
// https://learn.microsoft.com/en-us/windows/win32/medfound/image-stride
inline MxLong AlignToFourByte(MxLong p_value) const { return (p_value + 3) & -4; }
// Same as the one from legoutil.h, but flipped the other way
// TODO: While it's not outside the realm of possibility that they
// reimplemented Abs for only this file, that seems odd, right?
inline MxLong AbsFlipped(MxLong p_value) const { return p_value > 0 ? p_value : -p_value; }
inline BITMAPINFOHEADER* GetBmiHeader() const { return m_bmiHeader; }
inline MxLong GetBmiWidth() const { return m_bmiHeader->biWidth; }
inline MxLong GetBmiStride() const { return ((m_bmiHeader->biWidth + 3) & -4); }
inline MxLong GetBmiHeight() const { return m_bmiHeader->biHeight; }
inline MxLong GetBmiHeightAbs() const
{
return m_bmiHeader->biHeight > 0 ? m_bmiHeader->biHeight : -m_bmiHeader->biHeight;
}
inline MxLong GetBmiHeightAbs() const { return AbsFlipped(m_bmiHeader->biHeight); }
inline MxU8* GetBitmapData() const { return m_data; }
inline MxBITMAPINFO* GetBitmapInfo() const { return m_info; }
inline MxLong GetDataSize() const
{
MxLong absHeight = GetBmiHeightAbs();
MxLong alignedWidth = AlignToFourByte(m_bmiHeader->biWidth);
return alignedWidth * absHeight;
}
private:
MxResult ImportColorsToPalette(RGBQUAD*, MxPalette*);