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 static void test_raw_decompress(void) 103 { 104 DWORD codecs[] = {FCC('D', 'I', 'B', ' '), FCC('R', 'A', 'W', ' '), 105 FCC('M', 'R', 'L', 'E'), BI_RGB}, i, hr; 106 BITMAPINFO bi; 107 BITMAPINFOHEADER *bih, biho; 108 HIC hic; 109 ICINFO codec_info; 110 void *bits, *outbits; 111 112 /* Create an uncompressed 200x200 bitmap */ 113 bih = &bi.bmiHeader; 114 bih->biSize = sizeof(*bih); 115 bih->biWidth = 200; 116 bih->biHeight = 200; 117 bih->biPlanes = 1; 118 bih->biBitCount = 24; 119 bih->biCompression = BI_RGB; 120 bih->biSizeImage = bih->biWidth * (bih->biBitCount / 8) * bih->biHeight; 121 bih->biXPelsPerMeter = 10000; 122 bih->biYPelsPerMeter = 10000; 123 bih->biClrUsed = 0; 124 bih->biClrImportant = 0; 125 biho = *bih; 126 127 bits = HeapAlloc(GetProcessHeap(), 0, bih->biSizeImage); 128 ok(bits != NULL, "Expected non-NULL value\n"); 129 outbits = HeapAlloc(GetProcessHeap(), 0, bih->biSizeImage); 130 ok(outbits != NULL, "Expected non-NULL value\n"); 131 132 for (i = 0; i < ARRAY_SIZE(codecs); i++) 133 { 134 memset(bits, i + 0xAF, bih->biSizeImage); 135 136 /* Check which codec is able to decompress uncompressed data */ 137 hic = ICLocate(FCC('V', 'I', 'D', 'C'), codecs[i], bih, NULL, ICMODE_DECOMPRESS); 138 ok(hic != NULL, "Test[%d]: Expected non-NULL return\n", i); 139 140 /* Now which is this codec? Windows returns MRLE for uncompressed cases */ 141 memset(&codec_info, 0, sizeof(codec_info)); 142 hr = ICGetInfo(hic, &codec_info, sizeof(codec_info)); 143 ok(hr == sizeof(codec_info), "Test[%d]: Incorrect amount of data returned\n", i); 144 ok(codec_info.fccType == FCC('v', 'i', 'd', 'c'), 145 "Test[%d]: Expected a video type, got 0x%x\n", i, codec_info.fccType); 146 ok(codec_info.fccHandler == FCC('M', 'R', 'L', 'E'), 147 "Test[%d]: Expected MRLE, got 0x%x\n", i, codec_info.fccHandler); 148 149 /* Decompress the frame and check if we get the same output */ 150 memset(outbits, 0, bih->biSizeImage); 151 hr = ICDecompress(hic, 0, bih, bits, &biho, outbits); 152 ok(hr == ICERR_OK, "Test[%d]: Expected ICERR_OK, got %d\n", i, hr); 153 ok(!memcmp(bits, outbits, bih->biSizeImage), "Test[%d]: Image contents do not match!\n", i); 154 155 hr = ICClose(hic); 156 ok(hr == ICERR_OK, "Test[%d]: Expected ICERR_OK, got %d\n", i, hr); 157 } 158 HeapFree(GetProcessHeap(), 0, bits); 159 HeapFree(GetProcessHeap(), 0, outbits); 160 } 161 162 START_TEST(msrle) 163 { 164 test_encode(); 165 test_raw_decompress(); 166 } 167