[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53166] trunk/blender/source/blender/ editors/interface/interface_icons.c: DPI: icons were still drawing with color fringing when scaled up/down, opengl

Brecht Van Lommel brechtvanlommel at pandora.be
Wed Dec 19 11:13:00 CET 2012


Revision: 53166
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53166
Author:   blendix
Date:     2012-12-19 10:12:58 +0000 (Wed, 19 Dec 2012)
Log Message:
-----------
DPI: icons were still drawing with color fringing when scaled up/down, opengl
texture needs to be premul alpha for correct results.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/interface/interface_icons.c

Modified: trunk/blender/source/blender/editors/interface/interface_icons.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_icons.c	2012-12-19 09:50:31 UTC (rev 53165)
+++ trunk/blender/source/blender/editors/interface/interface_icons.c	2012-12-19 10:12:58 UTC (rev 53166)
@@ -467,7 +467,10 @@
 		bbuf = IMB_ibImageFromMemory((unsigned char *)datatoc_ ##name## _png, \
 		                             datatoc_ ##name## _png_size,             \
 		                             IB_rect, NULL, "<brush icon>");          \
-		def_internal_icon(bbuf, icon_id, 0, 0, w, ICON_TYPE_BUFFER);          \
+		if (bbuf) {                                                           \
+			IMB_premultiply_alpha(bbuf);                                      \
+			def_internal_icon(bbuf, icon_id, 0, 0, w, ICON_TYPE_BUFFER);      \
+		}                                                                     \
 		IMB_freeImBuf(bbuf);                                                  \
 	} (void)0
 	/* end INIT_BRUSH_ICON */
@@ -537,10 +540,14 @@
 	if (b16buf == NULL)
 		b16buf = IMB_ibImageFromMemory((unsigned char *)datatoc_blender_icons16_png,
 		                             datatoc_blender_icons16_png_size, IB_rect, NULL, "<blender icons>");
+	if (b16buf)
+		IMB_premultiply_alpha(b16buf);
 
 	if (b32buf == NULL)
 		b32buf = IMB_ibImageFromMemory((unsigned char *)datatoc_blender_icons32_png,
 		                             datatoc_blender_icons32_png_size, IB_rect, NULL, "<blender icons>");
+	if (b32buf)
+		IMB_premultiply_alpha(b32buf);
 	
 	if (b16buf && b32buf) {
 		/* free existing texture if any */
@@ -940,8 +947,8 @@
 {
 	float x1, x2, y1, y2;
 
-	if (rgb) glColor4f(rgb[0], rgb[1], rgb[2], alpha);
-	else glColor4f(1.0f, 1.0f, 1.0f, alpha);
+	if (rgb) glColor4f(alpha*rgb[0], rgb[1], rgb[2], alpha);
+	else glColor4f(alpha, alpha, alpha, alpha);
 
 	x1 = ix * icongltex.invw;
 	x2 = (ix + ih) * icongltex.invw;
@@ -1017,8 +1024,11 @@
 		di->data.vector.func((int)x, (int)y, ICON_DEFAULT_HEIGHT, ICON_DEFAULT_HEIGHT, 1.0f); 
 	}
 	else if (di->type == ICON_TYPE_TEXTURE) {
+		/* texture image use premul alpha for correct scaling */
+		glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
 		icon_draw_texture(x, y, (float)w, (float)h, di->data.texture.x, di->data.texture.y,
 		                  di->data.texture.w, di->data.texture.h, alpha, rgb);
+		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 	}
 	else if (di->type == ICON_TYPE_BUFFER) {
 		/* it is a builtin icon */
@@ -1026,7 +1036,9 @@
 
 		if (!iimg->rect) return;  /* something has gone wrong! */
 
+		glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
 		icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, rgb, is_preview);
+		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 	}
 	else if (di->type == ICON_TYPE_PREVIEW) {
 		PreviewImage *pi = BKE_previewimg_get((ID *)icon->obj);




More information about the Bf-blender-cvs mailing list