[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19933] trunk/blender/source/blender/src/ imagepaint.c: [#18623] projection paint alpha paintingacts as 1bit -- 2. 49RC1

Campbell Barton ideasman42 at gmail.com
Sun Apr 26 23:30:42 CEST 2009


Revision: 19933
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19933
Author:   campbellbarton
Date:     2009-04-26 23:30:42 +0200 (Sun, 26 Apr 2009)

Log Message:
-----------
[#18623] projection paint alpha paintingacts as 1bit -- 2.49RC1

Also fixed...
- smear with alpha channels (had to disabled blending modes).
- using uninitialized memory in a few cases.
- negative index in an array bug.

Modified Paths:
--------------
    trunk/blender/source/blender/src/imagepaint.c

Modified: trunk/blender/source/blender/src/imagepaint.c
===================================================================
--- trunk/blender/source/blender/src/imagepaint.c	2009-04-26 21:23:59 UTC (rev 19932)
+++ trunk/blender/source/blender/src/imagepaint.c	2009-04-26 21:30:42 UTC (rev 19933)
@@ -707,7 +707,7 @@
 		Vec2Weightf(uv, tf->uv[0], tf->uv[2], tf->uv[3], w);
 	}
 	
-	ibuf = BKE_image_get_ibuf((Image *)tf->tpage, NULL); /* TODO - this may be slow, the only way around it is to have an ibuf index per face */
+	ibuf = tf->tpage->ibufs.first; /* we must have got the imbuf before getting here */
 	if (!ibuf) return 0;
 	
 	if (interp) {
@@ -1362,7 +1362,7 @@
 		ImBuf *ibuf_other;
 		const MTFace *tf_other = ps->dm_mtface_mask + face_index;
 		
-		if (tf_other->tpage && (ibuf_other = BKE_image_get_ibuf((Image *)tf_other->tpage, NULL))) {
+		if (tf_other->tpage && (ibuf_other = BKE_image_get_ibuf(tf_other->tpage, NULL))) {
 			/* BKE_image_get_ibuf - TODO - this may be slow */
 			unsigned char rgba_ub[4];
 			float rgba_f[4];
@@ -1518,7 +1518,7 @@
 			ImBuf *ibuf_other;
 			const MTFace *tf_other = ps->dm_mtface_clone + face_index;
 			
-			if (tf_other->tpage && (ibuf_other = BKE_image_get_ibuf((Image *)tf_other->tpage, NULL))) {
+			if (tf_other->tpage && (ibuf_other = BKE_image_get_ibuf(tf_other->tpage, NULL))) {
 				/* BKE_image_get_ibuf - TODO - this may be slow */
 				
 				if (ibuf->rect_float) {
@@ -1969,7 +1969,6 @@
 	const int flip = ((SIDE_OF_LINE(v1coSS, v2coSS, v3coSS) > 0.0f) != (SIDE_OF_LINE(uv1co, uv2co, uv3co) > 0.0f));
 	
 	float bucket_bounds_ss[4][2];
-	float w[3];
 
 	/* get the UV space bounding box */
 	inside_bucket_flag |= BLI_in_rctf(bucket_bounds, v1coSS[0], v1coSS[1]);
@@ -2040,6 +2039,7 @@
 		/* Maximum possible 6 intersections when using a rectangle and triangle */
 		float isectVCosSS[8][3]; /* The 3rd float is used to store angle for qsort(), NOT as a Z location */
 		float v1_clipSS[2], v2_clipSS[2];
+		float w[3];
 		
 		/* calc center*/
 		float cent[2] = {0.0f, 0.0f};
@@ -2082,6 +2082,7 @@
 		
 		if ((*tot) < 3) { /* no intersections to speak of */
 			*tot = 0;
+			return;
 		}
 	
 		/* now we have all points we need, collect their angles and sort them clockwise */
@@ -2116,7 +2117,6 @@
 		if (flip)	qsort(isectVCosSS, *tot, sizeof(float)*3, float_z_sort_flip);
 		else		qsort(isectVCosSS, *tot, sizeof(float)*3, float_z_sort);
 		
-		
 		/* remove doubles */
 		/* first/last check */
 		if (fabs(isectVCosSS[0][0]-isectVCosSS[(*tot)-1][0]) < PROJ_GEOM_TOLERANCE &&  fabs(isectVCosSS[0][1]-isectVCosSS[(*tot)-1][1]) < PROJ_GEOM_TOLERANCE) {
@@ -3030,7 +3030,7 @@
 	ps->buckets_x = (int)(ps->screen_width / (((float)ps->brush->size) / PROJ_BUCKET_BRUSH_DIV));
 	ps->buckets_y = (int)(ps->screen_height / (((float)ps->brush->size) / PROJ_BUCKET_BRUSH_DIV));
 	
-	printf("\tscreenspace bucket division x:%d y:%d\n", ps->buckets_x, ps->buckets_y);
+	/* printf("\tscreenspace bucket division x:%d y:%d\n", ps->buckets_x, ps->buckets_y); */
 	
 	/* really high values could cause problems since it has to allocate a few
 	 * (ps->buckets_x*ps->buckets_y) sized arrays  */
@@ -3203,7 +3203,7 @@
 				
 				image_index = BLI_linklist_index(image_LinkList, tf->tpage);
 				
-				if (image_index==-1 && BKE_image_get_ibuf((Image *)tf->tpage, NULL)) { /* MemArena dosnt have an append func */
+				if (image_index==-1 && BKE_image_get_ibuf(tf->tpage, NULL)) { /* MemArena dosnt have an append func */
 					BLI_linklist_append(&image_LinkList, tf->tpage);
 					image_index = ps->image_tot;
 					ps->image_tot++;
@@ -3225,10 +3225,10 @@
 	
 	for (node= image_LinkList, i=0; node; node= node->next, i++, projIma++) {
 		projIma->ima = node->link;
-		// calloced - projIma->touch = 0;
+		projIma->touch = 0;
 		projIma->ibuf = BKE_image_get_ibuf(projIma->ima, NULL);
 		projIma->partRedrawRect =  BLI_memarena_alloc(arena, sizeof(ImagePaintPartialRedraw) * PROJ_BOUNDBOX_SQUARED);
-		// calloced - memset(projIma->partRedrawRect, 0, sizeof(ImagePaintPartialRedraw) * PROJ_BOUNDBOX_SQUARED);
+		memset(projIma->partRedrawRect, 0, sizeof(ImagePaintPartialRedraw) * PROJ_BOUNDBOX_SQUARED);
 	}
 	
 	/* we have built the array, discard the linked list */
@@ -3378,7 +3378,7 @@
 
 static int partial_redraw_array_merge(ImagePaintPartialRedraw *pr, ImagePaintPartialRedraw *pr_other, int tot)
 {
-	int touch;
+	int touch= 0;
 	while (tot--) {
 		pr->x1 = MIN2(pr->x1, pr_other->x1);
 		pr->y1 = MIN2(pr->y1, pr_other->y1);
@@ -3506,6 +3506,7 @@
 	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;
+	cp[3]= (mfac*cp1[3]+fac*cp2[3])/255;
 }
 
 static void blend_color_mix_float(float *cp, const float *cp1, const float *cp2, const float fac)
@@ -3514,6 +3515,7 @@
 	cp[0]= mfac*cp1[0] + fac*cp2[0];
 	cp[1]= mfac*cp1[1] + fac*cp2[1];
 	cp[2]= mfac*cp1[2] + fac*cp2[2];
+	cp[3]= mfac*cp1[3] + fac*cp2[3];
 }
 
 static void do_projectpaint_clone(ProjPaintState *ps, ProjPixel *projPixel, float *rgba, float alpha, float mask)
@@ -3550,8 +3552,8 @@
 	
 	if (project_paint_PickColor(ps, co, NULL, rgba_ub, 1)==0)
 		return; 
-	
-	((ProjPixelClone *)projPixel)->clonepx.uint = IMB_blend_color(*projPixel->pixel.uint_pt, *((unsigned int *)rgba_ub), (int)(alpha*mask*255), ps->blend);
+	/* ((ProjPixelClone *)projPixel)->clonepx.uint = IMB_blend_color(*projPixel->pixel.uint_pt, *((unsigned int *)rgba_ub), (int)(alpha*mask*255), ps->blend); */
+	blend_color_mix(((ProjPixelClone *)projPixel)->clonepx.ch, projPixel->pixel.ch_pt, rgba_ub, (int)(alpha*mask*255));
 	BLI_linklist_prepend_arena(smearPixels, (void *)projPixel, smearArena);
 } 
 
@@ -3564,7 +3566,8 @@
 		return;
 	
 	IMAPAINT_FLOAT_RGBA_TO_CHAR(rgba_smear, projPixel->pixel.f_pt);
-	((ProjPixelClone *)projPixel)->clonepx.uint = IMB_blend_color(*((unsigned int *)rgba_smear), *((unsigned int *)rgba_ub), (int)(alpha*mask*255), ps->blend);
+	/* (ProjPixelClone *)projPixel)->clonepx.uint = IMB_blend_color(*((unsigned int *)rgba_smear), *((unsigned int *)rgba_ub), (int)(alpha*mask*255), ps->blend); */
+	blend_color_mix(((ProjPixelClone *)projPixel)->clonepx.ch, rgba_smear, (rgba_ub), (int)(alpha*mask*255)); 
 	BLI_linklist_prepend_arena(smearPixels_f, (void *)projPixel, smearArena);
 }
 
@@ -4325,7 +4328,7 @@
 		) {
 			ImBuf *ibuf;
 			
-			newimage = (Image*)((s->me->mtface+newfaceindex)->tpage);
+			newimage = (s->me->mtface+newfaceindex)->tpage;
 			ibuf= BKE_image_get_ibuf(newimage, G.sima?&G.sima->iuser:NULL);
 
 			if(ibuf && ibuf->rect)





More information about the Bf-blender-cvs mailing list