Fix #35658: OpenEXR (from Maya) - missing passes
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 10 Jun 2013 13:54:09 +0000 (13:54 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 10 Jun 2013 13:54:09 +0000 (13:54 +0000)
Added some special case for two-component channels name.

Maybe magic could be simplified to just use last char of
channel name as an id, but extra paranoid check never hurts.

source/blender/imbuf/intern/openexr/openexr_api.cpp

index b0932148076eac76a51f2de4ab3d72607d8a8ce3..8159520f6933d23079ee8874c95afcbc1e3b225d 100644 (file)
@@ -899,12 +899,36 @@ static int imb_exr_split_channel_name(ExrChannel *echan, char *layname, char *pa
                printf("multilayer read: bad channel name: %s\n", name);
                return 0;
        }
+       else if (len == 1) {
+               echan->chan_id = token[0];
+       }
        else if (len > 1) {
-               BLI_strncpy(tokenbuf, token, len);
-               printf("multilayer read: channel token too long: %s\n", tokenbuf);
-               return 0;
+               bool ok = false;
+
+               if (len == 2) {
+                       /* some multilayers are using two-letter channels name,
+                        * like, MX or NZ, which is basically has structure of
+                        *   <pass_prefix><component>
+                        *
+                        * This is a bit silly, but see file from [#35658].
+                        *
+                        * Here we do some magic to distinguish such cases.
+                        */
+                       if (ELEM3(token[1], 'X', 'Y', 'Z') ||
+                           ELEM3(token[1], 'R', 'G', 'B') ||
+                           ELEM3(token[1], 'U', 'V', 'A'))
+                       {
+                               echan->chan_id = token[1];
+                               ok = true;
+                       }
+               }
+
+               if (ok == false) {
+                       BLI_strncpy(tokenbuf, token, std::min(len + 1, EXR_TOT_MAXNAME));
+                       printf("multilayer read: channel token too long: %s\n", tokenbuf);
+                       return 0;
+               }
        }
-       echan->chan_id = token[0];
        end -= len + 1; /* +1 to skip '.' separator */
 
        /* second token is pass name */