Skip to content

Commit 2bc7af1

Browse files
Joachim Priesnerivyl
Joachim Priesner
authored andcommitted
windowscodecs: BitmapScaler_CopyPixels: Do not demand a larger buffer than necessary.
Only `bytesperrow` bytes are written to each row of the output rect. Therefore the last row need not be padded to `cbStride` bytes. Signed-off-by: Joachim Priesner <joachim.priesner@web.de> Signed-off-by: Esme Povirk <esme@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> (cherry picked from commit cdb9a27) Fix for the black texture problem in BeamNG.drive. Link: #160
1 parent f915d55 commit 2bc7af1

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

dlls/windowscodecs/scaler.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ static HRESULT WINAPI BitmapScaler_CopyPixels(IWICBitmapScaler *iface,
251251
goto end;
252252
}
253253

254-
if ((cbStride * dest_rect.Height) > cbBufferSize)
254+
if (cbStride * (dest_rect.Height - 1) + bytesperrow > cbBufferSize)
255255
{
256256
hr = E_INVALIDARG;
257257
goto end;

dlls/windowscodecs/tests/bitmap.c

+8-5
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ static void test_bitmap_scaler(void)
11511151
double res_x, res_y;
11521152
IWICBitmap *bitmap;
11531153
UINT width, height;
1154-
BYTE buf[16];
1154+
BYTE buf[93]; /* capable of holding a 7*4px, 24bpp image with stride 24 -> buffer size = 3*24+21 */
11551155
HRESULT hr;
11561156

11571157
hr = IWICImagingFactory_CreateBitmap(factory, 4, 2, &GUID_WICPixelFormat24bppBGR, WICBitmapCacheOnLoad, &bitmap);
@@ -1243,28 +1243,28 @@ static void test_bitmap_scaler(void)
12431243
WICBitmapInterpolationModeNearestNeighbor);
12441244
ok(hr == E_INVALIDARG, "Failed to initialize bitmap scaler, hr %#x.\n", hr);
12451245

1246-
hr = IWICBitmapScaler_Initialize(scaler, (IWICBitmapSource *)bitmap, 8, 4,
1246+
hr = IWICBitmapScaler_Initialize(scaler, (IWICBitmapSource *)bitmap, 7, 4,
12471247
WICBitmapInterpolationModeNearestNeighbor);
12481248
ok(hr == S_OK, "Failed to initialize bitmap scaler, hr %#x.\n", hr);
12491249

12501250
hr = IWICBitmapScaler_Initialize(scaler, (IWICBitmapSource *)bitmap, 0, 4,
12511251
WICBitmapInterpolationModeNearestNeighbor);
12521252
ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
12531253

1254-
hr = IWICBitmapScaler_Initialize(scaler, (IWICBitmapSource *)bitmap, 8, 0,
1254+
hr = IWICBitmapScaler_Initialize(scaler, (IWICBitmapSource *)bitmap, 7, 0,
12551255
WICBitmapInterpolationModeNearestNeighbor);
12561256
ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
12571257

12581258
hr = IWICBitmapScaler_Initialize(scaler, NULL, 8, 4, WICBitmapInterpolationModeNearestNeighbor);
12591259
ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
12601260

1261-
hr = IWICBitmapScaler_Initialize(scaler, (IWICBitmapSource *)bitmap, 8, 4,
1261+
hr = IWICBitmapScaler_Initialize(scaler, (IWICBitmapSource *)bitmap, 7, 4,
12621262
WICBitmapInterpolationModeNearestNeighbor);
12631263
ok(hr == WINCODEC_ERR_WRONGSTATE, "Unexpected hr %#x.\n", hr);
12641264

12651265
hr = IWICBitmapScaler_GetSize(scaler, &width, &height);
12661266
ok(hr == S_OK, "Failed to get scaler size, hr %#x.\n", hr);
1267-
ok(width == 8, "Unexpected width %u.\n", width);
1267+
ok(width == 7, "Unexpected width %u.\n", width);
12681268
ok(height == 4, "Unexpected height %u.\n", height);
12691269

12701270
hr = IWICBitmapScaler_GetSize(scaler, NULL, &height);
@@ -1307,6 +1307,9 @@ static void test_bitmap_scaler(void)
13071307
ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "Unexpected hr %#x.\n", hr);
13081308
IWICPalette_Release(palette);
13091309

1310+
hr = IWICBitmapScaler_CopyPixels(scaler, NULL, /*cbStride=*/24, sizeof(buf), buf);
1311+
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1312+
13101313
IWICBitmapScaler_Release(scaler);
13111314

13121315
IWICBitmap_Release(bitmap);

0 commit comments

Comments
 (0)