ReactOS  0.4.14-dev-98-gb0d4763
msrle.c
Go to the documentation of this file.
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 {
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;
73  ok(res == ICERR_OK, "ICSendMessage(ICM_GETDEFAULTQUALITY) failed: %ld\n", res);
74  ok(quality == 8500, "quality = %d\n", quality);
75 
76  quality = 0xdeadbeef;
78  ok(res == ICERR_UNSUPPORTED, "ICSendMessage(ICM_GETQUALITY) failed: %ld\n", res);
79  ok(quality == 0xdeadbeef, "quality = %d\n", quality);
80 
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 
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;
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 
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  }
159  HeapFree(GetProcessHeap(), 0, outbits);
160 }
161 
163 {
164  test_encode();
166 }
#define ICM_GETQUALITY
Definition: vfw.h:89
static HANDLE PIO_APC_ROUTINE PVOID PIO_STATUS_BLOCK ULONG PVOID ULONG PVOID ULONG out_size
Definition: file.c:100
HIC VFWAPI ICOpen(DWORD fccType, DWORD fccHandler, UINT wMode)
Definition: msvideo_main.c:437
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
START_TEST(msrle)
Definition: msrle.c:162
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1471
#define ICVERSION
Definition: vfw.h:45
HRESULT hr
Definition: shlfolder.c:183
static const struct image_codec codecs[NUM_CODECS]
Definition: image.c:4235
DWORD biClrImportant
Definition: amvideo.idl:40
#define ICCOMPRESS_KEYFRAME
Definition: vfw.h:170
static void test_raw_decompress(void)
Definition: msrle.c:102
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
LRESULT VFWAPI ICSendMessage(HIC hic, UINT msg, DWORD_PTR lParam1, DWORD_PTR lParam2)
LONG biXPelsPerMeter
Definition: amvideo.idl:37
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
#define ICM_GETDEFAULTQUALITY
Definition: vfw.h:88
#define AVIIF_KEYFRAME
Definition: aviriff.h:131
#define VIDCF_TEMPORAL
Definition: vfw.h:299
#define ICERR_OK
Definition: vfw.h:50
LONG biYPelsPerMeter
Definition: amvideo.idl:38
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:10929
#define ICCompressGetFormat(hic, lpbiInput, lpbiOutput)
Definition: vfw.h:204
struct _test_info info[]
Definition: SetCursorPos.c:19
#define VIDCF_CRUNCH
Definition: vfw.h:298
#define sprintf(buf, format,...)
Definition: sprintf.c:55
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
DWORD VFWAPIV ICDecompress(HIC hic, DWORD dwFlags, LPBITMAPINFOHEADER lpbiFormat, LPVOID lpData, LPBITMAPINFOHEADER lpbi, LPVOID lpBits)
Definition: msvideo_main.c:854
LRESULT WINAPI ICClose(HIC hic)
DWORD biCompression
Definition: amvideo.idl:35
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
DWORD VFWAPIV ICCompress(HIC hic, DWORD dwFlags, LPBITMAPINFOHEADER lpbiOutput, LPVOID lpData, LPBITMAPINFOHEADER lpbiInput, LPVOID lpBits, LPDWORD lpckid, LPDWORD lpdwFlags, LONG lFrameNum, DWORD dwFrameSize, DWORD dwQuality, LPBITMAPINFOHEADER lpbiPrev, LPVOID lpPrev)
Definition: msvideo_main.c:824
#define FCC(ch0, ch1, ch2, ch3)
Definition: aviriff.h:38
#define ICCompressGetFormatSize(hic, lpbi)
Definition: vfw.h:210
HIC VFWAPI ICLocate(DWORD fccType, DWORD fccHandler, LPBITMAPINFOHEADER lpbiIn, LPBITMAPINFOHEADER lpbiOut, WORD wMode)
Definition: msvideo_main.c:671
LRESULT VFWAPI ICGetInfo(HIC hic, ICINFO *picinfo, DWORD cb)
Definition: msvideo_main.c:601
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
#define trace
Definition: atltest.h:70
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
static void test_encode(void)
Definition: msrle.c:45
#define ICMODE_DECOMPRESS
Definition: vfw.h:269
unsigned long DWORD
Definition: ntddk_ex.h:95
#define VIDCF_QUALITY
Definition: vfw.h:297
DWORD biSizeImage
Definition: amvideo.idl:36
int quality
Definition: jpeglib.h:991
Definition: _map.h:44
GLbitfield flags
Definition: glext.h:7161
#define ICERR_UNSUPPORTED
Definition: vfw.h:56
#define todo_wine
Definition: test.h:154
#define ICM_SETQUALITY
Definition: vfw.h:90
#define AVIIF_TWOCC
Definition: vfw.h:977
unsigned char BYTE
Definition: mem.h:68
uint32_t DWORD_PTR
Definition: typedefs.h:63
Definition: vfw.h:280
static void test_output(const BYTE *output, int out_size, const BYTE *expect, int size)
Definition: msrle.c:27
#define ICMODE_COMPRESS
Definition: vfw.h:268
#define ARRAY_SIZE(a)
Definition: main.h:24
#define ok(value,...)
Definition: atltest.h:57
#define expect(expected, got)
Definition: combo.c:36
GLuint res
Definition: glext.h:9613
#define ICQUALITY_HIGH
Definition: vfw.h:277
LONG_PTR LRESULT
Definition: windef.h:209
#define memset(x, y, z)
Definition: compat.h:39
#define BI_RGB
Definition: precomp.h:34
#define HeapFree(x, y, z)
Definition: compat.h:394
struct CFHEADER header
Definition: fdi.c:109
static int output_header(const WCHAR *prop, ULONG column_width)
Definition: main.c:150