Added patch to fix implementation of ICGetDisplayFormat.

This commit is contained in:
Sebastian Lackner 2016-03-31 02:56:10 +02:00
parent 98284e0a1e
commit 086b729ec2
3 changed files with 404 additions and 0 deletions

View File

@ -0,0 +1,384 @@
From 396e4a11fbc0773d9519e84ff0d77c3ff3ec6efc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Thu, 31 Mar 2016 00:58:04 +0200
Subject: msvfw32: Try different formarts in ICGetDisplayFormat.
---
dlls/msvfw32/msvideo_main.c | 88 ++++++++++++----
dlls/msvfw32/tests/msvfw.c | 240 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 307 insertions(+), 21 deletions(-)
diff --git a/dlls/msvfw32/msvideo_main.c b/dlls/msvfw32/msvideo_main.c
index 4f1a2bf..28f405e 100644
--- a/dlls/msvfw32/msvideo_main.c
+++ b/dlls/msvfw32/msvideo_main.c
@@ -719,24 +719,79 @@ HIC VFWAPI ICGetDisplayFormat(
HIC hic,LPBITMAPINFOHEADER lpbiIn,LPBITMAPINFOHEADER lpbiOut,
INT depth,INT dx,INT dy)
{
- HIC tmphic = hic;
+ static const struct
+ {
+ int depth;
+ int compression;
+ }
+ try_depths[] =
+ {
+ { 8, BI_RGB},
+ {16, BI_RGB},
+ {16, BI_BITFIELDS},
+ {24, BI_RGB},
+ {32, BI_RGB},
+ };
- TRACE("(%p,%p,%p,%d,%d,%d)!\n",hic,lpbiIn,lpbiOut,depth,dx,dy);
+ int screen_depth, i;
+ BOOL found = FALSE;
+ HIC tmphic;
+ HDC hdc;
- if (!tmphic) {
- tmphic=ICLocate(ICTYPE_VIDEO,0,lpbiIn,NULL,ICMODE_DECOMPRESS);
- if (!tmphic)
- return tmphic;
- }
- if ((dy == lpbiIn->biHeight) && (dx == lpbiIn->biWidth))
- dy = dx = 0; /* no resize needed */
+ TRACE("(%p,%p,%p,%d,%d,%d)!\n", hic, lpbiIn, lpbiOut, depth, dx, dy);
+
+ tmphic = hic ? hic : ICLocate(ICTYPE_VIDEO, 0, lpbiIn, NULL, ICMODE_DECOMPRESS);
+ if (!tmphic) return tmphic;
+
+ hdc = GetDC(0);
+ screen_depth = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
+ ReleaseDC(0, hdc);
+
+ if (!dx) dx = lpbiIn->biWidth;
+ if (!dy) dy = lpbiIn->biHeight;
+ if (!depth) depth = screen_depth;
/* Can we decompress it ? */
- if (ICDecompressQuery(tmphic,lpbiIn,NULL) != 0)
+ if (ICDecompressQuery(tmphic, lpbiIn, NULL) != ICERR_OK)
goto errout; /* no, sorry */
ICSendMessage(tmphic, ICM_DECOMPRESS_GET_FORMAT, (DWORD_PTR)lpbiIn, (DWORD_PTR)lpbiOut);
+ lpbiOut->biSize = sizeof(BITMAPINFOHEADER);
+ lpbiOut->biWidth = dx;
+ lpbiOut->biHeight = dy;
+ lpbiOut->biPlanes = 1;
+ lpbiOut->biSizeImage = 0;
+
+ for (i = 0; i < sizeof(try_depths) / sizeof(try_depths[0]); i++)
+ {
+ if (!found && try_depths[i].depth != depth)
+ continue;
+
+ found = TRUE;
+ lpbiOut->biBitCount = try_depths[i].depth;
+ lpbiOut->biCompression = try_depths[i].compression;
+
+ if (ICDecompressQuery(tmphic, lpbiIn, lpbiOut) == ICERR_OK)
+ goto success;
+ }
+
+ if (!found)
+ {
+ lpbiOut->biBitCount = depth;
+ lpbiOut->biCompression = BI_RGB;
+ if (ICDecompressQuery(tmphic, lpbiIn, lpbiOut) == ICERR_OK)
+ goto success;
+
+ lpbiOut->biBitCount = screen_depth;
+ lpbiOut->biCompression = BI_RGB;
+ if (ICDecompressQuery(tmphic, lpbiIn, lpbiOut) == ICERR_OK)
+ goto success;
+ }
+
+ if (ICSendMessage(tmphic, ICM_DECOMPRESS_GET_FORMAT, (DWORD_PTR)lpbiIn, (DWORD_PTR)lpbiOut))
+ goto errout;
+
if (lpbiOut->biCompression != 0) {
FIXME("Ooch, how come decompressor outputs compressed data (%d)??\n",
lpbiOut->biCompression);
@@ -746,20 +801,11 @@ HIC VFWAPI ICGetDisplayFormat(
lpbiOut->biSize);
lpbiOut->biSize = sizeof(*lpbiOut);
}
- if (!depth) {
- HDC hdc;
-
- hdc = GetDC(0);
- depth = GetDeviceCaps(hdc,BITSPIXEL)*GetDeviceCaps(hdc,PLANES);
- ReleaseDC(0,hdc);
- if (depth==15) depth = 16;
- if (depth<8) depth = 8;
- }
- if (lpbiIn->biBitCount == 8)
- depth = 8;
+success:
TRACE("=> %p\n", tmphic);
return tmphic;
+
errout:
if (hic!=tmphic)
ICClose(tmphic);
diff --git a/dlls/msvfw32/tests/msvfw.c b/dlls/msvfw32/tests/msvfw.c
index 125cac5..7fd4c43 100644
--- a/dlls/msvfw32/tests/msvfw.c
+++ b/dlls/msvfw32/tests/msvfw.c
@@ -285,9 +285,249 @@ static void test_ICSeqCompress(void)
ok(err == ICERR_BADHANDLE, "Expected -8, got %d\n", err);
}
+struct msg_result
+{
+ int msg_index;
+ UINT msg;
+ BOOL output_format;
+ int width;
+ int height;
+ int bits;
+ int compression;
+ LRESULT result;
+ BOOL todo;
+};
+
+static struct msg_result expected_msgs[] =
+{
+ /* Wine bug - shouldn't be called */
+ { 0, DRV_LOAD, FALSE, 0, 0, 0, 0, TRUE, TRUE},
+ { 0, DRV_ENABLE, FALSE, 0, 0, 0, 0, 0, TRUE},
+
+ { 0, DRV_OPEN, FALSE, 0, 0, 0, 0, 0xdeadbeef, FALSE},
+
+ /* test 1 */
+ { 1, ICM_DECOMPRESS_QUERY, FALSE, 0, 0, 0, 0, ICERR_OK, FALSE},
+ { 2, ICM_DECOMPRESS_GET_FORMAT, TRUE, 320, 240, 16, BI_RGB, ICERR_BADFORMAT, FALSE},
+ { 3, ICM_DECOMPRESS_QUERY, TRUE, 640, 480, 8, BI_RGB, ICERR_BADFORMAT, FALSE},
+ { 4, ICM_DECOMPRESS_QUERY, TRUE, 640, 480, 16, BI_RGB, ICERR_BADFORMAT, FALSE},
+ { 5, ICM_DECOMPRESS_QUERY, TRUE, 640, 480, 16, BI_BITFIELDS, ICERR_BADFORMAT, FALSE},
+ { 6, ICM_DECOMPRESS_QUERY, TRUE, 640, 480, 24, BI_RGB, ICERR_BADFORMAT, FALSE},
+ { 7, ICM_DECOMPRESS_QUERY, TRUE, 640, 480, 32, BI_RGB, ICERR_BADFORMAT, FALSE},
+ { 8, ICM_DECOMPRESS_GET_FORMAT, TRUE, 640, 480, 32, BI_RGB, ICERR_OK, FALSE},
+
+ /* test 2 */
+ { 9, ICM_DECOMPRESS_QUERY, FALSE, 0, 0, 0, 0, ICERR_OK, FALSE},
+ {10, ICM_DECOMPRESS_GET_FORMAT, TRUE, 320, 240, 16, BI_RGB, ICERR_BADFORMAT, FALSE},
+ {11, ICM_DECOMPRESS_QUERY, TRUE, 640, 480, 8, BI_RGB, ICERR_BADFORMAT, FALSE},
+ {12, ICM_DECOMPRESS_QUERY, TRUE, 640, 480, 16, BI_RGB, ICERR_OK, FALSE},
+
+ /* test 3 */
+ {13, ICM_DECOMPRESS_QUERY, FALSE, 0, 0, 0, 0, ICERR_OK, FALSE},
+ {14, ICM_DECOMPRESS_GET_FORMAT, TRUE, 320, 240, 16, BI_RGB, ICERR_OK, FALSE},
+ {15, ICM_DECOMPRESS_QUERY, TRUE, 640, 480, 8, BI_RGB, ICERR_BADFORMAT, FALSE},
+ {16, ICM_DECOMPRESS_QUERY, TRUE, 640, 480, 16, BI_RGB, ICERR_OK, FALSE},
+
+ /* test 4 */
+ {17, ICM_DECOMPRESS_QUERY, FALSE, 0, 0, 0, 0, ICERR_OK, FALSE},
+ {18, ICM_DECOMPRESS_GET_FORMAT, TRUE, 320, 240, 16, BI_RGB, ICERR_BADFORMAT, FALSE},
+ {19, ICM_DECOMPRESS_QUERY, TRUE, 640, 480, 24, BI_RGB, ICERR_BADFORMAT, FALSE},
+ {20, ICM_DECOMPRESS_QUERY, TRUE, 640, 480, 32, BI_RGB, ICERR_BADFORMAT, FALSE},
+ {21, ICM_DECOMPRESS_GET_FORMAT, TRUE, 640, 480, 32, BI_RGB, ICERR_OK, FALSE},
+
+ /* test 5 */
+ {22, ICM_DECOMPRESS_QUERY, FALSE, 0, 0, 0, 0, ICERR_OK, FALSE},
+ {23, ICM_DECOMPRESS_GET_FORMAT, TRUE, 320, 240, 16, BI_RGB, ICERR_OK, FALSE},
+ {24, ICM_DECOMPRESS_QUERY, TRUE, 640, 480, 32, BI_RGB, ICERR_OK, FALSE},
+
+ /* test 6 */
+ {25, ICM_DECOMPRESS_QUERY, FALSE, 0, 0, 0, 0, ICERR_OK, FALSE},
+ {26, ICM_DECOMPRESS_GET_FORMAT, TRUE, 320, 240, 16, BI_RGB, ICERR_OK, FALSE},
+ {27, ICM_DECOMPRESS_QUERY, TRUE, 640, 480, 32, BI_RGB, ICERR_OK, FALSE},
+
+ /* test 7 */
+ {28, ICM_DECOMPRESS_QUERY, FALSE, 0, 0, 0, 0, ICERR_OK, FALSE},
+ {29, ICM_DECOMPRESS_GET_FORMAT, TRUE, 320, 240, 16, BI_RGB, ICERR_OK, FALSE},
+ {30, ICM_DECOMPRESS_QUERY, TRUE, 640, 480, 9, BI_RGB, ICERR_BADFORMAT, FALSE},
+ {31, ICM_DECOMPRESS_QUERY, TRUE, 640, 480, 32, BI_RGB, ICERR_BADFORMAT, FALSE},
+ {32, ICM_DECOMPRESS_GET_FORMAT, TRUE, 640, 480, 32, BI_RGB, ICERR_OK, FALSE},
+
+ /* test 8 */
+ {33, ICM_DECOMPRESS_QUERY, FALSE, 0, 0, 0, 0, ICERR_OK, FALSE},
+ {34, ICM_DECOMPRESS_GET_FORMAT, TRUE, 320, 240, 16, BI_RGB, ICERR_OK, FALSE},
+ {35, ICM_DECOMPRESS_QUERY, TRUE, 800, 600, 32, BI_RGB, ICERR_OK, FALSE},
+
+ /* Wine bug - shouldn't be called */
+ {36, DRV_DISABLE, FALSE, 0, 0, 0, 0, ICERR_OK, TRUE},
+ {36, DRV_FREE, FALSE, 0, 0, 0, 0, ICERR_OK, TRUE},
+};
+
+static int msg_index = 0;
+
+static struct msg_result *get_expected_msg(UINT msg)
+{
+ int i = 0;
+ for(; i < sizeof(expected_msgs) / sizeof(expected_msgs[0]); i++)
+ {
+ if (expected_msgs[i].msg_index == msg_index && expected_msgs[i].msg == msg)
+ return &expected_msgs[i];
+ }
+ return NULL;
+}
+
+LRESULT WINAPI driver_proc_test(DWORD_PTR dwDriverId, HDRVR hdrvr, UINT msg,
+ LPARAM lParam1, LPARAM lParam2)
+{
+ struct msg_result *expected = get_expected_msg(msg);
+ LRESULT res = expected ? expected->result : ICERR_UNSUPPORTED;
+
+ if (msg == DRV_CLOSE)
+ return ICERR_OK;
+
+ if (!expected)
+ {
+ ok(0, "unexpected message: %04x %ld %ld at msg index %d\n",
+ msg, lParam1, lParam2, msg_index);
+ return ICERR_UNSUPPORTED;
+ }
+ else if (expected->todo)
+ {
+ todo_wine ok(0, "unexpected message: %04x %ld %ld at msg index %d\n",
+ msg, lParam1, lParam2, msg_index);
+ return res;
+ }
+
+ switch (msg)
+ {
+ case ICM_DECOMPRESS_QUERY:
+ {
+ BITMAPINFOHEADER *out = (BITMAPINFOHEADER *)lParam2;
+
+ if (!lParam2)
+ {
+ trace("query -> without format\n");
+ ok(!expected->output_format, "Expected no output format pointer\n");
+ break;
+ }
+
+ ok(expected->output_format, "Expected output format pointer\n");
+ ok(out->biWidth == expected->width,
+ "Expected width %d, got %d\n", expected->width, out->biWidth);
+ ok(out->biHeight == expected->height,
+ "Expected height %d, got %d\n", expected->height, out->biHeight);
+ ok(out->biBitCount == expected->bits,
+ "Expected biBitCount %d, got %d\n", expected->bits, out->biBitCount);
+ ok(out->biCompression == expected->compression,
+ "Expected compression %d, got %d\n", expected->compression, out->biCompression);
+
+ trace("query -> width: %d, height: %d, bit: %d, compression: %d\n",
+ out->biWidth, out->biHeight, out->biBitCount, out->biCompression);
+ break;
+ }
+
+ case ICM_DECOMPRESS_GET_FORMAT:
+ {
+ BITMAPINFOHEADER *out = (BITMAPINFOHEADER *)lParam2;
+
+ if (!lParam2)
+ {
+ trace("format -> without format\n");
+ ok(!expected->output_format, "Expected no output format pointer\n");
+ break;
+ }
+
+ ok(expected->output_format, "Expected output format pointer\n");
+ ok(out->biWidth == expected->width,
+ "Expected width %d, got %d\n", expected->width, out->biWidth);
+ ok(out->biHeight == expected->height,
+ "Expected height %d, got %d\n", expected->height, out->biHeight);
+ ok(out->biBitCount == expected->bits,
+ "Expected biBitCount %d, got %d\n", expected->bits, out->biBitCount);
+ ok(out->biCompression == expected->compression,
+ "Expected compression %d, got %d\n", expected->compression, out->biCompression);
+
+ trace("format -> width: %d, height: %d, bit: %d, compression: %d\n",
+ out->biWidth, out->biHeight, out->biBitCount, out->biCompression);
+
+ out->biBitCount = 64;
+ break;
+ }
+ }
+
+ msg_index++;
+ return res;
+}
+
+
+void test_ICGetDisplayFormat(void)
+{
+ static const struct
+ {
+ int bits_wanted;
+ int bits_expected;
+ int dx;
+ int width_expected;
+ int dy;
+ int height_expected;
+ int msg_index;
+ }
+ tests[] =
+ {
+ { 8, 64, 0, 640, 0, 480, 9},
+ { 8, 16, 0, 640, 0, 480, 13},
+ { 8, 16, 0, 640, 0, 480, 17},
+ {24, 64, 0, 640, 0, 480, 22},
+ {32, 32, 0, 640, 0, 480, 25},
+ { 0, 32, 0, 640, 0, 480, 28},
+ { 9, 64, 0, 640, 0, 480, 33},
+ {32, 32, 800, 800, 600, 600, 36},
+ };
+
+ HIC ic, ic2;
+ BITMAPINFOHEADER in;
+ BITMAPINFOHEADER out;
+ int i;
+
+ ic = ICOpenFunction(ICTYPE_VIDEO, 0xdeadbeef, ICMODE_DECOMPRESS, driver_proc_test);
+ ok(!!ic, "Opening driver failed\n");
+
+ for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
+ {
+ memset(&in, 0, sizeof(in));
+ memset(&out, 0, sizeof(out));
+
+ in.biSize = sizeof(in);
+ in.biWidth = 640;
+ in.biHeight = 480;
+ in.biPlanes = 1;
+ in.biBitCount = 32;
+ in.biCompression = BI_PNG;
+ in.biSizeImage = 1024;
+
+ out.biBitCount = 16;
+ out.biWidth = 320;
+ out.biHeight = 240;
+
+ ic2 = ICGetDisplayFormat(ic, &in, &out, tests[i].bits_wanted, tests[i].dx, tests[i].dy);
+ ok(!!ic2, "Expected ICGetDisplayFormat to succeeded\n");
+
+ ok(out.biBitCount == tests[i].bits_expected,
+ "Expected biBitCount %d, got %d\n", tests[i].bits_expected, out.biBitCount);
+ ok(out.biWidth == tests[i].width_expected,
+ "Expected biWidth %d, got %d\n", tests[i].width_expected, out.biWidth);
+ ok(out.biHeight == tests[i].height_expected,
+ "Expected biHeight %d, got %d\n", tests[i].height_expected, out.biHeight);
+ ok(msg_index == tests[i].msg_index,
+ "Expected msg_index %d, got %d\n", tests[i].msg_index, msg_index);
+ }
+
+ ICClose(ic);
+}
+
START_TEST(msvfw)
{
test_OpenCase();
test_Locate();
test_ICSeqCompress();
+ test_ICGetDisplayFormat();
}
--
2.7.1

View File

@ -0,0 +1 @@
Fixes: [23175] Fix implementation of ICGetDisplayFormat

View File

@ -197,6 +197,7 @@ patch_enable_all ()
enable_msidb_Implementation="$1"
enable_msvcr120__SetWinRTOutOfMemoryExceptionCallback="$1"
enable_msvcrt_Math_Precision="$1"
enable_msvfw32_ICGetDisplayFormat="$1"
enable_ntdll_APC_Performance="$1"
enable_ntdll_APC_Start_Process="$1"
enable_ntdll_Activation_Context="$1"
@ -768,6 +769,9 @@ patch_enable ()
msvcrt-Math_Precision)
enable_msvcrt_Math_Precision="$2"
;;
msvfw32-ICGetDisplayFormat)
enable_msvfw32_ICGetDisplayFormat="$2"
;;
ntdll-APC_Performance)
enable_ntdll_APC_Performance="$2"
;;
@ -4609,6 +4613,21 @@ if test "$enable_msvcrt_Math_Precision" -eq 1; then
) >> "$patchlist"
fi
# Patchset msvfw32-ICGetDisplayFormat
# |
# | This patchset fixes the following Wine bugs:
# | * [#23175] Fix implementation of ICGetDisplayFormat
# |
# | Modified files:
# | * dlls/msvfw32/msvideo_main.c, dlls/msvfw32/tests/msvfw.c
# |
if test "$enable_msvfw32_ICGetDisplayFormat" -eq 1; then
patch_apply msvfw32-ICGetDisplayFormat/0001-msvfw32-Try-different-formarts-in-ICGetDisplayFormat.patch
(
echo '+ { "Michael Müller", "msvfw32: Try different formarts in ICGetDisplayFormat.", 1 },';
) >> "$patchlist"
fi
# Patchset ntdll-APC_Performance
# |
# | Modified files: