[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53563] trunk/blender/source/blender: There was a typo in previous commit

Sergey Sharybin sergey.vfx at gmail.com
Fri Jan 4 21:34:14 CET 2013


Revision: 53563
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53563
Author:   nazgul
Date:     2013-01-04 20:34:06 +0000 (Fri, 04 Jan 2013)
Log Message:
-----------
There was a typo in previous commit

Additional changes:

- Made mipmapping operate with unsigned short instead of char
  which allowed to eliminate extra division by 255, so prevision
  should be a bit better now.

- Actually, this is not real unsigned short range, but it's a
  range of 255*255 which is more convenient for mipmapping, so
  made conversion functions private for scaling.c

  Not sure it worth making this functions operate in 65535
  range, for now current behavior seems to be just fine.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_math_color.h
    trunk/blender/source/blender/blenlib/intern/math_color_inline.c
    trunk/blender/source/blender/imbuf/intern/scaling.c

Modified: trunk/blender/source/blender/blenlib/BLI_math_color.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_color.h	2013-01-04 18:19:07 UTC (rev 53562)
+++ trunk/blender/source/blender/blenlib/BLI_math_color.h	2013-01-04 20:34:06 UTC (rev 53563)
@@ -106,8 +106,6 @@
 MINLINE void straight_to_premul_v4(float straight[4], const float premul[4]);
 MINLINE void straight_uchar_to_premul_float(float result[4], const unsigned char color[4]);
 MINLINE void premul_float_to_straight_uchar(unsigned char *result, const float color[4]);
-MINLINE void straight_uchar_to_premul_int(int result[4], const unsigned char color[4]);
-MINLINE void premul_int_to_straight_uchar(unsigned char *result, const int color[4]);
 
 /************************** Other *************************/
 

Modified: trunk/blender/source/blender/blenlib/intern/math_color_inline.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_color_inline.c	2013-01-04 18:19:07 UTC (rev 53562)
+++ trunk/blender/source/blender/blenlib/intern/math_color_inline.c	2013-01-04 20:34:06 UTC (rev 53563)
@@ -326,32 +326,4 @@
 	}
 }
 
-MINLINE void straight_uchar_to_premul_int(int result[4], const unsigned char color[4])
-{
-	int alpha = color[3];
-
-	result[0] = (color[0] * alpha) / 255;
-	result[1] = (color[1] * alpha) / 255;
-	result[2] = (color[2] * alpha) / 255;
-	result[3] = alpha;
-}
-
-MINLINE void premul_int_to_straight_uchar(unsigned char *result, const int color[4])
-{
-	if (color[3] == 0 || color[3] == 255) {
-		result[0] = color[0];
-		result[1] = color[1];
-		result[2] = color[2];
-		result[3] = color[3];
-	}
-	else {
-		int alpha = color[3];
-
-		result[0] = color[0] * 255 / alpha;
-		result[0] = color[1] * 255 / alpha;
-		result[0] = color[2] * 255 / alpha;
-		result[3] = alpha;
-	}
-}
-
 #endif /* __MATH_COLOR_INLINE_C__ */

Modified: trunk/blender/source/blender/imbuf/intern/scaling.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/scaling.c	2013-01-04 18:19:07 UTC (rev 53562)
+++ trunk/blender/source/blender/imbuf/intern/scaling.c	2013-01-04 20:34:06 UTC (rev 53563)
@@ -292,6 +292,37 @@
 	return (ibuf2);
 }
 
+/* pretty much specific functions which converts uchar <-> ushort but assumes
+ * ushort range of 255*255 which is more convenient here
+ */
+MINLINE void straight_uchar_to_premul_ushort(unsigned short result[4], const unsigned char color[4])
+{
+	unsigned short alpha = color[3];
+
+	result[0] = color[0] * alpha;
+	result[1] = color[1] * alpha;
+	result[2] = color[2] * alpha;
+	result[3] = alpha * 255;
+}
+
+MINLINE void premul_ushort_to_straight_uchar(unsigned char *result, const unsigned short color[4])
+{
+	if (color[3] <= 255) {
+		result[0] = color[0] / 255;
+		result[1] = color[1] / 255;
+		result[2] = color[2] / 255;
+		result[3] = color[3] / 255;
+	}
+	else {
+		unsigned short alpha = color[3] / 255;
+
+		result[0] = color[0] / alpha;
+		result[1] = color[1] / alpha;
+		result[2] = color[2] / alpha;
+		result[3] = alpha;
+	}
+}
+
 /* result in ibuf2, scaling should be done correctly */
 void imb_onehalf_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1)
 {
@@ -311,19 +342,19 @@
 		for (y = ibuf2->y; y > 0; y--) {
 			cp2 = cp1 + (ibuf1->x << 2);
 			for (x = ibuf2->x; x > 0; x--) {
-				int p1i[8], p2i[8], desti[4];
+				unsigned short p1i[8], p2i[8], desti[4];
 
-				straight_uchar_to_premul_int(p1i, cp1);
-				straight_uchar_to_premul_int(p2i, cp2);
-				straight_uchar_to_premul_int(p1i + 4, cp1 + 4);
-				straight_uchar_to_premul_int(p2i + 4, cp2 + 4);
+				straight_uchar_to_premul_ushort(p1i, cp1);
+				straight_uchar_to_premul_ushort(p2i, cp2);
+				straight_uchar_to_premul_ushort(p1i + 4, cp1 + 4);
+				straight_uchar_to_premul_ushort(p2i + 4, cp2 + 4);
 
-				desti[0] = (p1i[0] + p2i[0] + p1i[4] + p2i[4]) >> 2;
-				desti[1] = (p1i[1] + p2i[1] + p1i[5] + p2i[5]) >> 2;
-				desti[2] = (p1i[2] + p2i[2] + p1i[6] + p2i[6]) >> 2;
-				desti[3] = (p1i[3] + p2i[3] + p1i[7] + p2i[7]) >> 2;
+				desti[0] = ((unsigned int) p1i[0] + p2i[0] + p1i[4] + p2i[4]) >> 2;
+				desti[1] = ((unsigned int) p1i[1] + p2i[1] + p1i[5] + p2i[5]) >> 2;
+				desti[2] = ((unsigned int) p1i[2] + p2i[2] + p1i[6] + p2i[6]) >> 2;
+				desti[3] = ((unsigned int) p1i[3] + p2i[3] + p1i[7] + p2i[7]) >> 2;
 
-				premul_int_to_straight_uchar(dest, desti);
+				premul_ushort_to_straight_uchar(dest, desti);
 
 				cp1 += 8;
 				cp2 += 8;




More information about the Bf-blender-cvs mailing list