From ddddc9d5d2ca27d0a4d47e78c0745b749961ef4d Mon Sep 17 00:00:00 2001 From: disinvite Date: Sat, 14 Oct 2023 15:03:19 -0400 Subject: [PATCH] More accurate pointer math for the 16-bit case --- LEGO1/mxtransitionmanager.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/LEGO1/mxtransitionmanager.cpp b/LEGO1/mxtransitionmanager.cpp index 5428a92b..a7b1ba3d 100644 --- a/LEGO1/mxtransitionmanager.cpp +++ b/LEGO1/mxtransitionmanager.cpp @@ -318,7 +318,10 @@ void MxTransitionManager::Transition_Pixelation() } else { MxU32 new_color = MAKELONG(sample, sample); - MxU8 *pos = surface + k * ddsd.lPitch + x_shift; + // You might expect a cast to MxU16* instead, but lPitch is + // bytes/scanline, not pixels/scanline. Therefore, we just + // need to double the x_shift to get to the right spot. + MxU8 *pos = surface + k * ddsd.lPitch + 2*x_shift; MxU32 *dest = (MxU32*)pos; // Sets 10 pixels (20 bytes) dest[0] = new_color;