[Bf-blender-cvs] [dfa5bd689e4] master: Fix possible wrong image color space when it is created from image buffer

Sergey Sharybin noreply at git.blender.org
Fri Jul 1 09:51:44 CEST 2022


Commit: dfa5bd689e470ad9b8fc7328927afdbe0159e0c1
Author: Sergey Sharybin
Date:   Thu Jun 30 15:31:12 2022 +0200
Branches: master
https://developer.blender.org/rBdfa5bd689e470ad9b8fc7328927afdbe0159e0c1

Fix possible wrong image color space when it is created from image buffer

>From quick look it doesn't seem to be leading to real issues yet as the
image buffers are created with the default roles, but valid color space
is needed to be ensured for an upcoming development.

===================================================================

M	source/blender/blenkernel/intern/image.cc
M	source/blender/imbuf/IMB_colormanagement.h
M	source/blender/imbuf/intern/colormanagement.c

===================================================================

diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc
index ed8652ca470..b6294eb058c 100644
--- a/source/blender/blenkernel/intern/image.cc
+++ b/source/blender/blenkernel/intern/image.cc
@@ -1172,6 +1172,33 @@ Image *BKE_image_add_generated(Main *bmain,
   return ima;
 }
 
+static void image_colorspace_from_imbuf(Image *image, const ImBuf *ibuf)
+{
+  const char *colorspace_name = NULL;
+
+  if (ibuf->rect_float) {
+    if (ibuf->float_colorspace) {
+      colorspace_name = IMB_colormanagement_colorspace_get_name(ibuf->float_colorspace);
+    }
+    else {
+      colorspace_name = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_FLOAT);
+    }
+  }
+
+  if (ibuf->rect && !colorspace_name) {
+    if (ibuf->rect_colorspace) {
+      colorspace_name = IMB_colormanagement_colorspace_get_name(ibuf->rect_colorspace);
+    }
+    else {
+      colorspace_name = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_BYTE);
+    }
+  }
+
+  if (colorspace_name) {
+    STRNCPY(image->colorspace_settings.name, colorspace_name);
+  }
+}
+
 Image *BKE_image_add_from_imbuf(Main *bmain, ImBuf *ibuf, const char *name)
 {
   if (name == nullptr) {
@@ -1199,6 +1226,7 @@ Image *BKE_image_add_from_imbuf(Main *bmain, ImBuf *ibuf, const char *name)
   }
 
   image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0);
+  image_colorspace_from_imbuf(ima, ibuf);
 
   /* Consider image dirty since its content can not be re-created unless the image is explicitly
    * saved. */
diff --git a/source/blender/imbuf/IMB_colormanagement.h b/source/blender/imbuf/IMB_colormanagement.h
index 2f0d2f9b449..0818dd653a1 100644
--- a/source/blender/imbuf/IMB_colormanagement.h
+++ b/source/blender/imbuf/IMB_colormanagement.h
@@ -341,6 +341,7 @@ const char *IMB_colormanagement_look_get_indexed_name(int index);
 
 int IMB_colormanagement_colorspace_get_named_index(const char *name);
 const char *IMB_colormanagement_colorspace_get_indexed_name(int index);
+const char *IMB_colormanagement_colorspace_get_name(const struct ColorSpace *colorspace);
 const char *IMB_colormanagement_view_get_default_name(const char *display_name);
 
 void IMB_colormanagement_colorspace_from_ibuf_ftype(
diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c
index a58c2ba4c44..b95ec1cd92b 100644
--- a/source/blender/imbuf/intern/colormanagement.c
+++ b/source/blender/imbuf/intern/colormanagement.c
@@ -3174,6 +3174,11 @@ const char *IMB_colormanagement_colorspace_get_indexed_name(int index)
   return "";
 }
 
+const char *IMB_colormanagement_colorspace_get_name(const ColorSpace *colorspace)
+{
+  return colorspace->name;
+}
+
 void IMB_colormanagement_colorspace_from_ibuf_ftype(
     ColorManagedColorspaceSettings *colorspace_settings, ImBuf *ibuf)
 {



More information about the Bf-blender-cvs mailing list