From 4f610a30ad8e7dad6b007f982add9848d950799e Mon Sep 17 00:00:00 2001
From: Martin Vignali <martin.vignali@gmail.com>
Date: Sun, 19 Aug 2018 19:35:01 +0200
Subject: [PATCH 1/2] avcodec/psd : add support for gray float

---
 libavcodec/psd.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/libavcodec/psd.c b/libavcodec/psd.c
index 66f2ec28d7..d061fe97e5 100644
--- a/libavcodec/psd.c
+++ b/libavcodec/psd.c
@@ -369,6 +369,8 @@ static int decode_frame(AVCodecContext *avctx, void *data,
                 avctx->pix_fmt = AV_PIX_FMT_GRAY8;
             } else if (s->channel_depth == 16) {
                 avctx->pix_fmt = AV_PIX_FMT_GRAY16BE;
+            } else if (s->channel_depth == 32) {
+                avctx->pix_fmt = AV_PIX_FMT_GRAYF32LE;
             } else {
                 avpriv_report_missing_feature(avctx, "channel depth %d for grayscale", s->channel_depth);
                 return AVERROR_PATCHWELCOME;
@@ -399,6 +401,11 @@ static int decode_frame(AVCodecContext *avctx, void *data,
 
     /* decode picture if need */
     if (s->compression == PSD_RLE) {
+        if (s->channel_depth == 32) {
+            avpriv_report_missing_feature(avctx, "float with rle compression");
+            return AVERROR_PATCHWELCOME;
+        }
+
         s->tmp = av_malloc(s->uncompressed_size);
         if (!s->tmp)
             return AVERROR(ENOMEM);
@@ -434,9 +441,21 @@ static int decode_frame(AVCodecContext *avctx, void *data,
             }
         }
     } else {/* Planar */
-        if (s->channel_count == 1)/* gray 8 or gray 16be */
+        if (s->channel_count == 1)/* gray 8, gray 16be, gray float */
             eq_channel[0] = 0;/* assign first channel, to first plane */
 
+        if (s->pixel_size == 4) { /* float pix fmt */
+            for (c = 0; c < s->channel_count; c++) {
+                plane_number = eq_channel[c];
+                uint32_t * ptr_32 = (uint32_t *)picture->data[plane_number];/* get the right plane */
+                for (y = 0; y < s->height; y++) {
+                    for (x = 0; x < s->width; x++) {
+                        index_out = y * picture->linesize[0] / 4 + x;
+                        ptr_32[index_out] = bytestream_get_be32(&ptr_data);
+                    }
+                }
+            }
+        } else {
         for (c = 0; c < s->channel_count; c++) {
             plane_number = eq_channel[c];
             ptr = picture->data[plane_number];/* get the right plane */
@@ -446,6 +465,7 @@ static int decode_frame(AVCodecContext *avctx, void *data,
                 ptr_data += s->line_size;
             }
         }
+        }
     }
 
     if (s->color_mode == PSD_INDEXED) {
-- 
2.14.3 (Apple Git-98)

