Commit 257fbc3a authored by Paul B Mahol's avatar Paul B Mahol

avcodec/dds: add support for 4bpp format

Signed-off-by: 's avatarPaul B Mahol <onemda@gmail.com>
parent 9d16e46d
...@@ -102,6 +102,7 @@ typedef struct DDSContext { ...@@ -102,6 +102,7 @@ typedef struct DDSContext {
int compressed; int compressed;
int paletted; int paletted;
int bpp;
enum DDSPostProc postproc; enum DDSPostProc postproc;
const uint8_t *tex_data; // Compressed texture const uint8_t *tex_data; // Compressed texture
...@@ -148,7 +149,7 @@ static int parse_pixel_format(AVCodecContext *avctx) ...@@ -148,7 +149,7 @@ static int parse_pixel_format(AVCodecContext *avctx)
ctx->paletted = 0; ctx->paletted = 0;
} }
bpp = bytestream2_get_le32(gbc); // rgbbitcount bpp = ctx->bpp = bytestream2_get_le32(gbc); // rgbbitcount
r = bytestream2_get_le32(gbc); // rbitmask r = bytestream2_get_le32(gbc); // rbitmask
g = bytestream2_get_le32(gbc); // gbitmask g = bytestream2_get_le32(gbc); // gbitmask
b = bytestream2_get_le32(gbc); // bbitmask b = bytestream2_get_le32(gbc); // bbitmask
...@@ -354,8 +355,11 @@ static int parse_pixel_format(AVCodecContext *avctx) ...@@ -354,8 +355,11 @@ static int parse_pixel_format(AVCodecContext *avctx)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
} else { } else {
/* 4 bpp */
if (bpp == 4 && r == 0 && g == 0 && b == 0 && a == 0)
avctx->pix_fmt = AV_PIX_FMT_PAL8;
/* 8 bpp */ /* 8 bpp */
if (bpp == 8 && r == 0xff && g == 0 && b == 0 && a == 0) else if (bpp == 8 && r == 0xff && g == 0 && b == 0 && a == 0)
avctx->pix_fmt = AV_PIX_FMT_GRAY8; avctx->pix_fmt = AV_PIX_FMT_GRAY8;
else if (bpp == 8 && r == 0 && g == 0 && b == 0 && a == 0xff) else if (bpp == 8 && r == 0 && g == 0 && b == 0 && a == 0xff)
avctx->pix_fmt = AV_PIX_FMT_GRAY8; avctx->pix_fmt = AV_PIX_FMT_GRAY8;
...@@ -676,6 +680,36 @@ static int dds_decode(AVCodecContext *avctx, void *data, ...@@ -676,6 +680,36 @@ static int dds_decode(AVCodecContext *avctx, void *data,
/* Use the decompress function on the texture, one block per thread. */ /* Use the decompress function on the texture, one block per thread. */
ctx->tex_data = gbc->buffer; ctx->tex_data = gbc->buffer;
avctx->execute2(avctx, decompress_texture_thread, frame, NULL, ctx->slice_count); avctx->execute2(avctx, decompress_texture_thread, frame, NULL, ctx->slice_count);
} else if (!ctx->paletted && ctx->bpp == 4) {
uint8_t *dst = frame->data[0];
int x, y, i;
/* Use the first 64 bytes as palette, then copy the rest. */
bytestream2_get_buffer(gbc, frame->data[1], 16 * 4);
for (i = 0; i < 16; i++) {
AV_WN32(frame->data[1] + i*4,
(frame->data[1][2+i*4]<<0)+
(frame->data[1][1+i*4]<<8)+
(frame->data[1][0+i*4]<<16)+
(frame->data[1][3+i*4]<<24)
);
}
frame->palette_has_changed = 1;
if (bytestream2_get_bytes_left(gbc) < frame->height * frame->width / 2) {
av_log(avctx, AV_LOG_ERROR, "Buffer is too small (%d < %d).\n",
bytestream2_get_bytes_left(gbc), frame->height * frame->width / 2);
return AVERROR_INVALIDDATA;
}
for (y = 0; y < frame->height; y++) {
for (x = 0; x < frame->width; x += 2) {
uint8_t val = bytestream2_get_byte(gbc);
dst[x ] = val & 0xF;
dst[x + 1] = val >> 4;
}
dst += frame->linesize[0];
}
} else { } else {
int linesize = av_image_get_linesize(avctx->pix_fmt, frame->width, 0); int linesize = av_image_get_linesize(avctx->pix_fmt, frame->width, 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment