[Bf-blender-cvs] [4875f41ea6d] temp-udim-images: Implement custom UDIM tile labeling

Lukas Stockner noreply at git.blender.org
Tue Jun 12 21:47:13 CEST 2018


Commit: 4875f41ea6da125035364ab76c0e208ab8e2c333
Author: Lukas Stockner
Date:   Tue Jun 12 19:46:39 2018 +0200
Branches: temp-udim-images
https://developer.blender.org/rB4875f41ea6da125035364ab76c0e208ab8e2c333

Implement custom UDIM tile labeling

Not exposed in UI/RNA yet.

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

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

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

diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index 6d2caf8f93f..6d04c4b9c39 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -276,8 +276,9 @@ bool BKE_image_has_opengl_texture(struct Image *ima);
 
 /* get tile index for tiled images */
 int BKE_image_get_tile_index(struct Image *ima, struct ImageUser *iuser);
+void BKE_image_get_tile_label(struct Image *ima, int tile, char *label, int len_label);
 
-struct ImageTile *BKE_image_add_tile(struct Image *ima);
+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);
 
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 5b1ed1bb67a..7e92f354438 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -3024,7 +3024,20 @@ int BKE_image_get_tile_index(struct Image *ima, struct ImageUser *iuser)
 	return iuser->tile;
 }
 
-ImageTile *BKE_image_add_tile(struct Image *ima)
+void BKE_image_get_tile_label(Image *ima, int tile, char *label, int len_label)
+{
+	label[0] = '\0';
+	if (!ima || ima->source != IMA_SRC_TILED || tile >= ima->num_tiles) {
+		return;
+	}
+
+	if (ima->tiles[tile].label[0])
+		BLI_strncpy(label, ima->tiles[tile].label, len_label);
+	else
+		BLI_snprintf(label, len_label, "%d", 1001 + tile);
+}
+
+ImageTile *BKE_image_add_tile(struct Image *ima, const char *label)
 {
 	if (ima->source != IMA_SRC_TILED) {
 		return NULL;
@@ -3035,6 +3048,10 @@ ImageTile *BKE_image_add_tile(struct Image *ima)
 	ima->tiles = MEM_recallocN(ima->tiles, sizeof(ImageTile)*ima->num_tiles);
 	ima->tiles[tile_id].ok = 1;
 
+	if (label) {
+		BLI_strncpy(ima->tiles[tile_id].label, label, sizeof(ima->tiles[tile_id].label));
+	}
+
 	return &ima->tiles[tile_id];
 }
 
diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c
index 7a8d132efd0..f9bc0946b1e 100644
--- a/source/blender/editors/space_image/image_draw.c
+++ b/source/blender/editors/space_image/image_draw.c
@@ -478,7 +478,7 @@ static void sima_draw_zbuffloat_pixels(Scene *scene, float x1, float y1, int rec
 	MEM_freeN(rectf);
 }
 
-static void draw_image_buffer(const bContext *C, SpaceImage *sima, ARegion *ar, Scene *scene, ImBuf *ibuf, float fx, float fy, float zoomx, float zoomy)
+static void draw_image_buffer(const bContext *C, SpaceImage *sima, ARegion *ar, Scene *scene, ImBuf *ibuf, float fx, float fy, float zoomx, float zoomy, const char *label)
 {
 	int x, y;
 
@@ -546,6 +546,24 @@ static void draw_image_buffer(const bContext *C, SpaceImage *sima, ARegion *ar,
 		if (sima->flag & SI_USE_ALPHA)
 			glDisable(GL_BLEND);
 	}
+
+	if (label && label[0]) {
+		glEnable(GL_BLEND);
+		glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+		BLF_size(blf_mono_font, 25 * U.pixelsize, U.dpi);
+
+		int textwidth = BLF_width(blf_mono_font, label, strlen(label)) + 10;
+		float opacity;
+		float stepx = BLI_rcti_size_x(&ar->v2d.mask) / BLI_rctf_size_x(&ar->v2d.cur);
+		if (textwidth < 0.5f*(stepx - 10)) opacity = 1.0f;
+		else if (textwidth < (stepx - 10)) opacity = 2.0f - 2.0f*(textwidth / (stepx - 10));
+		else opacity = 0.0f;
+		BLF_color4ub(blf_mono_font, 220, 220, 220, 150*opacity);
+		BLF_position(blf_mono_font, (int) (x + 10), (int) (y + 10), 0);
+		BLF_draw_ascii(blf_mono_font, label, strlen(label));
+
+		glDisable(GL_BLEND);
+	}
 }
 
 /* draw uv edit */
@@ -687,27 +705,6 @@ static bool draw_image_udim_grid(ARegion *ar, SpaceImage *sima, float zoomx, flo
 	immEnd();
 	immUnbindProgram();
 
-	glEnable(GL_BLEND);
-	glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-    BLF_size(blf_mono_font, 25 * U.pixelsize, U.dpi);
-
-    char id[256];
-    for (int y = ymin; y < ymax; y++) {
-        for (int x = xmin; x < xmax; x++) {
-            BLI_snprintf(id, sizeof(id), "%d", 1001 + y*10 + x);
-            int textwidth = BLF_width(blf_mono_font, id, sizeof(id)) + 10;
-            float opacity;
-            if (textwidth < 0.5f*(stepx - 10)) opacity = 1.0f;
-            else if (textwidth < (stepx - 10)) opacity = 2.0f - 2.0f*(textwidth / (stepx - 10));
-            else opacity = 0.0f;
-			BLF_color4ub(blf_mono_font, 220, 220, 220, 150*opacity);
-            BLF_position(blf_mono_font, (int) (x1 + x*stepx + 10), (int) (y1 + y*stepy + 10), 0);
-            BLF_draw_ascii(blf_mono_font, id, sizeof(id));
-        }
-    }
-
-	glDisable(GL_BLEND);
-
     return true;
 }
 
@@ -782,7 +779,9 @@ void draw_image_main(const bContext *C, ARegion *ar)
 		}
 	}
 	else {
-		draw_image_buffer(C, sima, ar, scene, ibuf, 0.0f, 0.0f, zoomx, zoomy);
+		char label[64];
+		BKE_image_get_tile_label(ima, 0, label, sizeof(label));
+		draw_image_buffer(C, sima, ar, scene, ibuf, 0.0f, 0.0f, zoomx, zoomy, label);
 
 		if (sima->flag & SI_DRAW_METADATA) {
 			int x, y;
@@ -803,7 +802,9 @@ void draw_image_main(const bContext *C, ARegion *ar)
 			if (ibuf) {
 				int x_pos = t%10;
 				int y_pos = t/10;
-				draw_image_buffer(C, sima, ar, scene, ibuf, x_pos, y_pos, zoomx, zoomy);
+				char label[64];
+				BKE_image_get_tile_label(ima, t, label, sizeof(label));
+				draw_image_buffer(C, sima, ar, scene, ibuf, x_pos, y_pos, zoomx, zoomy, label);
 			}
 			ED_space_image_release_buffer(sima, ibuf, lock);
 		}
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 26a2f542788..d809ba2ac62 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -3873,7 +3873,7 @@ static int add_tile_exec(bContext *C, wmOperator *UNUSED(op))
 	SpaceImage *sima = CTX_wm_space_image(C);
 	Image *ima = ED_space_image(sima);
 
-	if (BKE_image_add_tile(ima) == NULL)
+	if (BKE_image_add_tile(ima, NULL) == NULL)
 		return OPERATOR_CANCELLED;
 
 	WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
diff --git a/source/blender/makesdna/DNA_image_types.h b/source/blender/makesdna/DNA_image_types.h
index 45abfd276c0..4338e921e94 100644
--- a/source/blender/makesdna/DNA_image_types.h
+++ b/source/blender/makesdna/DNA_image_types.h
@@ -96,6 +96,7 @@ typedef struct ImageTile {
 	struct GPUTexture *gputexture[2]; /* TEXTARGET_COUNT */
 	char ok;
 	char pad[7];
+	char label[64];
 } ImageTile;
 
 /* iuser->flag */



More information about the Bf-blender-cvs mailing list