annotate smc.c @ 1760:ebe7fa49ddcc libavcodec

mpeg4 pts fix
author michael
date Mon, 26 Jan 2004 19:04:32 +0000
parents 586b5c08863c
children 1514fd5d434b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1610
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
1 /*
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
2 * Quicktime Graphics (SMC) Video Decoder
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
3 * Copyright (C) 2003 the ffmpeg project
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
4 *
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
9 *
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
13 * Lesser General Public License for more details.
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
14 *
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
18 *
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
19 */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
20
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
21 /**
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
22 * @file smc.c
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
23 * QT SMC Video Decoder by Mike Melanson (melanson@pcisys.net)
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
24 * For more information about the SMC format, visit:
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
25 * http://www.pcisys.net/~melanson/codecs/
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
26 *
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
27 * The SMC decoder outputs PAL8 colorspace data.
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
28 */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
29
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
30 #include <stdio.h>
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
31 #include <stdlib.h>
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
32 #include <string.h>
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
33 #include <unistd.h>
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
34
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
35 #include "common.h"
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
36 #include "avcodec.h"
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
37 #include "dsputil.h"
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
38
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
39 #define CPAIR 2
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
40 #define CQUAD 4
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
41 #define COCTET 8
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
42
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
43 #define COLORS_PER_TABLE 256
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
44
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
45 typedef struct SmcContext {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
46
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
47 AVCodecContext *avctx;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
48 DSPContext dsp;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
49 AVFrame frame;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
50
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
51 unsigned char *buf;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
52 int size;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
53
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
54 /* SMC color tables */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
55 unsigned char color_pairs[COLORS_PER_TABLE * CPAIR];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
56 unsigned char color_quads[COLORS_PER_TABLE * CQUAD];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
57 unsigned char color_octets[COLORS_PER_TABLE * COCTET];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
58
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
59 } SmcContext;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
60
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
61 #define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
62 #define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
63 (((uint8_t*)(x))[1] << 16) | \
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
64 (((uint8_t*)(x))[2] << 8) | \
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
65 ((uint8_t*)(x))[3])
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
66 #define GET_BLOCK_COUNT() \
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
67 (opcode & 0x10) ? (1 + s->buf[stream_ptr++]) : 1 + (opcode & 0x0F);
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
68
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
69 #define ADVANCE_BLOCK() \
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
70 { \
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
71 pixel_ptr += 4; \
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
72 if (pixel_ptr >= width) \
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
73 { \
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
74 pixel_ptr = 0; \
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
75 row_ptr += stride * 4; \
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
76 } \
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
77 total_blocks--; \
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
78 if (total_blocks < 0) \
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
79 { \
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
80 printf("warning: block counter just went negative (this should not happen)\n"); \
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
81 return; \
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
82 } \
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
83 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
84
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
85 static void smc_decode_stream(SmcContext *s)
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
86 {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
87 int width = s->avctx->width;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
88 int height = s->avctx->height;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
89 int stride = s->frame.linesize[0];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
90 int i;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
91 int stream_ptr = 0;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
92 int chunk_size;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
93 unsigned char opcode;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
94 int n_blocks;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
95 unsigned int color_flags;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
96 unsigned int color_flags_a;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
97 unsigned int color_flags_b;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
98 unsigned int flag_mask;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
99
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
100 unsigned char *pixels = s->frame.data[0];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
101
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
102 int image_size = height * s->frame.linesize[0];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
103 int row_ptr = 0;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
104 int pixel_ptr = 0;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
105 int pixel_x, pixel_y;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
106 int row_inc = stride - 4;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
107 int block_ptr;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
108 int prev_block_ptr;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
109 int prev_block_ptr1, prev_block_ptr2;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
110 int prev_block_flag;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
111 int total_blocks;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
112 int color_table_index; /* indexes to color pair, quad, or octet tables */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
113 int pixel;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
114
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
115 int color_pair_index = 0;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
116 int color_quad_index = 0;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
117 int color_octet_index = 0;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
118
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
119 /* make the palette available */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
120 memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE);
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
121 if (s->avctx->palctrl->palette_changed) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
122 s->frame.palette_has_changed = 1;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
123 s->avctx->palctrl->palette_changed = 0;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
124 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
125
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
126 chunk_size = BE_32(&s->buf[stream_ptr]) & 0x00FFFFFF;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
127 stream_ptr += 4;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
128 if (chunk_size != s->size)
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
129 printf("warning: MOV chunk size != encoded chunk size (%d != %d); using MOV chunk size\n",
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
130 chunk_size, s->size);
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
131
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
132 chunk_size = s->size;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
133 total_blocks = (s->avctx->width * s->avctx->height) / (4 * 4);
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
134
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
135 /* traverse through the blocks */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
136 while (total_blocks) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
137 /* sanity checks */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
138 /* make sure stream ptr hasn't gone out of bounds */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
139 if (stream_ptr > chunk_size) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
140 printf("SMC decoder just went out of bounds (stream ptr = %d, chunk size = %d)\n",
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
141 stream_ptr, chunk_size);
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
142 return;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
143 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
144 /* make sure the row pointer hasn't gone wild */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
145 if (row_ptr >= image_size) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
146 printf("SMC decoder just went out of bounds (row ptr = %d, height = %d)\n",
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
147 row_ptr, image_size);
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
148 return;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
149 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
150
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
151 opcode = s->buf[stream_ptr++];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
152 switch (opcode & 0xF0) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
153 /* skip n blocks */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
154 case 0x00:
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
155 case 0x10:
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
156 n_blocks = GET_BLOCK_COUNT();
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
157 while (n_blocks--) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
158 ADVANCE_BLOCK();
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
159 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
160 break;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
161
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
162 /* repeat last block n times */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
163 case 0x20:
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
164 case 0x30:
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
165 n_blocks = GET_BLOCK_COUNT();
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
166
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
167 /* sanity check */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
168 if ((row_ptr == 0) && (pixel_ptr == 0)) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
169 printf("encountered repeat block opcode (%02X) but no blocks rendered yet\n",
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
170 opcode & 0xF0);
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
171 break;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
172 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
173
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
174 /* figure out where the previous block started */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
175 if (pixel_ptr == 0)
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
176 prev_block_ptr1 =
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
177 (row_ptr - s->avctx->width * 4) + s->avctx->width - 4;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
178 else
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
179 prev_block_ptr1 = row_ptr + pixel_ptr - 4;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
180
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
181 while (n_blocks--) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
182 block_ptr = row_ptr + pixel_ptr;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
183 prev_block_ptr = prev_block_ptr1;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
184 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
185 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
186 pixels[block_ptr++] = pixels[prev_block_ptr++];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
187 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
188 block_ptr += row_inc;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
189 prev_block_ptr += row_inc;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
190 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
191 ADVANCE_BLOCK();
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
192 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
193 break;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
194
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
195 /* repeat previous pair of blocks n times */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
196 case 0x40:
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
197 case 0x50:
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
198 n_blocks = GET_BLOCK_COUNT();
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
199 n_blocks *= 2;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
200
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
201 /* sanity check */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
202 if ((row_ptr == 0) && (pixel_ptr < 2 * 4)) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
203 printf("encountered repeat block opcode (%02X) but not enough blocks rendered yet\n",
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
204 opcode & 0xF0);
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
205 break;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
206 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
207
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
208 /* figure out where the previous 2 blocks started */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
209 if (pixel_ptr == 0)
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
210 prev_block_ptr1 = (row_ptr - s->avctx->width * 4) +
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
211 s->avctx->width - 4 * 2;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
212 else if (pixel_ptr == 4)
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
213 prev_block_ptr1 = (row_ptr - s->avctx->width * 4) + row_inc;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
214 else
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
215 prev_block_ptr1 = row_ptr + pixel_ptr - 4 * 2;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
216
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
217 if (pixel_ptr == 0)
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
218 prev_block_ptr2 = (row_ptr - s->avctx->width * 4) + row_inc;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
219 else
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
220 prev_block_ptr2 = row_ptr + pixel_ptr - 4;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
221
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
222 prev_block_flag = 0;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
223 while (n_blocks--) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
224 block_ptr = row_ptr + pixel_ptr;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
225 if (prev_block_flag)
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
226 prev_block_ptr = prev_block_ptr2;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
227 else
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
228 prev_block_ptr = prev_block_ptr1;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
229 prev_block_flag = !prev_block_flag;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
230
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
231 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
232 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
233 pixels[block_ptr++] = pixels[prev_block_ptr++];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
234 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
235 block_ptr += row_inc;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
236 prev_block_ptr += row_inc;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
237 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
238 ADVANCE_BLOCK();
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
239 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
240 break;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
241
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
242 /* 1-color block encoding */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
243 case 0x60:
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
244 case 0x70:
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
245 n_blocks = GET_BLOCK_COUNT();
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
246 pixel = s->buf[stream_ptr++];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
247
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
248 while (n_blocks--) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
249 block_ptr = row_ptr + pixel_ptr;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
250 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
251 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
252 pixels[block_ptr++] = pixel;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
253 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
254 block_ptr += row_inc;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
255 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
256 ADVANCE_BLOCK();
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
257 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
258 break;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
259
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
260 /* 2-color block encoding */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
261 case 0x80:
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
262 case 0x90:
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
263 n_blocks = (opcode & 0x0F) + 1;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
264
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
265 /* figure out which color pair to use to paint the 2-color block */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
266 if ((opcode & 0xF0) == 0x80) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
267 /* fetch the next 2 colors from bytestream and store in next
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
268 * available entry in the color pair table */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
269 for (i = 0; i < CPAIR; i++) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
270 pixel = s->buf[stream_ptr++];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
271 color_table_index = CPAIR * color_pair_index + i;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
272 s->color_pairs[color_table_index] = pixel;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
273 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
274 /* this is the base index to use for this block */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
275 color_table_index = CPAIR * color_pair_index;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
276 color_pair_index++;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
277 /* wraparound */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
278 if (color_pair_index == COLORS_PER_TABLE)
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
279 color_pair_index = 0;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
280 } else
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
281 color_table_index = CPAIR * s->buf[stream_ptr++];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
282
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
283 while (n_blocks--) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
284 color_flags = BE_16(&s->buf[stream_ptr]);
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
285 stream_ptr += 2;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
286 flag_mask = 0x8000;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
287 block_ptr = row_ptr + pixel_ptr;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
288 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
289 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
290 if (color_flags & flag_mask)
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
291 pixel = color_table_index + 1;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
292 else
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
293 pixel = color_table_index;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
294 flag_mask >>= 1;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
295 pixels[block_ptr++] = s->color_pairs[pixel];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
296 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
297 block_ptr += row_inc;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
298 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
299 ADVANCE_BLOCK();
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
300 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
301 break;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
302
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
303 /* 4-color block encoding */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
304 case 0xA0:
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
305 case 0xB0:
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
306 n_blocks = (opcode & 0x0F) + 1;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
307
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
308 /* figure out which color quad to use to paint the 4-color block */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
309 if ((opcode & 0xF0) == 0xA0) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
310 /* fetch the next 4 colors from bytestream and store in next
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
311 * available entry in the color quad table */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
312 for (i = 0; i < CQUAD; i++) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
313 pixel = s->buf[stream_ptr++];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
314 color_table_index = CQUAD * color_quad_index + i;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
315 s->color_quads[color_table_index] = pixel;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
316 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
317 /* this is the base index to use for this block */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
318 color_table_index = CQUAD * color_quad_index;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
319 color_quad_index++;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
320 /* wraparound */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
321 if (color_quad_index == COLORS_PER_TABLE)
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
322 color_quad_index = 0;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
323 } else
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
324 color_table_index = CQUAD * s->buf[stream_ptr++];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
325
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
326 while (n_blocks--) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
327 color_flags = BE_32(&s->buf[stream_ptr]);
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
328 stream_ptr += 4;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
329 /* flag mask actually acts as a bit shift count here */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
330 flag_mask = 30;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
331 block_ptr = row_ptr + pixel_ptr;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
332 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
333 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
334 pixel = color_table_index +
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
335 ((color_flags >> flag_mask) & 0x03);
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
336 flag_mask -= 2;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
337 pixels[block_ptr++] = s->color_quads[pixel];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
338 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
339 block_ptr += row_inc;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
340 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
341 ADVANCE_BLOCK();
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
342 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
343 break;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
344
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
345 /* 8-color block encoding */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
346 case 0xC0:
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
347 case 0xD0:
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
348 n_blocks = (opcode & 0x0F) + 1;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
349
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
350 /* figure out which color octet to use to paint the 8-color block */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
351 if ((opcode & 0xF0) == 0xC0) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
352 /* fetch the next 8 colors from bytestream and store in next
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
353 * available entry in the color octet table */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
354 for (i = 0; i < COCTET; i++) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
355 pixel = s->buf[stream_ptr++];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
356 color_table_index = COCTET * color_octet_index + i;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
357 s->color_octets[color_table_index] = pixel;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
358 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
359 /* this is the base index to use for this block */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
360 color_table_index = COCTET * color_octet_index;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
361 color_octet_index++;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
362 /* wraparound */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
363 if (color_octet_index == COLORS_PER_TABLE)
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
364 color_octet_index = 0;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
365 } else
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
366 color_table_index = COCTET * s->buf[stream_ptr++];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
367
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
368 while (n_blocks--) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
369 /*
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
370 For this input of 6 hex bytes:
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
371 01 23 45 67 89 AB
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
372 Mangle it to this output:
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
373 flags_a = xx012456, flags_b = xx89A37B
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
374 */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
375 /* build the color flags */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
376 color_flags_a = color_flags_b = 0;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
377 color_flags_a =
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
378 (s->buf[stream_ptr + 0] << 16) |
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
379 ((s->buf[stream_ptr + 1] & 0xF0) << 8) |
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
380 ((s->buf[stream_ptr + 2] & 0xF0) << 4) |
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
381 ((s->buf[stream_ptr + 2] & 0x0F) << 4) |
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
382 ((s->buf[stream_ptr + 3] & 0xF0) >> 4);
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
383 color_flags_b =
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
384 (s->buf[stream_ptr + 4] << 16) |
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
385 ((s->buf[stream_ptr + 5] & 0xF0) << 8) |
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
386 ((s->buf[stream_ptr + 1] & 0x0F) << 8) |
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
387 ((s->buf[stream_ptr + 3] & 0x0F) << 4) |
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
388 (s->buf[stream_ptr + 5] & 0x0F);
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
389 stream_ptr += 6;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
390
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
391 color_flags = color_flags_a;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
392 /* flag mask actually acts as a bit shift count here */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
393 flag_mask = 21;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
394 block_ptr = row_ptr + pixel_ptr;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
395 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
396 /* reload flags at third row (iteration pixel_y == 2) */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
397 if (pixel_y == 2) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
398 color_flags = color_flags_b;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
399 flag_mask = 21;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
400 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
401 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
402 pixel = color_table_index +
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
403 ((color_flags >> flag_mask) & 0x07);
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
404 flag_mask -= 3;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
405 pixels[block_ptr++] = s->color_octets[pixel];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
406 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
407 block_ptr += row_inc;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
408 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
409 ADVANCE_BLOCK();
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
410 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
411 break;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
412
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
413 /* 16-color block encoding (every pixel is a different color) */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
414 case 0xE0:
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
415 n_blocks = (opcode & 0x0F) + 1;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
416
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
417 while (n_blocks--) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
418 block_ptr = row_ptr + pixel_ptr;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
419 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
420 for (pixel_x = 0; pixel_x < 4; pixel_x++) {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
421 pixels[block_ptr++] = s->buf[stream_ptr++];
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
422 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
423 block_ptr += row_inc;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
424 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
425 ADVANCE_BLOCK();
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
426 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
427 break;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
428
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
429 case 0xF0:
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
430 printf("0xF0 opcode seen in SMC chunk (xine developers would like to know)\n");
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
431 break;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
432 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
433 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
434 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
435
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
436 static int smc_decode_init(AVCodecContext *avctx)
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
437 {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
438 SmcContext *s = (SmcContext *)avctx->priv_data;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
439
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
440 s->avctx = avctx;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
441 avctx->pix_fmt = PIX_FMT_PAL8;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
442 avctx->has_b_frames = 0;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
443 dsputil_init(&s->dsp, avctx);
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
444
1630
586b5c08863c - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 1610
diff changeset
445 s->frame.data[0] = NULL;
1610
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
446
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
447 return 0;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
448 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
449
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
450 static int smc_decode_frame(AVCodecContext *avctx,
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
451 void *data, int *data_size,
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
452 uint8_t *buf, int buf_size)
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
453 {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
454 SmcContext *s = (SmcContext *)avctx->priv_data;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
455
1630
586b5c08863c - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 1610
diff changeset
456 /* no supplementary picture */
586b5c08863c - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 1610
diff changeset
457 if (buf_size == 0)
586b5c08863c - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 1610
diff changeset
458 return 0;
586b5c08863c - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 1610
diff changeset
459
1610
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
460 s->buf = buf;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
461 s->size = buf_size;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
462
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
463 s->frame.reference = 1;
1630
586b5c08863c - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 1610
diff changeset
464 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE |
586b5c08863c - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 1610
diff changeset
465 FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE;
586b5c08863c - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 1610
diff changeset
466 if (avctx->reget_buffer(avctx, &s->frame)) {
586b5c08863c - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 1610
diff changeset
467 printf ("reget_buffer() failed\n");
1610
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
468 return -1;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
469 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
470
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
471 smc_decode_stream(s);
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
472
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
473 *data_size = sizeof(AVFrame);
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
474 *(AVFrame*)data = s->frame;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
475
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
476 /* always report that the buffer was completely consumed */
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
477 return buf_size;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
478 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
479
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
480 static int smc_decode_end(AVCodecContext *avctx)
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
481 {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
482 SmcContext *s = (SmcContext *)avctx->priv_data;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
483
1630
586b5c08863c - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 1610
diff changeset
484 if (s->frame.data[0])
586b5c08863c - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 1610
diff changeset
485 avctx->release_buffer(avctx, &s->frame);
1610
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
486
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
487 return 0;
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
488 }
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
489
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
490 AVCodec smc_decoder = {
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
491 "smc",
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
492 CODEC_TYPE_VIDEO,
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
493 CODEC_ID_SMC,
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
494 sizeof(SmcContext),
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
495 smc_decode_init,
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
496 NULL,
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
497 smc_decode_end,
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
498 smc_decode_frame,
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
499 CODEC_CAP_DR1,
b0fe2a0adf49 added Apple Graphics (SMC) decoder
melanson
parents:
diff changeset
500 };