avcodec/magicyuv: add 14bit rgb(a) support

This commit is contained in:
Paul B Mahol 2023-09-27 15:41:01 +02:00
parent 29b673bdcf
commit eaffbd9ac4
3 changed files with 25 additions and 5 deletions

View File

@ -73,12 +73,16 @@ typedef struct MagicYUVContext {
int (*magy_decode_slice)(AVCodecContext *avctx, void *tdata,
int j, int threadnr);
LLVidDSPContext llviddsp;
HuffEntry he[1 << 14];
uint8_t len[1 << 14];
} MagicYUVContext;
static int huff_build(const uint8_t len[], uint16_t codes_pos[33],
static int huff_build(AVCodecContext *avctx,
const uint8_t len[], uint16_t codes_pos[33],
VLC *vlc, VLC_MULTI *multi, int nb_elems, void *logctx)
{
HuffEntry he[4096];
MagicYUVContext *s = avctx->priv_data;
HuffEntry *he = s->he;
for (int i = 31; i > 0; i--)
codes_pos[i] += codes_pos[i + 1];
@ -381,7 +385,7 @@ static int build_huffman(AVCodecContext *avctx, const uint8_t *table,
{
MagicYUVContext *s = avctx->priv_data;
GetByteContext gb;
uint8_t len[4096];
uint8_t *len = s->len;
uint16_t length_count[33] = { 0 };
int i = 0, j = 0, k;
@ -409,7 +413,7 @@ static int build_huffman(AVCodecContext *avctx, const uint8_t *table,
if (j == max) {
j = 0;
if (huff_build(len, length_count, &s->vlc[i], &s->multi[i], max, avctx)) {
if (huff_build(avctx, len, length_count, &s->vlc[i], &s->multi[i], max, avctx)) {
av_log(avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");
return AVERROR_INVALIDDATA;
}
@ -526,6 +530,16 @@ static int magy_decode_frame(AVCodecContext *avctx, AVFrame *p,
s->decorrelate = 1;
s->bps = 12;
break;
case 0x71:
avctx->pix_fmt = AV_PIX_FMT_GBRP14;
s->decorrelate = 1;
s->bps = 14;
break;
case 0x72:
avctx->pix_fmt = AV_PIX_FMT_GBRAP14;
s->decorrelate = 1;
s->bps = 14;
break;
case 0x73:
avctx->pix_fmt = AV_PIX_FMT_GRAY10;
s->bps = 10;
@ -653,7 +667,9 @@ static int magy_decode_frame(AVCodecContext *avctx, AVFrame *p,
avctx->pix_fmt == AV_PIX_FMT_GBRP10 ||
avctx->pix_fmt == AV_PIX_FMT_GBRAP10||
avctx->pix_fmt == AV_PIX_FMT_GBRAP12||
avctx->pix_fmt == AV_PIX_FMT_GBRP12) {
avctx->pix_fmt == AV_PIX_FMT_GBRAP14||
avctx->pix_fmt == AV_PIX_FMT_GBRP12||
avctx->pix_fmt == AV_PIX_FMT_GBRP14) {
FFSWAP(uint8_t*, p->data[0], p->data[1]);
FFSWAP(int, p->linesize[0], p->linesize[1]);
} else {

View File

@ -260,6 +260,8 @@ const AVCodecTag ff_codec_movvideo_tags[] = {
{ AV_CODEC_ID_MAGICYUV, MKTAG('M', '8', 'Y', 'A') },
{ AV_CODEC_ID_MAGICYUV, MKTAG('M', '2', 'R', 'A') },
{ AV_CODEC_ID_MAGICYUV, MKTAG('M', '2', 'R', 'G') },
{ AV_CODEC_ID_MAGICYUV, MKTAG('M', '4', 'R', 'A') },
{ AV_CODEC_ID_MAGICYUV, MKTAG('M', '4', 'R', 'G') },
{ AV_CODEC_ID_SHEERVIDEO, MKTAG('S', 'h', 'r', '0') },
{ AV_CODEC_ID_SHEERVIDEO, MKTAG('S', 'h', 'r', '1') },

View File

@ -463,6 +463,8 @@ const AVCodecTag ff_codec_bmp_tags[] = {
{ AV_CODEC_ID_MAGICYUV, MKTAG('M', '0', 'Y', '4') },
{ AV_CODEC_ID_MAGICYUV, MKTAG('M', '2', 'R', 'A') },
{ AV_CODEC_ID_MAGICYUV, MKTAG('M', '2', 'R', 'G') },
{ AV_CODEC_ID_MAGICYUV, MKTAG('M', '4', 'R', 'A') },
{ AV_CODEC_ID_MAGICYUV, MKTAG('M', '4', 'R', 'G') },
{ AV_CODEC_ID_YLC, MKTAG('Y', 'L', 'C', '0') },
{ AV_CODEC_ID_SPEEDHQ, MKTAG('S', 'H', 'Q', '0') },
{ AV_CODEC_ID_SPEEDHQ, MKTAG('S', 'H', 'Q', '1') },