[FFmpeg-devel] [PATCH]Support 32bit palette in targa

Michael Niedermayer michaelni at gmx.at
Tue Oct 9 01:14:06 CEST 2012


On Mon, Oct 08, 2012 at 01:11:47PM +0200, Carl Eugen Hoyos wrote:
> Hi!
> 
> The Targa specification and gimp agree that the targa palette
> may contain transparency information.
> ImageMagick is broken: It allows 32bit palette entries but
> reads them identically as 24bit entries leading to a broken
> ("shifted") image.
> 
> Please comment, Carl Eugen

>  targa.c    |    5 +++++
>  targaenc.c |    6 +++---
>  2 files changed, 8 insertions(+), 3 deletions(-)
> 61f853c3def447bafd8dc06deaaacc9c7c204d32  patchtgapal32.diff
> diff --git a/libavcodec/targa.c b/libavcodec/targa.c
> index 339d7c4..5e9d2e9 100644
> --- a/libavcodec/targa.c
> +++ b/libavcodec/targa.c
> @@ -181,6 +181,7 @@ static int decode_frame(AVCodecContext *avctx,
>              return -1;
>          }
>          switch (csize) {
> +        case 32: pal_sample_size = 4; break;
>          case 24: pal_sample_size = 3; break;
>          case 16:
>          case 15: pal_sample_size = 2; break;
> @@ -201,6 +202,10 @@ static int decode_frame(AVCodecContext *avctx,
>                  return AVERROR_INVALIDDATA;
>              }
>              switch (pal_sample_size) {
> +            case 4:
> +                for (t = 0; t < colors; t++)
> +                    *pal++ = bytestream2_get_le32u(&s->gb);
> +                break;
>              case 3:
>                  /* RGB24 */
>                  for (t = 0; t < colors; t++)

this is probably ok



> diff --git a/libavcodec/targaenc.c b/libavcodec/targaenc.c
> index 2f22e94..cc082aa 100644
> --- a/libavcodec/targaenc.c
> +++ b/libavcodec/targaenc.c
> @@ -107,11 +107,11 @@ static int targa_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
>          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]  = 32;         /* palette contains 32 bit entries */
>          pkt->data[16] = 8;          /* bpp */
>          for (i = 0; i < 256; i++)
> -            AV_WL24(pkt->data + 18 + 3 * i, *(uint32_t *)(p->data[1] + i * 4));
> -        out += 256 * 3;             /* skip past the palette we just output */
> +            AV_WL32(pkt->data + 18 + 4 * i, *(uint32_t *)(p->data[1] + i * 4));
> +        out += 256 * 4;             /* skip past the palette we just output */

if i understand correctly this would break imagemagik reading tgas
from ffmpeg if so
i think the palette should be checked and only stored as 32bit when
its needed for some entry

also please add a regression test once encoder and decoder support it

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Republics decline into democracies and democracies degenerate into
despotisms. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121009/0ddeb9d8/attachment.asc>


More information about the ffmpeg-devel mailing list