annotate msvidc.c @ 3218:8ba06b63f873

Fix green borders -> black borders, patch from D. Holm, also small fix to dxr3 ao.
author atmos4
date Fri, 30 Nov 2001 16:11:43 +0000
parents 39f88ed93dd1
children 09f972eef7a3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2960
6b69f306cf6e added copyleft header ;)
alex
parents: 2827
diff changeset
1 /*
6b69f306cf6e added copyleft header ;)
alex
parents: 2827
diff changeset
2 Microsoft Video 1 Decoder
6b69f306cf6e added copyleft header ;)
alex
parents: 2827
diff changeset
3
6b69f306cf6e added copyleft header ;)
alex
parents: 2827
diff changeset
4 (C) 2001 Mike Melanson
6b69f306cf6e added copyleft header ;)
alex
parents: 2827
diff changeset
5
6b69f306cf6e added copyleft header ;)
alex
parents: 2827
diff changeset
6 The description of the algorithm you can read here:
6b69f306cf6e added copyleft header ;)
alex
parents: 2827
diff changeset
7 http://www.pcisys.net/~melanson/video1.txt
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
8
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
9 32bpp support (c) alex
2960
6b69f306cf6e added copyleft header ;)
alex
parents: 2827
diff changeset
10 */
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
11
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
12 #define LE_16(x) *(unsigned short *)(x)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
13
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
14 #define DECODE_BGR555_TO_BGR888(x) \
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
15 x.c1_b = (x.c1 >> 7) & 0xF8; \
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
16 x.c1_g = (x.c1 >> 2) & 0xF8; \
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
17 x.c1_r = (x.c1 << 3) & 0xF8; \
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
18 x.c2_b = (x.c2 >> 7) & 0xF8; \
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
19 x.c2_g = (x.c2 >> 2) & 0xF8; \
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
20 x.c2_r = (x.c2 << 3) & 0xF8;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
21
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
22 #define DECODE_PALETTE_TO_BGR888(x) \
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
23 x.c1_b = palette_map[x.c1 * 4 + 2]; \
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
24 x.c1_g = palette_map[x.c1 * 4 + 1]; \
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
25 x.c1_r = palette_map[x.c1 * 4 + 0]; \
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
26 x.c2_b = palette_map[x.c2 * 4 + 2]; \
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
27 x.c2_g = palette_map[x.c2 * 4 + 1]; \
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
28 x.c2_r = palette_map[x.c2 * 4 + 0];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
29
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
30 struct
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
31 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
32 unsigned short c1, c2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
33 unsigned char c1_r, c1_g, c1_b;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
34 unsigned char c2_r, c2_g, c2_b;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
35 } quad[2][2];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
36
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
37 void AVI_Decode_Video1_16(
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
38 char *encoded,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
39 int encoded_size,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
40 char *decoded,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
41 int width,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
42 int height,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
43 int bytes_per_pixel)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
44 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
45 int block_ptr, pixel_ptr;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
46 int pixel_x, pixel_y; // pixel width and height iterators
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
47 int block_x, block_y; // block width and height iterators
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
48 int blocks_wide, blocks_high; // width and height in 4x4 blocks
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
49 int block_inc;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
50 int row_dec;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
51
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
52 // decoding parameters
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
53 int stream_ptr;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
54 unsigned char byte_a, byte_b;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
55 unsigned short flags;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
56 int skip_blocks;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
57
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
58 stream_ptr = 0;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
59 skip_blocks = 0;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
60 blocks_wide = width / 4;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
61 blocks_high = height / 4;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
62 block_inc = 4 * bytes_per_pixel;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
63 row_dec = (width + 4) * bytes_per_pixel;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
64
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
65 for (block_y = blocks_high; block_y > 0; block_y--)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
66 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
67 block_ptr = ((block_y * 4) - 1) * (width * bytes_per_pixel);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
68 for (block_x = blocks_wide; block_x > 0; block_x--)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
69 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
70 // check if this block should be skipped
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
71 if (skip_blocks)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
72 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
73 block_ptr += block_inc;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
74 skip_blocks--;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
75 continue;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
76 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
77
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
78 pixel_ptr = block_ptr;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
79
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
80 // get the next two bytes in the encoded data stream
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
81 byte_a = encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
82 byte_b = encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
83
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
84 // check if the decode is finished
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
85 if ((byte_a == 0) && (byte_b == 0))
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
86 return;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
87
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
88 // check if this is a skip code
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
89 else if ((byte_b & 0xFC) == 0x84)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
90 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
91 // but don't count the current block
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
92 skip_blocks = ((byte_b - 0x84) << 8) + byte_a - 1;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
93 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
94
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
95 // check if this is in the 2- or 8-color classes
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
96 else if (byte_b < 0x80)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
97 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
98 flags = (byte_b << 8) | byte_a;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
99
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
100 quad[0][0].c1 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
101 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
102 quad[0][0].c2 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
103 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
104
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
105 DECODE_BGR555_TO_BGR888(quad[0][0]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
106
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
107 if (quad[0][0].c1 & 0x8000)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
108 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
109 // 8-color encoding
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
110 quad[1][0].c1 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
111 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
112 quad[1][0].c2 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
113 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
114 quad[0][1].c1 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
115 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
116 quad[0][1].c2 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
117 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
118 quad[1][1].c1 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
119 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
120 quad[1][1].c2 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
121 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
122
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
123 DECODE_BGR555_TO_BGR888(quad[0][1]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
124 DECODE_BGR555_TO_BGR888(quad[1][0]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
125 DECODE_BGR555_TO_BGR888(quad[1][1]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
126
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
127 for (pixel_y = 0; pixel_y < 4; pixel_y++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
128 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
129 for (pixel_x = 0; pixel_x < 4; pixel_x++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
130 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
131 if (flags & 1)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
132 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
133 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c1_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
134 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c1_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
135 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c1_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
136 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
137 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
138 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
139 else
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
140 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
141 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c2_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
142 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c2_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
143 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c2_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
144 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
145 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
146 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
147
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
148 // get the next flag ready to go
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
149 flags >>= 1;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
150 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
151 pixel_ptr -= row_dec;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
152 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
153 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
154 else
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
155 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
156 // 2-color encoding
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
157 for (pixel_y = 0; pixel_y < 4; pixel_y++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
158 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
159 for (pixel_x = 0; pixel_x < 4; pixel_x++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
160 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
161 if (flags & 1)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
162 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
163 decoded[pixel_ptr++] = quad[0][0].c1_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
164 decoded[pixel_ptr++] = quad[0][0].c1_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
165 decoded[pixel_ptr++] = quad[0][0].c1_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
166 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
167 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
168 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
169 else
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
170 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
171 decoded[pixel_ptr++] = quad[0][0].c2_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
172 decoded[pixel_ptr++] = quad[0][0].c2_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
173 decoded[pixel_ptr++] = quad[0][0].c2_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
174 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
175 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
176 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
177
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
178 // get the next flag ready to go
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
179 flags >>= 1;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
180 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
181 pixel_ptr -= row_dec;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
182 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
183 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
184 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
185
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
186 // otherwise, it's a 1-color block
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
187 else
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
188 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
189 quad[0][0].c1 = (byte_b << 8) | byte_a;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
190 DECODE_BGR555_TO_BGR888(quad[0][0]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
191
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
192 for (pixel_y = 0; pixel_y < 4; pixel_y++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
193 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
194 for (pixel_x = 0; pixel_x < 4; pixel_x++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
195 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
196 decoded[pixel_ptr++] = quad[0][0].c1_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
197 decoded[pixel_ptr++] = quad[0][0].c1_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
198 decoded[pixel_ptr++] = quad[0][0].c1_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
199 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
200 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
201 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
202 pixel_ptr -= row_dec;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
203 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
204 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
205
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
206 block_ptr += block_inc;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
207 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
208 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
209 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
210
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
211 void AVI_Decode_Video1_8(
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
212 char *encoded,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
213 int encoded_size,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
214 char *decoded,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
215 int width,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
216 int height,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
217 unsigned char *palette_map,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
218 int bytes_per_pixel)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
219 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
220 int block_ptr, pixel_ptr;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
221 int pixel_x, pixel_y; // pixel width and height iterators
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
222 int block_x, block_y; // block width and height iterators
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
223 int blocks_wide, blocks_high; // width and height in 4x4 blocks
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
224 int block_inc;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
225 int row_dec;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
226
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
227 // decoding parameters
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
228 int stream_ptr;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
229 unsigned char byte_a, byte_b;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
230 unsigned short flags;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
231 int skip_blocks;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
232
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
233 stream_ptr = 0;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
234 skip_blocks = 0;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
235 blocks_wide = width / 4;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
236 blocks_high = height / 4;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
237 block_inc = 4 * bytes_per_pixel;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
238 row_dec = (width + 4) * bytes_per_pixel;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
239
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
240 for (block_y = blocks_high; block_y > 0; block_y--)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
241 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
242 block_ptr = ((block_y * 4) - 1) * (width * bytes_per_pixel);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
243 for (block_x = blocks_wide; block_x > 0; block_x--)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
244 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
245 // check if this block should be skipped
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
246 if (skip_blocks)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
247 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
248 block_ptr += block_inc;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
249 skip_blocks--;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
250 continue;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
251 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
252
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
253 pixel_ptr = block_ptr;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
254
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
255 // get the next two bytes in the encoded data stream
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
256 byte_a = encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
257 byte_b = encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
258
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
259 // check if the decode is finished
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
260 if ((byte_a == 0) && (byte_b == 0))
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
261 return;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
262
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
263 // check if this is a skip code
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
264 else if ((byte_b & 0xFC) == 0x84)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
265 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
266 // but don't count the current block
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
267 skip_blocks = ((byte_b - 0x84) << 8) + byte_a - 1;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
268 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
269
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
270 // check if this is a 2-color block
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
271 else if (byte_b < 0x80)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
272 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
273 flags = (byte_b << 8) | byte_a;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
274
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
275 quad[0][0].c1 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
276 quad[0][0].c2 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
277
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
278 DECODE_PALETTE_TO_BGR888(quad[0][0]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
279
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
280 // 2-color encoding
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
281 for (pixel_y = 0; pixel_y < 4; pixel_y++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
282 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
283 for (pixel_x = 0; pixel_x < 4; pixel_x++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
284 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
285 if (flags & 1)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
286 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
287 decoded[pixel_ptr++] = quad[0][0].c1_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
288 decoded[pixel_ptr++] = quad[0][0].c1_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
289 decoded[pixel_ptr++] = quad[0][0].c1_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
290 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
291 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
292 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
293 else
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
294 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
295 decoded[pixel_ptr++] = quad[0][0].c2_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
296 decoded[pixel_ptr++] = quad[0][0].c2_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
297 decoded[pixel_ptr++] = quad[0][0].c2_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
298 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
299 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
300 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
301
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
302 // get the next flag ready to go
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
303 flags >>= 1;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
304 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
305 pixel_ptr -= row_dec;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
306 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
307 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
308
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
309 // check if it's an 8-color block
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
310 else if (byte_b >= 0x90)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
311 {
3100
d930dbae8473 fixed 8-bit variant
melanson
parents: 2960
diff changeset
312 flags = (byte_b << 8) | byte_a;
d930dbae8473 fixed 8-bit variant
melanson
parents: 2960
diff changeset
313
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
314 quad[0][0].c1 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
315 quad[0][0].c2 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
316 quad[1][0].c1 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
317 quad[1][0].c2 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
318
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
319 quad[0][1].c1 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
320 quad[0][1].c2 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
321 quad[1][1].c1 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
322 quad[1][1].c2 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
323
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
324 DECODE_PALETTE_TO_BGR888(quad[0][0]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
325 DECODE_PALETTE_TO_BGR888(quad[0][1]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
326 DECODE_PALETTE_TO_BGR888(quad[1][0]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
327 DECODE_PALETTE_TO_BGR888(quad[1][1]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
328
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
329 for (pixel_y = 0; pixel_y < 4; pixel_y++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
330 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
331 for (pixel_x = 0; pixel_x < 4; pixel_x++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
332 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
333 if (flags & 1)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
334 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
335 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c1_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
336 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c1_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
337 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c1_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
338 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
339 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
340 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
341 else
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
342 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
343 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c2_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
344 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c2_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
345 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c2_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
346 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
347 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
348 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
349
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
350 // get the next flag ready to go
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
351 flags >>= 1;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
352 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
353 pixel_ptr -= row_dec;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
354 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
355 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
356
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
357 // otherwise, it's a 1-color block
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
358 else
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
359 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
360 // init c2 along with c1 just so c2 is a known value for macro
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
361 quad[0][0].c1 = quad[0][0].c2 = byte_a;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
362 DECODE_PALETTE_TO_BGR888(quad[0][0]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
363
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
364 for (pixel_y = 0; pixel_y < 4; pixel_y++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
365 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
366 for (pixel_x = 0; pixel_x < 4; pixel_x++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
367 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
368 decoded[pixel_ptr++] = quad[0][0].c1_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
369 decoded[pixel_ptr++] = quad[0][0].c1_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
370 decoded[pixel_ptr++] = quad[0][0].c1_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
371 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
372 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
373 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
374 pixel_ptr -= row_dec;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
375 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
376 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
377
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
378 block_ptr += block_inc;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
379 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
380 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
381 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
382