Mercurial > mplayer.hg
annotate libmpcodecs/native/qtrpza.c @ 9319:2e8204f9da6d
1l
author | arpi |
---|---|
date | Fri, 07 Feb 2003 20:01:19 +0000 |
parents | 9fc45fe0d444 |
children |
rev | line source |
---|---|
4615
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
1 /* |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
2 * |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
3 * Apple Video (rpza) QuickTime Decoder for Mplayer |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
4 * (c) 2002 Roberto Togni |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
5 * |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
6 * Fourcc: rpza, azpr |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
7 * |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
8 * Some code comes from qtsmc.c by Mike Melanson |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
9 * |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4615
diff
changeset
|
10 * A description of the decoding algorithm can be found here: |
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4615
diff
changeset
|
11 * http://www.pcisys.net/~melanson/codecs/ |
4615
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
12 */ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
13 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
14 #include "config.h" |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
15 #include "bswap.h" |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
16 #include "mp_msg.h" |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
17 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
18 #define BE_16(x) (be2me_16(*(unsigned short *)(x))) |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
19 #define BE_32(x) (be2me_32(*(unsigned int *)(x))) |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
20 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
21 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
22 #define ADVANCE_BLOCK() \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
23 { \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
24 pixel_ptr += block_x_inc; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
25 if (pixel_ptr >= (width * bytes_per_pixel)) \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
26 { \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
27 pixel_ptr = 0; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
28 row_ptr += block_y_inc * 4; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
29 } \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
30 total_blocks--; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
31 if (total_blocks < 0) \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
32 { \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
33 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "block counter just went negative (this should not happen)\n"); \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
34 return; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
35 } \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
36 } |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
37 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
38 #define PAINT_CURRENT_PIXEL(r, g, b, color) \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
39 { \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
40 if (bytes_per_pixel == 2) { \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
41 (*(unsigned short*)(&decoded[block_ptr])) = color & 0x7fff; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
42 block_ptr += 2; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
43 } else { \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
44 decoded[block_ptr++] = (b); \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
45 decoded[block_ptr++] = (g); \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
46 decoded[block_ptr++] = (r); \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
47 if (bytes_per_pixel == 4) /* 32bpp */ \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
48 block_ptr++; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
49 } \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
50 } |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
51 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
52 #define COLOR_FIX(col_out, col_in) (col_out) = ((col_in) << 3) | ((col_in) >> 2) |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
53 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
54 #define COLOR_TO_RGB(r, g, b, color) \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
55 { \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
56 if (bytes_per_pixel != 2) { \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
57 unsigned short tmp; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
58 tmp = (color >> 10) & 0x1f; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
59 COLOR_FIX (r, tmp); \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
60 tmp = (color >> 5) & 0x1f; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
61 COLOR_FIX (g, tmp); \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
62 tmp = color & 0x1f; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
63 COLOR_FIX (b, tmp); \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
64 } \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
65 } |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
66 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
67 #define COLORAB_TO_RGB4(rgb4, color4, colorA, colorB) \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
68 { \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
69 unsigned short ta, tb, tt; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
70 if (bytes_per_pixel != 2) { \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
71 ta = (colorA >> 10) & 0x1f; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
72 tb = (colorB >> 10) & 0x1f; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
73 COLOR_FIX (rgb4[3][0], ta); \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
74 COLOR_FIX (rgb4[0][0], tb); \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
75 tt = (11 * ta + 21 * tb) >> 5; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
76 COLOR_FIX (rgb4[1][0], tt); \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
77 tt = (21 * ta + 11 * tb) >> 5; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
78 COLOR_FIX (rgb4[2][0], tt); \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
79 ta = (colorA >> 5) & 0x1f; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
80 tb = (colorB >> 5) & 0x1f; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
81 COLOR_FIX (rgb4[3][1], ta); \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
82 COLOR_FIX (rgb4[0][1], tb); \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
83 tt = (11 * ta + 21 * tb) >> 5; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
84 COLOR_FIX (rgb4[1][1], tt); \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
85 tt = (21 * ta + 11 * tb) >> 5; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
86 COLOR_FIX (rgb4[2][1], tt); \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
87 ta = colorA & 0x1f; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
88 tb = colorB & 0x1f; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
89 COLOR_FIX (rgb4[3][2], ta); \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
90 COLOR_FIX (rgb4[0][2], tb); \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
91 tt = (11 * ta + 21 * tb) >> 5; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
92 COLOR_FIX (rgb4[1][2], tt); \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
93 tt = (21 * ta + 11 * tb) >> 5; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
94 COLOR_FIX (rgb4[2][2], tt); \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
95 } else { \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
96 color4[3] = colorA; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
97 color4[0] = colorB; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
98 ta = (colorA >> 10) & 0x1f; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
99 tb = (colorB >> 10) & 0x1f; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
100 color4[1] = ((11 * ta + 21 * tb) << 5) & 0x7c00; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
101 color4[2] = ((21 * ta + 11 * tb) << 5) & 0x7c00; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
102 ta = (colorA >> 5) & 0x1f; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
103 tb = (colorB >> 5) & 0x1f; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
104 color4[1] |= (11 * ta + 21 * tb) & 0x3e0; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
105 color4[2] |= (21 * ta + 11 * tb) & 0x3e0; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
106 ta = colorA & 0x1f; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
107 tb = colorB & 0x1f; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
108 color4[1] |= (11 * ta + 21 * tb) >> 5; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
109 color4[2] |= (21 * ta + 11 * tb) >> 5; \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
110 } \ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
111 } |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
112 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
113 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
114 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
115 /* |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
116 * rpza frame decoder |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
117 * |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
118 * Input values: |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
119 * |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
120 * *encoded: buffer of encoded data (chunk) |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
121 * encoded_size: length of encoded buffer |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
122 * *decoded: buffer where decoded data is written (image buffer) |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
123 * width: width of decoded frame in pixels |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
124 * height: height of decoded frame in pixels |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
125 * bytes_per_pixel: bytes/pixel in output image (color depth) |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
126 * |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
127 */ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
128 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
129 void qt_decode_rpza(char *encoded, int encoded_size, char *decoded, int width, |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
130 int height, int bytes_per_pixel) |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
131 { |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
132 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
133 int stream_ptr = 0; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
134 int chunk_size; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
135 unsigned char opcode; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
136 int n_blocks; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
137 unsigned short colorA, colorB; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
138 unsigned char r, g, b; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
139 unsigned char rgb4[4][3]; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
140 unsigned short color4[4]; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
141 unsigned char index, idx; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
142 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
143 int row_ptr = 0; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
144 int pixel_ptr = 0; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
145 int pixel_x, pixel_y; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
146 int row_inc = bytes_per_pixel * (width - 4); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
147 int block_x_inc = bytes_per_pixel * 4; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
148 int block_y_inc = bytes_per_pixel * width; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
149 int block_ptr; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
150 int total_blocks; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
151 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
152 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
153 /* First byte is always 0xe1. Warn if it's different */ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
154 if ((unsigned char)encoded[stream_ptr] != 0xe1) |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
155 mp_msg(MSGT_DECVIDEO, MSGL_WARN, |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
156 "First chunk byte is 0x%02x instead of 0x1e\n", |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
157 (unsigned char)encoded[stream_ptr]); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
158 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
159 /* Get chunk size, ingnoring first byte */ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
160 chunk_size = BE_32(&encoded[stream_ptr]) & 0x00FFFFFF; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
161 stream_ptr += 4; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
162 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
163 /* If length mismatch use size from MOV file and try to decode anyway */ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
164 if (chunk_size != encoded_size) |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
165 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "MOV chunk size != encoded chunk size; using MOV chunk size\n"); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
166 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
167 chunk_size = encoded_size; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
168 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
169 /* Number of 4x4 blocks in frame. */ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
170 total_blocks = (width * height) / (4 * 4); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
171 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
172 /* Process chunk data */ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
173 while (stream_ptr < chunk_size) { |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
174 opcode = encoded[stream_ptr++]; /* Get opcode */ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
175 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
176 n_blocks = (opcode & 0x1f) +1; /* Extract block counter from opcode */ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
177 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
178 /* If opcode MSbit is 0, we need more data to decide what to do */ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
179 if ((opcode & 0x80) == 0) { |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
180 colorA = (opcode << 8) | ((unsigned char)encoded[stream_ptr++]); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
181 opcode = 0; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
182 if ((encoded[stream_ptr] & 0x80) != 0) { |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
183 /* Must behave as opcode 110xxxxx, using colorA computed above.*/ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
184 /* Use fake opcode 0x20 to enter switch block at the right place */ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
185 opcode = 0x20; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
186 n_blocks = 1; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
187 } |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
188 } |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
189 switch (opcode & 0xe0) { |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
190 /* Skip blocks */ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
191 case 0x80: |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
192 while (n_blocks--) |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
193 ADVANCE_BLOCK(); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
194 break; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
195 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
196 /* Fill blocks with one color */ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
197 case 0xa0: |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
198 colorA = BE_16 (&encoded[stream_ptr]); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
199 stream_ptr += 2; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
200 COLOR_TO_RGB (r, g, b, colorA); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
201 while (n_blocks--) { |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
202 block_ptr = row_ptr + pixel_ptr; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
203 for (pixel_y = 0; pixel_y < 4; pixel_y++) { |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
204 for (pixel_x = 0; pixel_x < 4; pixel_x++){ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
205 PAINT_CURRENT_PIXEL(r, g, b, colorA); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
206 } |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
207 block_ptr += row_inc; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
208 } |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
209 ADVANCE_BLOCK(); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
210 } |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
211 break; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
212 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
213 /* Fill blocks with 4 colors */ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
214 case 0xc0: |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
215 colorA = BE_16 (&encoded[stream_ptr]); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
216 stream_ptr += 2; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
217 case 0x20: |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
218 colorB = BE_16 (&encoded[stream_ptr]); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
219 stream_ptr += 2; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
220 COLORAB_TO_RGB4 (rgb4, color4, colorA, colorB); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
221 while (n_blocks--) { |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
222 block_ptr = row_ptr + pixel_ptr; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
223 for (pixel_y = 0; pixel_y < 4; pixel_y++) { |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
224 index = encoded[stream_ptr++]; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
225 for (pixel_x = 0; pixel_x < 4; pixel_x++){ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
226 idx = (index >> (2 * (3 - pixel_x))) & 0x03; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
227 PAINT_CURRENT_PIXEL(rgb4[idx][0], rgb4[idx][1], rgb4[idx][2], color4[idx]); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
228 } |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
229 block_ptr += row_inc; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
230 } |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
231 ADVANCE_BLOCK(); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
232 } |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
233 break; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
234 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
235 /* Fill block with 16 colors */ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
236 case 0x00: |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
237 block_ptr = row_ptr + pixel_ptr; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
238 for (pixel_y = 0; pixel_y < 4; pixel_y++) { |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
239 for (pixel_x = 0; pixel_x < 4; pixel_x++){ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
240 /* We already have color of upper left pixel */ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
241 if ((pixel_y != 0) || (pixel_x !=0)) { |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
242 colorA = BE_16 (&encoded[stream_ptr]); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
243 stream_ptr += 2; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
244 } |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
245 COLOR_TO_RGB (r, g, b, colorA); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
246 PAINT_CURRENT_PIXEL(r, g, b, colorA); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
247 } |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
248 block_ptr += row_inc; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
249 } |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
250 ADVANCE_BLOCK(); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
251 break; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
252 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
253 /* Unknown opcode */ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
254 default: |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
255 mp_msg(MSGT_DECVIDEO, MSGL_HINT, "Unknown opcode %d in rpza chunk." |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
256 " Skip remaining %lu bytes of chunk data.\n", opcode, |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
257 chunk_size - stream_ptr); |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
258 return; |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
259 } /* Opcode switch */ |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
260 |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
261 } |
b1fe5f58cd82
Added native codec support for QT RPZA data, courtesy of Roberto Togni
melanson
parents:
diff
changeset
|
262 } |