[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19973] trunk/blender/source/blender/imbuf /intern/scaling.c: bugfix #18609

Ton Roosendaal ton at blender.org
Wed Apr 29 13:20:07 CEST 2009


Revision: 19973
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19973
Author:   ton
Date:     2009-04-29 13:20:07 +0200 (Wed, 29 Apr 2009)

Log Message:
-----------
bugfix #18609

This fixes a commit from Peter, revision 12931, Dec 17 2007
He added quick image scaling code, derived from ppmqscale, 
http://libdv.sf.net

This implementation gave ugly banding. especially visible on
dark colors or byte images with very close colors.

Solution is to add correct rounding, seems to me normal for such
fixed point magic. Optimizing code and keeping quality is tricky
dudes! Results for scaling down in sequencer were bad for over a
year (2.47 and 2.48 both wrong).

Revision Links:
--------------
    http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12931

Modified Paths:
--------------
    trunk/blender/source/blender/imbuf/intern/scaling.c

Modified: trunk/blender/source/blender/imbuf/intern/scaling.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/scaling.c	2009-04-29 11:16:26 UTC (rev 19972)
+++ trunk/blender/source/blender/imbuf/intern/scaling.c	2009-04-29 11:20:07 UTC (rev 19973)
@@ -609,34 +609,35 @@
 
 			w = (weight1y * weight1x) >> 16;
 
-			dst_line1[x].r += (line[0] * w) >> 16;
-			dst_line1[x].g += (line[1] * w) >> 16;
-			dst_line1[x].b += (line[2] * w) >> 16;
-			dst_line1[x].a += (line[3] * w) >> 16;
+			/* ensure correct rounding, without this you get ugly banding (ton) */
+			dst_line1[x].r += (line[0] * w + 32767) >> 16;
+			dst_line1[x].g += (line[1] * w + 32767) >> 16;
+			dst_line1[x].b += (line[2] * w + 32767) >> 16;
+			dst_line1[x].a += (line[3] * w + 32767) >> 16;
 			dst_line1[x].weight += w;
 
 			w = (weight2y * weight1x) >> 16;
 
-			dst_line2[x].r += (line[0] * w) >> 16;
-			dst_line2[x].g += (line[1] * w) >> 16;
-			dst_line2[x].b += (line[2] * w) >> 16;
-			dst_line2[x].a += (line[3] * w) >> 16;
+			dst_line2[x].r += (line[0] * w + 32767) >> 16;
+			dst_line2[x].g += (line[1] * w + 32767) >> 16;
+			dst_line2[x].b += (line[2] * w + 32767) >> 16;
+			dst_line2[x].a += (line[3] * w + 32767) >> 16;
 			dst_line2[x].weight += w;
 
 			w = (weight1y * weight2x) >> 16;
 
-			dst_line1[x+1].r += (line[0] * w) >> 16;
-			dst_line1[x+1].g += (line[1] * w) >> 16;
-			dst_line1[x+1].b += (line[2] * w) >> 16;
-			dst_line1[x+1].a += (line[3] * w) >> 16;
+			dst_line1[x+1].r += (line[0] * w + 32767) >> 16;
+			dst_line1[x+1].g += (line[1] * w + 32767) >> 16;
+			dst_line1[x+1].b += (line[2] * w + 32767) >> 16;
+			dst_line1[x+1].a += (line[3] * w + 32767) >> 16;
 			dst_line1[x+1].weight += w;
 
 			w = (weight2y * weight2x) >> 16;
 
-			dst_line2[x+1].r += (line[0] * w) >> 16;
-			dst_line2[x+1].g += (line[1] * w) >> 16;
-			dst_line2[x+1].b += (line[2] * w) >> 16;
-			dst_line2[x+1].a += (line[3] * w) >> 16;
+			dst_line2[x+1].r += (line[0] * w + 32767) >> 16;
+			dst_line2[x+1].g += (line[1] * w + 32767) >> 16;
+			dst_line2[x+1].b += (line[2] * w + 32767) >> 16;
+			dst_line2[x+1].a += (line[3] * w + 32767) >> 16;
 			dst_line2[x+1].weight += w;
 
 			x_dst += dx_dst;





More information about the Bf-blender-cvs mailing list