Load_ClipBoard_Image() fix

lines are aligned on DWORD boundaries
This commit is contained in:
Thomas Bernard 2018-12-20 13:04:10 +01:00
parent 7ce94604a3
commit ec6d619efa

View File

@ -1273,7 +1273,9 @@ static void Load_ClipBoard_Image(T_IO_Context * context)
if (clipboard != NULL) if (clipboard != NULL)
{ {
const PBITMAPINFO bmi = (PBITMAPINFO)GlobalLock(clipboard); const PBITMAPINFO bmi = (PBITMAPINFO)GlobalLock(clipboard);
if (bmi != NULL) if (bmi == NULL)
GFX2_Log(GFX2_ERROR, "GlobalLock() failed error 0x%08x\n", GetLastError());
else
{ {
unsigned long width, height; unsigned long width, height;
width = bmi->bmiHeader.biWidth; width = bmi->bmiHeader.biWidth;
@ -1317,9 +1319,9 @@ static void Load_ClipBoard_Image(T_IO_Context * context)
{ {
const byte * line; const byte * line;
if (bmi->bmiHeader.biHeight > 0) if (bmi->bmiHeader.biHeight > 0)
line = pixels + (height - y - 1) * bmi->bmiHeader.biWidth; line = pixels + (height - y - 1) * ((bmi->bmiHeader.biWidth + 3) & ~3);
else else
line = pixels + y * bmi->bmiHeader.biWidth; line = pixels + y * ((bmi->bmiHeader.biWidth + 3) & ~3);
for (x = 0; x < width; x++) for (x = 0; x < width; x++)
Set_pixel(context, x, y, line[x]); Set_pixel(context, x, y, line[x]);
} }
@ -1327,11 +1329,11 @@ static void Load_ClipBoard_Image(T_IO_Context * context)
case 24: case 24:
for (y = 0; y < height; y++) for (y = 0; y < height; y++)
{ {
const byte * line; const byte * line = pixels;
if (bmi->bmiHeader.biHeight > 0) if (bmi->bmiHeader.biHeight > 0)
line = pixels + (height - y - 1) * bmi->bmiHeader.biWidth * 3; line += (height - y - 1) * ((bmi->bmiHeader.biWidth * 3 + 3) & ~3);
else else
line = pixels + y * bmi->bmiHeader.biWidth * 3; line += y * ((bmi->bmiHeader.biWidth * 3 + 3) & ~3);
for (x = 0; x < width; x++) for (x = 0; x < width; x++)
Set_pixel_24b(context, x, y, line[x*3 + 2], line[x*3 + 1], line[x*3]); Set_pixel_24b(context, x, y, line[x*3 + 2], line[x*3 + 1], line[x*3]);
} }