summaryrefslogtreecommitdiff
path: root/libavcodec/targaenc.c
diff options
context:
space:
mode:
authorCarl Eugen Hoyos <cehoyos@ag.or.at>2012-10-09 10:13:14 +0200
committerCarl Eugen Hoyos <cehoyos@ag.or.at>2012-10-09 10:13:14 +0200
commit61a9f099b7da38722f758db38d9c89d1b39f3a87 (patch)
tree9fc9e6c2b247dbe37c6a7c6ceae560f52ff27bba /libavcodec/targaenc.c
parent1e83e6ad7a8b5d6994c50f531c30f25f787f0c0e (diff)
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.
Diffstat (limited to 'libavcodec/targaenc.c')
-rw-r--r--libavcodec/targaenc.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/libavcodec/targaenc.c b/libavcodec/targaenc.c
index 35e3ea5bdd..4a71f27522 100644
--- a/libavcodec/targaenc.c
+++ b/libavcodec/targaenc.c
@@ -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;