2004-09-28 06:09:49 +03:00
|
|
|
/*
|
|
|
|
* QuickDraw (qdrw) codec
|
|
|
|
* Copyright (c) 2004 Konstantin Shishkov
|
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2004-09-28 06:09:49 +03:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 18:30:46 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2004-09-28 06:09:49 +03:00
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2004-09-28 06:09:49 +03:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-10-07 18:30:46 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-13 00:43:26 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2004-09-28 06:09:49 +03:00
|
|
|
*/
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2004-09-28 06:09:49 +03:00
|
|
|
/**
|
2010-04-20 17:45:34 +03:00
|
|
|
* @file
|
2004-09-28 06:09:49 +03:00
|
|
|
* Apple QuickDraw codec.
|
|
|
|
*/
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2012-08-06 16:49:32 +03:00
|
|
|
#include "libavutil/common.h"
|
2009-01-12 00:19:48 +02:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2004-09-28 06:09:49 +03:00
|
|
|
#include "avcodec.h"
|
2012-11-10 15:22:56 +03:00
|
|
|
#include "internal.h"
|
2004-09-28 06:09:49 +03:00
|
|
|
|
2005-12-17 20:14:38 +02:00
|
|
|
static int decode_frame(AVCodecContext *avctx,
|
2012-11-13 21:35:22 +03:00
|
|
|
void *data, int *got_frame,
|
2009-04-07 18:59:50 +03:00
|
|
|
AVPacket *avpkt)
|
2004-09-28 06:09:49 +03:00
|
|
|
{
|
2012-11-19 12:40:03 +03:00
|
|
|
const uint8_t *buf = avpkt->data;
|
2011-09-30 01:05:46 +03:00
|
|
|
const uint8_t *buf_end = avpkt->data + avpkt->size;
|
2012-11-19 12:40:03 +03:00
|
|
|
int buf_size = avpkt->size;
|
2012-11-21 23:34:46 +03:00
|
|
|
AVFrame * const p = data;
|
2004-09-28 06:09:49 +03:00
|
|
|
uint8_t* outdata;
|
|
|
|
int colors;
|
2012-11-19 12:38:03 +03:00
|
|
|
int i, ret;
|
2007-04-06 07:40:13 +03:00
|
|
|
uint32_t *pal;
|
|
|
|
int r, g, b;
|
2005-12-17 20:14:38 +02:00
|
|
|
|
lavc: factorize ff_{thread_,re,}get_buffer error messages.
Coccinelle profile used:
@@
expression r, ctx, f, loglevel, str, flags;
@@
-if ((r = ff_get_buffer(ctx, f, flags)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_get_buffer(ctx, f, flags)) < 0)
+ return r;
@@
expression r, ctx, f, loglevel, str;
@@
-if ((r = ff_reget_buffer(ctx, f)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_reget_buffer(ctx, f)) < 0)
+ return r;
@@
expression r, ctx, f, loglevel, str, flags;
@@
-if ((r = ff_thread_get_buffer(ctx, f, flags)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_thread_get_buffer(ctx, f, flags)) < 0)
+ return r;
...along with some manual patches for the remaining ones.
2013-03-12 10:41:53 +03:00
|
|
|
if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
|
2012-11-19 12:38:03 +03:00
|
|
|
return ret;
|
2012-11-19 12:40:03 +03:00
|
|
|
p->pict_type = AV_PICTURE_TYPE_I;
|
|
|
|
p->key_frame = 1;
|
2004-09-28 06:09:49 +03:00
|
|
|
|
2012-11-21 23:34:46 +03:00
|
|
|
outdata = p->data[0];
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2011-09-30 01:05:46 +03:00
|
|
|
if (buf_end - buf < 0x68 + 4)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2012-11-19 12:40:03 +03:00
|
|
|
buf += 0x68; /* jump to palette */
|
2007-01-20 00:12:59 +02:00
|
|
|
colors = AV_RB32(buf);
|
2012-11-19 12:40:03 +03:00
|
|
|
buf += 4;
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2012-11-19 12:40:03 +03:00
|
|
|
if (colors < 0 || colors > 256) {
|
2004-09-28 06:09:49 +03:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Error color count - %i(0x%X)\n", colors, colors);
|
2012-11-19 12:38:03 +03:00
|
|
|
return AVERROR_INVALIDDATA;
|
2004-09-28 06:09:49 +03:00
|
|
|
}
|
2011-09-30 01:05:46 +03:00
|
|
|
if (buf_end - buf < (colors + 1) * 8)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2007-04-06 07:40:13 +03:00
|
|
|
pal = (uint32_t*)p->data[1];
|
2004-09-28 06:09:49 +03:00
|
|
|
for (i = 0; i <= colors; i++) {
|
2005-01-23 23:36:24 +02:00
|
|
|
unsigned int idx;
|
2007-01-20 00:12:59 +02:00
|
|
|
idx = AV_RB16(buf); /* color index */
|
2004-09-28 06:09:49 +03:00
|
|
|
buf += 2;
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2005-01-23 23:36:24 +02:00
|
|
|
if (idx > 255) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Palette index out of range: %u\n", idx);
|
|
|
|
buf += 6;
|
|
|
|
continue;
|
|
|
|
}
|
2007-04-06 07:40:13 +03:00
|
|
|
r = *buf++;
|
2004-09-28 06:09:49 +03:00
|
|
|
buf++;
|
2007-04-06 07:40:13 +03:00
|
|
|
g = *buf++;
|
2004-09-28 06:09:49 +03:00
|
|
|
buf++;
|
2007-04-06 07:40:13 +03:00
|
|
|
b = *buf++;
|
2004-09-28 06:09:49 +03:00
|
|
|
buf++;
|
2012-10-14 04:17:13 +03:00
|
|
|
pal[idx] = 0xFFU << 24 | r << 16 | g << 8 | b;
|
2004-09-28 06:09:49 +03:00
|
|
|
}
|
2007-04-06 07:40:13 +03:00
|
|
|
p->palette_has_changed = 1;
|
2004-09-28 06:09:49 +03:00
|
|
|
|
2011-09-30 01:05:46 +03:00
|
|
|
if (buf_end - buf < 18)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2004-09-28 06:09:49 +03:00
|
|
|
buf += 18; /* skip unneeded data */
|
|
|
|
for (i = 0; i < avctx->height; i++) {
|
|
|
|
int size, left, code, pix;
|
2008-02-01 17:40:03 +02:00
|
|
|
const uint8_t *next;
|
2004-09-28 06:09:49 +03:00
|
|
|
uint8_t *out;
|
|
|
|
int tsize = 0;
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2004-09-28 06:09:49 +03:00
|
|
|
/* decode line */
|
2012-11-19 12:40:03 +03:00
|
|
|
out = outdata;
|
2007-01-20 00:12:59 +02:00
|
|
|
size = AV_RB16(buf); /* size of packed line */
|
2004-09-28 06:09:49 +03:00
|
|
|
buf += 2;
|
2011-09-30 01:05:46 +03:00
|
|
|
if (buf_end - buf < size)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
2004-09-28 06:09:49 +03:00
|
|
|
left = size;
|
|
|
|
next = buf + size;
|
|
|
|
while (left > 0) {
|
|
|
|
code = *buf++;
|
|
|
|
if (code & 0x80 ) { /* run */
|
|
|
|
pix = *buf++;
|
2012-11-21 23:34:46 +03:00
|
|
|
if ((out + (257 - code)) > (outdata + p->linesize[0]))
|
2005-01-23 23:36:24 +02:00
|
|
|
break;
|
2007-04-06 07:40:13 +03:00
|
|
|
memset(out, pix, 257 - code);
|
2012-11-19 12:40:03 +03:00
|
|
|
out += 257 - code;
|
2004-09-28 06:09:49 +03:00
|
|
|
tsize += 257 - code;
|
2012-11-19 12:40:03 +03:00
|
|
|
left -= 2;
|
2004-09-28 06:09:49 +03:00
|
|
|
} else { /* copy */
|
2012-11-21 23:34:46 +03:00
|
|
|
if ((out + code) > (outdata + p->linesize[0]))
|
2005-01-23 23:36:24 +02:00
|
|
|
break;
|
2011-09-30 01:05:46 +03:00
|
|
|
if (buf_end - buf < code + 1)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2007-04-06 07:40:13 +03:00
|
|
|
memcpy(out, buf, code + 1);
|
2012-11-19 12:40:03 +03:00
|
|
|
out += code + 1;
|
|
|
|
buf += code + 1;
|
|
|
|
left -= 2 + code;
|
2004-09-28 06:09:49 +03:00
|
|
|
tsize += code + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buf = next;
|
2012-11-21 23:34:46 +03:00
|
|
|
outdata += p->linesize[0];
|
2004-09-28 06:09:49 +03:00
|
|
|
}
|
|
|
|
|
2012-11-13 21:35:22 +03:00
|
|
|
*got_frame = 1;
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2004-09-28 06:09:49 +03:00
|
|
|
return buf_size;
|
|
|
|
}
|
|
|
|
|
2012-11-19 12:40:03 +03:00
|
|
|
static av_cold int decode_init(AVCodecContext *avctx)
|
|
|
|
{
|
2012-10-06 13:10:34 +03:00
|
|
|
avctx->pix_fmt= AV_PIX_FMT_PAL8;
|
2004-09-28 06:09:49 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-25 23:40:11 +02:00
|
|
|
AVCodec ff_qdraw_decoder = {
|
2011-07-17 13:54:31 +03:00
|
|
|
.name = "qdraw",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
2012-08-05 12:11:04 +03:00
|
|
|
.id = AV_CODEC_ID_QDRAW,
|
2011-07-17 13:54:31 +03:00
|
|
|
.init = decode_init,
|
|
|
|
.decode = decode_frame,
|
|
|
|
.capabilities = CODEC_CAP_DR1,
|
2012-04-06 19:19:39 +03:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("Apple QuickDraw"),
|
2004-09-28 06:09:49 +03:00
|
|
|
};
|