[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13749] trunk/blender/source/blender/nodes /intern:

Brecht Van Lommel brechtvanlommel at pandora.be
Mon Feb 18 16:21:59 CET 2008


Revision: 13749
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13749
Author:   blendix
Date:     2008-02-18 16:21:59 +0100 (Mon, 18 Feb 2008)

Log Message:
-----------

Bugfix for defocus node gamma correct. It applied gamma correct to
a premul image but that doesn't work correct. Now it depremuls and
premuls again around the gamma correction. Better solution might be
possible, but this gives compatible results.

Modified Paths:
--------------
    trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_defocus.c
    trunk/blender/source/blender/nodes/intern/CMP_util.c
    trunk/blender/source/blender/nodes/intern/CMP_util.h

Modified: trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_defocus.c
===================================================================
--- trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_defocus.c	2008-02-18 14:06:45 UTC (rev 13748)
+++ trunk/blender/source/blender/nodes/intern/CMP_nodes/CMP_defocus.c	2008-02-18 15:21:59 UTC (rev 13749)
@@ -798,16 +798,22 @@
 	// ok, process
 	old = img;
 	if (nqd->gamco) {
-		// gamma correct, blender func is simplified, fixed value & RGBA only, should make user param
+		// gamma correct, blender func is simplified, fixed value & RGBA only,
+		// should make user param. also depremul and premul afterwards, gamma
+		// correction can't work with premul alpha
 		old = dupalloc_compbuf(img);
+		premul_compbuf(old, 1);
 		gamma_correct_compbuf(old, 0);
+		premul_compbuf(old, 0);
 	}
 	
 	new = alloc_compbuf(old->x, old->y, old->type, 1);
 	defocus_blur(node, new, old, zbuf_use, in[1]->vec[0]*nqd->scale);
 	
 	if (nqd->gamco) {
+		premul_compbuf(new, 1);
 		gamma_correct_compbuf(new, 1);
+		premul_compbuf(new, 0);
 		free_compbuf(old);
 	}
 	if(node->exec & NODE_BREAK) {

Modified: trunk/blender/source/blender/nodes/intern/CMP_util.c
===================================================================
--- trunk/blender/source/blender/nodes/intern/CMP_util.c	2008-02-18 14:06:45 UTC (rev 13748)
+++ trunk/blender/source/blender/nodes/intern/CMP_util.c	2008-02-18 15:21:59 UTC (rev 13749)
@@ -575,9 +575,39 @@
    }
 }
 
+void premul_compbuf(CompBuf *img, int inversed)
+{
+   float *drect;
+   int x;
 
+   if(img->type!=CB_RGBA) return;
 
+   drect= img->rect;
+   if(inversed) {
+      for(x=img->x*img->y; x>0; x--, drect+=4) {
+		 if(drect[3] == 0.0f) {
+			 drect[0]= 0.0f;
+			 drect[1]= 0.0f;
+			 drect[2]= 0.0f;
+		 }
+		 else {
+			 drect[0] /= drect[3];
+			 drect[1] /= drect[3];
+			 drect[2] /= drect[3];
+		 }
+      }
+   }
+   else {
+      for(x=img->x*img->y; x>0; x--, drect+=4) {
+		 drect[0] *= drect[3];
+		 drect[1] *= drect[3];
+		 drect[2] *= drect[3];
+      }
+   }
+}
 
+
+
 /*
  *  2D Fast Hartley Transform, used for convolution
  */

Modified: trunk/blender/source/blender/nodes/intern/CMP_util.h
===================================================================
--- trunk/blender/source/blender/nodes/intern/CMP_util.h	2008-02-18 14:06:45 UTC (rev 13748)
+++ trunk/blender/source/blender/nodes/intern/CMP_util.h	2008-02-18 15:21:59 UTC (rev 13749)
@@ -176,6 +176,7 @@
 void do_ycca_to_rgba(bNode *node, float *out, float *in);
 
 void gamma_correct_compbuf(CompBuf *img, int inversed);
+void premul_compbuf(CompBuf *img, int inversed);
 void convolve(CompBuf* dst, CompBuf* in1, CompBuf* in2);
 
 extern void node_ID_title_cb(void *node_v, void *unused_v);





More information about the Bf-blender-cvs mailing list