[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49895] trunk/blender/source/blender/ editors/sculpt_paint/paint_image.c: fix [#32299] 16bit float texture + ' Quick Edit' gives wrong result

Campbell Barton ideasman42 at gmail.com
Tue Aug 14 17:38:10 CEST 2012


Revision: 49895
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49895
Author:   campbellbarton
Date:     2012-08-14 15:38:10 +0000 (Tue, 14 Aug 2012)
Log Message:
-----------
fix [#32299] 16bit float texture + 'Quick Edit' gives wrong result

Modified Paths:
--------------
    trunk/blender/source/blender/editors/sculpt_paint/paint_image.c

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2012-08-14 14:45:27 UTC (rev 49894)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2012-08-14 15:38:10 UTC (rev 49895)
@@ -3713,7 +3713,7 @@
 	cp[3] = mfac * cp1[3] + fac * cp2[3];
 }
 
-static void blend_color_mix_accum(unsigned char *cp, const unsigned char *cp1, const unsigned char *cp2, const int fac)
+static void blend_color_mix_accum(unsigned char cp[4], const unsigned char cp1[4], const unsigned char cp2[4], const int fac)
 {
 	/* this and other blending modes previously used >>8 instead of /255. both
 	 * are not equivalent (>>8 is /256), and the former results in rounding
@@ -3726,7 +3726,18 @@
 	cp[2] = (mfac * cp1[2] + fac * cp2[2]) / 255;
 	cp[3] = alpha > 255 ? 255 : alpha;
 }
+static void blend_color_mix_accum_float(float cp[4], const float cp1[4], const unsigned char cp2[4], const float fac)
+{
+	const float mfac = 1.0f - fac;
+	const float alpha = cp1[3] + (fac * (cp2[3] / 255.0f));
 
+	cp[0] = (mfac * cp1[0] + (fac * (cp2[0] / 255.0f)));
+	cp[1] = (mfac * cp1[1] + (fac * (cp2[1] / 255.0f)));
+	cp[2] = (mfac * cp1[2] + (fac * (cp2[2] / 255.0f)));
+	cp[3] = alpha > 1.0f ? 1.0f : alpha;
+}
+
+
 static void do_projectpaint_clone(ProjPaintState *ps, ProjPixel *projPixel, float alpha, float mask)
 {
 	if (ps->is_airbrush == 0 && mask < 1.0f) {
@@ -3886,7 +3897,7 @@
 	
 	/* printf("brush bounds %d %d %d %d\n", bucketMin[0], bucketMin[1], bucketMax[0], bucketMax[1]); */
 	
-	while (project_bucket_iter_next(ps, &bucket_index, &bucket_bounds, pos)) {				
+	while (project_bucket_iter_next(ps, &bucket_index, &bucket_bounds, pos)) {
 		
 		/* Check this bucket and its faces are initialized */
 		if (ps->bucketFlags[bucket_index] == PROJ_BUCKET_NULL) {
@@ -3901,12 +3912,37 @@
 			for (node = ps->bucketRect[bucket_index]; node; node = node->next) {
 				projPixel = (ProjPixel *)node->link;
 
-				bicubic_interpolation_color(ps->reproject_ibuf, projPixel->newColor.ch, NULL, projPixel->projCoSS[0], projPixel->projCoSS[1]);
-				if (projPixel->newColor.ch[3]) {
-					mask = ((float)projPixel->mask) / 65535.0f;
-					blend_color_mix_accum(projPixel->pixel.ch_pt,  projPixel->origColor.ch, projPixel->newColor.ch, (int)(mask * projPixel->newColor.ch[3]));
+				/* copy of code below */
+				if (last_index != projPixel->image_index) {
+					last_index = projPixel->image_index;
+					last_projIma = projImages + last_index;
 
+					last_projIma->touch = 1;
+					is_floatbuf = last_projIma->ibuf->rect_float ? 1 : 0;
+					use_color_correction = (last_projIma->ibuf->profile == IB_PROFILE_LINEAR_RGB) ? 1 : 0;
 				}
+				/* end copy */
+
+				if (is_floatbuf) {
+					/* re-project buffer is assumed byte - TODO, allow float */
+					bicubic_interpolation_color(ps->reproject_ibuf, projPixel->newColor.ch, NULL,
+					                            projPixel->projCoSS[0], projPixel->projCoSS[1]);
+					if (projPixel->newColor.ch[3]) {
+						mask = ((float)projPixel->mask) / 65535.0f;
+						blend_color_mix_accum_float(projPixel->pixel.f_pt,  projPixel->origColor.f,
+						                            projPixel->newColor.ch, (mask * (projPixel->newColor.ch[3] / 255.0f)));
+					}
+				}
+				else {
+					/* re-project buffer is assumed byte - TODO, allow float */
+					bicubic_interpolation_color(ps->reproject_ibuf, projPixel->newColor.ch, NULL,
+					                            projPixel->projCoSS[0], projPixel->projCoSS[1]);
+					if (projPixel->newColor.ch[3]) {
+						mask = ((float)projPixel->mask) / 65535.0f;
+						blend_color_mix_accum(projPixel->pixel.ch_pt,  projPixel->origColor.ch,
+						                      projPixel->newColor.ch, (int)(mask * projPixel->newColor.ch[3]));
+					}
+				}
 			}
 		}
 		else {
@@ -3959,6 +3995,7 @@
 						
 						if (alpha > 0.0f) {
 
+							/* copy of code above */
 							if (last_index != projPixel->image_index) {
 								last_index = projPixel->image_index;
 								last_projIma = projImages + last_index;
@@ -3967,6 +4004,7 @@
 								is_floatbuf = last_projIma->ibuf->rect_float ? 1 : 0;
 								use_color_correction = (last_projIma->ibuf->profile == IB_PROFILE_LINEAR_RGB) ? 1 : 0;
 							}
+							/* end copy */
 
 							last_partial_redraw_cell = last_projIma->partRedrawRect + projPixel->bb_cell_index;
 							last_partial_redraw_cell->x1 = MIN2(last_partial_redraw_cell->x1, projPixel->x_px);




More information about the Bf-blender-cvs mailing list