Static for height-specific abs, fix StrechBits

This commit is contained in:
disinvite 2024-05-27 18:59:10 -04:00
parent d59495f02e
commit 979a05857d
2 changed files with 20 additions and 8 deletions

View File

@ -87,11 +87,12 @@ class MxBitmap : public MxCore {
// FUNCTION: BETA10 0x1002c510
inline MxLong AlignToFourByte(MxLong p_value) const { return (p_value + 3) & -4; }
// Same as the one from legoutils.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?
// DECOMP: This could be a free function. It is static here because it has no
// reference to "this". In the beta it is called in two places:
// 1. GetBmiHeightAbs
// 2. at 0x101523b9, in reference to BITMAPINFOHEADER.biHeight
// FUNCTION: BETA10 0x1002c690
inline MxLong AbsFlipped(MxLong p_value) const { return p_value > 0 ? p_value : -p_value; }
static MxLong HeightAbs(MxLong p_value) { return p_value > 0 ? p_value : -p_value; }
inline BITMAPINFOHEADER* GetBmiHeader() const { return m_bmiHeader; }
@ -101,7 +102,7 @@ class MxBitmap : public MxCore {
inline MxLong GetBmiHeight() const { return m_bmiHeader->biHeight; }
// FUNCTION: BETA10 0x1002c470
inline MxLong GetBmiHeightAbs() const { return AbsFlipped(m_bmiHeader->biHeight); }
inline MxLong GetBmiHeightAbs() const { return HeightAbs(m_bmiHeader->biHeight); }
// FUNCTION: BETA10 0x10083900
inline MxU8* GetImage() const { return m_data; }
@ -156,6 +157,17 @@ class MxBitmap : public MxCore {
// MxBitmap::`scalar deleting destructor'
private:
// FUNCTION: BETA10 0x1013dd30
inline MxBool IsBottomUp()
{
if (m_bmiHeader->biCompression == BI_RGB_TOPDOWN) {
return FALSE;
}
else {
return m_bmiHeader->biHeight > 0;
}
}
MxResult ImportColorsToPalette(RGBQUAD*, MxPalette*);
MxBITMAPINFO* m_info; // 0x08

View File

@ -194,7 +194,7 @@ MxResult MxBitmap::LoadFile(HANDLE p_handle)
m_bmiHeader = &m_info->m_bmiHeader;
m_paletteData = m_info->m_bmiColors;
if (m_info->m_bmiHeader.biSizeImage == 0) {
MxLong height = AbsFlipped(m_info->m_bmiHeader.biHeight);
MxLong height = HeightAbs(m_info->m_bmiHeader.biHeight);
m_info->m_bmiHeader.biSizeImage = AlignToFourByte(m_info->m_bmiHeader.biWidth) * height;
}
result = SUCCESS;
@ -433,8 +433,8 @@ MxResult MxBitmap::StretchBits(
)
{
// Compression fix?
if ((m_bmiHeader->biCompression != BI_RGB_TOPDOWN) && (0 < m_bmiHeader->biHeight)) {
p_ySrc = (m_bmiHeader->biHeight - p_destHeight) - p_ySrc;
if (IsBottomUp()) {
p_ySrc = GetBmiHeightAbs() - p_ySrc - p_destHeight;
}
return StretchDIBits(