Code cleanup: jitter, use 2d float array
authorCampbell Barton <ideasman42@gmail.com>
Mon, 17 Mar 2014 23:50:24 +0000 (10:50 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 17 Mar 2014 23:52:38 +0000 (10:52 +1100)
13 files changed:
source/blender/blenkernel/intern/editderivedmesh.c
source/blender/blenkernel/intern/effect.c
source/blender/blenkernel/intern/particle_system.c
source/blender/blenkernel/intern/smoke.c
source/blender/blenlib/BLI_jitter.h
source/blender/blenlib/intern/jitter.c
source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp
source/blender/editors/render/render_opengl.c
source/blender/render/intern/source/initrender.c
source/blender/render/intern/source/rayshade.c
source/blender/render/intern/source/rendercore.c
source/blender/render/intern/source/shadbuf.c
source/blender/render/intern/source/zbuf.c

index b3e0bfa387b39d26417880294544729cde35f8ef..913edba753ab48f94a65e69a26f08cd184d973f3 100644 (file)
@@ -1829,7 +1829,7 @@ static void statvis_calc_thickness(
        if (use_jit) {
                int j;
                BLI_assert(samples < 32);
-               BLI_jitter_init(jit_ofs[0], samples);
+               BLI_jitter_init(jit_ofs, samples);
 
                for (j = 0; j < samples; j++) {
                        uv_from_jitter_v2(jit_ofs[j]);
index fc18a204526750004e6f304087dfd7fe65d6723b..91d12d39af41f6d8e14e21de8a1d6315d67b8841 100644 (file)
@@ -55,7 +55,6 @@
 #include "BLI_math.h"
 #include "BLI_blenlib.h"
 #include "BLI_noise.h"
-#include "BLI_jitter.h"
 #include "BLI_rand.h"
 #include "BLI_utildefines.h"
 
index 92b2876cb7808ec4b5f2a4092c55edd438672a56..32f8ba920e64c4d4aa22809552a41ed46675e83d 100644 (file)
@@ -690,7 +690,7 @@ static void hammersley_create(float *out, int n, int seed, float amount)
        }
 }
 
-/* modified copy from effect.c */
+/* almost exact copy of BLI_jitter_init */
 static void init_mv_jit(float *jit, int num, int seed2, float amount)
 {
        RNG *rng;
@@ -721,9 +721,9 @@ static void init_mv_jit(float *jit, int num, int seed2, float amount)
        jit2= MEM_mallocN(12 + 2*sizeof(float)*num, "initjit");
 
        for (i=0 ; i<4 ; i++) {
-               BLI_jitterate1(jit, jit2, num, rad1);
-               BLI_jitterate1(jit, jit2, num, rad1);
-               BLI_jitterate2(jit, jit2, num, rad2);
+               BLI_jitterate1((float (*)[2])jit, (float (*)[2])jit2, num, rad1);
+               BLI_jitterate1((float (*)[2])jit, (float (*)[2])jit2, num, rad1);
+               BLI_jitterate2((float (*)[2])jit, (float (*)[2])jit2, num, rad2);
        }
        MEM_freeN(jit2);
        BLI_rng_free(rng);
index d8c27d4468c895eee847d63d8805eab7fce701d2..5e7f1983fe8217b89acf0e2834385d5528f8f830 100644 (file)
@@ -44,7 +44,6 @@
 
 #include "BLI_linklist.h"
 #include "BLI_rand.h"
-#include "BLI_jitter.h"
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 #include "BLI_edgehash.h"
index 936a5260a681b599be24f24e1636b5f68eec5c77..769fb4456784bac24059e3c4b042f68a52a22872 100644 (file)
@@ -32,9 +32,9 @@
  *  \ingroup bli
  */
 
-void    BLI_jitter_init(float *jitarr, int num);
-void    BLI_jitterate1(float *jit1, float *jit2, int num, float radius1);
-void    BLI_jitterate2(float *jit1, float *jit2, int num, float radius2);
+void BLI_jitter_init(float (*jitarr)[2], int num);
+void BLI_jitterate1(float (*jit1)[2], float (*jit2)[2], int num, float radius1);
+void BLI_jitterate2(float (*jit1)[2], float (*jit2)[2], int num, float radius2);
 
 #endif
 
index 7141bedcf05a8c984c5f2a80b016f0ecd7384883..bc2b5677fa567f86659938759886d748d2f01e95 100644 (file)
 #include "BLI_rand.h"
 #include "BLI_jitter.h"
 
+#include "BLI_strict_flags.h"
 
-void BLI_jitterate1(float *jit1, float *jit2, int num, float rad1)
+
+void BLI_jitterate1(float (*jit1)[2], float (*jit2)[2], int num, float rad1)
 {
        int i, j, k;
        float vecx, vecy, dvecx, dvecy, x, y, len;
 
-       for (i = 2 * num - 2; i >= 0; i -= 2) {
+       for (i = num - 1; i >= 0; i--) {
                dvecx = dvecy = 0.0;
-               x = jit1[i];
-               y = jit1[i + 1];
-               for (j = 2 * num - 2; j >= 0; j -= 2) {
+               x = jit1[i][0];
+               y = jit1[i][1];
+               for (j = num - 1; j >= 0; j--) {
                        if (i != j) {
-                               vecx = jit1[j] - x - 1.0f;
-                               vecy = jit1[j + 1] - y - 1.0f;
+                               vecx = jit1[j][0] - x - 1.0f;
+                               vecy = jit1[j][1] - y - 1.0f;
                                for (k = 3; k > 0; k--) {
                                        if (fabsf(vecx) < rad1 && fabsf(vecy) < rad1) {
-                                               len =  sqrt(vecx * vecx + vecy * vecy);
+                                               len =  sqrtf(vecx * vecx + vecy * vecy);
                                                if (len > 0 && len < rad1) {
                                                        len = len / rad1;
                                                        dvecx += vecx / len;
@@ -63,7 +65,7 @@ void BLI_jitterate1(float *jit1, float *jit2, int num, float rad1)
                                        vecx += 1.0f;
 
                                        if (fabsf(vecx) < rad1 && fabsf(vecy) < rad1) {
-                                               len =  sqrt(vecx * vecx + vecy * vecy);
+                                               len =  sqrtf(vecx * vecx + vecy * vecy);
                                                if (len > 0 && len < rad1) {
                                                        len = len / rad1;
                                                        dvecx += vecx / len;
@@ -73,7 +75,7 @@ void BLI_jitterate1(float *jit1, float *jit2, int num, float rad1)
                                        vecx += 1.0f;
 
                                        if (fabsf(vecx) < rad1 && fabsf(vecy) < rad1) {
-                                               len =  sqrt(vecx * vecx + vecy * vecy);
+                                               len =  sqrtf(vecx * vecx + vecy * vecy);
                                                if (len > 0 && len < rad1) {
                                                        len = len / rad1;
                                                        dvecx += vecx / len;
@@ -90,25 +92,25 @@ void BLI_jitterate1(float *jit1, float *jit2, int num, float rad1)
                y -= dvecy / 18.0f;
                x -= floorf(x);
                y -= floorf(y);
-               jit2[i] = x;
-               jit2[i + 1] = y;
+               jit2[i][0] = x;
+               jit2[i][1] = y;
        }
-       memcpy(jit1, jit2, 2 * num * sizeof(float));
+       memcpy(jit1, jit2, 2 * (unsigned int)num * sizeof(float));
 }
 
-void BLI_jitterate2(float *jit1, float *jit2, int num, float rad2)
+void BLI_jitterate2(float (*jit1)[2], float (*jit2)[2], int num, float rad2)
 {
        int i, j;
        float vecx, vecy, dvecx, dvecy, x, y;
 
-       for (i = 2 * num - 2; i >= 0; i -= 2) {
+       for (i = num - 1; i >= 0; i--) {
                dvecx = dvecy = 0.0;
-               x = jit1[i];
-               y = jit1[i + 1];
-               for (j = 2 * num - 2; j >= 0; j -= 2) {
+               x = jit1[i][0];
+               y = jit1[i][1];
+               for (j = num - 1; j >= 0; j--) {
                        if (i != j) {
-                               vecx = jit1[j] - x - 1.0f;
-                               vecy = jit1[j + 1] - y - 1.0f;
+                               vecx = jit1[j][0] - x - 1.0f;
+                               vecy = jit1[j][1] - y - 1.0f;
 
                                if (fabsf(vecx) < rad2) dvecx += vecx * rad2;
                                vecx += 1.0f;
@@ -129,32 +131,39 @@ void BLI_jitterate2(float *jit1, float *jit2, int num, float rad2)
                y -= dvecy / 2.0f;
                x -= floorf(x);
                y -= floorf(y);
-               jit2[i] = x;
-               jit2[i + 1] = y;
+               jit2[i][0] = x;
+               jit2[i][1] = y;
        }
-       memcpy(jit1, jit2, 2 * num * sizeof(float));
+       memcpy(jit1, jit2, (unsigned int)num * sizeof(float[2]));
 }
 
 
-void BLI_jitter_init(float *jitarr, int num)
+void BLI_jitter_init(float (*jitarr)[2], int num)
 {
-       float *jit2, x, rad1, rad2, rad3;
+       float (*jit2)[2];
+       float num_fl, num_fl_sqrt;
+       float x, rad1, rad2, rad3;
        RNG *rng;
        int i;
 
-       if (num == 0) return;
+       if (num == 0) {
+               return;
+       }
+
+       num_fl = (float)num;
+       num_fl_sqrt = sqrtf(num_fl);
 
-       jit2 = MEM_mallocN(12 + 2 * sizeof(float) * num, "initjit");
-       rad1 = 1.0f / sqrtf((float)num);
-       rad2 = 1.0f / ((float)num);
-       rad3 = sqrtf((float)num) / ((float)num);
+       jit2 = MEM_mallocN(12 + (unsigned int)num * sizeof(float[2]), "initjit");
+       rad1 = 1.0f        / num_fl_sqrt;
+       rad2 = 1.0f        / num_fl;
+       rad3 = num_fl_sqrt / num_fl;
 
-       rng = BLI_rng_new(31415926 + num);
+       rng = BLI_rng_new(31415926 + (unsigned int)num);
 
        x = 0;
-       for (i = 0; i < 2 * num; i += 2) {
-               jitarr[i] = x + rad1 * (float)(0.5 - BLI_rng_get_double(rng));
-               jitarr[i + 1] = ((float)i / 2) / num + rad1 * (float)(0.5 - BLI_rng_get_double(rng));
+       for (i = 0; i < num; i++) {
+               jitarr[i][0] =                 x + rad1 * (float)(0.5 - BLI_rng_get_double(rng));
+               jitarr[i][1] = (float)i / num_fl + rad1 * (float)(0.5 - BLI_rng_get_double(rng));
                x += rad3;
                x -= floorf(x);
        }
@@ -170,12 +179,8 @@ void BLI_jitter_init(float *jitarr, int num)
        MEM_freeN(jit2);
        
        /* finally, move jittertab to be centered around (0, 0) */
-       for (i = 0; i < 2 * num; i += 2) {
-               jitarr[i] -= 0.5f;
-               jitarr[i + 1] -= 0.5f;
+       for (i = 0; i < num; i++) {
+               jitarr[i][0] -= 0.5f;
+               jitarr[i][1] -= 0.5f;
        }
-       
 }
-
-
-/* eof */
index 362d7f6d2d7dfb2f3c2103f531bada83cf6a3362..c507b4cfa98aa22d25ca9684372e6c3f04b1b3ea 100644 (file)
@@ -171,7 +171,7 @@ void PlaneDistortMaskOperation::calculateCorners(const float corners[4][2], bool
 
 void PlaneDistortMaskOperation::initExecution()
 {
-       BLI_jitter_init(m_jitter[0], m_osa);
+       BLI_jitter_init(m_jitter, m_osa);
 }
 
 void PlaneDistortMaskOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
index 354ea4df5c7ab7c1e44a0c50adf876c4d5d02eb4..dba44bacd039a299342dbf919c7bcc90f55683d5 100644 (file)
@@ -212,7 +212,7 @@ static void screen_opengl_render_apply(OGLRender *oglrender)
                        int *accum_buffer = MEM_mallocN(sizex * sizey * sizeof(int) * 4, "accum1");
                        int i, j;
 
-                       BLI_jitter_init(jit_ofs[0], scene->r.osa);
+                       BLI_jitter_init(jit_ofs, scene->r.osa);
 
                        /* first sample buffer, also initializes 'rv3d->persmat' */
                        ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat, draw_bgpic, draw_sky);
index 2fb723faa1291ac0a73fae1044c01f5ae904f3cb..fa47593bbe4402489d4f30c7805891738024e5cd 100644 (file)
@@ -92,10 +92,10 @@ static void init_render_jit(Render *re)
        
        if (lastjit != re->r.osa || last_mblur_jit != re->r.mblur_samples) {
                memset(jit, 0, sizeof(jit));
-               BLI_jitter_init(jit[0], re->r.osa);
+               BLI_jitter_init(jit, re->r.osa);
                
                memset(mblur_jit, 0, sizeof(mblur_jit));
-               BLI_jitter_init(mblur_jit[0], re->r.mblur_samples);
+               BLI_jitter_init(mblur_jit, re->r.mblur_samples);
        }
        
        lastjit = re->r.osa;
index 6dd2692f52e3dfaee4744bab00fac1029f11672d..ae5b9ec5999173f7e383bd1d9791863bdc3d33bd 100644 (file)
@@ -42,7 +42,6 @@
 
 #include "BLI_blenlib.h"
 #include "BLI_cpu.h"
-#include "BLI_jitter.h"
 #include "BLI_math.h"
 #include "BLI_rand.h"
 #include "BLI_utildefines.h"
index c3ca3ee45592f8e92577bf13607b61a8201e5aeb..a6f37f2670c1f081128eb695472c3ffde94884b3 100644 (file)
@@ -41,7 +41,6 @@
 
 #include "BLI_math.h"
 #include "BLI_blenlib.h"
-#include "BLI_jitter.h"
 #include "BLI_rand.h"
 #include "BLI_threads.h"
 #include "BLI_utildefines.h"
index 0c3bf85cd241959efc7bb1a7b6c2a8d0213f160c..9010cf8917e05c10f58050edef6575485bb1256f 100644 (file)
@@ -141,7 +141,7 @@ static float *give_jitter_tab(int samp)
 
        if (ctab[samp]==0) {
                ctab[samp]= 1;
-               BLI_jitter_init(jit[offset], samp*samp);
+               BLI_jitter_init((float (*)[2])jit[offset], samp*samp);
        }
                
        return jit[offset];
index 37cf9ad76c3a88b4e10659db3113443619c6128a..a74d6efbc0b822c7e72f06334345a166dbf2563f 100644 (file)
@@ -3066,7 +3066,7 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
        /* has to become static, the init-jit calls a random-seed, screwing up texture noise node */
        if (firsttime) {
                firsttime= 0;
-               BLI_jitter_init(jit[0], 256);
+               BLI_jitter_init(jit, 256);
        }
        
        memset(newrect, 0, sizeof(float)*xsize*ysize*4);