fdfe54657602128d423944dfc6d52d40b3b9a8fc
[reactos.git] / rostests / winetests / msrle32 / msrle.c
1 /*
2 * Copyright 2013 Jacek Caban for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #define WIN32_LEAN_AND_MEAN
20 #include <windows.h>
21 #include <vfw.h>
22 #include <aviriff.h>
23 #include <stdio.h>
24
25 #include <wine/test.h>
26
27 static void test_output(const BYTE *output, int out_size, const BYTE *expect, int size)
28 {
29 char buf[512], *ptr;
30 int i;
31
32 i = out_size == size && !memcmp(output, expect, size);
33 ok(i, "Unexpected output\n");
34 if(i)
35 return;
36
37 for(i=0, ptr=buf; i<out_size; i++)
38 ptr += sprintf(ptr, "%x ", output[i]);
39 trace("Got: %s\n", buf);
40 for(i=0, ptr=buf; i<size; i++)
41 ptr += sprintf(ptr, "%x ", expect[i]);
42 trace("Exp: %s\n", buf);
43 }
44
45 static void test_encode(void)
46 {
47 BITMAPINFOHEADER *output_header;
48 DWORD output_size, flags, quality;
49 BYTE buf[64];
50 ICINFO info;
51 HIC hic;
52 LRESULT res;
53
54 struct { BITMAPINFOHEADER header; RGBQUAD map[256]; }
55 input_header = { {sizeof(BITMAPINFOHEADER), 32, 1, 1, 8, 0, 32*8, 0, 0, 256, 256},
56 {{255,0,0}, {0,255,0}, {0,0,255}, {255,255,255}}};
57
58 static BYTE input1[32] = {1,2,3,3,3,3,2,3,1};
59 static const BYTE output1[] = {1,1,1,2,4,3,0,3,2,3,1,0,23,0,0,0,0,1};
60
61 hic = ICOpen(FCC('V','I','D','C'), FCC('m','r','l','e'), ICMODE_COMPRESS);
62 ok(hic != NULL, "ICOpen failed\n");
63
64 res = ICGetInfo(hic, &info, sizeof(info));
65 ok(res == sizeof(info), "res = %ld\n", res);
66 ok(info.dwSize == sizeof(info), "dwSize = %d\n", info.dwSize);
67 ok(info.fccHandler == FCC('M','R','L','E'), "fccHandler = %x\n", info.fccHandler);
68 todo_wine ok(info.dwFlags == (VIDCF_QUALITY|VIDCF_CRUNCH|VIDCF_TEMPORAL), "dwFlags = %x\n", info.dwFlags);
69 ok(info.dwVersionICM == ICVERSION, "dwVersionICM = %d\n", info.dwVersionICM);
70
71 quality = 0xdeadbeef;
72 res = ICSendMessage(hic, ICM_GETDEFAULTQUALITY, (DWORD_PTR)&quality, 0);
73 ok(res == ICERR_OK, "ICSendMessage(ICM_GETDEFAULTQUALITY) failed: %ld\n", res);
74 ok(quality == 8500, "quality = %d\n", quality);
75
76 quality = 0xdeadbeef;
77 res = ICSendMessage(hic, ICM_GETQUALITY, (DWORD_PTR)&quality, 0);
78 ok(res == ICERR_UNSUPPORTED, "ICSendMessage(ICM_GETQUALITY) failed: %ld\n", res);
79 ok(quality == 0xdeadbeef, "quality = %d\n", quality);
80
81 quality = ICQUALITY_HIGH;
82 res = ICSendMessage(hic, ICM_SETQUALITY, (DWORD_PTR)&quality, 0);
83 ok(res == ICERR_UNSUPPORTED, "ICSendMessage(ICM_SETQUALITY) failed: %ld\n", res);
84
85 output_size = ICCompressGetFormatSize(hic, &input_header.header);
86 ok(output_size == 1064, "output_size = %d\n", output_size);
87
88 output_header = HeapAlloc(GetProcessHeap(), 0, output_size);
89 ICCompressGetFormat(hic, &input_header.header, output_header);
90
91 flags = 0;
92 res = ICCompress(hic, ICCOMPRESS_KEYFRAME, output_header, buf, &input_header.header, input1, 0, &flags, 0, 0, 0, NULL, NULL);
93 ok(res == ICERR_OK, "ICCompress failed: %ld\n", res);
94 test_output(buf, output_header->biSizeImage, output1, sizeof(output1));
95 ok(flags == (AVIIF_TWOCC|AVIIF_KEYFRAME), "flags = %x\n", flags);
96
97 HeapFree(GetProcessHeap(), 0, output_header);
98
99 ICClose(hic);
100 }
101
102 START_TEST(msrle)
103 {
104 test_encode();
105 }