Mercurial > mplayer.hg
annotate qtsmc.c @ 4856:7dfcfd1b9bf7
rename V -> VC just for understanding
author | nick |
---|---|
date | Mon, 25 Feb 2002 08:27:15 +0000 |
parents | b3d18d070ec1 |
children |
rev | line source |
---|---|
4227 | 1 /* |
2 Apple Graphics (SMC) Decoder for MPlayer | |
3 by Mike Melanson | |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
4 Special thanks for Roberto Togni <rtogni@bresciaonline.it> for |
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
5 tracking down the final, nagging bugs. |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
6 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
7 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
|
8 http://www.pcisys.net/~melanson/codecs/ |
4227 | 9 */ |
10 | |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
11 #include <stdlib.h> |
4227 | 12 #include "config.h" |
13 #include "bswap.h" | |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
14 #include "mp_msg.h" |
4227 | 15 |
16 #define BE_16(x) (be2me_16(*(unsigned short *)(x))) | |
17 #define BE_32(x) (be2me_32(*(unsigned int *)(x))) | |
18 | |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
19 #define COLORS_PER_TABLE 256 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
20 #define BYTES_PER_COLOR 4 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
21 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
22 #define CPAIR 2 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
23 #define CQUAD 4 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
24 #define COCTET 8 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
25 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
26 static unsigned char *color_pairs; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
27 static unsigned char *color_quads; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
28 static unsigned char *color_octets; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
29 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
30 static int color_pair_index; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
31 static int color_quad_index; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
32 static int color_octet_index; |
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 static int smc_initialized; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
35 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
36 // returns 0 if successfully initialized (enough memory was available), |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
37 // non-zero on failure |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
38 int qt_init_decode_smc(void) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
39 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
40 // be pessimistic to start |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
41 smc_initialized = 0; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
42 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
43 // allocate memory for the 3 palette tables |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
44 if ((color_pairs = (unsigned char *)malloc( |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
45 COLORS_PER_TABLE * BYTES_PER_COLOR * 2)) == 0) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
46 return 1; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
47 if ((color_quads = (unsigned char *)malloc( |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
48 COLORS_PER_TABLE * BYTES_PER_COLOR * 4)) == 0) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
49 return 1; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
50 if ((color_octets = (unsigned char *)malloc( |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
51 COLORS_PER_TABLE * BYTES_PER_COLOR * 8)) == 0) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
52 return 1; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
53 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
54 // if execution got this far, initialization succeeded |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
55 smc_initialized = 1; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
56 return 0; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
57 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
58 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
59 #define GET_BLOCK_COUNT \ |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
60 (opcode & 0x10) ? (1 + encoded[stream_ptr++]) : 1 + (opcode & 0x0F); |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
61 #define ADVANCE_BLOCK() \ |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
62 { \ |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
63 pixel_ptr += block_x_inc; \ |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
64 if (pixel_ptr >= byte_width) \ |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
65 { \ |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
66 pixel_ptr = 0; \ |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
67 row_ptr += block_y_inc * 4; \ |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
68 } \ |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
69 total_blocks--; \ |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
70 if (total_blocks < 0) \ |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
71 { \ |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
72 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
|
73 return; \ |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
74 } \ |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
75 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
76 |
4227 | 77 void qt_decode_smc( |
78 unsigned char *encoded, | |
79 int encoded_size, | |
80 unsigned char *decoded, | |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
81 int pixel_width, |
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
82 int pixel_height, |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
83 unsigned char *palette_map, |
4227 | 84 int bytes_per_pixel) |
85 { | |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
86 int i; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
87 int stream_ptr = 0; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
88 int chunk_size; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
89 unsigned char opcode; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
90 int n_blocks; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
91 unsigned int color_flags; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
92 unsigned int color_flags_a; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
93 unsigned int color_flags_b; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
94 unsigned int flag_mask; |
4227 | 95 |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
96 int byte_width = pixel_width * bytes_per_pixel; // width of a row in bytes |
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
97 int byte_height = pixel_height * byte_width; // max image size, basically |
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; |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
101 int row_inc = bytes_per_pixel * (pixel_width - 4); |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
102 int block_x_inc = bytes_per_pixel * 4; |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
103 int block_y_inc = bytes_per_pixel * pixel_width; |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
104 int block_ptr; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
105 int prev_block_ptr; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
106 int prev_block_ptr1, prev_block_ptr2; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
107 int prev_block_flag; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
108 int total_blocks; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
109 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
|
110 int color_index; // indexes into palette map |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
111 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
112 if (!smc_initialized) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
113 return; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
114 |
4298
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
115 // reset color tables |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
116 color_pair_index = 0; |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
117 color_quad_index = 0; |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
118 color_octet_index = 0; |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
119 |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
120 chunk_size = BE_32(&encoded[stream_ptr]) & 0x00FFFFFF; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
121 stream_ptr += 4; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
122 if (chunk_size != encoded_size) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
123 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
|
124 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
125 chunk_size = encoded_size; |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
126 total_blocks = (pixel_width * pixel_height) / (4 * 4); |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
127 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
128 // traverse through the blocks |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
129 while (total_blocks) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
130 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
131 // sanity checks |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
132 // 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
|
133 if (stream_ptr > chunk_size) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
134 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
135 mp_msg(MSGT_DECVIDEO, MSGL_ERR, |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
136 "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
|
137 stream_ptr, chunk_size); |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
138 return; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
139 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
140 // make sure the row pointer hasn't gone wild |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
141 if (row_ptr >= byte_height) |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
142 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
143 mp_msg(MSGT_DECVIDEO, MSGL_ERR, |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
144 "SMC decoder just went out of bounds (row ptr = %d, height = %d)\n", |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
145 row_ptr, byte_height); |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
146 return; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
147 } |
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 opcode = encoded[stream_ptr++]; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
150 switch (opcode & 0xF0) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
151 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
152 // skip n blocks |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
153 case 0x00: |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
154 case 0x10: |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
155 n_blocks = GET_BLOCK_COUNT; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
156 while (n_blocks--) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
157 ADVANCE_BLOCK(); |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
158 break; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
159 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
160 // repeat last block n times |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
161 case 0x20: |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
162 case 0x30: |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
163 n_blocks = GET_BLOCK_COUNT; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
164 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
165 // sanity check |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
166 if ((row_ptr == 0) && (pixel_ptr == 0)) |
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 mp_msg(MSGT_DECVIDEO, MSGL_WARN, |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
169 "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
|
170 opcode & 0xF0); |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
171 break; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
172 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
173 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
174 // figure out where the previous block started |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
175 if (pixel_ptr == 0) |
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
176 prev_block_ptr1 = (row_ptr - block_y_inc * 4) + |
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
177 byte_width - block_x_inc; |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
178 else |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
179 prev_block_ptr1 = row_ptr + pixel_ptr - block_x_inc; |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
180 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
181 while (n_blocks--) |
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 block_ptr = row_ptr + pixel_ptr; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
184 prev_block_ptr = prev_block_ptr1; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
185 for (pixel_y = 0; pixel_y < 4; pixel_y++) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
186 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
187 for (pixel_x = 0; pixel_x < 4; pixel_x++) |
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 decoded[block_ptr++] = decoded[prev_block_ptr++]; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
190 decoded[block_ptr++] = decoded[prev_block_ptr++]; |
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 if (bytes_per_pixel == 4) /* 32bpp */ |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
193 { |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
194 block_ptr++; |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
195 prev_block_ptr++; |
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
196 } |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
197 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
198 block_ptr += row_inc; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
199 prev_block_ptr += row_inc; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
200 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
201 ADVANCE_BLOCK(); |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
202 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
203 break; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
204 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
205 // repeat previous pair of blocks n times |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
206 case 0x40: |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
207 case 0x50: |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
208 n_blocks = GET_BLOCK_COUNT; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
209 n_blocks *= 2; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
210 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
211 // sanity check |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
212 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
|
213 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
214 mp_msg(MSGT_DECVIDEO, MSGL_WARN, |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
215 "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
|
216 opcode & 0xF0); |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
217 break; |
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 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
220 // figure out where the previous 2 blocks started |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
221 if (pixel_ptr == 0) |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
222 prev_block_ptr1 = (row_ptr - block_y_inc * 4) + |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
223 byte_width - block_x_inc * 2; |
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
224 else if (pixel_ptr == block_x_inc) |
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
225 prev_block_ptr1 = (row_ptr - block_y_inc * 4) + |
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
226 byte_width - block_x_inc; |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
227 else |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
228 prev_block_ptr1 = row_ptr + pixel_ptr - block_x_inc * 2; |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
229 |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
230 if (pixel_ptr == 0) |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
231 prev_block_ptr2 = (row_ptr - block_y_inc * 4) + |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
232 (byte_width - block_x_inc); |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
233 else |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
234 prev_block_ptr2 = row_ptr + pixel_ptr - block_x_inc; |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
235 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
236 prev_block_flag = 0; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
237 while (n_blocks--) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
238 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
239 block_ptr = row_ptr + pixel_ptr; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
240 if (prev_block_flag) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
241 prev_block_ptr = prev_block_ptr2; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
242 else |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
243 prev_block_ptr = prev_block_ptr1; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
244 prev_block_flag = !prev_block_flag; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
245 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
246 for (pixel_y = 0; pixel_y < 4; pixel_y++) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
247 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
248 for (pixel_x = 0; pixel_x < 4; pixel_x++) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
249 { |
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 decoded[block_ptr++] = decoded[prev_block_ptr++]; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
253 if (bytes_per_pixel == 4) /* 32bpp */ |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
254 { |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
255 block_ptr++; |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
256 prev_block_ptr++; |
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
257 } |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
258 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
259 block_ptr += row_inc; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
260 prev_block_ptr += row_inc; |
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 ADVANCE_BLOCK(); |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
263 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
264 break; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
265 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
266 // 1-color block encoding |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
267 case 0x60: |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
268 case 0x70: |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
269 n_blocks = GET_BLOCK_COUNT; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
270 color_index = encoded[stream_ptr++] * 4; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
271 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
272 while (n_blocks--) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
273 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
274 block_ptr = row_ptr + pixel_ptr; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
275 for (pixel_y = 0; pixel_y < 4; pixel_y++) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
276 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
277 for (pixel_x = 0; pixel_x < 4; pixel_x++) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
278 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
279 decoded[block_ptr++] = palette_map[color_index + 0]; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
280 decoded[block_ptr++] = palette_map[color_index + 1]; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
281 decoded[block_ptr++] = palette_map[color_index + 2]; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
282 if (bytes_per_pixel == 4) /* 32bpp */ |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
283 block_ptr++; |
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 block_ptr += row_inc; |
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 ADVANCE_BLOCK(); |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
288 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
289 break; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
290 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
291 // 2-color block encoding |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
292 case 0x80: |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
293 case 0x90: |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
294 n_blocks = (opcode & 0x0F) + 1; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
295 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
296 // 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
|
297 if ((opcode & 0xF0) == 0x80) |
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 // 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
|
300 // available entry in the color pair table |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
301 for (i = 0; i < CPAIR; i++) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
302 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
303 color_index = encoded[stream_ptr++] * BYTES_PER_COLOR; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
304 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
|
305 (i * BYTES_PER_COLOR); |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
306 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
|
307 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
|
308 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
|
309 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
310 // 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
|
311 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
|
312 color_pair_index++; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
313 if (color_pair_index == COLORS_PER_TABLE) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
314 color_pair_index = 0; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
315 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
316 else |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
317 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
|
318 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
319 while (n_blocks--) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
320 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
321 color_flags = BE_16(&encoded[stream_ptr]); |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
322 stream_ptr += 2; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
323 flag_mask = 0x8000; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
324 block_ptr = row_ptr + pixel_ptr; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
325 for (pixel_y = 0; pixel_y < 4; pixel_y++) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
326 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
327 for (pixel_x = 0; pixel_x < 4; pixel_x++) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
328 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
329 if (color_flags & flag_mask) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
330 color_index = color_table_index + BYTES_PER_COLOR; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
331 else |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
332 color_index = color_table_index; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
333 flag_mask >>= 1; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
334 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
335 decoded[block_ptr++] = color_pairs[color_index + 0]; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
336 decoded[block_ptr++] = color_pairs[color_index + 1]; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
337 decoded[block_ptr++] = color_pairs[color_index + 2]; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
338 if (bytes_per_pixel == 4) /* 32bpp */ |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
339 block_ptr++; |
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 block_ptr += row_inc; |
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 ADVANCE_BLOCK(); |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
344 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
345 break; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
346 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
347 // 4-color block encoding |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
348 case 0xA0: |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
349 case 0xB0: |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
350 n_blocks = (opcode & 0x0F) + 1; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
351 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
352 // 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
|
353 if ((opcode & 0xF0) == 0xA0) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
354 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
355 // fetch the next 4 colors from bytestream and store in next |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
356 // available entry in the color quad table |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
357 for (i = 0; i < CQUAD; i++) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
358 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
359 color_index = encoded[stream_ptr++] * BYTES_PER_COLOR; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
360 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
|
361 (i * BYTES_PER_COLOR); |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
362 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
|
363 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
|
364 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
|
365 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
366 // 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
|
367 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
|
368 color_quad_index++; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
369 if (color_quad_index == COLORS_PER_TABLE) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
370 color_quad_index = 0; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
371 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
372 else |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
373 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
|
374 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
375 while (n_blocks--) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
376 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
377 color_flags = BE_32(&encoded[stream_ptr]); |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
378 stream_ptr += 4; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
379 // 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
|
380 flag_mask = 30; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
381 block_ptr = row_ptr + pixel_ptr; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
382 for (pixel_y = 0; pixel_y < 4; pixel_y++) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
383 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
384 for (pixel_x = 0; pixel_x < 4; pixel_x++) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
385 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
386 color_index = color_table_index + (BYTES_PER_COLOR * |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
387 ((color_flags >> flag_mask) & 0x03)); |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
388 flag_mask -= 2; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
389 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
390 decoded[block_ptr++] = color_quads[color_index + 0]; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
391 decoded[block_ptr++] = color_quads[color_index + 1]; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
392 decoded[block_ptr++] = color_quads[color_index + 2]; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
393 if (bytes_per_pixel == 4) /* 32bpp */ |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
394 block_ptr++; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
395 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
396 block_ptr += row_inc; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
397 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
398 ADVANCE_BLOCK(); |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
399 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
400 break; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
401 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
402 // 8-color block encoding |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
403 case 0xC0: |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
404 case 0xD0: |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
405 n_blocks = (opcode & 0x0F) + 1; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
406 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
407 // 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
|
408 if ((opcode & 0xF0) == 0xC0) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
409 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
410 // fetch the next 8 colors from bytestream and store in next |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
411 // available entry in the color octet table |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
412 for (i = 0; i < COCTET; i++) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
413 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
414 color_index = encoded[stream_ptr++] * BYTES_PER_COLOR; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
415 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
|
416 (i * BYTES_PER_COLOR); |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
417 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
|
418 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
|
419 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
|
420 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
421 // 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
|
422 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
|
423 color_octet_index++; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
424 if (color_octet_index == COLORS_PER_TABLE) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
425 color_octet_index = 0; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
426 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
427 else |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
428 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
|
429 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
430 while (n_blocks--) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
431 { |
4298
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
432 /* |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
433 For this input: |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
434 01 23 45 67 89 AB |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
435 This is the output: |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
436 flags_a = xx012456, flags_b = xx89A37B |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
437 */ |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
438 // build the color flags |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
439 color_flags_a = color_flags_b = 0; |
4298
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
440 color_flags_a = |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
441 (encoded[stream_ptr + 0] << 16) | |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
442 ((encoded[stream_ptr + 1] & 0xF0) << 8) | |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
443 ((encoded[stream_ptr + 2] & 0xF0) << 4) | |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
444 ((encoded[stream_ptr + 2] & 0x0F) << 4) | |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
445 ((encoded[stream_ptr + 3] & 0xF0) >> 4); |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
446 color_flags_b = |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
447 (encoded[stream_ptr + 4] << 16) | |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
448 ((encoded[stream_ptr + 5] & 0xF0) << 8) | |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
449 ((encoded[stream_ptr + 1] & 0x0F) << 8) | |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
450 ((encoded[stream_ptr + 3] & 0x0F) << 4) | |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
451 (encoded[stream_ptr + 5] & 0x0F); |
9eb7a02393a3
fixed some major flaws; decoder is now almost correct
melanson
parents:
4275
diff
changeset
|
452 stream_ptr += 6; |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
453 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
454 color_flags = color_flags_a; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
455 // 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
|
456 flag_mask = 21; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
457 block_ptr = row_ptr + pixel_ptr; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
458 for (pixel_y = 0; pixel_y < 4; pixel_y++) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
459 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
460 // reload flags at third row (iteration pixel_y == 2) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
461 if (pixel_y == 2) |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
462 { |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
463 color_flags = color_flags_b; |
4647
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
464 flag_mask = 21; |
b3d18d070ec1
fixed the last few SMC bugs, thanks to Roberto Togni's bug hunting
melanson
parents:
4298
diff
changeset
|
465 } |
4275
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
466 for (pixel_x = 0; pixel_x < 4; pixel_x++) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
467 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
468 color_index = color_table_index + (BYTES_PER_COLOR * |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
469 ((color_flags >> flag_mask) & 0x07)); |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
470 flag_mask -= 3; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
471 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
472 decoded[block_ptr++] = color_octets[color_index + 0]; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
473 decoded[block_ptr++] = color_octets[color_index + 1]; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
474 decoded[block_ptr++] = color_octets[color_index + 2]; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
475 if (bytes_per_pixel == 4) /* 32bpp */ |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
476 block_ptr++; |
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 block_ptr += row_inc; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
479 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
480 ADVANCE_BLOCK(); |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
481 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
482 break; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
483 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
484 // 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
|
485 case 0xE0: |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
486 n_blocks = (opcode & 0x0F) + 1; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
487 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
488 while (n_blocks--) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
489 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
490 block_ptr = row_ptr + pixel_ptr; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
491 for (pixel_y = 0; pixel_y < 4; pixel_y++) |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
492 { |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
493 for (pixel_x = 0; pixel_x < 4; pixel_x++) |
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 color_index = encoded[stream_ptr++] * BYTES_PER_COLOR; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
496 decoded[block_ptr++] = palette_map[color_index + 0]; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
497 decoded[block_ptr++] = palette_map[color_index + 1]; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
498 decoded[block_ptr++] = palette_map[color_index + 2]; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
499 if (bytes_per_pixel == 4) /* 32bpp */ |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
500 block_ptr++; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
501 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
502 block_ptr += row_inc; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
503 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
504 ADVANCE_BLOCK(); |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
505 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
506 break; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
507 |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
508 case 0xF0: |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
509 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
|
510 break; |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
511 } |
818be6ba8758
initial implementation of SMC codec; it almost works, too!
melanson
parents:
4227
diff
changeset
|
512 } |
4227 | 513 } |