Fix #34779: Channels disappear from multilayer exr sequence
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 27 Mar 2013 11:26:10 +0000 (11:26 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 27 Mar 2013 11:26:10 +0000 (11:26 +0000)
Issue was caused by delayed or missing image user frame
number update, which lead to image loading failure in
cases node is updating from image signal callback.

Solved in a way that file from image datablock is used
for sockets detection instead of loading image for
current frame.

source/blender/blenkernel/BKE_image.h
source/blender/blenkernel/intern/image.c
source/blender/nodes/composite/nodes/node_composite_image.c

index 26ac2cc8bb433800cab0c70f9d36c809d639105d..0f8e25b9df5483d86c80217df8704b0f2f3213e4 100644 (file)
@@ -232,6 +232,8 @@ void BKE_image_buf_fill_checker_color(unsigned char *rect, float *rect_float, in
 unsigned char *BKE_image_get_pixels_for_frame(struct Image *image, int frame);
 float *BKE_image_get_float_pixels_for_frame(struct Image *image, int frame);
 
+/* Guess offset for the first frame in the sequence */
+int BKE_image_sequence_guess_offset(struct Image *image);
 #ifdef __cplusplus
 }
 #endif
index 26651d76f688745a3153c405a4d6490fc5ee31df..c9034cfe7bb0c83becbdff2ba3f9c1fc2c2b0092 100644 (file)
@@ -3430,3 +3430,15 @@ float *BKE_image_get_float_pixels_for_frame(struct Image *image, int frame)
 
        return pixels;
 }
+
+int BKE_image_sequence_guess_offset(Image *image)
+{
+       unsigned short numlen;
+       char head[FILE_MAX], tail[FILE_MAX];
+       char num[FILE_MAX] = {0};
+
+       BLI_stringdec(image->name, head, tail, &numlen);
+       BLI_strncpy(num, image->name + strlen(head), numlen + 1);
+
+       return atoi(num);
+}
index c09903ad6c554f3cdf861e8574ee9360082ba5ca..e2c4db55fd81be9bdb54272a7b30255e2febf90b 100644 (file)
@@ -174,11 +174,24 @@ static void cmp_node_image_create_outputs(bNodeTree *ntree, bNode *node)
 {
        Image *ima= (Image *)node->id;
        if (ima) {
-               ImageUser *iuser= node->storage;
+               ImageUser *iuser = node->storage;
+               ImageUser load_iuser = {0};
                ImBuf *ibuf;
-               
+               int offset = BKE_image_sequence_guess_offset(ima);
+
+               /* It is possible that image user in this node is not
+                * properly updated yet. In this case loading image will
+                * fail and sockets detection will go wrong.
+                *
+                * So we manually construct image user to be sure first
+                * image from sequence (that one which is set as fileanme
+                * for image datablock) is used for sockets detection
+                */
+               load_iuser.ok = 1;
+               load_iuser.framenr = offset;
+
                /* make sure ima->type is correct */
-               ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
+               ibuf = BKE_image_acquire_ibuf(ima, &load_iuser, NULL);
                
                if (ima->rr) {
                        RenderLayer *rl= BLI_findlink(&ima->rr->layers, iuser->layer);