[Bf-blender-cvs] [50bfc4b] master: Metadata display support - patch by Julian and me.

Antony Riakiotakis noreply at git.blender.org
Tue Apr 21 18:37:35 CEST 2015


Commit: 50bfc4bfa0eabb68fcb5b5e82f80281fbaddcfeb
Author: Antony Riakiotakis
Date:   Mon Apr 20 19:57:57 2015 +0200
Branches: master
https://developer.blender.org/rB50bfc4bfa0eabb68fcb5b5e82f80281fbaddcfeb

Metadata display support - patch by Julian and me.

Basically, blender adds a few metadata fields to images when
we render an image. Those metadata can now be viewed in the
image editor.

Also, made sure metadata are available when we write imbufs
to disc with "Save As". There may be more cases here that need
fixing, but this means that loading an image with metadata
will now properly preserve them in blender.

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

M	release/scripts/startup/bl_ui/space_image.py
M	source/blender/editors/include/ED_screen.h
M	source/blender/editors/include/ED_util.h
M	source/blender/editors/screen/area.c
M	source/blender/editors/space_image/image_draw.c
M	source/blender/editors/space_image/image_ops.c
M	source/blender/editors/space_image/space_image.c
M	source/blender/editors/util/CMakeLists.txt
M	source/blender/imbuf/IMB_imbuf.h
M	source/blender/imbuf/intern/IMB_metadata.h
M	source/blender/imbuf/intern/metadata.c
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/release/scripts/startup/bl_ui/space_image.py b/release/scripts/startup/bl_ui/space_image.py
index e454216..bd48116 100644
--- a/release/scripts/startup/bl_ui/space_image.py
+++ b/release/scripts/startup/bl_ui/space_image.py
@@ -84,6 +84,7 @@ class IMAGE_MT_view(Menu):
             layout.prop(toolsettings, "show_uv_local_view")
 
         layout.prop(uv, "show_other_objects")
+        layout.prop(uv, "show_metadata")
         if paint.brush and (context.image_paint_object or sima.mode == 'PAINT'):
             layout.prop(uv, "show_texpaint")
             layout.prop(toolsettings, "show_uv_local_view", text="Show same material")
diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h
index 90b0b35..b7c261c 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -66,6 +66,7 @@ void    ED_region_header_init(struct ARegion *ar);
 void    ED_region_header(const struct bContext *C, struct ARegion *ar);
 void    ED_region_toggle_hidden(struct bContext *C, struct ARegion *ar);
 void    ED_region_info_draw(struct ARegion *ar, const char *text, int block, float fill_color[4]);
+void    ED_region_image_metadata_draw(struct ARegion *ar, struct ImBuf *ibuf, float zoomx, float zoomy);
 void    ED_region_grid_draw(struct ARegion *ar, float zoomx, float zoomy);
 float	ED_region_blend_factor(struct ARegion *ar);
 void	ED_region_visible_rect(struct ARegion *ar, struct rcti *rect);
diff --git a/source/blender/editors/include/ED_util.h b/source/blender/editors/include/ED_util.h
index 9556c60..96d7828 100644
--- a/source/blender/editors/include/ED_util.h
+++ b/source/blender/editors/include/ED_util.h
@@ -42,6 +42,8 @@ void    ED_editors_exit(struct bContext *C);
 
 bool    ED_editors_flush_edits(const struct bContext *C, bool for_render);
 
+void ED_draw_ibuf_meta_data(const bContext *C, struct ImBuf *ibuf);
+
 /* ************** Undo ************************ */
 
 /* undo.c */
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index d786c0c..1c87d95 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -61,6 +61,9 @@
 #include "BIF_glutil.h"
 #include "BLF_api.h"
 
+#include "IMB_imbuf.h"
+#include "IMB_imbuf_types.h"
+
 #include "UI_interface.h"
 #include "UI_interface_icons.h"
 #include "UI_resources.h"
@@ -2027,6 +2030,200 @@ void ED_region_info_draw(ARegion *ar, const char *text, int block, float fill_co
 	glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
 }
 
+#define MAX_METADATA_STR    1024
+
+const char *meta_data_list[] =
+{
+	"File",
+	"Strip",
+	"Note",
+	"Date",
+	"RenderTime",
+	"Marker",
+	"Time",
+	"Frame",
+	"Camera",
+	"Scene"
+};
+
+BLI_INLINE bool metadata_is_valid(ImBuf *ibuf, char *r_str, short index)
+{
+	return (IMB_metadata_get_field(ibuf, meta_data_list[index], r_str, MAX_METADATA_STR) && r_str[0]);
+}
+
+static void metadata_draw_lines(ImBuf *ibuf, rcti rect, int fontid, const bool is_top)
+{
+	char temp_str[MAX_METADATA_STR];
+	int line_width, line_height;
+	int ofs_y = 0;
+	short line_index;
+	short i;
+
+	for (line_index = 0; line_index < 4 && is_top == true; line_index++) {
+		/* first line */
+		if (line_index == 0) {
+			int len;
+			bool do_newline = false;
+			float height = 0.0;
+			BLI_snprintf(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[0]);
+			len = strlen(temp_str);
+			if (metadata_is_valid(ibuf, temp_str + len, 0)) {
+				BLF_position(fontid, rect.xmin + (0.2f * U.widget_unit),
+				             rect.ymax - (1.5f * U.widget_unit - UI_UNIT_Y), 0.0f);
+				BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
+				do_newline = true;
+				height = BLF_height(fontid, temp_str, strlen(temp_str));
+			}
+
+			BLI_snprintf(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[0]);
+			len = strlen(temp_str);
+			if (metadata_is_valid(ibuf, temp_str + len, 1)) {
+				len = strlen(temp_str);
+				line_width = BLF_width(fontid, temp_str, len);
+				BLF_position(fontid, rect.xmax - line_width - (0.2f * U.widget_unit),
+				             rect.ymax - (1.5f * U.widget_unit - UI_UNIT_Y), 0.0f);
+				BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
+				do_newline = true;
+				height = max_ff(BLF_height(fontid, temp_str, len), height);
+			}
+
+			if (do_newline)
+				ofs_y += (height + (0.2f * U.widget_unit));
+		}
+		else if (line_index == 1) {
+			if (metadata_is_valid(ibuf, temp_str, line_index + 1)) {
+				BLF_position(fontid, rect.xmin + (0.2f * U.widget_unit),
+				             rect.ymax - (1.5f * U.widget_unit - UI_UNIT_Y) - ofs_y, 0.0f);
+				BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
+				ofs_y += (BLF_height(fontid, temp_str, strlen(temp_str)) + (0.2f * U.widget_unit));
+			}
+		}
+		else {
+			if (metadata_is_valid(ibuf, temp_str, line_index + 1)) {
+				BLF_position(fontid, rect.xmax + (0.2f * U.widget_unit),
+				             rect.ymax - (1.5f * U.widget_unit - UI_UNIT_Y) - ofs_y, 0.0f);
+				BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
+				ofs_y += (BLF_height(fontid, temp_str, strlen(temp_str)) + (0.2f * U.widget_unit));
+			}
+		}
+	}
+
+	if (is_top == false) {
+		int ofs_x = 0;
+		for (i = 5; i < 10; i++) {
+			if (metadata_is_valid(ibuf, temp_str, i)) {
+				line_height = BLF_height(fontid, temp_str, strlen(temp_str));
+				BLF_position(fontid, rect.xmin + (0.2f * U.widget_unit) + ofs_x,
+				             rect.ymin - line_height + (1.5f * U.widget_unit), 0.0f);
+				BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
+	
+				ofs_x += BLF_width(fontid, temp_str, strlen(temp_str)) + UI_UNIT_X;
+			}
+		}
+	}
+}
+
+static float metadata_box_height_get(ImBuf *ibuf, int fontid, const bool is_top)
+{
+	char str[MAX_METADATA_STR];
+	float height = 0;
+	short i;
+
+	if (is_top) {
+		for (i = 0; i < 5 ; i++) {
+			if (metadata_is_valid(ibuf, str, i)) {
+				height += BLF_height(fontid, str, strlen(str));
+			}
+		}
+	}
+	else {
+		for (i = 5; i < 10; i++) {
+			if (metadata_is_valid(ibuf, str, i)) {
+				height += BLF_height(fontid, str, strlen(str));
+			}
+		}
+	}
+
+	if (height) {
+		return (height + (0.2f * U.widget_unit));
+	}
+
+	return 0;
+}
+
+#undef MAX_METADATA_STR
+
+void ED_region_image_metadata_draw(ARegion *ar, ImBuf *ibuf, float zoomx, float zoomy)
+{
+	uiStyle *style = UI_style_get_dpi();
+	int fontid = style->widget.uifont_id;
+	float box_y;
+	rcti rect;
+	int x, y;
+
+	if (!ibuf->metadata)
+		return;
+
+	/* find window pixel coordinates of origin */
+	UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);
+
+	glPushMatrix();
+
+	/* offset and zoom using ogl */
+	glTranslatef(x, y, 0.0f);
+	glScalef(zoomx, zoomy, 1.0f);
+
+	/* *** upper box*** */
+
+	/* get needed box height */
+	box_y = metadata_box_height_get(ibuf, fontid, true);
+
+	if (box_y) {
+		glColor3f(0.1f, 0.1f, 0.1f);
+		//glColor3f(1.0f, 0.15f, 0.8f); /* Pinkyfied version for Pablo */
+
+		/* set up rect */
+		BLI_rcti_init(&rect, 0, ibuf->x, ibuf->y, ibuf->y + box_y);
+		/* draw top box */
+		glRecti(rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+
+		BLF_clipping(fontid, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+		BLF_enable(fontid, BLF_CLIPPING);
+
+		glColor3f(1.0f, 1.0f, 1.0f);
+
+		metadata_draw_lines(ibuf, rect, fontid, true);
+
+		BLF_disable(fontid, BLF_CLIPPING);
+	}
+
+
+	/* *** lower box*** */
+
+	box_y = metadata_box_height_get(ibuf, fontid, false);
+
+	if (box_y) {
+		glColor3f(0.1f, 0.1f, 0.1f);
+		//glColor3f(1.0f, 0.15f, 0.8f); /* Pinkyfied version for Pablo */
+
+		/* set up box rect */
+		BLI_rcti_init(&rect, 0, ibuf->x, -box_y, 0);
+		/* draw top box */
+		glRecti(rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+
+		BLF_clipping(fontid, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+		BLF_enable(fontid, BLF_CLIPPING);
+
+		glColor3f(1.0f, 1.0f, 1.0f);
+
+		metadata_draw_lines(ibuf, rect, fontid, false);
+
+		BLF_disable(fontid, BLF_CLIPPING);
+	}
+
+	glPopMatrix();
+}
+
 void ED_region_grid_draw(ARegion *ar, float zoomx, float zoomy)
 {
 	float gridsize, gridstep = 1.0f / 32.0f;
diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c
index 5a3c3e9..04e874b 100644
--- a/source/blender/editors/space_image/image_draw.c
+++ b/source/blender/editors/space_image/image_draw.c
@@ -836,14 +836,23 @@ void draw_image_main(const bContext *C, ARegion *ar)
 	ibuf = ED_space_image_acquire_buffer(sima, &lock);
 
 	/* draw the image or grid */
-	if (ibuf == NULL)
+	if (ibuf == NULL) {
 		ED_region_grid_draw(ar, zoomx, zoomy);
-	else if (sima->flag & SI_DRAW_TILE)
-		draw_image_buffer_repeated(C, sima, ar, scene, ima, ibuf, zoomx, zoomy);
-	else if (ima && (ima->tpageflag & IMA_TILES))
-		draw_image_buffer_tiled(sima, ar, scene, ima, ibuf, 0.0f, 0.0, zoomx, zoomy);
-	else
-		draw_image_buffer(C, sima, ar, scene, ibuf, 0.0f, 0.0f, zoomx, zoomy);
+	}
+	else {
+
+		if (sima->flag & SI_DRAW_TILE)
+			draw_image_buffer_repeated(C, sima, ar, scene, ima, ibuf, zoomx, zoomy);
+		else if (ima && (ima->tpageflag & IMA_TILES))
+			draw_image_buffer_tiled(sima, ar, scene, ima, ibuf, 0.0f, 0.0, zoomx, zoomy);
+		else
+			draw_image_buffer(C, sima, ar, scene, ibuf, 0.0f, 0.0f, zoomx, zoomy);
+		
+		if (sima->flag & SI_DRAW_METADATA)
+			ED_region_image_metadata_draw(ar, ibuf, zoomx, zoomy);
+	}
+
+	ED_space_image_release_buffer(sima, ibuf, lock);
 
 	/* paint helpers */
 	if (show_paint)
@@ -866,8 +875,6 @@ void draw_image_main(const bContext *C, ARegion *ar)
 	}
 #endif
 
-	ED_space_image_release_buffer(sima, ibuf, lock);
-
 	if (show_viewer) {
 		BLI_unlock_thread(LOCK_DRAW_IMAGE);
 	}
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 756f90f..2fe2e66 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -1672,6 +1672,12 @@ static bool save_image_doit(bContext *C, SpaceImage *sima, wmOperator *op, SaveI
 					goto cleanup;
 				}
 			}
+			if (1) {
+				Scene *scene = CTX_data_scene(C);
+				if (scene && scene->camera) {
+					BKE_imbuf_stamp_info(scene, scene->camera, ibuf);
+				}
+			}
 		}
 
 		/* fancy multiview OpenEXR */
@@ -1693,6 +1699,7 @@ static bool save

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list