Bugfix for defocus node gamma correct. It applied gamma correct to
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 18 Feb 2008 15:21:59 +0000 (15:21 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 18 Feb 2008 15:21:59 +0000 (15:21 +0000)
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.

source/blender/nodes/intern/CMP_nodes/CMP_defocus.c
source/blender/nodes/intern/CMP_util.c
source/blender/nodes/intern/CMP_util.h

index 866bf406d1e850286a5e17050084096679fa4104..f8be69d80926d1f709b9dbdbe976a96fd30c3be1 100644 (file)
@@ -798,16 +798,22 @@ static void node_composit_exec_defocus(void *data, bNode *node, bNodeStack **in,
        // 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) {
index eee33e33ff55112f7db4df1c1c1ae0749d53afea..21e0f034a159dedcfe434d815b33f73ae6dc06b2 100644 (file)
@@ -575,6 +575,36 @@ void gamma_correct_compbuf(CompBuf *img, int inversed)
    }
 }
 
+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(fabs(drect[3]) < 1e-5f) {
+                        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];
+      }
+   }
+}
 
 
 
index 7cb10b75f3a6b46cc58740785654f3b66f23b82e..6fa5251710a61ef1ec978f414c08fa8a9ae9759b 100644 (file)
@@ -176,6 +176,7 @@ void do_hsva_to_rgba(bNode *node, float *out, float *in);
 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);