2 * QuickDraw (qdrw) codec
3 * Copyright (c) 2004 Konstantin Shishkov
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 * Apple QuickDraw codec.
29 #include "mpegvideo.h"
31 typedef struct QdrawContext{
32 AVCodecContext *avctx;
34 uint8_t palette[256*3];
37 static int decode_frame(AVCodecContext *avctx,
38 void *data, int *data_size,
39 uint8_t *buf, int buf_size)
41 QdrawContext * const a = avctx->priv_data;
42 AVFrame * const p= (AVFrame*)&a->pic;
48 avctx->release_buffer(avctx, p);
51 if(avctx->get_buffer(avctx, p) < 0){
52 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
58 outdata = a->pic.data[0];
60 buf += 0x68; /* jump to palette */
64 if(colors < 0 || colors > 256) {
65 av_log(avctx, AV_LOG_ERROR, "Error color count - %i(0x%X)\n", colors, colors);
69 for (i = 0; i <= colors; i++) {
71 idx = BE_16(buf); /* color index */
75 av_log(avctx, AV_LOG_ERROR, "Palette index out of range: %u\n", idx);
79 a->palette[idx * 3 + 0] = *buf++;
81 a->palette[idx * 3 + 1] = *buf++;
83 a->palette[idx * 3 + 2] = *buf++;
87 buf += 18; /* skip unneeded data */
88 for (i = 0; i < avctx->height; i++) {
89 int size, left, code, pix;
96 size = BE_16(buf); /* size of packed line */
102 if (code & 0x80 ) { /* run */
105 if ((out + (257 - code) * 3) > (outdata + a->pic.linesize[0]))
107 for (i = 0; i < 257 - code; i++) {
108 *out++ = a->palette[pix * 3 + 0];
109 *out++ = a->palette[pix * 3 + 1];
110 *out++ = a->palette[pix * 3 + 2];
116 if ((out + code * 3) > (outdata + a->pic.linesize[0]))
118 for (i = 0; i <= code; i++) {
120 *out++ = a->palette[pix * 3 + 0];
121 *out++ = a->palette[pix * 3 + 1];
122 *out++ = a->palette[pix * 3 + 2];
129 outdata += a->pic.linesize[0];
132 *data_size = sizeof(AVFrame);
133 *(AVFrame*)data = a->pic;
138 static int decode_init(AVCodecContext *avctx){
139 // QdrawContext * const a = avctx->priv_data;
141 if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) {
145 avctx->pix_fmt= PIX_FMT_RGB24;
150 AVCodec qdraw_decoder = {
154 sizeof(QdrawContext),