annotate qdrw.c @ 4784:7738ad31b6e2 libavcodec

vc1_split should be static
author kostya
date Wed, 04 Apr 2007 13:26:26 +0000
parents 05e932ddaaa9
children 94301f9f53f7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
1 /*
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
2 * QuickDraw (qdrw) codec
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
3 * Copyright (c) 2004 Konstantin Shishkov
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3800
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3800
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3800
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
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: 3800
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3800
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
15 * Lesser General Public License for more details.
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
16 *
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
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: 3800
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: 2967
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
20 *
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
21 */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2455
diff changeset
22
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
23 /**
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
24 * @file qdrw.c
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
25 * Apple QuickDraw codec.
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
26 */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2455
diff changeset
27
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
28 #include "avcodec.h"
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
29 #include "mpegvideo.h"
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
30
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
31 typedef struct QdrawContext{
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
32 AVCodecContext *avctx;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
33 AVFrame pic;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
34 uint8_t palette[256*3];
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
35 } QdrawContext;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
36
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2455
diff changeset
37 static int decode_frame(AVCodecContext *avctx,
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
38 void *data, int *data_size,
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
39 uint8_t *buf, int buf_size)
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
40 {
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
41 QdrawContext * const a = avctx->priv_data;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
42 AVFrame * const p= (AVFrame*)&a->pic;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
43 uint8_t* outdata;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
44 int colors;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
45 int i;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2455
diff changeset
46
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
47 if(p->data[0])
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
48 avctx->release_buffer(avctx, p);
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
49
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
50 p->reference= 0;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
51 if(avctx->get_buffer(avctx, p) < 0){
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
52 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
53 return -1;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
54 }
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
55 p->pict_type= I_TYPE;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
56 p->key_frame= 1;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
57
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
58 outdata = a->pic.data[0];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2455
diff changeset
59
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
60 buf += 0x68; /* jump to palette */
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
61 colors = AV_RB32(buf);
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
62 buf += 4;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2455
diff changeset
63
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
64 if(colors < 0 || colors > 256) {
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
65 av_log(avctx, AV_LOG_ERROR, "Error color count - %i(0x%X)\n", colors, colors);
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
66 return -1;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
67 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2455
diff changeset
68
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
69 for (i = 0; i <= colors; i++) {
2455
d74d342cabb9 Check pointers before writing to memory
rtognimp
parents: 2453
diff changeset
70 unsigned int idx;
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
71 idx = AV_RB16(buf); /* color index */
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
72 buf += 2;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2455
diff changeset
73
2455
d74d342cabb9 Check pointers before writing to memory
rtognimp
parents: 2453
diff changeset
74 if (idx > 255) {
d74d342cabb9 Check pointers before writing to memory
rtognimp
parents: 2453
diff changeset
75 av_log(avctx, AV_LOG_ERROR, "Palette index out of range: %u\n", idx);
d74d342cabb9 Check pointers before writing to memory
rtognimp
parents: 2453
diff changeset
76 buf += 6;
d74d342cabb9 Check pointers before writing to memory
rtognimp
parents: 2453
diff changeset
77 continue;
d74d342cabb9 Check pointers before writing to memory
rtognimp
parents: 2453
diff changeset
78 }
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
79 a->palette[idx * 3 + 0] = *buf++;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
80 buf++;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
81 a->palette[idx * 3 + 1] = *buf++;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
82 buf++;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
83 a->palette[idx * 3 + 2] = *buf++;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
84 buf++;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
85 }
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
86
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
87 buf += 18; /* skip unneeded data */
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
88 for (i = 0; i < avctx->height; i++) {
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
89 int size, left, code, pix;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
90 uint8_t *next;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
91 uint8_t *out;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
92 int tsize = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2455
diff changeset
93
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
94 /* decode line */
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
95 out = outdata;
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
96 size = AV_RB16(buf); /* size of packed line */
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
97 buf += 2;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
98 left = size;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
99 next = buf + size;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
100 while (left > 0) {
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
101 code = *buf++;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
102 if (code & 0x80 ) { /* run */
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
103 int i;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
104 pix = *buf++;
2455
d74d342cabb9 Check pointers before writing to memory
rtognimp
parents: 2453
diff changeset
105 if ((out + (257 - code) * 3) > (outdata + a->pic.linesize[0]))
d74d342cabb9 Check pointers before writing to memory
rtognimp
parents: 2453
diff changeset
106 break;
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
107 for (i = 0; i < 257 - code; i++) {
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
108 *out++ = a->palette[pix * 3 + 0];
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
109 *out++ = a->palette[pix * 3 + 1];
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
110 *out++ = a->palette[pix * 3 + 2];
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
111 }
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
112 tsize += 257 - code;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
113 left -= 2;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
114 } else { /* copy */
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
115 int i, pix;
2455
d74d342cabb9 Check pointers before writing to memory
rtognimp
parents: 2453
diff changeset
116 if ((out + code * 3) > (outdata + a->pic.linesize[0]))
d74d342cabb9 Check pointers before writing to memory
rtognimp
parents: 2453
diff changeset
117 break;
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
118 for (i = 0; i <= code; i++) {
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
119 pix = *buf++;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
120 *out++ = a->palette[pix * 3 + 0];
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
121 *out++ = a->palette[pix * 3 + 1];
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
122 *out++ = a->palette[pix * 3 + 2];
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
123 }
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
124 left -= 2 + code;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
125 tsize += code + 1;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
126 }
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
127 }
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
128 buf = next;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
129 outdata += a->pic.linesize[0];
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
130 }
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
131
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
132 *data_size = sizeof(AVFrame);
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
133 *(AVFrame*)data = a->pic;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2455
diff changeset
134
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
135 return buf_size;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
136 }
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
137
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
138 static int decode_init(AVCodecContext *avctx){
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
139 // QdrawContext * const a = avctx->priv_data;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
140
3800
9b75ab171fa9 1l: correct argument order in avcodec_check_dimensions
kostya
parents: 3036
diff changeset
141 if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) {
2455
d74d342cabb9 Check pointers before writing to memory
rtognimp
parents: 2453
diff changeset
142 return 1;
d74d342cabb9 Check pointers before writing to memory
rtognimp
parents: 2453
diff changeset
143 }
d74d342cabb9 Check pointers before writing to memory
rtognimp
parents: 2453
diff changeset
144
2275
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
145 avctx->pix_fmt= PIX_FMT_RGB24;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
146
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
147 return 0;
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
148 }
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
149
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
150 AVCodec qdraw_decoder = {
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
151 "qdraw",
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
152 CODEC_TYPE_VIDEO,
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
153 CODEC_ID_QDRAW,
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
154 sizeof(QdrawContext),
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
155 decode_init,
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
156 NULL,
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
157 NULL,
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
158 decode_frame,
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
159 CODEC_CAP_DR1,
c443a6af19a7 support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff changeset
160 };