annotate cinepak.c @ 4479:423ce4451ca8

tested and fixed on 2.2.x, more comments
author alex
date Sat, 02 Feb 2002 17:35:53 +0000
parents 47b9d8d3f3c5
children 1504901deed8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3643
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
1 /* ------------------------------------------------------------------------
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
2 * Radius Cinepak Video Decoder
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
3 *
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
4 * Dr. Tim Ferguson, 2001.
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
5 * For more details on the algorithm:
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
6 * http://www.csse.monash.edu.au/~timf/videocodec.html
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
7 *
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
8 * This is basically a vector quantiser with adaptive vector density. The
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
9 * frame is segmented into 4x4 pixel blocks, and each block is coded using
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
10 * either 1 or 4 vectors.
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
11 *
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
12 * There are still some issues with this code yet to be resolved. In
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
13 * particular with decoding in the strip boundaries.
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
14 * ------------------------------------------------------------------------ */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
15 #include <stdio.h>
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
16 #include <stdlib.h>
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
17 #include <string.h>
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
18 #include <sys/types.h>
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
19 #include <unistd.h>
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
20 #include <math.h>
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
21
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
22 #include "config.h"
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
23
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
24 #define DBUG 0
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
25 #define MAX_STRIPS 32
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
26
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
27 /* ------------------------------------------------------------------------ */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
28 typedef struct
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
29 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
30 unsigned char y0, y1, y2, y3;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
31 char u, v;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
32 unsigned long rgb0, rgb1, rgb2, rgb3; /* should be a union */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
33 unsigned char r[4], g[4], b[4];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
34 } cvid_codebook;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
35
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
36 typedef struct {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
37 cvid_codebook *v4_codebook[MAX_STRIPS];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
38 cvid_codebook *v1_codebook[MAX_STRIPS];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
39 int strip_num;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
40 } cinepak_info;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
41
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
42
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
43 /* ------------------------------------------------------------------------ */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
44 static unsigned char *in_buffer, uiclip[1024], *uiclp = NULL;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
45
4076
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
46 #define SCALEBITS 16
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
47 #define ONE_HALF ((long) 1 << (SCALEBITS-1))
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
48 #define FIX(x) ((long) ((x) * (1L<<SCALEBITS) + 0.5))
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
49 static long CU_Y_tab[256], CV_Y_tab[256], CU_Cb_tab[256], CV_Cb_tab[256],
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
50 CU_Cr_tab[256], CV_Cr_tab[256];
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
51
3643
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
52 #define get_byte() *(in_buffer++)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
53 #define skip_byte() in_buffer++
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
54 #define get_word() ((unsigned short)(in_buffer += 2, \
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
55 (in_buffer[-2] << 8 | in_buffer[-1])))
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
56 #define get_long() ((unsigned long)(in_buffer += 4, \
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
57 (in_buffer[-4] << 24 | in_buffer[-3] << 16 | in_buffer[-2] << 8 | in_buffer[-1])))
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
58
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
59
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
60 /* ---------------------------------------------------------------------- */
3646
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
61 static inline void read_codebook_yuy2(cvid_codebook *c, int mode)
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
62 {
4076
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
63 unsigned char y0, y1, y2, y3, u, v;
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
64 int y_uv;
3646
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
65
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
66 if(mode) /* black and white */
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
67 {
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
68 c->y0 = get_byte();
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
69 c->y1 = get_byte();
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
70 c->y2 = get_byte();
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
71 c->y3 = get_byte();
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
72 c->u = c->v = 128;
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
73 }
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
74 else /* colour */
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
75 {
4076
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
76 y0 = get_byte(); /* luma */
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
77 y1 = get_byte();
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
78 y2 = get_byte();
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
79 y3 = get_byte();
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
80 u = 128+get_byte(); /* chroma */
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
81 v = 128+get_byte();
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
82
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
83 /* YUV * inv(CinYUV)
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
84 * | Y | | 1 -0.0655 0.0110 | | CY |
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
85 * | Cb | = | 0 1.1656 -0.0062 | | CU |
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
86 * | Cr | | 0 0.0467 1.4187 | | CV |
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
87 */
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
88 y_uv = (int)((CU_Y_tab[u] + CV_Y_tab[v]) >> SCALEBITS);
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
89 c->y0 = uiclp[y0 + y_uv];
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
90 c->y1 = uiclp[y1 + y_uv];
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
91 c->y2 = uiclp[y2 + y_uv];
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
92 c->y3 = uiclp[y3 + y_uv];
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
93 c->u = uiclp[(int)((CU_Cb_tab[u] + CV_Cb_tab[v]) >> SCALEBITS)];
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
94 c->v = uiclp[(int)((CU_Cr_tab[u] + CV_Cr_tab[v]) >> SCALEBITS)];
3646
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
95 }
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
96 }
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
97
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
98 //#define PACK_YUV(cb,y0,y1,u,v) ((cb->y0<<24)|(((unsigned char)cb->u)<<16)|(cb->y1<<8)|(((unsigned char)cb->v)))
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
99 #define PACK_YUV(cb,y0,y1,u,v) ((((unsigned char)cb->v)<<24)|(cb->y1<<16)|(((unsigned char)cb->u)<<8)|(cb->y0))
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
100
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
101 #define TO_YUY2_U0(cb) PACK_YUV(cb,y0,y0,u,v)
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
102 #define TO_YUY2_U1(cb) PACK_YUV(cb,y1,y1,u,v)
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
103 #define TO_YUY2_L0(cb) PACK_YUV(cb,y2,y2,u,v)
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
104 #define TO_YUY2_L1(cb) PACK_YUV(cb,y3,y3,u,v)
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
105
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
106 #define TO_YUY2_U(cb) PACK_YUV(cb,y0,y1,u,v)
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
107 #define TO_YUY2_L(cb) PACK_YUV(cb,y2,y3,u,v)
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
108
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
109 /* ------------------------------------------------------------------------ */
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
110 inline void cvid_v1_yuy2(unsigned char *frm, unsigned char *end, int stride, cvid_codebook *cb)
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
111 {
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
112 unsigned long *vptr = (unsigned long *)frm, rgb;
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
113 int row_inc = stride/4;
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
114
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
115 vptr[0] = TO_YUY2_U0(cb);
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
116 vptr[1] = TO_YUY2_U1(cb);
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
117 vptr += row_inc; if(vptr > (unsigned long *)end) return;
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
118
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
119 vptr[0] = TO_YUY2_U0(cb);
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
120 vptr[1] = TO_YUY2_U1(cb);
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
121 vptr += row_inc; if(vptr > (unsigned long *)end) return;
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
122
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
123 vptr[0] = TO_YUY2_L0(cb);
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
124 vptr[1] = TO_YUY2_L1(cb);
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
125 vptr += row_inc; if(vptr > (unsigned long *)end) return;
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
126
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
127 vptr[0] = TO_YUY2_L0(cb);
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
128 vptr[1] = TO_YUY2_L1(cb);
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
129 }
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
130
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
131
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
132 /* ------------------------------------------------------------------------ */
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
133 inline void cvid_v4_yuy2(unsigned char *frm, unsigned char *end, int stride, cvid_codebook *cb0,
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
134 cvid_codebook *cb1, cvid_codebook *cb2, cvid_codebook *cb3)
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
135 {
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
136 unsigned long *vptr = (unsigned long *)frm;
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
137 int row_inc = stride/4;
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
138
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
139 vptr[0] = TO_YUY2_U(cb0);
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
140 vptr[1] = TO_YUY2_U(cb1);
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
141 vptr += row_inc; if(vptr > (unsigned long *)end) return;
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
142
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
143 vptr[0] = TO_YUY2_L(cb0);
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
144 vptr[1] = TO_YUY2_L(cb1);
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
145 vptr += row_inc; if(vptr > (unsigned long *)end) return;
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
146
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
147 vptr[0] = TO_YUY2_U(cb2);
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
148 vptr[1] = TO_YUY2_U(cb3);
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
149 vptr += row_inc; if(vptr > (unsigned long *)end) return;
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
150
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
151 vptr[0] = TO_YUY2_L(cb2);
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
152 vptr[1] = TO_YUY2_L(cb3);
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
153
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
154 }
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
155
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
156
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
157 /* ---------------------------------------------------------------------- */
3643
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
158 static inline void read_codebook_32(cvid_codebook *c, int mode)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
159 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
160 int uvr, uvg, uvb;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
161
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
162 if(mode) /* black and white */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
163 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
164 c->y0 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
165 c->y1 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
166 c->y2 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
167 c->y3 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
168 c->u = c->v = 0;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
169
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
170 c->rgb0 = (c->y0 << 16) | (c->y0 << 8) | c->y0;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
171 c->rgb1 = (c->y1 << 16) | (c->y1 << 8) | c->y1;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
172 c->rgb2 = (c->y2 << 16) | (c->y2 << 8) | c->y2;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
173 c->rgb3 = (c->y3 << 16) | (c->y3 << 8) | c->y3;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
174 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
175 else /* colour */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
176 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
177 c->y0 = get_byte(); /* luma */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
178 c->y1 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
179 c->y2 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
180 c->y3 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
181 c->u = get_byte(); /* chroma */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
182 c->v = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
183
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
184 uvr = c->v << 1;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
185 uvg = -((c->u+1) >> 1) - c->v;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
186 uvb = c->u << 1;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
187
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
188 c->rgb0 = (uiclp[c->y0 + uvr] << 16) | (uiclp[c->y0 + uvg] << 8) | uiclp[c->y0 + uvb];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
189 c->rgb1 = (uiclp[c->y1 + uvr] << 16) | (uiclp[c->y1 + uvg] << 8) | uiclp[c->y1 + uvb];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
190 c->rgb2 = (uiclp[c->y2 + uvr] << 16) | (uiclp[c->y2 + uvg] << 8) | uiclp[c->y2 + uvb];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
191 c->rgb3 = (uiclp[c->y3 + uvr] << 16) | (uiclp[c->y3 + uvg] << 8) | uiclp[c->y3 + uvb];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
192 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
193 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
194
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
195
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
196 /* ------------------------------------------------------------------------ */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
197 inline void cvid_v1_32(unsigned char *frm, unsigned char *end, int stride, cvid_codebook *cb)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
198 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
199 unsigned long *vptr = (unsigned long *)frm, rgb;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
200 int row_inc = stride/4;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
201
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
202 vptr[0] = rgb = cb->rgb0; vptr[1] = rgb;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
203 vptr[2] = rgb = cb->rgb1; vptr[3] = rgb;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
204 vptr += row_inc; if(vptr > (unsigned long *)end) return;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
205 vptr[0] = rgb = cb->rgb0; vptr[1] = rgb;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
206 vptr[2] = rgb = cb->rgb1; vptr[3] = rgb;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
207 vptr += row_inc; if(vptr > (unsigned long *)end) return;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
208 vptr[0] = rgb = cb->rgb2; vptr[1] = rgb;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
209 vptr[2] = rgb = cb->rgb3; vptr[3] = rgb;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
210 vptr += row_inc; if(vptr > (unsigned long *)end) return;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
211 vptr[0] = rgb = cb->rgb2; vptr[1] = rgb;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
212 vptr[2] = rgb = cb->rgb3; vptr[3] = rgb;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
213 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
214
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
215
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
216 /* ------------------------------------------------------------------------ */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
217 inline void cvid_v4_32(unsigned char *frm, unsigned char *end, int stride, cvid_codebook *cb0,
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
218 cvid_codebook *cb1, cvid_codebook *cb2, cvid_codebook *cb3)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
219 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
220 unsigned long *vptr = (unsigned long *)frm;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
221 int row_inc = stride/4;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
222
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
223 vptr[0] = cb0->rgb0;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
224 vptr[1] = cb0->rgb1;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
225 vptr[2] = cb1->rgb0;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
226 vptr[3] = cb1->rgb1;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
227 vptr += row_inc; if(vptr > (unsigned long *)end) return;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
228 vptr[0] = cb0->rgb2;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
229 vptr[1] = cb0->rgb3;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
230 vptr[2] = cb1->rgb2;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
231 vptr[3] = cb1->rgb3;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
232 vptr += row_inc; if(vptr > (unsigned long *)end) return;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
233 vptr[0] = cb2->rgb0;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
234 vptr[1] = cb2->rgb1;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
235 vptr[2] = cb3->rgb0;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
236 vptr[3] = cb3->rgb1;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
237 vptr += row_inc; if(vptr > (unsigned long *)end) return;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
238 vptr[0] = cb2->rgb2;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
239 vptr[1] = cb2->rgb3;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
240 vptr[2] = cb3->rgb2;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
241 vptr[3] = cb3->rgb3;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
242 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
243
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
244
3646
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
245
3643
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
246 /* ---------------------------------------------------------------------- */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
247 static inline void read_codebook_24(cvid_codebook *c, int mode)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
248 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
249 int uvr, uvg, uvb;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
250
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
251 if(mode) /* black and white */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
252 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
253 c->y0 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
254 c->y1 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
255 c->y2 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
256 c->y3 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
257 c->u = c->v = 0;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
258
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
259 c->r[0] = c->g[0] = c->b[0] = c->y0;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
260 c->r[1] = c->g[1] = c->b[1] = c->y1;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
261 c->r[2] = c->g[2] = c->b[2] = c->y2;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
262 c->r[3] = c->g[3] = c->b[3] = c->y3;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
263 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
264 else /* colour */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
265 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
266 c->y0 = get_byte(); /* luma */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
267 c->y1 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
268 c->y2 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
269 c->y3 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
270 c->u = get_byte(); /* chroma */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
271 c->v = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
272
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
273 uvr = c->v << 1;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
274 uvg = -((c->u+1) >> 1) - c->v;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
275 uvb = c->u << 1;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
276
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
277 c->r[0] = uiclp[c->y0 + uvr]; c->g[0] = uiclp[c->y0 + uvg]; c->b[0] = uiclp[c->y0 + uvb];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
278 c->r[1] = uiclp[c->y1 + uvr]; c->g[1] = uiclp[c->y1 + uvg]; c->b[1] = uiclp[c->y1 + uvb];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
279 c->r[2] = uiclp[c->y2 + uvr]; c->g[2] = uiclp[c->y2 + uvg]; c->b[2] = uiclp[c->y2 + uvb];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
280 c->r[3] = uiclp[c->y3 + uvr]; c->g[3] = uiclp[c->y3 + uvg]; c->b[3] = uiclp[c->y3 + uvb];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
281 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
282 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
283
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
284
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
285 /* ------------------------------------------------------------------------ */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
286 void cvid_v1_24(unsigned char *vptr, unsigned char *end, int stride, cvid_codebook *cb)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
287 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
288 unsigned char r, g, b;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
289 int row_inc = stride-4*3;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
290
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
291 *vptr++ = b = cb->b[0]; *vptr++ = g = cb->g[0]; *vptr++ = r = cb->r[0];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
292 *vptr++ = b; *vptr++ = g; *vptr++ = r;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
293 *vptr++ = b = cb->b[1]; *vptr++ = g = cb->g[1]; *vptr++ = r = cb->r[1];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
294 *vptr++ = b; *vptr++ = g; *vptr++ = r;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
295 vptr += row_inc; if(vptr > end) return;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
296 *vptr++ = b = cb->b[0]; *vptr++ = g = cb->g[0]; *vptr++ = r = cb->r[0];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
297 *vptr++ = b; *vptr++ = g; *vptr++ = r;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
298 *vptr++ = b = cb->b[1]; *vptr++ = g = cb->g[1]; *vptr++ = r = cb->r[1];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
299 *vptr++ = b; *vptr++ = g; *vptr++ = r;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
300 vptr += row_inc; if(vptr > end) return;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
301 *vptr++ = b = cb->b[2]; *vptr++ = g = cb->g[2]; *vptr++ = r = cb->r[2];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
302 *vptr++ = b; *vptr++ = g; *vptr++ = r;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
303 *vptr++ = b = cb->b[3]; *vptr++ = g = cb->g[3]; *vptr++ = r = cb->r[3];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
304 *vptr++ = b; *vptr++ = g; *vptr++ = r;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
305 vptr += row_inc; if(vptr > end) return;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
306 *vptr++ = b = cb->b[2]; *vptr++ = g = cb->g[2]; *vptr++ = r = cb->r[2];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
307 *vptr++ = b; *vptr++ = g; *vptr++ = r;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
308 *vptr++ = b = cb->b[3]; *vptr++ = g = cb->g[3]; *vptr++ = r = cb->r[3];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
309 *vptr++ = b; *vptr++ = g; *vptr++ = r;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
310 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
311
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
312
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
313 /* ------------------------------------------------------------------------ */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
314 void cvid_v4_24(unsigned char *vptr, unsigned char *end, int stride, cvid_codebook *cb0,
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
315 cvid_codebook *cb1, cvid_codebook *cb2, cvid_codebook *cb3)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
316 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
317 int row_inc = stride-4*3;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
318
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
319 *vptr++ = cb0->b[0]; *vptr++ = cb0->g[0]; *vptr++ = cb0->r[0];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
320 *vptr++ = cb0->b[1]; *vptr++ = cb0->g[1]; *vptr++ = cb0->r[1];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
321 *vptr++ = cb1->b[0]; *vptr++ = cb1->g[0]; *vptr++ = cb1->r[0];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
322 *vptr++ = cb1->b[1]; *vptr++ = cb1->g[1]; *vptr++ = cb1->r[1];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
323 vptr += row_inc; if(vptr > end) return;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
324 *vptr++ = cb0->b[2]; *vptr++ = cb0->g[2]; *vptr++ = cb0->r[2];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
325 *vptr++ = cb0->b[3]; *vptr++ = cb0->g[3]; *vptr++ = cb0->r[3];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
326 *vptr++ = cb1->b[2]; *vptr++ = cb1->g[2]; *vptr++ = cb1->r[2];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
327 *vptr++ = cb1->b[3]; *vptr++ = cb1->g[3]; *vptr++ = cb1->r[3];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
328 vptr += row_inc; if(vptr > end) return;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
329 *vptr++ = cb2->b[0]; *vptr++ = cb2->g[0]; *vptr++ = cb2->r[0];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
330 *vptr++ = cb2->b[1]; *vptr++ = cb2->g[1]; *vptr++ = cb2->r[1];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
331 *vptr++ = cb3->b[0]; *vptr++ = cb3->g[0]; *vptr++ = cb3->r[0];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
332 *vptr++ = cb3->b[1]; *vptr++ = cb3->g[1]; *vptr++ = cb3->r[1];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
333 vptr += row_inc; if(vptr > end) return;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
334 *vptr++ = cb2->b[2]; *vptr++ = cb2->g[2]; *vptr++ = cb2->r[2];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
335 *vptr++ = cb2->b[3]; *vptr++ = cb2->g[3]; *vptr++ = cb2->r[3];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
336 *vptr++ = cb3->b[2]; *vptr++ = cb3->g[2]; *vptr++ = cb3->r[2];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
337 *vptr++ = cb3->b[3]; *vptr++ = cb3->g[3]; *vptr++ = cb3->r[3];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
338 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
339
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
340
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
341 /* ------------------------------------------------------------------------
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
342 * Call this function once at the start of the sequence and save the
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
343 * returned context for calls to decode_cinepak().
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
344 */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
345 void *decode_cinepak_init(void)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
346 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
347 cinepak_info *cvinfo;
4076
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
348 int i, x;
3643
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
349
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
350 if((cvinfo = calloc(sizeof(cinepak_info), 1)) == NULL) return NULL;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
351 cvinfo->strip_num = 0;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
352
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
353 if(uiclp == NULL)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
354 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
355 uiclp = uiclip+512;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
356 for(i = -512; i < 512; i++)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
357 uiclp[i] = (i < 0 ? 0 : (i > 255 ? 255 : i));
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
358 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
359
4076
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
360 for(i = 0, x = -128; i < 256; i++, x++)
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
361 {
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
362 CU_Y_tab[i] = (-FIX(0.0655)) * x;
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
363 CV_Y_tab[i] = (FIX(0.0110)) * x + ONE_HALF;
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
364 CU_Cb_tab[i] = (FIX(1.1656)) * x;
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
365 CV_Cb_tab[i] = (-FIX(0.0062)) * x + ONE_HALF + FIX(128);
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
366 CU_Cr_tab[i] = (FIX(0.0467)) * x;
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
367 CV_Cr_tab[i] = (FIX(1.4187)) * x + ONE_HALF + FIX(128);
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
368 }
47b9d8d3f3c5 committed Tim Ferguson's patch for proper YUV color space conversion
melanson
parents: 3646
diff changeset
369
3643
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
370 return (void *)cvinfo;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
371 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
372
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
373
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
374 /* ------------------------------------------------------------------------
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
375 * This function decodes a buffer containing a Cinepak encoded frame.
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
376 *
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
377 * context - the context created by decode_cinepak_init().
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
378 * buf - the input buffer to be decoded
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
379 * size - the size of the input buffer
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
380 * frame - the output frame buffer (24 or 32 bit per pixel)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
381 * width - the width of the output frame
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
382 * height - the height of the output frame
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
383 * bit_per_pixel - the number of bits per pixel allocated to the output
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
384 * frame (only 24 or 32 bpp are supported)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
385 */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
386 void decode_cinepak(void *context, unsigned char *buf, int size, unsigned char *frame, int width, int height, int bit_per_pixel)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
387 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
388 cinepak_info *cvinfo = (cinepak_info *)context;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
389 cvid_codebook *v4_codebook, *v1_codebook, *codebook = NULL;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
390 unsigned long x, y, y_bottom, frame_flags, strips, cv_width, cv_height, cnum,
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
391 strip_id, chunk_id, x0, y0, x1, y1, ci, flag, mask;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
392 long len, top_size, chunk_size;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
393 unsigned char *frm_ptr, *frm_end;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
394 int i, cur_strip, d0, d1, d2, d3, frm_stride, bpp = 3;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
395 void (*read_codebook)(cvid_codebook *c, int mode) = read_codebook_24;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
396 void (*cvid_v1)(unsigned char *frm, unsigned char *end, int stride, cvid_codebook *cb) = cvid_v1_24;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
397 void (*cvid_v4)(unsigned char *frm, unsigned char *end, int stride, cvid_codebook *cb0,
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
398 cvid_codebook *cb1, cvid_codebook *cb2, cvid_codebook *cb3) = cvid_v4_24;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
399
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
400 x = y = 0;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
401 y_bottom = 0;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
402 in_buffer = buf;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
403
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
404 frame_flags = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
405 len = get_byte() << 16;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
406 len |= get_byte() << 8;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
407 len |= get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
408
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
409 switch(bit_per_pixel)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
410 {
3646
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
411 case 16:
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
412 bpp = 2;
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
413 read_codebook = read_codebook_yuy2;
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
414 cvid_v1 = cvid_v1_yuy2;
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
415 cvid_v4 = cvid_v4_yuy2;
3f25f07f4e92 Cinepak YUY2 support
arpi
parents: 3643
diff changeset
416 break;
3643
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
417 case 24:
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
418 bpp = 3;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
419 read_codebook = read_codebook_24;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
420 cvid_v1 = cvid_v1_24;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
421 cvid_v4 = cvid_v4_24;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
422 break;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
423 case 32:
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
424 bpp = 4;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
425 read_codebook = read_codebook_32;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
426 cvid_v1 = cvid_v1_32;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
427 cvid_v4 = cvid_v4_32;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
428 break;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
429 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
430
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
431 frm_stride = width * bpp;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
432 frm_ptr = frame;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
433 frm_end = frm_ptr + width * height * bpp;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
434
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
435 if(len != size)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
436 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
437 if(len & 0x01) len++; /* AVIs tend to have a size mismatch */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
438 if(len != size)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
439 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
440 printf("CVID: corruption %d (QT/AVI) != %ld (CV)\n", size, len);
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
441 // return;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
442 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
443 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
444
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
445 cv_width = get_word();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
446 cv_height = get_word();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
447 strips = get_word();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
448
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
449 if(strips > cvinfo->strip_num)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
450 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
451 if(strips >= MAX_STRIPS)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
452 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
453 printf("CVID: strip overflow (more than %d)\n", MAX_STRIPS);
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
454 return;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
455 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
456
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
457 for(i = cvinfo->strip_num; i < strips; i++)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
458 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
459 if((cvinfo->v4_codebook[i] = (cvid_codebook *)calloc(sizeof(cvid_codebook), 260)) == NULL)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
460 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
461 printf("CVID: codebook v4 alloc err\n");
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
462 return;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
463 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
464
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
465 if((cvinfo->v1_codebook[i] = (cvid_codebook *)calloc(sizeof(cvid_codebook), 260)) == NULL)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
466 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
467 printf("CVID: codebook v1 alloc err\n");
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
468 return;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
469 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
470 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
471 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
472 cvinfo->strip_num = strips;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
473
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
474 #if DBUG
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
475 printf("CVID: <%ld,%ld> strips %ld\n", cv_width, cv_height, strips);
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
476 #endif
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
477
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
478 for(cur_strip = 0; cur_strip < strips; cur_strip++)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
479 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
480 v4_codebook = cvinfo->v4_codebook[cur_strip];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
481 v1_codebook = cvinfo->v1_codebook[cur_strip];
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
482
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
483 if((cur_strip > 0) && (!(frame_flags & 0x01)))
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
484 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
485 memcpy(cvinfo->v4_codebook[cur_strip], cvinfo->v4_codebook[cur_strip-1], 260 * sizeof(cvid_codebook));
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
486 memcpy(cvinfo->v1_codebook[cur_strip], cvinfo->v1_codebook[cur_strip-1], 260 * sizeof(cvid_codebook));
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
487 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
488
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
489 strip_id = get_word(); /* 1000 = key strip, 1100 = iter strip */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
490 top_size = get_word();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
491 y0 = get_word(); /* FIXME: most of these are ignored at the moment */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
492 x0 = get_word();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
493 y1 = get_word();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
494 x1 = get_word();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
495
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
496 y_bottom += y1;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
497 top_size -= 12;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
498 x = 0;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
499 if(x1 != width)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
500 printf("CVID: Warning x1 (%ld) != width (%d)\n", x1, width);
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
501
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
502 #if DBUG
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
503 printf(" %d) %04lx %04ld <%ld,%ld> <%ld,%ld> yt %ld %d\n",
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
504 cur_strip, strip_id, top_size, x0, y0, x1, y1, y_bottom);
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
505 #endif
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
506
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
507 while(top_size > 0)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
508 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
509 chunk_id = get_word();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
510 chunk_size = get_word();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
511
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
512 #if DBUG
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
513 printf(" %04lx %04ld\n", chunk_id, chunk_size);
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
514 #endif
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
515 top_size -= chunk_size;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
516 chunk_size -= 4;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
517
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
518 switch(chunk_id)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
519 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
520 /* -------------------- Codebook Entries -------------------- */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
521 case 0x2000:
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
522 case 0x2200:
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
523 codebook = (chunk_id == 0x2200 ? v1_codebook : v4_codebook);
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
524 cnum = chunk_size/6;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
525 for(i = 0; i < cnum; i++) read_codebook(codebook+i, 0);
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
526 break;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
527
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
528 case 0x2400:
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
529 case 0x2600: /* 8 bit per pixel */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
530 codebook = (chunk_id == 0x2600 ? v1_codebook : v4_codebook);
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
531 cnum = chunk_size/4;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
532 for(i = 0; i < cnum; i++) read_codebook(codebook+i, 1);
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
533 break;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
534
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
535 case 0x2100:
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
536 case 0x2300:
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
537 codebook = (chunk_id == 0x2300 ? v1_codebook : v4_codebook);
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
538
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
539 ci = 0;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
540 while(chunk_size > 0)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
541 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
542 flag = get_long();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
543 chunk_size -= 4;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
544
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
545 for(i = 0; i < 32; i++)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
546 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
547 if(flag & 0x80000000)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
548 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
549 chunk_size -= 6;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
550 read_codebook(codebook+ci, 0);
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
551 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
552
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
553 ci++;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
554 flag <<= 1;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
555 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
556 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
557 while(chunk_size > 0) { skip_byte(); chunk_size--; }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
558 break;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
559
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
560 case 0x2500:
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
561 case 0x2700: /* 8 bit per pixel */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
562 codebook = (chunk_id == 0x2700 ? v1_codebook : v4_codebook);
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
563
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
564 ci = 0;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
565 while(chunk_size > 0)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
566 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
567 flag = get_long();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
568 chunk_size -= 4;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
569
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
570 for(i = 0; i < 32; i++)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
571 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
572 if(flag & 0x80000000)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
573 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
574 chunk_size -= 4;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
575 read_codebook(codebook+ci, 1);
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
576 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
577
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
578 ci++;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
579 flag <<= 1;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
580 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
581 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
582 while(chunk_size > 0) { skip_byte(); chunk_size--; }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
583 break;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
584
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
585 /* -------------------- Frame -------------------- */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
586 case 0x3000:
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
587 while((chunk_size > 0) && (y < y_bottom))
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
588 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
589 flag = get_long();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
590 chunk_size -= 4;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
591
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
592 for(i = 0; i < 32; i++)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
593 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
594 if(y >= y_bottom) break;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
595 if(flag & 0x80000000) /* 4 bytes per block */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
596 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
597 d0 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
598 d1 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
599 d2 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
600 d3 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
601 chunk_size -= 4;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
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);
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
603 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
604 else /* 1 byte per block */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
605 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
606 cvid_v1(frm_ptr + (y * frm_stride + x * bpp), frm_end, frm_stride, v1_codebook + get_byte());
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
607 chunk_size--;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
608 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
609
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
610 x += 4;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
611 if(x >= width)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
612 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
613 x = 0;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
614 y += 4;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
615 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
616 flag <<= 1;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
617 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
618 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
619 while(chunk_size > 0) { skip_byte(); chunk_size--; }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
620 break;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
621
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
622 case 0x3100:
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
623 while((chunk_size > 0) && (y < y_bottom))
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
624 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
625 /* ---- flag bits: 0 = SKIP, 10 = V1, 11 = V4 ---- */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
626 flag = (unsigned long)get_long();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
627 chunk_size -= 4;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
628 mask = 0x80000000;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
629
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
630 while((mask) && (y < y_bottom))
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
631 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
632 if(flag & mask)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
633 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
634 if(mask == 1)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
635 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
636 if(chunk_size < 0) break;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
637 flag = (unsigned long)get_long();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
638 chunk_size -= 4;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
639 mask = 0x80000000;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
640 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
641 else mask >>= 1;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
642
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
643 if(flag & mask) /* V4 */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
644 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
645 d0 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
646 d1 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
647 d2 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
648 d3 = get_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
649 chunk_size -= 4;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
650 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);
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
651 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
652 else /* V1 */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
653 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
654 chunk_size--;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
655 cvid_v1(frm_ptr + (y * frm_stride + x * bpp), frm_end, frm_stride, v1_codebook + get_byte());
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
656 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
657 } /* else SKIP */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
658
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
659 mask >>= 1;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
660 x += 4;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
661 if(x >= width)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
662 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
663 x = 0;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
664 y += 4;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
665 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
666 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
667 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
668
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
669 while(chunk_size > 0) { skip_byte(); chunk_size--; }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
670 break;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
671
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
672 case 0x3200: /* each byte is a V1 codebook */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
673 while((chunk_size > 0) && (y < y_bottom))
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
674 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
675 cvid_v1(frm_ptr + (y * frm_stride + x * bpp), frm_end, frm_stride, v1_codebook + get_byte());
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
676 chunk_size--;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
677 x += 4;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
678 if(x >= width)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
679 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
680 x = 0;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
681 y += 4;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
682 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
683 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
684 while(chunk_size > 0) { skip_byte(); chunk_size--; }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
685 break;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
686
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
687 default:
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
688 printf("CVID: unknown chunk_id %08lx\n", chunk_id);
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
689 while(chunk_size > 0) { skip_byte(); chunk_size--; }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
690 break;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
691 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
692 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
693 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
694
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
695 if(len != size)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
696 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
697 if(len & 0x01) len++; /* AVIs tend to have a size mismatch */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
698 if(len != size)
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
699 {
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
700 long xlen;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
701 skip_byte();
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
702 xlen = get_byte() << 16;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
703 xlen |= get_byte() << 8;
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
704 xlen |= get_byte(); /* Read Len */
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
705 printf("CVID: END INFO chunk size %d cvid size1 %ld cvid size2 %ld\n", size, len, xlen);
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
706 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
707 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
708 }
fb9fd7e2dd35 native opensourec Cinepak (CVID) codec by im Ferguson <timf@mail.csse.monash.edu.au>
arpi
parents:
diff changeset
709