code cleanup: replace most fRGB functions with inline vector functions
authorCampbell Barton <ideasman42@gmail.com>
Thu, 14 Jun 2012 19:22:55 +0000 (19:22 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 14 Jun 2012 19:22:55 +0000 (19:22 +0000)
source/blender/compositor/operations/COM_GlareBaseOperation.h
source/blender/compositor/operations/COM_GlareFogGlowOperation.cpp
source/blender/compositor/operations/COM_GlareGhostOperation.cpp
source/blender/nodes/composite/node_composite_util.c
source/blender/nodes/composite/node_composite_util.h
source/blender/nodes/composite/nodes/node_composite_glare.c
source/blender/nodes/composite/nodes/node_composite_tonemap.c

index dc708044d31339cb089358720f55ce0999f5fa34..ac67ac055e916e2f2a79136cbb033a02d3423d37 100644 (file)
 typedef float fRGB[4];
 
 /* TODO - replace with BLI_math_vector */
-/* copy c2 to c1 */
-#define fRGB_copy(c1, c2) { c1[0] = c2[0];  c1[1] = c2[1];  c1[2] = c2[2]; c1[3] = c2[3]; } (void)0
-/* add c2 to c1 */
-#define fRGB_add(c1, c2) { c1[0] += c2[0];  c1[1] += c2[1];  c1[2] += c2[2]; } (void)0
-/* multiply c by float value s */
-#define fRGB_mult(c, s) { c[0] *= s;  c[1] *= s;  c[2] *= s; } (void)0
-/* multiply c2 by s and add to c1 */
-#define fRGB_madd(c1, c2, s) { c1[0] += c2[0] * s;  c1[1] += c2[1] * s;  c1[2] += c2[2] * s; } (void)0
-/* multiply c2 by color c1 */
-#define fRGB_colormult(c, cs) { c[0] *= cs[0];  c[1] *= cs[1];  c[2] *= cs[2]; } (void)0
 /* multiply c2 by color rgb, rgb as separate arguments */
 #define fRGB_rgbmult(c, r, g, b) { c[0] *= (r);  c[1] *= (g);  c[2] *= (b); } (void)0
 
index a91445be4b5b49a2e665231e6ef4aa38f8e49364..694aa26bcde40741370b76200aeba25eb3ec0511 100644 (file)
@@ -277,7 +277,7 @@ void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
        for (y = 0; y < kernelHeight; y++) {
                colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_NUMBER_OF_CHANNELS];
                for (x = 0; x < kernelWidth; x++)
-                       fRGB_add(wt, colp[x]);
+                       add_v3_v3(wt, colp[x]);
        }
        if (wt[0] != 0.f) wt[0] = 1.f / wt[0];
        if (wt[1] != 0.f) wt[1] = 1.f / wt[1];
@@ -285,7 +285,7 @@ void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
        for (y = 0; y < kernelHeight; y++) {
                colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_NUMBER_OF_CHANNELS];
                for (x = 0; x < kernelWidth; x++)
-                       fRGB_colormult(colp[x], wt);
+                       mul_v3_v3(colp[x], wt);
        }
 
        // copy image data, unpacking interleaved RGBA into separate channels
@@ -395,7 +395,7 @@ void GlareFogGlowOperation::generateGlare(float *data, MemoryBuffer *inputTile,
                        //w = (1.f-fabs(u))*(1.f-fabs(v));
                        // actually, Hanning window is ok, cos^2 for some reason is slower
                        w = (0.5f + 0.5f * cos((double)u * M_PI)) * (0.5f + 0.5f * cos((double)v * M_PI));
-                       fRGB_mult(fcol, w);
+                       mul_v3_fl(fcol, w);
                        ckrn->writePixel(x, y, fcol);
                }
        }
index 2d5fe57b817b1bfef7be5ae14b636a53f494a74f..39fffd6ac6407eaa92f450ea402a070a997b8708 100644 (file)
@@ -85,11 +85,11 @@ void GlareGhostOperation::generateGlare(float *data, MemoryBuffer *inputTile, No
                        s = (u - 0.5f) * sc + 0.5f, t = (v - 0.5f) * sc + 0.5f;
                        tbuf1->read(c, s * gbuf->getWidth(), t * gbuf->getHeight());
                        sm = smoothMask(s, t);
-                       fRGB_mult(c, sm);
+                       mul_v3_fl(c, sm);
                        s = (u - 0.5f) * isc + 0.5f, t = (v - 0.5f) * isc + 0.5f;
                        tbuf2->read(tc, s * gbuf->getWidth() - 0.5f, t * gbuf->getHeight() - 0.5f);
                        sm = smoothMask(s, t);
-                       fRGB_madd(c, tc, sm);
+                       madd_v3_v3fl(c, tc, sm);
 
                        gbuf->writePixel(x, y, c);
                }
@@ -109,9 +109,9 @@ void GlareGhostOperation::generateGlare(float *data, MemoryBuffer *inputTile, No
                                        s = (u - 0.5f) * scalef[np] + 0.5f;
                                        t = (v - 0.5f) * scalef[np] + 0.5f;
                                        gbuf->read(c, s * gbuf->getWidth() - 0.5f, t * gbuf->getHeight() - 0.5f);
-                                       fRGB_colormult(c, cm[np]);
+                                       mul_v3_v3(c, cm[np]);
                                        sm = smoothMask(s, t) * 0.25f;
-                                       fRGB_madd(tc, c, sm);
+                                       madd_v3_v3fl(tc, c, sm);
                                }
                                tbuf1->addPixel(x, y, tc);
                        }
index ff223ac83cf7a07d111df6b9f3a9f84a0750363c..afd10d96e99355f57bbc439377506828100759a0 100644 (file)
@@ -1022,7 +1022,7 @@ void convolve(CompBuf* dst, CompBuf* in1, CompBuf* in2)
        for (y=0; y<in2->y; y++) {
                colp = (fRGB*)&in2->rect[y*in2->x*in2->type];
                for (x=0; x<in2->x; x++)
-                       fRGB_add(wt, colp[x]);
+                       add_v3_v3(wt, colp[x]);
        }
        if (wt[0] != 0.f) wt[0] = 1.f/wt[0];
        if (wt[1] != 0.f) wt[1] = 1.f/wt[1];
@@ -1030,7 +1030,7 @@ void convolve(CompBuf* dst, CompBuf* in1, CompBuf* in2)
        for (y=0; y<in2->y; y++) {
                colp = (fRGB*)&in2->rect[y*in2->x*in2->type];
                for (x=0; x<in2->x; x++)
-                       fRGB_colormult(colp[x], wt);
+                       mul_v3_v3(colp[x], wt);
        }
 
        // copy image data, unpacking interleaved RGBA into separate channels
@@ -1279,14 +1279,14 @@ CompBuf* qd_downScaledCopy(CompBuf* src, int scale)
                                        xx = x*scale;
                                        mx = xx + scale;
                                        if (mx > src->x) mx = src->x;
-                                       colsum[0] = colsum[1] = colsum[2] = 0.f;
+                                       zero_v3(colsum);
                                        for (sy=yy; sy<my; sy++) {
                                                fRGB* scolp = (fRGB*)&src->rect[sy*src->x*src->type];
                                                for (sx=xx; sx<mx; sx++)
-                                                       fRGB_add(colsum, scolp[sx]);
+                                                       add_v3_v3(colsum, scolp[sx]);
                                        }
-                                       fRGB_mult(colsum, fscale);
-                                       fRGB_copy(fcolp[x], colsum);
+                                       mul_v3_fl(colsum, fscale);
+                                       copy_v3_v3(fcolp[x], colsum);
                                }
                        }
                }
index 42e6ea6bd20e122e3926d685f04d452011a8b58c..8f772b19d5e55ad30531b29b4e15cef6d4354b66 100644 (file)
@@ -182,16 +182,6 @@ extern void node_ID_title_cb(void *node_v, void *unused_v);
 /* utility functions used by glare, tonemap and lens distortion */
 /* soms macros for color handling */
 typedef float fRGB[4];
-/* copy c2 to c1 */
-#define fRGB_copy(c1, c2) { c1[0]=c2[0];  c1[1]=c2[1];  c1[2]=c2[2]; c1[3]=c2[3]; } (void)0
-/* add c2 to c1 */
-#define fRGB_add(c1, c2) { c1[0]+=c2[0];  c1[1]+=c2[1];  c1[2]+=c2[2]; } (void)0
-/* multiply c by float value s */
-#define fRGB_mult(c, s) { c[0]*=s;  c[1]*=s;  c[2]*=s; } (void)0
-/* multiply c2 by s and add to c1 */
-#define fRGB_madd(c1, c2, s) { c1[0]+=c2[0]*s;  c1[1]+=c2[1]*s;  c1[2]+=c2[2]*s; } (void)0
-/* multiply c2 by color c1 */
-#define fRGB_colormult(c, cs) { c[0]*=cs[0];  c[1]*=cs[1];  c[2]*=cs[2]; } (void)0
 /* multiply c2 by color rgb, rgb as separate arguments */
 #define fRGB_rgbmult(c, r, g, b) { c[0]*=(r);  c[1]*=(g);  c[2]*=(b); } (void)0
 
index 9b1505e933326403994a57f110d8375b19ed0e21..17a23d4295e6d6d96dc8d45964fc20824f980979 100644 (file)
@@ -53,16 +53,16 @@ static void mixImages(CompBuf *dst, CompBuf *src, float mix)
                        dcolp = (fRGB*)&dst->rect[y*dst->x*dst->type];
                        scolp = (fRGB*)&src->rect[y*dst->x*dst->type];
                        for (x=0; x<dst->x; x++) {
-                               fRGB_copy(c1, dcolp[x]);
-                               fRGB_copy(c2, scolp[x]);
+                               copy_v3_v3(c1, dcolp[x]);
+                               copy_v3_v3(c2, scolp[x]);
                                c1[0] += mix*(c2[0] - c1[0]);
                                c1[1] += mix*(c2[1] - c1[1]);
                                c1[2] += mix*(c2[2] - c1[2]);
                                if (c1[0] < 0.f) c1[0] = 0.f;
                                if (c1[1] < 0.f) c1[1] = 0.f;
                                if (c1[2] < 0.f) c1[2] = 0.f;
-                               fRGB_mult(c1, mf);
-                               fRGB_copy(dcolp[x], c1);
+                               mul_v3_fl(c1, mf);
+                               copy_v3_v3(dcolp[x], c1);
                        }
                }
        }
@@ -72,7 +72,7 @@ static void mixImages(CompBuf *dst, CompBuf *src, float mix)
                for (y=0; y<dst->y; y++) {
                        dcolp = (fRGB*)&dst->rect[y*dst->x*dst->type];
                        for (x=0; x<dst->x; x++) {
-                               fRGB_copy(c1, dcolp[x]);
+                               copy_v3_v3(c1, dcolp[x]);
                                qd_getPixelLerp(src, (x + 0.5f)*xr - 0.5f, (y + 0.5f)*yr - 0.5f, c2);
                                c1[0] += mix*(c2[0] - c1[0]);
                                c1[1] += mix*(c2[1] - c1[1]);
@@ -80,8 +80,8 @@ static void mixImages(CompBuf *dst, CompBuf *src, float mix)
                                if (c1[0] < 0.f) c1[0] = 0.f;
                                if (c1[1] < 0.f) c1[1] = 0.f;
                                if (c1[2] < 0.f) c1[2] = 0.f;
-                               fRGB_mult(c1, mf);
-                               fRGB_copy(dcolp[x], c1);
+                               mul_v3_fl(c1, mf);
+                               copy_v3_v3(dcolp[x], c1);
                        }
                }
        }
@@ -146,11 +146,11 @@ static void star4(NodeGlare* ndg, CompBuf* dst, CompBuf* src)
                                xm = x - i;
                                xp = x + i;
                                qd_getPixel(tbuf1, x, y, c);
-                               fRGB_mult(c, f1);
+                               mul_v3_fl(c, f1);
                                qd_getPixel(tbuf1, (ndg->angle ? xm : x), ym, tc);
-                               fRGB_madd(c, tc, f2);
+                               madd_v3_v3fl(c, tc, f2);
                                qd_getPixel(tbuf1, (ndg->angle ? xp : x), yp, tc);
-                               fRGB_madd(c, tc, f2);
+                               madd_v3_v3fl(c, tc, f2);
                                qd_setPixel(tbuf1, x, y, c);
                        }
                }
@@ -162,11 +162,11 @@ static void star4(NodeGlare* ndg, CompBuf* dst, CompBuf* src)
                                xm = x - i;
                                xp = x + i;
                                qd_getPixel(tbuf1, x, y, c);
-                               fRGB_mult(c, f1);
+                               mul_v3_fl(c, f1);
                                qd_getPixel(tbuf1, (ndg->angle ? xm : x), ym, tc);
-                               fRGB_madd(c, tc, f2);
+                               madd_v3_v3fl(c, tc, f2);
                                qd_getPixel(tbuf1, (ndg->angle ? xp : x), yp, tc);
-                               fRGB_madd(c, tc, f2);
+                               madd_v3_v3fl(c, tc, f2);
                                qd_setPixel(tbuf1, x, y, c);
                        }
                }
@@ -179,11 +179,11 @@ static void star4(NodeGlare* ndg, CompBuf* dst, CompBuf* src)
                                xm = x - i;
                                xp = x + i;
                                qd_getPixel(tbuf2, x, y, c);
-                               fRGB_mult(c, f1);
+                               mul_v3_fl(c, f1);
                                qd_getPixel(tbuf2, xm, (ndg->angle ? yp : y), tc);
-                               fRGB_madd(c, tc, f2);
+                               madd_v3_v3fl(c, tc, f2);
                                qd_getPixel(tbuf2, xp, (ndg->angle ? ym : y), tc);
-                               fRGB_madd(c, tc, f2);
+                               madd_v3_v3fl(c, tc, f2);
                                qd_setPixel(tbuf2, x, y, c);
                        }
                }
@@ -195,11 +195,11 @@ static void star4(NodeGlare* ndg, CompBuf* dst, CompBuf* src)
                                xm = x - i;
                                xp = x + i;
                                qd_getPixel(tbuf2, x, y, c);
-                               fRGB_mult(c, f1);
+                               mul_v3_fl(c, f1);
                                qd_getPixel(tbuf2, xm, (ndg->angle ? yp : y), tc);
-                               fRGB_madd(c, tc, f2);
+                               madd_v3_v3fl(c, tc, f2);
                                qd_getPixel(tbuf2, xp, (ndg->angle ? ym : y), tc);
-                               fRGB_madd(c, tc, f2);
+                               madd_v3_v3fl(c, tc, f2);
                                qd_setPixel(tbuf2, x, y, c);
                        }
                }
@@ -342,11 +342,11 @@ static void ghosts(NodeGlare* ndg, CompBuf* dst, CompBuf* src)
                        s = (u-0.5f)*sc + 0.5f, t = (v-0.5f)*sc + 0.5f;
                        qd_getPixelLerp(tbuf1, s*gbuf->x, t*gbuf->y, c);
                        sm = smoothMask(s, t);
-                       fRGB_mult(c, sm);
+                       mul_v3_fl(c, sm);
                        s = (u-0.5f)*isc + 0.5f, t = (v-0.5f)*isc + 0.5f;
                        qd_getPixelLerp(tbuf2, s*gbuf->x - 0.5f, t*gbuf->y - 0.5f, tc);
                        sm = smoothMask(s, t);
-                       fRGB_madd(c, tc, sm);
+                       madd_v3_v3fl(c, tc, sm);
                        qd_setPixel(gbuf, x, y, c);
                }
        }
@@ -363,9 +363,9 @@ static void ghosts(NodeGlare* ndg, CompBuf* dst, CompBuf* src)
                                        s = (u-0.5f)*scalef[np] + 0.5f;
                                        t = (v-0.5f)*scalef[np] + 0.5f;
                                        qd_getPixelLerp(gbuf, s*gbuf->x - 0.5f, t*gbuf->y - 0.5f, c);
-                                       fRGB_colormult(c, cm[np]);
+                                       mul_v3_v3(c, cm[np]);
                                        sm = smoothMask(s, t)*0.25f;
-                                       fRGB_madd(tc, c, sm);
+                                       madd_v3_v3fl(tc, c, sm);
                                }
                                p = (x + y*tbuf1->x)*tbuf1->type;
                                tbuf1->rect[p] += tc[0];
@@ -413,7 +413,7 @@ static void fglow(NodeGlare* ndg, CompBuf* dst, CompBuf* src)
                        //w = (1.f-fabs(u))*(1.f-fabs(v));
                        // actually, Hanning window is ok, cos^2 for some reason is slower
                        w = (0.5f + 0.5f*cos((double)u*M_PI))*(0.5f + 0.5f*cos((double)v*M_PI));
-                       fRGB_mult(fcol, w);
+                       mul_v3_fl(fcol, w);
                        qd_setPixel(ckrn, x, y, fcol);
                }
        }
index 6196825c9b3761e8c60d3b6d3ed7b723de222b37..50006e599e50d8fefb3a71685a962598de0f7118 100644 (file)
@@ -53,14 +53,14 @@ static float avgLogLum(CompBuf *src, float* auto_key, float* Lav, float* Cav)
        while (p--) {
                float L = rgb_to_luma_y(bc[0]);
                *Lav += L;
-               fRGB_add(Cav, bc[0]);
+               add_v3_v3(Cav, bc[0]);
                lsum += (float)log((double)MAX2(L, 0.0) + 1e-5);
                maxl = (L > maxl) ? L : maxl;
                minl = (L < minl) ? L : minl;
                bc++;
        }
        *Lav *= sc;
-       fRGB_mult(Cav, sc);
+       mul_v3_fl(Cav, sc);
        maxl = log((double)maxl + 1e-5); minl = log((double)minl + 1e-5f); avl = lsum*sc;
        *auto_key = (maxl > minl) ? ((maxl - avl) / (maxl - minl)) : 1.f;
        return exp((double)avl);
@@ -109,8 +109,8 @@ static void tonemap(NodeTonemap* ntm, CompBuf* dst, CompBuf* src)
                fRGB* sp = (fRGB*)&src->rect[y*src->x*src->type];
                fRGB* dp = (fRGB*)&dst->rect[y*src->x*src->type];
                for (x=0; x<src->x; x++) {
-                       fRGB_copy(dp[x], sp[x]);
-                       fRGB_mult(dp[x], al);
+                       copy_v4_v4(dp[x], sp[x]);
+                       mul_v3_fl(dp[x], al);
                        dr = dp[x][0] + ntm->offset;
                        dg = dp[x][1] + ntm->offset;
                        db = dp[x][2] + ntm->offset;