Revision: 17499
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17499
Author:   campbellbarton
Date:     2008-11-19 04:28:07 +0100 (Wed, 19 Nov 2008)

Log Message:
-----------
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float 
v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float 
v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float 
v, int xout, int yout);

Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float 
*col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float 
*col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float 
*col_float, float u, float v);

This is needed so for projection painting but generally useful if you want to 
get the interpolated color of a pixel in an image without having a destination 
imbuf.

While editing these I noticed the functons are a bit dodgy, they assume the 
input ImBuf has matching float/chr buffer to the output.

Modified Paths:
--------------
    trunk/blender/source/blender/imbuf/IMB_imbuf.h
    trunk/blender/source/blender/imbuf/intern/imageprocess.c

Modified: trunk/blender/source/blender/imbuf/IMB_imbuf.h
===================================================================
--- trunk/blender/source/blender/imbuf/IMB_imbuf.h      2008-11-19 03:15:52 UTC 
(rev 17498)
+++ trunk/blender/source/blender/imbuf/IMB_imbuf.h      2008-11-19 03:28:07 UTC 
(rev 17499)
@@ -403,9 +403,14 @@
  *
  * @attention defined in imageprocess.c
  */
-void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float x, float 
y, int xout, int yout);
+void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float 
v, int xout, int yout);
 void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, 
float v, int xout, int yout);
 void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, 
float v, int xout, int yout);
+
+void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float 
*col_float, float u, float v);
+void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float 
*col_float, float u, float v);
+void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float 
*col_float, float u, float v);
+
 /**
  * Change the ordering of the color bytes pointed to by rect from
  * rgba to abgr. size * 4 color bytes are reordered.

Modified: trunk/blender/source/blender/imbuf/intern/imageprocess.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/imageprocess.c    2008-11-19 
03:15:52 UTC (rev 17498)
+++ trunk/blender/source/blender/imbuf/intern/imageprocess.c    2008-11-19 
03:28:07 UTC (rev 17499)
@@ -80,7 +80,18 @@
                }
        }
 }
+static void pixel_from_buffer(struct ImBuf *ibuf, unsigned char *outI, float 
*outF, int x, int y)
 
+{
+       int offset = ibuf->x * y * 4 + 4*x;
+       
+       if (ibuf->rect)
+               outI= (unsigned char *)ibuf->rect + offset;
+       
+       if (ibuf->rect_float)
+               outF= (float *)ibuf->rect_float + offset;
+}
+
 /**************************************************************************
 *                            INTERPOLATIONS 
 *
@@ -110,25 +121,19 @@
 }
 #endif
 
-
-void bicubic_interpolation(ImBuf *in, ImBuf *out, float x, float y, int xout, 
int yout)
+void bicubic_interpolation_color(struct ImBuf *in, unsigned char *outI, float 
*outF, float u, float v)
 {
        int i,j,n,m,x1,y1;
-       unsigned char *dataI,*outI;
-       float a,b,w,wx,wy[4], outR,outG,outB,outA,*dataF,*outF;
-       int do_rect, do_float;
+       unsigned char *dataI;
+       float a,b,w,wx,wy[4], outR,outG,outB,outA,*dataF;
 
-       if (in == NULL) return;
-       if (in->rect == NULL && in->rect_float == NULL) return;
+       /* ImBuf in must have a valid rect or rect_float, assume this is alredy 
checked */
 
-       do_rect= (out->rect != NULL);
-       do_float= (out->rect_float != NULL);
+       i= (int)floor(u);
+       j= (int)floor(v);
+       a= u - i;
+       b= v - j;
 
-       i= (int)floor(x);
-       j= (int)floor(y);
-       a= x - i;
-       b= y - j;
-
        outR = outG = outB = outA = 0.0f;
        
 /* Optimized and not so easy to read */
@@ -151,14 +156,14 @@
                                        /* except that would call P() 16 times 
per pixel therefor pow() 64 times, better precalc these */
                                        w = wx * wy[m+1];
                                        
-                                       if (do_float) {
+                                       if (outF) {
                                                dataF= in->rect_float + in->x * 
y1 * 4 + 4*x1;
                                                outR+= dataF[0] * w;
                                                outG+= dataF[1] * w;
                                                outB+= dataF[2] * w;
                                                outA+= dataF[3] * w;
                                        }
-                                       if (do_rect) {
+                                       if (outI) {
                                                dataI= (unsigned char*)in->rect 
+ in->x * y1 * 4 + 4*x1;
                                                outR+= dataI[0] * w;
                                                outG+= dataI[1] * w;
@@ -198,15 +203,13 @@
        }
 #endif
        
-       if (do_rect) {
-               outI= (unsigned char *)out->rect + out->x * yout * 4 + 4*xout;
+       if (outI) {
                outI[0]= (int)outR;
                outI[1]= (int)outG;
                outI[2]= (int)outB;
                outI[3]= (int)outA;
        }
-       if (do_float) {
-               outF= (float *)out->rect_float + out->x * yout * 4 + 4*xout;
+       if (outF) {
                outF[0]= outR;
                outF[1]= outG;
                outF[2]= outB;
@@ -214,24 +217,34 @@
        }
 }
 
+
+void bicubic_interpolation(ImBuf *in, ImBuf *out, float u, float v, int xout, 
int yout)
+{
+       
+       unsigned char *outI = NULL;
+       float *outF = NULL;
+       
+       if (in == NULL || (in->rect == NULL && in->rect_float == NULL)) return;
+       
+       pixel_from_buffer(out, outI, outF, xout, yout); /* gcc warns these 
could be uninitialized, but its ok */
+       
+       bicubic_interpolation_color(in, outI, outF, u, v);
+}
+
 /* function assumes out to be zero'ed, only does RGBA */
 /* BILINEAR INTERPOLATION */
-void bilinear_interpolation(ImBuf *in, ImBuf *out, float u, float v, int xout, 
int yout)
+void bilinear_interpolation_color(struct ImBuf *in, unsigned char *outI, float 
*outF, float u, float v)
 {
-       float *row1, *row2, *row3, *row4, a, b, *outF;
-       unsigned char *row1I, *row2I, *row3I, *row4I, *outI;
+       float *row1, *row2, *row3, *row4, a, b;
+       unsigned char *row1I, *row2I, *row3I, *row4I;
        float a_b, ma_b, a_mb, ma_mb;
        float empty[4]= {0.0f, 0.0f, 0.0f, 0.0f};
        unsigned char emptyI[4]= {0, 0, 0, 0};
        int y1, y2, x1, x2;
-       int do_rect, do_float;
+       
+       
+       /* ImBuf in must have a valid rect or rect_float, assume this is alredy 
checked */
 
-       if (in==NULL) return;
-       if (in->rect==NULL && in->rect_float==NULL) return;
-
-       do_rect= (out->rect != NULL);
-       do_float= (out->rect_float != NULL);
-
        x1= (int)floor(u);
        x2= (int)ceil(u);
        y1= (int)floor(v);
@@ -240,16 +253,7 @@
        // sample area entirely outside image? 
        if (x2<0 || x1>in->x-1 || y2<0 || y1>in->y-1) return;
 
-       if (do_rect)
-               outI=(unsigned char *)out->rect + out->x * yout * 4 + 4*xout;
-       else
-               outI= NULL;
-       if (do_float)
-               outF=(float *)out->rect_float + out->x * yout * 4 + 4*xout;
-       else    
-               outF= NULL;
-
-       if (do_float) {
+       if (outF) {
                // sample including outside of edges of image 
                if (x1<0 || y1<0) row1= empty;
                else row1= (float *)in->rect_float + in->x * y1 * 4 + 4*x1;
@@ -272,7 +276,7 @@
                outF[2]= ma_mb*row1[2] + a_mb*row3[2] + ma_b*row2[2]+ 
a_b*row4[2];
                outF[3]= ma_mb*row1[3] + a_mb*row3[3] + ma_b*row2[3]+ 
a_b*row4[3];
        }
-       if (do_rect) {
+       if (outI) {
                // sample including outside of edges of image 
                if (x1<0 || y1<0) row1I= emptyI;
                else row1I= (unsigned char *)in->rect + in->x * y1 * 4 + 4*x1;
@@ -297,45 +301,44 @@
        }
 }
 
+void bilinear_interpolation(ImBuf *in, ImBuf *out, float u, float v, int xout, 
int yout)
+{
+       
+       unsigned char *outI = NULL;
+       float *outF = NULL;
+       
+       if (in == NULL || (in->rect == NULL && in->rect_float == NULL)) return;
+       
+       pixel_from_buffer(out, outI, outF, xout, yout); /* gcc warns these 
could be uninitialized, but its ok */
+       
+       bilinear_interpolation_color(in, outI, outF, u, v);
+}
+
 /* function assumes out to be zero'ed, only does RGBA */
 /* NEAREST INTERPOLATION */
-void neareast_interpolation(ImBuf *in, ImBuf *out, float u, float v,int xout, 
int yout)
+void neareast_interpolation_color(struct ImBuf *in, unsigned char *outI, float 
*outF, float u, float v)
 {
-       float *outF,*dataF;
-       unsigned char *dataI,*outI;
+       float *dataF;
+       unsigned char *dataI;
        int y1, x1;
-       int do_rect, do_float;
 
-       if (in==NULL) return;
-       if (in->rect==NULL && in->rect_float==NULL) return;
-
-       do_rect= (out->rect != NULL);
-       do_float= (out->rect_float != NULL);
-
+       /* ImBuf in must have a valid rect or rect_float, assume this is alredy 
checked */
+       
        x1= (int)(u);
        y1= (int)(v);
 
-       if (do_rect)
-               outI=(unsigned char *)out->rect + out->x * yout * 4 + 4*xout;
-       else
-               outI= NULL;
-       if (do_float)
-               outF=(float *)out->rect_float + out->x * yout * 4 + 4*xout;
-       else
-               outF= NULL;
-
        // sample area entirely outside image? 
        if (x1<0 || x1>in->x-1 || y1<0 || y1>in->y-1) return;
        
        // sample including outside of edges of image 
        if (x1<0 || y1<0) {
-               if (do_rect) {
+               if (outI) {
                        outI[0]= 0;
                        outI[1]= 0;
                        outI[2]= 0;
                        outI[3]= 0;
                }
-               if (do_float) {
+               if (outF) {
                        outF[0]= 0.0f;
                        outF[1]= 0.0f;
                        outF[2]= 0.0f;
@@ -343,14 +346,14 @@
                }
        } else {
                dataI= (unsigned char *)in->rect + in->x * y1 * 4 + 4*x1;
-               if (do_rect) {
+               if (outI) {
                        outI[0]= dataI[0];
                        outI[1]= dataI[1];
                        outI[2]= dataI[2];
                        outI[3]= dataI[3];
                }
                dataF= in->rect_float + in->x * y1 * 4 + 4*x1;
-               if (do_float) {
+               if (outF) {
                        outF[0]= dataF[0];
                        outF[1]= dataF[1];
                        outF[2]= dataF[2];
@@ -358,3 +361,16 @@
                }
        }       
 }
+
+void neareast_interpolation(ImBuf *in, ImBuf *out, float x, float y, int xout, 
int yout)
+{
+       
+       unsigned char *outI = NULL;
+       float *outF = NULL;
+
+       if (in == NULL || (in->rect == NULL && in->rect_float == NULL)) return;
+       
+       pixel_from_buffer(out, outI, outF, xout, yout); /* gcc warns these 
could be uninitialized, but its ok */
+       
+       neareast_interpolation_color(in, outI, outF, x, y);
+}
\ No newline at end of file


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to