Followup for fix T37718: image was not saving with proper settings second time
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 19 Dec 2013 11:17:40 +0000 (17:17 +0600)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 19 Dec 2013 11:20:12 +0000 (17:20 +0600)
This was actually a regression after color management re-implementation, need
to copy settings from saved image buffer to an original one since they might
be modified during save.

Also noticed image format planes detection didn't work properly from an image
buffer. Made it so save operator works fine now, but also marked a TODO in
BKE_imbuf_to_image_format() which needs to be investigated further.

source/blender/blenkernel/intern/image.c
source/blender/editors/space_image/image_ops.c

index 74e32d9f53c52a2512645288adaa07cee22dd5d6..3d59b719ca03dd0a46a092dc219665c4df4f7acb 100644 (file)
@@ -1497,6 +1497,12 @@ void BKE_imbuf_to_image_format(struct ImageFormatData *im_format, const ImBuf *i
        }
 
        /* planes */
+       /* TODO(sergey): Channels doesn't correspond actual planes used for image buffer
+        *               For example byte buffer will have 4 channels but it might easily
+        *               be BW or RGB image.
+        *
+        *               Need to use im_format->planes = imbuf->planes instead?
+        */
        switch (imbuf->channels) {
                case 0:
                case 4: im_format->planes = R_IMF_PLANES_RGBA;
index a2f49af1730f5b62e2de1d6645b984b64c47f95e..7120a699f020b829a460514c51babbf6cfaa6719 100644 (file)
@@ -1233,8 +1233,6 @@ static int save_image_options_init(SaveImageOptions *simopts, SpaceImage *sima,
                Image *ima = sima->image;
                short is_depth_set = FALSE;
 
-               simopts->im_format.planes = ibuf->planes;
-
                if (ELEM(ima->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)) {
                        /* imtype */
                        simopts->im_format = scene->r.im_format;
@@ -1250,6 +1248,9 @@ static int save_image_options_init(SaveImageOptions *simopts, SpaceImage *sima,
                        }
                        simopts->im_format.quality = ibuf->ftype & 0xff;
                }
+
+               simopts->im_format.planes = ibuf->planes;
+
                //simopts->subimtype = scene->r.subimtype; /* XXX - this is lame, we need to make these available too! */
 
                BLI_strncpy(simopts->filepath, ibuf->name, sizeof(simopts->filepath));
@@ -1430,8 +1431,16 @@ static void save_image_doit(bContext *C, SpaceImage *sima, wmOperator *op, SaveI
 
                WM_cursor_wait(0);
 
-               if (colormanaged_ibuf != ibuf)
+               if (colormanaged_ibuf != ibuf) {
+                       /* This guys might be modified by image buffer write functions,
+                        * need to copy them back from color managed image buffer to an
+                        * original one, so file type of image is being properly updated.
+                        */
+                       ibuf->ftype = colormanaged_ibuf->ftype;
+                       ibuf->planes = colormanaged_ibuf->planes;
+
                        IMB_freeImBuf(colormanaged_ibuf);
+               }
        }
 
        ED_space_image_release_buffer(sima, ibuf, lock);