Mercurial > mplayer.hg
annotate msvidc.c @ 3915:8f71d01a22d7
ACEL.P fixed (avifile sync)
author | arpi |
---|---|
date | Mon, 31 Dec 2001 04:35:20 +0000 |
parents | 21c7b77b3e83 |
children | 31cd2e0bb961 |
rev | line source |
---|---|
2960 | 1 /* |
2 Microsoft Video 1 Decoder | |
3 | |
4 (C) 2001 Mike Melanson | |
5 | |
6 The description of the algorithm you can read here: | |
7 http://www.pcisys.net/~melanson/video1.txt | |
3184 | 8 |
9 32bpp support (c) alex | |
2960 | 10 */ |
2827
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
11 |
3509
21c7b77b3e83
fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents:
3332
diff
changeset
|
12 #include "config.h" |
21c7b77b3e83
fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents:
3332
diff
changeset
|
13 #include "bswap.h" |
21c7b77b3e83
fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents:
3332
diff
changeset
|
14 |
21c7b77b3e83
fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents:
3332
diff
changeset
|
15 #define LE_16(x) (le2me_16(*(unsigned short *)(x))) |
2827
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
16 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
17 #define DECODE_BGR555_TO_BGR888(x) \ |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
18 x.c1_b = (x.c1 >> 7) & 0xF8; \ |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
19 x.c1_g = (x.c1 >> 2) & 0xF8; \ |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
20 x.c1_r = (x.c1 << 3) & 0xF8; \ |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
21 x.c2_b = (x.c2 >> 7) & 0xF8; \ |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
22 x.c2_g = (x.c2 >> 2) & 0xF8; \ |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
23 x.c2_r = (x.c2 << 3) & 0xF8; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
24 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
25 #define DECODE_PALETTE_TO_BGR888(x) \ |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
26 x.c1_b = palette_map[x.c1 * 4 + 2]; \ |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
27 x.c1_g = palette_map[x.c1 * 4 + 1]; \ |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
28 x.c1_r = palette_map[x.c1 * 4 + 0]; \ |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
29 x.c2_b = palette_map[x.c2 * 4 + 2]; \ |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
30 x.c2_g = palette_map[x.c2 * 4 + 1]; \ |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
31 x.c2_r = palette_map[x.c2 * 4 + 0]; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
32 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
33 struct |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
34 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
35 unsigned short c1, c2; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
36 unsigned char c1_r, c1_g, c1_b; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
37 unsigned char c2_r, c2_g, c2_b; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
38 } quad[2][2]; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
39 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
40 void AVI_Decode_Video1_16( |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
41 char *encoded, |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
42 int encoded_size, |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
43 char *decoded, |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
44 int width, |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
45 int height, |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
46 int bytes_per_pixel) |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
47 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
48 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
|
49 int total_blocks; |
2827
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
50 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
|
51 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
|
52 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
|
53 int block_inc; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
54 int row_dec; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
55 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
56 // decoding parameters |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
57 int stream_ptr; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
58 unsigned char byte_a, byte_b; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
59 unsigned short flags; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
60 int skip_blocks; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
61 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
62 stream_ptr = 0; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
63 skip_blocks = 0; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
64 blocks_wide = width / 4; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
65 blocks_high = height / 4; |
3332
09f972eef7a3
fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents:
3184
diff
changeset
|
66 total_blocks = blocks_wide * blocks_high; |
2827
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
67 block_inc = 4 * bytes_per_pixel; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
68 row_dec = (width + 4) * bytes_per_pixel; |
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 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
|
71 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
72 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
|
73 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
|
74 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
75 // check if this block should be skipped |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
76 if (skip_blocks) |
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 block_ptr += block_inc; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
79 skip_blocks--; |
3332
09f972eef7a3
fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents:
3184
diff
changeset
|
80 total_blocks--; |
2827
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
81 continue; |
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 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
84 pixel_ptr = block_ptr; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
85 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
86 // 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
|
87 byte_a = encoded[stream_ptr++]; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
88 byte_b = encoded[stream_ptr++]; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
89 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
90 // 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
|
91 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
|
92 return; |
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 // check if this is a skip code |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
95 else if ((byte_b & 0xFC) == 0x84) |
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 // but don't count the current block |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
98 skip_blocks = ((byte_b - 0x84) << 8) + byte_a - 1; |
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 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
101 // 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
|
102 else if (byte_b < 0x80) |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
103 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
104 flags = (byte_b << 8) | byte_a; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
105 |
3509
21c7b77b3e83
fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents:
3332
diff
changeset
|
106 // quad[0][0].c1 = LE_16(&encoded[stream_ptr]); |
2827
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
107 quad[0][0].c1 = LE_16(&encoded[stream_ptr]); |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
108 stream_ptr += 2; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
109 quad[0][0].c2 = LE_16(&encoded[stream_ptr]); |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
110 stream_ptr += 2; |
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 DECODE_BGR555_TO_BGR888(quad[0][0]); |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
113 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
114 if (quad[0][0].c1 & 0x8000) |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
115 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
116 // 8-color encoding |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
117 quad[1][0].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[1][0].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[0][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[0][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 quad[1][1].c1 = LE_16(&encoded[stream_ptr]); |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
126 stream_ptr += 2; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
127 quad[1][1].c2 = LE_16(&encoded[stream_ptr]); |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
128 stream_ptr += 2; |
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 DECODE_BGR555_TO_BGR888(quad[0][1]); |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
131 DECODE_BGR555_TO_BGR888(quad[1][0]); |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
132 DECODE_BGR555_TO_BGR888(quad[1][1]); |
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 for (pixel_y = 0; pixel_y < 4; pixel_y++) |
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 for (pixel_x = 0; pixel_x < 4; pixel_x++) |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
137 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
138 if (flags & 1) |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
139 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
140 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
|
141 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
|
142 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c1_b; |
3184 | 143 if (bytes_per_pixel == 4) /* 32bpp */ |
144 pixel_ptr++; | |
2827
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
145 } |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
146 else |
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 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
|
149 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
|
150 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c2_b; |
3184 | 151 if (bytes_per_pixel == 4) /* 32bpp */ |
152 pixel_ptr++; | |
2827
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 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
155 // get the next flag ready to go |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
156 flags >>= 1; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
157 } |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
158 pixel_ptr -= row_dec; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
159 } |
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 else |
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 // 2-color encoding |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
164 for (pixel_y = 0; pixel_y < 4; pixel_y++) |
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 for (pixel_x = 0; pixel_x < 4; pixel_x++) |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
167 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
168 if (flags & 1) |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
169 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
170 decoded[pixel_ptr++] = quad[0][0].c1_r; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
171 decoded[pixel_ptr++] = quad[0][0].c1_g; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
172 decoded[pixel_ptr++] = quad[0][0].c1_b; |
3184 | 173 if (bytes_per_pixel == 4) /* 32bpp */ |
174 pixel_ptr++; | |
2827
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
175 } |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
176 else |
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 decoded[pixel_ptr++] = quad[0][0].c2_r; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
179 decoded[pixel_ptr++] = quad[0][0].c2_g; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
180 decoded[pixel_ptr++] = quad[0][0].c2_b; |
3184 | 181 if (bytes_per_pixel == 4) /* 32bpp */ |
182 pixel_ptr++; | |
2827
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 // get the next flag ready to go |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
186 flags >>= 1; |
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 pixel_ptr -= row_dec; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
189 } |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
190 } |
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 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
193 // otherwise, it's a 1-color block |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
194 else |
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 quad[0][0].c1 = (byte_b << 8) | byte_a; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
197 DECODE_BGR555_TO_BGR888(quad[0][0]); |
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 for (pixel_y = 0; pixel_y < 4; pixel_y++) |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
200 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
201 for (pixel_x = 0; pixel_x < 4; pixel_x++) |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
202 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
203 decoded[pixel_ptr++] = quad[0][0].c1_r; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
204 decoded[pixel_ptr++] = quad[0][0].c1_g; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
205 decoded[pixel_ptr++] = quad[0][0].c1_b; |
3184 | 206 if (bytes_per_pixel == 4) /* 32bpp */ |
207 pixel_ptr++; | |
2827
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 pixel_ptr -= row_dec; |
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 } |
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 block_ptr += block_inc; |
3332
09f972eef7a3
fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents:
3184
diff
changeset
|
214 total_blocks--; |
2827
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
215 } |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
216 } |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
217 } |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
218 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
219 void AVI_Decode_Video1_8( |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
220 char *encoded, |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
221 int encoded_size, |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
222 char *decoded, |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
223 int width, |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
224 int height, |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
225 unsigned char *palette_map, |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
226 int bytes_per_pixel) |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
227 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
228 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
|
229 int total_blocks; |
2827
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
230 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
|
231 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
|
232 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
|
233 int block_inc; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
234 int row_dec; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
235 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
236 // decoding parameters |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
237 int stream_ptr; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
238 unsigned char byte_a, byte_b; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
239 unsigned short flags; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
240 int skip_blocks; |
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 stream_ptr = 0; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
243 skip_blocks = 0; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
244 blocks_wide = width / 4; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
245 blocks_high = height / 4; |
3332
09f972eef7a3
fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents:
3184
diff
changeset
|
246 total_blocks = blocks_wide * blocks_high; |
2827
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
247 block_inc = 4 * bytes_per_pixel; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
248 row_dec = (width + 4) * bytes_per_pixel; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
249 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
250 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
|
251 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
252 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
|
253 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
|
254 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
255 // check if this block should be skipped |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
256 if (skip_blocks) |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
257 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
258 block_ptr += block_inc; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
259 skip_blocks--; |
3332
09f972eef7a3
fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents:
3184
diff
changeset
|
260 total_blocks--; |
2827
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
261 continue; |
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 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
264 pixel_ptr = block_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 // 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
|
267 byte_a = encoded[stream_ptr++]; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
268 byte_b = encoded[stream_ptr++]; |
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 the decode is finished |
3332
09f972eef7a3
fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents:
3184
diff
changeset
|
271 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
|
272 return; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
273 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
274 // check if this is a skip code |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
275 else if ((byte_b & 0xFC) == 0x84) |
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 // but don't count the current block |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
278 skip_blocks = ((byte_b - 0x84) << 8) + byte_a - 1; |
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 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
281 // check if this is a 2-color block |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
282 else if (byte_b < 0x80) |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
283 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
284 flags = (byte_b << 8) | byte_a; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
285 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
286 quad[0][0].c1 = (unsigned char)encoded[stream_ptr++]; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
287 quad[0][0].c2 = (unsigned char)encoded[stream_ptr++]; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
288 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
289 DECODE_PALETTE_TO_BGR888(quad[0][0]); |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
290 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
291 // 2-color encoding |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
292 for (pixel_y = 0; pixel_y < 4; pixel_y++) |
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 for (pixel_x = 0; pixel_x < 4; pixel_x++) |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
295 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
296 if (flags & 1) |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
297 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
298 decoded[pixel_ptr++] = quad[0][0].c1_r; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
299 decoded[pixel_ptr++] = quad[0][0].c1_g; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
300 decoded[pixel_ptr++] = quad[0][0].c1_b; |
3184 | 301 if (bytes_per_pixel == 4) /* 32bpp */ |
302 pixel_ptr++; | |
2827
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
303 } |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
304 else |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
305 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
306 decoded[pixel_ptr++] = quad[0][0].c2_r; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
307 decoded[pixel_ptr++] = quad[0][0].c2_g; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
308 decoded[pixel_ptr++] = quad[0][0].c2_b; |
3184 | 309 if (bytes_per_pixel == 4) /* 32bpp */ |
310 pixel_ptr++; | |
2827
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 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
313 // get the next flag ready to go |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
314 flags >>= 1; |
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 pixel_ptr -= row_dec; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
317 } |
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 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
320 // check if it's an 8-color block |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
321 else if (byte_b >= 0x90) |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
322 { |
3100 | 323 flags = (byte_b << 8) | byte_a; |
324 | |
2827
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
325 quad[0][0].c1 = (unsigned char)encoded[stream_ptr++]; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
326 quad[0][0].c2 = (unsigned char)encoded[stream_ptr++]; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
327 quad[1][0].c1 = (unsigned char)encoded[stream_ptr++]; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
328 quad[1][0].c2 = (unsigned char)encoded[stream_ptr++]; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
329 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
330 quad[0][1].c1 = (unsigned char)encoded[stream_ptr++]; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
331 quad[0][1].c2 = (unsigned char)encoded[stream_ptr++]; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
332 quad[1][1].c1 = (unsigned char)encoded[stream_ptr++]; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
333 quad[1][1].c2 = (unsigned char)encoded[stream_ptr++]; |
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 DECODE_PALETTE_TO_BGR888(quad[0][0]); |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
336 DECODE_PALETTE_TO_BGR888(quad[0][1]); |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
337 DECODE_PALETTE_TO_BGR888(quad[1][0]); |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
338 DECODE_PALETTE_TO_BGR888(quad[1][1]); |
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 for (pixel_y = 0; pixel_y < 4; pixel_y++) |
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 for (pixel_x = 0; pixel_x < 4; pixel_x++) |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
343 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
344 if (flags & 1) |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
345 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
346 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
|
347 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
|
348 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c1_b; |
3184 | 349 if (bytes_per_pixel == 4) /* 32bpp */ |
350 pixel_ptr++; | |
2827
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
351 } |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
352 else |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
353 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
354 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
|
355 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
|
356 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c2_b; |
3184 | 357 if (bytes_per_pixel == 4) /* 32bpp */ |
358 pixel_ptr++; | |
2827
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 |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
361 // get the next flag ready to go |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
362 flags >>= 1; |
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 pixel_ptr -= row_dec; |
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 } |
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 // otherwise, it's a 1-color block |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
369 else |
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 // 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
|
372 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
|
373 DECODE_PALETTE_TO_BGR888(quad[0][0]); |
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 for (pixel_y = 0; pixel_y < 4; pixel_y++) |
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 for (pixel_x = 0; pixel_x < 4; pixel_x++) |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
378 { |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
379 decoded[pixel_ptr++] = quad[0][0].c1_r; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
380 decoded[pixel_ptr++] = quad[0][0].c1_g; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
381 decoded[pixel_ptr++] = quad[0][0].c1_b; |
3184 | 382 if (bytes_per_pixel == 4) /* 32bpp */ |
383 pixel_ptr++; | |
2827
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 pixel_ptr -= row_dec; |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
386 } |
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 block_ptr += block_inc; |
3332
09f972eef7a3
fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents:
3184
diff
changeset
|
390 total_blocks--; |
2827
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
391 } |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
392 } |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
393 } |
b4d46817f050
ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff
changeset
|
394 |