[Bf-blender-cvs] [ccbfdd05d78] temp-udim-images: Improve creating and saving tiled images

Lukas Stockner noreply at git.blender.org
Fri Jul 27 21:43:31 CEST 2018


Commit: ccbfdd05d78e9cfd0d4464a939432dad086f4261
Author: Lukas Stockner
Date:   Thu Jul 26 22:58:45 2018 +0200
Branches: temp-udim-images
https://developer.blender.org/rBccbfdd05d78e9cfd0d4464a939432dad086f4261

Improve creating and saving tiled images

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

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_image.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 530a6783f3c..b36530c3db0 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -196,7 +196,7 @@ struct Image *BKE_image_load_exists(struct Main *bmain, const char *filepath);
 /* adds image, adds ibuf, generates color or pattern */
 struct Image *BKE_image_add_generated(
         struct Main *bmain, unsigned int width, unsigned int height, const char *name,
-        int depth, int floatbuf, short gen_type, const float color[4], const bool stereo3d);
+        int depth, int floatbuf, short gen_type, const float color[4], const bool stereo3d, bool tiled);
 /* 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 870949018bc..806e7123244 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -732,10 +732,16 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char
 /* adds new image block, creates ImBuf and initializes color */
 Image *BKE_image_add_generated(
         Main *bmain, unsigned int width, unsigned int height, const char *name,
-        int depth, int floatbuf, short gen_type, const float color[4], const bool stereo3d)
+        int depth, int floatbuf, short gen_type, const float color[4], const bool stereo3d, const bool tiled)
 {
 	/* on save, type is changed to FILE in editsima.c */
-	Image *ima = image_alloc(bmain, name, IMA_SRC_GENERATED, IMA_TYPE_UV_TEST);
+	Image *ima;
+	if (tiled) {
+		ima = image_alloc(bmain, name, IMA_SRC_TILED, IMA_TYPE_IMAGE);
+	}
+	else {
+		ima = image_alloc(bmain, name, IMA_SRC_GENERATED, IMA_TYPE_UV_TEST);
+	}
 
 	if (ima) {
 		int view_id;
@@ -752,7 +758,7 @@ Image *BKE_image_add_generated(
 		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(ima, ibuf, stereo3d ? view_id : (tiled ? 0 : IMA_NO_INDEX), 0);
 
 			/* image_assign_ibuf puts buffer to the cache, which increments user counter. */
 			IMB_freeImBuf(ibuf);
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 507a7b0f51e..50d42aed248 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -5712,7 +5712,7 @@ static Image *proj_paint_image_create(wmOperator *op, Main *bmain)
 	}
 	ima = BKE_image_add_generated(
 	        bmain, width, height, imagename, alpha ? 32 : 24, use_float,
-	        gen_type, color, false);
+	        gen_type, color, false, false);
 
 	return ima;
 }
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 998a27fba54..f1012c46f2f 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -1776,6 +1776,11 @@ static int save_image_options_init(Main *bmain, SaveImageOptions *simopts, Space
 				BLI_snprintf(simopts->filepath, sizeof(simopts->filepath), "//%s", ima->id.name + 2);
 				BLI_path_abs(simopts->filepath, is_prev_save ? G.ima : BKE_main_blendfile_path(bmain));
 			}
+
+			/* append UDIM numbering if not present */
+			if (ima->source == IMA_SRC_TILED && (BLI_stringdec(ima->name, NULL, NULL, NULL) != 1001)) {
+				strncat(simopts->filepath, ".1001", sizeof(simopts->filepath) - 6);
+			}
 		}
 
 		/* color management */
@@ -2119,6 +2124,14 @@ static bool save_image_doit(bContext *C, SpaceImage *sima, wmOperator *op, SaveI
 {
 	Image *ima = ED_space_image(sima);
 
+	if (ima->source == IMA_SRC_TILED) {
+		if (BLI_stringdec(simopts->filepath, NULL, NULL, NULL) != 1001) {
+			BKE_reportf(op->reports, RPT_ERROR,
+			            "When saving a tiled image, the path '%s' must contain the UDIM tag 1001", simopts->filepath);
+			return false;
+		}
+	}
+
 	WM_cursor_wait(1);
 
 	if (!save_image_single(C, sima, op, simopts, do_newpath, 0)) {
@@ -2547,11 +2560,12 @@ static int image_new_exec(bContext *C, wmOperator *op)
 	RNA_float_get_array(op->ptr, "color", color);
 	alpha = RNA_boolean_get(op->ptr, "alpha");
 	stereo3d = RNA_boolean_get(op->ptr, "use_stereo_3d");
+	bool tiled = RNA_boolean_get(op->ptr, "tiled");
 
 	if (!alpha)
 		color[3] = 1.0f;
 
-	ima = BKE_image_add_generated(bmain, width, height, name, alpha ? 32 : 24, floatbuf, gen_type, color, stereo3d);
+	ima = BKE_image_add_generated(bmain, width, height, name, alpha ? 32 : 24, floatbuf, gen_type, color, stereo3d, tiled);
 
 	if (!ima) {
 		image_new_free(op);
@@ -2635,6 +2649,9 @@ static void image_new_draw(bContext *UNUSED(C), wmOperator *op)
 	uiItemL(col[0], "", ICON_NONE);
 	uiItemR(col[1], &ptr, "float", 0, NULL, ICON_NONE);
 
+	uiItemL(col[0], "", ICON_NONE);
+	uiItemR(col[1], &ptr, "tiled", 0, NULL, ICON_NONE);
+
 #if 0
 	if (is_multiview) {
 		uiItemL(col[0], "", ICON_NONE);
@@ -2683,6 +2700,8 @@ void IMAGE_OT_new(wmOperatorType *ot)
 	RNA_def_property_flag(prop, PROP_HIDDEN);
 	prop = RNA_def_boolean(ot->srna, "use_stereo_3d", 0, "Stereo 3D", "Create an image with left and right views");
 	RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
+	prop = RNA_def_boolean(ot->srna, "tiled", 0, "Tiled", "Create a tiled image");
+	RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 }
 
 #undef IMA_DEF_NAME
diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c
index 0b540e813fd..36aed870f04 100644
--- a/source/blender/makesrna/intern/rna_image.c
+++ b/source/blender/makesrna/intern/rna_image.c
@@ -191,9 +191,7 @@ static const EnumPropertyItem *rna_Image_source_itemf(bContext *UNUSED(C), Point
 		RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_SEQUENCE);
 		RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_MOVIE);
 		RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_GENERATED);
-		if (BLI_stringdec(ima->name, NULL, NULL, NULL) == 1001) {
-			RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_TILED);
-		}
+		RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_TILED);
 	}
 
 	RNA_enum_item_end(&item, &totitem);
diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c
index febe74f63c9..974503bfaab 100644
--- a/source/blender/makesrna/intern/rna_main_api.c
+++ b/source/blender/makesrna/intern/rna_main_api.c
@@ -330,13 +330,13 @@ static Lamp *rna_Main_lights_new(Main *bmain, const char *name, int type)
 	return lamp;
 }
 
-static Image *rna_Main_images_new(Main *bmain, const char *name, int width, int height, bool alpha, bool float_buffer, bool stereo3d)
+static Image *rna_Main_images_new(Main *bmain, const char *name, int width, int height, bool alpha, bool float_buffer, bool stereo3d, bool tiled)
 {
 	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);
+	Image *image = BKE_image_add_generated(bmain, width, height, safe_name, alpha ? 32 : 24, float_buffer, 0, color, stereo3d, tiled);
 	id_us_min(&image->id);
 	return image;
 }
@@ -1004,6 +1004,7 @@ void RNA_def_main_images(BlenderRNA *brna, PropertyRNA *cprop)
 	RNA_def_boolean(func, "alpha", 0, "Alpha", "Use alpha channel");
 	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, "tiled", 0, "Tiled", "Create a tiled image");
 	/* 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