This is taking me longer than I wanted.
authorKent Mein <mein@cs.umn.edu>
Fri, 19 Jan 2007 21:06:35 +0000 (21:06 +0000)
committerKent Mein <mein@cs.umn.edu>
Fri, 19 Jan 2007 21:06:35 +0000 (21:06 +0000)
All of these I think still need work but they at least do not coredump.
Basically they need some troubleshooting.

I'm heading home now so will work on it again tomorrow hopefully.
If anyone is bored feel free to take a look at them and see if you can
find the problems.  (dnr.c also needs to be converted to float aware)

Kent

release/plugins/sequence/blur.c
release/plugins/sequence/color-correction-hsv.c
release/plugins/sequence/color-correction-yuv.c
release/plugins/sequence/scatter.c

index 9687d04e066cf4680258e810beda915b9f8d8190..8a415187f91a45f9aa0151e0b4716e48e1c31f2e 100644 (file)
@@ -138,8 +138,13 @@ void blurbuf(struct ImBuf *ibuf, int nr, Cast *cast)
        if(cast->gamma != 1.0) gamwarp(tbuf, 1.0 / cast->gamma);
 
        /* Very bad code warning! This fails badly with float-buffers!!! */
-       freeN(ibuf->rect);
-       ibuf->rect= tbuf->rect;
+       if (ibuf->rect_float) {
+               freeN(ibuf->rect_float);
+               ibuf->rect_float= tbuf->rect_float;
+       } else {
+               freeN(ibuf->rect);
+               ibuf->rect= tbuf->rect;
+       }
        freeN(tbuf);
        
 }
@@ -153,6 +158,7 @@ void doblur(struct ImBuf *mbuf, float fac, Cast *cast)
        float ifac, pfac;
        int n, b1, b2;
        char *irect, *prect, *mrect;
+       float *irectf, *prectf, *mrectf;
        
        /* wich buffers ? */
                                
@@ -178,30 +184,55 @@ void doblur(struct ImBuf *mbuf, float fac, Cast *cast)
        blurbuf(ibuf, n, cast);
        blurbuf(ibuf, n, cast);
        
-       fac= 255.0*(fac-pfac)/(ifac-pfac);
-       b1= fac;
+       fac = (fac-pfac)/(ifac-pfac);
+       b1= 255.0*fac;
        if(b1>255) b1= 255;
        b2= 255-b1;
        
        if(b1==255) {
-               memcpy(mbuf->rect, ibuf->rect, 4*ibuf->x*ibuf->y);
+               if (mbuf->rect_float) 
+                       memcpy(mbuf->rect_float, ibuf->rect_float, 4*ibuf->x*ibuf->y * sizeof(float));
+               else
+                       memcpy(mbuf->rect_float, ibuf->rect_float, 4*ibuf->x*ibuf->y);
        }
        else if(b1==0) {
-               memcpy(mbuf->rect, pbuf->rect, 4*pbuf->x*pbuf->y);
+               if (mbuf->rect_float)
+                       memcpy(mbuf->rect_float, pbuf->rect_float, 4*pbuf->x*pbuf->y * sizeof(float));
+               else
+                       memcpy(mbuf->rect, pbuf->rect, 4*pbuf->x*pbuf->y);
        }
        else {  /* interpolate */
                n= ibuf->x*ibuf->y;
-               irect= (char *)ibuf->rect;
-               prect= (char *)pbuf->rect;
-               mrect= (char *)mbuf->rect;
-               while(n--) {
-                       mrect[0]= (irect[0]*b1+ prect[0]*b2)>>8;
-                       mrect[1]= (irect[1]*b1+ prect[1]*b2)>>8;
-                       mrect[2]= (irect[2]*b1+ prect[2]*b2)>>8;
-                       mrect[3]= (irect[3]*b1+ prect[3]*b2)>>8;
-                       mrect+= 4;
-                       irect+= 4;
-                       prect+= 4;
+               if (mbuf->rect_float) {
+                       irectf= ibuf->rect_float;
+                       prectf= pbuf->rect_float;
+                       mrectf= mbuf->rect_float;
+                       while(n--) {
+                               mrectf[0]= (irectf[0]*fac+ prectf[0]*(1-fac))/2;
+                               mrectf[1]= (irectf[1]*fac+ prectf[1]*(1-fac))/2;
+                               mrectf[2]= (irectf[2]*fac+ prectf[2]*(1-fac))/2;
+                               mrectf[3]= (irectf[3]*fac+ prectf[3]*(1-fac))/2;
+                               mrectf[0]= 1;
+                               mrectf[1]= 1;
+                               mrectf[2]= 1;
+                               mrectf[3]= 1;
+                               mrectf+= 4;
+                               irectf+= 4;
+                               prectf+= 4;
+                       }
+               } else {
+                       irect= (char *)ibuf->rect;
+                       prect= (char *)pbuf->rect;
+                       mrect= (char *)mbuf->rect;
+                       while(n--) {
+                               mrect[0]= (irect[0]*b1+ prect[0]*b2)>>8;
+                               mrect[1]= (irect[1]*b1+ prect[1]*b2)>>8;
+                               mrect[2]= (irect[2]*b1+ prect[2]*b2)>>8;
+                               mrect[3]= (irect[3]*b1+ prect[3]*b2)>>8;
+                               mrect+= 4;
+                               irect+= 4;
+                               prect+= 4;
+                       }
                }
        }
        freeImBuf(ibuf);
@@ -221,7 +252,8 @@ void plugin_seq_doit(Cast *cast, float facf0, float facf1, int x, int y, ImBuf *
                bfacf1 = (facf1 * 6.0) + 1.0;
        }
 
-       memcpy(out->rect, ibuf1->rect, 4*out->x*out->y);
+       if (out->rect_float) memcpy(out->rect_float, ibuf1->rect_float, 4*out->x*out->y * sizeof(float));
+       else memcpy(out->rect, ibuf1->rect, 4*out->x*out->y);
 
        /* it blurs interlaced, only tested with even fields */
        de_interlace(out);
@@ -231,11 +263,14 @@ void plugin_seq_doit(Cast *cast, float facf0, float facf1, int x, int y, ImBuf *
        
        doblur(out, bfacf0, cast); /*fieldA*/
 
-       out->rect += out->x * out->y;
+       if (out->rect_float) out->rect_float += out->x * out->y;
+       else out->rect += out->x * out->y;
 
        doblur(out, bfacf1, cast); /*fieldB*/
 
-       out->rect -= out->x * out->y;
+       if (out->rect_float) out->rect_float -= out->x * out->y;
+       else out->rect -= out->x * out->y;
+
        out->flags |= IB_fields;
 
        interlace(out);
index 2e57c6f0f4825cdf585832598c12a7a80dba2aae..ec8478706f1fac73b3d3283a2cd33082db20af79 100644 (file)
@@ -182,10 +182,12 @@ static void rgb_to_hsv (double  r, double  g, double  b,
 
 void plugin_seq_doit(Cast *cast, float facf0, float facf1, int width, 
        int height, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *out, ImBuf *use) {
-       char *dest, *src1, *src2;
+       char *dest, *src1;
        int x, y, c;
        double gamma_table[256];
        double uv_table[256];
+       float *destf = out->rect_float;
+       float *src1f = ibuf1->rect_float;
        
        if (!ibuf1) return;
 
@@ -224,7 +226,9 @@ void plugin_seq_doit(Cast *cast, float facf0, float facf1, int width,
                        double h,s,v,r,g,b;
                        double fac;
 
-                       rgb_to_hsv((double) src1[0]/255.0,
+                       if (ibuf1->rect_float) rgb_to_hsv(src1f[0], src1f[1],
+                               src1f[2],&h,&s,&v);
+                       else rgb_to_hsv((double) src1[0]/255.0,
                                   (double) src1[1]/255.0,
                                   (double) src1[2]/255.0,
                                   &h, &s, &v);
@@ -238,10 +242,18 @@ void plugin_seq_doit(Cast *cast, float facf0, float facf1, int width,
                        }
                        hsv_to_rgb(h,s,v, &r, &g, &b);
                        
-                       *dest++ = r*255.0;
-                       *dest++ = g*255.0;
-                       *dest++ = b*255.0;
-                       dest++;
+                       if (out->rect_float) {
+                               destf[0] = r;
+                               destf[1] = g;
+                               destf[2] = b;
+                               destf = destf + 4;
+                               src1f +=4;
+                       } else {
+                               dest[0] = r*255.0;
+                               dest[1] = g*255.0;
+                               dest[2] = b*255.0;
+                               dest += 4;
+                       }
 
                        src1 += 4;
                }
index c68d78c9fc0a836539440dd958b238be342c43bf..54290ba37a24cda52eb878b27b6e3982055c2639 100644 (file)
@@ -119,6 +119,8 @@ void plugin_seq_doit(Cast *cast, float facf0, float facf1, int width,
        float yuv[3];
        float gamma_table[256];
        float uv_table[256];
+       float *destf = out->rect_float;
+       float *src1f = ibuf1->rect_float;
        
        if (!ibuf1) return;
 
@@ -155,9 +157,15 @@ void plugin_seq_doit(Cast *cast, float facf0, float facf1, int width,
        for (y = 0; y < height; y++) {
                for (x = 0; x < width; x++) {
                        float fac;
-                       rgb[0]= (float)src1[0]/255.0;
-                       rgb[1]= (float)src1[1]/255.0;
-                       rgb[2]= (float)src1[2]/255.0;
+                       if (out->rect_float) {
+                               rgb[0]= (float)src1f[0]/255.0;
+                               rgb[1]= (float)src1f[1]/255.0;
+                               rgb[2]= (float)src1f[2]/255.0;
+                       } else {
+                               rgb[0]= (float)src1[0]/255.0;
+                               rgb[1]= (float)src1[1]/255.0;
+                               rgb[2]= (float)src1[2]/255.0;
+                       }
                        rgb_to_yuv(rgb, yuv);
 
                        yuv[0] = gamma_table[(int) (yuv[0] * 255.0)] / 255.0;
@@ -179,12 +187,19 @@ void plugin_seq_doit(Cast *cast, float facf0, float facf1, int width,
                        }
                        yuv_to_rgb(yuv, rgb);
                        
-                       *dest++ = rgb[0]*255.0;
-                       *dest++ = rgb[1]*255.0;
-                       *dest++ = rgb[2]*255.0;
-                       dest++;
-
-                       src1 += 4;
+                       if (out->rect_float) {
+                               *destf++ = rgb[0];
+                               *destf++ = rgb[1];
+                               *destf++ = rgb[2];
+                               destf++;
+                               src1f += 4;
+                       } else {
+                               *dest++ = rgb[0]*255.0;
+                               *dest++ = rgb[1]*255.0;
+                               *dest++ = rgb[2]*255.0;
+                               dest++;
+                               src1 += 4;
+                       }
                }
        }
 
index b61b53c1a85fa674a53b80f4d8fdde936984f94e..ea2302563895c0ea1bf5da64420954d3abc9f242 100644 (file)
@@ -99,20 +99,17 @@ void plugin_getinfo(PluginInfo *info)
 /* ************************************************************
        Scatter
        
-       with usage of ImBuf rect operation.
-       
    ************************************************************ */
 
-static void ibufrectop(ImBuf *dbuf, ImBuf *sbuf,       
+static void rectcpy(ImBuf *dbuf, ImBuf *sbuf,  
                                int destx, int desty, 
-                               int srcx, int srcy, int width, int height,
-                               void (*operation)(), 
-                               int value)
+                               int srcx, int srcy, int width, int height)
 {
        uint *drect,*srect;
+       float *dfrect, *sfrect;
+       int tmp;
 
        if (dbuf == 0) return;
-       if (operation == 0) return;
 
        if (destx < 0){
                srcx -= destx ;
@@ -140,41 +137,71 @@ static void ibufrectop(ImBuf *dbuf, ImBuf *sbuf,
        if (sbuf){
                if (width > sbuf->x - srcx) width = sbuf->x - srcx;
                if (height > sbuf->y - srcy) height = sbuf->y - srcy;
+               srect = sbuf->rect;
+               sfrect = sbuf->rect_float;
        }
 
        if (width <= 0) return;
        if (height <= 0) return;
 
        drect = dbuf->rect;
-       if (sbuf) srect = sbuf->rect;
+       dfrect = dbuf->rect_float;
+
+       tmp = desty * dbuf->x + destx;
+
+       if (dbuf->rect_float) dfrect += tmp;
+       else drect += tmp;
 
-       drect += desty * dbuf->x;
-       drect += destx;
        destx = dbuf->x;
 
        if (sbuf) {
-               srect += srcy * sbuf->x;
-               srect += srcx;
+               tmp = srcy * sbuf->x + srcx;
+               if (dbuf->rect_float) sfrect += tmp;
+               else srect += tmp;
                srcx = sbuf->x;
        } else{
-               srect = drect;
+               if (dbuf->rect_float) sfrect = dfrect;
+               else srect = drect;
                srcx = destx;
        }
 
        for (;height > 0; height--){
-               operation(drect, srect, width, value);
-               drect += destx;
-               srect += srcx;
+               if (dbuf->rect_float) {
+                       memcpy(dfrect,sfrect, srcx * sizeof(float));
+                       dfrect += destx;
+                       sfrect += srcx;
+               } else {
+                       memcpy(drect,srect, srcx * sizeof(int));
+                       drect += destx;
+                       srect += srcx;
+               }
        }
 }
 
-static void rectcpy(uint *drect, uint *srect, int x) {
-       memcpy(drect,srect, x * sizeof(int));
-}
-
-static void rectfill(uint *drect, uint *srect, int x, int value)
+static void fill_out(ImBuf *out, float r, float g, float b, float a)
 {
-       for (;x > 0; x--) *drect++ = value;
+       int tot,x;
+       float *rectf = out->rect_float;
+       unsigned char *rect = (unsigned char *)out->rect;
+
+       tot = out->x * out->y;
+       if (out->rect_float) {
+               for (x = 0;x < tot; x++) {
+                       rectf[0] = r;
+                       rectf[1] = g;
+                       rectf[2] = b;
+                       rectf[3] = a;
+                       rectf = rectf + 4;
+               }
+       } else {
+               for (x=0;x < tot;x++) {
+                       rect[0] = (int)(r * 255);
+                       rect[1] = (int)(g * 255);
+                               rect[2] = (int)(b * 255);
+                               rect[3] = (int)(a * 255);
+                       rect += 4;
+               }
+       }
 }
 
 
@@ -184,7 +211,7 @@ void plugin_seq_doit(Cast *cast, float facf0, float facf1, int sx, int sy, ImBuf
        int x, y, lr;
        
        /* fill imbuf 'out' with black */
-       ibufrectop(out, ibuf1,0,0,0,0,32767,32767,rectfill, 0);
+       fill_out(out, 0,0,0,0);
 
        switch (cast->type) {
                case 0:
@@ -223,12 +250,12 @@ void plugin_seq_doit(Cast *cast, float facf0, float facf1, int sx, int sy, ImBuf
                                break;
                }
                
-               ibufrectop(out, ibuf1, 0, y, x, y, 32767, 1, rectcpy, 0);
+               rectcpy(out, ibuf1, 0, y, x, y, 32767, 1);
                if (cast->wrap) {
-                       ibufrectop(out, ibuf1, 0, y, x + sx, y, 32767, 1, rectcpy, 0);
-                       ibufrectop(out, ibuf1, 0, y, x + sx + sx, y, 32767, 1, rectcpy, 0);
-                       ibufrectop(out, ibuf1, 0, y, x - sx, y, 32767, 1, rectcpy, 0);
-                       ibufrectop(out, ibuf1, 0, y, x - sx - sx, y, 32767, 1, rectcpy, 0);
+                       rectcpy(out, ibuf1, 0, y, x + sx, y, 32767, 1);
+                       rectcpy(out, ibuf1, 0, y, x + sx + sx, y, 32767, 1);
+                       rectcpy(out, ibuf1, 0, y, x - sx, y, 32767, 1);
+                       rectcpy(out, ibuf1, 0, y, x - sx - sx, y, 32767, 1);
                }
        }
 }