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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 * ------------------------------------------------------------------------ */
43 #define WIN32_NO_STATUS
45 #define COM_NO_WINDOWS_H
51 //#include "winuser.h"
52 //#include "commdlg.h"
54 //#include "mmsystem.h"
55 #include "iccvid_private.h"
57 #include <wine/debug.h>
59 WINE_DEFAULT_DEBUG_CHANNEL(iccvid
);
61 static HINSTANCE ICCVID_hModule
;
63 #define ICCVID_MAGIC mmioFOURCC('c', 'v', 'i', 'd')
64 #define compare_fourcc(fcc1, fcc2) (((fcc1)^(fcc2))&~0x20202020)
69 /* ------------------------------------------------------------------------ */
72 unsigned char y0
, y1
, y2
, y3
;
74 unsigned char r
[4], g
[4], b
[4];
78 cvid_codebook
*v4_codebook
[MAX_STRIPS
];
79 cvid_codebook
*v1_codebook
[MAX_STRIPS
];
80 unsigned int strip_num
;
83 typedef struct _ICCVID_Info
90 static inline LPVOID
heap_alloc( size_t size
)
92 return HeapAlloc( GetProcessHeap(), 0, size
);
95 static inline BOOL
heap_free( LPVOID ptr
)
97 return HeapFree( GetProcessHeap(), 0, ptr
);
101 /* ------------------------------------------------------------------------ */
102 static unsigned char *in_buffer
, uiclip
[1024], *uiclp
= NULL
;
104 #define get_byte() *(in_buffer++)
105 #define skip_byte() in_buffer++
106 #define get_word() ((unsigned short)(in_buffer += 2, \
107 (in_buffer[-2] << 8 | in_buffer[-1])))
108 #define get_long() ((unsigned long)(in_buffer += 4, \
109 (in_buffer[-4] << 24 | in_buffer[-3] << 16 | in_buffer[-2] << 8 | in_buffer[-1])))
112 /* ---------------------------------------------------------------------- */
113 static inline void read_codebook(cvid_codebook
*c
, int mode
)
117 if(mode
) /* black and white */
125 c
->r
[0] = c
->g
[0] = c
->b
[0] = c
->y0
;
126 c
->r
[1] = c
->g
[1] = c
->b
[1] = c
->y1
;
127 c
->r
[2] = c
->g
[2] = c
->b
[2] = c
->y2
;
128 c
->r
[3] = c
->g
[3] = c
->b
[3] = c
->y3
;
132 c
->y0
= get_byte(); /* luma */
136 c
->u
= get_byte(); /* chroma */
140 uvg
= -((c
->u
+1) >> 1) - c
->v
;
143 c
->r
[0] = uiclp
[c
->y0
+ uvr
]; c
->g
[0] = uiclp
[c
->y0
+ uvg
]; c
->b
[0] = uiclp
[c
->y0
+ uvb
];
144 c
->r
[1] = uiclp
[c
->y1
+ uvr
]; c
->g
[1] = uiclp
[c
->y1
+ uvg
]; c
->b
[1] = uiclp
[c
->y1
+ uvb
];
145 c
->r
[2] = uiclp
[c
->y2
+ uvr
]; c
->g
[2] = uiclp
[c
->y2
+ uvg
]; c
->b
[2] = uiclp
[c
->y2
+ uvb
];
146 c
->r
[3] = uiclp
[c
->y3
+ uvr
]; c
->g
[3] = uiclp
[c
->y3
+ uvg
]; c
->b
[3] = uiclp
[c
->y3
+ uvb
];
151 #define MAKECOLOUR32(r,g,b) (((r) << 16) | ((g) << 8) | (b))
152 /*#define MAKECOLOUR24(r,g,b) (((r) << 16) | ((g) << 8) | (b))*/
153 #define MAKECOLOUR16(r,g,b) (((r) >> 3) << 11)| (((g) >> 2) << 5)| (((b) >> 3) << 0)
154 #define MAKECOLOUR15(r,g,b) (((r) >> 3) << 10)| (((g) >> 3) << 5)| (((b) >> 3) << 0)
156 /* ------------------------------------------------------------------------ */
157 static void cvid_v1_32(unsigned char *frm
, unsigned char *limit
, int stride
, cvid_codebook
*cb
)
159 unsigned long *vptr
= (unsigned long *)frm
;
161 int row_inc
= -stride
/4;
163 int row_inc
= stride
/4;
167 /* fill 4x4 block of pixels with colour values from codebook */
168 for (y
= 0; y
< 4; y
++)
170 if (&vptr
[y
*row_inc
] < (unsigned long *)limit
) return;
171 for (x
= 0; x
< 4; x
++)
172 vptr
[y
*row_inc
+ x
] = MAKECOLOUR32(cb
->r
[x
/2+(y
/2)*2], cb
->g
[x
/2+(y
/2)*2], cb
->b
[x
/2+(y
/2)*2]);
177 /* ------------------------------------------------------------------------ */
178 static void cvid_v4_32(unsigned char *frm
, unsigned char *limit
, int stride
, cvid_codebook
*cb0
,
179 cvid_codebook
*cb1
, cvid_codebook
*cb2
, cvid_codebook
*cb3
)
181 unsigned long *vptr
= (unsigned long *)frm
;
183 int row_inc
= -stride
/4;
185 int row_inc
= stride
/4;
188 cvid_codebook
* cb
[] = {cb0
,cb1
,cb2
,cb3
};
190 /* fill 4x4 block of pixels with colour values from codebooks */
191 for (y
= 0; y
< 4; y
++)
193 if (&vptr
[y
*row_inc
] < (unsigned long *)limit
) return;
194 for (x
= 0; x
< 4; x
++)
195 vptr
[y
*row_inc
+ x
] = MAKECOLOUR32(cb
[x
/2+(y
/2)*2]->r
[x
%2+(y
%2)*2], cb
[x
/2+(y
/2)*2]->g
[x
%2+(y
%2)*2], cb
[x
/2+(y
/2)*2]->b
[x
%2+(y
%2)*2]);
200 /* ------------------------------------------------------------------------ */
201 static void cvid_v1_24(unsigned char *vptr
, unsigned char *limit
, int stride
, cvid_codebook
*cb
)
204 int row_inc
= -stride
;
206 int row_inc
= stride
;
210 /* fill 4x4 block of pixels with colour values from codebook */
211 for (y
= 0; y
< 4; y
++)
213 if (&vptr
[y
*row_inc
] < limit
) return;
214 for (x
= 0; x
< 4; x
++)
216 vptr
[y
*row_inc
+ x
*3 + 0] = cb
->b
[x
/2+(y
/2)*2];
217 vptr
[y
*row_inc
+ x
*3 + 1] = cb
->g
[x
/2+(y
/2)*2];
218 vptr
[y
*row_inc
+ x
*3 + 2] = cb
->r
[x
/2+(y
/2)*2];
224 /* ------------------------------------------------------------------------ */
225 static void cvid_v4_24(unsigned char *vptr
, unsigned char *limit
, int stride
, cvid_codebook
*cb0
,
226 cvid_codebook
*cb1
, cvid_codebook
*cb2
, cvid_codebook
*cb3
)
229 int row_inc
= -stride
;
231 int row_inc
= stride
;
233 cvid_codebook
* cb
[] = {cb0
,cb1
,cb2
,cb3
};
236 /* fill 4x4 block of pixels with colour values from codebooks */
237 for (y
= 0; y
< 4; y
++)
239 if (&vptr
[y
*row_inc
] < limit
) return;
240 for (x
= 0; x
< 4; x
++)
242 vptr
[y
*row_inc
+ x
*3 + 0] = cb
[x
/2+(y
/2)*2]->b
[x
%2+(y
%2)*2];
243 vptr
[y
*row_inc
+ x
*3 + 1] = cb
[x
/2+(y
/2)*2]->g
[x
%2+(y
%2)*2];
244 vptr
[y
*row_inc
+ x
*3 + 2] = cb
[x
/2+(y
/2)*2]->r
[x
%2+(y
%2)*2];
250 /* ------------------------------------------------------------------------ */
251 static void cvid_v1_16(unsigned char *frm
, unsigned char *limit
, int stride
, cvid_codebook
*cb
)
253 unsigned short *vptr
= (unsigned short *)frm
;
255 int row_inc
= -stride
/2;
257 int row_inc
= stride
/2;
261 /* fill 4x4 block of pixels with colour values from codebook */
262 for (y
= 0; y
< 4; y
++)
264 if (&vptr
[y
*row_inc
] < (unsigned short *)limit
) return;
265 for (x
= 0; x
< 4; x
++)
266 vptr
[y
*row_inc
+ x
] = MAKECOLOUR16(cb
->r
[x
/2+(y
/2)*2], cb
->g
[x
/2+(y
/2)*2], cb
->b
[x
/2+(y
/2)*2]);
271 /* ------------------------------------------------------------------------ */
272 static void cvid_v4_16(unsigned char *frm
, unsigned char *limit
, int stride
, cvid_codebook
*cb0
,
273 cvid_codebook
*cb1
, cvid_codebook
*cb2
, cvid_codebook
*cb3
)
275 unsigned short *vptr
= (unsigned short *)frm
;
277 int row_inc
= -stride
/2;
279 int row_inc
= stride
/2;
281 cvid_codebook
* cb
[] = {cb0
,cb1
,cb2
,cb3
};
284 /* fill 4x4 block of pixels with colour values from codebooks */
285 for (y
= 0; y
< 4; y
++)
287 if (&vptr
[y
*row_inc
] < (unsigned short *)limit
) return;
288 for (x
= 0; x
< 4; x
++)
289 vptr
[y
*row_inc
+ x
] = MAKECOLOUR16(cb
[x
/2+(y
/2)*2]->r
[x
%2+(y
%2)*2], cb
[x
/2+(y
/2)*2]->g
[x
%2+(y
%2)*2], cb
[x
/2+(y
/2)*2]->b
[x
%2+(y
%2)*2]);
293 /* ------------------------------------------------------------------------ */
294 static void cvid_v1_15(unsigned char *frm
, unsigned char *limit
, int stride
, cvid_codebook
*cb
)
296 unsigned short *vptr
= (unsigned short *)frm
;
298 int row_inc
= -stride
/2;
300 int row_inc
= stride
/2;
304 /* fill 4x4 block of pixels with colour values from codebook */
305 for (y
= 0; y
< 4; y
++)
307 if (&vptr
[y
*row_inc
] < (unsigned short *)limit
) return;
308 for (x
= 0; x
< 4; x
++)
309 vptr
[y
*row_inc
+ x
] = MAKECOLOUR15(cb
->r
[x
/2+(y
/2)*2], cb
->g
[x
/2+(y
/2)*2], cb
->b
[x
/2+(y
/2)*2]);
314 /* ------------------------------------------------------------------------ */
315 static void cvid_v4_15(unsigned char *frm
, unsigned char *limit
, int stride
, cvid_codebook
*cb0
,
316 cvid_codebook
*cb1
, cvid_codebook
*cb2
, cvid_codebook
*cb3
)
318 unsigned short *vptr
= (unsigned short *)frm
;
320 int row_inc
= -stride
/2;
322 int row_inc
= stride
/2;
324 cvid_codebook
* cb
[] = {cb0
,cb1
,cb2
,cb3
};
327 /* fill 4x4 block of pixels with colour values from codebooks */
328 for (y
= 0; y
< 4; y
++)
330 if (&vptr
[y
*row_inc
] < (unsigned short *)limit
) return;
331 for (x
= 0; x
< 4; x
++)
332 vptr
[y
*row_inc
+ x
] = MAKECOLOUR15(cb
[x
/2+(y
/2)*2]->r
[x
%2+(y
%2)*2], cb
[x
/2+(y
/2)*2]->g
[x
%2+(y
%2)*2], cb
[x
/2+(y
/2)*2]->b
[x
%2+(y
%2)*2]);
337 /* ------------------------------------------------------------------------
338 * Call this function once at the start of the sequence and save the
339 * returned context for calls to decode_cinepak().
341 static cinepak_info
*decode_cinepak_init(void)
343 cinepak_info
*cvinfo
;
346 cvinfo
= heap_alloc( sizeof (cinepak_info
) );
349 cvinfo
->strip_num
= 0;
354 for(i
= -512; i
< 512; i
++)
355 uiclp
[i
] = (i
< 0 ? 0 : (i
> 255 ? 255 : i
));
361 static void free_cvinfo( cinepak_info
*cvinfo
)
365 for( i
=0; i
<cvinfo
->strip_num
; i
++ )
367 heap_free(cvinfo
->v4_codebook
[i
]);
368 heap_free(cvinfo
->v1_codebook
[i
]);
373 typedef void (*fn_cvid_v1
)(unsigned char *frm
, unsigned char *limit
,
374 int stride
, cvid_codebook
*cb
);
375 typedef void (*fn_cvid_v4
)(unsigned char *frm
, unsigned char *limit
, int stride
,
376 cvid_codebook
*cb0
, cvid_codebook
*cb1
,
377 cvid_codebook
*cb2
, cvid_codebook
*cb3
);
379 /* ------------------------------------------------------------------------
380 * This function decodes a buffer containing a Cinepak encoded frame.
382 * context - the context created by decode_cinepak_init().
383 * buf - the input buffer to be decoded
384 * size - the size of the input buffer
385 * frame - the output frame buffer (24 or 32 bit per pixel)
386 * width - the width of the output frame
387 * height - the height of the output frame
388 * bit_per_pixel - the number of bits per pixel allocated to the output
389 * frame (only 24 or 32 bpp are supported)
391 static void decode_cinepak(cinepak_info
*cvinfo
, unsigned char *buf
, int size
,
392 unsigned char *frame
, unsigned int width
, unsigned int height
, int bit_per_pixel
)
394 cvid_codebook
*v4_codebook
, *v1_codebook
, *codebook
= NULL
;
395 unsigned long x
, y
, y_bottom
, frame_flags
, strips
, cv_width
, cv_height
,
396 cnum
, strip_id
, chunk_id
, x0
, y0
, x1
, y1
, ci
, flag
, mask
;
397 long len
, top_size
, chunk_size
;
398 unsigned char *frm_ptr
;
399 unsigned int i
, cur_strip
;
400 int d0
, d1
, d2
, d3
, frm_stride
, bpp
= 3;
401 fn_cvid_v1 cvid_v1
= cvid_v1_24
;
402 fn_cvid_v4 cvid_v4
= cvid_v4_24
;
408 frame_flags
= get_byte();
409 len
= get_byte() << 16;
410 len
|= get_byte() << 8;
413 switch(bit_per_pixel
)
417 cvid_v1
= cvid_v1_15
;
418 cvid_v4
= cvid_v4_15
;
422 cvid_v1
= cvid_v1_16
;
423 cvid_v4
= cvid_v4_16
;
427 cvid_v1
= cvid_v1_24
;
428 cvid_v4
= cvid_v4_24
;
432 cvid_v1
= cvid_v1_32
;
433 cvid_v4
= cvid_v4_32
;
437 frm_stride
= width
* bpp
;
442 if(len
& 0x01) len
++; /* AVIs tend to have a size mismatch */
445 ERR("CVID: corruption %d (QT/AVI) != %ld (CV)\n", size
, len
);
450 cv_width
= get_word();
451 cv_height
= get_word();
454 if(strips
> cvinfo
->strip_num
)
456 if(strips
>= MAX_STRIPS
)
458 ERR("CVID: strip overflow (more than %d)\n", MAX_STRIPS
);
462 for(i
= cvinfo
->strip_num
; i
< strips
; i
++)
464 if((cvinfo
->v4_codebook
[i
] = heap_alloc(sizeof(cvid_codebook
) * 260)) == NULL
)
466 ERR("CVID: codebook v4 alloc err\n");
470 if((cvinfo
->v1_codebook
[i
] = heap_alloc(sizeof(cvid_codebook
) * 260)) == NULL
)
472 ERR("CVID: codebook v1 alloc err\n");
477 cvinfo
->strip_num
= strips
;
479 TRACE("CVID: <%ld,%ld> strips %ld\n", cv_width
, cv_height
, strips
);
481 for(cur_strip
= 0; cur_strip
< strips
; cur_strip
++)
483 v4_codebook
= cvinfo
->v4_codebook
[cur_strip
];
484 v1_codebook
= cvinfo
->v1_codebook
[cur_strip
];
486 if((cur_strip
> 0) && (!(frame_flags
& 0x01)))
488 memcpy(cvinfo
->v4_codebook
[cur_strip
], cvinfo
->v4_codebook
[cur_strip
-1], 260 * sizeof(cvid_codebook
));
489 memcpy(cvinfo
->v1_codebook
[cur_strip
], cvinfo
->v1_codebook
[cur_strip
-1], 260 * sizeof(cvid_codebook
));
492 strip_id
= get_word(); /* 1000 = key strip, 1100 = iter strip */
493 top_size
= get_word();
494 y0
= get_word(); /* FIXME: most of these are ignored at the moment */
503 WARN("CVID: Warning x1 (%ld) != width (%d)\n", x1
, width
);
505 TRACE(" %d) %04lx %04ld <%ld,%ld> <%ld,%ld> yt %ld\n",
506 cur_strip
, strip_id
, top_size
, x0
, y0
, x1
, y1
, y_bottom
);
510 chunk_id
= get_word();
511 chunk_size
= get_word();
513 TRACE(" %04lx %04ld\n", chunk_id
, chunk_size
);
514 top_size
-= chunk_size
;
519 /* -------------------- Codebook Entries -------------------- */
522 codebook
= (chunk_id
== 0x2200 ? v1_codebook
: v4_codebook
);
524 for(i
= 0; i
< cnum
; i
++) read_codebook(codebook
+i
, 0);
528 case 0x2600: /* 8 bit per pixel */
529 codebook
= (chunk_id
== 0x2600 ? v1_codebook
: v4_codebook
);
531 for(i
= 0; i
< cnum
; i
++) read_codebook(codebook
+i
, 1);
536 codebook
= (chunk_id
== 0x2300 ? v1_codebook
: v4_codebook
);
539 while(chunk_size
> 0)
544 for(i
= 0; i
< 32; i
++)
546 if(flag
& 0x80000000)
549 read_codebook(codebook
+ci
, 0);
556 while(chunk_size
> 0) { skip_byte(); chunk_size
--; }
560 case 0x2700: /* 8 bit per pixel */
561 codebook
= (chunk_id
== 0x2700 ? v1_codebook
: v4_codebook
);
564 while(chunk_size
> 0)
569 for(i
= 0; i
< 32; i
++)
571 if(flag
& 0x80000000)
574 read_codebook(codebook
+ci
, 1);
581 while(chunk_size
> 0) { skip_byte(); chunk_size
--; }
584 /* -------------------- Frame -------------------- */
586 while((chunk_size
> 0) && (y
< y_bottom
))
591 for(i
= 0; i
< 32; i
++)
593 if(y
>= y_bottom
) break;
594 if(flag
& 0x80000000) /* 4 bytes per block */
602 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
);
604 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
);
607 else /* 1 byte per block */
610 cvid_v1(frm_ptr
+ (y
* frm_stride
+ x
* bpp
), frm_end
, frm_stride
, v1_codebook
+ get_byte());
612 cvid_v1(frm_ptr
+ ((height
- 1 - y
) * frm_stride
+ x
* bpp
), frame
, frm_stride
, v1_codebook
+ get_byte());
626 while(chunk_size
> 0) { skip_byte(); chunk_size
--; }
630 while((chunk_size
> 0) && (y
< y_bottom
))
632 /* ---- flag bits: 0 = SKIP, 10 = V1, 11 = V4 ---- */
637 while((mask
) && (y
< y_bottom
))
643 if(chunk_size
< 0) break;
650 if(flag
& mask
) /* V4 */
658 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
);
660 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
);
667 cvid_v1(frm_ptr
+ (y
* frm_stride
+ x
* bpp
), frm_end
, frm_stride
, v1_codebook
+ get_byte());
669 cvid_v1(frm_ptr
+ ((height
- 1 - y
) * frm_stride
+ x
* bpp
), frame
, frm_stride
, v1_codebook
+ get_byte());
684 while(chunk_size
> 0) { skip_byte(); chunk_size
--; }
687 case 0x3200: /* each byte is a V1 codebook */
688 while((chunk_size
> 0) && (y
< y_bottom
))
691 cvid_v1(frm_ptr
+ (y
* frm_stride
+ x
* bpp
), frm_end
, frm_stride
, v1_codebook
+ get_byte());
693 cvid_v1(frm_ptr
+ ((height
- 1 - y
) * frm_stride
+ x
* bpp
), frame
, frm_stride
, v1_codebook
+ get_byte());
703 while(chunk_size
> 0) { skip_byte(); chunk_size
--; }
707 ERR("CVID: unknown chunk_id %08lx\n", chunk_id
);
708 while(chunk_size
> 0) { skip_byte(); chunk_size
--; }
716 if(len
& 0x01) len
++; /* AVIs tend to have a size mismatch */
721 xlen
= get_byte() << 16;
722 xlen
|= get_byte() << 8;
723 xlen
|= get_byte(); /* Read Len */
724 WARN("CVID: END INFO chunk size %d cvid size1 %ld cvid size2 %ld\n",
730 static void ICCVID_dump_BITMAPINFO(const BITMAPINFO
* bmi
)
738 bmi
->bmiHeader
.biPlanes
,
739 bmi
->bmiHeader
.biBitCount
,
740 bmi
->bmiHeader
.biHeight
,
741 bmi
->bmiHeader
.biWidth
,
742 debugstr_an( (const char *)&bmi
->bmiHeader
.biCompression
, 4 ) );
745 static inline int ICCVID_CheckMask(RGBQUAD bmiColors
[3], COLORREF redMask
, COLORREF blueMask
, COLORREF greenMask
)
747 COLORREF realRedMask
= MAKECOLOUR32(bmiColors
[0].rgbRed
, bmiColors
[0].rgbGreen
, bmiColors
[0].rgbBlue
);
748 COLORREF realBlueMask
= MAKECOLOUR32(bmiColors
[1].rgbRed
, bmiColors
[1].rgbGreen
, bmiColors
[1].rgbBlue
);
749 COLORREF realGreenMask
= MAKECOLOUR32(bmiColors
[2].rgbRed
, bmiColors
[2].rgbGreen
, bmiColors
[2].rgbBlue
);
751 TRACE("\nbmiColors[0] = 0x%08x\nbmiColors[1] = 0x%08x\nbmiColors[2] = 0x%08x\n",
752 realRedMask
, realBlueMask
, realGreenMask
);
754 if ((realRedMask
== redMask
) &&
755 (realBlueMask
== blueMask
) &&
756 (realGreenMask
== greenMask
))
761 static LRESULT
ICCVID_DecompressQuery( ICCVID_Info
*info
, LPBITMAPINFO in
, LPBITMAPINFO out
)
763 TRACE("ICM_DECOMPRESS_QUERY %p %p %p\n", info
, in
, out
);
765 if( (info
==NULL
) || (info
->dwMagic
!=ICCVID_MAGIC
) )
766 return ICERR_BADPARAM
;
769 ICCVID_dump_BITMAPINFO(in
);
771 if( in
->bmiHeader
.biCompression
!= ICCVID_MAGIC
)
772 return ICERR_BADFORMAT
;
777 ICCVID_dump_BITMAPINFO(out
);
779 if( in
->bmiHeader
.biPlanes
!= out
->bmiHeader
.biPlanes
)
780 return ICERR_BADFORMAT
;
781 if( in
->bmiHeader
.biHeight
!= out
->bmiHeader
.biHeight
)
782 return ICERR_BADFORMAT
;
783 if( in
->bmiHeader
.biWidth
!= out
->bmiHeader
.biWidth
)
784 return ICERR_BADFORMAT
;
786 switch( out
->bmiHeader
.biBitCount
)
789 if ( out
->bmiHeader
.biCompression
== BI_BITFIELDS
)
791 if ( !ICCVID_CheckMask(out
->bmiColors
, 0x7C00, 0x03E0, 0x001F) &&
792 !ICCVID_CheckMask(out
->bmiColors
, 0xF800, 0x07E0, 0x001F) )
794 TRACE("unsupported output bit field(s) for 16-bit colors\n");
795 return ICERR_BADFORMAT
;
803 TRACE("unsupported output bitcount = %d\n", out
->bmiHeader
.biBitCount
);
804 return ICERR_BADFORMAT
;
811 static LRESULT
ICCVID_DecompressGetFormat( ICCVID_Info
*info
, LPBITMAPINFO in
, LPBITMAPINFO out
)
815 TRACE("ICM_DECOMPRESS_GETFORMAT %p %p %p\n", info
, in
, out
);
817 if( (info
==NULL
) || (info
->dwMagic
!=ICCVID_MAGIC
) )
818 return ICERR_BADPARAM
;
820 size
= in
->bmiHeader
.biSize
;
821 if (in
->bmiHeader
.biBitCount
<= 8)
822 size
+= in
->bmiHeader
.biClrUsed
* sizeof(RGBQUAD
);
826 memcpy( out
, in
, size
);
827 out
->bmiHeader
.biCompression
= BI_RGB
;
828 out
->bmiHeader
.biSizeImage
= in
->bmiHeader
.biHeight
829 * in
->bmiHeader
.biWidth
*4;
835 static LRESULT
ICCVID_DecompressBegin( ICCVID_Info
*info
, LPBITMAPINFO in
, LPBITMAPINFO out
)
837 TRACE("ICM_DECOMPRESS_BEGIN %p %p %p\n", info
, in
, out
);
839 if( (info
==NULL
) || (info
->dwMagic
!=ICCVID_MAGIC
) )
840 return ICERR_BADPARAM
;
842 info
->bits_per_pixel
= out
->bmiHeader
.biBitCount
;
844 if (info
->bits_per_pixel
== 16)
846 if ( out
->bmiHeader
.biCompression
== BI_BITFIELDS
)
848 if ( ICCVID_CheckMask(out
->bmiColors
, 0x7C00, 0x03E0, 0x001F) )
849 info
->bits_per_pixel
= 15;
850 else if ( ICCVID_CheckMask(out
->bmiColors
, 0xF800, 0x07E0, 0x001F) )
851 info
->bits_per_pixel
= 16;
854 TRACE("unsupported output bit field(s) for 16-bit colors\n");
855 return ICERR_UNSUPPORTED
;
859 info
->bits_per_pixel
= 15;
862 TRACE("bit_per_pixel = %d\n", info
->bits_per_pixel
);
865 free_cvinfo( info
->cvinfo
);
866 info
->cvinfo
= decode_cinepak_init();
871 static LRESULT
ICCVID_Decompress( ICCVID_Info
*info
, ICDECOMPRESS
*icd
, DWORD size
)
875 TRACE("ICM_DECOMPRESS %p %p %d\n", info
, icd
, size
);
877 if( (info
==NULL
) || (info
->dwMagic
!=ICCVID_MAGIC
) )
878 return ICERR_BADPARAM
;
879 if (info
->cvinfo
==NULL
)
881 ERR("ICM_DECOMPRESS sent after ICM_DECOMPRESS_END\n");
882 return ICERR_BADPARAM
;
885 width
= icd
->lpbiInput
->biWidth
;
886 height
= icd
->lpbiInput
->biHeight
;
888 decode_cinepak(info
->cvinfo
, icd
->lpInput
, icd
->lpbiInput
->biSizeImage
,
889 icd
->lpOutput
, width
, height
, info
->bits_per_pixel
);
894 static LRESULT
ICCVID_DecompressEx( ICCVID_Info
*info
, ICDECOMPRESSEX
*icd
, DWORD size
)
898 TRACE("ICM_DECOMPRESSEX %p %p %d\n", info
, icd
, size
);
900 if( (info
==NULL
) || (info
->dwMagic
!=ICCVID_MAGIC
) )
901 return ICERR_BADPARAM
;
902 if (info
->cvinfo
==NULL
)
904 ERR("ICM_DECOMPRESSEX sent after ICM_DECOMPRESS_END\n");
905 return ICERR_BADPARAM
;
908 /* FIXME: flags are ignored */
910 width
= icd
->lpbiSrc
->biWidth
;
911 height
= icd
->lpbiSrc
->biHeight
;
913 decode_cinepak(info
->cvinfo
, icd
->lpSrc
, icd
->lpbiSrc
->biSizeImage
,
914 icd
->lpDst
, width
, height
, info
->bits_per_pixel
);
919 static LRESULT
ICCVID_Close( ICCVID_Info
*info
)
921 if( (info
==NULL
) || (info
->dwMagic
!=ICCVID_MAGIC
) )
924 free_cvinfo( info
->cvinfo
);
929 static LRESULT
ICCVID_GetInfo( ICCVID_Info
*info
, ICINFO
*icinfo
, DWORD dwSize
)
931 if (!icinfo
) return sizeof(ICINFO
);
932 if (dwSize
< sizeof(ICINFO
)) return 0;
934 icinfo
->dwSize
= sizeof(ICINFO
);
935 icinfo
->fccType
= ICTYPE_VIDEO
;
936 icinfo
->fccHandler
= info
? info
->dwMagic
: ICCVID_MAGIC
;
938 icinfo
->dwVersion
= ICVERSION
;
939 icinfo
->dwVersionICM
= ICVERSION
;
941 LoadStringW(ICCVID_hModule
, IDS_NAME
, icinfo
->szName
, sizeof(icinfo
->szName
)/sizeof(WCHAR
));
942 LoadStringW(ICCVID_hModule
, IDS_DESCRIPTION
, icinfo
->szDescription
, sizeof(icinfo
->szDescription
)/sizeof(WCHAR
));
943 /* msvfw32 will fill icinfo->szDriver for us */
945 return sizeof(ICINFO
);
948 static LRESULT
ICCVID_DecompressEnd( ICCVID_Info
*info
)
952 free_cvinfo( info
->cvinfo
);
958 LRESULT WINAPI
ICCVID_DriverProc( DWORD_PTR dwDriverId
, HDRVR hdrvr
, UINT msg
,
959 LPARAM lParam1
, LPARAM lParam2
)
961 ICCVID_Info
*info
= (ICCVID_Info
*) dwDriverId
;
963 TRACE("%ld %p %d %ld %ld\n", dwDriverId
, hdrvr
, msg
, lParam1
, lParam2
);
979 ICINFO
*icinfo
= (ICINFO
*)lParam2
;
983 if (icinfo
&& compare_fourcc(icinfo
->fccType
, ICTYPE_VIDEO
)) return 0;
985 info
= heap_alloc( sizeof (ICCVID_Info
) );
988 info
->dwMagic
= ICCVID_MAGIC
;
991 return (LRESULT
) info
;
995 return ICCVID_Close( info
);
998 return ICCVID_GetInfo( info
, (ICINFO
*)lParam1
, (DWORD
)lParam2
);
1000 case ICM_DECOMPRESS_QUERY
:
1001 return ICCVID_DecompressQuery( info
, (LPBITMAPINFO
) lParam1
,
1002 (LPBITMAPINFO
) lParam2
);
1003 case ICM_DECOMPRESS_GET_FORMAT
:
1004 return ICCVID_DecompressGetFormat( info
, (LPBITMAPINFO
) lParam1
,
1005 (LPBITMAPINFO
) lParam2
);
1006 case ICM_DECOMPRESS_BEGIN
:
1007 return ICCVID_DecompressBegin( info
, (LPBITMAPINFO
) lParam1
,
1008 (LPBITMAPINFO
) lParam2
);
1009 case ICM_DECOMPRESS
:
1010 return ICCVID_Decompress( info
, (ICDECOMPRESS
*) lParam1
,
1012 case ICM_DECOMPRESSEX
:
1013 return ICCVID_DecompressEx( info
, (ICDECOMPRESSEX
*) lParam1
,
1016 case ICM_DECOMPRESS_END
:
1017 return ICCVID_DecompressEnd( info
);
1019 case ICM_COMPRESS_QUERY
:
1020 FIXME("compression not implemented\n");
1021 return ICERR_BADFORMAT
;
1024 return ICERR_UNSUPPORTED
;
1027 FIXME("Unknown message: %04x %ld %ld\n", msg
, lParam1
, lParam2
);
1029 return ICERR_UNSUPPORTED
;
1032 BOOL WINAPI
DllMain(HINSTANCE hModule
, DWORD dwReason
, LPVOID lpReserved
)
1034 TRACE("(%p,%d,%p)\n", hModule
, dwReason
, lpReserved
);
1038 case DLL_PROCESS_ATTACH
:
1039 DisableThreadLibraryCalls(hModule
);
1040 ICCVID_hModule
= hModule
;
1043 case DLL_PROCESS_DETACH
: