2 * QuickDraw (qdrw) codec
3 * Copyright (c) 2004 Konstantin Shishkov
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Apple QuickDraw codec.
27 #include "mpegvideo.h"
29 typedef struct QdrawContext
{
30 AVCodecContext
*avctx
;
32 uint8_t palette
[256*3];
35 static int decode_frame(AVCodecContext
*avctx
,
36 void *data
, int *data_size
,
37 uint8_t *buf
, int buf_size
)
39 QdrawContext
* const a
= avctx
->priv_data
;
40 AVFrame
* const p
= (AVFrame
*)&a
->pic
;
46 avctx
->release_buffer(avctx
, p
);
49 if(avctx
->get_buffer(avctx
, p
) < 0){
50 av_log(avctx
, AV_LOG_ERROR
, "get_buffer() failed\n");
56 outdata
= a
->pic
.data
[0];
58 buf
+= 0x68; /* jump to palette */
62 if(colors
< 0 || colors
> 256) {
63 av_log(avctx
, AV_LOG_ERROR
, "Error color count - %i(0x%X)\n", colors
, colors
);
67 for (i
= 0; i
<= colors
; i
++) {
69 idx
= BE_16(buf
); /* color index */
73 av_log(avctx
, AV_LOG_ERROR
, "Palette index out of range: %u\n", idx
);
77 a
->palette
[idx
* 3 + 0] = *buf
++;
79 a
->palette
[idx
* 3 + 1] = *buf
++;
81 a
->palette
[idx
* 3 + 2] = *buf
++;
85 buf
+= 18; /* skip unneeded data */
86 for (i
= 0; i
< avctx
->height
; i
++) {
87 int size
, left
, code
, pix
;
94 size
= BE_16(buf
); /* size of packed line */
100 if (code
& 0x80 ) { /* run */
103 if ((out
+ (257 - code
) * 3) > (outdata
+ a
->pic
.linesize
[0]))
105 for (i
= 0; i
< 257 - code
; i
++) {
106 *out
++ = a
->palette
[pix
* 3 + 0];
107 *out
++ = a
->palette
[pix
* 3 + 1];
108 *out
++ = a
->palette
[pix
* 3 + 2];
114 if ((out
+ code
* 3) > (outdata
+ a
->pic
.linesize
[0]))
116 for (i
= 0; i
<= code
; i
++) {
118 *out
++ = a
->palette
[pix
* 3 + 0];
119 *out
++ = a
->palette
[pix
* 3 + 1];
120 *out
++ = a
->palette
[pix
* 3 + 2];
127 outdata
+= a
->pic
.linesize
[0];
130 *data_size
= sizeof(AVFrame
);
131 *(AVFrame
*)data
= a
->pic
;
136 static int decode_init(AVCodecContext
*avctx
){
137 // QdrawContext * const a = avctx->priv_data;
139 if (avcodec_check_dimensions(avctx
, avctx
->height
, avctx
->width
) < 0) {
143 avctx
->pix_fmt
= PIX_FMT_RGB24
;
148 AVCodec qdraw_decoder
= {
152 sizeof(QdrawContext
),