IDirect3DTexture::InitFromFile attempts to create a palette-based image, but currently it is flipping the red and blue components of the palette. This MR fixes this in both test and code.
From: Jeff Smith whydoubt@gmail.com
In BMP files with 24-bit depth, color components are stored in BGR order. Due to magic values being used several places in tests to reduce the components, some logical errors are hard to spot.
Give names to the magic values to make logical errors more apparent. --- dlls/d3drm/tests/d3drm.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/dlls/d3drm/tests/d3drm.c b/dlls/d3drm/tests/d3drm.c index 5745fea4b09..87986547a4d 100644 --- a/dlls/d3drm/tests/d3drm.c +++ b/dlls/d3drm/tests/d3drm.c @@ -6145,6 +6145,10 @@ static void test_create_device_3(void) IDirect3DRM_Release(d3drm); }
+#define MOD_R 247 +#define MOD_G 239 +#define MOD_B 251 + static char *create_bitmap(unsigned int w, unsigned int h, BOOL palettized) { unsigned int bpp = palettized ? 8 : 24; @@ -6205,9 +6209,9 @@ static char *create_bitmap(unsigned int w, unsigned int h, BOOL palettized) } else { - buffer[i++] = j % 251; - buffer[i++] = j % 239; - buffer[i++] = j++ % 247; + buffer[i++] = j % MOD_B; + buffer[i++] = j % MOD_G; + buffer[i++] = j++ % MOD_R; } } ret = WriteFile(file, buffer, size, &written, NULL); @@ -6253,11 +6257,11 @@ static void test_bitmap_data(unsigned int test_idx, const D3DRMIMAGE *img, const unsigned char *ptr = &data[i * img->bytes_per_line + j * 4]; unsigned int idx = upside_down ? (h - 1 - i) * w + j : i * w + j;
- if (ptr[0] != idx % 251 || ptr[1] != idx % 239 || ptr[2] != idx % 247 || ptr[3] != 0xff) + if (ptr[0] != idx % MOD_B || ptr[1] != idx % MOD_G || ptr[2] != idx % MOD_R || ptr[3] != 0xff) { ok(0, "Test %u: Got unexpected color 0x%02x%02x%02x%02x at position %u, %u, " "expected 0x%02x%02x%02x%02x.\n", test_idx, ptr[0], ptr[1], ptr[2], ptr[3], - j, i, idx % 251, idx % 239, idx % 247, 0xff); + j, i, idx % MOD_B, idx % MOD_G, idx % MOD_R, 0xff); return; } } @@ -6283,8 +6287,8 @@ static void test_bitmap_data(unsigned int test_idx, const D3DRMIMAGE *img, for (i = 0; i < img->palette_size; ++i) { unsigned int idx = upside_down ? (h - 1) * w - i + (i % w) * 2 : i; - ok(img->palette[i].red == idx % 251 - && img->palette[i].green == idx % 239 && img->palette[i].blue == idx % 247, + ok(img->palette[i].red == idx % MOD_B + && img->palette[i].green == idx % MOD_G && img->palette[i].blue == idx % MOD_R, "Test %u: Got unexpected palette entry (%u) color 0x%02x%02x%02x.\n", test_idx, i, img->palette[i].red, img->palette[i].green, img->palette[i].blue); ok(img->palette[i].flags == D3DRMPALETTE_READONLY,
From: Jeff Smith whydoubt@gmail.com
Fix the pallete-building code used by IDirect3DTexture::InitFromFile to use color components correctly. Also, fix and expand the tests to properly check the components of a built palette. --- dlls/d3drm/tests/d3drm.c | 5 +++-- dlls/d3drm/texture.c | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/dlls/d3drm/tests/d3drm.c b/dlls/d3drm/tests/d3drm.c index 87986547a4d..3153f7191f4 100644 --- a/dlls/d3drm/tests/d3drm.c +++ b/dlls/d3drm/tests/d3drm.c @@ -6287,8 +6287,8 @@ static void test_bitmap_data(unsigned int test_idx, const D3DRMIMAGE *img, for (i = 0; i < img->palette_size; ++i) { unsigned int idx = upside_down ? (h - 1) * w - i + (i % w) * 2 : i; - ok(img->palette[i].red == idx % MOD_B - && img->palette[i].green == idx % MOD_G && img->palette[i].blue == idx % MOD_R, + ok(img->palette[i].red == idx % MOD_R + && img->palette[i].green == idx % MOD_G && img->palette[i].blue == idx % MOD_B, "Test %u: Got unexpected palette entry (%u) color 0x%02x%02x%02x.\n", test_idx, i, img->palette[i].red, img->palette[i].green, img->palette[i].blue); ok(img->palette[i].flags == D3DRMPALETTE_READONLY, @@ -6367,6 +6367,7 @@ static void test_load_texture(void) {100, 100, FALSE}, {99, 100, FALSE}, {3, 39, FALSE}, + {16, 16, FALSE}, };
hr = Direct3DRMCreate(&d3drm1); diff --git a/dlls/d3drm/texture.c b/dlls/d3drm/texture.c index a60317b48bc..29e304d8598 100644 --- a/dlls/d3drm/texture.c +++ b/dlls/d3drm/texture.c @@ -103,9 +103,9 @@ static BOOL d3drm_image_palettise(D3DRMIMAGE *image, unsigned char *src_data, for (i = 0; i < colour_count; ++i) { entry = &palette[i]; - if (entry->red == src_ptr[x * 3 + 0] + if (entry->red == src_ptr[x * 3 + 2] && entry->green == src_ptr[x * 3 + 1] - && entry->blue == src_ptr[x * 3 + 2]) + && entry->blue == src_ptr[x * 3 + 0]) break; }
@@ -119,9 +119,9 @@ static BOOL d3drm_image_palettise(D3DRMIMAGE *image, unsigned char *src_data, }
entry = &palette[colour_count++]; - entry->red = src_ptr[x * 3 + 0]; + entry->red = src_ptr[x * 3 + 2]; entry->green = src_ptr[x * 3 + 1]; - entry->blue = src_ptr[x * 3 + 2]; + entry->blue = src_ptr[x * 3 + 0]; entry->flags = D3DRMPALETTE_READONLY; }