annotate qtsmc.c @ 4279:4301c4adbcf7

reported working at 1600x1200 too, pciconfig stuff fixed, you can enable it with #define MGA_PCICONFIG_MEMDETECT
author alex
date Sun, 20 Jan 2002 13:11:23 +0000
parents 818be6ba8758
children 9eb7a02393a3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4227
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
1 /*
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
2 Apple Graphics (SMC) Decoder for MPlayer
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
3 by Mike Melanson
4275
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
4
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
5 The description of the decoding algorithm can be found here:
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
6 http://www.pcisys.net/~melanson/codecs/
4227
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
7 */
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
8
4275
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
9 #include <stdlib.h>
4227
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
10 #include "config.h"
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
11 #include "bswap.h"
4275
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
12 #include "mp_msg.h"
4227
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
13
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
14 #define BE_16(x) (be2me_16(*(unsigned short *)(x)))
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
15 #define BE_32(x) (be2me_32(*(unsigned int *)(x)))
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
16
4275
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
17 #define COLORS_PER_TABLE 256
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
18 #define BYTES_PER_COLOR 4
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
19
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
20 #define CPAIR 2
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
21 #define CQUAD 4
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
22 #define COCTET 8
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
23
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
24 static unsigned char *color_pairs;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
25 static unsigned char *color_quads;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
26 static unsigned char *color_octets;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
27
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
28 static int color_pair_index;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
29 static int color_quad_index;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
30 static int color_octet_index;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
31
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
32 static int smc_initialized;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
33
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
34 // returns 0 if successfully initialized (enough memory was available),
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
35 // non-zero on failure
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
36 int qt_init_decode_smc(void)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
37 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
38 // be pessimistic to start
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
39 smc_initialized = 0;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
40
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
41 // allocate memory for the 3 palette tables
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
42 if ((color_pairs = (unsigned char *)malloc(
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
43 COLORS_PER_TABLE * BYTES_PER_COLOR * 2)) == 0)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
44 return 1;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
45 if ((color_quads = (unsigned char *)malloc(
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
46 COLORS_PER_TABLE * BYTES_PER_COLOR * 4)) == 0)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
47 return 1;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
48 if ((color_octets = (unsigned char *)malloc(
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
49 COLORS_PER_TABLE * BYTES_PER_COLOR * 8)) == 0)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
50 return 1;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
51
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
52 color_pair_index = 0;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
53 color_quad_index = 0;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
54 color_octet_index = 0;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
55
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
56 // if execution got this far, initialization succeeded
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
57 smc_initialized = 1;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
58 return 0;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
59 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
60
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
61 #define GET_BLOCK_COUNT \
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
62 (opcode & 0x10) ? (1 + encoded[stream_ptr++]) : 1 + (opcode & 0x0F);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
63 #define ADVANCE_BLOCK() \
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
64 { \
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
65 pixel_ptr += block_x_inc; \
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
66 if (pixel_ptr >= (width * bytes_per_pixel)) \
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
67 { \
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
68 pixel_ptr = 0; \
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
69 row_ptr += block_y_inc * 4; \
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
70 } \
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
71 total_blocks--; \
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
72 if (total_blocks < 0) \
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
73 { \
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
74 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "block counter just went negative (this should not happen)\n"); \
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
75 return; \
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
76 } \
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
77 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
78
4227
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
79 void qt_decode_smc(
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
80 unsigned char *encoded,
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
81 int encoded_size,
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
82 unsigned char *decoded,
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
83 int width,
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
84 int height,
4275
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
85 unsigned char *palette_map,
4227
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
86 int bytes_per_pixel)
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
87 {
4275
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
88 int i;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
89 int stream_ptr = 0;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
90 int chunk_size;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
91 unsigned char opcode;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
92 int n_blocks;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
93 unsigned int color_flags;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
94 unsigned int color_flags_a;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
95 unsigned int color_flags_b;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
96 unsigned int flag_mask;
4227
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
97
4275
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
98 int row_ptr = 0;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
99 int pixel_ptr = 0;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
100 int pixel_x, pixel_y;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
101 int row_inc = bytes_per_pixel * (width - 4);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
102 int max_height = row_inc * height;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
103 int block_x_inc = bytes_per_pixel * 4;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
104 int block_y_inc = bytes_per_pixel * width;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
105 int block_ptr;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
106 int prev_block_ptr;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
107 int prev_block_ptr1, prev_block_ptr2;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
108 int prev_block_flag;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
109 int total_blocks;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
110 int color_table_index; // indexes to color pair, quad, or octet tables
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
111 int color_index; // indexes into palette map
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
112
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
113 static int counter;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
114
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
115 //printf ("opcode count = %d\n", counter);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
116 counter = 0;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
117
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
118 if (!smc_initialized)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
119 return;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
120
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
121 chunk_size = BE_32(&encoded[stream_ptr]) & 0x00FFFFFF;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
122 stream_ptr += 4;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
123 if (chunk_size != encoded_size)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
124 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "MOV chunk size != encoded chunk size; using MOV chunk size\n");
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
125
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
126 chunk_size = encoded_size;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
127 total_blocks = (width * height) / (4 * 4);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
128
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
129 // traverse through the blocks
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
130 while (total_blocks)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
131 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
132 // sanity checks
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
133 // make sure stream ptr hasn't gone out of bounds
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
134 if (stream_ptr > chunk_size)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
135 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
136 mp_msg(MSGT_DECVIDEO, MSGL_ERR,
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
137 "SMC decoder just went out of bounds (stream ptr = %d, chunk size = %d)\n",
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
138 stream_ptr, chunk_size);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
139 return;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
140 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
141 // make sure the row pointer hasn't gone wild
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
142 if (row_ptr >= max_height)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
143 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
144 mp_msg(MSGT_DECVIDEO, MSGL_ERR,
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
145 "SMC decoder just went out of bounds (row ptr = %d, height = %d)\n",
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
146 row_ptr, max_height);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
147 return;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
148 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
149
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
150 opcode = encoded[stream_ptr++];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
151 //printf ("opcode %02X\n", opcode & 0xF0);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
152 counter++;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
153 switch (opcode & 0xF0)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
154 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
155 // skip n blocks
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
156 case 0x00:
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
157 case 0x10:
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
158 n_blocks = GET_BLOCK_COUNT;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
159 while (n_blocks--)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
160 ADVANCE_BLOCK();
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
161 break;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
162
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
163 // repeat last block n times
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
164 case 0x20:
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
165 case 0x30:
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
166 n_blocks = GET_BLOCK_COUNT;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
167
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
168 // sanity check
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
169 if ((row_ptr == 0) && (pixel_ptr == 0))
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
170 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
171 mp_msg(MSGT_DECVIDEO, MSGL_WARN,
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
172 "encountered repeat block opcode (%02X) but no blocks rendered yet\n",
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
173 opcode & 0xF0);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
174 break;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
175 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
176
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
177 // figure out where the previous block started
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
178 if (row_ptr == 0)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
179 prev_block_ptr1 = (row_ptr - block_y_inc * 4) + width - 4;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
180 else
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
181 prev_block_ptr1 = row_ptr + pixel_ptr - 4;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
182
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
183 while (n_blocks--)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
184 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
185 block_ptr = row_ptr + pixel_ptr;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
186 prev_block_ptr = prev_block_ptr1;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
187 for (pixel_y = 0; pixel_y < 4; pixel_y++)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
188 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
189 for (pixel_x = 0; pixel_x < 4; pixel_x++)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
190 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
191 decoded[block_ptr++] = decoded[prev_block_ptr++];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
192 decoded[block_ptr++] = decoded[prev_block_ptr++];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
193 decoded[block_ptr++] = decoded[prev_block_ptr++];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
194 if (bytes_per_pixel == 4) /* 32bpp */
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
195 block_ptr++;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
196 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
197 block_ptr += row_inc;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
198 prev_block_ptr += row_inc;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
199 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
200 ADVANCE_BLOCK();
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
201 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
202 break;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
203
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
204 // repeat previous pair of blocks n times
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
205 case 0x40:
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
206 case 0x50:
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
207 n_blocks = GET_BLOCK_COUNT;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
208 n_blocks *= 2;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
209
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
210 // sanity check
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
211 if ((row_ptr == 0) && (pixel_ptr < 2 * block_x_inc))
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
212 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
213 mp_msg(MSGT_DECVIDEO, MSGL_WARN,
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
214 "encountered repeat block opcode (%02X) but not enough blocks rendered yet\n",
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
215 opcode & 0xF0);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
216 break;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
217 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
218
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
219 // figure out where the previous 2 blocks started
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
220 if (row_ptr == 0)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
221 prev_block_ptr1 = (row_ptr - block_y_inc * 4) +
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
222 ((width - 4) * bytes_per_pixel);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
223 else
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
224 prev_block_ptr1 = row_ptr + pixel_ptr - block_x_inc;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
225
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
226 if (row_ptr == 0)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
227 prev_block_ptr2 = (row_ptr - block_y_inc * 4) +
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
228 ((width - 8) * bytes_per_pixel);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
229 else if (row_ptr == block_x_inc)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
230 prev_block_ptr2 = (row_ptr - block_y_inc * 4) +
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
231 ((width - 4) * bytes_per_pixel);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
232 else
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
233 prev_block_ptr2 = row_ptr + pixel_ptr - (block_x_inc * 2);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
234
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
235 prev_block_flag = 0;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
236 while (n_blocks--)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
237 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
238 block_ptr = row_ptr + pixel_ptr;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
239 if (prev_block_flag)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
240 prev_block_ptr = prev_block_ptr2;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
241 else
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
242 prev_block_ptr = prev_block_ptr1;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
243 prev_block_flag = !prev_block_flag;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
244
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
245 for (pixel_y = 0; pixel_y < 4; pixel_y++)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
246 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
247 for (pixel_x = 0; pixel_x < 4; pixel_x++)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
248 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
249 decoded[block_ptr++] = decoded[prev_block_ptr++];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
250 decoded[block_ptr++] = decoded[prev_block_ptr++];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
251 decoded[block_ptr++] = decoded[prev_block_ptr++];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
252 if (bytes_per_pixel == 4) /* 32bpp */
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
253 block_ptr++;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
254 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
255 block_ptr += row_inc;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
256 prev_block_ptr += row_inc;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
257 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
258 ADVANCE_BLOCK();
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
259 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
260 break;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
261
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
262 // 1-color block encoding
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
263 case 0x60:
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
264 case 0x70:
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
265 n_blocks = GET_BLOCK_COUNT;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
266 color_index = encoded[stream_ptr++] * 4;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
267
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
268 while (n_blocks--)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
269 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
270 block_ptr = row_ptr + pixel_ptr;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
271 for (pixel_y = 0; pixel_y < 4; pixel_y++)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
272 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
273 for (pixel_x = 0; pixel_x < 4; pixel_x++)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
274 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
275 decoded[block_ptr++] = palette_map[color_index + 0];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
276 decoded[block_ptr++] = palette_map[color_index + 1];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
277 decoded[block_ptr++] = palette_map[color_index + 2];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
278 if (bytes_per_pixel == 4) /* 32bpp */
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
279 block_ptr++;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
280 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
281 block_ptr += row_inc;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
282 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
283 ADVANCE_BLOCK();
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
284 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
285 break;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
286
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
287 // 2-color block encoding
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
288 case 0x80:
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
289 case 0x90:
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
290 n_blocks = (opcode & 0x0F) + 1;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
291
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
292 // figure out which color pair to use to paint the 2-color block
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
293 if ((opcode & 0xF0) == 0x80)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
294 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
295 // fetch the next 2 colors from bytestream and store in next
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
296 // available entry in the color pair table
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
297 for (i = 0; i < CPAIR; i++)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
298 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
299 color_index = encoded[stream_ptr++] * BYTES_PER_COLOR;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
300 color_table_index = CPAIR * BYTES_PER_COLOR * color_pair_index +
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
301 (i * BYTES_PER_COLOR);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
302 color_pairs[color_table_index + 0] = palette_map[color_index + 0];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
303 color_pairs[color_table_index + 1] = palette_map[color_index + 1];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
304 color_pairs[color_table_index + 2] = palette_map[color_index + 2];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
305 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
306 // this is the base index to use for this block
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
307 color_table_index = CPAIR * BYTES_PER_COLOR * color_pair_index;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
308 color_pair_index++;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
309 if (color_pair_index == COLORS_PER_TABLE)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
310 color_pair_index = 0;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
311 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
312 else
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
313 color_table_index = CPAIR * BYTES_PER_COLOR * encoded[stream_ptr++];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
314
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
315 while (n_blocks--)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
316 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
317 color_flags = BE_16(&encoded[stream_ptr]);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
318 stream_ptr += 2;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
319 flag_mask = 0x8000;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
320 block_ptr = row_ptr + pixel_ptr;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
321 for (pixel_y = 0; pixel_y < 4; pixel_y++)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
322 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
323 for (pixel_x = 0; pixel_x < 4; pixel_x++)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
324 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
325 if (color_flags & flag_mask)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
326 color_index = color_table_index + BYTES_PER_COLOR;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
327 else
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
328 color_index = color_table_index;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
329 flag_mask >>= 1;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
330
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
331 decoded[block_ptr++] = color_pairs[color_index + 0];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
332 decoded[block_ptr++] = color_pairs[color_index + 1];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
333 decoded[block_ptr++] = color_pairs[color_index + 2];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
334 if (bytes_per_pixel == 4) /* 32bpp */
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
335 block_ptr++;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
336 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
337 block_ptr += row_inc;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
338 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
339 ADVANCE_BLOCK();
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
340 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
341 break;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
342
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
343 // 4-color block encoding
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
344 case 0xA0:
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
345 case 0xB0:
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
346 //for(i = 0; i < 16; i++)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
347 // printf (" %02X", encoded[stream_ptr - 1 + i]);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
348 //printf ("\n");
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
349 n_blocks = (opcode & 0x0F) + 1;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
350
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
351 // figure out which color quad to use to paint the 4-color block
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
352 if ((opcode & 0xF0) == 0xA0)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
353 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
354 // fetch the next 4 colors from bytestream and store in next
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
355 // available entry in the color pair table
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
356 for (i = 0; i < CQUAD; i++)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
357 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
358 color_index = encoded[stream_ptr++] * BYTES_PER_COLOR;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
359 color_table_index = CQUAD * BYTES_PER_COLOR * color_quad_index +
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
360 (i * BYTES_PER_COLOR);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
361 color_quads[color_table_index + 0] = palette_map[color_index + 0];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
362 color_quads[color_table_index + 1] = palette_map[color_index + 1];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
363 color_quads[color_table_index + 2] = palette_map[color_index + 2];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
364 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
365 // this is the base index to use for this block
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
366 color_table_index = CQUAD * BYTES_PER_COLOR * color_quad_index;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
367 color_quad_index++;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
368 if (color_quad_index == COLORS_PER_TABLE)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
369 color_quad_index = 0;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
370 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
371 else
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
372 color_table_index = CQUAD * BYTES_PER_COLOR * encoded[stream_ptr++];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
373
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
374 while (n_blocks--)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
375 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
376 color_flags = BE_32(&encoded[stream_ptr]);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
377 stream_ptr += 4;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
378 // flag mask actually acts as a bit shift count here
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
379 flag_mask = 30;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
380 block_ptr = row_ptr + pixel_ptr;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
381 for (pixel_y = 0; pixel_y < 4; pixel_y++)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
382 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
383 for (pixel_x = 0; pixel_x < 4; pixel_x++)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
384 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
385 color_index = color_table_index + (BYTES_PER_COLOR *
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
386 ((color_flags >> flag_mask) & 0x03));
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
387 flag_mask -= 2;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
388
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
389 decoded[block_ptr++] = color_quads[color_index + 0];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
390 decoded[block_ptr++] = color_quads[color_index + 1];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
391 decoded[block_ptr++] = color_quads[color_index + 2];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
392 if (bytes_per_pixel == 4) /* 32bpp */
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
393 block_ptr++;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
394 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
395 block_ptr += row_inc;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
396 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
397 ADVANCE_BLOCK();
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
398 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
399 break;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
400
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
401 // 8-color block encoding
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
402 case 0xC0:
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
403 case 0xD0:
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
404 n_blocks = (opcode & 0x0F) + 1;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
405
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
406 // figure out which color octet to use to paint the 8-color block
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
407 if ((opcode & 0xF0) == 0xC0)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
408 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
409 // fetch the next 8 colors from bytestream and store in next
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
410 // available entry in the color pair table
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
411 for (i = 0; i < COCTET; i++)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
412 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
413 color_index = encoded[stream_ptr++] * BYTES_PER_COLOR;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
414 color_table_index = COCTET * BYTES_PER_COLOR * color_octet_index +
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
415 (i * BYTES_PER_COLOR);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
416 color_octets[color_table_index + 0] = palette_map[color_index + 0];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
417 color_octets[color_table_index + 1] = palette_map[color_index + 1];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
418 color_octets[color_table_index + 2] = palette_map[color_index + 2];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
419 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
420 // this is the base index to use for this block
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
421 color_table_index = COCTET * BYTES_PER_COLOR * color_octet_index;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
422 color_octet_index++;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
423 if (color_octet_index == COLORS_PER_TABLE)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
424 color_octet_index = 0;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
425 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
426 else
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
427 color_table_index = COCTET * BYTES_PER_COLOR * encoded[stream_ptr++];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
428
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
429 while (n_blocks--)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
430 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
431 // build the color flags
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
432 color_flags_a = color_flags_b = 0;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
433 color_flags_a |= (encoded[stream_ptr++] << 16);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
434 color_flags_b |= (encoded[stream_ptr++] << 16);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
435 color_flags_a |= (encoded[stream_ptr++] << 8);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
436 color_flags_b |= (encoded[stream_ptr++] << 8);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
437 color_flags_a |= (encoded[stream_ptr++] << 0);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
438 color_flags_b |= (encoded[stream_ptr++] << 0);
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
439
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
440 color_flags = color_flags_a;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
441 // flag mask actually acts as a bit shift count here
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
442 flag_mask = 21;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
443 block_ptr = row_ptr + pixel_ptr;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
444 for (pixel_y = 0; pixel_y < 4; pixel_y++)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
445 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
446 // reload flags at third row (iteration pixel_y == 2)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
447 if (pixel_y == 2)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
448 color_flags = color_flags_b;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
449 for (pixel_x = 0; pixel_x < 4; pixel_x++)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
450 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
451 color_index = color_table_index + (BYTES_PER_COLOR *
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
452 ((color_flags >> flag_mask) & 0x07));
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
453 flag_mask -= 3;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
454
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
455 decoded[block_ptr++] = color_octets[color_index + 0];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
456 decoded[block_ptr++] = color_octets[color_index + 1];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
457 decoded[block_ptr++] = color_octets[color_index + 2];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
458 if (bytes_per_pixel == 4) /* 32bpp */
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
459 block_ptr++;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
460 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
461 block_ptr += row_inc;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
462 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
463 ADVANCE_BLOCK();
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
464 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
465 break;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
466
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
467 // 16-color block encoding (every pixel is a different color)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
468 case 0xE0:
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
469 n_blocks = (opcode & 0x0F) + 1;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
470
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
471 while (n_blocks--)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
472 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
473 block_ptr = row_ptr + pixel_ptr;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
474 for (pixel_y = 0; pixel_y < 4; pixel_y++)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
475 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
476 for (pixel_x = 0; pixel_x < 4; pixel_x++)
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
477 {
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
478 color_index = encoded[stream_ptr++] * BYTES_PER_COLOR;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
479 decoded[block_ptr++] = palette_map[color_index + 0];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
480 decoded[block_ptr++] = palette_map[color_index + 1];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
481 decoded[block_ptr++] = palette_map[color_index + 2];
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
482 if (bytes_per_pixel == 4) /* 32bpp */
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
483 block_ptr++;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
484 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
485 block_ptr += row_inc;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
486 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
487 ADVANCE_BLOCK();
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
488 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
489 break;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
490
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
491 case 0xF0:
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
492 mp_msg(MSGT_DECVIDEO, MSGL_HINT, "0xF0 opcode seen in SMC chunk (MPlayer developers would like to know)\n");
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
493 break;
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
494 }
818be6ba8758 initial implementation of SMC codec; it almost works, too!
melanson
parents: 4227
diff changeset
495 }
4227
4b652eac6738 added skeleton for QT SMC decoder
melanson
parents:
diff changeset
496 }