[Bf-blender-cvs] [4b690341720] temp-udim-images: Allow to override the size of newly generated tiles

Lukas Stockner noreply at git.blender.org
Fri Jun 15 14:09:16 CEST 2018


Commit: 4b690341720a2a5c20ac5a25cd1ec777a288bd9f
Author: Lukas Stockner
Date:   Fri Jun 15 13:40:35 2018 +0200
Branches: temp-udim-images
https://developer.blender.org/rB4b690341720a2a5c20ac5a25cd1ec777a288bd9f

Allow to override the size of newly generated tiles

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

M	source/blender/blenkernel/BKE_image.h
M	source/blender/blenkernel/intern/image.c
M	source/blender/editors/space_image/image_ops.c

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

diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index d320e5feae0..21d3a4cc8cf 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -282,7 +282,7 @@ struct ImageTile *BKE_image_add_tile(struct Image *ima, const char *label);
 bool BKE_image_remove_tile(struct Image *ima);
 bool BKE_image_make_tiled(struct Image *ima, int num_tiles);
 
-bool BKE_image_generate_tile(struct Image *ima, int tile, const float color[4], int gen_type);
+bool BKE_image_generate_tile(struct Image *ima, int tile, int width, int height, const float color[4], int gen_type);
 
 struct GPUTexture *BKE_image_get_gpu_texture(struct Image *ima, int tile, int type);
 void BKE_image_set_gpu_texture(struct Image *ima, int tile, int type, struct GPUTexture *tex);
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 25b5adfc6d6..dfa1e0d14ba 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -3112,7 +3112,7 @@ void BKE_image_set_gpu_texture(struct Image *ima, int tile, int type, struct GPU
 	ima->tiles[tile].gputexture[type] = tex;
 }
 
-bool BKE_image_generate_tile(struct Image *ima, int tile, const float color[4], int gen_type)
+bool BKE_image_generate_tile(struct Image *ima, int tile, int width, int height, const float color[4], int gen_type)
 {
 	if (!ima || ima->source != IMA_SRC_TILED || tile < 0 || tile >= ima->num_tiles) {
 		return false;
@@ -3126,13 +3126,11 @@ bool BKE_image_generate_tile(struct Image *ima, int tile, const float color[4],
 	if (!main_ibuf) {
 		return false;
 	}
-	int x = main_ibuf->x;
-	int y = main_ibuf->y;
 	int planes = main_ibuf->planes;
 	bool is_float = (main_ibuf->rect_float != NULL);
 	BKE_image_release_ibuf(ima, main_ibuf, NULL);
 
-	ImBuf *tile_ibuf = add_ibuf_size(x, y, ima->name, planes, is_float, gen_type, color, &ima->colorspace_settings);
+	ImBuf *tile_ibuf = add_ibuf_size(width, height, ima->name, planes, is_float, gen_type, color, &ima->colorspace_settings);
 
 	if (tile_ibuf) {
 		image_assign_ibuf(ima, tile_ibuf, 0, tile);
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 9ce138532e3..8e90cca48e3 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -3951,8 +3951,10 @@ static int generate_tile_exec(bContext *C, wmOperator *op)
 	float color[4];
 	RNA_float_get_array(op->ptr, "color", color);
 	int gen_type = RNA_enum_get(op->ptr, "generated_type");
+	int width = RNA_int_get(op->ptr, "width");
+	int height = RNA_int_get(op->ptr, "height");
 
-	if (!BKE_image_generate_tile(ima, sima->curtile, color, gen_type))
+	if (!BKE_image_generate_tile(ima, sima->curtile, width, height, color, gen_type))
 		return OPERATOR_CANCELLED;
 
 	WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
@@ -3962,6 +3964,14 @@ static int generate_tile_exec(bContext *C, wmOperator *op)
 
 static int generate_tile_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
 {
+	SpaceImage *sima = CTX_wm_space_image(C);
+	Image *ima = ED_space_image(sima);
+	ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
+	if (ibuf) {
+		RNA_int_set(op->ptr, "width", ibuf->x);
+		RNA_int_set(op->ptr, "height", ibuf->y);
+		BKE_image_release_ibuf(ima, ibuf, NULL);
+	}
 	return WM_operator_props_dialog_popup(C, op, 15 * UI_UNIT_X, 5 * UI_UNIT_Y);
 }
 
@@ -3982,6 +3992,12 @@ static void generate_tile_draw(bContext *UNUSED(C), wmOperator *op)
 	uiItemL(col[0], IFACE_("Color"), ICON_NONE);
 	uiItemR(col[1], &ptr, "color", 0, "", ICON_NONE);
 
+	uiItemL(col[0], IFACE_("Width"), ICON_NONE);
+	uiItemR(col[1], &ptr, "width", 0, "", ICON_NONE);
+
+	uiItemL(col[0], IFACE_("Height"), ICON_NONE);
+	uiItemR(col[1], &ptr, "height", 0, "", ICON_NONE);
+
 	uiItemL(col[0], IFACE_("Generated Type"), ICON_NONE);
 	uiItemR(col[1], &ptr, "generated_type", 0, "", ICON_NONE);
 }
@@ -4009,4 +4025,8 @@ void IMAGE_OT_generate_tile(wmOperatorType *ot)
 	RNA_def_property_float_array_default(prop, default_color);
 	RNA_def_enum(ot->srna, "generated_type", rna_enum_image_generated_type_items, IMA_GENTYPE_BLANK,
 	             "Generated Type", "Fill the image with a grid for UV map testing");
+	prop = RNA_def_int(ot->srna, "width", 1024, 1, INT_MAX, "Width", "Image width", 1, 16384);
+	RNA_def_property_subtype(prop, PROP_PIXEL);
+	prop = RNA_def_int(ot->srna, "height", 1024, 1, INT_MAX, "Height", "Image height", 1, 16384);
+	RNA_def_property_subtype(prop, PROP_PIXEL);
 }
\ No newline at end of file



More information about the Bf-blender-cvs mailing list