Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-03-18 03:50:24 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-03-18 03:52:38 +0400
commitec55074f89220ba729e2b84058a3a55feb13ab34 (patch)
tree31d0126d1d3b6223fdc44c6387afa452b052780b /source/blender
parent4d44f70d5ff7f4948be85f67f2d88e9df799b532 (diff)
Code cleanup: jitter, use 2d float array
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/intern/editderivedmesh.c2
-rw-r--r--source/blender/blenkernel/intern/effect.c1
-rw-r--r--source/blender/blenkernel/intern/particle_system.c8
-rw-r--r--source/blender/blenkernel/intern/smoke.c1
-rw-r--r--source/blender/blenlib/BLI_jitter.h6
-rw-r--r--source/blender/blenlib/intern/jitter.c87
-rw-r--r--source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp2
-rw-r--r--source/blender/editors/render/render_opengl.c2
-rw-r--r--source/blender/render/intern/source/initrender.c4
-rw-r--r--source/blender/render/intern/source/rayshade.c1
-rw-r--r--source/blender/render/intern/source/rendercore.c1
-rw-r--r--source/blender/render/intern/source/shadbuf.c2
-rw-r--r--source/blender/render/intern/source/zbuf.c2
13 files changed, 60 insertions, 59 deletions
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c
index b3e0bfa387b..913edba753a 100644
--- a/source/blender/blenkernel/intern/editderivedmesh.c
+++ b/source/blender/blenkernel/intern/editderivedmesh.c
@@ -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]);
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c
index fc18a204526..91d12d39af4 100644
--- a/source/blender/blenkernel/intern/effect.c
+++ b/source/blender/blenkernel/intern/effect.c
@@ -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"
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index 92b2876cb78..32f8ba920e6 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -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);
diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index d8c27d4468c..5e7f1983fe8 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -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"
diff --git a/source/blender/blenlib/BLI_jitter.h b/source/blender/blenlib/BLI_jitter.h
index 936a5260a68..769fb445678 100644
--- a/source/blender/blenlib/BLI_jitter.h
+++ b/source/blender/blenlib/BLI_jitter.h
@@ -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
diff --git a/source/blender/blenlib/intern/jitter.c b/source/blender/blenlib/intern/jitter.c
index 7141bedcf05..bc2b5677fa5 100644
--- a/source/blender/blenlib/intern/jitter.c
+++ b/source/blender/blenlib/intern/jitter.c
@@ -37,23 +37,25 @@
#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 */
diff --git a/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp b/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp
index 362d7f6d2d7..c507b4cfa98 100644
--- a/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp
+++ b/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp
@@ -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)
diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c
index 354ea4df5c7..dba44bacd03 100644
--- a/source/blender/editors/render/render_opengl.c
+++ b/source/blender/editors/render/render_opengl.c
@@ -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);
diff --git a/source/blender/render/intern/source/initrender.c b/source/blender/render/intern/source/initrender.c
index 2fb723faa12..fa47593bbe4 100644
--- a/source/blender/render/intern/source/initrender.c
+++ b/source/blender/render/intern/source/initrender.c
@@ -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;
diff --git a/source/blender/render/intern/source/rayshade.c b/source/blender/render/intern/source/rayshade.c
index 6dd2692f52e..ae5b9ec5999 100644
--- a/source/blender/render/intern/source/rayshade.c
+++ b/source/blender/render/intern/source/rayshade.c
@@ -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"
diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c
index c3ca3ee4559..a6f37f2670c 100644
--- a/source/blender/render/intern/source/rendercore.c
+++ b/source/blender/render/intern/source/rendercore.c
@@ -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"
diff --git a/source/blender/render/intern/source/shadbuf.c b/source/blender/render/intern/source/shadbuf.c
index 0c3bf85cd24..9010cf8917e 100644
--- a/source/blender/render/intern/source/shadbuf.c
+++ b/source/blender/render/intern/source/shadbuf.c
@@ -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];
diff --git a/source/blender/render/intern/source/zbuf.c b/source/blender/render/intern/source/zbuf.c
index 37cf9ad76c3..a74d6efbc0b 100644
--- a/source/blender/render/intern/source/zbuf.c
+++ b/source/blender/render/intern/source/zbuf.c
@@ -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);