Rev 288 | Rev 290 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
259 | daniel-mar | 1 | /* |
2 | This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop |
||
3 | Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au |
||
4 | Copyright (C) 2018-2021 Daniel Marschall, ViaThinkSoft |
||
5 | |||
6 | This program is free software; you can redistribute it and/or modify |
||
7 | it under the terms of the GNU General Public License as published by |
||
8 | the Free Software Foundation; either version 2 of the License, or |
||
9 | (at your option) any later version. |
||
10 | |||
11 | This program is distributed in the hope that it will be useful, |
||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
14 | GNU General Public License for more details. |
||
15 | |||
16 | You should have received a copy of the GNU General Public License |
||
17 | along with this program; if not, write to the Free Software |
||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
19 | */ |
||
20 | |||
21 | #ifdef MAC_ENV |
||
268 | daniel-mar | 22 | #include <fp.h> |
259 | daniel-mar | 23 | #endif |
24 | |||
25 | #include <math.h> |
||
26 | #include <stdlib.h> |
||
27 | |||
28 | #ifndef PARSERTEST |
||
29 | #include "ff.h" |
||
30 | #endif |
||
268 | daniel-mar | 31 | |
259 | daniel-mar | 32 | #include "funcs.h" |
33 | #include "y.tab.h" |
||
34 | |||
35 | #include "node.h" // for symbol "var[]" |
||
36 | |||
37 | #define RINT //no rounding for now |
||
38 | |||
39 | //#if TARGET_API_MAC_CARBON |
||
40 | // this is another incompatibility between Classic stdclib and OS X stdclib |
||
41 | // ***FIXME: need to access real OS X includes for Carbon build |
||
42 | //#undef RAND_MAX |
||
43 | //#define RAND_MAX 0x7fffffff |
||
44 | //#endif |
||
45 | |||
46 | extern value_type slider[],cell[],var[],map[][0x100]; |
||
47 | extern unsigned char *image_ptr; |
||
48 | |||
49 | double costab[COSTABSIZE]; |
||
50 | double tantab[TANTABSIZE]; |
||
51 | void init_trigtab(){ |
||
52 | int i; |
||
53 | for(i=0;i<COSTABSIZE;++i){ |
||
54 | costab[i] = cos(FFANGLE(i)); |
||
55 | } |
||
56 | for(i=0;i<TANTABSIZE;++i){ |
||
57 | if (i>=TANTABSIZE/2) { |
||
58 | /* the last '-1' in the expression '512-i-1' is for FilterFactory compatibility, and to avoid the undefined pi/2 area */ |
||
59 | tantab[i] = -tantab[TANTABSIZE-i-1]; |
||
60 | } else { |
||
61 | tantab[i] = tan(FFANGLE(i)); |
||
62 | } |
||
63 | } |
||
64 | } |
||
65 | |||
66 | /* Channel z for the input pixel at coordinates x,y. |
||
67 | * Coordinates are relative to the input image data (pb->inData) */ |
||
68 | static value_type rawsrc(value_type x,value_type y,value_type z){ |
||
69 | if (HAS_BIG_DOC(gpb)) { |
||
70 | if (x < BIGDOC_IN_RECT(gpb).left) |
||
71 | x = BIGDOC_IN_RECT(gpb).left; |
||
72 | else if (x >= BIGDOC_IN_RECT(gpb).right) |
||
73 | x = BIGDOC_IN_RECT(gpb).right - 1; |
||
74 | if (y < BIGDOC_IN_RECT(gpb).top) |
||
75 | y = BIGDOC_IN_RECT(gpb).top; |
||
76 | else if (y >= BIGDOC_IN_RECT(gpb).bottom) |
||
77 | y = BIGDOC_IN_RECT(gpb).bottom - 1; |
||
78 | return ((unsigned char*)gpb->inData)[(long)gpb->inRowBytes * (y - BIGDOC_IN_RECT(gpb).top) |
||
79 | + (long)nplanes * (x - BIGDOC_IN_RECT(gpb).left) + z]; |
||
80 | } else { |
||
81 | if (x < IN_RECT(gpb).left) |
||
82 | x = IN_RECT(gpb).left; |
||
83 | else if (x >= IN_RECT(gpb).right) |
||
84 | x = IN_RECT(gpb).right - 1; |
||
85 | if (y < IN_RECT(gpb).top) |
||
86 | y = IN_RECT(gpb).top; |
||
87 | else if (y >= IN_RECT(gpb).bottom) |
||
88 | y = IN_RECT(gpb).bottom - 1; |
||
89 | return ((unsigned char*)gpb->inData)[(long)gpb->inRowBytes * (y - IN_RECT(gpb).top) |
||
90 | + (long)nplanes * (x - IN_RECT(gpb).left) + z]; |
||
91 | } |
||
92 | } |
||
93 | |||
94 | /* src(x,y,z) Channel z for the pixel at coordinates x,y. |
||
95 | * Coordinates are relative to filtered area (selection). */ |
||
96 | value_type ff_src(value_type x,value_type y,value_type z){ |
||
268 | daniel-mar | 97 | #ifdef PARSERTEST |
259 | daniel-mar | 98 | return 0; |
268 | daniel-mar | 99 | #else |
259 | daniel-mar | 100 | if(x < 0) |
101 | x = 0; |
||
102 | else if(x >= var['X']) |
||
103 | x = var['X']-1; |
||
104 | if(y < 0) |
||
105 | y = 0; |
||
106 | else if(y >= var['Y']) |
||
107 | y = var['Y']-1; |
||
108 | return z >= 0 && z < var['Z'] ? |
||
109 | image_ptr[(long)gpb->inRowBytes*y + (long)nplanes*x + z] : 0; |
||
268 | daniel-mar | 110 | #endif |
259 | daniel-mar | 111 | } |
112 | |||
113 | /* rad(d,m,z) Channel z in the source image, which is m units away, |
||
114 | at an angle of d, from the center of the image */ |
||
115 | value_type ff_rad(value_type d,value_type m,value_type z){ |
||
116 | return ff_src(ff_r2x(d,m) + var['X']/2, ff_r2y(d,m) + var['Y']/2, z); |
||
117 | } |
||
118 | |||
119 | /* ctl(i) Value of slider i, where i is an integer between 0 and 7, inclusive */ |
||
120 | value_type ff_ctl(value_type i){ |
||
121 | return i>=0 && i<=7 ? slider[i] : 0; |
||
122 | } |
||
123 | |||
124 | /* val(i,a,b) Value of slider i, mapped onto the range a to b */ |
||
125 | value_type ff_val(value_type i,value_type a,value_type b){ |
||
126 | return ((long)ff_ctl(i)*(b-a))/255 + a; |
||
127 | } |
||
128 | |||
129 | /* map(i,n) Item n from mapping table i, where i is an integer between |
||
130 | |||
131 | inclusive */ |
||
132 | value_type ff_map(value_type i,value_type n){ |
||
133 | /* |
||
134 | if( i>=0 && i<=3 && n>=0 && n<=255 ){ |
||
135 | int H = slider[i*2],L = slider[i*2+1]; |
||
136 | return n<=L || H==L ? 0 : ( n>=H ? 255 : ((n-L)*255L)/(H-L) ); |
||
137 | }else |
||
138 | return 0; |
||
139 | */ |
||
140 | // this code is from GIMP User Filter |
||
141 | value_type x = ff_ctl(i*2), |
||
142 | y = ff_ctl(i*2+1); |
||
143 | return abs(((long)n*(y-x) / 255)+x); |
||
144 | } |
||
145 | |||
146 | /* min(a,b) Lesser of a and b */ |
||
147 | value_type ff_min(value_type a,value_type b){ |
||
148 | return a < b ? a : b; |
||
149 | } |
||
150 | |||
151 | /* max(a,b) Greater of a and b */ |
||
152 | value_type ff_max(value_type a,value_type b){ |
||
153 | return a > b ? a : b; |
||
154 | } |
||
155 | |||
156 | /* abs(a) Absolute value of a */ |
||
157 | value_type ff_abs(value_type a){ |
||
158 | return abs(a); |
||
159 | } |
||
160 | |||
161 | /* add(a,b,c) Sum of a and b, or c, whichever is lesser */ |
||
162 | value_type ff_add(value_type a,value_type b,value_type c){ |
||
163 | return ff_min(a+b,c); |
||
164 | } |
||
165 | |||
166 | /* sub(a,b,c) Difference of a and b, or c, whichever is greater */ |
||
167 | value_type ff_sub(value_type a,value_type b,value_type c){ |
||
168 | return ff_max(ff_dif(a,b),c); |
||
169 | } |
||
170 | |||
171 | /* dif(a,b) Absolute value of the difference of a and b */ |
||
172 | value_type ff_dif(value_type a,value_type b){ |
||
173 | return abs(a-b); |
||
174 | } |
||
175 | |||
289 | daniel-mar | 176 | uint16_t gFactoryRndIndexCounter1 = 0; |
177 | uint16_t gFactoryRndIndexCounter2 = 31; |
||
286 | daniel-mar | 178 | uint32_t gFactoryRndLookup[56]; |
288 | daniel-mar | 179 | uint32_t gFactoryRndSeed; |
180 | uint32_t gFactoryRndSeedSave; |
||
286 | daniel-mar | 181 | |
288 | daniel-mar | 182 | void factory_fill_rnd_lookup(uint32_t seed); |
286 | daniel-mar | 183 | |
288 | daniel-mar | 184 | uint32_t factory_rnd(uint32_t a, uint32_t b) { |
289 | daniel-mar | 185 | uint32_t mj; // Note: This must be "uint32_t". With "long" (as described by Knuth), it won't match FilterFactory's algorithm |
186 | int range; |
||
286 | daniel-mar | 187 | |
288 | daniel-mar | 188 | if (gFactoryRndSeed != gFactoryRndSeedSave) { |
189 | // (Intentional) behavior of Filter Foundry |
||
190 | factory_fill_rnd_lookup(gFactoryRndSeed); |
||
289 | daniel-mar | 191 | gFactoryRndIndexCounter1 = 0; |
192 | gFactoryRndIndexCounter2 = 31; |
||
288 | daniel-mar | 193 | } |
194 | |||
195 | // Algorithm of Filter Factory |
||
289 | daniel-mar | 196 | // Filter Factory uses Donald E.Knuth's subtractive |
197 | // random number generator algorithm ("ran3"), which has been published |
||
198 | // in Page 283 of "The Art of Computer Programming, volume 2: Seminumerical Algorithms", |
||
199 | // Addison-Wesley, Reading, MA, second edition, 1981. |
||
200 | // https://www.cec.uchile.cl/cinetica/pcordero/MC_libros/NumericalRecipesinC.pdf (PDF Page 307) |
||
288 | daniel-mar | 201 | |
289 | daniel-mar | 202 | if (++gFactoryRndIndexCounter1 == 56) gFactoryRndIndexCounter1 = 1; |
203 | if (++gFactoryRndIndexCounter2 == 56) gFactoryRndIndexCounter2 = 1; |
||
286 | daniel-mar | 204 | |
289 | daniel-mar | 205 | mj = gFactoryRndLookup[gFactoryRndIndexCounter1] - |
206 | gFactoryRndLookup[gFactoryRndIndexCounter2]; |
||
207 | gFactoryRndLookup[gFactoryRndIndexCounter1] = mj; |
||
286 | daniel-mar | 208 | |
289 | daniel-mar | 209 | // This is Filter Factory specific: |
210 | // Squeeze result into interval [a..b] |
||
211 | if (a == 0) { |
||
212 | // This part is optional; it is intended to increase the |
||
213 | // performance by avoiding modulo/divide if possible. |
||
214 | switch (b) { |
||
215 | case 255: |
||
216 | return mj & 0xFF; |
||
217 | case 127: |
||
218 | return mj & 0x7F; |
||
219 | case 63: |
||
220 | return mj & 0x3F; |
||
221 | case 31: |
||
222 | return mj & 0x1F; |
||
223 | case 15: |
||
224 | return mj & 0xF; |
||
225 | case 7: |
||
226 | return mj & 0x7; |
||
227 | case 3: |
||
228 | return mj & 0x3; |
||
229 | case 1: |
||
230 | return mj & 0x1; |
||
231 | } |
||
232 | } |
||
286 | daniel-mar | 233 | range = b - a; |
234 | if (range < 0) return 0; |
||
289 | daniel-mar | 235 | return a + (mj % (range + 1)); |
286 | daniel-mar | 236 | } |
237 | |||
288 | daniel-mar | 238 | void factory_fill_rnd_lookup(uint32_t seed) { |
286 | daniel-mar | 239 | // Algorithm of Filter Factory |
289 | daniel-mar | 240 | // Filter Factory uses Donald E.Knuth's subtractive |
241 | // random number generator algorithm ("ran3"), which has been published |
||
242 | // in Page 283 of "The Art of Computer Programming, volume 2: Seminumerical Algorithms", |
||
243 | // Addison-Wesley, Reading, MA, second edition, 1981. |
||
244 | // https://www.cec.uchile.cl/cinetica/pcordero/MC_libros/NumericalRecipesinC.pdf (PDF Page 307) |
||
286 | daniel-mar | 245 | |
289 | daniel-mar | 246 | long mj, mk; |
247 | int i, ii, k; |
||
286 | daniel-mar | 248 | |
287 | daniel-mar | 249 | // 161803398 = 1.61803398 * 10^8 ~= phi * 10^8 |
289 | daniel-mar | 250 | mj = 161803398 - (seed & 0x7fff); |
251 | gFactoryRndLookup[55] = mj; |
||
286 | daniel-mar | 252 | |
289 | daniel-mar | 253 | mk = 1; |
254 | for (i=1; i<=54; ++i) { |
||
255 | ii = (21 * i) % 55; |
||
256 | gFactoryRndLookup[ii] = mk; |
||
257 | mk = mj - mk; |
||
258 | mj = gFactoryRndLookup[ii]; |
||
286 | daniel-mar | 259 | } |
260 | |||
289 | daniel-mar | 261 | for (k=1; k<=4; ++k) { |
262 | for (i=1; i<=55; ++i) { |
||
263 | gFactoryRndLookup[i] -= gFactoryRndLookup[1+(i + 30) % 55]; |
||
287 | daniel-mar | 264 | } |
286 | daniel-mar | 265 | } |
266 | |||
288 | daniel-mar | 267 | gFactoryRndSeedSave = seed; |
268 | |||
286 | daniel-mar | 269 | return; |
270 | } |
||
271 | |||
288 | daniel-mar | 272 | int32_t factory_rst(uint32_t seed) { |
287 | daniel-mar | 273 | // We implement rst(i) differently in Filter Foundry: |
286 | daniel-mar | 274 | // Every call of rst() will renew the lookup table, |
275 | // while in Filter Factory, there are strange things going |
||
276 | // on, like only setting the state in pixel [0,0,0] and |
||
277 | // only before rnd() is called, etc. |
||
287 | daniel-mar | 278 | |
288 | daniel-mar | 279 | gFactoryRndSeed = seed; |
287 | daniel-mar | 280 | |
281 | return 0; |
||
286 | daniel-mar | 282 | } |
283 | |||
287 | daniel-mar | 284 | void factory_initialize_rnd_variables() { |
288 | daniel-mar | 285 | gFactoryRndSeed = 0; // default seed |
286 | gFactoryRndSeedSave = gFactoryRndSeed + 1; // force rnd() to call factory_fill_rnd_lookup() |
||
287 | daniel-mar | 287 | } |
288 | |||
259 | daniel-mar | 289 | /* rnd(a,b) Random number between a and b, inclusive */ |
290 | value_type ff_rnd(value_type a,value_type b){ |
||
286 | daniel-mar | 291 | return factory_rnd(a,b); |
292 | // return (int)((abs(a-b)+1)*(rand()/(RAND_MAX+1.))) + ff_min(a,b); |
||
259 | daniel-mar | 293 | // return ((unsigned)rand() % (ff_dif(a,b)+1)) + ff_min(a,b); |
294 | } |
||
295 | |||
296 | /* mix(a,b,n,d) Mixture of a and b by fraction n/d, a*n/d+b*(d-n)/d */ |
||
297 | value_type ff_mix(value_type a,value_type b,value_type n,value_type d){ |
||
298 | return d ? ((long)a*n)/d + ((long)b*(d-n))/d : 0; |
||
299 | } |
||
300 | |||
301 | /* scl(a,il,ih,ol,oh) Scale a from input range (il to ih) |
||
302 | to output range (ol to oh) */ |
||
303 | value_type ff_scl(value_type a,value_type il,value_type ih, |
||
304 | value_type ol,value_type oh){ |
||
305 | return ih==il ? 0 : ol + ((long)(oh-ol)*(a-il))/(ih-il); |
||
306 | } |
||
307 | |||
308 | static uint32_t isqrt(uint32_t x) { |
||
309 | // based on https://gist.github.com/orlp/3481770 |
||
310 | |||
311 | static uint32_t lkpSquares[65535]; |
||
312 | static int lkpInitialized = 0; |
||
313 | const uint32_t *p; |
||
314 | int i; |
||
315 | |||
316 | while (lkpInitialized == 1) { /* If other thread is currently creating the lookup table, then wait */ } |
||
317 | if (!lkpInitialized) { |
||
318 | lkpInitialized = 1; |
||
319 | for (i = 0; i < 65535; ++i) { |
||
320 | lkpSquares[i] = i * i; |
||
321 | } |
||
322 | lkpInitialized = 2; |
||
323 | } |
||
324 | |||
325 | p = lkpSquares; |
||
326 | |||
327 | if (p[32768] <= x) p += 32768; |
||
328 | if (p[16384] <= x) p += 16384; |
||
329 | if (p[8192] <= x) p += 8192; |
||
330 | if (p[4096] <= x) p += 4096; |
||
331 | if (p[2048] <= x) p += 2048; |
||
332 | if (p[1024] <= x) p += 1024; |
||
333 | if (p[512] <= x) p += 512; |
||
334 | if (p[256] <= x) p += 256; |
||
335 | if (p[128] <= x) p += 128; |
||
336 | if (p[64] <= x) p += 64; |
||
337 | if (p[32] <= x) p += 32; |
||
338 | if (p[16] <= x) p += 16; |
||
339 | if (p[8] <= x) p += 8; |
||
340 | if (p[4] <= x) p += 4; |
||
341 | if (p[2] <= x) p += 2; |
||
342 | if (p[1] <= x) p += 1; |
||
343 | |||
344 | return (uint32_t)(p - lkpSquares); |
||
345 | } |
||
346 | |||
347 | /* sqr(x) Square root of x */ |
||
348 | value_type ff_sqr(value_type x){ |
||
349 | return x < 0 ? 0 : isqrt(x); |
||
350 | } |
||
351 | |||
352 | /* sin(x) Sine function of x, where x is an integer between 0 and |
||
353 | 1024, inclusive, and the value returned is an integer |
||
354 | between -512 and 512, inclusive (Windows) or -1024 and |
||
355 | 1024, inclusive (Mac OS) */ |
||
356 | value_type ff_sin(value_type x){ |
||
357 | //return RINT(TRIGAMP*sin(FFANGLE(x))); |
||
358 | return ff_cos(x-256); |
||
359 | } |
||
360 | |||
361 | /* cos(x) Cosine function of x, where x is an integer between 0 and |
||
362 | 1024, inclusive, and the value returned is an integer |
||
363 | between -512 and 512, inclusive (Windows) or -1024 and |
||
364 | 1024, inclusive (Mac OS) */ |
||
365 | value_type ff_cos(value_type x){ |
||
366 | //return RINT(TRIGAMP*cos(FFANGLE(x))); |
||
367 | return (value_type)RINT(TRIGAMP*costab[abs(x) % COSTABSIZE]); |
||
368 | } |
||
369 | |||
370 | /* tan(x) Tangent function of x, where x is an integer |
||
371 | between -256 and 256, inclusive. Althought the Filter Factory manual |
||
372 | stated that the return value is bounded to -512 and 512, inclusive (Windows) or |
||
373 | -1024 and 1024, inclusive (Mac OS), the output is actually NOT bounded! */ |
||
374 | value_type ff_tan(value_type x){ |
||
375 | // Following filter shows that the Filter Factory manual differs from the implementation. |
||
376 | // R = cos(x) > 1024 || cos(x) < -1024 || cos(-x) > 1024 || cos(-x) < -1024 ? 255 : 0 |
||
377 | // G = tan(x) > 1024 || tan(x) < -1024 || tan(-x) > 1024 || tan(-x) < -1024 ? 255 : 0 |
||
378 | // B = sin(x) > 1024 || sin(x) < -1024 || sin(-x) > 1024 || sin(-x) < -1024 ? 255 : 0 |
||
379 | // It outputs green stripes, showing that the output of tan() is not bounded. |
||
380 | // So, we do it the same way to stay compatible. |
||
381 | if (x < 0) x--; /* required for Filter Factory compatibility */ |
||
382 | while (x < 0) x += TANTABSIZE; |
||
383 | return (value_type)RINT(2*TRIGAMP*tantab[x % TANTABSIZE]); // We need the x2 multiplicator for some reason |
||
384 | } |
||
385 | |||
386 | /* r2x(d,m) x displacement of the pixel m units away, at an angle of d, |
||
387 | from an arbitrary center */ |
||
388 | value_type ff_r2x(value_type d,value_type m){ |
||
389 | return (value_type)RINT(m*costab[abs(d) % COSTABSIZE]); |
||
390 | } |
||
391 | |||
392 | /* r2y(d,m) y displacement of the pixel m units away, at an angle of d, |
||
393 | from an arbitrary center */ |
||
394 | value_type ff_r2y(value_type d,value_type m){ |
||
395 | return (value_type)RINT(m*costab[abs(d-256) % COSTABSIZE]); |
||
396 | } |
||
397 | |||
398 | /* Attention! This is NOT a function. It is internally used to calculate the variable "d". */ |
||
399 | value_type ff_c2d_negated(value_type x, value_type y) { |
||
400 | // NOTE: FilterFactory uses c2d(x,y):=atan2(y,x), but d:=atan2(-y,-x) |
||
401 | // Due to compatibility reasons, we implement it the same way! |
||
402 | // Sign of y difference is negated, as we are dealing with top-down coordinates angle is "observed" |
||
403 | return (value_type)RINT(TO_FFANGLE(atan2(-y,-x))); |
||
404 | } |
||
405 | |||
406 | /* c2d(x,y) Angle displacement of the pixel at coordinates x,y */ |
||
407 | value_type ff_c2d(value_type x,value_type y){ |
||
408 | // Behavior of FilterFoundry <1.7: |
||
409 | //return ff_c2d_negated(x,y); |
||
410 | |||
411 | // Behavior in FilterFoundry 1.7+: Matches FilterFactory |
||
412 | return (value_type)RINT(TO_FFANGLE(atan2(y,x))); |
||
413 | } |
||
414 | |||
415 | /* c2m(x,y) Magnitude displacement of the pixel at coordinates x,y */ |
||
416 | value_type ff_c2m(value_type x,value_type y){ |
||
417 | return isqrt((long)x*x + (long)y*y); |
||
418 | } |
||
419 | |||
420 | /* get(i) Returns the current cell value at i */ |
||
421 | value_type ff_get(value_type i){ |
||
422 | // Filter Factory: |
||
423 | //return i>=0 && i<NUM_CELLS ? cell[i] : i; |
||
424 | |||
425 | // Filter Foundry: |
||
426 | return i>=0 && i<NUM_CELLS ? cell[i] : 0; |
||
427 | } |
||
428 | |||
429 | /* put(v,i) Puts the new value v into cell i */ |
||
430 | value_type ff_put(value_type v,value_type i){ |
||
431 | if(i>=0 && i<NUM_CELLS) |
||
432 | cell[i] = v; |
||
433 | return v; |
||
434 | } |
||
435 | |||
436 | /* Convolve. Applies a convolution matrix and divides with d. */ |
||
437 | value_type ff_cnv(value_type m11,value_type m12,value_type m13, |
||
438 | value_type m21,value_type m22,value_type m23, |
||
439 | value_type m31,value_type m32,value_type m33, |
||
440 | value_type d) |
||
441 | { |
||
268 | daniel-mar | 442 | #ifdef PARSERTEST |
259 | daniel-mar | 443 | return 0; |
268 | daniel-mar | 444 | #else |
259 | daniel-mar | 445 | long total; |
446 | int x, y, z; |
||
447 | // shift x,y from selection-relative to image relative |
||
448 | if (HAS_BIG_DOC(gpb)) { |
||
449 | x = var['x'] + BIGDOC_FILTER_RECT(gpb).left; |
||
450 | y = var['y'] + BIGDOC_FILTER_RECT(gpb).top; |
||
451 | } else { |
||
452 | x = var['x'] + FILTER_RECT(gpb).left; |
||
453 | y = var['y'] + FILTER_RECT(gpb).top; |
||
454 | } |
||
455 | z = var['z']; |
||
456 | |||
457 | if(z >= 0 && z < var['Z']) |
||
458 | total = m11*rawsrc(x-1,y-1,z) + m12*rawsrc(x,y-1,z) + m13*rawsrc(x+1,y-1,z) |
||
459 | + m21*rawsrc(x-1,y, z) + m22*rawsrc(x,y, z) + m23*rawsrc(x+1,y, z) |
||
460 | + m31*rawsrc(x-1,y+1,z) + m32*rawsrc(x,y+1,z) + m33*rawsrc(x+1,y+1,z); |
||
461 | else |
||
462 | total = 0; |
||
463 | |||
464 | return d ? total/d : 0; |
||
268 | daniel-mar | 465 | #endif |
259 | daniel-mar | 466 | } |
467 | |||
468 | /* rst(i) sets a random seed and returns 0. (undocumented Filter Factory function). |
||
469 | Added by DM, 18 Dec 2018 */ |
||
470 | value_type ff_rst(value_type seed){ |
||
286 | daniel-mar | 471 | factory_rst(seed); |
472 | // srand(seed); |
||
259 | daniel-mar | 473 | return 0; |
474 | } |
||
475 | |||
476 | value_type zero_val = 0; |
||
477 | value_type one_val = 1; |
||
478 | value_type max_channel_val = 255; |
||
479 | |||
480 | /* predefined symbols */ |
||
481 | struct sym_rec predefs[]={ |
||
482 | /* functions */ |
||
483 | |||
484 | {0,TOK_FN3,"src", (pfunc_type)ff_src, 0}, |
||
485 | {0,TOK_FN3,"rad", (pfunc_type)ff_rad, 0}, |
||
486 | {0,TOK_FN1,"ctl", (pfunc_type)ff_ctl, 0}, |
||
487 | {0,TOK_FN3,"val", (pfunc_type)ff_val, 0}, |
||
488 | {0,TOK_FN2,"map", (pfunc_type)ff_map, 0}, |
||
489 | {0,TOK_FN2,"min", (pfunc_type)ff_min, 0}, |
||
490 | {0,TOK_FN2,"max", (pfunc_type)ff_max, 0}, |
||
491 | {0,TOK_FN1,"abs", (pfunc_type)ff_abs, 0}, |
||
492 | {0,TOK_FN3,"add", (pfunc_type)ff_add, 0}, |
||
493 | {0,TOK_FN3,"sub", (pfunc_type)ff_sub, 0}, |
||
494 | {0,TOK_FN2,"dif", (pfunc_type)ff_dif, 0}, |
||
495 | {0,TOK_FN2,"rnd", (pfunc_type)ff_rnd, 0}, |
||
496 | {0,TOK_FN4,"mix", (pfunc_type)ff_mix, 0}, |
||
497 | {0,TOK_FN5,"scl", (pfunc_type)ff_scl, 0}, |
||
498 | {0,TOK_FN1,"sqr", (pfunc_type)ff_sqr, 0}, |
||
499 | {0,TOK_FN1,"sqrt", (pfunc_type)ff_sqr, 0}, // sqrt() is synonym to sqr() in Premiere |
||
500 | {0,TOK_FN1,"sin", (pfunc_type)ff_sin, 0}, |
||
501 | {0,TOK_FN1,"cos", (pfunc_type)ff_cos, 0}, |
||
502 | {0,TOK_FN1,"tan", (pfunc_type)ff_tan, 0}, |
||
503 | {0,TOK_FN2,"r2x", (pfunc_type)ff_r2x, 0}, |
||
504 | {0,TOK_FN2,"r2y", (pfunc_type)ff_r2y, 0}, |
||
505 | {0,TOK_FN2,"c2d", (pfunc_type)ff_c2d, 0}, |
||
506 | {0,TOK_FN2,"c2m", (pfunc_type)ff_c2m, 0}, |
||
507 | {0,TOK_FN1,"get", (pfunc_type)ff_get, 0}, |
||
508 | {0,TOK_FN2,"put", (pfunc_type)ff_put, 0}, |
||
509 | {0,TOK_FN10,"cnv",(pfunc_type)ff_cnv, 0}, |
||
510 | {0,TOK_FN1,"rst", (pfunc_type)ff_rst, 0}, // undocumented FilterFactory function |
||
511 | |||
512 | /* predefined variables (names with more than 1 character); most of them are undocumented in FilterFactory */ |
||
513 | /* the predefined variables with 1 character are defined in lexer.l and process.c */ |
||
514 | /* in this table, you must not add TOK_VAR with only 1 character (since this case is not defined in parser.y) */ |
||
515 | |||
516 | {0,TOK_VAR,"rmax",0, &max_channel_val}, // alias of 'R' (defined in lexer.l, line 129) |
||
517 | {0,TOK_VAR,"gmax",0, &max_channel_val}, // alias of 'G' (defined in lexer.l, line 129) |
||
518 | {0,TOK_VAR,"bmax",0, &max_channel_val}, // alias of 'B' (defined in lexer.l, line 129) |
||
519 | {0,TOK_VAR,"amax",0, &max_channel_val}, // alias of 'A' (defined in lexer.l, line 129) |
||
520 | {0,TOK_VAR,"cmax",0, &max_channel_val}, // alias of 'C' (defined in lexer.l, line 129) |
||
521 | {0,TOK_VAR,"imax",0, &max_channel_val}, // alias of 'I' (defined in lexer.l, line 129) |
||
522 | {0,TOK_VAR,"umax",0, &max_channel_val}, // alias of 'U' (defined in lexer.l, line 129) |
||
523 | {0,TOK_VAR,"vmax",0, &max_channel_val}, // alias of 'V' (defined in lexer.l, line 129) |
||
524 | {0,TOK_VAR,"dmax",0, &var['D']}, |
||
525 | {0,TOK_VAR,"mmax",0, &var['M']}, |
||
526 | {0,TOK_VAR,"pmax",0, &var['Z']}, |
||
527 | {0,TOK_VAR,"xmax",0, &var['X']}, |
||
528 | {0,TOK_VAR,"ymax",0, &var['Y']}, |
||
529 | {0,TOK_VAR,"zmax",0, &var['Z']}, |
||
530 | |||
531 | {0,TOK_VAR,"rmin",0, &zero_val}, |
||
532 | {0,TOK_VAR,"gmin",0, &zero_val}, |
||
533 | {0,TOK_VAR,"bmin",0, &zero_val}, |
||
534 | {0,TOK_VAR,"amin",0, &zero_val}, |
||
535 | {0,TOK_VAR,"cmin",0, &zero_val}, |
||
536 | {0,TOK_VAR,"imin",0, &zero_val}, |
||
537 | {0,TOK_VAR,"umin",0, &zero_val}, |
||
538 | {0,TOK_VAR,"vmin",0, &zero_val}, |
||
539 | {0,TOK_VAR,"dmin",0, &zero_val}, |
||
540 | {0,TOK_VAR,"mmin",0, &zero_val}, |
||
541 | {0,TOK_VAR,"pmin",0, &zero_val}, |
||
542 | {0,TOK_VAR,"xmin",0, &zero_val}, |
||
543 | {0,TOK_VAR,"ymin",0, &zero_val}, |
||
544 | {0,TOK_VAR,"zmin",0, &zero_val}, |
||
545 | |||
546 | /* Undocumented synonyms of FilterFactory for compatibility with Premiere */ |
||
547 | {0,TOK_FN10,"cnv0",(pfunc_type)ff_cnv, 0}, |
||
548 | {0,TOK_FN3,"src0", (pfunc_type)ff_src, 0}, |
||
549 | {0,TOK_FN3,"rad0", (pfunc_type)ff_rad, 0}, |
||
550 | {0,TOK_FN10,"cnv1",(pfunc_type)ff_cnv, 0}, |
||
551 | {0,TOK_FN3,"src1", (pfunc_type)ff_src, 0}, |
||
552 | {0,TOK_FN3,"rad1", (pfunc_type)ff_rad, 0}, |
||
553 | {0,TOK_VAR,"r0",0, &var['r']}, |
||
554 | {0,TOK_VAR,"g0",0, &var['g']}, |
||
555 | {0,TOK_VAR,"b0",0, &var['b']}, |
||
556 | {0,TOK_VAR,"a0",0, &var['a']}, |
||
557 | {0,TOK_VAR,"c0",0, &var['c']}, |
||
558 | {0,TOK_VAR,"i0",0, &var['i']}, |
||
559 | {0,TOK_VAR,"u0",0, &var['u']}, |
||
560 | {0,TOK_VAR,"v0",0, &var['v']}, |
||
561 | {0,TOK_VAR,"d0",0, &var['d']}, |
||
562 | {0,TOK_VAR,"m0",0, &var['m']}, |
||
563 | {0,TOK_VAR,"r1",0, &var['r']}, |
||
564 | {0,TOK_VAR,"g1",0, &var['g']}, |
||
565 | {0,TOK_VAR,"b1",0, &var['b']}, |
||
566 | {0,TOK_VAR,"a1",0, &var['a']}, |
||
567 | {0,TOK_VAR,"c1",0, &var['c']}, |
||
568 | {0,TOK_VAR,"i1",0, &var['i']}, |
||
569 | {0,TOK_VAR,"u1",0, &var['u']}, |
||
570 | {0,TOK_VAR,"v1",0, &var['v']}, |
||
571 | {0,TOK_VAR,"d1",0, &var['d']}, |
||
572 | {0,TOK_VAR,"m1",0, &var['m']}, |
||
573 | {0,TOK_VAR,"tmin",0, &zero_val}, |
||
574 | {0,TOK_VAR,"tmax",0, &one_val}, |
||
575 | {0,TOK_VAR,"total",0, &one_val}, |
||
576 | |||
577 | {0,0,0,0,0} |
||
578 | }; |