[FFmpeg-cvslog] Write 32bit palette to Targa files.

Carl Eugen Hoyos git at videolan.org
Tue Oct 9 10:15:06 CEST 2012


ffmpeg | branch: master | Carl Eugen Hoyos <cehoyos at ag.or.at> | Tue Oct  9 10:13:14 2012 +0200| [61a9f099b7da38722f758db38d9c89d1b39f3a87] | committer: 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.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=61a9f099b7da38722f758db38d9c89d1b39f3a87
---

 libavcodec/targaenc.c |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/libavcodec/targaenc.c b/libavcodec/targaenc.c
index 35e3ea5..4a71f27 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;



More information about the ffmpeg-cvslog mailing list