Commit 61a9f099 authored by Carl Eugen Hoyos's avatar Carl Eugen Hoyos

Write 32bit palette to Targa files.

Current ImageMagick fails to read such files,
therefore only write the 32bit palette if the
palette actually contains any transparency
information.
parent 1e83e6ad
......@@ -103,16 +103,27 @@ static int targa_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
avctx->bits_per_coded_sample = av_get_bits_per_pixel(&av_pix_fmt_descriptors[avctx->pix_fmt]);
switch(avctx->pix_fmt) {
case AV_PIX_FMT_PAL8:
case AV_PIX_FMT_PAL8: {
int pal_bpp = 24; /* Only write 32bit palette if there is transparency information */
for (i = 0; i < 256; i++)
if (AV_RN32(p->data[1] + 4 * i) >> 24 != 0xFF) {
pal_bpp = 32;
break;
}
pkt->data[1] = 1; /* palette present */
pkt->data[2] = TGA_PAL; /* uncompressed palettised image */
pkt->data[6] = 1; /* palette contains 256 entries */
pkt->data[7] = 24; /* palette contains 24 bit entries */
pkt->data[7] = pal_bpp; /* palette contains pal_bpp bit entries */
pkt->data[16] = 8; /* bpp */
for (i = 0; i < 256; i++)
if (pal_bpp == 32) {
AV_WL32(pkt->data + 18 + 4 * i, *(uint32_t *)(p->data[1] + i * 4));
} else {
AV_WL24(pkt->data + 18 + 3 * i, *(uint32_t *)(p->data[1] + i * 4));
out += 256 * 3; /* skip past the palette we just output */
}
out += 32 * pal_bpp; /* skip past the palette we just output */
break;
}
case AV_PIX_FMT_GRAY8:
pkt->data[2] = TGA_BW; /* uncompressed grayscale image */
avctx->bits_per_coded_sample = 0x28;
......
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