annotate msvidc.c @ 4807:156482788caf

osd outside movie support for vo_sdl, patch by Fredrik Kuivinen
author atmos4
date Fri, 22 Feb 2002 15:25:11 +0000
parents 31cd2e0bb961
children
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:
4129
31cd2e0bb961 QT demuxer loads palette information from files that transport palettes in
melanson
parents: 3509
diff changeset
7 http://www.pcisys.net/~melanson/codecs/
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
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
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
106 quad[0][0].c1 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
107 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
108 quad[0][0].c2 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
109 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
110
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
111 DECODE_BGR555_TO_BGR888(quad[0][0]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
112
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
113 if (quad[0][0].c1 & 0x8000)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
114 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
115 // 8-color encoding
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
116 quad[1][0].c1 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
117 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
118 quad[1][0].c2 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
119 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
120 quad[0][1].c1 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
121 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
122 quad[0][1].c2 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
123 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
124 quad[1][1].c1 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
125 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
126 quad[1][1].c2 = LE_16(&encoded[stream_ptr]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
127 stream_ptr += 2;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
128
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
129 DECODE_BGR555_TO_BGR888(quad[0][1]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
130 DECODE_BGR555_TO_BGR888(quad[1][0]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
131 DECODE_BGR555_TO_BGR888(quad[1][1]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
132
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
133 for (pixel_y = 0; pixel_y < 4; pixel_y++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
134 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
135 for (pixel_x = 0; pixel_x < 4; pixel_x++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
136 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
137 if (flags & 1)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
138 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
139 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
140 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
141 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c1_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
142 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
143 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
144 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
145 else
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
146 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
147 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
148 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
149 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c2_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
150 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
151 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
152 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
153
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
154 // get the next flag ready to go
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
155 flags >>= 1;
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 pixel_ptr -= row_dec;
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 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
160 else
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 // 2-color encoding
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
163 for (pixel_y = 0; pixel_y < 4; pixel_y++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
164 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
165 for (pixel_x = 0; pixel_x < 4; pixel_x++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
166 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
167 if (flags & 1)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
168 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
169 decoded[pixel_ptr++] = quad[0][0].c1_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
170 decoded[pixel_ptr++] = quad[0][0].c1_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
171 decoded[pixel_ptr++] = quad[0][0].c1_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
172 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
173 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
174 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
175 else
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
176 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
177 decoded[pixel_ptr++] = quad[0][0].c2_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
178 decoded[pixel_ptr++] = quad[0][0].c2_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
179 decoded[pixel_ptr++] = quad[0][0].c2_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
180 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
181 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
182 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
183
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
184 // get the next flag ready to go
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
185 flags >>= 1;
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 pixel_ptr -= row_dec;
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 }
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 // otherwise, it's a 1-color block
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
193 else
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 quad[0][0].c1 = (byte_b << 8) | byte_a;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
196 DECODE_BGR555_TO_BGR888(quad[0][0]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
197
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
198 for (pixel_y = 0; pixel_y < 4; pixel_y++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
199 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
200 for (pixel_x = 0; pixel_x < 4; pixel_x++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
201 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
202 decoded[pixel_ptr++] = quad[0][0].c1_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
203 decoded[pixel_ptr++] = quad[0][0].c1_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
204 decoded[pixel_ptr++] = quad[0][0].c1_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
205 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
206 pixel_ptr++;
2827
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 pixel_ptr -= row_dec;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
209 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
210 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
211
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
212 block_ptr += block_inc;
3332
09f972eef7a3 fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents: 3184
diff changeset
213 total_blocks--;
2827
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 }
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 void AVI_Decode_Video1_8(
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
219 char *encoded,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
220 int encoded_size,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
221 char *decoded,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
222 int width,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
223 int height,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
224 unsigned char *palette_map,
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
225 int bytes_per_pixel)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
226 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
227 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
228 int total_blocks;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
229 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
230 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
231 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
232 int block_inc;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
233 int row_dec;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
234
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
235 // decoding parameters
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
236 int stream_ptr;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
237 unsigned char byte_a, byte_b;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
238 unsigned short flags;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
239 int skip_blocks;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
240
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
241 stream_ptr = 0;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
242 skip_blocks = 0;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
243 blocks_wide = width / 4;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
244 blocks_high = height / 4;
3332
09f972eef7a3 fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents: 3184
diff changeset
245 total_blocks = blocks_wide * blocks_high;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
246 block_inc = 4 * bytes_per_pixel;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
247 row_dec = (width + 4) * bytes_per_pixel;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
248
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
249 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
250 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
251 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
252 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
253 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
254 // check if this block should be skipped
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
255 if (skip_blocks)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
256 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
257 block_ptr += block_inc;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
258 skip_blocks--;
3332
09f972eef7a3 fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents: 3184
diff changeset
259 total_blocks--;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
260 continue;
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
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
263 pixel_ptr = block_ptr;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
264
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
265 // 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
266 byte_a = encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
267 byte_b = encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
268
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
269 // 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
270 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
271 return;
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 // check if this is a skip code
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
274 else if ((byte_b & 0xFC) == 0x84)
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 // but don't count the current block
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
277 skip_blocks = ((byte_b - 0x84) << 8) + byte_a - 1;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
278 }
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 // check if this is a 2-color block
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
281 else if (byte_b < 0x80)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
282 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
283 flags = (byte_b << 8) | byte_a;
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 quad[0][0].c1 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
286 quad[0][0].c2 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
287
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
288 DECODE_PALETTE_TO_BGR888(quad[0][0]);
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 // 2-color encoding
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
291 for (pixel_y = 0; pixel_y < 4; pixel_y++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
292 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
293 for (pixel_x = 0; pixel_x < 4; pixel_x++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
294 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
295 if (flags & 1)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
296 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
297 decoded[pixel_ptr++] = quad[0][0].c1_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
298 decoded[pixel_ptr++] = quad[0][0].c1_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
299 decoded[pixel_ptr++] = quad[0][0].c1_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
300 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
301 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
302 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
303 else
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
304 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
305 decoded[pixel_ptr++] = quad[0][0].c2_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
306 decoded[pixel_ptr++] = quad[0][0].c2_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
307 decoded[pixel_ptr++] = quad[0][0].c2_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
308 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
309 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
310 }
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 // get the next flag ready to go
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
313 flags >>= 1;
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 pixel_ptr -= row_dec;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
316 }
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 // check if it's an 8-color block
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
320 else if (byte_b >= 0x90)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
321 {
3100
d930dbae8473 fixed 8-bit variant
melanson
parents: 2960
diff changeset
322 flags = (byte_b << 8) | byte_a;
d930dbae8473 fixed 8-bit variant
melanson
parents: 2960
diff changeset
323
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
324 quad[0][0].c1 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
325 quad[0][0].c2 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
326 quad[1][0].c1 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
327 quad[1][0].c2 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
328
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
329 quad[0][1].c1 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
330 quad[0][1].c2 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
331 quad[1][1].c1 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
332 quad[1][1].c2 = (unsigned char)encoded[stream_ptr++];
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
333
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
334 DECODE_PALETTE_TO_BGR888(quad[0][0]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
335 DECODE_PALETTE_TO_BGR888(quad[0][1]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
336 DECODE_PALETTE_TO_BGR888(quad[1][0]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
337 DECODE_PALETTE_TO_BGR888(quad[1][1]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
338
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
339 for (pixel_y = 0; pixel_y < 4; pixel_y++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
340 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
341 for (pixel_x = 0; pixel_x < 4; pixel_x++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
342 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
343 if (flags & 1)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
344 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
345 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c1_r;
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_g;
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_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
348 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
349 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
350 }
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
351 else
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
352 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
353 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
354 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
355 decoded[pixel_ptr++] = quad[pixel_x >> 1][pixel_y >> 1].c2_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
356 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
357 pixel_ptr++;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
358 }
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 // get the next flag ready to go
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
361 flags >>= 1;
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 pixel_ptr -= row_dec;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
364 }
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 // otherwise, it's a 1-color block
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
368 else
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
369 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
370 // 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
371 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
372 DECODE_PALETTE_TO_BGR888(quad[0][0]);
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
373
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
374 for (pixel_y = 0; pixel_y < 4; pixel_y++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
375 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
376 for (pixel_x = 0; pixel_x < 4; pixel_x++)
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
377 {
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
378 decoded[pixel_ptr++] = quad[0][0].c1_r;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
379 decoded[pixel_ptr++] = quad[0][0].c1_g;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
380 decoded[pixel_ptr++] = quad[0][0].c1_b;
3184
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
381 if (bytes_per_pixel == 4) /* 32bpp */
39f88ed93dd1 added 32bpp output support
alex
parents: 3100
diff changeset
382 pixel_ptr++;
2827
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 pixel_ptr -= row_dec;
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
385 }
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 block_ptr += block_inc;
3332
09f972eef7a3 fixed Video 1 bug which cut off decoding too soon, resulting in torn
melanson
parents: 3184
diff changeset
389 total_blocks--;
2827
b4d46817f050 ms video1 (cram) codecs by Mike Melanson <melanson@pcisys.net>
arpi
parents:
diff changeset
390 }
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