diff mbox

[FFmpeg-devel] lavc/psd: Support indexed files

Message ID 201612301448.12403.cehoyos@ag.or.at
State Accepted
Headers show

Commit Message

Carl Eugen Hoyos Dec. 30, 2016, 1:48 p.m. UTC
Hi!

Attached patch fixes ticket #6045.

Please comment, Carl Eugen
From 0bd8d59e1ad0009f88aa6871d4ed915a12f5900d Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <cehoyos@ag.or.at>
Date: Fri, 30 Dec 2016 14:45:36 +0100
Subject: [PATCH] lavc/psd: Support indexed files.

Fixes ticket #6045.
---
 libavcodec/psd.c |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

Michael Niedermayer Dec. 31, 2016, 2:29 a.m. UTC | #1
On Fri, Dec 30, 2016 at 02:48:12PM +0100, Carl Eugen Hoyos wrote:
> Hi!
> 
> Attached patch fixes ticket #6045.
> 
> Please comment, Carl Eugen

>  psd.c |   25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 0881ec94d476ac47ae4d91487d968d6ac82f7992  0001-lavc-psd-Support-indexed-files.patch
> From 0bd8d59e1ad0009f88aa6871d4ed915a12f5900d Mon Sep 17 00:00:00 2001
> From: Carl Eugen Hoyos <cehoyos@ag.or.at>
> Date: Fri, 30 Dec 2016 14:45:36 +0100
> Subject: [PATCH] lavc/psd: Support indexed files.
> 
> Fixes ticket #6045.

in the absence of other replies, this LGTM

thx

[...]
Carl Eugen Hoyos Jan. 2, 2017, 10:44 a.m. UTC | #2
2016-12-31 3:29 GMT+01:00 Michael Niedermayer <michael@niedermayer.cc>:
> On Fri, Dec 30, 2016 at 02:48:12PM +0100, Carl Eugen Hoyos wrote:

>> Fixes ticket #6045.
>
> in the absence of other replies, this LGTM

Replaced a for loop with a presumably faster memset and pushed.

Thank you, Carl Eugen
diff mbox

Patch

diff --git a/libavcodec/psd.c b/libavcodec/psd.c
index 3181a41..1ca4dc9 100644
--- a/libavcodec/psd.c
+++ b/libavcodec/psd.c
@@ -60,6 +60,8 @@  typedef struct PSDContext {
 
     enum PsdCompr compression;
     enum PsdColorMode color_mode;
+
+    uint8_t palette[AVPALETTE_SIZE];
 } PSDContext;
 
 static int decode_header(PSDContext * s)
@@ -159,6 +161,15 @@  static int decode_header(PSDContext * s)
         av_log(s->avctx, AV_LOG_ERROR, "Incomplete file.\n");
         return AVERROR_INVALIDDATA;
     }
+    if (len_section) {
+        int i,j;
+        for (i = 0; i < 256; i++)
+            s->palette[i * 4 + 3 * !HAVE_BIGENDIAN] = 0xffu;
+        for (j = HAVE_BIGENDIAN; j < 3 + HAVE_BIGENDIAN; j++)
+            for (i = 0; i < FFMIN(256, len_section / 3); i++)
+                s->palette[i * 4 + (HAVE_BIGENDIAN ? j : 2 - j)] = bytestream2_get_byteu(&s->gb);
+        len_section -= i * 3;
+    }
     bytestream2_skip(&s->gb, len_section);
 
     /* image ressources */
@@ -309,6 +320,15 @@  static int decode_frame(AVCodecContext *avctx, void *data,
     s->uncompressed_size = s->line_size * s->height * s->channel_count;
 
     switch (s->color_mode) {
+    case PSD_INDEXED:
+        if (s->channel_depth != 8 || s->channel_count != 1) {
+            av_log(s->avctx, AV_LOG_ERROR,
+                   "Invalid indexed file (channel_depth %d, channel_count %d)\n",
+                   s->channel_depth, s->channel_count);
+            return AVERROR_INVALIDDATA;
+        }
+        avctx->pix_fmt = AV_PIX_FMT_PAL8;
+        break;
     case PSD_RGB:
         if (s->channel_count == 3) {
             if (s->channel_depth == 8) {
@@ -416,6 +436,11 @@  static int decode_frame(AVCodecContext *avctx, void *data,
         }
     }
 
+    if (s->color_mode == PSD_INDEXED) {
+        picture->palette_has_changed = 1;
+        memcpy(picture->data[1], s->palette, AVPALETTE_SIZE);
+    }
+
     av_freep(&s->tmp);
 
     picture->pict_type = AV_PICTURE_TYPE_I;