From 19f79f73a8b241127bec2b177b8f7d289071120a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 22 Oct 2011 03:39:13 +0000 Subject: BLI_utildefine minor edits - removed AVG2, was only used once. - remove unused LONGCOPY define. - removed BLI_STRUCT_OFFSET, was only used once, replce with offsetof - formatting edits, split some macros over multiple lines. --- source/blender/blenkernel/intern/subsurf_ccg.c | 2 +- source/blender/blenlib/BLI_blenlib.h | 7 - source/blender/blenlib/BLI_utildefines.h | 226 +++++++++++++-------- .../nodes/node_composite_directionalblur.c | 5 +- 4 files changed, 146 insertions(+), 94 deletions(-) diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 3d3806f7c02..0d9f27e4fa9 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -141,7 +141,7 @@ static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, int useAgin ccgSubSurf_setUseAgeCounts(ccgSS, 1, 8, 8, 8); } - ccgSubSurf_setCalcVertexNormals(ccgSS, 1, BLI_STRUCT_OFFSET(DMGridData, no)); + ccgSubSurf_setCalcVertexNormals(ccgSS, 1, offsetof(DMGridData, no)); return ccgSS; } diff --git a/source/blender/blenlib/BLI_blenlib.h b/source/blender/blenlib/BLI_blenlib.h index 4eb4b71da12..a5c0e03c09e 100644 --- a/source/blender/blenlib/BLI_blenlib.h +++ b/source/blender/blenlib/BLI_blenlib.h @@ -84,13 +84,6 @@ extern "C" { #include "BLI_noise.h" -/** - * @param strct The structure of interest - * @param member The name of a member field of @a strct - * @retval The offset in bytes of @a member within @a strct - */ -#define BLI_STRUCT_OFFSET(strct, member) ((int)(intptr_t) &((strct*) 0)->member) - #ifdef __cplusplus } #endif diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index b2b3e7381c6..c1eed40de74 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -67,63 +67,113 @@ #define MAX3(x,y,z) MAX2( MAX2((x),(y)) , (z) ) #define MAX4(x,y,z,a) MAX2( MAX2((x),(y)) , MAX2((z),(a)) ) -#define INIT_MINMAX(min, max) { (min)[0]= (min)[1]= (min)[2]= 1.0e30f; (max)[0]= (max)[1]= (max)[2]= -1.0e30f; } - -#define INIT_MINMAX2(min, max) { (min)[0]= (min)[1]= 1.0e30f; (max)[0]= (max)[1]= -1.0e30f; } - -#define DO_MIN(vec, min) { if( (min)[0]>(vec)[0] ) (min)[0]= (vec)[0]; \ - if( (min)[1]>(vec)[1] ) (min)[1]= (vec)[1]; \ - if( (min)[2]>(vec)[2] ) (min)[2]= (vec)[2]; } \ - -#define DO_MAX(vec, max) { if( (max)[0]<(vec)[0] ) (max)[0]= (vec)[0]; \ - if( (max)[1]<(vec)[1] ) (max)[1]= (vec)[1]; \ - if( (max)[2]<(vec)[2] ) (max)[2]= (vec)[2]; } \ - -#define DO_MINMAX(vec, min, max) { if( (min)[0]>(vec)[0] ) (min)[0]= (vec)[0]; \ - if( (min)[1]>(vec)[1] ) (min)[1]= (vec)[1]; \ - if( (min)[2]>(vec)[2] ) (min)[2]= (vec)[2]; \ - if( (max)[0]<(vec)[0] ) (max)[0]= (vec)[0]; \ - if( (max)[1]<(vec)[1] ) (max)[1]= (vec)[1]; \ - if( (max)[2]<(vec)[2] ) (max)[2]= (vec)[2]; } \ - -#define DO_MINMAX2(vec, min, max) { if( (min)[0]>(vec)[0] ) (min)[0]= (vec)[0]; \ - if( (min)[1]>(vec)[1] ) (min)[1]= (vec)[1]; \ - if( (max)[0]<(vec)[0] ) (max)[0]= (vec)[0]; \ - if( (max)[1]<(vec)[1] ) (max)[1]= (vec)[1]; } +#define INIT_MINMAX(min, max) { \ + (min)[0]= (min)[1]= (min)[2]= 1.0e30f; \ + (max)[0]= (max)[1]= (max)[2]= -1.0e30f; \ + } +#define INIT_MINMAX2(min, max) { \ + (min)[0]= (min)[1]= 1.0e30f; \ + (max)[0]= (max)[1]= -1.0e30f; \ + } +#define DO_MIN(vec, min) { \ + if( (min)[0]>(vec)[0] ) (min)[0]= (vec)[0]; \ + if( (min)[1]>(vec)[1] ) (min)[1]= (vec)[1]; \ + if( (min)[2]>(vec)[2] ) (min)[2]= (vec)[2]; \ + } +#define DO_MAX(vec, max) { \ + if( (max)[0]<(vec)[0] ) (max)[0]= (vec)[0]; \ + if( (max)[1]<(vec)[1] ) (max)[1]= (vec)[1]; \ + if( (max)[2]<(vec)[2] ) (max)[2]= (vec)[2]; \ + } +#define DO_MINMAX(vec, min, max) { \ + if( (min)[0]>(vec)[0] ) (min)[0]= (vec)[0]; \ + if( (min)[1]>(vec)[1] ) (min)[1]= (vec)[1]; \ + if( (min)[2]>(vec)[2] ) (min)[2]= (vec)[2]; \ + if( (max)[0]<(vec)[0] ) (max)[0]= (vec)[0]; \ + if( (max)[1]<(vec)[1] ) (max)[1]= (vec)[1]; \ + if( (max)[2]<(vec)[2] ) (max)[2]= (vec)[2]; \ + } +#define DO_MINMAX2(vec, min, max) { \ + if( (min)[0]>(vec)[0] ) (min)[0]= (vec)[0]; \ + if( (min)[1]>(vec)[1] ) (min)[1]= (vec)[1]; \ + if( (max)[0]<(vec)[0] ) (max)[0]= (vec)[0]; \ + if( (max)[1]<(vec)[1] ) (max)[1]= (vec)[1]; \ + } /* some math and copy defines */ #ifndef SWAP -# define SWAP(type, a, b) { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; } +# define SWAP(type, a, b) { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; } #endif -#define ABS(a) ( (a)<0 ? (-(a)) : (a) ) - -#define AVG2(x, y) ( 0.5 * ((x) + (y)) ) +#define ABS(a) ( (a)<0 ? (-(a)) : (a) ) #define FTOCHAR(val) ((val)<=0.0f)? 0 : (((val)>(1.0f-0.5f/255.0f))? 255 : (char)((255.0f*(val))+0.5f)) #define FTOUSHORT(val) ((val >= 1.0f-0.5f/65535)? 65535: (val <= 0.0f)? 0: (unsigned short)(val*65535.0f + 0.5f)) -#define F3TOCHAR3(v2,v1) (v1)[0]=FTOCHAR((v2[0])); (v1)[1]=FTOCHAR((v2[1])); (v1)[2]=FTOCHAR((v2[2])) -#define F3TOCHAR4(v2,v1) { (v1)[0]=FTOCHAR((v2[0])); (v1)[1]=FTOCHAR((v2[1])); (v1)[2]=FTOCHAR((v2[2])); \ - (v1)[3] = 255; } -#define F4TOCHAR4(v2,v1) { (v1)[0]=FTOCHAR((v2[0])); (v1)[1]=FTOCHAR((v2[1])); (v1)[2]=FTOCHAR((v2[2])); \ - (v1)[3]=FTOCHAR((v2[3])); } - - -#define VECCOPY(v1,v2) {*(v1)= *(v2); *(v1+1)= *(v2+1); *(v1+2)= *(v2+2);} -#define VECCOPY2D(v1,v2) {*(v1)= *(v2); *(v1+1)= *(v2+1);} -#define QUATCOPY(v1,v2) {*(v1)= *(v2); *(v1+1)= *(v2+1); *(v1+2)= *(v2+2); *(v1+3)= *(v2+3);} -#define LONGCOPY(a, b, c) {int lcpc=c, *lcpa=(int *)a, *lcpb=(int *)b; while(lcpc-->0) *(lcpa++)= *(lcpb++);} - - -#define VECADD(v1,v2,v3) {*(v1)= *(v2) + *(v3); *(v1+1)= *(v2+1) + *(v3+1); *(v1+2)= *(v2+2) + *(v3+2);} -#define VECSUB(v1,v2,v3) {*(v1)= *(v2) - *(v3); *(v1+1)= *(v2+1) - *(v3+1); *(v1+2)= *(v2+2) - *(v3+2);} -#define VECSUB2D(v1,v2,v3) {*(v1)= *(v2) - *(v3); *(v1+1)= *(v2+1) - *(v3+1);} -#define VECADDFAC(v1,v2,v3,fac) {*(v1)= *(v2) + *(v3)*(fac); *(v1+1)= *(v2+1) + *(v3+1)*(fac); *(v1+2)= *(v2+2) + *(v3+2)*(fac);} -#define VECSUBFAC(v1,v2,v3,fac) {*(v1)= *(v2) - *(v3)*(fac); *(v1+1)= *(v2+1) - *(v3+1)*(fac); *(v1+2)= *(v2+2) - *(v3+2)*(fac);} -#define QUATADDFAC(v1,v2,v3,fac) {*(v1)= *(v2) + *(v3)*(fac); *(v1+1)= *(v2+1) + *(v3+1)*(fac); *(v1+2)= *(v2+2) + *(v3+2)*(fac); *(v1+3)= *(v2+3) + *(v3+3)*(fac);} - -#define INPR(v1, v2) ( (v1)[0]*(v2)[0] + (v1)[1]*(v2)[1] + (v1)[2]*(v2)[2] ) +#define F3TOCHAR3(v2, v1) { \ + (v1)[0]= FTOCHAR((v2[0])); \ + (v1)[1]= FTOCHAR((v2[1])); \ + (v1)[2]= FTOCHAR((v2[2])); \ + } +#define F3TOCHAR4(v2, v1) { \ + (v1)[0]= FTOCHAR((v2[0])); \ + (v1)[1]= FTOCHAR((v2[1])); \ + (v1)[2]= FTOCHAR((v2[2])); \ + (v1)[3]= 255; \ + } +#define F4TOCHAR4(v2, v1) { \ + (v1)[0]= FTOCHAR((v2[0])); \ + (v1)[1]= FTOCHAR((v2[1])); \ + (v1)[2]= FTOCHAR((v2[2])); \ + (v1)[3]= FTOCHAR((v2[3])); \ + } +#define VECCOPY(v1, v2) { \ + *(v1)= *(v2); \ + *(v1+1)= *(v2+1); \ + *(v1+2)= *(v2+2); \ + } +#define VECCOPY2D(v1, v2) { \ + *(v1)= *(v2); \ + *(v1+1)= *(v2+1); \ + } +#define QUATCOPY(v1, v2) { \ + *(v1)= *(v2); \ + *(v1+1)= *(v2+1); \ + *(v1+2)= *(v2+2); \ + *(v1+3)= *(v2+3); \ + } +#define VECADD(v1,v2,v3) { \ + *(v1)= *(v2) + *(v3); \ + *(v1+1)= *(v2+1) + *(v3+1); \ + *(v1+2)= *(v2+2) + *(v3+2); \ + } +#define VECSUB(v1,v2,v3) { \ + *(v1)= *(v2) - *(v3); \ + *(v1+1)= *(v2+1) - *(v3+1); \ + *(v1+2)= *(v2+2) - *(v3+2); \ + } +#define VECSUB2D(v1,v2,v3) { \ + *(v1)= *(v2) - *(v3); \ + *(v1+1)= *(v2+1) - *(v3+1); \ + } +#define VECADDFAC(v1,v2,v3,fac) { \ + *(v1)= *(v2) + *(v3)*(fac); \ + *(v1+1)= *(v2+1) + *(v3+1)*(fac); \ + *(v1+2)= *(v2+2) + *(v3+2)*(fac); \ + } +#define VECSUBFAC(v1,v2,v3,fac) { \ + *(v1)= *(v2) - *(v3)*(fac); \ + *(v1+1)= *(v2+1) - *(v3+1)*(fac); \ + *(v1+2)= *(v2+2) - *(v3+2)*(fac); \ + } +#define QUATADDFAC(v1,v2,v3,fac) { \ + *(v1)= *(v2) + *(v3)*(fac); \ + *(v1+1)= *(v2+1) + *(v3+1)*(fac); \ + *(v1+2)= *(v2+2) + *(v3+2)*(fac); \ + *(v1+3)= *(v2+3) + *(v3+3)*(fac); \ + } + +#define INPR(v1, v2) ( (v1)[0]*(v2)[0] + (v1)[1]*(v2)[1] + (v1)[2]*(v2)[2] ) /* some misc stuff.... */ #define CLAMP(a, b, c) if((a)<(b)) (a)=(b); else if((a)>(c)) (a)=(c) @@ -138,28 +188,36 @@ #define IN_RANGE_INCL(a, b, c) ((b < c)? ((b<=a && a<=c)? 1:0) : ((c<=a && a<=b)? 1:0)) /* array helpers */ -#define ARRAY_LAST_ITEM(arr_start, arr_dtype, elem_size, tot) (arr_dtype *)((char*)arr_start + (elem_size*(tot - 1))) -#define ARRAY_HAS_ITEM(item, arr_start, arr_dtype, elem_size, tot) ((item >= arr_start) && (item <= ARRAY_LAST_ITEM(arr_start, arr_dtype, elem_size, tot))) +#define ARRAY_LAST_ITEM(arr_start, arr_dtype, elem_size, tot) \ + (arr_dtype *)((char*)arr_start + (elem_size*(tot - 1))) + +#define ARRAY_HAS_ITEM(item, arr_start, arr_dtype, elem_size, tot) ( \ + (item >= arr_start) && \ + (item <= ARRAY_LAST_ITEM(arr_start, arr_dtype, elem_size, tot)) \ + ) /* This one rotates the bytes in an int64, int (32) and short (16) */ -#define SWITCH_INT64(a) { \ - char s_i, *p_i; \ - p_i= (char *)&(a); \ - s_i=p_i[0]; p_i[0]=p_i[7]; p_i[7]=s_i; \ - s_i=p_i[1]; p_i[1]=p_i[6]; p_i[6]=s_i; \ - s_i=p_i[2]; p_i[2]=p_i[5]; p_i[5]=s_i; \ - s_i=p_i[3]; p_i[3]=p_i[4]; p_i[4]=s_i; } - - #define SWITCH_INT(a) { \ - char s_i, *p_i; \ - p_i= (char *)&(a); \ - s_i=p_i[0]; p_i[0]=p_i[3]; p_i[3]=s_i; \ - s_i=p_i[1]; p_i[1]=p_i[2]; p_i[2]=s_i; } - -#define SWITCH_SHORT(a) { \ - char s_i, *p_i; \ - p_i= (char *)&(a); \ - s_i=p_i[0]; p_i[0]=p_i[1]; p_i[1]=s_i; } +#define SWITCH_INT64(a) { \ + char s_i, *p_i; \ + p_i= (char *)&(a); \ + s_i= p_i[0]; p_i[0]= p_i[7]; p_i[7]= s_i; \ + s_i= p_i[1]; p_i[1]= p_i[6]; p_i[6]= s_i; \ + s_i= p_i[2]; p_i[2]= p_i[5]; p_i[5]= s_i; \ + s_i= p_i[3]; p_i[3]= p_i[4]; p_i[4]= s_i; \ + } + +#define SWITCH_INT(a) { \ + char s_i, *p_i; \ + p_i= (char *)&(a); \ + s_i= p_i[0]; p_i[0]= p_i[3]; p_i[3]= s_i; \ + s_i= p_i[1]; p_i[1]= p_i[2]; p_i[2]= s_i; \ + } + +#define SWITCH_SHORT(a) { \ + char s_i, *p_i; \ + p_i= (char *)&(a); \ + s_i=p_i[0]; p_i[0]=p_i[1]; p_i[1]=s_i; \ + } /* Warning-free macros for storing ints in pointers. Use these _only_ @@ -221,25 +279,25 @@ # else # define _dummy_abort() (void)0 # endif -# if defined(__GNUC__) || defined(_MSC_VER) /* just want to check if __func__ is available */ -# define BLI_assert(a) \ -do { \ - if (!(a)) { \ - fprintf(stderr, \ - "BLI_assert failed: %s, %s(), %d at \'%s\'\n", \ - __FILE__, __func__, __LINE__, STRINGIFY(a)); \ - _dummy_abort(); \ - } \ +# if defined(__GNUC__) || defined(_MSC_VER) /* check __func__ is available */ +# define BLI_assert(a) \ +do { \ + if (!(a)) { \ + fprintf(stderr, \ + "BLI_assert failed: %s, %s(), %d at \'%s\'\n", \ + __FILE__, __func__, __LINE__, STRINGIFY(a)); \ + _dummy_abort(); \ + } \ } while (0) # else # define BLI_assert(a) \ -do { \ - if (0 == (a)) { \ - fprintf(stderr, \ - "BLI_assert failed: %s, %d at \'%s\'\n", \ - __FILE__, __LINE__, STRINGIFY(a)); \ - _dummy_abort(); \ - } \ +do { \ + if (0 == (a)) { \ + fprintf(stderr, \ + "BLI_assert failed: %s, %d at \'%s\'\n", \ + __FILE__, __LINE__, STRINGIFY(a)); \ + _dummy_abort(); \ + } \ } while (0) # endif #else diff --git a/source/blender/nodes/composite/nodes/node_composite_directionalblur.c b/source/blender/nodes/composite/nodes/node_composite_directionalblur.c index 1a5e3150f53..34815fcb24c 100644 --- a/source/blender/nodes/composite/nodes/node_composite_directionalblur.c +++ b/source/blender/nodes/composite/nodes/node_composite_directionalblur.c @@ -86,8 +86,9 @@ static CompBuf *dblur(bNode *node, CompBuf *img, int iterations, int wrap, getpix(tmp, cs * u + ss * v + center_x_pix, cs * v - ss * u + center_y_pix, col); /* mix img and transformed tmp */ - for(j= 0; j < 4; ++j) - img->rect[p + j]= AVG2(img->rect[p + j], col[j]); + for(j= 0; j < 4; ++j) { + img->rect[p + j]= 0.5f * (img->rect[p + j] + col[j]); + } } } -- cgit v1.2.3