Hello,

In attach patch to fix layer detection inside exr file.
Only search a channel match, if the layer name also match. If no layer name
is set, doesn't change the previous behaviour.
Avoid to automatically mix channel from several layer. And when layer
doesn't have the same pixel type, avoid a decoding error.

This patch also change the log messages, when layer option is set, to know
which channel is detected, and which is ignored.

For example, if an exr file have the following channels
B
G
R
myLayer.A
myLayer.B
myLayer.G
myLayer.R

Before this patch, if we use -layer myLayer option
the following channels will be process :
B
G
R
myLayer.A

And if myLayer.A doesn't have the same pixel type than B, G, R, the
decoding failed.

After this patch :
myLayer.A
myLayer.B
myLayer.G
myLayer.R


The second patch, is just the ident.

Comment welcome

Martin Vignali
Jokyo Images


-- 
Martin Vignali
Jokyo Images
18 rue du Transvaal
69008 Lyon
06 99 89 33 30
m.vign...@jokyo-images.com
http://www.jokyo-images.com/
From 4154f2a1d0f2b1165d43aa3c039f09894a809c98 Mon Sep 17 00:00:00 2001
From: Martin Vignali <martin.vign...@gmail.com>
Date: Sat, 4 Jun 2016 17:42:20 +0200
Subject: [PATCH 1/2] libavcodec/exr : fix layer detection. Only test a channel
 if the layer name match. Avoid to try to mix channel between the main layer
 (rgba layer), and the layer request by the user.

---
 libavcodec/exr.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavcodec/exr.c b/libavcodec/exr.c
index 2c4f15e..55bdf6e 100644
--- a/libavcodec/exr.c
+++ b/libavcodec/exr.c
@@ -1262,6 +1262,7 @@ static int check_header_variable(EXRContext *s,
 static int decode_header(EXRContext *s)
 {
     int magic_number, version, i, flags, sar = 0;
+    int layer_match = 0;
 
     s->current_channel_offset = 0;
     s->xmin               = ~0;
@@ -1332,14 +1333,21 @@ static int decode_header(EXRContext *s)
 
                 if (strcmp(s->layer, "") != 0) {
                     if (strncmp(ch_gb.buffer, s->layer, strlen(s->layer)) == 0) {
+                        layer_match = 1;
+                        av_log(s->avctx, AV_LOG_INFO,
+                               "Channel match layer : %s.\n", ch_gb.buffer);
                         ch_gb.buffer += strlen(s->layer);
                         if (*ch_gb.buffer == '.')
                             ch_gb.buffer++;         /* skip dot if not given */
+                    } else {
                         av_log(s->avctx, AV_LOG_INFO,
-                               "Layer %s.%s matched.\n", s->layer, ch_gb.buffer);
+                               "Channel doesn't match layer : %s.\n", ch_gb.buffer);
                     }
+                } else {
+                    layer_match = 1;
                 }
 
+                if (layer_match) { /* only search channel if the layer match is valid */
                 if (!strcmp(ch_gb.buffer, "R") ||
                     !strcmp(ch_gb.buffer, "X") ||
                     !strcmp(ch_gb.buffer, "U"))
@@ -1357,6 +1365,7 @@ static int decode_header(EXRContext *s)
                 else
                     av_log(s->avctx, AV_LOG_WARNING,
                            "Unsupported channel %.256s.\n", ch_gb.buffer);
+                }
 
                 /* skip until you get a 0 */
                 while (bytestream2_get_bytes_left(&ch_gb) > 0 &&
-- 
1.9.3 (Apple Git-50)

From ecadb36ac8d4e17e0f39113f102a4c5a426dd09a Mon Sep 17 00:00:00 2001
From: Martin Vignali <martin.vign...@gmail.com>
Date: Sat, 4 Jun 2016 17:45:31 +0200
Subject: [PATCH 2/2] libavodec/exr : (cosmetic) indent the if (layer_match)
 part.

---
 libavcodec/exr.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/libavcodec/exr.c b/libavcodec/exr.c
index 55bdf6e..088f64b 100644
--- a/libavcodec/exr.c
+++ b/libavcodec/exr.c
@@ -1348,23 +1348,23 @@ static int decode_header(EXRContext *s)
                 }
 
                 if (layer_match) { /* only search channel if the layer match is valid */
-                if (!strcmp(ch_gb.buffer, "R") ||
-                    !strcmp(ch_gb.buffer, "X") ||
-                    !strcmp(ch_gb.buffer, "U"))
-                    channel_index = 0;
-                else if (!strcmp(ch_gb.buffer, "G") ||
-                         !strcmp(ch_gb.buffer, "Y") ||
-                         !strcmp(ch_gb.buffer, "V"))
-                    channel_index = 1;
-                else if (!strcmp(ch_gb.buffer, "B") ||
-                         !strcmp(ch_gb.buffer, "Z") ||
-                         !strcmp(ch_gb.buffer, "W"))
-                    channel_index = 2;
-                else if (!strcmp(ch_gb.buffer, "A"))
-                    channel_index = 3;
-                else
-                    av_log(s->avctx, AV_LOG_WARNING,
-                           "Unsupported channel %.256s.\n", ch_gb.buffer);
+                    if (!strcmp(ch_gb.buffer, "R") ||
+                        !strcmp(ch_gb.buffer, "X") ||
+                        !strcmp(ch_gb.buffer, "U"))
+                        channel_index = 0;
+                    else if (!strcmp(ch_gb.buffer, "G") ||
+                             !strcmp(ch_gb.buffer, "Y") ||
+                             !strcmp(ch_gb.buffer, "V"))
+                        channel_index = 1;
+                    else if (!strcmp(ch_gb.buffer, "B") ||
+                             !strcmp(ch_gb.buffer, "Z") ||
+                             !strcmp(ch_gb.buffer, "W"))
+                        channel_index = 2;
+                    else if (!strcmp(ch_gb.buffer, "A"))
+                        channel_index = 3;
+                    else
+                        av_log(s->avctx, AV_LOG_WARNING,
+                               "Unsupported channel %.256s.\n", ch_gb.buffer);
                 }
 
                 /* skip until you get a 0 */
-- 
1.9.3 (Apple Git-50)

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to