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 * ------------------------------------------------------------------------ */
51 #include "iccvid_private.h"
53 #include "wine/debug.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(iccvid
);
57 static HINSTANCE ICCVID_hModule
;
59 #define ICCVID_MAGIC mmioFOURCC('c', 'v', 'i', 'd')
60 #define compare_fourcc(fcc1, fcc2) (((fcc1)^(fcc2))&~0x20202020)
63 /* ------------------------------------------------------------------------ */
66 unsigned char y0
, y1
, y2
, y3
;
68 unsigned char r
[4], g
[4], b
[4];
72 cvid_codebook
*v4_codebook
[MAX_STRIPS
];
73 cvid_codebook
*v1_codebook
[MAX_STRIPS
];
74 unsigned int strip_num
;
77 typedef struct _ICCVID_Info
84 static inline LPVOID
heap_alloc( size_t size
)
86 return HeapAlloc( GetProcessHeap(), 0, size
);
89 static inline BOOL
heap_free( LPVOID ptr
)
91 return HeapFree( GetProcessHeap(), 0, ptr
);
95 /* ------------------------------------------------------------------------ */
96 static unsigned char *in_buffer
, uiclip
[1024], *uiclp
= NULL
;
98 #define get_byte() *(in_buffer++)
99 #define skip_byte() in_buffer++
100 #define get_word() ((unsigned short)(in_buffer += 2, \
101 (in_buffer[-2] << 8 | in_buffer[-1])))
102 #define get_long() ((unsigned long)(in_buffer += 4, \
103 (in_buffer[-4] << 24 | in_buffer[-3] << 16 | in_buffer[-2] << 8 | in_buffer[-1])))
106 /* ---------------------------------------------------------------------- */
107 static inline void read_codebook(cvid_codebook
*c
, int mode
)
111 if(mode
) /* black and white */
119 c
->r
[0] = c
->g
[0] = c
->b
[0] = c
->y0
;
120 c
->r
[1] = c
->g
[1] = c
->b
[1] = c
->y1
;
121 c
->r
[2] = c
->g
[2] = c
->b
[2] = c
->y2
;
122 c
->r
[3] = c
->g
[3] = c
->b
[3] = c
->y3
;
126 c
->y0
= get_byte(); /* luma */
130 c
->u
= get_byte(); /* chroma */
134 uvg
= -((c
->u
+1) >> 1) - c
->v
;
137 c
->r
[0] = uiclp
[c
->y0
+ uvr
]; c
->g
[0] = uiclp
[c
->y0
+ uvg
]; c
->b
[0] = uiclp
[c
->y0
+ uvb
];
138 c
->r
[1] = uiclp
[c
->y1
+ uvr
]; c
->g
[1] = uiclp
[c
->y1
+ uvg
]; c
->b
[1] = uiclp
[c
->y1
+ uvb
];
139 c
->r
[2] = uiclp
[c
->y2
+ uvr
]; c
->g
[2] = uiclp
[c
->y2
+ uvg
]; c
->b
[2] = uiclp
[c
->y2
+ uvb
];
140 c
->r
[3] = uiclp
[c
->y3
+ uvr
]; c
->g
[3] = uiclp
[c
->y3
+ uvg
]; c
->b
[3] = uiclp
[c
->y3
+ uvb
];
145 #define MAKECOLOUR32(r,g,b) (((r) << 16) | ((g) << 8) | (b))
146 /*#define MAKECOLOUR24(r,g,b) (((r) << 16) | ((g) << 8) | (b))*/
147 #define MAKECOLOUR16(r,g,b) (((r) >> 3) << 11)| (((g) >> 2) << 5)| (((b) >> 3) << 0)
148 #define MAKECOLOUR15(r,g,b) (((r) >> 3) << 10)| (((g) >> 3) << 5)| (((b) >> 3) << 0)
150 /* ------------------------------------------------------------------------ */
151 static void cvid_v1_32(unsigned char *frm
, unsigned char *limit
, int stride
, cvid_codebook
*cb
)
153 unsigned long *vptr
= (unsigned long *)frm
;
155 int row_inc
= -stride
/4;
157 int row_inc
= stride
/4;
161 /* fill 4x4 block of pixels with colour values from codebook */
162 for (y
= 0; y
< 4; y
++)
164 if (&vptr
[y
*row_inc
] < (unsigned long *)limit
) return;
165 for (x
= 0; x
< 4; x
++)
166 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]);
171 /* ------------------------------------------------------------------------ */
172 static void cvid_v4_32(unsigned char *frm
, unsigned char *limit
, int stride
, cvid_codebook
*cb0
,
173 cvid_codebook
*cb1
, cvid_codebook
*cb2
, cvid_codebook
*cb3
)
175 unsigned long *vptr
= (unsigned long *)frm
;
177 int row_inc
= -stride
/4;
179 int row_inc
= stride
/4;
182 cvid_codebook
* cb
[] = {cb0
,cb1
,cb2
,cb3
};
184 /* fill 4x4 block of pixels with colour values from codebooks */
185 for (y
= 0; y
< 4; y
++)
187 if (&vptr
[y
*row_inc
] < (unsigned long *)limit
) return;
188 for (x
= 0; x
< 4; x
++)
189 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]);
194 /* ------------------------------------------------------------------------ */
195 static void cvid_v1_24(unsigned char *vptr
, unsigned char *limit
, int stride
, cvid_codebook
*cb
)
198 int row_inc
= -stride
;
200 int row_inc
= stride
;
204 /* fill 4x4 block of pixels with colour values from codebook */
205 for (y
= 0; y
< 4; y
++)
207 if (&vptr
[y
*row_inc
] < limit
) return;
208 for (x
= 0; x
< 4; x
++)
210 vptr
[y
*row_inc
+ x
*3 + 0] = cb
->b
[x
/2+(y
/2)*2];
211 vptr
[y
*row_inc
+ x
*3 + 1] = cb
->g
[x
/2+(y
/2)*2];
212 vptr
[y
*row_inc
+ x
*3 + 2] = cb
->r
[x
/2+(y
/2)*2];
218 /* ------------------------------------------------------------------------ */
219 static void cvid_v4_24(unsigned char *vptr
, unsigned char *limit
, int stride
, cvid_codebook
*cb0
,
220 cvid_codebook
*cb1
, cvid_codebook
*cb2
, cvid_codebook
*cb3
)
223 int row_inc
= -stride
;
225 int row_inc
= stride
;
227 cvid_codebook
* cb
[] = {cb0
,cb1
,cb2
,cb3
};
230 /* fill 4x4 block of pixels with colour values from codebooks */
231 for (y
= 0; y
< 4; y
++)
233 if (&vptr
[y
*row_inc
] < limit
) return;
234 for (x
= 0; x
< 4; x
++)
236 vptr
[y
*row_inc
+ x
*3 + 0] = cb
[x
/2+(y
/2)*2]->b
[x
%2+(y
%2)*2];
237 vptr
[y
*row_inc
+ x
*3 + 1] = cb
[x
/2+(y
/2)*2]->g
[x
%2+(y
%2)*2];
238 vptr
[y
*row_inc
+ x
*3 + 2] = cb
[x
/2+(y
/2)*2]->r
[x
%2+(y
%2)*2];
244 /* ------------------------------------------------------------------------ */
245 static void cvid_v1_16(unsigned char *frm
, unsigned char *limit
, int stride
, cvid_codebook
*cb
)
247 unsigned short *vptr
= (unsigned short *)frm
;
249 int row_inc
= -stride
/2;
251 int row_inc
= stride
/2;
255 /* fill 4x4 block of pixels with colour values from codebook */
256 for (y
= 0; y
< 4; y
++)
258 if (&vptr
[y
*row_inc
] < (unsigned short *)limit
) return;
259 for (x
= 0; x
< 4; x
++)
260 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]);
265 /* ------------------------------------------------------------------------ */
266 static void cvid_v4_16(unsigned char *frm
, unsigned char *limit
, int stride
, cvid_codebook
*cb0
,
267 cvid_codebook
*cb1
, cvid_codebook
*cb2
, cvid_codebook
*cb3
)
269 unsigned short *vptr
= (unsigned short *)frm
;
271 int row_inc
= -stride
/2;
273 int row_inc
= stride
/2;
275 cvid_codebook
* cb
[] = {cb0
,cb1
,cb2
,cb3
};
278 /* fill 4x4 block of pixels with colour values from codebooks */
279 for (y
= 0; y
< 4; y
++)
281 if (&vptr
[y
*row_inc
] < (unsigned short *)limit
) return;
282 for (x
= 0; x
< 4; x
++)
283 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]);
287 /* ------------------------------------------------------------------------ */
288 static void cvid_v1_15(unsigned char *frm
, unsigned char *limit
, int stride
, cvid_codebook
*cb
)
290 unsigned short *vptr
= (unsigned short *)frm
;
292 int row_inc
= -stride
/2;
294 int row_inc
= stride
/2;
298 /* fill 4x4 block of pixels with colour values from codebook */
299 for (y
= 0; y
< 4; y
++)
301 if (&vptr
[y
*row_inc
] < (unsigned short *)limit
) return;
302 for (x
= 0; x
< 4; x
++)
303 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]);
308 /* ------------------------------------------------------------------------ */
309 static void cvid_v4_15(unsigned char *frm
, unsigned char *limit
, int stride
, cvid_codebook
*cb0
,
310 cvid_codebook
*cb1
, cvid_codebook
*cb2
, cvid_codebook
*cb3
)
312 unsigned short *vptr
= (unsigned short *)frm
;
314 int row_inc
= -stride
/2;
316 int row_inc
= stride
/2;
318 cvid_codebook
* cb
[] = {cb0
,cb1
,cb2
,cb3
};
321 /* fill 4x4 block of pixels with colour values from codebooks */
322 for (y
= 0; y
< 4; y
++)
324 if (&vptr
[y
*row_inc
] < (unsigned short *)limit
) return;
325 for (x
= 0; x
< 4; x
++)
326 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]);
331 /* ------------------------------------------------------------------------
332 * Call this function once at the start of the sequence and save the
333 * returned context for calls to decode_cinepak().
335 static cinepak_info
*decode_cinepak_init(void)
337 cinepak_info
*cvinfo
;
340 cvinfo
= heap_alloc( sizeof (cinepak_info
) );
343 cvinfo
->strip_num
= 0;
348 for(i
= -512; i
< 512; i
++)
349 uiclp
[i
] = (i
< 0 ? 0 : (i
> 255 ? 255 : i
));
355 static void free_cvinfo( cinepak_info
*cvinfo
)
359 for( i
=0; i
<cvinfo
->strip_num
; i
++ )
361 heap_free(cvinfo
->v4_codebook
[i
]);
362 heap_free(cvinfo
->v1_codebook
[i
]);
367 typedef void (*fn_cvid_v1
)(unsigned char *frm
, unsigned char *limit
,
368 int stride
, cvid_codebook
*cb
);
369 typedef void (*fn_cvid_v4
)(unsigned char *frm
, unsigned char *limit
, int stride
,
370 cvid_codebook
*cb0
, cvid_codebook
*cb1
,
371 cvid_codebook
*cb2
, cvid_codebook
*cb3
);
373 /* ------------------------------------------------------------------------
374 * This function decodes a buffer containing a Cinepak encoded frame.
376 * context - the context created by decode_cinepak_init().
377 * buf - the input buffer to be decoded
378 * size - the size of the input buffer
379 * frame - the output frame buffer (24 or 32 bit per pixel)
380 * width - the width of the output frame
381 * height - the height of the output frame
382 * bit_per_pixel - the number of bits per pixel allocated to the output
383 * frame (only 24 or 32 bpp are supported)
385 static void decode_cinepak(cinepak_info
*cvinfo
, unsigned char *buf
, int size
,
386 unsigned char *frame
, unsigned int width
, unsigned int height
, int bit_per_pixel
)
388 cvid_codebook
*v4_codebook
, *v1_codebook
, *codebook
= NULL
;
389 unsigned long x
, y
, y_bottom
, frame_flags
, strips
, cv_width
, cv_height
,
390 cnum
, strip_id
, chunk_id
, x0
, y0
, x1
, y1
, ci
, flag
, mask
;
391 long len
, top_size
, chunk_size
;
392 unsigned char *frm_ptr
;
393 unsigned int i
, cur_strip
;
394 int d0
, d1
, d2
, d3
, frm_stride
, bpp
= 3;
395 fn_cvid_v1 cvid_v1
= cvid_v1_24
;
396 fn_cvid_v4 cvid_v4
= cvid_v4_24
;
402 frame_flags
= get_byte();
403 len
= get_byte() << 16;
404 len
|= get_byte() << 8;
407 switch(bit_per_pixel
)
411 cvid_v1
= cvid_v1_15
;
412 cvid_v4
= cvid_v4_15
;
416 cvid_v1
= cvid_v1_16
;
417 cvid_v4
= cvid_v4_16
;
421 cvid_v1
= cvid_v1_24
;
422 cvid_v4
= cvid_v4_24
;
426 cvid_v1
= cvid_v1_32
;
427 cvid_v4
= cvid_v4_32
;
431 frm_stride
= width
* bpp
;
436 if(len
& 0x01) len
++; /* AVIs tend to have a size mismatch */
439 ERR("CVID: corruption %d (QT/AVI) != %ld (CV)\n", size
, len
);
444 cv_width
= get_word();
445 cv_height
= get_word();
448 if(strips
> cvinfo
->strip_num
)
450 if(strips
>= MAX_STRIPS
)
452 ERR("CVID: strip overflow (more than %d)\n", MAX_STRIPS
);
456 for(i
= cvinfo
->strip_num
; i
< strips
; i
++)
458 if((cvinfo
->v4_codebook
[i
] = heap_alloc(sizeof(cvid_codebook
) * 260)) == NULL
)
460 ERR("CVID: codebook v4 alloc err\n");
464 if((cvinfo
->v1_codebook
[i
] = heap_alloc(sizeof(cvid_codebook
) * 260)) == NULL
)
466 ERR("CVID: codebook v1 alloc err\n");
471 cvinfo
->strip_num
= strips
;
473 TRACE("CVID: <%ld,%ld> strips %ld\n", cv_width
, cv_height
, strips
);
475 for(cur_strip
= 0; cur_strip
< strips
; cur_strip
++)
477 v4_codebook
= cvinfo
->v4_codebook
[cur_strip
];
478 v1_codebook
= cvinfo
->v1_codebook
[cur_strip
];
480 if((cur_strip
> 0) && (!(frame_flags
& 0x01)))
482 memcpy(cvinfo
->v4_codebook
[cur_strip
], cvinfo
->v4_codebook
[cur_strip
-1], 260 * sizeof(cvid_codebook
));
483 memcpy(cvinfo
->v1_codebook
[cur_strip
], cvinfo
->v1_codebook
[cur_strip
-1], 260 * sizeof(cvid_codebook
));
486 strip_id
= get_word(); /* 1000 = key strip, 1100 = iter strip */
487 top_size
= get_word();
488 y0
= get_word(); /* FIXME: most of these are ignored at the moment */
497 WARN("CVID: Warning x1 (%ld) != width (%d)\n", x1
, width
);
499 TRACE(" %d) %04lx %04ld <%ld,%ld> <%ld,%ld> yt %ld\n",
500 cur_strip
, strip_id
, top_size
, x0
, y0
, x1
, y1
, y_bottom
);
504 chunk_id
= get_word();
505 chunk_size
= get_word();
507 TRACE(" %04lx %04ld\n", chunk_id
, chunk_size
);
508 top_size
-= chunk_size
;
513 /* -------------------- Codebook Entries -------------------- */
516 codebook
= (chunk_id
== 0x2200 ? v1_codebook
: v4_codebook
);
518 for(i
= 0; i
< cnum
; i
++) read_codebook(codebook
+i
, 0);
522 case 0x2600: /* 8 bit per pixel */
523 codebook
= (chunk_id
== 0x2600 ? v1_codebook
: v4_codebook
);
525 for(i
= 0; i
< cnum
; i
++) read_codebook(codebook
+i
, 1);
530 codebook
= (chunk_id
== 0x2300 ? v1_codebook
: v4_codebook
);
533 while(chunk_size
> 0)
538 for(i
= 0; i
< 32; i
++)
540 if(flag
& 0x80000000)
543 read_codebook(codebook
+ci
, 0);
550 while(chunk_size
> 0) { skip_byte(); chunk_size
--; }
554 case 0x2700: /* 8 bit per pixel */
555 codebook
= (chunk_id
== 0x2700 ? v1_codebook
: v4_codebook
);
558 while(chunk_size
> 0)
563 for(i
= 0; i
< 32; i
++)
565 if(flag
& 0x80000000)
568 read_codebook(codebook
+ci
, 1);
575 while(chunk_size
> 0) { skip_byte(); chunk_size
--; }
578 /* -------------------- Frame -------------------- */
580 while((chunk_size
> 0) && (y
< y_bottom
))
585 for(i
= 0; i
< 32; i
++)
587 if(y
>= y_bottom
) break;
588 if(flag
& 0x80000000) /* 4 bytes per block */
596 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
);
598 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
);
601 else /* 1 byte per block */
604 cvid_v1(frm_ptr
+ (y
* frm_stride
+ x
* bpp
), frm_end
, frm_stride
, v1_codebook
+ get_byte());
606 cvid_v1(frm_ptr
+ ((height
- 1 - y
) * frm_stride
+ x
* bpp
), frame
, frm_stride
, v1_codebook
+ get_byte());
620 while(chunk_size
> 0) { skip_byte(); chunk_size
--; }
624 while((chunk_size
> 0) && (y
< y_bottom
))
626 /* ---- flag bits: 0 = SKIP, 10 = V1, 11 = V4 ---- */
631 while((mask
) && (y
< y_bottom
))
637 if(chunk_size
< 0) break;
644 if(flag
& mask
) /* V4 */
652 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
);
654 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
);
661 cvid_v1(frm_ptr
+ (y
* frm_stride
+ x
* bpp
), frm_end
, frm_stride
, v1_codebook
+ get_byte());
663 cvid_v1(frm_ptr
+ ((height
- 1 - y
) * frm_stride
+ x
* bpp
), frame
, frm_stride
, v1_codebook
+ get_byte());
678 while(chunk_size
> 0) { skip_byte(); chunk_size
--; }
681 case 0x3200: /* each byte is a V1 codebook */
682 while((chunk_size
> 0) && (y
< y_bottom
))
685 cvid_v1(frm_ptr
+ (y
* frm_stride
+ x
* bpp
), frm_end
, frm_stride
, v1_codebook
+ get_byte());
687 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
--; }
701 ERR("CVID: unknown chunk_id %08lx\n", chunk_id
);
702 while(chunk_size
> 0) { skip_byte(); chunk_size
--; }
710 if(len
& 0x01) len
++; /* AVIs tend to have a size mismatch */
715 xlen
= get_byte() << 16;
716 xlen
|= get_byte() << 8;
717 xlen
|= get_byte(); /* Read Len */
718 WARN("CVID: END INFO chunk size %d cvid size1 %ld cvid size2 %ld\n",
724 static void ICCVID_dump_BITMAPINFO(const BITMAPINFO
* bmi
)
732 bmi
->bmiHeader
.biPlanes
,
733 bmi
->bmiHeader
.biBitCount
,
734 bmi
->bmiHeader
.biHeight
,
735 bmi
->bmiHeader
.biWidth
,
736 debugstr_an( (const char *)&bmi
->bmiHeader
.biCompression
, 4 ) );
739 static inline int ICCVID_CheckMask(RGBQUAD bmiColors
[3], COLORREF redMask
, COLORREF blueMask
, COLORREF greenMask
)
741 COLORREF realRedMask
= MAKECOLOUR32(bmiColors
[0].rgbRed
, bmiColors
[0].rgbGreen
, bmiColors
[0].rgbBlue
);
742 COLORREF realBlueMask
= MAKECOLOUR32(bmiColors
[1].rgbRed
, bmiColors
[1].rgbGreen
, bmiColors
[1].rgbBlue
);
743 COLORREF realGreenMask
= MAKECOLOUR32(bmiColors
[2].rgbRed
, bmiColors
[2].rgbGreen
, bmiColors
[2].rgbBlue
);
745 TRACE("\nbmiColors[0] = 0x%08x\nbmiColors[1] = 0x%08x\nbmiColors[2] = 0x%08x\n",
746 realRedMask
, realBlueMask
, realGreenMask
);
748 if ((realRedMask
== redMask
) &&
749 (realBlueMask
== blueMask
) &&
750 (realGreenMask
== greenMask
))
755 static LRESULT
ICCVID_DecompressQuery( ICCVID_Info
*info
, LPBITMAPINFO in
, LPBITMAPINFO out
)
757 TRACE("ICM_DECOMPRESS_QUERY %p %p %p\n", info
, in
, out
);
759 if( (info
==NULL
) || (info
->dwMagic
!=ICCVID_MAGIC
) )
760 return ICERR_BADPARAM
;
763 ICCVID_dump_BITMAPINFO(in
);
765 if( in
->bmiHeader
.biCompression
!= ICCVID_MAGIC
)
766 return ICERR_BADFORMAT
;
771 ICCVID_dump_BITMAPINFO(out
);
773 if( in
->bmiHeader
.biPlanes
!= out
->bmiHeader
.biPlanes
)
774 return ICERR_BADFORMAT
;
775 if( in
->bmiHeader
.biHeight
!= out
->bmiHeader
.biHeight
)
776 return ICERR_BADFORMAT
;
777 if( in
->bmiHeader
.biWidth
!= out
->bmiHeader
.biWidth
)
778 return ICERR_BADFORMAT
;
780 switch( out
->bmiHeader
.biBitCount
)
783 if ( out
->bmiHeader
.biCompression
== BI_BITFIELDS
)
785 if ( !ICCVID_CheckMask(out
->bmiColors
, 0x7C00, 0x03E0, 0x001F) &&
786 !ICCVID_CheckMask(out
->bmiColors
, 0xF800, 0x07E0, 0x001F) )
788 TRACE("unsupported output bit field(s) for 16-bit colors\n");
789 return ICERR_BADFORMAT
;
797 TRACE("unsupported output bitcount = %d\n", out
->bmiHeader
.biBitCount
);
798 return ICERR_BADFORMAT
;
805 static LRESULT
ICCVID_DecompressGetFormat( ICCVID_Info
*info
, LPBITMAPINFO in
, LPBITMAPINFO out
)
809 TRACE("ICM_DECOMPRESS_GETFORMAT %p %p %p\n", info
, in
, out
);
811 if( (info
==NULL
) || (info
->dwMagic
!=ICCVID_MAGIC
) )
812 return ICERR_BADPARAM
;
814 size
= in
->bmiHeader
.biSize
;
815 if (in
->bmiHeader
.biBitCount
<= 8)
816 size
+= in
->bmiHeader
.biClrUsed
* sizeof(RGBQUAD
);
820 memcpy( out
, in
, size
);
821 out
->bmiHeader
.biCompression
= BI_RGB
;
822 out
->bmiHeader
.biSizeImage
= in
->bmiHeader
.biHeight
823 * in
->bmiHeader
.biWidth
*4;
829 static LRESULT
ICCVID_DecompressBegin( ICCVID_Info
*info
, LPBITMAPINFO in
, LPBITMAPINFO out
)
831 TRACE("ICM_DECOMPRESS_BEGIN %p %p %p\n", info
, in
, out
);
833 if( (info
==NULL
) || (info
->dwMagic
!=ICCVID_MAGIC
) )
834 return ICERR_BADPARAM
;
836 info
->bits_per_pixel
= out
->bmiHeader
.biBitCount
;
838 if (info
->bits_per_pixel
== 16)
840 if ( out
->bmiHeader
.biCompression
== BI_BITFIELDS
)
842 if ( ICCVID_CheckMask(out
->bmiColors
, 0x7C00, 0x03E0, 0x001F) )
843 info
->bits_per_pixel
= 15;
844 else if ( ICCVID_CheckMask(out
->bmiColors
, 0xF800, 0x07E0, 0x001F) )
845 info
->bits_per_pixel
= 16;
848 TRACE("unsupported output bit field(s) for 16-bit colors\n");
849 return ICERR_UNSUPPORTED
;
853 info
->bits_per_pixel
= 15;
856 TRACE("bit_per_pixel = %d\n", info
->bits_per_pixel
);
859 free_cvinfo( info
->cvinfo
);
860 info
->cvinfo
= decode_cinepak_init();
865 static LRESULT
ICCVID_Decompress( ICCVID_Info
*info
, ICDECOMPRESS
*icd
, DWORD size
)
869 TRACE("ICM_DECOMPRESS %p %p %d\n", info
, icd
, size
);
871 if( (info
==NULL
) || (info
->dwMagic
!=ICCVID_MAGIC
) )
872 return ICERR_BADPARAM
;
873 if (info
->cvinfo
==NULL
)
875 ERR("ICM_DECOMPRESS sent after ICM_DECOMPRESS_END\n");
876 return ICERR_BADPARAM
;
879 width
= icd
->lpbiInput
->biWidth
;
880 height
= icd
->lpbiInput
->biHeight
;
882 decode_cinepak(info
->cvinfo
, icd
->lpInput
, icd
->lpbiInput
->biSizeImage
,
883 icd
->lpOutput
, width
, height
, info
->bits_per_pixel
);
888 static LRESULT
ICCVID_DecompressEx( ICCVID_Info
*info
, ICDECOMPRESSEX
*icd
, DWORD size
)
892 TRACE("ICM_DECOMPRESSEX %p %p %d\n", info
, icd
, size
);
894 if( (info
==NULL
) || (info
->dwMagic
!=ICCVID_MAGIC
) )
895 return ICERR_BADPARAM
;
896 if (info
->cvinfo
==NULL
)
898 ERR("ICM_DECOMPRESSEX sent after ICM_DECOMPRESS_END\n");
899 return ICERR_BADPARAM
;
902 /* FIXME: flags are ignored */
904 width
= icd
->lpbiSrc
->biWidth
;
905 height
= icd
->lpbiSrc
->biHeight
;
907 decode_cinepak(info
->cvinfo
, icd
->lpSrc
, icd
->lpbiSrc
->biSizeImage
,
908 icd
->lpDst
, width
, height
, info
->bits_per_pixel
);
913 static LRESULT
ICCVID_Close( ICCVID_Info
*info
)
915 if( (info
==NULL
) || (info
->dwMagic
!=ICCVID_MAGIC
) )
918 free_cvinfo( info
->cvinfo
);
923 static LRESULT
ICCVID_GetInfo( ICCVID_Info
*info
, ICINFO
*icinfo
, DWORD dwSize
)
925 if (!icinfo
) return sizeof(ICINFO
);
926 if (dwSize
< sizeof(ICINFO
)) return 0;
928 icinfo
->dwSize
= sizeof(ICINFO
);
929 icinfo
->fccType
= ICTYPE_VIDEO
;
930 icinfo
->fccHandler
= info
? info
->dwMagic
: ICCVID_MAGIC
;
932 icinfo
->dwVersion
= ICVERSION
;
933 icinfo
->dwVersionICM
= ICVERSION
;
935 LoadStringW(ICCVID_hModule
, IDS_NAME
, icinfo
->szName
, sizeof(icinfo
->szName
)/sizeof(WCHAR
));
936 LoadStringW(ICCVID_hModule
, IDS_DESCRIPTION
, icinfo
->szDescription
, sizeof(icinfo
->szDescription
)/sizeof(WCHAR
));
937 /* msvfw32 will fill icinfo->szDriver for us */
939 return sizeof(ICINFO
);
942 static LRESULT
ICCVID_DecompressEnd( ICCVID_Info
*info
)
946 free_cvinfo( info
->cvinfo
);
952 LRESULT WINAPI
ICCVID_DriverProc( DWORD_PTR dwDriverId
, HDRVR hdrvr
, UINT msg
,
953 LPARAM lParam1
, LPARAM lParam2
)
955 ICCVID_Info
*info
= (ICCVID_Info
*) dwDriverId
;
957 TRACE("%ld %p %d %ld %ld\n", dwDriverId
, hdrvr
, msg
, lParam1
, lParam2
);
973 ICINFO
*icinfo
= (ICINFO
*)lParam2
;
977 if (icinfo
&& compare_fourcc(icinfo
->fccType
, ICTYPE_VIDEO
)) return 0;
979 info
= heap_alloc( sizeof (ICCVID_Info
) );
982 info
->dwMagic
= ICCVID_MAGIC
;
985 return (LRESULT
) info
;
989 return ICCVID_Close( info
);
992 return ICCVID_GetInfo( info
, (ICINFO
*)lParam1
, (DWORD
)lParam2
);
994 case ICM_DECOMPRESS_QUERY
:
995 return ICCVID_DecompressQuery( info
, (LPBITMAPINFO
) lParam1
,
996 (LPBITMAPINFO
) lParam2
);
997 case ICM_DECOMPRESS_GET_FORMAT
:
998 return ICCVID_DecompressGetFormat( info
, (LPBITMAPINFO
) lParam1
,
999 (LPBITMAPINFO
) lParam2
);
1000 case ICM_DECOMPRESS_BEGIN
:
1001 return ICCVID_DecompressBegin( info
, (LPBITMAPINFO
) lParam1
,
1002 (LPBITMAPINFO
) lParam2
);
1003 case ICM_DECOMPRESS
:
1004 return ICCVID_Decompress( info
, (ICDECOMPRESS
*) lParam1
,
1006 case ICM_DECOMPRESSEX
:
1007 return ICCVID_DecompressEx( info
, (ICDECOMPRESSEX
*) lParam1
,
1010 case ICM_DECOMPRESS_END
:
1011 return ICCVID_DecompressEnd( info
);
1013 case ICM_COMPRESS_QUERY
:
1014 FIXME("compression not implemented\n");
1015 return ICERR_BADFORMAT
;
1018 return ICERR_UNSUPPORTED
;
1021 FIXME("Unknown message: %04x %ld %ld\n", msg
, lParam1
, lParam2
);
1023 return ICERR_UNSUPPORTED
;
1026 BOOL WINAPI
DllMain(HINSTANCE hModule
, DWORD dwReason
, LPVOID lpReserved
)
1028 TRACE("(%p,%d,%p)\n", hModule
, dwReason
, lpReserved
);
1032 case DLL_PROCESS_ATTACH
:
1033 DisableThreadLibraryCalls(hModule
);
1034 ICCVID_hModule
= hModule
;