[Bf-blender-cvs] [ec55074] master: Code cleanup: jitter, use 2d float array
Campbell Barton
noreply at git.blender.org
Tue Mar 18 00:52:48 CET 2014
Commit: ec55074f89220ba729e2b84058a3a55feb13ab34
Author: Campbell Barton
Date: Tue Mar 18 10:50:24 2014 +1100
https://developer.blender.org/rBec55074f89220ba729e2b84058a3a55feb13ab34
Code cleanup: jitter, use 2d float array
===================================================================
M source/blender/blenkernel/intern/editderivedmesh.c
M source/blender/blenkernel/intern/effect.c
M source/blender/blenkernel/intern/particle_system.c
M source/blender/blenkernel/intern/smoke.c
M source/blender/blenlib/BLI_jitter.h
M source/blender/blenlib/intern/jitter.c
M source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp
M source/blender/editors/render/render_opengl.c
M source/blender/render/intern/source/initrender.c
M source/blender/render/intern/source/rayshade.c
M source/blender/render/intern/source/rendercore.c
M source/blender/render/intern/source/shadbuf.c
M source/blender/render/intern/source/zbuf.c
===================================================================
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c
index b3e0bfa..913edba 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 fc18a20..91d12d3 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 92b2876..32f8ba9 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 d8c27d4..5e7f198 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 936a526..769fb44 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 7141bed..bc2b567 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 362d7f6..c507b4c 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 354ea4d..dba44ba 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 2fb723f..fa47593 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 6dd2692..ae5b9ec 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"
#incl
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list