[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12306] trunk/blender: Image Stamping patch by Diego (and peach request) - stamps image info into metadata and optionally

Campbell Barton cbarton at metavr.com
Sat Oct 20 18:17:27 CEST 2007


Revision: 12306
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12306
Author:   campbellbarton
Date:     2007-10-20 18:17:27 +0200 (Sat, 20 Oct 2007)

Log Message:
-----------
Image Stamping patch by Diego (and peach request)- stamps image info into metadata and optionally
draws into the
frame.

This patch includes some changes I made...   
* use blenders bitmap fonts (rather then own fonts)
* select font size
* user interface layout changes
* Marker as another image stamp option

Also added some new API calls   
BMF_GetFontHeight(font);
BMF_DrawStringBuf(...);  - so we can draw text into an imbuf's image buffer.
get_frame_marker(frame) - get the last marker from the frame.
IMB_rectfill_area(...) - fill in an image buffer with a rectangle area of color.

TODO - draw stamp info in 3d view, at the moment it just displays in the animation.

Modified Paths:
--------------
    trunk/blender/intern/bmfont/BMF_Api.h
    trunk/blender/intern/bmfont/intern/BMF_Api.cpp
    trunk/blender/intern/bmfont/intern/BMF_BitmapFont.cpp
    trunk/blender/intern/bmfont/intern/BMF_BitmapFont.h
    trunk/blender/source/blender/blenkernel/BKE_blender.h
    trunk/blender/source/blender/blenkernel/BKE_image.h
    trunk/blender/source/blender/blenkernel/intern/image.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/blenpluginapi/iff.h
    trunk/blender/source/blender/imbuf/IMB_imbuf.h
    trunk/blender/source/blender/imbuf/intern/IMB_imginfo.h
    trunk/blender/source/blender/imbuf/intern/imginfo.c
    trunk/blender/source/blender/imbuf/intern/png.c
    trunk/blender/source/blender/imbuf/intern/rectop.c
    trunk/blender/source/blender/imbuf/intern/thumbs.c
    trunk/blender/source/blender/include/BSE_time.h
    trunk/blender/source/blender/makesdna/DNA_scene_types.h
    trunk/blender/source/blender/src/buttons_scene.c
    trunk/blender/source/blender/src/buttons_shading.c
    trunk/blender/source/blender/src/drawview.c
    trunk/blender/source/blender/src/editmesh_tools.c
    trunk/blender/source/blender/src/edittime.c
    trunk/blender/source/blender/src/transform_constraints.c

Modified: trunk/blender/intern/bmfont/BMF_Api.h
===================================================================
--- trunk/blender/intern/bmfont/BMF_Api.h	2007-10-20 15:59:16 UTC (rev 12305)
+++ trunk/blender/intern/bmfont/BMF_Api.h	2007-10-20 16:17:27 UTC (rev 12306)
@@ -110,6 +110,11 @@
 void BMF_GetFontBoundingBox(BMF_Font* font, int *xmin_r, int *ymin_r, int *xmax_r, int *ymax_r);
 
 /**
+ * Same as GetFontBoundingBox but only returns the height
+ */
+int BMF_GetFontHeight(BMF_Font* font);
+
+/**
  * Convert the given @a font to a texture, and return the GL texture
  * ID of the texture. If the texture ID is bound, text can
  * be drawn using the texture by calling DrawStringTexture.
@@ -134,6 +139,23 @@
  */
 void BMF_DrawStringTexture(BMF_Font* font, char* string, float x, float y, float z);
 
+	/**
+ * Draw the given @a string at the point @a xpos, @a ypos using
+ * char and float buffers.
+ * 
+ * @param string The c-string to draw.
+ * @param xpos The x coordinate to start drawing at.
+ * @param ypos The y coordinate to start drawing at.
+ * @param fgcol The forground color.
+ * @param bgcol The background color.
+ * @param buf Unsigned char image buffer, when NULL to not operate on it.
+ * @param fbuf float image buffer, when NULL to not operate on it.
+ * @param w image buffer width.
+ * @param h image buffer height.
+	 */
+void BMF_DrawStringBuf(BMF_Font* font, char *str, int posx, int posy, float *col, unsigned char *buf, float *fbuf, int w, int h);
+
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/blender/intern/bmfont/intern/BMF_Api.cpp
===================================================================
--- trunk/blender/intern/bmfont/intern/BMF_Api.cpp	2007-10-20 15:59:16 UTC (rev 12305)
+++ trunk/blender/intern/bmfont/intern/BMF_Api.cpp	2007-10-20 16:17:27 UTC (rev 12306)
@@ -164,6 +164,12 @@
 	((BMF_BitmapFont*)font)->GetFontBoundingBox(*xmin_r, *ymin_r, *xmax_r, *ymax_r);
 }
 
+int BMF_GetFontHeight(BMF_Font* font)
+{
+	if (!font) return -1;
+	return ((BMF_BitmapFont*)font)->GetFontHeight();
+}
+
 int BMF_GetFontTexture(BMF_Font* font) {
 	if (!font) return -1;
 	return ((BMF_BitmapFont*)font)->GetTexture();
@@ -173,3 +179,8 @@
 	if (!font) return;
 	((BMF_BitmapFont*)font)->DrawStringTexture(string, x, y, z);
 }
+
+void BMF_DrawStringBuf(BMF_Font* font, char *str, int posx, int posy, float *col, unsigned char *buf, float *fbuf, int w, int h) {
+	if (!font) return;
+	((BMF_BitmapFont*)font)->DrawStringBuf(str, posx, posy, col, buf, fbuf, w, h);
+}

Modified: trunk/blender/intern/bmfont/intern/BMF_BitmapFont.cpp
===================================================================
--- trunk/blender/intern/bmfont/intern/BMF_BitmapFont.cpp	2007-10-20 15:59:16 UTC (rev 12305)
+++ trunk/blender/intern/bmfont/intern/BMF_BitmapFont.cpp	2007-10-20 16:17:27 UTC (rev 12306)
@@ -35,6 +35,11 @@
  * Copyright (C) 2001 NaN Technologies B.V.
  */
 
+
+#include <stdio.h>
+
+
+
 #include <string.h>
 
 #ifdef HAVE_CONFIG_H
@@ -115,6 +120,11 @@
 	yMax = m_fontData->ymax;
 }
 
+int BMF_BitmapFont::GetFontHeight( void )
+{
+	return m_fontData->ymax - m_fontData->ymin;
+}
+
 void BMF_BitmapFont::GetStringBoundingBox(char* str, float*llx, float *lly, float *urx, float *ury)
 {
 	unsigned char c;
@@ -229,3 +239,83 @@
 	}
 	glEnd();
 }
+
+#define FTOCHAR(val) val<=0.0f?0: (val>=1.0f?255: (char)(255.0f*val))
+
+
+void BMF_BitmapFont::DrawStringBuf(char *str, int posx, int posy, float *col, unsigned char *buf, float *fbuf, int w, int h)
+{
+	int x, y;
+	
+	if (buf==0 && fbuf==0)
+		return;
+
+	/*offset for font*/
+	posx -= m_fontData->xmin;
+	posy -= m_fontData->ymin;
+	
+	if (buf) {
+		unsigned char colch[3];
+		unsigned char *max, *pixel;
+		unsigned char c;
+		
+		for (x=0; x<3; x++) {
+			colch[x] = FTOCHAR(col[x]);
+		}
+		
+		max = buf + (4 * (w * h));
+		while ((c = (unsigned char) *str++)) {
+			BMF_CharData & cd = m_fontData->chars[c];
+			if (cd.data_offset != -1) { 
+				for (y = 0; y < cd.height; y++) {
+					unsigned char* chrRow = &m_fontData->bitmap_data[cd.data_offset + ((cd.width+7)/8)*y];
+					for (x = cd.xorig; x < cd.width; x++) {
+						pixel = buf + 4 * (((posy + y) * w) + (posx + x));
+						if ((pixel < max) && (pixel > buf)) {
+							int byteIdx = x/8;
+							int bitIdx = 7 - (x%8);
+							
+							if (chrRow[byteIdx]&(1<<bitIdx)) {
+								pixel[0] = colch[0];
+								pixel[1] = colch[1];
+								pixel[2] = colch[2];
+							}
+						}
+					}
+				}
+			}
+			posx += cd.advance;
+		}
+	}
+	
+	if (fbuf) {
+		float *pixel, *max;
+		unsigned char c;
+		int x, y;
+		
+		max = fbuf + (4 * (w * h));
+		
+		while ((c = (unsigned char) *str++)) {
+			BMF_CharData & cd = m_fontData->chars[c];
+			if (cd.data_offset != -1) { 
+				for (y = 0; y < cd.height; y++) {
+					unsigned char* chrRow = &m_fontData->bitmap_data[cd.data_offset + ((cd.width+7)/8)*y];
+					for (x = cd.xorig; x < cd.width; x++) {
+						pixel = fbuf + 4 * (((posy + y - cd.yorig) * w) + (posx + x));
+						if ((pixel < max) && (pixel > fbuf)) {
+							int byteIdx = x/8;
+							int bitIdx = 7 - (x%8);
+							
+							if (chrRow[byteIdx]&(1<<bitIdx)) {
+								pixel[0] = col[0];
+								pixel[1] = col[1];
+								pixel[2] = col[2];
+							}
+						}
+					}
+				}
+			}
+			posx += cd.advance;
+		}
+	}
+}

Modified: trunk/blender/intern/bmfont/intern/BMF_BitmapFont.h
===================================================================
--- trunk/blender/intern/bmfont/intern/BMF_BitmapFont.h	2007-10-20 15:59:16 UTC (rev 12305)
+++ trunk/blender/intern/bmfont/intern/BMF_BitmapFont.h	2007-10-20 16:17:27 UTC (rev 12306)
@@ -79,6 +79,11 @@
 	void GetFontBoundingBox(int & xMin, int & yMin, int & xMax, int & yMax);
 	
 	/**
+	 * Return the bounding box height of the font.
+	 */
+	int GetFontHeight(void);
+	
+	/**
 	 * Returns the bounding box of a string of characters.
 	 * @param font	The font to use.
 	 * @param str	The string.
@@ -113,6 +118,21 @@
 	 */
 	void DrawStringTexture(char* string, float x, float y, float z);
 	
+	/**
+	 * Draw the given @a string at the point @a xpos, @a ypos using
+	 * char and float buffers.
+	 * 
+	 * @param string The c-string to draw.
+	 * @param xpos The x coordinate to start drawing at.
+	 * @param ypos The y coordinate to start drawing at.
+	 * @param col The forground color.
+	 * @param buf Unsigned char image buffer, when NULL to not operate on it.
+	 * @param fbuf float image buffer, when NULL to not operate on it.
+	 * @param w image buffer width.
+	 * @param h image buffer height.
+	 */
+	void DrawStringBuf(char *str, int posx, int posy, float *col, unsigned char *buf, float *fbuf, int w, int h);
+	
 protected:
 	/** Pointer to the font data. */
 	 BMF_FontData* m_fontData;

Modified: trunk/blender/source/blender/blenkernel/BKE_blender.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_blender.h	2007-10-20 15:59:16 UTC (rev 12305)
+++ trunk/blender/source/blender/blenkernel/BKE_blender.h	2007-10-20 16:17:27 UTC (rev 12306)
@@ -44,7 +44,7 @@
 struct MemFile;
 
 #define BLENDER_VERSION			245
-#define BLENDER_SUBVERSION		4
+#define BLENDER_SUBVERSION		5
 
 #define BLENDER_MINVERSION		240
 #define BLENDER_MINSUBVERSION	0

Modified: trunk/blender/source/blender/blenkernel/BKE_image.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_image.h	2007-10-20 15:59:16 UTC (rev 12305)
+++ trunk/blender/source/blender/blenkernel/BKE_image.h	2007-10-20 16:17:27 UTC (rev 12306)
@@ -46,6 +46,7 @@
 /* call from library */
 void	free_image(struct Image *me);
 
+void	BKE_stamp(struct ImBuf *ibuf);
 int		BKE_write_ibuf(struct ImBuf *ibuf, char *name, int imtype, int subimtype, int quality);
 void	BKE_makepicstring(char *string, char *base, int frame, int imtype);
 void	BKE_add_image_extension(char *string, int imtype);

Modified: trunk/blender/source/blender/blenkernel/intern/image.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image.c	2007-10-20 15:59:16 UTC (rev 12305)
+++ trunk/blender/source/blender/blenkernel/intern/image.c	2007-10-20 16:17:27 UTC (rev 12306)
@@ -52,6 +52,7 @@
 #include "DNA_image_types.h"
 #include "DNA_packedFile_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_camera_types.h"
 #include "DNA_texture_types.h"
 #include "DNA_userdef_types.h"
 
@@ -77,6 +78,12 @@
 /* bad level; call to free_realtime_image */
 #include "BKE_bad_level_calls.h"	
 
+/* for stamp drawing to an image */
+#include "../bmfont/BMF_Api.h"
+
+#include "blendef.h"
+#include "BSE_time.h"
+
 /* max int, to indicate we don't store sequences in ibuf */
 #define IMA_NO_INDEX	0x7FEFEFEF
 
@@ -770,7 +777,184 @@
 	strcat(string, extension);
 }
 
+void BKE_stamp(struct ImBuf *ibuf)
+{
+	char text[256], infotext[256];
+	int x, y, h, m, s, f;
+	int font_height;
+	int text_width;
+	int text_pad;
+	struct BMF_Font *font;
+	
+	
+#ifndef WIN32
+	struct tm *tl;
+	time_t t;
+#else
+	char sdate[9];
+#endif /* WIN32 */
 
+	if (!ibuf)
+		return;
+	
+	switch (G.scene->r.stamp_font_id) {
+	case 1: /* tiny */
+		font = BMF_GetFont(BMF_kHelveticaBold8);
+		break;
+	case 2: /* small */
+		font = BMF_GetFont(BMF_kHelveticaBold10);
+		break;
+	case 3: /* medium */
+		font = BMF_GetFont(BMF_kScreen12);
+		break;
+	case 0: /* large - default */
+		font = BMF_GetFont(BMF_kScreen15);
+		break;
+	case 4: /* huge */
+		font = BMF_GetFont(BMF_kHelveticaBold14);
+		break;
+	}
+	
+	font_height = BMF_GetFontHeight(font);
+	text_pad = BMF_GetStringWidth(font, " ");
+	
+	IMB_imginfo_change_field (ibuf, "File", G.sce);
+	if (G.scene->r.stamp & R_STAMP_DRAW) {
+		x = 1;
+		y = ibuf->y - font_height;
+		sprintf(text, "File: %s", G.sce);
+		text_width = BMF_GetStringWidth(font, text);
+		IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
+		BMF_DrawStringBuf(font, G.sce, x, y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
+		x = 1;
+		y -= font_height+1;
+	}
+
+
+	if (G.scene->r.stamp & R_STAMP_TIME) {
+		h= m= s= f= 0;
+		f = (int)(G.scene->r.cfra % G.scene->r.frs_sec);
+		s = (int)(G.scene->r.cfra / G.scene->r.frs_sec);
+
+		if (s) {
+			m = (int)(s / 60);
+			s %= 60;
+
+			if (m) {
+				h = (int)(m / 60);
+				m %= 60;
+			}
+		}
+
+		if (G.scene->r.frs_sec < 100)
+			sprintf (infotext, "%02d:%02d:%02d.%02d", h, m, s, f);
+		else
+			sprintf (infotext, "%02d:%02d:%02d.%03d", h, m, s, f);
+		

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list