259,24 → 259,37 |
|
// ------------------------------------------------------------------------------------------- |
|
double costab[COSTABSIZE]; |
double tantab[TANTABSIZE]; |
void init_trigtab(){ |
#ifdef PARSERTEST |
return; |
#else |
int i; |
|
if (gdata == NULL) return; // should not happen |
|
if (gdata->costab == NULL) { |
gdata->costab = (double*)malloc(sizeof(double) * COSTABSIZE); |
if (gdata->costab) { |
for(i=0;i<COSTABSIZE;++i){ |
costab[i] = cos(FFANGLE(i)); |
gdata->costab[i] = cos(FFANGLE(i)); |
} |
} |
} |
|
if (gdata->tantab == NULL) { |
gdata->tantab = (double*)malloc(sizeof(double) * TANTABSIZE); |
if (gdata->tantab) { |
for(i=0;i<TANTABSIZE;++i){ |
if (i>=TANTABSIZE/2) { |
/* the last '-1' in the expression '512-i-1' is for FilterFactory compatibility, and to avoid the undefined pi/2 area */ |
tantab[i] = -tantab[TANTABSIZE-i-1]; |
} else { |
tantab[i] = tan(FFANGLE(i)); |
gdata->tantab[i] = -gdata->tantab[TANTABSIZE - i - 1]; |
} |
else { |
gdata->tantab[i] = tan(FFANGLE(i)); |
} |
} |
} |
} |
#endif |
} |
|
358,7 → 371,7 |
#ifdef PARSERTEST |
return 0; |
#else |
return (value_type)RINT(m * costab[abs(d) % COSTABSIZE]); |
return (value_type)RINT(m * gdata->costab[abs(d) % COSTABSIZE]); |
#endif |
} |
|
388,7 → 401,7 |
#ifdef PARSERTEST |
return 0; |
#else |
return (value_type)RINT(m * costab[abs(d - 256) % COSTABSIZE]); |
return (value_type)RINT(m * gdata->costab[abs(d - 256) % COSTABSIZE]); |
#endif |
} |
|
498,18 → 511,40 |
#ifdef PARSERTEST |
return 0; |
#else |
value_type H, L; |
const int i2 = i << 1; |
|
// This is how Filter Factory for Windows implements it: |
if (i < 0) return 0; |
if (i > 3) return 0; |
H = slider[i2]; // ctl(2i) |
L = slider[i2 + 1]; // ctl(2i+1) |
if (n < 0) n = 0; |
if (n > 255) n = 255; // Note: MacFF probably does "return 255" if n>255 (see testcases/map1_factory_win.png) |
|
if (H == L) { |
// This is undocumented in Filter Factory! (Taken from Windows implementation) |
if (n < H) return 0; |
if (n >= L) return 255; |
} else if (L > H) { |
// This is undocumented in Filter Factory! (Taken from Windows implementation) |
if (n <= H) return 255; |
if (n >= L) return 0; |
} else { |
if (n <= L) return 0; |
if (n >= H) return 255; |
} |
return (n - L) * 255 / (H - L); |
|
// This is the original formula used by GIMP User Filter v0.8 (uf-pcode.h). |
// It was used in Filter Foundry till version 1.7.0.16, inclusive. |
/* |
if( i>=0 && i<=3 && n>=0 && n<=255 ){ |
int H = slider[i*2],L = slider[i*2+1]; |
return n<=L || H==L ? 0 : ( n>=H ? 255 : ((n-L)*255L)/(H-L) ); |
}else |
return 0; |
value_type H = ff_ctl(i * 2); |
value_type L = ff_ctl(i * 2 + 1); |
return abs(((long)n * (L - H) / 255) + H); |
*/ |
// this code is from GIMP User Filter |
value_type x = ff_ctl(i*2), |
y = ff_ctl(i*2+1); |
return abs(((long)n*(y-x) / 255)+x); |
#endif |
|
} |
|
// ------------------------------------------------------------------------------------------- |
936,7 → 971,7 |
return 0; |
#else |
//return RINT(TRIGAMP*cos(FFANGLE(x))); |
return (value_type)RINT(TRIGAMP * costab[abs(x) % COSTABSIZE]); |
return (value_type)RINT(TRIGAMP * gdata->costab[abs(x) % COSTABSIZE]); |
#endif |
} |
|
1019,7 → 1054,7 |
// So, we do it the same way to stay compatible. |
if (x < 0) x--; /* required for Filter Factory compatibility */ |
while (x < 0) x += TANTABSIZE; |
return (value_type)RINT(2*TRIGAMP*tantab[x % TANTABSIZE]); // We need the x2 multiplicator for some reason |
return (value_type)RINT(2 * TRIGAMP * gdata->tantab[x % TANTABSIZE]); // We need the x2 multiplicator for some reason |
#endif |
} |
|
1481,7 → 1516,7 |
#else |
long total; |
int x, y, z; |
// shift x,y from selection-relative to image relative |
// shift x,y from selection-relative to image relative required by rawsrc() |
if (HAS_BIG_DOC(gpb)) { |
x = var['x'] + BIGDOC_FILTER_RECT(gpb).left; |
y = var['y'] + BIGDOC_FILTER_RECT(gpb).top; |
1491,12 → 1526,13 |
} |
z = var['z']; |
|
// rawsrc() will choose the neighbor pixels if x/y goes out-of-bounds (outer border pixels) |
if(z >= 0 && z < var['Z']) |
total = m11*rawsrc(x-1,y-1,z) + m12*rawsrc(x,y-1,z) + m13*rawsrc(x+1,y-1,z) |
+ m21*rawsrc(x-1,y, z) + m22*rawsrc(x,y, z) + m23*rawsrc(x+1,y, z) |
+ m31*rawsrc(x-1,y+1,z) + m32*rawsrc(x,y+1,z) + m33*rawsrc(x+1,y+1,z); |
else |
total = 0; |
total = 0; // ... can this happen at all ?! |
|
return d ? total/d : 0; |
#endif |