annotate smc.c @ 9990:e909e1f7b3f1 libavcodec

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