2004-09-28 03:09:49 +00:00
|
|
|
/*
|
|
|
|
* QuickDraw (qdrw) codec
|
|
|
|
* Copyright (c) 2004 Konstantin Shishkov
|
2015-04-18 16:25:19 +00:00
|
|
|
* Copyright (c) 2015 Vittorio Giovara
|
2004-09-28 03:09:49 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2004-09-28 03:09:49 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 15:30:46 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2004-09-28 03:09:49 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2004-09-28 03:09:49 +00: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 15:30:46 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-12 22:43:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2004-09-28 03:09:49 +00:00
|
|
|
*/
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-09-28 03:09:49 +00:00
|
|
|
/**
|
2010-04-20 14:45:34 +00:00
|
|
|
* @file
|
2004-09-28 03:09:49 +00:00
|
|
|
* Apple QuickDraw codec.
|
2015-04-18 16:25:19 +00:00
|
|
|
* https://developer.apple.com/legacy/library/documentation/mac/QuickDraw/QuickDraw-461.html
|
2004-09-28 03:09:49 +00:00
|
|
|
*/
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2012-08-06 13:49:32 +00:00
|
|
|
#include "libavutil/common.h"
|
2009-01-11 22:19:48 +00:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2004-09-28 03:09:49 +00:00
|
|
|
#include "avcodec.h"
|
2015-04-18 16:25:18 +00:00
|
|
|
#include "bytestream.h"
|
2012-11-10 12:22:56 +00:00
|
|
|
#include "internal.h"
|
2004-09-28 03:09:49 +00:00
|
|
|
|
2015-04-18 16:25:19 +00:00
|
|
|
enum QuickdrawOpcodes {
|
2017-02-22 14:32:26 +00:00
|
|
|
CLIP = 0x0001,
|
2015-04-18 16:25:19 +00:00
|
|
|
PACKBITSRECT = 0x0098,
|
|
|
|
PACKBITSRGN,
|
2015-04-18 16:25:20 +00:00
|
|
|
DIRECTBITSRECT,
|
|
|
|
DIRECTBITSRGN,
|
2017-01-13 19:18:36 +00:00
|
|
|
SHORTCOMMENT = 0x00A0,
|
|
|
|
LONGCOMMENT,
|
2015-04-18 16:25:18 +00:00
|
|
|
|
2015-04-18 16:25:19 +00:00
|
|
|
EOP = 0x00FF,
|
|
|
|
};
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2015-04-18 16:25:19 +00:00
|
|
|
static int parse_palette(AVCodecContext *avctx, GetByteContext *gbc,
|
|
|
|
uint32_t *pal, int colors)
|
|
|
|
{
|
|
|
|
int i;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-09-28 03:09:49 +00:00
|
|
|
for (i = 0; i <= colors; i++) {
|
2015-04-18 16:25:18 +00:00
|
|
|
uint8_t r, g, b;
|
2015-04-18 16:25:19 +00:00
|
|
|
unsigned int idx = bytestream2_get_be16(gbc); /* color index */
|
2005-01-23 21:36:24 +00:00
|
|
|
if (idx > 255) {
|
2015-04-18 16:25:19 +00:00
|
|
|
av_log(avctx, AV_LOG_WARNING,
|
|
|
|
"Palette index out of range: %u\n", idx);
|
|
|
|
bytestream2_skip(gbc, 6);
|
2005-01-23 21:36:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-06-04 19:37:47 +00:00
|
|
|
if (avctx->pix_fmt != AV_PIX_FMT_PAL8)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2015-04-18 16:25:19 +00:00
|
|
|
r = bytestream2_get_byte(gbc);
|
|
|
|
bytestream2_skip(gbc, 1);
|
|
|
|
g = bytestream2_get_byte(gbc);
|
|
|
|
bytestream2_skip(gbc, 1);
|
|
|
|
b = bytestream2_get_byte(gbc);
|
|
|
|
bytestream2_skip(gbc, 1);
|
2015-05-11 19:11:03 +00:00
|
|
|
pal[idx] = (0xFFU << 24) | (r << 16) | (g << 8) | b;
|
2004-09-28 03:09:49 +00:00
|
|
|
}
|
2015-04-18 16:25:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-09-28 03:09:49 +00:00
|
|
|
|
2017-02-21 18:45:44 +00:00
|
|
|
static int decode_rle_bpp2(AVCodecContext *avctx, AVFrame *p, GetByteContext *gbc)
|
|
|
|
{
|
|
|
|
int offset = avctx->width;
|
|
|
|
uint8_t *outdata = p->data[0];
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < avctx->height; i++) {
|
|
|
|
int size, left, code, pix;
|
|
|
|
uint8_t *out = outdata;
|
|
|
|
int pos = 0;
|
|
|
|
|
|
|
|
/* size of packed line */
|
2017-02-27 13:15:11 +00:00
|
|
|
if (offset / 4 > 200)
|
|
|
|
size = left = bytestream2_get_be16(gbc);
|
|
|
|
else
|
|
|
|
size = left = bytestream2_get_byte(gbc);
|
2017-02-21 18:45:44 +00:00
|
|
|
if (bytestream2_get_bytes_left(gbc) < size)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
/* decode line */
|
|
|
|
while (left > 0) {
|
|
|
|
code = bytestream2_get_byte(gbc);
|
|
|
|
if (code & 0x80 ) { /* run */
|
|
|
|
pix = bytestream2_get_byte(gbc);
|
|
|
|
for (j = 0; j < 257 - code; j++) {
|
2017-02-27 10:39:36 +00:00
|
|
|
if (pos < offset)
|
|
|
|
out[pos++] = (pix & 0xC0) >> 6;
|
|
|
|
if (pos < offset)
|
|
|
|
out[pos++] = (pix & 0x30) >> 4;
|
|
|
|
if (pos < offset)
|
|
|
|
out[pos++] = (pix & 0x0C) >> 2;
|
|
|
|
if (pos < offset)
|
|
|
|
out[pos++] = (pix & 0x03);
|
2017-02-21 18:45:44 +00:00
|
|
|
}
|
|
|
|
left -= 2;
|
|
|
|
} else { /* copy */
|
|
|
|
for (j = 0; j < code + 1; j++) {
|
|
|
|
pix = bytestream2_get_byte(gbc);
|
2017-02-27 10:39:36 +00:00
|
|
|
if (pos < offset)
|
|
|
|
out[pos++] = (pix & 0xC0) >> 6;
|
|
|
|
if (pos < offset)
|
|
|
|
out[pos++] = (pix & 0x30) >> 4;
|
|
|
|
if (pos < offset)
|
|
|
|
out[pos++] = (pix & 0x0C) >> 2;
|
|
|
|
if (pos < offset)
|
|
|
|
out[pos++] = (pix & 0x03);
|
2017-02-21 18:45:44 +00:00
|
|
|
}
|
|
|
|
left -= 1 + (code + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
outdata += p->linesize[0];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int decode_rle_bpp4(AVCodecContext *avctx, AVFrame *p, GetByteContext *gbc)
|
|
|
|
{
|
|
|
|
int offset = avctx->width;
|
|
|
|
uint8_t *outdata = p->data[0];
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < avctx->height; i++) {
|
|
|
|
int size, left, code, pix;
|
|
|
|
uint8_t *out = outdata;
|
|
|
|
int pos = 0;
|
|
|
|
|
|
|
|
/* size of packed line */
|
|
|
|
size = left = bytestream2_get_be16(gbc);
|
|
|
|
if (bytestream2_get_bytes_left(gbc) < size)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
/* decode line */
|
|
|
|
while (left > 0) {
|
|
|
|
code = bytestream2_get_byte(gbc);
|
|
|
|
if (code & 0x80 ) { /* run */
|
|
|
|
pix = bytestream2_get_byte(gbc);
|
|
|
|
for (j = 0; j < 257 - code; j++) {
|
2017-02-27 10:39:36 +00:00
|
|
|
if (pos < offset)
|
|
|
|
out[pos++] = (pix & 0xF0) >> 4;
|
|
|
|
if (pos < offset)
|
|
|
|
out[pos++] = pix & 0xF;
|
2017-02-21 18:45:44 +00:00
|
|
|
}
|
|
|
|
left -= 2;
|
|
|
|
} else { /* copy */
|
|
|
|
for (j = 0; j < code + 1; j++) {
|
|
|
|
pix = bytestream2_get_byte(gbc);
|
2017-02-27 10:39:36 +00:00
|
|
|
if (pos < offset)
|
|
|
|
out[pos++] = (pix & 0xF0) >> 4;
|
|
|
|
if (pos < offset)
|
|
|
|
out[pos++] = pix & 0xF;
|
2017-02-21 18:45:44 +00:00
|
|
|
}
|
|
|
|
left -= 1 + (code + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
outdata += p->linesize[0];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-21 11:17:21 +00:00
|
|
|
static int decode_rle16(AVCodecContext *avctx, AVFrame *p, GetByteContext *gbc)
|
|
|
|
{
|
2017-02-21 18:16:35 +00:00
|
|
|
int offset = avctx->width;
|
2017-02-21 11:17:21 +00:00
|
|
|
uint8_t *outdata = p->data[0];
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < avctx->height; i++) {
|
|
|
|
int size, left, code, pix;
|
|
|
|
uint16_t *out = (uint16_t *)outdata;
|
|
|
|
int pos = 0;
|
|
|
|
|
|
|
|
/* size of packed line */
|
|
|
|
size = left = bytestream2_get_be16(gbc);
|
|
|
|
if (bytestream2_get_bytes_left(gbc) < size)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
/* decode line */
|
|
|
|
while (left > 0) {
|
|
|
|
code = bytestream2_get_byte(gbc);
|
|
|
|
if (code & 0x80 ) { /* run */
|
|
|
|
pix = bytestream2_get_be16(gbc);
|
|
|
|
for (j = 0; j < 257 - code; j++) {
|
2017-02-27 10:24:43 +00:00
|
|
|
if (pos < offset) {
|
|
|
|
out[pos++] = pix;
|
2017-02-21 11:17:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
left -= 3;
|
|
|
|
} else { /* copy */
|
|
|
|
for (j = 0; j < code + 1; j++) {
|
2017-02-27 10:24:43 +00:00
|
|
|
if (pos < offset) {
|
|
|
|
out[pos++] = bytestream2_get_be16(gbc);
|
|
|
|
} else {
|
|
|
|
bytestream2_skip(gbc, 2);
|
2017-02-21 11:17:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
left -= 1 + (code + 1) * 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
outdata += p->linesize[0];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-18 16:25:20 +00:00
|
|
|
static int decode_rle(AVCodecContext *avctx, AVFrame *p, GetByteContext *gbc,
|
|
|
|
int step)
|
2015-04-18 16:25:19 +00:00
|
|
|
{
|
2015-04-18 16:25:20 +00:00
|
|
|
int i, j;
|
|
|
|
int offset = avctx->width * step;
|
2015-04-18 16:25:19 +00:00
|
|
|
uint8_t *outdata = p->data[0];
|
2015-04-18 16:25:18 +00:00
|
|
|
|
2004-09-28 03:09:49 +00:00
|
|
|
for (i = 0; i < avctx->height; i++) {
|
|
|
|
int size, left, code, pix;
|
2015-04-18 16:25:18 +00:00
|
|
|
uint8_t *out = outdata;
|
2015-04-18 16:25:20 +00:00
|
|
|
int pos = 0;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2015-04-18 16:25:18 +00:00
|
|
|
/* size of packed line */
|
2015-04-18 16:25:19 +00:00
|
|
|
size = left = bytestream2_get_be16(gbc);
|
|
|
|
if (bytestream2_get_bytes_left(gbc) < size)
|
2011-09-29 22:05:46 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
2015-04-18 16:25:18 +00:00
|
|
|
/* decode line */
|
2004-09-28 03:09:49 +00:00
|
|
|
while (left > 0) {
|
2015-04-18 16:25:19 +00:00
|
|
|
code = bytestream2_get_byte(gbc);
|
2004-09-28 03:09:49 +00:00
|
|
|
if (code & 0x80 ) { /* run */
|
2015-04-18 16:25:19 +00:00
|
|
|
pix = bytestream2_get_byte(gbc);
|
2015-04-18 16:25:20 +00:00
|
|
|
for (j = 0; j < 257 - code; j++) {
|
2017-02-27 10:49:59 +00:00
|
|
|
if (pos < offset)
|
|
|
|
out[pos] = pix;
|
2015-04-18 16:25:20 +00:00
|
|
|
pos += step;
|
2017-02-27 10:49:59 +00:00
|
|
|
if (pos >= offset && step > 1) {
|
2015-04-18 16:25:20 +00:00
|
|
|
pos -= offset;
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
}
|
2012-11-19 09:40:03 +00:00
|
|
|
left -= 2;
|
2004-09-28 03:09:49 +00:00
|
|
|
} else { /* copy */
|
2015-04-18 16:25:20 +00:00
|
|
|
for (j = 0; j < code + 1; j++) {
|
2017-02-27 11:04:15 +00:00
|
|
|
pix = bytestream2_get_byte(gbc);
|
2017-02-27 10:49:59 +00:00
|
|
|
if (pos < offset)
|
2017-02-27 11:04:15 +00:00
|
|
|
out[pos] = pix;
|
2015-04-18 16:25:20 +00:00
|
|
|
pos += step;
|
2017-02-27 10:49:59 +00:00
|
|
|
if (pos >= offset && step > 1) {
|
2015-04-18 16:25:20 +00:00
|
|
|
pos -= offset;
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
}
|
2012-11-19 09:40:03 +00:00
|
|
|
left -= 2 + code;
|
2004-09-28 03:09:49 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-21 20:34:46 +00:00
|
|
|
outdata += p->linesize[0];
|
2004-09-28 03:09:49 +00:00
|
|
|
}
|
2015-04-18 16:25:19 +00:00
|
|
|
return 0;
|
2004-09-28 03:09:49 +00:00
|
|
|
}
|
|
|
|
|
2015-05-14 10:14:52 +00:00
|
|
|
static int check_header(const char *buf, int buf_size)
|
|
|
|
{
|
|
|
|
unsigned w, h, v0, v1;
|
|
|
|
|
|
|
|
if (buf_size < 40)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
w = AV_RB16(buf+6);
|
|
|
|
h = AV_RB16(buf+8);
|
|
|
|
v0 = AV_RB16(buf+10);
|
|
|
|
v1 = AV_RB16(buf+12);
|
|
|
|
|
|
|
|
if (!w || !h)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (v0 == 0x1101)
|
|
|
|
return 1;
|
|
|
|
if (v0 == 0x0011 && v1 == 0x02FF)
|
|
|
|
return 2;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-18 16:25:19 +00:00
|
|
|
static int decode_frame(AVCodecContext *avctx,
|
|
|
|
void *data, int *got_frame,
|
|
|
|
AVPacket *avpkt)
|
2012-11-19 09:40:03 +00:00
|
|
|
{
|
2015-04-18 16:25:19 +00:00
|
|
|
AVFrame * const p = data;
|
|
|
|
GetByteContext gbc;
|
|
|
|
int colors;
|
2017-02-23 14:20:24 +00:00
|
|
|
int w, h, ret;
|
2015-05-14 10:25:05 +00:00
|
|
|
int ver;
|
2004-09-28 03:09:49 +00:00
|
|
|
|
2015-04-18 16:25:19 +00:00
|
|
|
bytestream2_init(&gbc, avpkt->data, avpkt->size);
|
2015-05-14 10:14:52 +00:00
|
|
|
if ( bytestream2_get_bytes_left(&gbc) >= 552
|
|
|
|
&& check_header(gbc.buffer + 512, bytestream2_get_bytes_left(&gbc) - 512)
|
|
|
|
)
|
2015-05-11 19:11:04 +00:00
|
|
|
bytestream2_skip(&gbc, 512);
|
|
|
|
|
2015-05-14 10:25:05 +00:00
|
|
|
ver = check_header(gbc.buffer, bytestream2_get_bytes_left(&gbc));
|
|
|
|
|
2015-04-18 16:25:19 +00:00
|
|
|
/* smallest PICT header */
|
|
|
|
if (bytestream2_get_bytes_left(&gbc) < 40) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Frame is too small %d\n",
|
|
|
|
bytestream2_get_bytes_left(&gbc));
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
bytestream2_skip(&gbc, 6);
|
|
|
|
h = bytestream2_get_be16(&gbc);
|
|
|
|
w = bytestream2_get_be16(&gbc);
|
|
|
|
|
|
|
|
ret = ff_set_dimensions(avctx, w, h);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* version 1 is identified by 0x1101
|
|
|
|
* it uses byte-aligned opcodes rather than word-aligned */
|
2015-05-14 10:25:05 +00:00
|
|
|
if (ver == 1) {
|
2015-04-18 16:25:19 +00:00
|
|
|
avpriv_request_sample(avctx, "QuickDraw version 1");
|
|
|
|
return AVERROR_PATCHWELCOME;
|
2015-05-14 10:25:05 +00:00
|
|
|
} else if (ver != 2) {
|
|
|
|
avpriv_request_sample(avctx, "QuickDraw version unknown (%X)", bytestream2_get_be32(&gbc));
|
|
|
|
return AVERROR_PATCHWELCOME;
|
2015-04-18 16:25:19 +00:00
|
|
|
}
|
|
|
|
|
2015-05-14 10:25:05 +00:00
|
|
|
bytestream2_skip(&gbc, 4+26);
|
2015-04-18 16:25:19 +00:00
|
|
|
|
|
|
|
while (bytestream2_get_bytes_left(&gbc) >= 4) {
|
|
|
|
int bppcnt, bpp;
|
2015-04-18 16:25:20 +00:00
|
|
|
int rowbytes, pack_type;
|
2015-04-18 16:25:19 +00:00
|
|
|
int opcode = bytestream2_get_be16(&gbc);
|
|
|
|
|
|
|
|
switch(opcode) {
|
2017-02-22 14:32:26 +00:00
|
|
|
case CLIP:
|
2017-02-23 14:20:24 +00:00
|
|
|
bytestream2_skip(&gbc, 10);
|
2017-02-22 14:32:26 +00:00
|
|
|
break;
|
2015-04-18 16:25:19 +00:00
|
|
|
case PACKBITSRECT:
|
|
|
|
case PACKBITSRGN:
|
|
|
|
av_log(avctx, AV_LOG_DEBUG, "Parsing Packbit opcode\n");
|
|
|
|
|
|
|
|
bytestream2_skip(&gbc, 30);
|
|
|
|
bppcnt = bytestream2_get_be16(&gbc); /* cmpCount */
|
|
|
|
bpp = bytestream2_get_be16(&gbc); /* cmpSize */
|
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_DEBUG, "bppcount %d bpp %d\n", bppcnt, bpp);
|
|
|
|
if (bppcnt == 1 && bpp == 8) {
|
|
|
|
avctx->pix_fmt = AV_PIX_FMT_PAL8;
|
2017-02-21 18:45:44 +00:00
|
|
|
} else if (bppcnt == 1 && (bpp == 4 || bpp == 2)) {
|
|
|
|
avctx->pix_fmt = AV_PIX_FMT_PAL8;
|
2017-02-21 11:17:21 +00:00
|
|
|
} else if (bppcnt == 3 && bpp == 5) {
|
|
|
|
avctx->pix_fmt = AV_PIX_FMT_RGB555;
|
2015-04-18 16:25:19 +00:00
|
|
|
} else {
|
|
|
|
av_log(avctx, AV_LOG_ERROR,
|
|
|
|
"Invalid pixel format (bppcnt %d bpp %d) in Packbit\n",
|
|
|
|
bppcnt, bpp);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* jump to palette */
|
|
|
|
bytestream2_skip(&gbc, 18);
|
|
|
|
colors = bytestream2_get_be16(&gbc);
|
|
|
|
|
|
|
|
if (colors < 0 || colors > 256) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR,
|
|
|
|
"Error color count - %i(0x%X)\n", colors, colors);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
if (bytestream2_get_bytes_left(&gbc) < (colors + 1) * 8) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Palette is too small %d\n",
|
|
|
|
bytestream2_get_bytes_left(&gbc));
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2015-05-06 18:32:52 +00:00
|
|
|
if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
|
2015-04-18 16:25:19 +00:00
|
|
|
return ret;
|
|
|
|
|
2017-06-04 19:37:47 +00:00
|
|
|
ret = parse_palette(avctx, &gbc, (uint32_t *)p->data[1], colors);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2015-04-18 16:25:19 +00:00
|
|
|
p->palette_has_changed = 1;
|
|
|
|
|
|
|
|
/* jump to image data */
|
|
|
|
bytestream2_skip(&gbc, 18);
|
|
|
|
|
|
|
|
if (opcode == PACKBITSRGN) {
|
|
|
|
bytestream2_skip(&gbc, 2 + 8); /* size + rect */
|
|
|
|
avpriv_report_missing_feature(avctx, "Packbit mask region");
|
|
|
|
}
|
|
|
|
|
2017-02-21 11:17:21 +00:00
|
|
|
if (avctx->pix_fmt == AV_PIX_FMT_RGB555)
|
|
|
|
ret = decode_rle16(avctx, p, &gbc);
|
2017-02-21 23:21:52 +00:00
|
|
|
else if (bpp == 2)
|
2017-02-21 18:45:44 +00:00
|
|
|
ret = decode_rle_bpp2(avctx, p, &gbc);
|
2017-02-21 23:21:52 +00:00
|
|
|
else if (bpp == 4)
|
2017-02-21 18:45:44 +00:00
|
|
|
ret = decode_rle_bpp4(avctx, p, &gbc);
|
2017-02-21 11:17:21 +00:00
|
|
|
else
|
|
|
|
ret = decode_rle(avctx, p, &gbc, bppcnt);
|
2015-04-18 16:25:20 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
*got_frame = 1;
|
|
|
|
break;
|
|
|
|
case DIRECTBITSRECT:
|
|
|
|
case DIRECTBITSRGN:
|
|
|
|
av_log(avctx, AV_LOG_DEBUG, "Parsing Directbit opcode\n");
|
|
|
|
|
|
|
|
bytestream2_skip(&gbc, 4);
|
|
|
|
rowbytes = bytestream2_get_be16(&gbc) & 0x3FFF;
|
|
|
|
if (rowbytes <= 250) {
|
|
|
|
avpriv_report_missing_feature(avctx, "Short rowbytes");
|
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
}
|
|
|
|
|
2017-02-23 14:20:24 +00:00
|
|
|
bytestream2_skip(&gbc, 4);
|
|
|
|
h = bytestream2_get_be16(&gbc);
|
|
|
|
w = bytestream2_get_be16(&gbc);
|
|
|
|
bytestream2_skip(&gbc, 2);
|
|
|
|
|
|
|
|
ret = ff_set_dimensions(avctx, w, h);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2015-04-18 16:25:20 +00:00
|
|
|
pack_type = bytestream2_get_be16(&gbc);
|
|
|
|
|
|
|
|
bytestream2_skip(&gbc, 16);
|
|
|
|
bppcnt = bytestream2_get_be16(&gbc); /* cmpCount */
|
|
|
|
bpp = bytestream2_get_be16(&gbc); /* cmpSize */
|
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_DEBUG, "bppcount %d bpp %d\n", bppcnt, bpp);
|
|
|
|
if (bppcnt == 3 && bpp == 8) {
|
|
|
|
avctx->pix_fmt = AV_PIX_FMT_RGB24;
|
2017-03-22 19:34:28 +00:00
|
|
|
} else if (bppcnt == 3 && bpp == 5 || bppcnt == 2 && bpp == 8) {
|
2017-02-21 11:17:21 +00:00
|
|
|
avctx->pix_fmt = AV_PIX_FMT_RGB555;
|
2015-04-18 16:25:20 +00:00
|
|
|
} else if (bppcnt == 4 && bpp == 8) {
|
|
|
|
avctx->pix_fmt = AV_PIX_FMT_ARGB;
|
|
|
|
} else {
|
|
|
|
av_log(avctx, AV_LOG_ERROR,
|
|
|
|
"Invalid pixel format (bppcnt %d bpp %d) in Directbit\n",
|
|
|
|
bppcnt, bpp);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set packing when default is selected */
|
|
|
|
if (pack_type == 0)
|
|
|
|
pack_type = bppcnt;
|
|
|
|
|
|
|
|
if (pack_type != 3 && pack_type != 4) {
|
|
|
|
avpriv_request_sample(avctx, "Pack type %d", pack_type);
|
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
}
|
2016-04-08 07:40:32 +00:00
|
|
|
if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
|
2015-04-18 16:25:20 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* jump to data */
|
|
|
|
bytestream2_skip(&gbc, 30);
|
|
|
|
|
|
|
|
if (opcode == DIRECTBITSRGN) {
|
|
|
|
bytestream2_skip(&gbc, 2 + 8); /* size + rect */
|
|
|
|
avpriv_report_missing_feature(avctx, "DirectBit mask region");
|
|
|
|
}
|
|
|
|
|
2017-02-21 11:17:21 +00:00
|
|
|
if (avctx->pix_fmt == AV_PIX_FMT_RGB555)
|
|
|
|
ret = decode_rle16(avctx, p, &gbc);
|
|
|
|
else
|
|
|
|
ret = decode_rle(avctx, p, &gbc, bppcnt);
|
2015-04-18 16:25:19 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
*got_frame = 1;
|
|
|
|
break;
|
2017-01-13 19:18:36 +00:00
|
|
|
case LONGCOMMENT:
|
|
|
|
bytestream2_get_be16(&gbc);
|
|
|
|
bytestream2_skip(&gbc, bytestream2_get_be16(&gbc));
|
|
|
|
break;
|
2015-04-18 16:25:19 +00:00
|
|
|
default:
|
|
|
|
av_log(avctx, AV_LOG_TRACE, "Unknown 0x%04X opcode\n", opcode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* exit the loop when a known pixel block has been found */
|
|
|
|
if (*got_frame) {
|
|
|
|
int eop, trail;
|
|
|
|
|
|
|
|
/* re-align to a word */
|
|
|
|
bytestream2_skip(&gbc, bytestream2_get_bytes_left(&gbc) % 2);
|
|
|
|
|
|
|
|
eop = bytestream2_get_be16(&gbc);
|
|
|
|
trail = bytestream2_get_bytes_left(&gbc);
|
|
|
|
if (eop != EOP)
|
|
|
|
av_log(avctx, AV_LOG_WARNING,
|
|
|
|
"Missing end of picture opcode (found 0x%04X)\n", eop);
|
|
|
|
if (trail)
|
|
|
|
av_log(avctx, AV_LOG_WARNING, "Got %d trailing bytes\n", trail);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*got_frame) {
|
|
|
|
p->pict_type = AV_PICTURE_TYPE_I;
|
|
|
|
p->key_frame = 1;
|
|
|
|
|
|
|
|
return avpkt->size;
|
|
|
|
} else {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Frame contained no usable data\n");
|
|
|
|
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2004-09-28 03:09:49 +00:00
|
|
|
}
|
|
|
|
|
2011-01-25 21:40:11 +00:00
|
|
|
AVCodec ff_qdraw_decoder = {
|
2011-07-17 10:54:31 +00:00
|
|
|
.name = "qdraw",
|
2013-10-03 20:57:53 +00:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("Apple QuickDraw"),
|
2011-07-17 10:54:31 +00:00
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
2012-08-05 09:11:04 +00:00
|
|
|
.id = AV_CODEC_ID_QDRAW,
|
2011-07-17 10:54:31 +00:00
|
|
|
.decode = decode_frame,
|
2015-07-07 00:41:27 +00:00
|
|
|
.capabilities = AV_CODEC_CAP_DR1,
|
2004-09-28 03:09:49 +00:00
|
|
|
};
|