[Bf-blender-cvs] [6d22633a96a] master: Fix T66137: added normal map for painting has wrong color space until refresh

Brecht Van Lommel noreply at git.blender.org
Wed Jun 26 15:07:07 CEST 2019


Commit: 6d22633a96a4ef18051ba6a937ed9c1d1e5d967c
Author: Brecht Van Lommel
Date:   Wed Jun 26 15:04:44 2019 +0200
Branches: master
https://developer.blender.org/rB6d22633a96a4ef18051ba6a937ed9c1d1e5d967c

Fix T66137: added normal map for painting has wrong color space until refresh

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

M	source/blender/blenkernel/BKE_image.h
M	source/blender/blenkernel/intern/image.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/space_image/image_ops.c
M	source/blender/makesrna/intern/rna_main_api.c

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

diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index d6683509729..2bbad72b303 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -205,7 +205,8 @@ struct Image *BKE_image_add_generated(struct Main *bmain,
                                       int floatbuf,
                                       short gen_type,
                                       const float color[4],
-                                      const bool stereo3d);
+                                      const bool stereo3d,
+                                      const bool is_data);
 /* adds image from imbuf, owns imbuf */
 struct Image *BKE_image_add_from_imbuf(struct Main *bmain, struct ImBuf *ibuf, const char *name);
 
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 5c23987a8d9..073b2453299 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -679,41 +679,48 @@ Image *BKE_image_add_generated(Main *bmain,
                                int floatbuf,
                                short gen_type,
                                const float color[4],
-                               const bool stereo3d)
+                               const bool stereo3d,
+                               const bool is_data)
 {
   /* on save, type is changed to FILE in editsima.c */
   Image *ima = image_alloc(bmain, name, IMA_SRC_GENERATED, IMA_TYPE_UV_TEST);
+  if (ima == NULL) {
+    return NULL;
+  }
 
-  if (ima) {
-    int view_id;
-    const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME};
+  int view_id;
+  const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME};
 
-    /* STRNCPY(ima->name, name); */ /* don't do this, this writes in ain invalid filepath! */
-    ima->gen_x = width;
-    ima->gen_y = height;
-    ima->gen_type = gen_type;
-    ima->gen_flag |= (floatbuf ? IMA_GEN_FLOAT : 0);
-    ima->gen_depth = depth;
-    copy_v4_v4(ima->gen_color, color);
-
-    for (view_id = 0; view_id < 2; view_id++) {
-      ImBuf *ibuf;
-      ibuf = add_ibuf_size(
-          width, height, ima->name, depth, floatbuf, gen_type, color, &ima->colorspace_settings);
-      image_assign_ibuf(ima, ibuf, stereo3d ? view_id : IMA_NO_INDEX, 0);
-
-      /* image_assign_ibuf puts buffer to the cache, which increments user counter. */
-      IMB_freeImBuf(ibuf);
-      if (!stereo3d) {
-        break;
-      }
+  /* STRNCPY(ima->name, name); */ /* don't do this, this writes in ain invalid filepath! */
+  ima->gen_x = width;
+  ima->gen_y = height;
+  ima->gen_type = gen_type;
+  ima->gen_flag |= (floatbuf ? IMA_GEN_FLOAT : 0);
+  ima->gen_depth = depth;
+  copy_v4_v4(ima->gen_color, color);
 
-      image_add_view(ima, names[view_id], "");
+  if (is_data) {
+    STRNCPY(ima->colorspace_settings.name,
+            IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DATA));
+  }
+
+  for (view_id = 0; view_id < 2; view_id++) {
+    ImBuf *ibuf;
+    ibuf = add_ibuf_size(
+        width, height, ima->name, depth, floatbuf, gen_type, color, &ima->colorspace_settings);
+    image_assign_ibuf(ima, ibuf, stereo3d ? view_id : IMA_NO_INDEX, 0);
+
+    /* image_assign_ibuf puts buffer to the cache, which increments user counter. */
+    IMB_freeImBuf(ibuf);
+    if (!stereo3d) {
+      break;
     }
 
-    ima->ok = IMA_OK_LOADED;
+    image_add_view(ima, names[view_id], "");
   }
 
+  ima->ok = IMA_OK_LOADED;
+
   return ima;
 }
 
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 2cc8adf6f36..79731a6752d 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -6435,13 +6435,16 @@ static Image *proj_paint_image_create(wmOperator *op, Main *bmain, bool is_data)
     alpha = RNA_boolean_get(op->ptr, "alpha");
     RNA_string_get(op->ptr, "name", imagename);
   }
-  ima = BKE_image_add_generated(
-      bmain, width, height, imagename, alpha ? 32 : 24, use_float, gen_type, color, false);
-
-  if (is_data) {
-    STRNCPY(ima->colorspace_settings.name,
-            IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DATA));
-  }
+  ima = BKE_image_add_generated(bmain,
+                                width,
+                                height,
+                                imagename,
+                                alpha ? 32 : 24,
+                                use_float,
+                                gen_type,
+                                color,
+                                false,
+                                is_data);
 
   return ima;
 }
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 9eda7ffdc34..96eaa89d175 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -2499,7 +2499,7 @@ static int image_new_exec(bContext *C, wmOperator *op)
   }
 
   ima = BKE_image_add_generated(
-      bmain, width, height, name, alpha ? 32 : 24, floatbuf, gen_type, color, stereo3d);
+      bmain, width, height, name, alpha ? 32 : 24, floatbuf, gen_type, color, stereo3d, false);
 
   if (!ima) {
     image_new_free(op);
diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c
index f0f22d21078..d7acbb40bb8 100644
--- a/source/blender/makesrna/intern/rna_main_api.c
+++ b/source/blender/makesrna/intern/rna_main_api.c
@@ -371,14 +371,15 @@ static Image *rna_Main_images_new(Main *bmain,
                                   int height,
                                   bool alpha,
                                   bool float_buffer,
-                                  bool stereo3d)
+                                  bool stereo3d,
+                                  bool is_data)
 {
   char safe_name[MAX_ID_NAME - 2];
   rna_idname_validate(name, safe_name);
 
   float color[4] = {0.0, 0.0, 0.0, 1.0};
   Image *image = BKE_image_add_generated(
-      bmain, width, height, safe_name, alpha ? 32 : 24, float_buffer, 0, color, stereo3d);
+      bmain, width, height, safe_name, alpha ? 32 : 24, float_buffer, 0, color, stereo3d, is_data);
   id_us_min(&image->id);
   return image;
 }
@@ -1144,6 +1145,7 @@ void RNA_def_main_images(BlenderRNA *brna, PropertyRNA *cprop)
   RNA_def_boolean(
       func, "float_buffer", 0, "Float Buffer", "Create an image with floating point color");
   RNA_def_boolean(func, "stereo3d", 0, "Stereo 3D", "Create left and right views");
+  RNA_def_boolean(func, "is_data", 0, "Is Data", "Create image with non-color data color space");
   /* return type */
   parm = RNA_def_pointer(func, "image", "Image", "", "New image data-block");
   RNA_def_function_return(func, parm);



More information about the Bf-blender-cvs mailing list