2 * Radius Cinepak Video Decoder
4 * Copyright 2001 Dr. Tim Ferguson (see below)
5 * Portions Copyright 2003 Mike McCormack for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 /* Copyright notice from original source:
23 * ------------------------------------------------------------------------
24 * Radius Cinepak Video Decoder
26 * Dr. Tim Ferguson, 2001.
27 * For more details on the algorithm:
28 * http://www.csse.monash.edu.au/~timf/videocodec.html
30 * This is basically a vector quantiser with adaptive vector density. The
31 * frame is segmented into 4x4 pixel blocks, and each block is coded using
32 * either 1 or 4 vectors.
34 * There are still some issues with this code yet to be resolved. In
35 * particular with decoding in the strip boundaries. However, I have not
36 * yet found a sequence it doesn't work on. Ill keep trying :)
38 * You may freely use this source code. I only ask that you reference its
39 * source in your projects documentation:
40 * Tim Ferguson: http://www.csse.monash.edu.au/~timf/
41 * ------------------------------------------------------------------------ */
53 #include "wine/debug.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(iccvid);
57 #define ICCVID_MAGIC mmioFOURCC('c', 'v', 'i', 'd')
62 /* ------------------------------------------------------------------------ */
65 unsigned char y0, y1, y2, y3;
67 unsigned long rgb0, rgb1, rgb2, rgb3; /* should be a union */
68 unsigned char r[4], g[4], b[4];
72 cvid_codebook *v4_codebook[MAX_STRIPS];
73 cvid_codebook *v1_codebook[MAX_STRIPS];
77 typedef struct _ICCVID_Info
83 static inline LPVOID ICCVID_Alloc( size_t size, size_t count )
85 return HeapAlloc( GetProcessHeap(), 0, size*count );
88 static inline BOOL ICCVID_Free( LPVOID ptr )
90 return HeapFree( GetProcessHeap(), 0, ptr );
94 /* ------------------------------------------------------------------------ */
95 static unsigned char *in_buffer, uiclip[1024], *uiclp = NULL;
97 #define get_byte() *(in_buffer++)
98 #define skip_byte() in_buffer++
99 #define get_word() ((unsigned short)(in_buffer += 2, \
100 (in_buffer[-2] << 8 | in_buffer[-1])))
101 #define get_long() ((unsigned long)(in_buffer += 4, \
102 (in_buffer[-4] << 24 | in_buffer[-3] << 16 | in_buffer[-2] << 8 | in_buffer[-1])))
105 /* ---------------------------------------------------------------------- */
106 static inline void read_codebook_32(cvid_codebook *c, int mode)
110 if(mode) /* black and white */
118 c->rgb0 = (c->y0 << 16) | (c->y0 << 8) | c->y0;
119 c->rgb1 = (c->y1 << 16) | (c->y1 << 8) | c->y1;
120 c->rgb2 = (c->y2 << 16) | (c->y2 << 8) | c->y2;
121 c->rgb3 = (c->y3 << 16) | (c->y3 << 8) | c->y3;
125 c->y0 = get_byte(); /* luma */
129 c->u = get_byte(); /* chroma */
133 uvg = -((c->u+1) >> 1) - c->v;
136 c->rgb0 = (uiclp[c->y0 + uvr] << 16) | (uiclp[c->y0 + uvg] << 8) | uiclp[c->y0 + uvb];
137 c->rgb1 = (uiclp[c->y1 + uvr] << 16) | (uiclp[c->y1 + uvg] << 8) | uiclp[c->y1 + uvb];
138 c->rgb2 = (uiclp[c->y2 + uvr] << 16) | (uiclp[c->y2 + uvg] << 8) | uiclp[c->y2 + uvb];
139 c->rgb3 = (uiclp[c->y3 + uvr] << 16) | (uiclp[c->y3 + uvg] << 8) | uiclp[c->y3 + uvb];
144 /* ------------------------------------------------------------------------ */
145 inline void cvid_v1_32(unsigned char *frm, unsigned char *limit, int stride, cvid_codebook *cb)
147 unsigned long *vptr = (unsigned long *)frm, rgb;
148 int row_inc = stride/4;
153 vptr[0] = rgb = cb->rgb0; vptr[1] = rgb;
154 vptr[2] = rgb = cb->rgb1; vptr[3] = rgb;
156 vptr -= row_inc; if(vptr < (unsigned long *)limit) return;
158 vptr += row_inc; if(vptr > (unsigned long *)limit) return;
160 vptr[0] = rgb = cb->rgb0; vptr[1] = rgb;
161 vptr[2] = rgb = cb->rgb1; vptr[3] = rgb;
163 vptr -= row_inc; if(vptr < (unsigned long *)limit) return;
165 vptr += row_inc; if(vptr > (unsigned long *)limit) return;
167 vptr[0] = rgb = cb->rgb2; vptr[1] = rgb;
168 vptr[2] = rgb = cb->rgb3; vptr[3] = rgb;
170 vptr -= row_inc; if(vptr < (unsigned long *)limit) return;
172 vptr += row_inc; if(vptr > (unsigned long *)limit) return;
174 vptr[0] = rgb = cb->rgb2; vptr[1] = rgb;
175 vptr[2] = rgb = cb->rgb3; vptr[3] = rgb;
179 /* ------------------------------------------------------------------------ */
180 inline void cvid_v4_32(unsigned char *frm, unsigned char *limit, int stride, cvid_codebook *cb0,
181 cvid_codebook *cb1, cvid_codebook *cb2, cvid_codebook *cb3)
183 unsigned long *vptr = (unsigned long *)frm;
184 int row_inc = stride/4;
194 vptr -= row_inc; if(vptr < (unsigned long *)limit) return;
196 vptr += row_inc; if(vptr > (unsigned long *)limit) return;
203 vptr -= row_inc; if(vptr < (unsigned long *)limit) return;
205 vptr += row_inc; if(vptr > (unsigned long *)limit) return;
212 vptr -= row_inc; if(vptr < (unsigned long *)limit) return;
214 vptr += row_inc; if(vptr > (unsigned long *)limit) return;
223 /* ---------------------------------------------------------------------- */
224 static inline void read_codebook_24(cvid_codebook *c, int mode)
228 if(mode) /* black and white */
236 c->r[0] = c->g[0] = c->b[0] = c->y0;
237 c->r[1] = c->g[1] = c->b[1] = c->y1;
238 c->r[2] = c->g[2] = c->b[2] = c->y2;
239 c->r[3] = c->g[3] = c->b[3] = c->y3;
243 c->y0 = get_byte(); /* luma */
247 c->u = get_byte(); /* chroma */
251 uvg = -((c->u+1) >> 1) - c->v;
254 c->r[0] = uiclp[c->y0 + uvr]; c->g[0] = uiclp[c->y0 + uvg]; c->b[0] = uiclp[c->y0 + uvb];
255 c->r[1] = uiclp[c->y1 + uvr]; c->g[1] = uiclp[c->y1 + uvg]; c->b[1] = uiclp[c->y1 + uvb];
256 c->r[2] = uiclp[c->y2 + uvr]; c->g[2] = uiclp[c->y2 + uvg]; c->b[2] = uiclp[c->y2 + uvb];
257 c->r[3] = uiclp[c->y3 + uvr]; c->g[3] = uiclp[c->y3 + uvg]; c->b[3] = uiclp[c->y3 + uvb];
262 /* ------------------------------------------------------------------------ */
263 void cvid_v1_24(unsigned char *vptr, unsigned char *limit, int stride, cvid_codebook *cb)
265 unsigned char r, g, b;
267 int row_inc = stride+4*3;
269 int row_inc = stride-4*3;
275 *vptr++ = b = cb->b[0]; *vptr++ = g = cb->g[0]; *vptr++ = r = cb->r[0];
276 *vptr++ = b; *vptr++ = g; *vptr++ = r;
277 *vptr++ = b = cb->b[1]; *vptr++ = g = cb->g[1]; *vptr++ = r = cb->r[1];
278 *vptr++ = b; *vptr++ = g; *vptr++ = r;
280 vptr -= row_inc; if(vptr < limit) return;
282 vptr += row_inc; if(vptr > limit) return;
284 *vptr++ = b = cb->b[0]; *vptr++ = g = cb->g[0]; *vptr++ = r = cb->r[0];
285 *vptr++ = b; *vptr++ = g; *vptr++ = r;
286 *vptr++ = b = cb->b[1]; *vptr++ = g = cb->g[1]; *vptr++ = r = cb->r[1];
287 *vptr++ = b; *vptr++ = g; *vptr++ = r;
289 vptr -= row_inc; if(vptr < limit) return;
291 vptr += row_inc; if(vptr > limit) return;
293 *vptr++ = b = cb->b[2]; *vptr++ = g = cb->g[2]; *vptr++ = r = cb->r[2];
294 *vptr++ = b; *vptr++ = g; *vptr++ = r;
295 *vptr++ = b = cb->b[3]; *vptr++ = g = cb->g[3]; *vptr++ = r = cb->r[3];
296 *vptr++ = b; *vptr++ = g; *vptr++ = r;
298 vptr -= row_inc; if(vptr < limit) return;
300 vptr += row_inc; if(vptr > limit) return;
302 *vptr++ = b = cb->b[2]; *vptr++ = g = cb->g[2]; *vptr++ = r = cb->r[2];
303 *vptr++ = b; *vptr++ = g; *vptr++ = r;
304 *vptr++ = b = cb->b[3]; *vptr++ = g = cb->g[3]; *vptr++ = r = cb->r[3];
305 *vptr++ = b; *vptr++ = g; *vptr++ = r;
309 /* ------------------------------------------------------------------------ */
310 void cvid_v4_24(unsigned char *vptr, unsigned char *limit, int stride, cvid_codebook *cb0,
311 cvid_codebook *cb1, cvid_codebook *cb2, cvid_codebook *cb3)
314 int row_inc = stride+4*3;
316 int row_inc = stride-4*3;
322 *vptr++ = cb0->b[0]; *vptr++ = cb0->g[0]; *vptr++ = cb0->r[0];
323 *vptr++ = cb0->b[1]; *vptr++ = cb0->g[1]; *vptr++ = cb0->r[1];
324 *vptr++ = cb1->b[0]; *vptr++ = cb1->g[0]; *vptr++ = cb1->r[0];
325 *vptr++ = cb1->b[1]; *vptr++ = cb1->g[1]; *vptr++ = cb1->r[1];
327 vptr -= row_inc; if(vptr < limit) return;
329 vptr += row_inc; if(vptr > limit) return;
331 *vptr++ = cb0->b[2]; *vptr++ = cb0->g[2]; *vptr++ = cb0->r[2];
332 *vptr++ = cb0->b[3]; *vptr++ = cb0->g[3]; *vptr++ = cb0->r[3];
333 *vptr++ = cb1->b[2]; *vptr++ = cb1->g[2]; *vptr++ = cb1->r[2];
334 *vptr++ = cb1->b[3]; *vptr++ = cb1->g[3]; *vptr++ = cb1->r[3];
336 vptr -= row_inc; if(vptr < limit) return;
338 vptr += row_inc; if(vptr > limit) return;
340 *vptr++ = cb2->b[0]; *vptr++ = cb2->g[0]; *vptr++ = cb2->r[0];
341 *vptr++ = cb2->b[1]; *vptr++ = cb2->g[1]; *vptr++ = cb2->r[1];
342 *vptr++ = cb3->b[0]; *vptr++ = cb3->g[0]; *vptr++ = cb3->r[0];
343 *vptr++ = cb3->b[1]; *vptr++ = cb3->g[1]; *vptr++ = cb3->r[1];
345 vptr -= row_inc; if(vptr < limit) return;
347 vptr += row_inc; if(vptr > limit) return;
349 *vptr++ = cb2->b[2]; *vptr++ = cb2->g[2]; *vptr++ = cb2->r[2];
350 *vptr++ = cb2->b[3]; *vptr++ = cb2->g[3]; *vptr++ = cb2->r[3];
351 *vptr++ = cb3->b[2]; *vptr++ = cb3->g[2]; *vptr++ = cb3->r[2];
352 *vptr++ = cb3->b[3]; *vptr++ = cb3->g[3]; *vptr++ = cb3->r[3];
356 /* ------------------------------------------------------------------------
357 * Call this function once at the start of the sequence and save the
358 * returned context for calls to decode_cinepak().
360 cinepak_info *decode_cinepak_init(void)
362 cinepak_info *cvinfo;
365 cvinfo = ICCVID_Alloc( sizeof (cinepak_info), 1 );
368 cvinfo->strip_num = 0;
373 for(i = -512; i < 512; i++)
374 uiclp[i] = (i < 0 ? 0 : (i > 255 ? 255 : i));
380 void free_cvinfo( cinepak_info *cvinfo )
384 for( i=0; i<cvinfo->strip_num; i++ )
386 ICCVID_Free(cvinfo->v4_codebook[i]);
387 ICCVID_Free(cvinfo->v1_codebook[i]);
389 ICCVID_Free( cvinfo );
392 typedef void (*fn_read_codebook)(cvid_codebook *c, int mode);
393 typedef void (*fn_cvid_v1)(unsigned char *frm, unsigned char *limit,
394 int stride, cvid_codebook *cb);
395 typedef void (*fn_cvid_v4)(unsigned char *frm, unsigned char *limit, int stride,
396 cvid_codebook *cb0, cvid_codebook *cb1,
397 cvid_codebook *cb2, cvid_codebook *cb3);
399 /* ------------------------------------------------------------------------
400 * This function decodes a buffer containing a Cinepak encoded frame.
402 * context - the context created by decode_cinepak_init().
403 * buf - the input buffer to be decoded
404 * size - the size of the input buffer
405 * frame - the output frame buffer (24 or 32 bit per pixel)
406 * width - the width of the output frame
407 * height - the height of the output frame
408 * bit_per_pixel - the number of bits per pixel allocated to the output
409 * frame (only 24 or 32 bpp are supported)
411 void decode_cinepak(cinepak_info *cvinfo, unsigned char *buf, int size,
412 unsigned char *frame, int width, int height, int bit_per_pixel)
414 cvid_codebook *v4_codebook, *v1_codebook, *codebook = NULL;
415 unsigned long x, y, y_bottom, frame_flags, strips, cv_width, cv_height,
416 cnum, strip_id, chunk_id, x0, y0, x1, y1, ci, flag, mask;
417 long len, top_size, chunk_size;
418 unsigned char *frm_ptr, *frm_end;
419 int i, cur_strip, d0, d1, d2, d3, frm_stride, bpp = 3;
420 fn_read_codebook read_codebook = read_codebook_24;
421 fn_cvid_v1 cvid_v1 = cvid_v1_24;
422 fn_cvid_v4 cvid_v4 = cvid_v4_24;
428 frame_flags = get_byte();
429 len = get_byte() << 16;
430 len |= get_byte() << 8;
433 switch(bit_per_pixel)
437 read_codebook = read_codebook_24;
438 cvid_v1 = cvid_v1_24;
439 cvid_v4 = cvid_v4_24;
443 read_codebook = read_codebook_32;
444 cvid_v1 = cvid_v1_32;
445 cvid_v4 = cvid_v4_32;
449 frm_stride = width * bpp;
451 frm_end = frm_ptr + width * height * bpp;
455 if(len & 0x01) len++; /* AVIs tend to have a size mismatch */
458 ERR("CVID: corruption %d (QT/AVI) != %ld (CV)\n", size, len);
463 cv_width = get_word();
464 cv_height = get_word();
467 if(strips > cvinfo->strip_num)
469 if(strips >= MAX_STRIPS)
471 ERR("CVID: strip overflow (more than %d)\n", MAX_STRIPS);
475 for(i = cvinfo->strip_num; i < strips; i++)
477 if((cvinfo->v4_codebook[i] = (cvid_codebook *)ICCVID_Alloc(sizeof(cvid_codebook), 260)) == NULL)
479 ERR("CVID: codebook v4 alloc err\n");
483 if((cvinfo->v1_codebook[i] = (cvid_codebook *)ICCVID_Alloc(sizeof(cvid_codebook), 260)) == NULL)
485 ERR("CVID: codebook v1 alloc err\n");
490 cvinfo->strip_num = strips;
492 TRACE("CVID: <%ld,%ld> strips %ld\n", cv_width, cv_height, strips);
494 for(cur_strip = 0; cur_strip < strips; cur_strip++)
496 v4_codebook = cvinfo->v4_codebook[cur_strip];
497 v1_codebook = cvinfo->v1_codebook[cur_strip];
499 if((cur_strip > 0) && (!(frame_flags & 0x01)))
501 memcpy(cvinfo->v4_codebook[cur_strip], cvinfo->v4_codebook[cur_strip-1], 260 * sizeof(cvid_codebook));
502 memcpy(cvinfo->v1_codebook[cur_strip], cvinfo->v1_codebook[cur_strip-1], 260 * sizeof(cvid_codebook));
505 strip_id = get_word(); /* 1000 = key strip, 1100 = iter strip */
506 top_size = get_word();
507 y0 = get_word(); /* FIXME: most of these are ignored at the moment */
516 WARN("CVID: Warning x1 (%ld) != width (%d)\n", x1, width);
518 TRACE(" %d) %04lx %04ld <%ld,%ld> <%ld,%ld> yt %ld\n",
519 cur_strip, strip_id, top_size, x0, y0, x1, y1, y_bottom);
523 chunk_id = get_word();
524 chunk_size = get_word();
526 TRACE(" %04lx %04ld\n", chunk_id, chunk_size);
527 top_size -= chunk_size;
532 /* -------------------- Codebook Entries -------------------- */
535 codebook = (chunk_id == 0x2200 ? v1_codebook : v4_codebook);
537 for(i = 0; i < cnum; i++) read_codebook(codebook+i, 0);
541 case 0x2600: /* 8 bit per pixel */
542 codebook = (chunk_id == 0x2600 ? v1_codebook : v4_codebook);
544 for(i = 0; i < cnum; i++) read_codebook(codebook+i, 1);
549 codebook = (chunk_id == 0x2300 ? v1_codebook : v4_codebook);
552 while(chunk_size > 0)
557 for(i = 0; i < 32; i++)
559 if(flag & 0x80000000)
562 read_codebook(codebook+ci, 0);
569 while(chunk_size > 0) { skip_byte(); chunk_size--; }
573 case 0x2700: /* 8 bit per pixel */
574 codebook = (chunk_id == 0x2700 ? v1_codebook : v4_codebook);
577 while(chunk_size > 0)
582 for(i = 0; i < 32; i++)
584 if(flag & 0x80000000)
587 read_codebook(codebook+ci, 1);
594 while(chunk_size > 0) { skip_byte(); chunk_size--; }
597 /* -------------------- Frame -------------------- */
599 while((chunk_size > 0) && (y < y_bottom))
604 for(i = 0; i < 32; i++)
606 if(y >= y_bottom) break;
607 if(flag & 0x80000000) /* 4 bytes per block */
615 cvid_v4(frm_ptr + (y * frm_stride + x * bpp), frm_end, frm_stride, v4_codebook+d0, v4_codebook+d1, v4_codebook+d2, v4_codebook+d3);
617 cvid_v4(frm_ptr + ((height - 1 - y) * frm_stride + x * bpp), frame, frm_stride, v4_codebook+d0, v4_codebook+d1, v4_codebook+d2, v4_codebook+d3);
620 else /* 1 byte per block */
623 cvid_v1(frm_ptr + (y * frm_stride + x * bpp), frm_end, frm_stride, v1_codebook + get_byte());
625 cvid_v1(frm_ptr + ((height - 1 - y) * frm_stride + x * bpp), frame, frm_stride, v1_codebook + get_byte());
639 while(chunk_size > 0) { skip_byte(); chunk_size--; }
643 while((chunk_size > 0) && (y < y_bottom))
645 /* ---- flag bits: 0 = SKIP, 10 = V1, 11 = V4 ---- */
646 flag = (unsigned long)get_long();
650 while((mask) && (y < y_bottom))
656 if(chunk_size < 0) break;
657 flag = (unsigned long)get_long();
663 if(flag & mask) /* V4 */
671 cvid_v4(frm_ptr + (y * frm_stride + x * bpp), frm_end, frm_stride, v4_codebook+d0, v4_codebook+d1, v4_codebook+d2, v4_codebook+d3);
673 cvid_v4(frm_ptr + ((height - 1 - y) * frm_stride + x * bpp), frame, frm_stride, v4_codebook+d0, v4_codebook+d1, v4_codebook+d2, v4_codebook+d3);
680 cvid_v1(frm_ptr + (y * frm_stride + x * bpp), frm_end, frm_stride, v1_codebook + get_byte());
682 cvid_v1(frm_ptr + ((height - 1 - y) * frm_stride + x * bpp), frame, frm_stride, v1_codebook + get_byte());
697 while(chunk_size > 0) { skip_byte(); chunk_size--; }
700 case 0x3200: /* each byte is a V1 codebook */
701 while((chunk_size > 0) && (y < y_bottom))
704 cvid_v1(frm_ptr + (y * frm_stride + x * bpp), frm_end, frm_stride, v1_codebook + get_byte());
706 cvid_v1(frm_ptr + ((height - 1 - y) * frm_stride + x * bpp), frame, frm_stride, v1_codebook + get_byte());
716 while(chunk_size > 0) { skip_byte(); chunk_size--; }
720 ERR("CVID: unknown chunk_id %08lx\n", chunk_id);
721 while(chunk_size > 0) { skip_byte(); chunk_size--; }
729 if(len & 0x01) len++; /* AVIs tend to have a size mismatch */
734 xlen = get_byte() << 16;
735 xlen |= get_byte() << 8;
736 xlen |= get_byte(); /* Read Len */
737 WARN("CVID: END INFO chunk size %d cvid size1 %ld cvid size2 %ld\n",
743 LRESULT ICCVID_DecompressQuery( ICCVID_Info *info, LPBITMAPINFO in, LPBITMAPINFO out )
745 TRACE("ICM_DECOMPRESS_QUERY %p %p %p\n", info, in, out);
747 if( (info==NULL) || (info->dwMagic!=ICCVID_MAGIC) )
748 return ICERR_BADPARAM;
750 TRACE("planes = %d\n", in->bmiHeader.biPlanes );
751 TRACE("bpp = %d\n", in->bmiHeader.biBitCount );
752 TRACE("height = %ld\n", in->bmiHeader.biHeight );
753 TRACE("width = %ld\n", in->bmiHeader.biWidth );
754 TRACE("compr = %lx\n", in->bmiHeader.biCompression );
756 if( in->bmiHeader.biCompression != ICCVID_MAGIC )
757 return ICERR_UNSUPPORTED;
759 switch( in->bmiHeader.biBitCount )
765 TRACE("bitcount = %d\n", in->bmiHeader.biBitCount );
766 return ICERR_UNSUPPORTED;
770 return ICERR_UNSUPPORTED;
775 LRESULT ICCVID_DecompressGetFormat( ICCVID_Info *info, LPBITMAPINFO in, LPBITMAPINFO out )
777 TRACE("ICM_DECOMPRESS_GETFORMAT %p %p %p\n", info, in, out);
779 if( (info==NULL) || (info->dwMagic!=ICCVID_MAGIC) )
780 return ICERR_BADPARAM;
784 memcpy( out, in, sizeof (BITMAPINFO) );
785 out->bmiHeader.biCompression = BI_RGB;
786 out->bmiHeader.biSizeImage = in->bmiHeader.biHeight
787 * in->bmiHeader.biWidth *4;
790 return sizeof (BITMAPINFO);
793 LRESULT ICCVID_DecompressBegin( ICCVID_Info *info, LPBITMAPINFO in, LPBITMAPINFO out )
795 TRACE("ICM_DECOMPRESS_BEGIN %p %p %p\n", info, in, out);
797 if( (info==NULL) || (info->dwMagic!=ICCVID_MAGIC) )
798 return ICERR_BADPARAM;
801 free_cvinfo( info->cvinfo );
802 info->cvinfo = decode_cinepak_init();
807 LRESULT ICCVID_Decompress( ICCVID_Info *info, ICDECOMPRESS *icd, DWORD size )
812 TRACE("ICM_DECOMPRESS %p %p %ld\n", info, icd, size);
814 if( (info==NULL) || (info->dwMagic!=ICCVID_MAGIC) )
815 return ICERR_BADPARAM;
817 width = icd->lpbiInput->biWidth;
818 height = icd->lpbiInput->biHeight;
819 bit_per_pixel = icd->lpbiInput->biBitCount;
821 decode_cinepak(info->cvinfo, icd->lpInput, icd->lpbiInput->biSizeImage,
822 icd->lpOutput, width, height, bit_per_pixel);
827 LRESULT ICCVID_Close( ICCVID_Info *info )
829 if( (info==NULL) || (info->dwMagic!=ICCVID_MAGIC) )
832 free_cvinfo( info->cvinfo );
837 LRESULT WINAPI ICCVID_DriverProc( DWORD dwDriverId, HDRVR hdrvr, UINT msg,
838 LONG lParam1, LONG lParam2)
840 ICCVID_Info *info = (ICCVID_Info *) dwDriverId;
842 TRACE("%ld %p %d %ld %ld\n", dwDriverId, hdrvr, msg, lParam1, lParam2);
854 info = ICCVID_Alloc( sizeof (ICCVID_Info), 1 );
857 info->dwMagic = ICCVID_MAGIC;
860 return (LRESULT) info;
862 case ICM_DECOMPRESS_QUERY:
863 return ICCVID_DecompressQuery( info, (LPBITMAPINFO) lParam1,
864 (LPBITMAPINFO) lParam2 );
865 case ICM_DECOMPRESS_GET_FORMAT:
866 return ICCVID_DecompressGetFormat( info, (LPBITMAPINFO) lParam1,
867 (LPBITMAPINFO) lParam2 );
868 case ICM_DECOMPRESS_BEGIN:
869 return ICCVID_DecompressBegin( info, (LPBITMAPINFO) lParam1,
870 (LPBITMAPINFO) lParam2 );
872 return ICCVID_Decompress( info, (ICDECOMPRESS*) lParam1,
875 return ICCVID_Close( info );
878 FIXME("Unknown message: %d %ld %ld\n", msg, lParam1, lParam2);