[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27285] trunk/blender/source/blender/ editors/sculpt_paint/paint_image.c: reprojection

Campbell Barton ideasman42 at gmail.com
Fri Mar 5 21:22:17 CET 2010


Revision: 27285
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27285
Author:   campbellbarton
Date:     2010-03-05 21:22:17 +0100 (Fri, 05 Mar 2010)

Log Message:
-----------
reprojection
- blend in the projected image by its alpha rather then copy its alpha. this way you can easily mask out areas not to touch.
- undo was crashing.

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	2010-03-05 19:57:10 UTC (rev 27284)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2010-03-05 20:22:17 UTC (rev 27285)
@@ -3534,6 +3534,18 @@
 	cp[3]= mfac*cp1[3] + fac*cp2[3];
 }
 
+static void blend_color_mix_rgb(unsigned char *cp, const unsigned char *cp1, const unsigned char *cp2, 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
+	   errors that can turn colors black fast after repeated blending */
+	const int mfac= 255-fac;
+
+	cp[0]= (mfac*cp1[0]+fac*cp2[0])/255;
+	cp[1]= (mfac*cp1[1]+fac*cp2[1])/255;
+	cp[2]= (mfac*cp1[2]+fac*cp2[2])/255;
+}
+
 static void do_projectpaint_clone(ProjPaintState *ps, ProjPixel *projPixel, float *rgba, float alpha, float mask)
 {
 	if (ps->is_airbrush==0 && mask < 1.0f) {
@@ -3785,7 +3797,8 @@
 						else {
 							/* reprojection! */
 							bicubic_interpolation_color(ps->reproject_ibuf, projPixel->newColor.ch, NULL, projPixel->projCoSS[0], projPixel->projCoSS[1]);
-							blend_color_mix(projPixel->pixel.ch_pt,  projPixel->origColor.ch, projPixel->newColor.ch, (int)(mask*255));
+							if(projPixel->newColor.ch[3])
+								blend_color_mix_rgb(projPixel->pixel.ch_pt,  projPixel->origColor.ch, projPixel->newColor.ch, (mask*projPixel->newColor.ch[3]));
 						}
 					}
 					/* done painting */
@@ -5353,6 +5366,11 @@
 
 	ps.source= PROJ_SRC_CAM;
 
+	scene->toolsettings->imapaint.flag |= IMAGEPAINT_DRAWING;
+
+	undo_paint_push_begin(UNDO_PAINT_IMAGE, "Image Paint",
+		image_undo_restore, image_undo_free);
+
 	/* allocate and initialize spacial data structures */
 	project_paint_begin(&ps);
 
@@ -5379,6 +5397,8 @@
 
 	project_paint_end(&ps);
 
+	scene->toolsettings->imapaint.flag &= ~IMAGEPAINT_DRAWING;
+
 	return OPERATOR_FINISHED;
 }
 





More information about the Bf-blender-cvs mailing list