Refactor surrounding MxBitmap::GetAdjustedStride

This commit is contained in:
disinvite 2024-07-04 12:01:22 -04:00
parent 65e3c3dd05
commit 97f57e8952
4 changed files with 292 additions and 293 deletions

View File

@ -94,6 +94,7 @@ class MxBitmap : public MxCore {
// FUNCTION: BETA10 0x1002c690 // FUNCTION: BETA10 0x1002c690
static MxLong HeightAbs(MxLong p_value) { return p_value > 0 ? p_value : -p_value; } static MxLong HeightAbs(MxLong p_value) { return p_value > 0 ? p_value : -p_value; }
// FUNCTION: BETA10 0x10142030
inline BITMAPINFOHEADER* GetBmiHeader() const { return m_bmiHeader; } inline BITMAPINFOHEADER* GetBmiHeader() const { return m_bmiHeader; }
// FUNCTION: BETA10 0x1002c440 // FUNCTION: BETA10 0x1002c440
@ -124,15 +125,9 @@ class MxBitmap : public MxCore {
} }
} }
inline MxLong GetAdjustedStride() #define GetAdjustedStride(p_bitmap) \
{ (p_bitmap->IsTopDown() ? p_bitmap->AlignToFourByte(p_bitmap->GetBmiWidth()) \
if (m_bmiHeader->biCompression == BI_RGB_TOPDOWN || m_bmiHeader->biHeight < 0) { : -p_bitmap->AlignToFourByte(p_bitmap->GetBmiWidth()))
return GetBmiStride();
}
else {
return -GetBmiStride();
}
}
// FUNCTION: BETA10 0x1002c320 // FUNCTION: BETA10 0x1002c320
inline MxU8* GetStart(MxS32 p_left, MxS32 p_top) inline MxU8* GetStart(MxS32 p_left, MxS32 p_top)

View File

@ -99,7 +99,7 @@ class MxDisplaySurface : public MxCore {
inline LPDIRECTDRAWSURFACE GetDirectDrawSurface2() { return this->m_ddSurface2; } inline LPDIRECTDRAWSURFACE GetDirectDrawSurface2() { return this->m_ddSurface2; }
inline MxVideoParam& GetVideoParam() { return this->m_videoParam; } inline MxVideoParam& GetVideoParam() { return this->m_videoParam; }
static void FUN_100bb500( void FUN_100bb500(
MxU8** p_bitmapData, MxU8** p_bitmapData,
MxU8** p_surfaceData, MxU8** p_surfaceData,
MxU32 p_bitmapSize, MxU32 p_bitmapSize,

View File

@ -274,14 +274,11 @@ void MxBitmap::BitBlt(
MxS32 p_height MxS32 p_height
) )
{ {
MxLong dstHeight = GetBmiHeightAbs(); if (!GetRectIntersection(
MxLong srcHeight = p_src->GetBmiHeightAbs();
if (GetRectIntersection(
p_src->GetBmiWidth(), p_src->GetBmiWidth(),
srcHeight, p_src->GetBmiHeightAbs(),
GetBmiWidth(), GetBmiWidth(),
dstHeight, GetBmiHeightAbs(),
&p_srcLeft, &p_srcLeft,
&p_srcTop, &p_srcTop,
&p_dstLeft, &p_dstLeft,
@ -289,10 +286,13 @@ void MxBitmap::BitBlt(
&p_width, &p_width,
&p_height &p_height
)) { )) {
return;
}
MxU8* srcStart = p_src->GetStart(p_srcLeft, p_srcTop); MxU8* srcStart = p_src->GetStart(p_srcLeft, p_srcTop);
MxU8* dstStart = GetStart(p_dstLeft, p_dstTop); MxU8* dstStart = GetStart(p_dstLeft, p_dstTop);
MxLong srcStride = p_src->GetAdjustedStride(); MxLong srcStride = GetAdjustedStride(p_src);
MxLong dstStride = GetAdjustedStride(); MxLong dstStride = GetAdjustedStride(this);
while (p_height--) { while (p_height--) {
memcpy(dstStart, srcStart, p_width); memcpy(dstStart, srcStart, p_width);
@ -300,7 +300,6 @@ void MxBitmap::BitBlt(
srcStart += srcStride; srcStart += srcStride;
} }
} }
}
// FUNCTION: LEGO1 0x100bd020 // FUNCTION: LEGO1 0x100bd020
// FUNCTION: BETA10 0x1013d4ea // FUNCTION: BETA10 0x1013d4ea
@ -314,14 +313,11 @@ void MxBitmap::BitBltTransparent(
MxS32 p_height MxS32 p_height
) )
{ {
MxLong dstHeight = GetBmiHeightAbs(); if (!GetRectIntersection(
MxLong srcHeight = p_src->GetBmiHeightAbs();
if (GetRectIntersection(
p_src->GetBmiWidth(), p_src->GetBmiWidth(),
srcHeight, p_src->GetBmiHeightAbs(),
GetBmiWidth(), GetBmiWidth(),
dstHeight, GetBmiHeightAbs(),
&p_srcLeft, &p_srcLeft,
&p_srcTop, &p_srcTop,
&p_dstLeft, &p_dstLeft,
@ -329,10 +325,13 @@ void MxBitmap::BitBltTransparent(
&p_width, &p_width,
&p_height &p_height
)) { )) {
return;
}
MxU8* srcStart = p_src->GetStart(p_srcLeft, p_srcTop); MxU8* srcStart = p_src->GetStart(p_srcLeft, p_srcTop);
MxU8* dstStart = GetStart(p_dstLeft, p_dstTop); MxU8* dstStart = GetStart(p_dstLeft, p_dstTop);
MxLong srcStride = p_src->GetAdjustedStride() - p_width; MxLong srcStride = -p_width + GetAdjustedStride(p_src);
MxLong dstStride = GetAdjustedStride() - p_width; MxLong dstStride = -p_width + GetAdjustedStride(this);
for (MxS32 h = 0; h < p_height; h++) { for (MxS32 h = 0; h < p_height; h++) {
for (MxS32 w = 0; w < p_width; w++) { for (MxS32 w = 0; w < p_width; w++) {
@ -347,7 +346,6 @@ void MxBitmap::BitBltTransparent(
dstStart += dstStride; dstStart += dstStride;
} }
} }
}
// FUNCTION: LEGO1 0x100bd1c0 // FUNCTION: LEGO1 0x100bd1c0
// FUNCTION: BETA10 0x1013d684 // FUNCTION: BETA10 0x1013d684

View File

@ -7,6 +7,7 @@
#include "mxutilities.h" #include "mxutilities.h"
#include "mxvideomanager.h" #include "mxvideomanager.h"
#include <assert.h>
#include <windows.h> #include <windows.h>
DECOMP_SIZE_ASSERT(MxDisplaySurface, 0xac); DECOMP_SIZE_ASSERT(MxDisplaySurface, 0xac);
@ -319,6 +320,7 @@ void MxDisplaySurface::SetPalette(MxPalette* p_palette)
} }
// FUNCTION: LEGO1 0x100bacc0 // FUNCTION: LEGO1 0x100bacc0
// FUNCTION: BETA10 0x1014012b
void MxDisplaySurface::VTable0x28( void MxDisplaySurface::VTable0x28(
MxBitmap* p_bitmap, MxBitmap* p_bitmap,
MxS32 p_left, MxS32 p_left,
@ -329,7 +331,7 @@ void MxDisplaySurface::VTable0x28(
MxS32 p_height MxS32 p_height
) )
{ {
if (GetRectIntersection( if (!GetRectIntersection(
p_bitmap->GetBmiWidth(), p_bitmap->GetBmiWidth(),
p_bitmap->GetBmiHeightAbs(), p_bitmap->GetBmiHeightAbs(),
m_videoParam.GetRect().GetWidth(), m_videoParam.GetRect().GetWidth(),
@ -341,6 +343,8 @@ void MxDisplaySurface::VTable0x28(
&p_width, &p_width,
&p_height &p_height
)) { )) {
return;
}
DDSURFACEDESC ddsd; DDSURFACEDESC ddsd;
memset(&ddsd, 0, sizeof(ddsd)); memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd); ddsd.dwSize = sizeof(ddsd);
@ -351,7 +355,10 @@ void MxDisplaySurface::VTable0x28(
hr = m_ddSurface2->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL); hr = m_ddSurface2->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
} }
if (hr == DD_OK) { if (hr != DD_OK) {
return;
}
MxU8* data = p_bitmap->GetStart(p_left, p_top); MxU8* data = p_bitmap->GetStart(p_left, p_top);
if (m_videoParam.Flags().GetF1bit3()) { if (m_videoParam.Flags().GetF1bit3()) {
@ -361,21 +368,18 @@ void MxDisplaySurface::VTable0x28(
switch (m_surfaceDesc.ddpfPixelFormat.dwRGBBitCount) { switch (m_surfaceDesc.ddpfPixelFormat.dwRGBBitCount) {
case 8: { case 8: {
MxU8* surface = (MxU8*) ddsd.lpSurface + p_right + (p_bottom * ddsd.lPitch); MxU8* surface = (MxU8*) ddsd.lpSurface + p_right + (p_bottom * ddsd.lPitch);
MxLong stride = p_bitmap->GetAdjustedStride(); MxLong stride = -p_width + GetAdjustedStride(p_bitmap);
MxLong v22 = stride - p_width; MxLong length = -2 * p_width + ddsd.lPitch;
MxLong length = ddsd.lPitch - (2 * p_width);
while (p_height--) { while (p_height--) {
MxU8* surfaceBefore = surface; MxU8* surfaceBefore = surface;
for (MxS32 i = 0; p_width > i; i++) { for (MxS32 i = 0; p_width > i; i++) {
MxU8 element = *data; *surface++ = *data;
*surface++ = element; *surface++ = *data++;
data++;
*surface++ = *(data - 1);
} }
data += v22; data += stride;
surface += length; surface += length;
memcpy(surface, surfaceBefore, 2 * p_width); memcpy(surface, surfaceBefore, 2 * p_width);
@ -385,33 +389,30 @@ void MxDisplaySurface::VTable0x28(
} }
case 16: { case 16: {
MxU8* surface = (MxU8*) ddsd.lpSurface + (2 * p_right) + (p_bottom * ddsd.lPitch); MxU8* surface = (MxU8*) ddsd.lpSurface + (2 * p_right) + (p_bottom * ddsd.lPitch);
MxLong stride = p_bitmap->GetAdjustedStride(); MxLong stride = -p_width + GetAdjustedStride(p_bitmap);
// TODO: Match MxS32 length = -4 * p_width + ddsd.lPitch;
stride -= p_width;
MxS32 length = p_width * 4;
MxLong v62 = ddsd.lPitch - length;
MxS32 height = p_height; MxS32 height = p_height;
MxS32 width = p_width; MxS32 width = p_width;
MxU16* p16BitPal = m_16bitPal; MxS32 copyWidth = width * 4;
MxU16* p16bitPal = m_16bitPal;
if (stride || v62) { MxS32 i;
if (stride || length) {
while (height--) { while (height--) {
MxU8* surfaceBefore = surface; MxU8* surfaceBefore = surface;
for (MxS32 i = width; i > 0; i--) { for (i = 0; i < width; i++) {
MxU16 element = p16BitPal[*data++]; MxU16 element = p16bitPal[*data];
*(MxU16*) surface = element; *(MxU16*) surface = element;
surface += 2; surface += 2;
*(MxU16*) surface = element; *(MxU16*) surface = element;
data++;
surface += 2; surface += 2;
} }
data += stride; memcpy(surface, surfaceBefore, copyWidth);
surface += v62;
// Odd expression for the length?
memcpy(surface, surfaceBefore, 4 * ((MxU32) (4 * p_width) / 4));
surface += ddsd.lPitch; surface += ddsd.lPitch;
} }
} }
@ -419,26 +420,34 @@ void MxDisplaySurface::VTable0x28(
while (height--) { while (height--) {
MxU8* surfaceBefore = surface; MxU8* surfaceBefore = surface;
for (MxS32 i = width; i > 0; i--) { for (i = 0; i < width; i++) {
MxU16 element = p16BitPal[*data++]; MxU16 element = p16bitPal[*data];
*(MxU16*) surface = element; *(MxU16*) surface = element;
surface += 2; surface += 2;
*(MxU16*) surface = element; *(MxU16*) surface = element;
data++;
surface += 2; surface += 2;
} }
memcpy(surface, surfaceBefore, length); data += stride;
surface += length;
memcpy(surface, surfaceBefore, p_width * 4);
surface += ddsd.lPitch; surface += ddsd.lPitch;
} }
} }
break;
} }
default:
break;
} }
} }
else { else {
switch (m_surfaceDesc.ddpfPixelFormat.dwRGBBitCount) { switch (m_surfaceDesc.ddpfPixelFormat.dwRGBBitCount) {
case 8: { case 8: {
MxU8* surface = (MxU8*) ddsd.lpSurface + p_right + (p_bottom * ddsd.lPitch); MxU8* surface = (MxU8*) ddsd.lpSurface + p_right + (p_bottom * ddsd.lPitch);
MxLong stride = p_bitmap->GetAdjustedStride(); MxLong stride = GetAdjustedStride(p_bitmap);
MxLong length = ddsd.lPitch; MxLong length = ddsd.lPitch;
while (p_height--) { while (p_height--) {
@ -450,29 +459,30 @@ void MxDisplaySurface::VTable0x28(
} }
case 16: { case 16: {
MxU8* surface = (MxU8*) ddsd.lpSurface + (2 * p_right) + (p_bottom * ddsd.lPitch); MxU8* surface = (MxU8*) ddsd.lpSurface + (2 * p_right) + (p_bottom * ddsd.lPitch);
MxLong stride = p_bitmap->GetAdjustedStride(); MxLong stride = -p_width + GetAdjustedStride(p_bitmap);
MxLong v50 = stride - p_width; MxLong length = -2 * p_width + ddsd.lPitch;
MxLong length = ddsd.lPitch - (2 * p_width); for (MxS32 i = 0; i < p_height; i++) {
for (MxS32 i = 0; p_height > i; i++) { for (MxS32 j = 0; j < p_width; j++) {
for (MxS32 j = 0; p_width > j; j++) {
*(MxU16*) surface = m_16bitPal[*data++]; *(MxU16*) surface = m_16bitPal[*data++];
surface += 2; surface += 2;
} }
data += v50; data += stride;
surface += length; surface += length;
} }
break;
} }
default:
break;
} }
} }
m_ddSurface2->Unlock(ddsd.lpSurface); m_ddSurface2->Unlock(ddsd.lpSurface);
} }
}
}
// FUNCTION: LEGO1 0x100bb1d0 // FUNCTION: LEGO1 0x100bb1d0
// FUNCTION: BETA10 0x1014088e
void MxDisplaySurface::VTable0x30( void MxDisplaySurface::VTable0x30(
MxBitmap* p_bitmap, MxBitmap* p_bitmap,
MxS32 p_left, MxS32 p_left,
@ -484,7 +494,7 @@ void MxDisplaySurface::VTable0x30(
MxBool p_und MxBool p_und
) )
{ {
if (GetRectIntersection( if (!GetRectIntersection(
p_bitmap->GetBmiWidth(), p_bitmap->GetBmiWidth(),
p_bitmap->GetBmiHeightAbs(), p_bitmap->GetBmiHeightAbs(),
m_videoParam.GetRect().GetWidth(), m_videoParam.GetRect().GetWidth(),
@ -496,6 +506,8 @@ void MxDisplaySurface::VTable0x30(
&p_width, &p_width,
&p_height &p_height
)) { )) {
return;
}
DDSURFACEDESC ddsd; DDSURFACEDESC ddsd;
memset(&ddsd, 0, sizeof(ddsd)); memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd); ddsd.dwSize = sizeof(ddsd);
@ -506,32 +518,29 @@ void MxDisplaySurface::VTable0x30(
hr = m_ddSurface2->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL); hr = m_ddSurface2->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
} }
if (hr == DD_OK) { if (hr != DD_OK) {
return;
}
MxU8* data = p_bitmap->GetStart(p_left, p_top); MxU8* data = p_bitmap->GetStart(p_left, p_top);
switch (m_surfaceDesc.ddpfPixelFormat.dwRGBBitCount) { switch (m_surfaceDesc.ddpfPixelFormat.dwRGBBitCount) {
case 8: { case 8: {
MxU8* surface = (MxU8*) ddsd.lpSurface + p_right + (p_bottom * ddsd.lPitch); MxU8* surface = (MxU8*) ddsd.lpSurface + p_right + (p_bottom * ddsd.lPitch);
if (p_und) { if (p_und) {
FUN_100bb500( MxS32 size = p_bitmap->GetBmiHeader()->biSizeImage;
&data, FUN_100bb500(&data, &surface, size, p_width, p_height, ddsd.lPitch, 8);
&surface,
p_bitmap->GetBmiHeader()->biSizeImage,
p_width,
p_height,
ddsd.lPitch,
8
);
} }
else { else {
MxLong stride = p_bitmap->GetAdjustedStride(); MxLong stride = -p_width + GetAdjustedStride(p_bitmap);
MxLong length = ddsd.lPitch; MxLong length = -p_width + ddsd.lPitch;
for (MxS32 i = 0; p_height > i; i++) { for (MxS32 i = 0; i < p_height; i++) {
for (MxS32 j = 0; p_width > j; j++) { for (MxS32 j = 0; j < p_width; j++) {
if (*data != 0) { if (*data != 0) {
*(MxU8*) surface = *data; *surface = *data;
} }
data++; data++;
surface++; surface++;
} }
@ -545,43 +554,38 @@ void MxDisplaySurface::VTable0x30(
case 16: { case 16: {
MxU8* surface = (MxU8*) ddsd.lpSurface + (2 * p_right) + (p_bottom * ddsd.lPitch); MxU8* surface = (MxU8*) ddsd.lpSurface + (2 * p_right) + (p_bottom * ddsd.lPitch);
if (p_und) { if (p_und) {
FUN_100bb500( MxS32 size = p_bitmap->GetBmiHeader()->biSizeImage;
&data, FUN_100bb500(&data, &surface, size, p_width, p_height, ddsd.lPitch, 16);
&surface,
p_bitmap->GetBmiHeader()->biSizeImage,
p_width,
p_height,
ddsd.lPitch,
16
);
} }
else { else {
MxLong stride = p_bitmap->GetAdjustedStride(); MxLong stride = -p_width + GetAdjustedStride(p_bitmap);
MxLong v50 = stride - p_width; MxLong length = -2 * p_width + ddsd.lPitch;
MxLong length = ddsd.lPitch - (2 * p_width); for (MxS32 i = 0; i < p_height; i++) {
for (MxS32 i = 0; p_height > i; i++) { for (MxS32 j = 0; j < p_width; j++) {
for (MxS32 j = 0; p_width > j; j++) {
if (*data != 0) { if (*data != 0) {
*(MxU16*) surface = m_16bitPal[*data]; *(MxU16*) surface = m_16bitPal[*data];
} }
data++; data++;
surface += 2; surface += 2;
} }
data += v50; data += stride;
surface += length; surface += length;
} }
} }
break;
} }
default:
break;
} }
m_ddSurface2->Unlock(ddsd.lpSurface); m_ddSurface2->Unlock(ddsd.lpSurface);
} }
}
}
// STUB: LEGO1 0x100bb500 // STUB: LEGO1 0x100bb500
// STUB: BETA10 0x10140cd6
void MxDisplaySurface::FUN_100bb500( void MxDisplaySurface::FUN_100bb500(
MxU8** p_bitmapData, MxU8** p_bitmapData,
MxU8** p_surfaceData, MxU8** p_surfaceData,
@ -671,6 +675,7 @@ void MxDisplaySurface::ReleaseDC(HDC p_hdc)
} }
// FUNCTION: LEGO1 0x100bbc60 // FUNCTION: LEGO1 0x100bbc60
// FUNCTION: BETA10 0x10141745
LPDIRECTDRAWSURFACE MxDisplaySurface::VTable0x44( LPDIRECTDRAWSURFACE MxDisplaySurface::VTable0x44(
MxBitmap* p_bitmap, MxBitmap* p_bitmap,
undefined4* p_ret, undefined4* p_ret,
@ -680,7 +685,7 @@ LPDIRECTDRAWSURFACE MxDisplaySurface::VTable0x44(
{ {
LPDIRECTDRAWSURFACE surface = NULL; LPDIRECTDRAWSURFACE surface = NULL;
LPDIRECTDRAW draw = MVideoManager()->GetDirectDraw(); LPDIRECTDRAW draw = MVideoManager()->GetDirectDraw();
MVideoManager(); MxVideoParamFlags& flags = MVideoManager()->GetVideoParam().Flags();
DDSURFACEDESC ddsd; DDSURFACEDESC ddsd;
memset(&ddsd, 0, sizeof(ddsd)); memset(&ddsd, 0, sizeof(ddsd));
@ -693,9 +698,9 @@ LPDIRECTDRAWSURFACE MxDisplaySurface::VTable0x44(
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
ddsd.dwWidth = p_bitmap->GetBmiWidth(); ddsd.dwWidth = p_bitmap->GetBmiWidth();
ddsd.dwHeight = p_bitmap->GetBmiHeightAbs(); ddsd.dwHeight = p_bitmap->GetBmiHeightAbs();
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
*p_ret = 0; *p_ret = 0;
ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN; ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
if (draw->CreateSurface(&ddsd, &surface, NULL) != DD_OK) { if (draw->CreateSurface(&ddsd, &surface, NULL) != DD_OK) {
if (*p_ret) { if (*p_ret) {
@ -721,29 +726,26 @@ LPDIRECTDRAWSURFACE MxDisplaySurface::VTable0x44(
if (surface->Lock(NULL, &ddsd, DDLOCK_WAIT, 0) != DD_OK) { if (surface->Lock(NULL, &ddsd, DDLOCK_WAIT, 0) != DD_OK) {
surface->Release(); surface->Release();
surface = NULL; surface = NULL;
goto done;
} }
else if (p_doNotWriteToSurface) {
if (p_doNotWriteToSurface) { assert(0);
goto done;
} }
else {
MxU8* bitmapSrcPtr = p_bitmap->GetStart(0, 0); MxU8* bitmapSrcPtr = p_bitmap->GetStart(0, 0);
MxU16* surfaceData = (MxU16*) ddsd.lpSurface; MxU16* surfaceData = (MxU16*) ddsd.lpSurface;
MxLong widthNormal = p_bitmap->GetBmiWidth(); MxLong widthNormal = p_bitmap->GetBmiWidth();
MxLong heightAbs = p_bitmap->GetBmiHeightAbs(); MxLong heightAbs = p_bitmap->GetBmiHeightAbs();
// TODO: Probably p_bitmap->GetAdjustedStride() MxLong newPitch = ddsd.lPitch;
MxS32 rowSeek = p_bitmap->GetBmiStride(); MxS32 rowSeek = p_bitmap->AlignToFourByte(p_bitmap->GetBmiWidth());
if (p_bitmap->GetBmiHeader()->biCompression != BI_RGB_TOPDOWN && p_bitmap->GetBmiHeight() >= 0) { if (!p_bitmap->IsTopDown()) {
rowSeek = -rowSeek; rowSeek *= -1;
} }
MxLong newPitch = ddsd.lPitch;
switch (ddsd.ddpfPixelFormat.dwRGBBitCount) { switch (ddsd.ddpfPixelFormat.dwRGBBitCount) {
case 8: { case 8: {
for (MxS32 y = heightAbs; y > 0; y--) { for (MxS32 y = 0; y < heightAbs; y++) {
memcpy(surfaceData, bitmapSrcPtr, p_bitmap->GetBmiHeight()); memcpy(surfaceData, bitmapSrcPtr, widthNormal);
bitmapSrcPtr += rowSeek; bitmapSrcPtr += rowSeek;
surfaceData = (MxU16*) ((MxU8*) surfaceData + newPitch); surfaceData = (MxU16*) ((MxU8*) surfaceData + newPitch);
} }
@ -752,32 +754,29 @@ LPDIRECTDRAWSURFACE MxDisplaySurface::VTable0x44(
if (p_transparent && surface) { if (p_transparent && surface) {
DDCOLORKEY key; DDCOLORKEY key;
key.dwColorSpaceHighValue = 0; key.dwColorSpaceLowValue = key.dwColorSpaceHighValue = 0;
key.dwColorSpaceLowValue = 0;
surface->SetColorKey(DDCKEY_SRCBLT, &key); surface->SetColorKey(DDCKEY_SRCBLT, &key);
} }
break; break;
} }
case 16: case 16: {
if (m_16bitPal == NULL) { if (m_16bitPal == NULL) {
if (surface) { goto error;
surface->Release();
} }
return NULL;
} rowSeek -= widthNormal;
else { newPitch -= 2 * widthNormal;
rowSeek -= p_bitmap->GetBmiWidth();
newPitch -= 2 * p_bitmap->GetBmiWidth();
if (p_transparent) { if (p_transparent) {
for (MxS32 y = heightAbs; y > 0; y--) { for (MxS32 y = 0; y < heightAbs; y++) {
for (MxS32 x = widthNormal; x > 0; x--) { for (MxS32 x = 0; x < widthNormal; x++) {
if (*bitmapSrcPtr) { if (*bitmapSrcPtr == NULL) {
*surfaceData = m_16bitPal[*bitmapSrcPtr];
}
else {
*surfaceData = 31775; *surfaceData = 31775;
} }
else {
*surfaceData = m_16bitPal[*bitmapSrcPtr];
}
bitmapSrcPtr++; bitmapSrcPtr++;
surfaceData++; surfaceData++;
} }
@ -787,13 +786,12 @@ LPDIRECTDRAWSURFACE MxDisplaySurface::VTable0x44(
} }
DDCOLORKEY key; DDCOLORKEY key;
key.dwColorSpaceHighValue = 31775; key.dwColorSpaceLowValue = key.dwColorSpaceHighValue = 31775;
key.dwColorSpaceLowValue = 31775;
surface->SetColorKey(DDCKEY_SRCBLT, &key); surface->SetColorKey(DDCKEY_SRCBLT, &key);
} }
else { else {
for (MxS32 y = heightAbs; y > 0; y--) { for (MxS32 y = 0; y < heightAbs; y++) {
for (MxS32 x = widthNormal; x > 0; x--) { for (MxS32 x = 0; x < widthNormal; x++) {
*surfaceData++ = m_16bitPal[*bitmapSrcPtr++]; *surfaceData++ = m_16bitPal[*bitmapSrcPtr++];
} }
@ -803,12 +801,20 @@ LPDIRECTDRAWSURFACE MxDisplaySurface::VTable0x44(
} }
surface->Unlock(ddsd.lpSurface); surface->Unlock(ddsd.lpSurface);
break;
}
} }
} }
} }
done:
return surface; return surface;
error:
if (surface) {
surface->Release();
}
return NULL;
} }
// FUNCTION: LEGO1 0x100bbfb0 // FUNCTION: LEGO1 0x100bbfb0