Mercurial > libavcodec.hg
annotate qdrw.c @ 2359:a3c029107a88 libavcodec
fixing rv20201002
author | michael |
---|---|
date | Fri, 19 Nov 2004 18:19:36 +0000 |
parents | c443a6af19a7 |
children | f67b63ed036d |
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 * |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
5 * This library is free software; you can redistribute it and/or |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
6 * 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
|
7 * License as published by the Free Software Foundation; either |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
8 * version 2 of the License, or (at your option) any later version. |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
9 * |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
10 * This library is distributed in the hope that it will be useful, |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
11 * 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
|
12 * 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
|
13 * Lesser General Public License for more details. |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
14 * |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
15 * You should have received a copy of the GNU Lesser General Public |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
16 * License along with this library; if not, write to the Free Software |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
18 * |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
19 */ |
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 /** |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
22 * @file qdrw.c |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
23 * Apple QuickDraw codec. |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
24 */ |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
25 |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
26 #include "avcodec.h" |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
27 #include "mpegvideo.h" |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
28 |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
29 typedef struct QdrawContext{ |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
30 AVCodecContext *avctx; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
31 AVFrame pic; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
32 uint8_t palette[256*3]; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
33 } QdrawContext; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
34 |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
35 static int decode_frame(AVCodecContext *avctx, |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
36 void *data, int *data_size, |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
37 uint8_t *buf, int buf_size) |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
38 { |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
39 QdrawContext * const a = avctx->priv_data; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
40 AVFrame * const p= (AVFrame*)&a->pic; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
41 uint8_t* outdata; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
42 int colors; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
43 int i; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
44 |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
45 /* special case for last picture */ |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
46 if (buf_size == 0) { |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
47 return 0; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
48 } |
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 if(p->data[0]) |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
51 avctx->release_buffer(avctx, p); |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
52 |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
53 p->reference= 0; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
54 if(avctx->get_buffer(avctx, p) < 0){ |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
55 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
|
56 return -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 p->pict_type= I_TYPE; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
59 p->key_frame= 1; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
60 |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
61 outdata = a->pic.data[0]; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
62 |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
63 buf += 0x68; /* jump to palette */ |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
64 colors = BE_32(buf); |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
65 buf += 4; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
66 |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
67 if(colors < 0 || colors > 256) { |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
68 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
|
69 return -1; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
70 } |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
71 |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
72 for (i = 0; i <= colors; i++) { |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
73 int idx; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
74 idx = BE_16(buf); /* color index */ |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
75 buf += 2; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
76 |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
77 a->palette[idx * 3 + 0] = *buf++; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
78 buf++; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
79 a->palette[idx * 3 + 1] = *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 + 2] = *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 } |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
84 |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
85 if (colors) |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
86 a->pic.palette_has_changed = 1; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
87 |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
88 buf += 18; /* skip unneeded data */ |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
89 for (i = 0; i < avctx->height; i++) { |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
90 int size, left, code, pix; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
91 uint8_t *next; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
92 uint8_t *out; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
93 int tsize = 0; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
94 |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
95 /* decode line */ |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
96 out = outdata; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
97 size = BE_16(buf); /* size of packed line */ |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
98 buf += 2; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
99 left = size; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
100 next = buf + size; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
101 while (left > 0) { |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
102 code = *buf++; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
103 if (code & 0x80 ) { /* run */ |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
104 int i; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
105 pix = *buf++; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
106 for (i = 0; i < 257 - code; i++) { |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
107 *out++ = a->palette[pix * 3 + 0]; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
108 *out++ = a->palette[pix * 3 + 1]; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
109 *out++ = a->palette[pix * 3 + 2]; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
110 } |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
111 tsize += 257 - code; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
112 left -= 2; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
113 } else { /* copy */ |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
114 int i, pix; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
115 for (i = 0; i <= code; i++) { |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
116 pix = *buf++; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
117 *out++ = a->palette[pix * 3 + 0]; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
118 *out++ = a->palette[pix * 3 + 1]; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
119 *out++ = a->palette[pix * 3 + 2]; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
120 } |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
121 left -= 2 + code; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
122 tsize += code + 1; |
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 } |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
125 buf = next; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
126 outdata += a->pic.linesize[0]; |
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 |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
129 *data_size = sizeof(AVFrame); |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
130 *(AVFrame*)data = a->pic; |
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 return buf_size; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
133 } |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
134 |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
135 static int decode_init(AVCodecContext *avctx){ |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
136 // QdrawContext * const a = avctx->priv_data; |
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 avctx->pix_fmt= PIX_FMT_RGB24; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
139 |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
140 return 0; |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
141 } |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
142 |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
143 AVCodec qdraw_decoder = { |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
144 "qdraw", |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
145 CODEC_TYPE_VIDEO, |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
146 CODEC_ID_QDRAW, |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
147 sizeof(QdrawContext), |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
148 decode_init, |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
149 NULL, |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
150 NULL, |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
151 decode_frame, |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
152 CODEC_CAP_DR1, |
c443a6af19a7
support for Sierra Online audio files and Apple QuickDraw codec,
melanson
parents:
diff
changeset
|
153 }; |