annotate msvidc.c @ 3419:dfdc17415fb9

I'm missing a file ...
author jaf
date Sun, 09 Dec 2001 22:15:51 +0000
parents 09f972eef7a3
children 21c7b77b3e83
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;
3332
09f972eef7a3 fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents: 3184
diff changeset
46 int total_blocks;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
47 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
48 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
49 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
50 int block_inc;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
51 int row_dec;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
52
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
53 // decoding parameters
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
54 int stream_ptr;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
55 unsigned char byte_a, byte_b;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
56 unsigned short flags;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
57 int skip_blocks;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
58
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
59 stream_ptr = 0;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
60 skip_blocks = 0;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
61 blocks_wide = width / 4;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
62 blocks_high = height / 4;
3332
09f972eef7a3 fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents: 3184
diff changeset
63 total_blocks = blocks_wide * blocks_high;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
64 block_inc = 4 * bytes_per_pixel;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
65 row_dec = (width + 4) * bytes_per_pixel;
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 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
68 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
69 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
70 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
71 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
72 // check if this block should be skipped
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
73 if (skip_blocks)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
74 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
75 block_ptr += block_inc;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
76 skip_blocks--;
3332
09f972eef7a3 fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents: 3184
diff changeset
77 total_blocks--;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
78 continue;
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
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
81 pixel_ptr = block_ptr;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
82
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
83 // 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
84 byte_a = encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
85 byte_b = encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
86
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
87 // check if the decode is finished
3332
09f972eef7a3 fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents: 3184
diff changeset
88 if ((byte_a == 0) && (byte_b == 0) && (total_blocks == 0))
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
89 return;
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 // check if this is a skip code
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
92 else if ((byte_b & 0xFC) == 0x84)
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 // but don't count the current block
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
95 skip_blocks = ((byte_b - 0x84) << 8) + byte_a - 1;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
96 }
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 // 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
99 else if (byte_b < 0x80)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
100 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
101 flags = (byte_b << 8) | byte_a;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
102
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
103 quad[0][0].c1 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
104 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
105 quad[0][0].c2 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
106 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
107
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
108 DECODE_BGR555_TO_BGR888(quad[0][0]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
109
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
110 if (quad[0][0].c1 & 0x8000)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
111 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
112 // 8-color encoding
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
113 quad[1][0].c1 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
114 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
115 quad[1][0].c2 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
116 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
117 quad[0][1].c1 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
118 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
119 quad[0][1].c2 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
120 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
121 quad[1][1].c1 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
122 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
123 quad[1][1].c2 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
124 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
125
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
126 DECODE_BGR555_TO_BGR888(quad[0][1]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
127 DECODE_BGR555_TO_BGR888(quad[1][0]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
128 DECODE_BGR555_TO_BGR888(quad[1][1]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
129
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
130 for (pixel_y = 0; pixel_y < 4; pixel_y++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
131 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
132 for (pixel_x = 0; pixel_x < 4; pixel_x++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
133 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
134 if (flags & 1)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
135 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
136 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
137 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
138 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c1_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
139 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
140 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
141 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
142 else
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
143 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
144 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
145 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
146 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c2_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
147 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
148 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
149 }
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 // get the next flag ready to go
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
152 flags >>= 1;
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 pixel_ptr -= row_dec;
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 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
157 else
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 // 2-color encoding
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
160 for (pixel_y = 0; pixel_y < 4; pixel_y++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
161 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
162 for (pixel_x = 0; pixel_x < 4; pixel_x++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
163 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
164 if (flags & 1)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
165 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
166 decoded[pixel_ptr++] = quad[0][0].c1_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
167 decoded[pixel_ptr++] = quad[0][0].c1_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
168 decoded[pixel_ptr++] = quad[0][0].c1_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
169 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
170 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
171 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
172 else
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
173 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
174 decoded[pixel_ptr++] = quad[0][0].c2_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
175 decoded[pixel_ptr++] = quad[0][0].c2_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
176 decoded[pixel_ptr++] = quad[0][0].c2_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
177 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
178 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
179 }
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 // get the next flag ready to go
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
182 flags >>= 1;
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 pixel_ptr -= row_dec;
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 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
187 }
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 // otherwise, it's a 1-color block
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
190 else
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 quad[0][0].c1 = (byte_b << 8) | byte_a;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
193 DECODE_BGR555_TO_BGR888(quad[0][0]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
194
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
195 for (pixel_y = 0; pixel_y < 4; pixel_y++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
196 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
197 for (pixel_x = 0; pixel_x < 4; pixel_x++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
198 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
199 decoded[pixel_ptr++] = quad[0][0].c1_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
200 decoded[pixel_ptr++] = quad[0][0].c1_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
201 decoded[pixel_ptr++] = quad[0][0].c1_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
202 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
203 pixel_ptr++;
2827
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 pixel_ptr -= row_dec;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
206 }
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 block_ptr += block_inc;
3332
09f972eef7a3 fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents: 3184
diff changeset
210 total_blocks--;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
211 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
212 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
213 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
214
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
215 void AVI_Decode_Video1_8(
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
216 char *encoded,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
217 int encoded_size,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
218 char *decoded,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
219 int width,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
220 int height,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
221 unsigned char *palette_map,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
222 int bytes_per_pixel)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
223 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
224 int block_ptr, pixel_ptr;
3332
09f972eef7a3 fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents: 3184
diff changeset
225 int total_blocks;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
226 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
227 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
228 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
229 int block_inc;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
230 int row_dec;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
231
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
232 // decoding parameters
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
233 int stream_ptr;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
234 unsigned char byte_a, byte_b;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
235 unsigned short flags;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
236 int skip_blocks;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
237
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
238 stream_ptr = 0;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
239 skip_blocks = 0;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
240 blocks_wide = width / 4;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
241 blocks_high = height / 4;
3332
09f972eef7a3 fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents: 3184
diff changeset
242 total_blocks = blocks_wide * blocks_high;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
243 block_inc = 4 * bytes_per_pixel;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
244 row_dec = (width + 4) * bytes_per_pixel;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
245
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
246 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
247 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
248 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
249 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
250 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
251 // check if this block should be skipped
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
252 if (skip_blocks)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
253 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
254 block_ptr += block_inc;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
255 skip_blocks--;
3332
09f972eef7a3 fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents: 3184
diff changeset
256 total_blocks--;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
257 continue;
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
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
260 pixel_ptr = block_ptr;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
261
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
262 // 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
263 byte_a = encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
264 byte_b = encoded[stream_ptr++];
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 // check if the decode is finished
3332
09f972eef7a3 fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents: 3184
diff changeset
267 if ((byte_a == 0) && (byte_b == 0) && (total_blocks == 0))
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
268 return;
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 skip code
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
271 else if ((byte_b & 0xFC) == 0x84)
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 // but don't count the current block
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
274 skip_blocks = ((byte_b - 0x84) << 8) + byte_a - 1;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
275 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
276
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
277 // check if this is a 2-color block
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
278 else if (byte_b < 0x80)
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 flags = (byte_b << 8) | byte_a;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
281
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
282 quad[0][0].c1 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
283 quad[0][0].c2 = (unsigned char)encoded[stream_ptr++];
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 DECODE_PALETTE_TO_BGR888(quad[0][0]);
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 // 2-color encoding
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
288 for (pixel_y = 0; pixel_y < 4; pixel_y++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
289 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
290 for (pixel_x = 0; pixel_x < 4; pixel_x++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
291 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
292 if (flags & 1)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
293 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
294 decoded[pixel_ptr++] = quad[0][0].c1_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
295 decoded[pixel_ptr++] = quad[0][0].c1_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
296 decoded[pixel_ptr++] = quad[0][0].c1_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
297 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
298 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
299 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
300 else
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 decoded[pixel_ptr++] = quad[0][0].c2_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
303 decoded[pixel_ptr++] = quad[0][0].c2_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
304 decoded[pixel_ptr++] = quad[0][0].c2_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
305 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
306 pixel_ptr++;
2827
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 // get the next flag ready to go
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
310 flags >>= 1;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
311 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
312 pixel_ptr -= row_dec;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
313 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
314 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
315
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
316 // check if it's an 8-color block
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
317 else if (byte_b >= 0x90)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
318 {
3100
d930dbae8473 fixed 8-bit variant
melanson
parents: 2960
diff changeset
319 flags = (byte_b << 8) | byte_a;
d930dbae8473 fixed 8-bit variant
melanson
parents: 2960
diff changeset
320
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
321 quad[0][0].c1 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
322 quad[0][0].c2 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
323 quad[1][0].c1 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
324 quad[1][0].c2 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
325
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
326 quad[0][1].c1 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
327 quad[0][1].c2 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
328 quad[1][1].c1 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
329 quad[1][1].c2 = (unsigned char)encoded[stream_ptr++];
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 DECODE_PALETTE_TO_BGR888(quad[0][0]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
332 DECODE_PALETTE_TO_BGR888(quad[0][1]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
333 DECODE_PALETTE_TO_BGR888(quad[1][0]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
334 DECODE_PALETTE_TO_BGR888(quad[1][1]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
335
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
336 for (pixel_y = 0; pixel_y < 4; pixel_y++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
337 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
338 for (pixel_x = 0; pixel_x < 4; pixel_x++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
339 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
340 if (flags & 1)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
341 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
342 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
343 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
344 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c1_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
345 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
346 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
347 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
348 else
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 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
351 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
352 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c2_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
353 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
354 pixel_ptr++;
2827
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 // get the next flag ready to go
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
358 flags >>= 1;
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 pixel_ptr -= row_dec;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
361 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
362 }
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 // otherwise, it's a 1-color block
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
365 else
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
366 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
367 // 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
368 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
369 DECODE_PALETTE_TO_BGR888(quad[0][0]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
370
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
371 for (pixel_y = 0; pixel_y < 4; pixel_y++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
372 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
373 for (pixel_x = 0; pixel_x < 4; pixel_x++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
374 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
375 decoded[pixel_ptr++] = quad[0][0].c1_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
376 decoded[pixel_ptr++] = quad[0][0].c1_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
377 decoded[pixel_ptr++] = quad[0][0].c1_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
378 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
379 pixel_ptr++;
2827
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 pixel_ptr -= row_dec;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
382 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
383 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
384
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
385 block_ptr += block_inc;
3332
09f972eef7a3 fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents: 3184
diff changeset
386 total_blocks--;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
387 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
388 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
389 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
390