Merge commit '70daeacd6ef8b354dd7d2d77ad393831a5bbf033'
* commit '70daeacd6ef8b354dd7d2d77ad393831a5bbf033': PAF demuxer and decoder Conflicts: Changelog doc/general.texi libavcodec/avcodec.h libavcodec/codec_desc.c libavcodec/paf.c libavcodec/version.h libavformat/Makefile libavformat/allformats.c libavformat/paf.c libavformat/version.h See: 7de4a16508cb9bd2d40855f7114dea14329ef62a, and others Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
commit
16ddc58bd7
@ -288,6 +288,7 @@ enum AVCodecID {
|
|||||||
AV_CODEC_ID_FIC,
|
AV_CODEC_ID_FIC,
|
||||||
AV_CODEC_ID_ALIAS_PIX,
|
AV_CODEC_ID_ALIAS_PIX,
|
||||||
AV_CODEC_ID_BRENDER_PIX_DEPRECATED,
|
AV_CODEC_ID_BRENDER_PIX_DEPRECATED,
|
||||||
|
AV_CODEC_ID_PAF_VIDEO_DEPRECATED,
|
||||||
|
|
||||||
AV_CODEC_ID_BRENDER_PIX= MKBETAG('B','P','I','X'),
|
AV_CODEC_ID_BRENDER_PIX= MKBETAG('B','P','I','X'),
|
||||||
AV_CODEC_ID_Y41P = MKBETAG('Y','4','1','P'),
|
AV_CODEC_ID_Y41P = MKBETAG('Y','4','1','P'),
|
||||||
@ -474,6 +475,7 @@ enum AVCodecID {
|
|||||||
AV_CODEC_ID_COMFORT_NOISE,
|
AV_CODEC_ID_COMFORT_NOISE,
|
||||||
AV_CODEC_ID_TAK_DEPRECATED,
|
AV_CODEC_ID_TAK_DEPRECATED,
|
||||||
AV_CODEC_ID_METASOUND,
|
AV_CODEC_ID_METASOUND,
|
||||||
|
AV_CODEC_ID_PAF_AUDIO_DEPRECATED,
|
||||||
AV_CODEC_ID_FFWAVESYNTH = MKBETAG('F','F','W','S'),
|
AV_CODEC_ID_FFWAVESYNTH = MKBETAG('F','F','W','S'),
|
||||||
AV_CODEC_ID_SONIC = MKBETAG('S','O','N','C'),
|
AV_CODEC_ID_SONIC = MKBETAG('S','O','N','C'),
|
||||||
AV_CODEC_ID_SONIC_LS = MKBETAG('S','O','N','L'),
|
AV_CODEC_ID_SONIC_LS = MKBETAG('S','O','N','L'),
|
||||||
|
@ -1173,13 +1173,6 @@ static const AVCodecDescriptor codec_descriptors[] = {
|
|||||||
.long_name = NULL_IF_CONFIG_SMALL("LucasArts SMUSH video"),
|
.long_name = NULL_IF_CONFIG_SMALL("LucasArts SMUSH video"),
|
||||||
.props = AV_CODEC_PROP_LOSSY,
|
.props = AV_CODEC_PROP_LOSSY,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
.id = AV_CODEC_ID_PAF_VIDEO,
|
|
||||||
.type = AVMEDIA_TYPE_VIDEO,
|
|
||||||
.name = "paf_video",
|
|
||||||
.long_name = NULL_IF_CONFIG_SMALL("Amazing Studio Packed Animation File Video"),
|
|
||||||
.props = AV_CODEC_PROP_LOSSY,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
.id = AV_CODEC_ID_AVRN,
|
.id = AV_CODEC_ID_AVRN,
|
||||||
.type = AVMEDIA_TYPE_VIDEO,
|
.type = AVMEDIA_TYPE_VIDEO,
|
||||||
@ -1234,6 +1227,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
|
|||||||
.long_name = NULL_IF_CONFIG_SMALL("Mirillis FIC"),
|
.long_name = NULL_IF_CONFIG_SMALL("Mirillis FIC"),
|
||||||
.props = AV_CODEC_PROP_LOSSY,
|
.props = AV_CODEC_PROP_LOSSY,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.id = AV_CODEC_ID_PAF_VIDEO,
|
||||||
|
.type = AVMEDIA_TYPE_VIDEO,
|
||||||
|
.name = "paf_video",
|
||||||
|
.long_name = NULL_IF_CONFIG_SMALL("Amazing Studio Packed Animation File Video"),
|
||||||
|
.props = AV_CODEC_PROP_LOSSY,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.id = AV_CODEC_ID_VP7,
|
.id = AV_CODEC_ID_VP7,
|
||||||
.type = AVMEDIA_TYPE_VIDEO,
|
.type = AVMEDIA_TYPE_VIDEO,
|
||||||
@ -2411,13 +2411,6 @@ static const AVCodecDescriptor codec_descriptors[] = {
|
|||||||
.name = "sonicls",
|
.name = "sonicls",
|
||||||
.long_name = NULL_IF_CONFIG_SMALL("Sonic lossless"),
|
.long_name = NULL_IF_CONFIG_SMALL("Sonic lossless"),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
.id = AV_CODEC_ID_PAF_AUDIO,
|
|
||||||
.type = AVMEDIA_TYPE_AUDIO,
|
|
||||||
.name = "paf_audio",
|
|
||||||
.long_name = NULL_IF_CONFIG_SMALL("Amazing Studio Packed Animation File Audio"),
|
|
||||||
.props = AV_CODEC_PROP_LOSSY,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
.id = AV_CODEC_ID_OPUS,
|
.id = AV_CODEC_ID_OPUS,
|
||||||
.type = AVMEDIA_TYPE_AUDIO,
|
.type = AVMEDIA_TYPE_AUDIO,
|
||||||
@ -2446,6 +2439,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
|
|||||||
.long_name = NULL_IF_CONFIG_SMALL("Voxware MetaSound"),
|
.long_name = NULL_IF_CONFIG_SMALL("Voxware MetaSound"),
|
||||||
.props = AV_CODEC_PROP_LOSSY,
|
.props = AV_CODEC_PROP_LOSSY,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.id = AV_CODEC_ID_PAF_AUDIO,
|
||||||
|
.type = AVMEDIA_TYPE_AUDIO,
|
||||||
|
.name = "paf_audio",
|
||||||
|
.long_name = NULL_IF_CONFIG_SMALL("Amazing Studio Packed Animation File Audio"),
|
||||||
|
.props = AV_CODEC_PROP_LOSSY,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.id = AV_CODEC_ID_EVRC,
|
.id = AV_CODEC_ID_EVRC,
|
||||||
.type = AVMEDIA_TYPE_AUDIO,
|
.type = AVMEDIA_TYPE_AUDIO,
|
||||||
|
223
libavcodec/paf.c
223
libavcodec/paf.c
@ -19,16 +19,17 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "libavutil/imgutils.h"
|
||||||
#include "libavutil/intreadwrite.h"
|
#include "libavutil/intreadwrite.h"
|
||||||
|
|
||||||
#include "libavcodec/paf.h"
|
#include "libavcodec/paf.h"
|
||||||
#include "bytestream.h"
|
|
||||||
#include "avcodec.h"
|
#include "avcodec.h"
|
||||||
|
#include "bytestream.h"
|
||||||
#include "copy_block.h"
|
#include "copy_block.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "mathops.h"
|
||||||
|
|
||||||
|
static const uint8_t block_sequences[16][8] = {
|
||||||
static const uint8_t block_sequences[16][8] =
|
|
||||||
{
|
|
||||||
{ 0, 0, 0, 0, 0, 0, 0, 0 },
|
{ 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||||
{ 2, 0, 0, 0, 0, 0, 0, 0 },
|
{ 2, 0, 0, 0, 0, 0, 0, 0 },
|
||||||
{ 5, 7, 0, 0, 0, 0, 0, 0 },
|
{ 5, 7, 0, 0, 0, 0, 0, 0 },
|
||||||
@ -44,13 +45,16 @@ static const uint8_t block_sequences[16][8] =
|
|||||||
{ 2, 4, 5, 7, 0, 0, 0, 0 },
|
{ 2, 4, 5, 7, 0, 0, 0, 0 },
|
||||||
{ 2, 4, 5, 0, 0, 0, 0, 0 },
|
{ 2, 4, 5, 0, 0, 0, 0, 0 },
|
||||||
{ 2, 4, 6, 0, 0, 0, 0, 0 },
|
{ 2, 4, 6, 0, 0, 0, 0, 0 },
|
||||||
{ 2, 4, 5, 7, 5, 7, 0, 0 }
|
{ 2, 4, 5, 7, 5, 7, 0, 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct PAFVideoDecContext {
|
typedef struct PAFVideoDecContext {
|
||||||
AVFrame *pic;
|
AVFrame *pic;
|
||||||
GetByteContext gb;
|
GetByteContext gb;
|
||||||
|
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
|
||||||
int current_frame;
|
int current_frame;
|
||||||
uint8_t *frame[4];
|
uint8_t *frame[4];
|
||||||
int frame_size;
|
int frame_size;
|
||||||
@ -59,7 +63,7 @@ typedef struct PAFVideoDecContext {
|
|||||||
uint8_t *opcodes;
|
uint8_t *opcodes;
|
||||||
} PAFVideoDecContext;
|
} PAFVideoDecContext;
|
||||||
|
|
||||||
static av_cold int paf_vid_close(AVCodecContext *avctx)
|
static av_cold int paf_video_close(AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
PAFVideoDecContext *c = avctx->priv_data;
|
PAFVideoDecContext *c = avctx->priv_data;
|
||||||
int i;
|
int i;
|
||||||
@ -72,13 +76,18 @@ static av_cold int paf_vid_close(AVCodecContext *avctx)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold int paf_vid_init(AVCodecContext *avctx)
|
static av_cold int paf_video_init(AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
PAFVideoDecContext *c = avctx->priv_data;
|
PAFVideoDecContext *c = avctx->priv_data;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
c->width = avctx->width;
|
||||||
|
c->height = avctx->height;
|
||||||
|
|
||||||
if (avctx->height & 3 || avctx->width & 3) {
|
if (avctx->height & 3 || avctx->width & 3) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "width and height must be multiplies of 4\n");
|
av_log(avctx, AV_LOG_ERROR,
|
||||||
|
"width %d and height %d must be multiplie of 4.\n",
|
||||||
|
avctx->width, avctx->height);
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,12 +97,12 @@ static av_cold int paf_vid_init(AVCodecContext *avctx)
|
|||||||
if (!c->pic)
|
if (!c->pic)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
c->frame_size = FFALIGN(avctx->height, 256) * avctx->width;
|
c->frame_size = avctx->width * FFALIGN(avctx->height, 256);
|
||||||
c->video_size = avctx->height * avctx->width;
|
c->video_size = avctx->width * avctx->height;
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
c->frame[i] = av_mallocz(c->frame_size);
|
c->frame[i] = av_mallocz(c->frame_size);
|
||||||
if (!c->frame[i]) {
|
if (!c->frame[i]) {
|
||||||
paf_vid_close(avctx);
|
paf_video_close(avctx);
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,58 +110,59 @@ static av_cold int paf_vid_init(AVCodecContext *avctx)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_video_page_offset(AVCodecContext *avctx, uint8_t a, uint8_t b)
|
static void read4x4block(PAFVideoDecContext *c, uint8_t *dst, int width)
|
||||||
{
|
{
|
||||||
int x, y;
|
|
||||||
|
|
||||||
x = b & 0x7F;
|
|
||||||
y = ((a & 0x3F) << 1) | (b >> 7 & 1);
|
|
||||||
|
|
||||||
return y * 2 * avctx->width + x * 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void copy4h(AVCodecContext *avctx, uint8_t *dst)
|
|
||||||
{
|
|
||||||
PAFVideoDecContext *c = avctx->priv_data;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
bytestream2_get_buffer(&c->gb, dst, 4);
|
bytestream2_get_buffer(&c->gb, dst, 4);
|
||||||
dst += avctx->width;
|
dst += width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void copy_color_mask(AVCodecContext *avctx, uint8_t mask, uint8_t *dst, uint8_t color)
|
static void copy_color_mask(uint8_t *dst, int width, uint8_t mask, uint8_t color)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
if ((mask >> 4) & (1 << (3 - i)))
|
if (mask & (1 << 7 - i))
|
||||||
dst[i] = color;
|
dst[i] = color;
|
||||||
if ((mask & 15) & (1 << (3 - i)))
|
if (mask & (1 << 3 - i))
|
||||||
dst[avctx->width + i] = color;
|
dst[width + i] = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void copy_src_mask(AVCodecContext *avctx, uint8_t mask, uint8_t *dst, const uint8_t *src)
|
static void copy_src_mask(uint8_t *dst, int width, uint8_t mask, const uint8_t *src)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
if ((mask >> 4) & (1 << (3 - i)))
|
if (mask & (1 << 7 - i))
|
||||||
dst[i] = src[i];
|
dst[i] = src[i];
|
||||||
if ((mask & 15) & (1 << (3 - i)))
|
if (mask & (1 << 3 - i))
|
||||||
dst[avctx->width + i] = src[avctx->width + i];
|
dst[width + i] = src[width + i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int decode_0(AVCodecContext *avctx, uint8_t code, uint8_t *pkt)
|
static void set_src_position(PAFVideoDecContext *c,
|
||||||
|
const uint8_t **p,
|
||||||
|
const uint8_t **pend)
|
||||||
|
{
|
||||||
|
int val = bytestream2_get_be16(&c->gb);
|
||||||
|
int page = val >> 14;
|
||||||
|
int x = (val & 0x7F);
|
||||||
|
int y = ((val >> 7) & 0x7F);
|
||||||
|
|
||||||
|
*p = c->frame[page] + x * 2 + y * 2 * c->width;
|
||||||
|
*pend = c->frame[page] + c->frame_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int decode_0(PAFVideoDecContext *c, uint8_t *pkt, uint8_t code)
|
||||||
{
|
{
|
||||||
PAFVideoDecContext *c = avctx->priv_data;
|
|
||||||
uint32_t opcode_size, offset;
|
uint32_t opcode_size, offset;
|
||||||
uint8_t *dst, *dend, mask = 0, color = 0, a, b, p;
|
uint8_t *dst, *dend, mask = 0, color = 0;
|
||||||
const uint8_t *src, *send, *opcodes;
|
const uint8_t *src, *send, *opcodes;
|
||||||
int i, j, x = 0;
|
int i, j, op = 0;
|
||||||
|
|
||||||
i = bytestream2_get_byte(&c->gb);
|
i = bytestream2_get_byte(&c->gb);
|
||||||
if (i) {
|
if (i) {
|
||||||
@ -164,21 +174,22 @@ static int decode_0(AVCodecContext *avctx, uint8_t code, uint8_t *pkt)
|
|||||||
bytestream2_skip(&c->gb, 4 - align);
|
bytestream2_skip(&c->gb, 4 - align);
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
a = bytestream2_get_byte(&c->gb);
|
int page, val, x, y;
|
||||||
b = bytestream2_get_byte(&c->gb);
|
val = bytestream2_get_be16(&c->gb);
|
||||||
p = (a & 0xC0) >> 6;
|
page = val >> 14;
|
||||||
dst = c->frame[p] + get_video_page_offset(avctx, a, b);
|
x = (val & 0x7F) * 2;
|
||||||
dend = c->frame[p] + c->frame_size;
|
y = ((val >> 7) & 0x7F) * 2;
|
||||||
offset = (b & 0x7F) * 2;
|
dst = c->frame[page] + x + y * c->width;
|
||||||
|
dend = c->frame[page] + c->frame_size;
|
||||||
|
offset = (x & 0x7F) * 2;
|
||||||
j = bytestream2_get_le16(&c->gb) + offset;
|
j = bytestream2_get_le16(&c->gb) + offset;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
offset++;
|
offset++;
|
||||||
if (dst + 3 * avctx->width + 4 > dend)
|
if (dst + 3 * c->width + 4 > dend)
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
copy4h(avctx, dst);
|
read4x4block(c, dst, c->width);
|
||||||
if ((offset & 0x3F) == 0)
|
if ((offset & 0x3F) == 0)
|
||||||
dst += avctx->width * 3;
|
dst += c->width * 3;
|
||||||
dst += 4;
|
dst += 4;
|
||||||
} while (offset < j);
|
} while (offset < j);
|
||||||
} while (--i);
|
} while (--i);
|
||||||
@ -187,18 +198,14 @@ static int decode_0(AVCodecContext *avctx, uint8_t code, uint8_t *pkt)
|
|||||||
dst = c->frame[c->current_frame];
|
dst = c->frame[c->current_frame];
|
||||||
dend = c->frame[c->current_frame] + c->frame_size;
|
dend = c->frame[c->current_frame] + c->frame_size;
|
||||||
do {
|
do {
|
||||||
a = bytestream2_get_byte(&c->gb);
|
set_src_position(c, &src, &send);
|
||||||
b = bytestream2_get_byte(&c->gb);
|
if ((src + 3 * c->width + 4 > send) ||
|
||||||
p = (a & 0xC0) >> 6;
|
(dst + 3 * c->width + 4 > dend))
|
||||||
src = c->frame[p] + get_video_page_offset(avctx, a, b);
|
|
||||||
send = c->frame[p] + c->frame_size;
|
|
||||||
if ((src + 3 * avctx->width + 4 > send) ||
|
|
||||||
(dst + 3 * avctx->width + 4 > dend))
|
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
copy_block4(dst, src, avctx->width, avctx->width, 4);
|
copy_block4(dst, src, c->width, c->width, 4);
|
||||||
i++;
|
i++;
|
||||||
if ((i & 0x3F) == 0)
|
if ((i & 0x3F) == 0)
|
||||||
dst += avctx->width * 3;
|
dst += c->width * 3;
|
||||||
dst += 4;
|
dst += 4;
|
||||||
} while (i < c->video_size / 16);
|
} while (i < c->video_size / 16);
|
||||||
|
|
||||||
@ -213,22 +220,20 @@ static int decode_0(AVCodecContext *avctx, uint8_t code, uint8_t *pkt)
|
|||||||
|
|
||||||
dst = c->frame[c->current_frame];
|
dst = c->frame[c->current_frame];
|
||||||
|
|
||||||
for (i = 0; i < avctx->height; i += 4, dst += avctx->width * 3) {
|
for (i = 0; i < c->height; i += 4, dst += c->width * 3)
|
||||||
for (j = 0; j < avctx->width; j += 4, dst += 4) {
|
for (j = 0; j < c->width; j += 4, dst += 4) {
|
||||||
int opcode, k = 0;
|
int opcode, k = 0;
|
||||||
|
if (op > opcode_size)
|
||||||
if (x > opcode_size)
|
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
if (j & 4) {
|
if (j & 4) {
|
||||||
opcode = opcodes[x] & 15;
|
opcode = opcodes[op] & 15;
|
||||||
x++;
|
op++;
|
||||||
} else {
|
} else {
|
||||||
opcode = opcodes[x] >> 4;
|
opcode = opcodes[op] >> 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (block_sequences[opcode][k]) {
|
while (block_sequences[opcode][k]) {
|
||||||
|
offset = c->width * 2;
|
||||||
offset = avctx->width * 2;
|
|
||||||
code = block_sequences[opcode][k++];
|
code = block_sequences[opcode][k++];
|
||||||
|
|
||||||
switch (code) {
|
switch (code) {
|
||||||
@ -238,35 +243,30 @@ static int decode_0(AVCodecContext *avctx, uint8_t code, uint8_t *pkt)
|
|||||||
color = bytestream2_get_byte(&c->gb);
|
color = bytestream2_get_byte(&c->gb);
|
||||||
case 4:
|
case 4:
|
||||||
mask = bytestream2_get_byte(&c->gb);
|
mask = bytestream2_get_byte(&c->gb);
|
||||||
copy_color_mask(avctx, mask, dst + offset, color);
|
copy_color_mask(dst + offset, c->width, mask, color);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
offset = 0;
|
offset = 0;
|
||||||
case 6:
|
case 6:
|
||||||
a = bytestream2_get_byte(&c->gb);
|
set_src_position(c, &src, &send);
|
||||||
b = bytestream2_get_byte(&c->gb);
|
|
||||||
p = (a & 0xC0) >> 6;
|
|
||||||
src = c->frame[p] + get_video_page_offset(avctx, a, b);
|
|
||||||
send = c->frame[p] + c->frame_size;
|
|
||||||
case 7:
|
case 7:
|
||||||
if (src + offset + avctx->width + 4 > send)
|
if (src + offset + c->width + 4 > send)
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
mask = bytestream2_get_byte(&c->gb);
|
mask = bytestream2_get_byte(&c->gb);
|
||||||
copy_src_mask(avctx, mask, dst + offset, src + offset);
|
copy_src_mask(dst + offset, c->width, mask, src + offset);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int paf_vid_decode(AVCodecContext *avctx, void *data,
|
static int paf_video_decode(AVCodecContext *avctx, void *data,
|
||||||
int *got_frame, AVPacket *pkt)
|
int *got_frame, AVPacket *pkt)
|
||||||
{
|
{
|
||||||
PAFVideoDecContext *c = avctx->priv_data;
|
PAFVideoDecContext *c = avctx->priv_data;
|
||||||
uint8_t code, *dst, *src, *end;
|
uint8_t code, *dst, *end;
|
||||||
int i, frame, ret;
|
int i, frame, ret;
|
||||||
|
|
||||||
if ((ret = ff_reget_buffer(avctx, c->pic)) < 0)
|
if ((ret = ff_reget_buffer(avctx, c->pic)) < 0)
|
||||||
@ -275,7 +275,7 @@ static int paf_vid_decode(AVCodecContext *avctx, void *data,
|
|||||||
bytestream2_init(&c->gb, pkt->data, pkt->size);
|
bytestream2_init(&c->gb, pkt->data, pkt->size);
|
||||||
|
|
||||||
code = bytestream2_get_byte(&c->gb);
|
code = bytestream2_get_byte(&c->gb);
|
||||||
if (code & 0x20) {
|
if (code & 0x20) { // frame is keyframe
|
||||||
for (i = 0; i < 4; i++)
|
for (i = 0; i < 4; i++)
|
||||||
memset(c->frame[i], 0, c->frame_size);
|
memset(c->frame[i], 0, c->frame_size);
|
||||||
|
|
||||||
@ -288,7 +288,7 @@ static int paf_vid_decode(AVCodecContext *avctx, void *data,
|
|||||||
c->pic->pict_type = AV_PICTURE_TYPE_P;
|
c->pic->pict_type = AV_PICTURE_TYPE_P;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code & 0x40) {
|
if (code & 0x40) { // palette update
|
||||||
uint32_t *out = (uint32_t *)c->pic->data[1];
|
uint32_t *out = (uint32_t *)c->pic->data[1];
|
||||||
int index, count;
|
int index, count;
|
||||||
|
|
||||||
@ -310,24 +310,32 @@ static int paf_vid_decode(AVCodecContext *avctx, void *data,
|
|||||||
g = g << 2 | g >> 4;
|
g = g << 2 | g >> 4;
|
||||||
b = bytestream2_get_byteu(&c->gb);
|
b = bytestream2_get_byteu(&c->gb);
|
||||||
b = b << 2 | b >> 4;
|
b = b << 2 | b >> 4;
|
||||||
*out++ = 0xFFU << 24 | r << 16 | g << 8 | b;
|
*out++ = (0xFFU << 24) | (r << 16) | (g << 8) | b;
|
||||||
}
|
}
|
||||||
c->pic->palette_has_changed = 1;
|
c->pic->palette_has_changed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (code & 0x0F) {
|
switch (code & 0x0F) {
|
||||||
case 0:
|
case 0:
|
||||||
if ((ret = decode_0(avctx, code, pkt->data)) < 0)
|
/* Block-based motion compensation using 4x4 blocks with either
|
||||||
|
* horizontal or vertical vectors; might incorporate VQ as well. */
|
||||||
|
if ((ret = decode_0(c, pkt->data, code)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
/* Uncompressed data. This mode specifies that (width * height) bytes
|
||||||
|
* should be copied directly from the encoded buffer into the output. */
|
||||||
dst = c->frame[c->current_frame];
|
dst = c->frame[c->current_frame];
|
||||||
|
// possibly chunk length data
|
||||||
bytestream2_skip(&c->gb, 2);
|
bytestream2_skip(&c->gb, 2);
|
||||||
if (bytestream2_get_bytes_left(&c->gb) < c->video_size)
|
if (bytestream2_get_bytes_left(&c->gb) < c->video_size)
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
bytestream2_get_bufferu(&c->gb, dst, c->video_size);
|
bytestream2_get_bufferu(&c->gb, dst, c->video_size);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
/* Copy reference frame: Consume the next byte in the stream as the
|
||||||
|
* reference frame (which should be 0, 1, 2, or 3, and should not be
|
||||||
|
* the same as the current frame number). */
|
||||||
frame = bytestream2_get_byte(&c->gb);
|
frame = bytestream2_get_byte(&c->gb);
|
||||||
if (frame > 3)
|
if (frame > 3)
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
@ -335,6 +343,7 @@ static int paf_vid_decode(AVCodecContext *avctx, void *data,
|
|||||||
memcpy(c->frame[c->current_frame], c->frame[frame], c->frame_size);
|
memcpy(c->frame[c->current_frame], c->frame[frame], c->frame_size);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
|
/* Run length encoding.*/
|
||||||
dst = c->frame[c->current_frame];
|
dst = c->frame[c->current_frame];
|
||||||
end = dst + c->video_size;
|
end = dst + c->video_size;
|
||||||
|
|
||||||
@ -364,13 +373,9 @@ static int paf_vid_decode(AVCodecContext *avctx, void *data,
|
|||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
dst = c->pic->data[0];
|
av_image_copy_plane(c->pic->data[0], c->pic->linesize[0],
|
||||||
src = c->frame[c->current_frame];
|
c->frame[c->current_frame], c->width,
|
||||||
for (i = 0; i < avctx->height; i++) {
|
c->width, c->height);
|
||||||
memcpy(dst, src, avctx->width);
|
|
||||||
dst += c->pic->linesize[0];
|
|
||||||
src += avctx->width;
|
|
||||||
}
|
|
||||||
|
|
||||||
c->current_frame = (c->current_frame + 1) & 3;
|
c->current_frame = (c->current_frame + 1) & 3;
|
||||||
if ((ret = av_frame_ref(data, c->pic)) < 0)
|
if ((ret = av_frame_ref(data, c->pic)) < 0)
|
||||||
@ -381,7 +386,7 @@ static int paf_vid_decode(AVCodecContext *avctx, void *data,
|
|||||||
return pkt->size;
|
return pkt->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold int paf_aud_init(AVCodecContext *avctx)
|
static av_cold int paf_audio_init(AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
if (avctx->channels != 2) {
|
if (avctx->channels != 2) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
|
av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
|
||||||
@ -394,14 +399,14 @@ static av_cold int paf_aud_init(AVCodecContext *avctx)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int paf_aud_decode(AVCodecContext *avctx, void *data,
|
static int paf_audio_decode(AVCodecContext *avctx, void *data,
|
||||||
int *got_frame_ptr, AVPacket *pkt)
|
int *got_frame, AVPacket *pkt)
|
||||||
{
|
{
|
||||||
AVFrame *frame = data;
|
AVFrame *frame = data;
|
||||||
uint8_t *buf = pkt->data;
|
|
||||||
int16_t *output_samples;
|
int16_t *output_samples;
|
||||||
const uint8_t *t;
|
const uint8_t *src = pkt->data;
|
||||||
int frames, ret, i, j, k;
|
int frames, ret, i, j;
|
||||||
|
int16_t cb[256];
|
||||||
|
|
||||||
frames = pkt->size / PAF_SOUND_FRAME_SIZE;
|
frames = pkt->size / PAF_SOUND_FRAME_SIZE;
|
||||||
if (frames < 1)
|
if (frames < 1)
|
||||||
@ -412,40 +417,42 @@ static int paf_aud_decode(AVCodecContext *avctx, void *data,
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
output_samples = (int16_t *)frame->data[0];
|
output_samples = (int16_t *)frame->data[0];
|
||||||
for (i = 0; i < frames; i++) {
|
// codebook of 256 16-bit samples and 8-bit indices to it
|
||||||
t = buf + 256 * sizeof(uint16_t);
|
for (j = 0; j < frames; j++) {
|
||||||
for (j = 0; j < PAF_SOUND_SAMPLES; j++) {
|
for (i = 0; i < 256; i++)
|
||||||
for (k = 0; k < 2; k++) {
|
cb[i] = sign_extend(AV_RL16(src + i * 2), 16);
|
||||||
*output_samples++ = AV_RL16(buf + *t * 2);
|
src += 256 * 2;
|
||||||
t++;
|
// always 2 channels
|
||||||
|
for (i = 0; i < PAF_SOUND_SAMPLES * 2; i++)
|
||||||
|
*output_samples++ = cb[*src++];
|
||||||
}
|
}
|
||||||
}
|
*got_frame = 1;
|
||||||
buf += PAF_SOUND_FRAME_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
*got_frame_ptr = 1;
|
|
||||||
|
|
||||||
return pkt->size;
|
return pkt->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CONFIG_PAF_VIDEO_DECODER
|
||||||
AVCodec ff_paf_video_decoder = {
|
AVCodec ff_paf_video_decoder = {
|
||||||
.name = "paf_video",
|
.name = "paf_video",
|
||||||
.long_name = NULL_IF_CONFIG_SMALL("Amazing Studio Packed Animation File Video"),
|
.long_name = NULL_IF_CONFIG_SMALL("Amazing Studio Packed Animation File Video"),
|
||||||
.type = AVMEDIA_TYPE_VIDEO,
|
.type = AVMEDIA_TYPE_VIDEO,
|
||||||
.id = AV_CODEC_ID_PAF_VIDEO,
|
.id = AV_CODEC_ID_PAF_VIDEO,
|
||||||
.priv_data_size = sizeof(PAFVideoDecContext),
|
.priv_data_size = sizeof(PAFVideoDecContext),
|
||||||
.init = paf_vid_init,
|
.init = paf_video_init,
|
||||||
.close = paf_vid_close,
|
.close = paf_video_close,
|
||||||
.decode = paf_vid_decode,
|
.decode = paf_video_decode,
|
||||||
.capabilities = CODEC_CAP_DR1,
|
.capabilities = CODEC_CAP_DR1,
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CONFIG_PAF_AUDIO_DECODER
|
||||||
AVCodec ff_paf_audio_decoder = {
|
AVCodec ff_paf_audio_decoder = {
|
||||||
.name = "paf_audio",
|
.name = "paf_audio",
|
||||||
.long_name = NULL_IF_CONFIG_SMALL("Amazing Studio Packed Animation File Audio"),
|
.long_name = NULL_IF_CONFIG_SMALL("Amazing Studio Packed Animation File Audio"),
|
||||||
.type = AVMEDIA_TYPE_AUDIO,
|
.type = AVMEDIA_TYPE_AUDIO,
|
||||||
.id = AV_CODEC_ID_PAF_AUDIO,
|
.id = AV_CODEC_ID_PAF_AUDIO,
|
||||||
.init = paf_aud_init,
|
.init = paf_audio_init,
|
||||||
.decode = paf_aud_decode,
|
.decode = paf_audio_decode,
|
||||||
.capabilities = CODEC_CAP_DR1,
|
.capabilities = CODEC_CAP_DR1,
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
@ -2678,10 +2678,12 @@ static enum AVCodecID remap_deprecated_codec_id(enum AVCodecID id)
|
|||||||
case AV_CODEC_ID_BRENDER_PIX_DEPRECATED: return AV_CODEC_ID_BRENDER_PIX;
|
case AV_CODEC_ID_BRENDER_PIX_DEPRECATED: return AV_CODEC_ID_BRENDER_PIX;
|
||||||
case AV_CODEC_ID_OPUS_DEPRECATED: return AV_CODEC_ID_OPUS;
|
case AV_CODEC_ID_OPUS_DEPRECATED: return AV_CODEC_ID_OPUS;
|
||||||
case AV_CODEC_ID_TAK_DEPRECATED : return AV_CODEC_ID_TAK;
|
case AV_CODEC_ID_TAK_DEPRECATED : return AV_CODEC_ID_TAK;
|
||||||
|
case AV_CODEC_ID_PAF_AUDIO_DEPRECATED : return AV_CODEC_ID_PAF_AUDIO;
|
||||||
case AV_CODEC_ID_PCM_S24LE_PLANAR_DEPRECATED : return AV_CODEC_ID_PCM_S24LE_PLANAR;
|
case AV_CODEC_ID_PCM_S24LE_PLANAR_DEPRECATED : return AV_CODEC_ID_PCM_S24LE_PLANAR;
|
||||||
case AV_CODEC_ID_PCM_S32LE_PLANAR_DEPRECATED : return AV_CODEC_ID_PCM_S32LE_PLANAR;
|
case AV_CODEC_ID_PCM_S32LE_PLANAR_DEPRECATED : return AV_CODEC_ID_PCM_S32LE_PLANAR;
|
||||||
case AV_CODEC_ID_ESCAPE130_DEPRECATED : return AV_CODEC_ID_ESCAPE130;
|
case AV_CODEC_ID_ESCAPE130_DEPRECATED : return AV_CODEC_ID_ESCAPE130;
|
||||||
case AV_CODEC_ID_G2M_DEPRECATED : return AV_CODEC_ID_G2M;
|
case AV_CODEC_ID_G2M_DEPRECATED : return AV_CODEC_ID_G2M;
|
||||||
|
case AV_CODEC_ID_PAF_VIDEO_DEPRECATED : return AV_CODEC_ID_PAF_VIDEO;
|
||||||
case AV_CODEC_ID_WEBP_DEPRECATED: return AV_CODEC_ID_WEBP;
|
case AV_CODEC_ID_WEBP_DEPRECATED: return AV_CODEC_ID_WEBP;
|
||||||
case AV_CODEC_ID_HEVC_DEPRECATED: return AV_CODEC_ID_HEVC;
|
case AV_CODEC_ID_HEVC_DEPRECATED: return AV_CODEC_ID_HEVC;
|
||||||
default : return id;
|
default : return id;
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
#define LIBAVCODEC_VERSION_MAJOR 55
|
#define LIBAVCODEC_VERSION_MAJOR 55
|
||||||
#define LIBAVCODEC_VERSION_MINOR 55
|
#define LIBAVCODEC_VERSION_MINOR 55
|
||||||
#define LIBAVCODEC_VERSION_MICRO 101
|
#define LIBAVCODEC_VERSION_MICRO 102
|
||||||
|
|
||||||
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
|
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
|
||||||
LIBAVCODEC_VERSION_MINOR, \
|
LIBAVCODEC_VERSION_MINOR, \
|
||||||
|
@ -103,9 +103,11 @@ static int read_header(AVFormatContext *s)
|
|||||||
vst->duration =
|
vst->duration =
|
||||||
p->nb_frames = avio_rl32(pb);
|
p->nb_frames = avio_rl32(pb);
|
||||||
avio_skip(pb, 4);
|
avio_skip(pb, 4);
|
||||||
|
|
||||||
vst->codec->width = avio_rl32(pb);
|
vst->codec->width = avio_rl32(pb);
|
||||||
vst->codec->height = avio_rl32(pb);
|
vst->codec->height = avio_rl32(pb);
|
||||||
avio_skip(pb, 4);
|
avio_skip(pb, 4);
|
||||||
|
|
||||||
vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
|
vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
|
||||||
vst->codec->codec_tag = 0;
|
vst->codec->codec_tag = 0;
|
||||||
vst->codec->codec_id = AV_CODEC_ID_PAF_VIDEO;
|
vst->codec->codec_id = AV_CODEC_ID_PAF_VIDEO;
|
||||||
@ -143,9 +145,12 @@ static int read_header(AVFormatContext *s)
|
|||||||
p->frame_blks > INT_MAX / sizeof(uint32_t))
|
p->frame_blks > INT_MAX / sizeof(uint32_t))
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
|
|
||||||
p->blocks_count_table = av_mallocz(p->nb_frames * sizeof(uint32_t));
|
p->blocks_count_table = av_mallocz(p->nb_frames *
|
||||||
p->frames_offset_table = av_mallocz(p->nb_frames * sizeof(uint32_t));
|
sizeof(*p->blocks_count_table));
|
||||||
p->blocks_offset_table = av_mallocz(p->frame_blks * sizeof(uint32_t));
|
p->frames_offset_table = av_mallocz(p->nb_frames *
|
||||||
|
sizeof(*p->frames_offset_table));
|
||||||
|
p->blocks_offset_table = av_mallocz(p->frame_blks *
|
||||||
|
sizeof(*p->blocks_offset_table));
|
||||||
|
|
||||||
p->video_size = p->max_video_blks * p->buffer_size;
|
p->video_size = p->max_video_blks * p->buffer_size;
|
||||||
p->video_frame = av_mallocz(p->video_size);
|
p->video_frame = av_mallocz(p->video_size);
|
||||||
@ -209,7 +214,8 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
return pkt->size;
|
return pkt->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
count = (p->current_frame == 0) ? p->preload_count : p->blocks_count_table[p->current_frame - 1];
|
count = (p->current_frame == 0) ? p->preload_count
|
||||||
|
: p->blocks_count_table[p->current_frame - 1];
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
if (p->current_frame_block >= p->frame_blks)
|
if (p->current_frame_block >= p->frame_blks)
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
#define LIBAVFORMAT_VERSION_MAJOR 55
|
#define LIBAVFORMAT_VERSION_MAJOR 55
|
||||||
#define LIBAVFORMAT_VERSION_MINOR 35
|
#define LIBAVFORMAT_VERSION_MINOR 35
|
||||||
#define LIBAVFORMAT_VERSION_MICRO 101
|
#define LIBAVFORMAT_VERSION_MICRO 102
|
||||||
|
|
||||||
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
|
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
|
||||||
LIBAVFORMAT_VERSION_MINOR, \
|
LIBAVFORMAT_VERSION_MINOR, \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user