avcodec/cdxl: add support for raw videos with chunky format

Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
Paul B Mahol 2016-02-18 23:47:39 +01:00
parent 98a0053d0f
commit 4956dc88d1
2 changed files with 39 additions and 7 deletions

View File

@ -30,6 +30,7 @@
#include "libavutil/intreadwrite.h"
#include "libavutil/imgutils.h"
#include "avcodec.h"
#include "bytestream.h"
#include "get_bits.h"
#include "internal.h"
@ -107,6 +108,17 @@ static void bitline2chunky(CDXLVideoContext *c, int linesize, uint8_t *out)
}
}
static void chunky2chunky(CDXLVideoContext *c, int linesize, uint8_t *out)
{
GetByteContext gb;
int y;
bytestream2_init(&gb, c->video, c->video_size);
for (y = 0; y < c->avctx->height; y++) {
bytestream2_get_buffer(&gb, out + linesize * y, c->avctx->width * 3);
}
}
static void import_format(CDXLVideoContext *c, int linesize, uint8_t *out)
{
memset(out, 0, linesize * c->avctx->height);
@ -118,6 +130,9 @@ static void import_format(CDXLVideoContext *c, int linesize, uint8_t *out)
case BIT_LINE:
bitline2chunky(c, linesize, out);
break;
case CHUNKY:
chunky2chunky(c, linesize, out);
break;
}
}
@ -130,6 +145,11 @@ static void cdxl_decode_rgb(CDXLVideoContext *c, AVFrame *frame)
import_format(c, frame->linesize[0], frame->data[0]);
}
static void cdxl_decode_raw(CDXLVideoContext *c, AVFrame *frame)
{
import_format(c, frame->linesize[0], frame->data[0]);
}
static void cdxl_decode_ham6(CDXLVideoContext *c, AVFrame *frame)
{
AVCodecContext *avctx = c->avctx;
@ -242,7 +262,7 @@ static int cdxl_decode_frame(AVCodecContext *avctx, void *data,
return AVERROR_INVALIDDATA;
if (c->bpp < 1)
return AVERROR_INVALIDDATA;
if (c->format != BIT_PLANAR && c->format != BIT_LINE) {
if (c->format != BIT_PLANAR && c->format != BIT_LINE && c->format != CHUNKY) {
avpriv_request_sample(avctx, "Pixel format 0x%0x", c->format);
return AVERROR_PATCHWELCOME;
}
@ -250,7 +270,10 @@ static int cdxl_decode_frame(AVCodecContext *avctx, void *data,
if ((ret = ff_set_dimensions(avctx, w, h)) < 0)
return ret;
aligned_width = FFALIGN(c->avctx->width, 16);
if (c->format == CHUNKY)
aligned_width = avctx->width;
else
aligned_width = FFALIGN(c->avctx->width, 16);
c->padded_bits = aligned_width - c->avctx->width;
if (c->video_size < aligned_width * avctx->height * c->bpp / 8)
return AVERROR_INVALIDDATA;
@ -260,9 +283,12 @@ static int cdxl_decode_frame(AVCodecContext *avctx, void *data,
if (c->palette_size != (1 << (c->bpp - 1)))
return AVERROR_INVALIDDATA;
avctx->pix_fmt = AV_PIX_FMT_BGR24;
} else if (!encoding && c->bpp == 24 && c->format == CHUNKY &&
!c->palette_size) {
avctx->pix_fmt = AV_PIX_FMT_RGB24;
} else {
avpriv_request_sample(avctx, "Encoding %d and bpp %d",
encoding, c->bpp);
avpriv_request_sample(avctx, "Encoding %d, bpp %d and format 0x%x",
encoding, c->bpp, c->format);
return AVERROR_PATCHWELCOME;
}
@ -279,8 +305,10 @@ static int cdxl_decode_frame(AVCodecContext *avctx, void *data,
cdxl_decode_ham8(c, p);
else
cdxl_decode_ham6(c, p);
} else {
} else if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
cdxl_decode_rgb(c, p);
} else {
cdxl_decode_raw(c, p);
}
*got_frame = 1;

View File

@ -111,7 +111,7 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt)
uint32_t current_size, video_size, image_size;
uint16_t audio_size, palette_size, width, height;
int64_t pos;
int frames, ret;
int format, frames, ret;
if (avio_feof(pb))
return AVERROR_EOF;
@ -125,6 +125,7 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt)
return AVERROR_INVALIDDATA;
}
format = cdxl->header[1] & 0xE0;
current_size = AV_RB32(&cdxl->header[2]);
width = AV_RB16(&cdxl->header[14]);
height = AV_RB16(&cdxl->header[16]);
@ -132,7 +133,10 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt)
audio_size = AV_RB16(&cdxl->header[22]);
if (FFALIGN(width, 16) * (uint64_t)height * cdxl->header[19] > INT_MAX)
return AVERROR_INVALIDDATA;
image_size = FFALIGN(width, 16) * height * cdxl->header[19] / 8;
if (format == 0x20)
image_size = width * height * cdxl->header[19] / 8;
else
image_size = FFALIGN(width, 16) * height * cdxl->header[19] / 8;
video_size = palette_size + image_size;
if (palette_size > 512)