[Bf-blender-cvs] [5b4dfa6] temp-blf-wordwrap: Move color conversion out of blf_font_draw_buffer

Campbell Barton noreply at git.blender.org
Thu Sep 17 21:20:45 CEST 2015


Commit: 5b4dfa6b173e5c5bc575922e7d695a498e5557bb
Author: Campbell Barton
Date:   Fri Sep 18 05:13:36 2015 +1000
Branches: temp-blf-wordwrap
https://developer.blender.org/rB5b4dfa6b173e5c5bc575922e7d695a498e5557bb

Move color conversion out of blf_font_draw_buffer

So drawing each line doesn't need to re-convert colors.

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

M	source/blender/blenfont/intern/blf.c
M	source/blender/blenfont/intern/blf_font.c
M	source/blender/blenfont/intern/blf_internal_types.h
M	source/blender/blenfont/intern/blf_thumbs.c

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

diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index 12a1b08..8a48384 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -53,6 +53,8 @@
 #include "BIF_gl.h"
 #include "BLF_api.h"
 
+#include "IMB_colormanagement.h"
+
 #include "blf_internal_types.h"
 #include "blf_internal.h"
 
@@ -496,7 +498,7 @@ void BLF_rotation_default(float angle)
 	}
 }
 
-static void blf_draw__start(FontBLF *font, GLint *mode, GLint *param)
+static void blf_draw_gl__start(FontBLF *font, GLint *mode, GLint *param)
 {
 	/*
 	 * The pixmap alignment hack is handle
@@ -540,7 +542,7 @@ static void blf_draw__start(FontBLF *font, GLint *mode, GLint *param)
 		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 }
 
-static void blf_draw__end(GLint mode, GLint param)
+static void blf_draw_gl__end(GLint mode, GLint param)
 {
 	/* and restore the original value. */
 	if (param != GL_MODULATE)
@@ -569,14 +571,14 @@ void BLF_draw_ex(
 	BLF_RESULT_CHECK_INIT(r_info);
 
 	if (font && font->glyph_cache) {
-		blf_draw__start(font, &mode, &param);
+		blf_draw_gl__start(font, &mode, &param);
 		if (font->flags & BLF_WORD_WRAP) {
 			blf_font_draw__wrap(font, str, len, r_info);
 		}
 		else {
 			blf_font_draw(font, str, len, r_info);
 		}
-		blf_draw__end(mode, param);
+		blf_draw_gl__end(mode, param);
 	}
 }
 void BLF_draw(int fontid, const char *str, size_t len)
@@ -594,7 +596,7 @@ void BLF_draw_ascii_ex(
 	BLF_RESULT_CHECK_INIT(r_info);
 
 	if (font && font->glyph_cache) {
-		blf_draw__start(font, &mode, &param);
+		blf_draw_gl__start(font, &mode, &param);
 		if (font->flags & BLF_WORD_WRAP) {
 			/* use non-ascii draw function for word-wrap */
 			blf_font_draw__wrap(font, str, len, r_info);
@@ -602,7 +604,7 @@ void BLF_draw_ascii_ex(
 		else {
 			blf_font_draw_ascii(font, str, len, r_info);
 		}
-		blf_draw__end(mode, param);
+		blf_draw_gl__end(mode, param);
 	}
 }
 void BLF_draw_ascii(int fontid, const char *str, size_t len)
@@ -617,9 +619,9 @@ int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth)
 	int columns = 0;
 
 	if (font && font->glyph_cache) {
-		blf_draw__start(font, &mode, &param);
+		blf_draw_gl__start(font, &mode, &param);
 		columns = blf_font_draw_mono(font, str, len, cwidth);
-		blf_draw__end(mode, param);
+		blf_draw_gl__end(mode, param);
 	}
 
 	return columns;
@@ -901,12 +903,29 @@ void BLF_buffer_col(int fontid, float r, float g, float b, float a)
 	FontBLF *font = blf_get(fontid);
 
 	if (font) {
-		font->buf_info.col[0] = r;
-		font->buf_info.col[1] = g;
-		font->buf_info.col[2] = b;
-		font->buf_info.col[3] = a;
+		ARRAY_SET_ITEMS(font->buf_info.col_init, r, g, b, a);
+	}
+}
+
+
+static void blf_draw_buffer__start(FontBLF *font)
+{
+	FontBufInfoBLF *buf_info = &font->buf_info;
+
+	buf_info->col_char[0] = buf_info->col_init[0] * 255;
+	buf_info->col_char[1] = buf_info->col_init[1] * 255;
+	buf_info->col_char[2] = buf_info->col_init[2] * 255;
+	buf_info->col_char[3] = buf_info->col_init[3] * 255;
+
+	if (buf_info->display) {
+		copy_v4_v4(buf_info->col_float, buf_info->col_init);
+		IMB_colormanagement_display_to_scene_linear_v3(buf_info->col_float, buf_info->display);
+	}
+	else {
+		srgb_to_linearrgb_v4(buf_info->col_float, buf_info->col_init);
 	}
 }
+static void blf_draw_buffer__end(void) {}
 
 void BLF_draw_buffer_ex(
         int fontid, const char *str, size_t len,
@@ -915,12 +934,14 @@ void BLF_draw_buffer_ex(
 	FontBLF *font = blf_get(fontid);
 
 	if (font && font->glyph_cache && (font->buf_info.fbuf || font->buf_info.cbuf)) {
+		blf_draw_buffer__start(font);
 		if (font->flags & BLF_WORD_WRAP) {
 			blf_font_draw_buffer__wrap(font, str, len, r_info);
 		}
 		else {
 			blf_font_draw_buffer(font, str, len, r_info);
 		}
+		blf_draw_buffer__end();
 	}
 }
 void BLF_draw_buffer(
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 21427a1..27a6685 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -58,8 +58,6 @@
 #include "BIF_gl.h"
 #include "BLF_api.h"
 
-#include "IMB_colormanagement.h"
-
 #include "blf_internal_types.h"
 #include "blf_internal.h"
 
@@ -304,13 +302,8 @@ static void blf_font_draw_buffer_ex(
 
 	/* buffer specific vars */
 	FontBufInfoBLF *buf_info = &font->buf_info;
-	float b_col_float[4];
-	const unsigned char b_col_char[4] = {
-	    (unsigned char)(buf_info->col[0] * 255),
-	    (unsigned char)(buf_info->col[1] * 255),
-	    (unsigned char)(buf_info->col[2] * 255),
-	    (unsigned char)(buf_info->col[3] * 255)};
-
+	const float *b_col_float = buf_info->col_float;
+	const unsigned char *b_col_char = buf_info->col_char;
 	int chx, chy;
 	int y, x;
 	float a;
@@ -320,13 +313,6 @@ static void blf_font_draw_buffer_ex(
 	blf_font_ensure_ascii_table(font);
 
 	/* another buffer specific call for color conversion */
-	if (buf_info->display) {
-		copy_v4_v4(b_col_float, buf_info->col);
-		IMB_colormanagement_display_to_scene_linear_v3(b_col_float, buf_info->display);
-	}
-	else {
-		srgb_to_linearrgb_v4(b_col_float, buf_info->col);
-	}
 
 	while ((i < len) && str[i]) {
 		BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
@@ -955,10 +941,10 @@ static void blf_font_fill(FontBLF *font)
 	font->buf_info.w = 0;
 	font->buf_info.h = 0;
 	font->buf_info.ch = 0;
-	font->buf_info.col[0] = 0;
-	font->buf_info.col[1] = 0;
-	font->buf_info.col[2] = 0;
-	font->buf_info.col[3] = 0;
+	font->buf_info.col_init[0] = 0;
+	font->buf_info.col_init[1] = 0;
+	font->buf_info.col_init[2] = 0;
+	font->buf_info.col_init[3] = 0;
 
 	font->ft_lib = ft_lib;
 	font->ft_lib_mutex = &ft_lib_mutex;
diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h
index b613702..f17401a 100644
--- a/source/blender/blenfont/intern/blf_internal_types.h
+++ b/source/blender/blenfont/intern/blf_internal_types.h
@@ -152,7 +152,11 @@ typedef struct FontBufInfoBLF {
 
 	/* and the color, the alphas is get from the glyph!
 	 * color is srgb space */
-	float col[4];
+	float col_init[4];
+	/* cached conversion from 'col_init' */
+	unsigned char col_char[4];
+	float col_float[4];
+
 } FontBufInfoBLF;
 
 typedef struct FontBLF {
diff --git a/source/blender/blenfont/intern/blf_thumbs.c b/source/blender/blenfont/intern/blf_thumbs.c
index a2ba376..7647959 100644
--- a/source/blender/blenfont/intern/blf_thumbs.c
+++ b/source/blender/blenfont/intern/blf_thumbs.c
@@ -84,7 +84,7 @@ void BLF_thumb_preview(
 
 	/* Always create the image with a white font,
 	 * the caller can theme how it likes */
-	memcpy(font->buf_info.col, font_color, sizeof(font->buf_info.col));
+	memcpy(font->buf_info.col_init, font_color, sizeof(font->buf_info.col_init));
 	font->pos[1] = (float)h;
 
 	font_size_curr = font_size;




More information about the Bf-blender-cvs mailing list