Subversion Repositories filter_foundry

Rev

Rev 291 | Rev 295 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 291 Rev 294
Line 16... Line 16...
16
    You should have received a copy of the GNU General Public License
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
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
18
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
*/
19
*/
20
 
20
 
-
 
21
// Strict compatibility to Filter Factory
-
 
22
// Tested OK!
-
 
23
#define use_filterfactory_implementation_rad
-
 
24
//#define use_filterfactory_implementation_i
-
 
25
//#define use_filterfactory_implementation_u
-
 
26
//#define use_filterfactory_implementation_v
-
 
27
#define use_filterfactory_implementation_rnd
-
 
28
#define use_filterfactory_implementation_c2d
-
 
29
#define use_filterfactory_implementation_c2m
-
 
30
#define use_filterfactory_implementation_r2x
-
 
31
#define use_filterfactory_implementation_r2y
-
 
32
#define use_filterfactory_implementation_cos
-
 
33
#define use_filterfactory_implementation_sin
-
 
34
#define use_filterfactory_implementation_tan
-
 
35
#define use_filterfactory_implementation_sqr
-
 
36
 
-
 
37
// Not yet implemented!
-
 
38
//#define use_filterfactory_implementation_d
-
 
39
//#define use_filterfactory_implementation_m
-
 
40
//#define use_filterfactory_implementation_M
-
 
41
 
21
#ifdef MAC_ENV
42
#ifdef MAC_ENV
22
#include <fp.h>
43
#include <fp.h>
23
#endif
44
#endif
24
 
45
 
25
#include <math.h>
46
#include <math.h>
Line 41... Line 62...
41
// ***FIXME: need to access real OS X includes for Carbon build
62
// ***FIXME: need to access real OS X includes for Carbon build
42
//#undef RAND_MAX
63
//#undef RAND_MAX
43
//#define RAND_MAX    0x7fffffff
64
//#define RAND_MAX    0x7fffffff
44
//#endif
65
//#endif
45
 
66
 
-
 
67
const int FACTORY_COS_LOOKUP[1024] = {
-
 
68
        16384, 16383, 16382, 16381, 16379, 16376, 16372, 16368, 16364, 16359, 16353, 16346, 16339, 16331, 16323,
-
 
69
        16314, 16305, 16294, 16284, 16272, 16260, 16248, 16234, 16221, 16206, 16191, 16175, 16159, 16142, 16125,
-
 
70
        16107, 16088, 16069, 16049, 16028, 16007, 15985, 15963, 15940, 15917, 15893, 15868, 15842, 15817, 15790,
-
 
71
        15763, 15735, 15707, 15678, 15649, 15618, 15588, 15557, 15525, 15492, 15459, 15426, 15392, 15357, 15322,
-
 
72
        15286, 15249, 15212, 15175, 15136, 15098, 15058, 15018, 14978, 14937, 14895, 14853, 14811, 14767, 14723,
-
 
73
        14679, 14634, 14589, 14543, 14496, 14449, 14401, 14353, 14304, 14255, 14205, 14155, 14104, 14053, 14001,
-
 
74
        13948, 13895, 13842, 13788, 13733, 13678, 13622, 13566, 13510, 13452, 13395, 13337, 13278, 13219, 13159,
-
 
75
        13099, 13039, 12977, 12916, 12854, 12791, 12728, 12665, 12601, 12536, 12471, 12406, 12340, 12273, 12207,
-
 
76
        12139, 12072, 12003, 11935, 11866, 11796, 11726, 11656, 11585, 11513, 11442, 11370, 11297, 11224, 11151,
-
 
77
        11077, 11003, 10928, 10853, 10777, 10701, 10625, 10548, 10471, 10394, 10316, 10237, 10159, 10080, 10000,
-
 
78
        9920, 9840, 9760, 9679, 9597, 9516, 9434, 9351, 9269, 9186, 9102, 9018, 8934, 8850, 8765, 8680, 8595,
-
 
79
        8509, 8423, 8336, 8250, 8163, 8075, 7988, 7900, 7812, 7723, 7634, 7545, 7456, 7366, 7276, 7186, 7096,
-
 
80
        7005, 6914, 6822, 6731, 6639, 6547, 6455, 6362, 6270, 6176, 6083, 5990, 5896, 5802, 5708, 5614, 5519,
-
 
81
        5424, 5329, 5234, 5139, 5043, 4948, 4852, 4756, 4659, 4563, 4466, 4369, 4273, 4175, 4078, 3981, 3883,
-
 
82
        3785, 3687, 3589, 3491, 3393, 3295, 3196, 3097, 2998, 2900, 2801, 2702, 2602, 2503, 2404, 2304, 2205,
-
 
83
        2105, 2005, 1905, 1806, 1706, 1606, 1505, 1405, 1305, 1205, 1105, 1004, 904, 804, 703, 603, 502, 402,
-
 
84
        301, 201, 100, -100, -201, -301, -402, -502, -603, -703, -804, -904, -1004, -1105, -1205, -1305, -1405,
-
 
85
        -1505, -1606, -1706, -1806, -1905, -2005, -2105, -2205, -2304, -2404, -2503, -2602, -2702, -2801, -2900,
-
 
86
        -2998, -3097, -3196, -3295, -3393, -3491, -3589, -3687, -3785, -3883, -3981, -4078, -4175, -4273, -4369,
-
 
87
        -4466, -4563, -4659, -4756, -4852, -4948, -5043, -5139, -5234, -5329, -5424, -5519, -5614, -5708, -5802,
-
 
88
        -5896, -5990, -6083, -6176, -6270, -6362, -6455, -6547, -6639, -6731, -6822, -6914, -7005, -7096, -7186,
-
 
89
        -7276, -7366, -7456, -7545, -7634, -7723, -7812, -7900, -7988, -8075, -8163, -8250, -8336, -8423, -8509,
-
 
90
        -8595, -8680, -8765, -8850, -8934, -9018, -9102, -9186, -9269, -9351, -9434, -9516, -9597, -9679, -9760,
-
 
91
        -9840, -9920, -10000, -10080, -10159, -10237, -10316, -10394, -10471, -10548, -10625, -10701, -10777,
-
 
92
        -10853, -10928, -11003, -11077, -11151, -11224, -11297, -11370, -11442, -11513, -11585, -11656, -11726,
-
 
93
        -11796, -11866, -11935, -12003, -12072, -12139, -12207, -12273, -12340, -12406, -12471, -12536, -12601,
-
 
94
        -12665, -12728, -12791, -12854, -12916, -12977, -13039, -13099, -13159, -13219, -13278, -13337, -13395,
-
 
95
        -13452, -13510, -13566, -13622, -13678, -13733, -13788, -13842, -13895, -13948, -14001, -14053, -14104,
-
 
96
        -14155, -14205, -14255, -14304, -14353, -14401, -14449, -14496, -14543, -14589, -14634, -14679, -14723,
-
 
97
        -14767, -14811, -14853, -14895, -14937, -14978, -15018, -15058, -15098, -15136, -15175, -15212, -15249,
-
 
98
        -15286, -15322, -15357, -15392, -15426, -15459, -15492, -15525, -15557, -15588, -15618, -15649, -15678,
-
 
99
        -15707, -15735, -15763, -15790, -15817, -15842, -15868, -15893, -15917, -15940, -15963, -15985, -16007,
-
 
100
        -16028, -16049, -16069, -16088, -16107, -16125, -16142, -16159, -16175, -16191, -16206, -16221, -16234,
-
 
101
        -16248, -16260, -16272, -16284, -16294, -16305, -16314, -16323, -16331, -16339, -16346, -16353, -16359,
-
 
102
        -16364, -16368, -16372, -16376, -16379, -16381, -16382, -16383, -16384, -16384, -16383, -16382, -16381,
-
 
103
        -16379, -16376, -16372, -16368, -16364, -16359, -16353, -16346, -16339, -16331, -16323, -16314, -16305,
-
 
104
        -16294, -16284, -16272, -16260, -16248, -16234, -16221, -16206, -16191, -16175, -16159, -16142, -16125,
-
 
105
        -16107, -16088, -16069, -16049, -16028, -16007, -15985, -15963, -15940, -15917, -15893, -15868, -15842,
-
 
106
        -15817, -15790, -15763, -15735, -15707, -15678, -15649, -15618, -15588, -15557, -15525, -15492, -15459,
-
 
107
        -15426, -15392, -15357, -15322, -15286, -15249, -15212, -15175, -15136, -15098, -15058, -15018, -14978,
-
 
108
        -14937, -14895, -14853, -14811, -14767, -14723, -14679, -14634, -14589, -14543, -14496, -14449, -14401,
-
 
109
        -14353, -14304, -14255, -14205, -14155, -14104, -14053, -14001, -13948, -13895, -13842, -13788, -13733,
-
 
110
        -13678, -13622, -13566, -13510, -13452, -13395, -13337, -13278, -13219, -13159, -13099, -13039, -12977,
-
 
111
        -12916, -12854, -12791, -12728, -12665, -12601, -12536, -12471, -12406, -12340, -12273, -12207, -12139,
-
 
112
        -12072, -12003, -11935, -11866, -11796, -11726, -11656, -11585, -11513, -11442, -11370, -11297, -11224,
-
 
113
        -11151, -11077, -11003, -10928, -10853, -10777, -10701, -10625, -10548, -10471, -10394, -10316, -10237,
-
 
114
        -10159, -10080, -10000, -9920, -9840, -9760, -9679, -9597, -9516, -9434, -9351, -9269, -9186, -9102,
-
 
115
        -9018, -8934, -8850, -8765, -8680, -8595, -8509, -8423, -8336, -8250, -8163, -8075, -7988, -7900, -7812,
-
 
116
        -7723, -7634, -7545, -7456, -7366, -7276, -7186, -7096, -7005, -6914, -6822, -6731, -6639, -6547, -6455,
-
 
117
        -6362, -6270, -6176, -6083, -5990, -5896, -5802, -5708, -5614, -5519, -5424, -5329, -5234, -5139, -5043,
-
 
118
        -4948, -4852, -4756, -4659, -4563, -4466, -4369, -4273, -4175, -4078, -3981, -3883, -3785, -3687, -3589,
-
 
119
        -3491, -3393, -3295, -3196, -3097, -2998, -2900, -2801, -2702, -2602, -2503, -2404, -2304, -2205, -2105,
-
 
120
        -2005, -1905, -1806, -1706, -1606, -1505, -1405, -1305, -1205, -1105, -1004, -904, -804, -703, -603, -502,
-
 
121
        -402, -301, -201, -100, 100, 201, 301, 402, 502, 603, 703, 804, 904, 1004, 1105, 1205, 1305, 1405, 1505,
-
 
122
        1606, 1706, 1806, 1905, 2005, 2105, 2205, 2304, 2404, 2503, 2602, 2702, 2801, 2900, 2998, 3097, 3196,
-
 
123
        3295, 3393, 3491, 3589, 3687, 3785, 3883, 3981, 4078, 4175, 4273, 4369, 4466, 4563, 4659, 4756, 4852,
-
 
124
        4948, 5043, 5139, 5234, 5329, 5424, 5519, 5614, 5708, 5802, 5896, 5990, 6083, 6176, 6270, 6362, 6455,
-
 
125
        6547, 6639, 6731, 6822, 6914, 7005, 7096, 7186, 7276, 7366, 7456, 7545, 7634, 7723, 7812, 7900, 7988,
-
 
126
        8075, 8163, 8250, 8336, 8423, 8509, 8595, 8680, 8765, 8850, 8934, 9018, 9102, 9186, 9269, 9351, 9434,
-
 
127
        9516, 9597, 9679, 9760, 9840, 9920, 10000, 10080, 10159, 10237, 10316, 10394, 10471, 10548, 10625, 10701,
-
 
128
        10777, 10853, 10928, 11003, 11077, 11151, 11224, 11297, 11370, 11442, 11513, 11585, 11656, 11726, 11796,
-
 
129
        11866, 11935, 12003, 12072, 12139, 12207, 12273, 12340, 12406, 12471, 12536, 12601, 12665, 12728, 12791,
-
 
130
        12854, 12916, 12977, 13039, 13099, 13159, 13219, 13278, 13337, 13395, 13452, 13510, 13566, 13622, 13678,
-
 
131
        13733, 13788, 13842, 13895, 13948, 14001, 14053, 14104, 14155, 14205, 14255, 14304, 14353, 14401, 14449,
-
 
132
        14496, 14543, 14589, 14634, 14679, 14723, 14767, 14811, 14853, 14895, 14937, 14978, 15018, 15058, 15098,
-
 
133
        15136, 15175, 15212, 15249, 15286, 15322, 15357, 15392, 15426, 15459, 15492, 15525, 15557, 15588, 15618,
-
 
134
        15649, 15678, 15707, 15735, 15763, 15790, 15817, 15842, 15868, 15893, 15917, 15940, 15963, 15985, 16007,
-
 
135
        16028, 16049, 16069, 16088, 16107, 16125, 16142, 16159, 16175, 16191, 16206, 16221, 16234, 16248, 16260,
-
 
136
        16272, 16284, 16294, 16305, 16314, 16323, 16331, 16339, 16346, 16353, 16359, 16364, 16368, 16372, 16376,
-
 
137
        16379, 16381, 16382, 16383, 16384 };
-
 
138
 
-
 
139
const uint16_t FACTORY_C2D_LOOKUP[1024] = {
-
 
140
        64, 128, 191, 255, 319, 383, 447, 511, 575, 639, 703, 767, 831, 895, 959, 1023, 1087, 1151, 1215, 1279,
-
 
141
        1343, 1407, 1471, 1535, 1599, 1663, 1727, 1791, 1855, 1919, 1983, 2047, 2111, 2175, 2239, 2303, 2366,
-
 
142
        2430, 2494, 2558, 2622, 2686, 2750, 2814, 2878, 2942, 3005, 3069, 3133, 3197, 3261, 3325, 3388, 3452,
-
 
143
        3516, 3580, 3644, 3708, 3771, 3835, 3899, 3963, 4026, 4090, 4154, 4218, 4281, 4345, 4409, 4473, 4536,
-
 
144
        4600, 4664, 4727, 4791, 4855, 4918, 4982, 5046, 5109, 5173, 5236, 5300, 5364, 5427, 5491, 5554, 5618,
-
 
145
        5681, 5745, 5808, 5872, 5935, 5999, 6062, 6126, 6189, 6252, 6316, 6379, 6443, 6506, 6569, 6633, 6696,
-
 
146
        6759, 6823, 6886, 6949, 7013, 7076, 7139, 7202, 7266, 7329, 7392, 7455, 7518, 7582, 7645, 7708, 7771,
-
 
147
        7834, 7897, 7960, 8023, 8086, 8149, 8212, 8275, 8338, 8401, 8464, 8527, 8590, 8653, 8716, 8779, 8841,
-
 
148
        8904, 8967, 9030, 9093, 9155, 9218, 9281, 9344, 9406, 9469, 9532, 9594, 9657, 9720, 9782, 9845, 9907,
-
 
149
        9970, 10032, 10095, 10157, 10220, 10282, 10345, 10407, 10470, 10532, 10594, 10657, 10719, 10781, 10843,
-
 
150
        10906, 10968, 11030, 11092, 11155, 11217, 11279, 11341, 11403, 11465, 11527, 11589, 11651, 11713, 11775,
-
 
151
        11837, 11899, 11961, 12023, 12085, 12146, 12208, 12270, 12332, 12394, 12455, 12517, 12579, 12640, 12702,
-
 
152
        12764, 12825, 12887, 12948, 13010, 13071, 13133, 13194, 13256, 13317, 13379, 13440, 13501, 13563, 13624,
-
 
153
        13685, 13746, 13808, 13869, 13930, 13991, 14052, 14113, 14174, 14235, 14296, 14357, 14418, 14479, 14540,
-
 
154
        14601, 14662, 14723, 14784, 14844, 14905, 14966, 15027, 15087, 15148, 15208, 15269, 15330, 15390, 15451,
-
 
155
        15511, 15572, 15632, 15693, 15753, 15813, 15874, 15934, 15994, 16054, 16115, 16175, 16235, 16295, 16355,
-
 
156
        16415, 16475, 16535, 16595, 16655, 16715, 16775, 16835, 16895, 16955, 17015, 17074, 17134, 17194, 17254,
-
 
157
        17313, 17373, 17432, 17492, 17551, 17611, 17670, 17730, 17789, 17849, 17908, 17967, 18027, 18086, 18145,
-
 
158
        18204, 18264, 18323, 18382, 18441, 18500, 18559, 18618, 18677, 18736, 18795, 18854, 18912, 18971, 19030,
-
 
159
        19089, 19147, 19206, 19265, 19323, 19382, 19440, 19499, 19557, 19616, 19674, 19733, 19791, 19849, 19908,
-
 
160
        19966, 20024, 20082, 20141, 20199, 20257, 20315, 20373, 20431, 20489, 20547, 20605, 20663, 20720, 20778,
-
 
161
        20836, 20894, 20951, 21009, 21067, 21124, 21182, 21239, 21297, 21354, 21412, 21469, 21526, 21584, 21641,
-
 
162
        21698, 21756, 21813, 21870, 21927, 21984, 22041, 22098, 22155, 22212, 22269, 22326, 22383, 22439, 22496,
-
 
163
        22553, 22610, 22666, 22723, 22780, 22836, 22893, 22949, 23006, 23062, 23118, 23175, 23231, 23287, 23344,
-
 
164
        23400, 23456, 23512, 23568, 23624, 23680, 23736, 23792, 23848, 23904, 23960, 24016, 24071, 24127, 24183,
-
 
165
        24238, 24294, 24350, 24405, 24461, 24516, 24572, 24627, 24682, 24738, 24793, 24848, 24904, 24959, 25014,
-
 
166
        25069, 25124, 25179, 25234, 25289, 25344, 25399, 25454, 25509, 25563, 25618, 25673, 25727, 25782, 25836,
-
 
167
        25891, 25945, 26000, 26054, 26109, 26163, 26217, 26271, 26326, 26380, 26434, 26488, 26542, 26596, 26650,
-
 
168
        26704, 26758, 26812, 26866, 26920, 26974, 27027, 27081, 27135, 27188, 27242, 27295, 27349, 27402, 27456,
-
 
169
        27509, 27563, 27616, 27669, 27722, 27776, 27829, 27882, 27935, 27988, 28041, 28094, 28147, 28200, 28253,
-
 
170
        28305, 28358, 28411, 28464, 28516, 28569, 28621, 28674, 28726, 28779, 28831, 28884, 28936, 28988, 29041,
-
 
171
        29093, 29145, 29197, 29249, 29301, 29353, 29405, 29457, 29509, 29561, 29613, 29664, 29716, 29768, 29820,
-
 
172
        29871, 29923, 29974, 30026, 30077, 30129, 30180, 30231, 30283, 30334, 30385, 30436, 30488, 30539, 30590,
-
 
173
        30641, 30692, 30743, 30794, 30844, 30895, 30946, 30997, 31047, 31098, 31149, 31199, 31250, 31300, 31351,
-
 
174
        31401, 31452, 31502, 31552, 31602, 31653, 31703, 31753, 31803, 31853, 31903, 31953, 32003, 32053, 32103,
-
 
175
        32153, 32202, 32252, 32302, 32351, 32401, 32451, 32500, 32550, 32599, 32649, 32698, 32747, 32796, 32846,
-
 
176
        32895, 32944, 32993, 33042, 33091, 33140, 33189, 33238, 33287, 33336, 33385, 33434, 33482, 33531, 33580,
-
 
177
        33628, 33677, 33725, 33774, 33822, 33871, 33919, 33967, 34015, 34064, 34112, 34160, 34208, 34256, 34304,
-
 
178
        34352, 34400, 34448, 34496, 34544, 34592, 34639, 34687, 34735, 34782, 34830, 34877, 34925, 34972, 35020,
-
 
179
        35067, 35115, 35162, 35209, 35256, 35303, 35351, 35398, 35445, 35492, 35539, 35586, 35633, 35679, 35726,
-
 
180
        35773, 35820, 35866, 35913, 35960, 36006, 36053, 36099, 36146, 36192, 36239, 36285, 36331, 36377, 36424,
-
 
181
        36470, 36516, 36562, 36608, 36654, 36700, 36746, 36792, 36838, 36883, 36929, 36975, 37021, 37066, 37112,
-
 
182
        37157, 37203, 37248, 37294, 37339, 37385, 37430, 37475, 37520, 37566, 37611, 37656, 37701, 37746, 37791,
-
 
183
        37836, 37881, 37926, 37971, 38015, 38060, 38105, 38149, 38194, 38239, 38283, 38328, 38372, 38417, 38461,
-
 
184
        38505, 38550, 38594, 38638, 38682, 38727, 38771, 38815, 38859, 38903, 38947, 38991, 39035, 39078, 39122,
-
 
185
        39166, 39210, 39253, 39297, 39341, 39384, 39428, 39471, 39515, 39558, 39601, 39645, 39688, 39731, 39774,
-
 
186
        39818, 39861, 39904, 39947, 39990, 40033, 40076, 40119, 40161, 40204, 40247, 40290, 40332, 40375, 40418,
-
 
187
        40460, 40503, 40545, 40588, 40630, 40673, 40715, 40757, 40799, 40842, 40884, 40926, 40968, 41010, 41052,
-
 
188
        41094, 41136, 41178, 41220, 41262, 41303, 41345, 41387, 41429, 41470, 41512, 41553, 41595, 41636, 41678,
-
 
189
        41719, 41761, 41802, 41843, 41885, 41926, 41967, 42008, 42049, 42090, 42131, 42172, 42213, 42254, 42295,
-
 
190
        42336, 42376, 42417, 42458, 42499, 42539, 42580, 42620, 42661, 42701, 42742, 42782, 42823, 42863, 42903,
-
 
191
        42944, 42984, 43024, 43064, 43104, 43144, 43184, 43224, 43264, 43304, 43344, 43384, 43424, 43463, 43503,
-
 
192
        43543, 43582, 43622, 43662, 43701, 43741, 43780, 43820, 43859, 43898, 43938, 43977, 44016, 44055, 44094,
-
 
193
        44134, 44173, 44212, 44251, 44290, 44329, 44368, 44406, 44445, 44484, 44523, 44562, 44600, 44639, 44677,
-
 
194
        44716, 44755, 44793, 44832, 44870, 44908, 44947, 44985, 45023, 45062, 45100, 45138, 45176, 45214, 45252,
-
 
195
        45290, 45328, 45366, 45404, 45442, 45480, 45518, 45555, 45593, 45631, 45668, 45706, 45744, 45781, 45819,
-
 
196
        45856, 45894, 45931, 45968, 46006, 46043, 46080, 46117, 46155, 46192, 46229, 46266, 46303, 46340, 46377,
-
 
197
        46414, 46451, 46488, 46525, 46561, 46598, 46635, 46672, 46708, 46745, 46781, 46818, 46854, 46891, 46927,
-
 
198
        46964, 47000, 47037, 47073, 47109, 47145, 47182, 47218, 47254, 47290, 47326, 47362, 47398, 47434, 47470,
-
 
199
        47506, 47542, 47577, 47613, 47649, 47685, 47720, 47756, 47792, 47827, 47863, 47898, 47934, 47969, 48004,
-
 
200
        48040, 48075, 48110, 48146, 48181, 48216, 48251, 48286, 48322, 48357, 48392, 48427, 48462, 48496, 48531,
-
 
201
        48566, 48601, 48636, 48671, 48705, 48740, 48775, 48809, 48844, 48878, 48913, 48947, 48982, 49016, 49051,
-
 
202
        49085, 49119, 49154, 49188, 49222, 49256, 49290, 49324, 49359, 49393, 49427, 49461, 49495, 49528, 49562,
-
 
203
        49596, 49630, 49664, 49698, 49731, 49765, 49799, 49832, 49866, 49899, 49933, 49966, 50000, 50033, 50067,
-
 
204
        50100, 50133, 50167, 50200, 50233, 50266, 50299, 50333, 50366, 50399, 50432, 50465, 50498, 50531, 50564,
-
 
205
        50597, 50629, 50662, 50695, 50728, 50760, 50793, 50826, 50858, 50891, 50924, 50956, 50989, 51021, 51053,
-
 
206
        51086, 51118, 51151, 51183, 51215, 51247, 51280, 51312, 51344, 51376, 51408, 51440, 51472 };
-
 
207
 
-
 
208
const uint16_t FACTORY_C2M_LOOKUP[1024] = {
-
 
209
        32, 32, 32, 32, 32, 32, 33, 33, 33, 34, 35, 35, 36, 37, 38, 39, 39, 41, 42, 43, 44, 45, 47, 48, 49, 51,
-
 
210
        53, 54, 56, 58, 60, 62, 63, 66, 68, 70, 72, 74, 77, 79, 81, 84, 87, 89, 92, 95, 98, 100, 103, 106, 110,
-
 
211
        113, 116, 119, 123, 126, 129, 133, 137, 140, 144, 148, 152, 155, 159, 163, 167, 172, 176, 180, 184, 189,
-
 
212
        193, 198, 202, 207, 212, 217, 221, 226, 231, 236, 241, 246, 252, 257, 262, 268, 273, 279, 284, 290, 295,
-
 
213
        301, 307, 313, 319, 325, 331, 337, 343, 350, 356, 362, 369, 375, 382, 388, 395, 402, 409, 415, 422, 429,
-
 
214
        436, 443, 451, 458, 465, 473, 480, 487, 495, 503, 510, 518, 526, 534, 542, 549, 558, 566, 574, 582, 590,
-
 
215
        599, 607, 615, 624, 633, 641, 650, 659, 667, 676, 685, 694, 703, 712, 722, 731, 740, 750, 759, 768, 778,
-
 
216
        788, 797, 807, 817, 827, 837, 847, 857, 867, 877, 887, 897, 908, 918, 928, 939, 950, 960, 971, 982, 992,
-
 
217
        1003, 1014, 1025, 1036, 1047, 1059, 1070, 1081, 1092, 1104, 1115, 1127, 1138, 1150, 1162, 1174, 1185, 1197,
-
 
218
        1209, 1221, 1233, 1245, 1258, 1270, 1282, 1294, 1307, 1319, 1332, 1344, 1357, 1370, 1383, 1395, 1408, 1421,
-
 
219
        1434, 1447, 1460, 1474, 1487, 1500, 1514, 1527, 1540, 1554, 1568, 1581, 1595, 1609, 1622, 1636, 1650, 1664,
-
 
220
        1678, 1692, 1707, 1721, 1735, 1749, 1764, 1778, 1793, 1807, 1822, 1837, 1852, 1866, 1881, 1896, 1911, 1926,
-
 
221
        1941, 1956, 1972, 1987, 2002, 2018, 2033, 2048, 2064, 2080, 2095, 2111, 2127, 2143, 2159, 2174, 2190, 2207,
-
 
222
        2223, 2239, 2255, 2271, 2288, 2304, 2321, 2337, 2354, 2370, 2387, 2404, 2420, 2437, 2454, 2471, 2488, 2505,
-
 
223
        2522, 2540, 2557, 2574, 2592, 2609, 2626, 2644, 2662, 2679, 2697, 2715, 2732, 2750, 2768, 2786, 2804, 2822,
-
 
224
        2840, 2859, 2877, 2895, 2913, 2932, 2950, 2969, 2987, 3006, 3025, 3043, 3062, 3081, 3100, 3119, 3138, 3157,
-
 
225
        3176, 3195, 3214, 3234, 3253, 3272, 3292, 3311, 3331, 3351, 3370, 3390, 3410, 3430, 3449, 3469, 3489, 3509,
-
 
226
        3529, 3550, 3570, 3590, 3610, 3631, 3651, 3672, 3692, 3713, 3733, 3754, 3775, 3795, 3816, 3837, 3858, 3879,
-
 
227
        3900, 3921, 3942, 3964, 3985, 4006, 4027, 4049, 4070, 4092, 4113, 4135, 4157, 4178, 4200, 4222, 4244, 4266,
-
 
228
        4288, 4310, 4332, 4354, 4376, 4399, 4421, 4443, 4466, 4488, 4510, 4533, 4556, 4578, 4601, 4624, 4647, 4669,
-
 
229
        4692, 4715, 4738, 4761, 4784, 4808, 4831, 4854, 4877, 4901, 4924, 4948, 4971, 4995, 5018, 5042, 5066, 5089,
-
 
230
        5113, 5137, 5161, 5185, 5209, 5233, 5257, 5281, 5306, 5330, 5354, 5378, 5403, 5427, 5452, 5476, 5501, 5526,
-
 
231
        5550, 5575, 5600, 5625, 5650, 5675, 5700, 5725, 5750, 5775, 5800, 5825, 5851, 5876, 5901, 5927, 5952, 5978,
-
 
232
        6003, 6029, 6055, 6080, 6106, 6132, 6158, 6184, 6210, 6236, 6262, 6288, 6314, 6340, 6367, 6393, 6419, 6446,
-
 
233
        6472, 6499, 6525, 6552, 6578, 6605, 6632, 6658, 6685, 6712, 6739, 6766, 6793, 6820, 6847, 6874, 6901, 6929,
-
 
234
        6956, 6983, 7011, 7038, 7066, 7093, 7121, 7148, 7176, 7204, 7231, 7259, 7287, 7315, 7343, 7371, 7399, 7427,
-
 
235
        7455, 7483, 7511, 7539, 7568, 7596, 7624, 7653, 7681, 7710, 7738, 7767, 7796, 7824, 7853, 7882, 7911, 7940,
-
 
236
        7968, 7997, 8026, 8055, 8085, 8114, 8143, 8172, 8201, 8231, 8260, 8289, 8319, 8348, 8378, 8407, 8437, 8467,
-
 
237
        8496, 8526, 8556, 8586, 8616, 8646, 8675, 8705, 8736, 8766, 8796, 8826, 8856, 8886, 8917, 8947, 8977, 9008,
-
 
238
        9038, 9069, 9099, 9130, 9161, 9191, 9222, 9253, 9284, 9315, 9345, 9376, 9407, 9438, 9469, 9501, 9532, 9563,
-
 
239
        9594, 9625, 9657, 9688, 9719, 9751, 9782, 9814, 9845, 9877, 9909, 9940, 9972, 10004, 10036, 10068, 10099,
-
 
240
        10131, 10163, 10195, 10227, 10259, 10292, 10324, 10356, 10388, 10421, 10453, 10485, 10518, 10550, 10583,
-
 
241
        10615, 10648, 10680, 10713, 10746, 10778, 10811, 10844, 10877, 10910, 10943, 10976, 11009, 11042, 11075,
-
 
242
        11108, 11141, 11174, 11208, 11241, 11274, 11308, 11341, 11374, 11408, 11441, 11475, 11509, 11542, 11576,
-
 
243
        11610, 11643, 11677, 11711, 11745, 11779, 11813, 11847, 11881, 11915, 11949, 11983, 12017, 12051, 12085,
-
 
244
        12120, 12154, 12188, 12223, 12257, 12292, 12326, 12361, 12395, 12430, 12465, 12499, 12534, 12569, 12604,
-
 
245
        12638, 12673, 12708, 12743, 12778, 12813, 12848, 12883, 12918, 12954, 12989, 13024, 13059, 13095, 13130,
-
 
246
        13165, 13201, 13236, 13272, 13307, 13343, 13379, 13414, 13450, 13486, 13521, 13557, 13593, 13629, 13665,
-
 
247
        13701, 13736, 13772, 13809, 13845, 13881, 13917, 13953, 13989, 14025, 14062, 14098, 14134, 14171, 14207,
-
 
248
        14244, 14280, 14317, 14353, 14390, 14426, 14463, 14500, 14536, 14573, 14610, 14647, 14684, 14721, 14758,
-
 
249
        14794, 14831, 14869, 14906, 14943, 14980, 15017, 15054, 15091, 15129, 15166, 15203, 15241, 15278, 15316,
-
 
250
        15353, 15391, 15428, 15466, 15503, 15541, 15579, 15616, 15654, 15692, 15730, 15767, 15805, 15843, 15881,
-
 
251
        15919, 15957, 15995, 16033, 16071, 16109, 16147, 16186, 16224, 16262, 16300, 16339, 16377, 16416, 16454,
-
 
252
        16492, 16531, 16569, 16608, 16646, 16685, 16724, 16762, 16801, 16840, 16879, 16917, 16956, 16995, 17034,
-
 
253
        17073, 17112, 17151, 17190, 17229, 17268, 17307, 17346, 17385, 17425, 17464, 17503, 17542, 17582, 17621,
-
 
254
        17660, 17700, 17739, 17779, 17818, 17858, 17897, 17937, 17977, 18016, 18056, 18096, 18135, 18175, 18215,
-
 
255
        18255, 18295, 18335, 18375, 18415, 18455, 18495, 18535, 18575, 18615, 18655, 18695, 18735, 18776, 18816,
-
 
256
        18856, 18896, 18937, 18977, 19017, 19058, 19098, 19139, 19179, 19220, 19260, 19301, 19342, 19382, 19423,
-
 
257
        19464, 19505, 19545, 19586, 19627, 19668, 19709, 19750, 19791, 19832, 19873, 19914, 19955, 19996, 20037,
-
 
258
        20078, 20119, 20160, 20202, 20243, 20284, 20325, 20367, 20408, 20450, 20491, 20532, 20574, 20615, 20657,
-
 
259
        20699, 20740, 20782, 20823, 20865, 20907, 20949, 20990, 21032, 21074, 21116, 21158, 21199, 21241, 21283,
-
 
260
        21325, 21367, 21409, 21451, 21493, 21536, 21578, 21620, 21662, 21704, 21746, 21789, 21831, 21873, 21916,
-
 
261
        21958, 22000, 22043, 22085, 22128, 22170, 22213, 22255, 22298, 22341, 22383, 22426, 22468, 22511, 22554,
-
 
262
        22597, 22639, 22682, 22725, 22768, 22811, 22854, 22897, 22940, 22983, 23026, 23069, 23112, 23155, 23198,
-
 
263
        23241, 23284, 23328, 23371, 23414, 23457, 23501, 23544, 23587, 23631, 23674, 23717, 23761, 23804, 23848,
-
 
264
        23891, 23935, 23978, 24022, 24066, 24109, 24153, 24197, 24240, 24284, 24328, 24372, 24415, 24459, 24503,
-
 
265
        24547, 24591, 24635, 24679, 24723, 24767, 24811, 24855, 24899, 24943, 24987, 25031, 25075, 25120, 25164,
-
 
266
        25208, 25252, 25297, 25341, 25385, 25430, 25474, 25518, 25563, 25607, 25652, 25696, 25741, 25785, 25830,
-
 
267
        25874, 25919, 25964, 26008, 26053, 26098, 26142, 26187, 26232, 26277, 26322, 26366, 26411, 26456, 26501,
-
 
268
        26546, 26591, 26636, 26681, 26726, 26771, 26816, 26861, 26906, 26951, 26997, 27042, 27087, 27132 };
-
 
269
 
-
 
270
// -------------------------------------------------------------------------------------------
-
 
271
 
46
extern value_type slider[],cell[],var[],map[][0x100];
272
extern value_type slider[],cell[],var[],map[][0x100];
47
extern unsigned char *image_ptr;
273
extern unsigned char *image_ptr;
48
 
274
 
-
 
275
// -------------------------------------------------------------------------------------------
-
 
276
 
49
double costab[COSTABSIZE];
277
double costab[COSTABSIZE];
50
double tantab[TANTABSIZE];
278
double tantab[TANTABSIZE];
51
void init_trigtab(){
279
void init_trigtab(){
52
        int i;
280
        int i;
53
        for(i=0;i<COSTABSIZE;++i){
281
        for(i=0;i<COSTABSIZE;++i){
Line 61... Line 289...
61
                        tantab[i] = tan(FFANGLE(i));
289
                        tantab[i] = tan(FFANGLE(i));
62
                }
290
                }
63
        }
291
        }
64
}
292
}
65
 
293
 
-
 
294
// -------------------------------------------------------------------------------------------
-
 
295
 
66
/* Channel z for the input pixel at coordinates x,y.
296
/* Channel z for the input pixel at coordinates x,y.
67
 * Coordinates are relative to the input image data (pb->inData) */
297
 * Coordinates are relative to the input image data (pb->inData) */
68
static value_type rawsrc(value_type x,value_type y,value_type z){
298
static value_type rawsrc(value_type x,value_type y,value_type z){
69
        if (HAS_BIG_DOC(gpb)) {
299
        if (HAS_BIG_DOC(gpb)) {
70
                if (x < BIGDOC_IN_RECT(gpb).left)
300
                if (x < BIGDOC_IN_RECT(gpb).left)
Line 89... Line 319...
89
                return ((unsigned char*)gpb->inData)[(long)gpb->inRowBytes * (y - IN_RECT(gpb).top)
319
                return ((unsigned char*)gpb->inData)[(long)gpb->inRowBytes * (y - IN_RECT(gpb).top)
90
                        + (long)nplanes * (x - IN_RECT(gpb).left) + z];
320
                        + (long)nplanes * (x - IN_RECT(gpb).left) + z];
91
        }
321
        }
92
}
322
}
93
 
323
 
-
 
324
// -------------------------------------------------------------------------------------------
-
 
325
 
94
/* src(x,y,z) Channel z for the pixel at coordinates x,y.
326
/* src(x,y,z) Channel z for the pixel at coordinates x,y.
95
 * Coordinates are relative to filtered area (selection). */
327
 * Coordinates are relative to filtered area (selection). */
-
 
328
 
96
value_type ff_src(value_type x,value_type y,value_type z){
329
value_type ff_src(value_type x,value_type y,value_type z){
97
        #ifdef PARSERTEST
330
        #ifdef PARSERTEST
98
        return 0;
331
        return 0;
99
        #else
332
        #else
100
        if(x < 0)
333
        if(x < 0)
Line 108... Line 341...
108
        return z >= 0 && z < var['Z'] ?
341
        return z >= 0 && z < var['Z'] ?
109
                image_ptr[(long)gpb->inRowBytes*y + (long)nplanes*x + z] : 0;
342
                image_ptr[(long)gpb->inRowBytes*y + (long)nplanes*x + z] : 0;
110
        #endif
343
        #endif
111
}
344
}
112
 
345
 
-
 
346
// -------------------------------------------------------------------------------------------
-
 
347
 
113
/* rad(d,m,z) Channel z in the source image, which is m units away,
348
/* 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 */
349
        at an angle of d, from the center of the image */
-
 
350
 
-
 
351
value_type factory_rad(value_type d, value_type m, value_type z) {
-
 
352
        // https://misc.daniel-marschall.de/projects/filter_factory/function_rad.html
-
 
353
 
-
 
354
        const int xmin = 0;
-
 
355
        const int ymin = 0;
-
 
356
        const int zmin = 0;
-
 
357
 
-
 
358
        int eax, ebx, ecx;
-
 
359
 
-
 
360
        ebx = FACTORY_COS_LOOKUP[d & 1023];
-
 
361
        eax = (((int64_t)m * (int64_t)ebx) + 8191) >> 14;
-
 
362
        ecx = ((var['X'] - xmin) >> 1) + eax;
-
 
363
        if (ecx < 0) {
-
 
364
                ecx = 0;
-
 
365
        }
-
 
366
        else {
-
 
367
                eax = var['X'];
-
 
368
                if (ecx >= eax) {
-
 
369
                        ecx = eax - 1;
-
 
370
                }
-
 
371
        }
-
 
372
 
-
 
373
        ebx = FACTORY_COS_LOOKUP[(d - 256) & 1023];
-
 
374
        eax = (((int64_t)m * (int64_t)ebx) + 8191) >> 14;
-
 
375
        ebx = ((var['Y'] - ymin) >> 1) + eax;
-
 
376
        if (ebx < 0) {
-
 
377
                ebx = 0;
-
 
378
        }
-
 
379
        else {
-
 
380
                eax = var['Y'];
-
 
381
                if (ebx >= eax) {
-
 
382
                        ebx = eax - 1;
-
 
383
                }
-
 
384
        }
-
 
385
 
-
 
386
        // Now return pixel [x=ecx,y=ebx,z=esi] from the source image!
-
 
387
        //return ff_src(ecx, ebx, z);
-
 
388
        ebx *= gpb->inRowBytes;
-
 
389
        ecx *= var['Z'] - zmin;
-
 
390
        return image_ptr[z+ebx+ecx];
-
 
391
}
-
 
392
 
-
 
393
value_type foundry_rad(value_type d, value_type m, value_type z) {
-
 
394
        return ff_src(foundry_r2x(d, m) + var['X'] / 2, foundry_r2y(d, m) + var['Y'] / 2, z);
-
 
395
}
-
 
396
 
115
value_type ff_rad(value_type d,value_type m,value_type z){
397
value_type ff_rad(value_type d,value_type m,value_type z){
-
 
398
        #ifdef use_filterfactory_implementation_rad
-
 
399
        return factory_rad(d, m, z);
-
 
400
        #else
116
        return ff_src(ff_r2x(d,m) + var['X']/2, ff_r2y(d,m) + var['Y']/2, z);
401
        return foundry_rad(d, m, z);
-
 
402
        #endif
117
}
403
}
118
 
404
 
-
 
405
// -------------------------------------------------------------------------------------------
-
 
406
 
119
/* ctl(i) Value of slider i, where i is an integer between 0 and 7, inclusive */
407
/* ctl(i) Value of slider i, where i is an integer between 0 and 7, inclusive */
120
value_type ff_ctl(value_type i){
408
value_type ff_ctl(value_type i){
121
        return i>=0 && i<=7 ? slider[i] : 0;
409
        return i>=0 && i<=7 ? slider[i] : 0;
122
}
410
}
123
 
411
 
-
 
412
// -------------------------------------------------------------------------------------------
-
 
413
 
124
/* val(i,a,b) Value of slider i, mapped onto the range a to b */
414
/* 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){
415
value_type ff_val(value_type i,value_type a,value_type b){
126
        return ((long)ff_ctl(i)*(b-a))/255 + a;
416
        return ((long)ff_ctl(i)*(b-a))/255 + a;
127
}
417
}
128
 
418
 
-
 
419
// -------------------------------------------------------------------------------------------
-
 
420
 
129
/* map(i,n) Item n from mapping table i, where i is an integer between
421
/* map(i,n) Item n from mapping table i, where i is an integer between
130
        0 and 3, inclusive, and n is and integer between 0 and 255,
422
        0 and 3, inclusive, and n is and integer between 0 and 255,
131
        inclusive */
423
        inclusive */
132
value_type ff_map(value_type i,value_type n){
424
value_type ff_map(value_type i,value_type n){
133
/*
425
/*
Line 141... Line 433...
141
        value_type x = ff_ctl(i*2),
433
        value_type x = ff_ctl(i*2),
142
                           y = ff_ctl(i*2+1);
434
                           y = ff_ctl(i*2+1);
143
        return abs(((long)n*(y-x) / 255)+x);
435
        return abs(((long)n*(y-x) / 255)+x);
144
}
436
}
145
 
437
 
-
 
438
// -------------------------------------------------------------------------------------------
-
 
439
 
146
/* min(a,b) Lesser of a and b */
440
/* min(a,b) Lesser of a and b */
147
value_type ff_min(value_type a,value_type b){
441
value_type ff_min(value_type a,value_type b){
148
        return a < b ? a : b;
442
        return a < b ? a : b;
149
}
443
}
150
 
444
 
-
 
445
// -------------------------------------------------------------------------------------------
-
 
446
 
151
/* max(a,b) Greater of a and b */
447
/* max(a,b) Greater of a and b */
152
value_type ff_max(value_type a,value_type b){
448
value_type ff_max(value_type a,value_type b){
153
        return a > b ? a : b;
449
        return a > b ? a : b;
154
}
450
}
155
 
451
 
-
 
452
// -------------------------------------------------------------------------------------------
-
 
453
 
156
/* abs(a) Absolute value of a */
454
/* abs(a) Absolute value of a */
157
value_type ff_abs(value_type a){
455
value_type ff_abs(value_type a){
158
        return abs(a);
456
        return abs(a);
159
}
457
}
160
 
458
 
-
 
459
// -------------------------------------------------------------------------------------------
-
 
460
 
161
/* add(a,b,c) Sum of a and b, or c, whichever is lesser */
461
/* 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){
462
value_type ff_add(value_type a,value_type b,value_type c){
163
        return ff_min(a+b,c);
463
        return ff_min(a+b,c);
164
}
464
}
165
 
465
 
-
 
466
// -------------------------------------------------------------------------------------------
-
 
467
 
166
/* sub(a,b,c) Difference of a and b, or c, whichever is greater */
468
/* 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){
469
value_type ff_sub(value_type a,value_type b,value_type c){
168
        return ff_max(ff_dif(a,b),c);
470
        return ff_max(ff_dif(a,b),c);
169
}
471
}
170
 
472
 
-
 
473
// -------------------------------------------------------------------------------------------
-
 
474
 
171
/* dif(a,b) Absolute value of the difference of a and b */
475
/* dif(a,b) Absolute value of the difference of a and b */
172
value_type ff_dif(value_type a,value_type b){
476
value_type ff_dif(value_type a,value_type b){
173
        return abs(a-b);
477
        return abs(a-b);
174
}
478
}
175
 
479
 
-
 
480
// -------------------------------------------------------------------------------------------
-
 
481
 
-
 
482
/* rnd(a,b) Random number between a and b, inclusive */
-
 
483
 
176
struct factoryRngState {
484
struct factoryRngState {
177
        uint16_t index1;
485
        uint16_t index1;
178
        uint16_t index2;
486
        uint16_t index2;
179
        uint32_t seedTable[56];
487
        uint32_t seedTable[56];
180
        uint32_t seed;
488
        uint32_t seed;
Line 270... Line 578...
270
                default:
578
                default:
271
                        return a + (mj % (range + 1));
579
                        return a + (mj % (range + 1));
272
        }
580
        }
273
}
581
}
274
 
582
 
-
 
583
value_type foundry_rnd(value_type a, value_type b) {
-
 
584
        return (int)((abs(a-b)+1)*(rand()/(RAND_MAX+1.))) + ff_min(a,b);
-
 
585
        //      return ((unsigned)rand() % (ff_dif(a,b)+1)) + ff_min(a,b);
-
 
586
}
-
 
587
 
-
 
588
value_type ff_rnd(value_type a,value_type b){
-
 
589
        #ifdef use_filterfactory_implementation_rnd
-
 
590
        return factory_rnd(a, b, &gFactoryRngState);
-
 
591
        #else
-
 
592
        return foundry_rnd(a, b);
-
 
593
        #endif
-
 
594
}
-
 
595
 
-
 
596
// -------------------------------------------------------------------------------------------
-
 
597
 
-
 
598
void factory_initialize_rnd_variables() {
-
 
599
        gFactoryRngState.seed = 0; // default seed
-
 
600
        gFactoryRngState.seedSave = gFactoryRngState.seed + 1; // force rnd() to call factory_fill_rnd_lookup()
-
 
601
}
-
 
602
 
-
 
603
void foundry_initialize_rnd_variables() {
-
 
604
        srand(691204);
-
 
605
}
-
 
606
 
-
 
607
void initialize_rnd_variables() {
-
 
608
        #ifdef use_filterfactory_implementation_rnd
-
 
609
        factory_initialize_rnd_variables();
-
 
610
        #else
-
 
611
        foundry_initialize_rnd_variables();
-
 
612
        #endif
-
 
613
}
-
 
614
 
-
 
615
// -------------------------------------------------------------------------------------------
-
 
616
 
-
 
617
/* rst(i) sets a random seed and returns 0. (undocumented Filter Factory function).
-
 
618
   Added by DM, 18 Dec 2018 */
-
 
619
 
275
int32_t factory_rst(uint32_t seed, struct factoryRngState* state) {
620
int32_t factory_rst(uint32_t seed, struct factoryRngState* state) {
-
 
621
        // Attention: This is NOT the FilterFactory rst() implementation!
-
 
622
 
276
        // We implement rst(i) completely differently in Filter Foundry:
623
        // We implement rst(i) completely differently in Filter Foundry:
277
        // Every call of rst() will renew the lookup table.
624
        // Every call of rst() will renew the lookup table.
278
        // In Filter Factory, there are strange/buggy things going
625
        // In Filter Factory, there are strange/buggy things going
279
        // on: rst(i) only sets a seed and the lookup table is renewed
626
        // on: rst(i) only sets a seed and the lookup table is renewed
280
        // at the NEXT invocation of the filter. Furthermore, in FilterFactory,
627
        // at the NEXT invocation of the filter. Furthermore, in FilterFactory,
Line 292... Line 639...
292
        state->seedSave = seed+1;
639
        state->seedSave = seed + 1;
293
 
640
 
294
        return 0;
641
        return 0;
295
}
642
}
296
 
643
 
297
void factory_initialize_rnd_variables() {
644
value_type foundry_rst(value_type seed) {
298
        gFactoryRngState.seed = 0; // default seed
645
        srand(seed);
299
        gFactoryRngState.seedSave = gFactoryRngState.seed + 1; // force rnd() to call factory_fill_rnd_lookup()
-
 
-
 
646
        return 0;
300
}
647
}
301
 
648
 
302
/* rnd(a,b) Random number between a and b, inclusive */
649
value_type ff_rst(value_type seed) {
303
value_type ff_rnd(value_type a,value_type b){
650
        #ifdef use_filterfactory_implementation_rnd
304
        return factory_rnd(a,b,&gFactoryRngState);
651
        return factory_rst(seed, &gFactoryRngState);
305
//      return (int)((abs(a-b)+1)*(rand()/(RAND_MAX+1.))) + ff_min(a,b);
-
 
-
 
652
        #else
306
//      return ((unsigned)rand() % (ff_dif(a,b)+1)) + ff_min(a,b);
653
        return foundry_rst(seed);
-
 
654
        #endif
307
}
655
}
308
 
656
 
-
 
657
// -------------------------------------------------------------------------------------------
-
 
658
 
309
/* mix(a,b,n,d) Mixture of a and b by fraction n/d, a*n/d+b*(d-n)/d */
659
/* mix(a,b,n,d) Mixture of a and b by fraction n/d, a*n/d+b*(d-n)/d */
310
value_type ff_mix(value_type a,value_type b,value_type n,value_type d){
660
value_type ff_mix(value_type a,value_type b,value_type n,value_type d){
311
        return d ? ((long)a*n)/d + ((long)b*(d-n))/d : 0;
661
        return d ? ((long)a*n)/d + ((long)b*(d-n))/d : 0;
312
}
662
}
313
 
663
 
-
 
664
// -------------------------------------------------------------------------------------------
-
 
665
 
314
/* scl(a,il,ih,ol,oh) Scale a from input range (il to ih)
666
/* scl(a,il,ih,ol,oh) Scale a from input range (il to ih)
315
                      to output range (ol to oh) */
667
                      to output range (ol to oh) */
316
value_type ff_scl(value_type a,value_type il,value_type ih,
668
value_type ff_scl(value_type a,value_type il,value_type ih,
317
                  value_type ol,value_type oh){
669
                  value_type ol,value_type oh){
318
        return ih==il ? 0 : ol + ((long)(oh-ol)*(a-il))/(ih-il);
670
        return ih==il ? 0 : ol + ((long)(oh-ol)*(a-il))/(ih-il);
319
}
671
}
320
 
672
 
-
 
673
// -------------------------------------------------------------------------------------------
-
 
674
 
-
 
675
/* sqr(x) Square root of x */
-
 
676
 
321
static uint32_t isqrt(uint32_t x) {
677
static uint32_t isqrt(uint32_t x) {
322
        // based on https://gist.github.com/orlp/3481770
678
        // based on https://gist.github.com/orlp/3481770
323
 
679
 
324
        static uint32_t lkpSquares[65535];
680
        static uint32_t lkpSquares[65535];
325
        static int lkpInitialized = 0;
681
        static int lkpInitialized = 0;
Line 355... Line 711...
355
        if (p[1] <= x) p += 1;
711
        if (p[1] <= x) p += 1;
356
 
712
 
357
        return (uint32_t)(p - lkpSquares);
713
        return (uint32_t)(p - lkpSquares);
358
}
714
}
359
 
715
 
360
/* sqr(x) Square root of x */
716
value_type factory_sqr(value_type x) {
-
 
717
        // https://misc.daniel-marschall.de/projects/filter_factory/function_sqr.html
-
 
718
 
-
 
719
        int ebx = x;
-
 
720
        if (ebx > 1) {
-
 
721
                int ecx = ebx;
-
 
722
                ebx = ebx >> 1;
-
 
723
                int eax = 2;
-
 
724
                while (ebx > eax) {
-
 
725
                        eax = ecx;
-
 
726
                        eax /= ebx;
-
 
727
                        ebx += eax;
-
 
728
                        ebx = ebx >> 1;
-
 
729
                }
-
 
730
        }
-
 
731
        return ebx;
-
 
732
}
-
 
733
 
361
value_type ff_sqr(value_type x){
734
value_type foundry_sqr(value_type x) {
-
 
735
        // Note: FilterFactory has sqr(x)=x if x<0 . Here we set sqr(x)=0 for x<0
362
        return x < 0 ? 0 : isqrt(x);
736
        return x < 0 ? 0 : isqrt(x);
363
}
737
}
364
 
738
 
365
/* sin(x) Sine function of x, where x is an integer between 0 and
-
 
366
   1024, inclusive, and the value returned is an integer
-
 
367
   between -512 and 512, inclusive (Windows) or -1024 and
-
 
368
   1024, inclusive (Mac OS) */
-
 
369
value_type ff_sin(value_type x){
739
value_type ff_sqr(value_type x){
-
 
740
        #ifdef use_filterfactory_implementation_sqr
370
        //return RINT(TRIGAMP*sin(FFANGLE(x)));
741
        return factory_sqr(x);
-
 
742
        #else
371
        return ff_cos(x-256);
743
        return foundry_sqr(x);
-
 
744
        #endif
372
}
745
}
373
 
746
 
-
 
747
// -------------------------------------------------------------------------------------------
-
 
748
 
374
/* cos(x) Cosine function of x, where x is an integer between 0 and
749
/* cos(x) Cosine function of x, where x is an integer between 0 and
375
   1024, inclusive, and the value returned is an integer
750
   1024, inclusive, and the value returned is an integer
376
   between -512 and 512, inclusive (Windows) or -1024 and
751
   between -512 and 512, inclusive (Windows) or -1024 and
377
   1024, inclusive (Mac OS) */
752
   1024, inclusive (Mac OS) */
-
 
753
 
378
value_type ff_cos(value_type x){
754
value_type factory_cos(value_type x) {
-
 
755
        // https://misc.daniel-marschall.de/projects/filter_factory/function_cos.html
-
 
756
        int res;
-
 
757
        if (x < 0) x = -x;
-
 
758
        x &= 0x3ff; // 1023
-
 
759
        res = FACTORY_COS_LOOKUP[x];
-
 
760
        return res >= 0 ? (res / 32) : res / 32 - 1;
-
 
761
}
-
 
762
 
-
 
763
value_type foundry_cos(value_type x) {
379
        //return RINT(TRIGAMP*cos(FFANGLE(x)));
764
        //return RINT(TRIGAMP*cos(FFANGLE(x)));
380
        return (value_type)RINT(TRIGAMP*costab[abs(x) % COSTABSIZE]);
765
        return (value_type)RINT(TRIGAMP * costab[abs(x) % COSTABSIZE]);
381
}
766
}
382
 
767
 
-
 
768
value_type ff_cos(value_type x){
-
 
769
        #ifdef use_filterfactory_implementation_cos
-
 
770
        return factory_cos(x);
-
 
771
        #else
-
 
772
        return foundry_cos(x);
-
 
773
        #endif
-
 
774
}
-
 
775
 
-
 
776
// -------------------------------------------------------------------------------------------
-
 
777
 
-
 
778
/* sin(x) Sine function of x, where x is an integer between 0 and
-
 
779
   1024, inclusive, and the value returned is an integer
-
 
780
   between -512 and 512, inclusive (Windows) or -1024 and
-
 
781
   1024, inclusive (Mac OS) */
-
 
782
 
-
 
783
value_type factory_sin(value_type x) {
-
 
784
        // https://misc.daniel-marschall.de/projects/filter_factory/function_sin.html
-
 
785
        return factory_cos(x - 256);
-
 
786
}
-
 
787
 
-
 
788
value_type foundry_sin(value_type x) {
-
 
789
        //return RINT(TRIGAMP*sin(FFANGLE(x)));
-
 
790
        return foundry_cos(x - 256);
-
 
791
}
-
 
792
 
-
 
793
value_type ff_sin(value_type x) {
-
 
794
        #ifdef use_filterfactory_implementation_sin
-
 
795
        return factory_sin(x);
-
 
796
        #else
-
 
797
        return foundry_sin(x);
-
 
798
        #endif
-
 
799
}
-
 
800
 
-
 
801
// -------------------------------------------------------------------------------------------
-
 
802
 
383
/* tan(x) Tangent function of x, where x is an integer
803
/* tan(x) Tangent function of x, where x is an integer
384
   between -256 and 256, inclusive. Althought the Filter Factory manual
804
   between -256 and 256, inclusive. Althought the Filter Factory manual
385
   stated that the return value is bounded to -512 and 512, inclusive (Windows) or
805
   stated that the return value is bounded to -512 and 512, inclusive (Windows) or
386
   -1024 and 1024, inclusive (Mac OS), the output is actually NOT bounded! */
806
   -1024 and 1024, inclusive (Mac OS), the output is actually NOT bounded! */
-
 
807
 
-
 
808
value_type factory_tan(value_type x) {
-
 
809
        // https://misc.daniel-marschall.de/projects/filter_factory/function_tan.html
-
 
810
        int v1 = x;
-
 
811
        int v2 = v1 < 0 ? -v1 : v1;
-
 
812
        v2 &= 0x3ff; // 1023
-
 
813
        v2 = FACTORY_COS_LOOKUP[v2];
-
 
814
        v1 -= 256;
-
 
815
        if (v1 < 0) v1 = -v1;
-
 
816
        v1 &= 0x3ff; // 1023
-
 
817
        v1 = FACTORY_COS_LOOKUP[v1];
-
 
818
        if (v2 == 0) return 0;
-
 
819
        v1 = v1 << 10; // v1 *= 1024;
-
 
820
        return v1 / v2;
-
 
821
}
-
 
822
 
387
value_type ff_tan(value_type x){
823
value_type foundry_tan(value_type x){
388
        // Following filter shows that the Filter Factory manual differs from the implementation.
824
        // Following filter shows that the Filter Factory manual differs from the implementation.
389
        //     R = cos(x) > 1024 || cos(x) < -1024 || cos(-x) > 1024 || cos(-x) < -1024 ? 255 : 0
825
        //     R = cos(x) > 1024 || cos(x) < -1024 || cos(-x) > 1024 || cos(-x) < -1024 ? 255 : 0
390
        //     G = tan(x) > 1024 || tan(x) < -1024 || tan(-x) > 1024 || tan(-x) < -1024 ? 255 : 0
826
        //     G = tan(x) > 1024 || tan(x) < -1024 || tan(-x) > 1024 || tan(-x) < -1024 ? 255 : 0
391
        //     B = sin(x) > 1024 || sin(x) < -1024 || sin(-x) > 1024 || sin(-x) < -1024 ? 255 : 0
827
        //     B = sin(x) > 1024 || sin(x) < -1024 || sin(-x) > 1024 || sin(-x) < -1024 ? 255 : 0
392
        // It outputs green stripes, showing that the output of tan() is not bounded.
828
        // It outputs green stripes, showing that the output of tan() is not bounded.
Line 394... Line 830...
394
        if (x < 0) x--; /* required for Filter Factory compatibility */
830
        if (x < 0) x--; /* required for Filter Factory compatibility */
395
        while (x < 0) x += TANTABSIZE;
831
        while (x < 0) x += TANTABSIZE;
396
        return (value_type)RINT(2*TRIGAMP*tantab[x % TANTABSIZE]); // We need the x2 multiplicator for some reason
832
        return (value_type)RINT(2*TRIGAMP*tantab[x % TANTABSIZE]); // We need the x2 multiplicator for some reason
397
}
833
}
398
 
834
 
-
 
835
value_type ff_tan(value_type x) {
-
 
836
        #ifdef use_filterfactory_implementation_tan
-
 
837
        return factory_tan(x);
-
 
838
        #else
-
 
839
        return foundry_tan(x);
-
 
840
        #endif
-
 
841
}
-
 
842
 
-
 
843
// -------------------------------------------------------------------------------------------
-
 
844
 
399
/* r2x(d,m) x displacement of the pixel m units away, at an angle of d,
845
/* r2x(d,m) x displacement of the pixel m units away, at an angle of d,
400
   from an arbitrary center */
846
   from an arbitrary center */
-
 
847
 
401
value_type ff_r2x(value_type d,value_type m){
848
value_type factory_r2x(value_type d, value_type m) {
-
 
849
        // https://misc.daniel-marschall.de/projects/filter_factory/function_r2x.html
-
 
850
        int eax = m;
-
 
851
        int ebx = d;
-
 
852
        ebx &= 1023;
-
 
853
        ebx = FACTORY_COS_LOOKUP[ebx];
-
 
854
        return (((int64_t)eax * (int64_t)ebx) + 8191) >> 14;
-
 
855
}
-
 
856
 
-
 
857
value_type foundry_r2x(value_type d, value_type m) {
402
        return (value_type)RINT(m*costab[abs(d) % COSTABSIZE]);
858
        return (value_type)RINT(m * costab[abs(d) % COSTABSIZE]);
403
}
859
}
404
 
860
 
-
 
861
value_type ff_r2x(value_type d,value_type m){
-
 
862
        #ifdef use_filterfactory_implementation_r2x
-
 
863
        return factory_r2x(d,m);
-
 
864
        #else
-
 
865
        return foundry_r2x(d, m);
-
 
866
        #endif
-
 
867
}
-
 
868
 
-
 
869
// -------------------------------------------------------------------------------------------
-
 
870
 
405
/* r2y(d,m) y displacement of the pixel m units away, at an angle of d,
871
/* r2y(d,m) y displacement of the pixel m units away, at an angle of d,
406
   from an arbitrary center */
872
   from an arbitrary center */
-
 
873
 
407
value_type ff_r2y(value_type d,value_type m){
874
value_type factory_r2y(value_type d, value_type m) {
-
 
875
        // https://misc.daniel-marschall.de/projects/filter_factory/function_r2y.html
-
 
876
        return factory_r2x(d - 256, m);
-
 
877
}
-
 
878
 
-
 
879
value_type foundry_r2y(value_type d, value_type m) {
408
        return (value_type)RINT(m*costab[abs(d-256) % COSTABSIZE]);
880
        return (value_type)RINT(m * costab[abs(d - 256) % COSTABSIZE]);
409
}
881
}
410
 
882
 
-
 
883
value_type ff_r2y(value_type d,value_type m){
-
 
884
        #ifdef use_filterfactory_implementation_r2y
-
 
885
        return factory_r2y(d, m);
-
 
886
        #else
-
 
887
        return foundry_r2y(d, m);
-
 
888
        #endif
-
 
889
}
-
 
890
 
411
/* Attention! This is NOT a function. It is internally used to calculate the variable "d". */
891
// -------------------------------------------------------------------------------------------
-
 
892
 
-
 
893
value_type ff_D() {
-
 
894
        return 1024;
-
 
895
}
-
 
896
 
-
 
897
// -------------------------------------------------------------------------------------------
-
 
898
 
-
 
899
value_type factory_d() {
-
 
900
        return 0; // TODO!
-
 
901
}
-
 
902
 
412
value_type ff_c2d_negated(value_type x, value_type y) {
903
value_type foundry_c2d_negated(int x, int y) {
-
 
904
        return (value_type)RINT(TO_FFANGLE(atan2(-y, -x)));
-
 
905
}
-
 
906
 
-
 
907
value_type foundry_d() {
413
        // NOTE: FilterFactory uses c2d(x,y):=atan2(y,x), but d:=atan2(-y,-x)
908
        // NOTE: FilterFactory uses c2d(x,y):=atan2(y,x), but d:=atan2(-y,-x)
414
        // Due to compatibility reasons, we implement it the same way!
909
        // Due to compatibility reasons, we implement it the same way!
415
        // Sign of y difference is negated, as we are dealing with top-down coordinates angle is "observed"
910
        // Sign of y difference is negated, as we are dealing with top-down coordinates angle is "observed"
-
 
911
        int x = var['X'] / 2 - var['x'];
-
 
912
        int y = var['Y'] / 2 - var['y'];
-
 
913
        return ff_c2d_negated(x, y);
-
 
914
}
-
 
915
 
-
 
916
value_type ff_d() {
-
 
917
        #ifdef use_filterfactory_implementation_d
-
 
918
        return factory_d();
-
 
919
        #else
-
 
920
        return foundry_d();
-
 
921
        #endif
-
 
922
}
-
 
923
 
-
 
924
// -------------------------------------------------------------------------------------------
-
 
925
 
-
 
926
value_type factory_M() {
-
 
927
        return 0; // TODO!
-
 
928
}
-
 
929
 
-
 
930
value_type foundry_M() {
416
        return (value_type)RINT(TO_FFANGLE(atan2(-y,-x)));
931
        return foundry_c2m(var['X'], var['Y']) / 2;
-
 
932
}
-
 
933
 
-
 
934
value_type ff_M() {
-
 
935
        #ifdef use_filterfactory_implementation_M
-
 
936
        return factory_M();
-
 
937
        #else
-
 
938
        return foundry_M();
-
 
939
        #endif
-
 
940
}
-
 
941
 
-
 
942
// -------------------------------------------------------------------------------------------
-
 
943
 
-
 
944
value_type factory_m() {
-
 
945
        return 0; // TODO!
-
 
946
}
-
 
947
 
-
 
948
value_type foundry_m() {
-
 
949
        return foundry_c2m(var['X'] / 2 - var['x'], var['Y'] / 2 - var['y']);
-
 
950
}
-
 
951
 
-
 
952
value_type ff_m() {
-
 
953
        #ifdef use_filterfactory_implementation_m
-
 
954
        return factory_m();
-
 
955
        #else
-
 
956
        return foundry_m();
-
 
957
        #endif
-
 
958
}
-
 
959
 
-
 
960
// -------------------------------------------------------------------------------------------
-
 
961
 
-
 
962
value_type factory_i() {
-
 
963
        return ((76L * var['r']) + (150L * var['g']) + (29L * var['b'])) / 256; // range: [0..254]
-
 
964
}
-
 
965
 
-
 
966
value_type foundry_i() {
-
 
967
        // These formulas are more accurate, e.g. pure white has now i=255 instead of 254
-
 
968
        return ((299L * var['r']) + (587L * var['g']) + (114L * var['b'])) / 1000;    // range: [0..255]
-
 
969
}
-
 
970
 
-
 
971
value_type ff_i() {
-
 
972
        #ifdef use_filterfactory_implementation_i
-
 
973
        return factory_i();
-
 
974
        #else
-
 
975
        return foundry_i();
-
 
976
        #endif
-
 
977
}
-
 
978
 
-
 
979
// -------------------------------------------------------------------------------------------
-
 
980
 
-
 
981
value_type factory_u() {
-
 
982
        return ((-19L * var['r']) + (-37L * var['g']) + (56L * var['b'])) / 256; // range: [-55..55]
-
 
983
}
-
 
984
 
-
 
985
value_type foundry_u() {
-
 
986
        // These formulas are more accurate, e.g. pure white has now i=255 instead of 254
-
 
987
        return ((-147407L * var['r']) + (-289391L * var['g']) + (436798L * var['b'])) / 2000000; // range: [-55..55]
-
 
988
}
-
 
989
 
-
 
990
value_type ff_u() {
-
 
991
        #ifdef use_filterfactory_implementation_u
-
 
992
        return factory_u();
-
 
993
        #else
-
 
994
        return foundry_u();
-
 
995
        #endif
-
 
996
}
-
 
997
 
-
 
998
// -------------------------------------------------------------------------------------------
-
 
999
 
-
 
1000
value_type factory_v() {
-
 
1001
        return ((78L * var['r']) + (-65L * var['g']) + (-13L * var['b'])) / 256; // range: [-77..77]
-
 
1002
}
-
 
1003
 
-
 
1004
value_type foundry_v() {
-
 
1005
        // These formulas are more accurate, e.g. pure white has now i=255 instead of 254
-
 
1006
        return ((614777L * var['r']) + (-514799L * var['g']) + (-99978L * var['b'])) / 2000000; // range: [-78..78]
-
 
1007
}
-
 
1008
 
-
 
1009
value_type ff_v() {
-
 
1010
        #ifdef use_filterfactory_implementation_v
-
 
1011
        return factory_v();
-
 
1012
        #else
-
 
1013
        return foundry_v();
-
 
1014
        #endif
417
}
1015
}
418
 
1016
 
-
 
1017
// -------------------------------------------------------------------------------------------
-
 
1018
 
419
/* c2d(x,y) Angle displacement of the pixel at coordinates x,y */
1019
/* c2d(x,y) Angle displacement of the pixel at coordinates x,y */
-
 
1020
 
-
 
1021
value_type factory_c2d(value_type x, value_type y) {
-
 
1022
        // https://misc.daniel-marschall.de/projects/filter_factory/function_c2d.html
-
 
1023
        int32_t aaa, bbb, ccc;
-
 
1024
        aaa = y;
-
 
1025
        bbb = x;
-
 
1026
        ccc = 0;
-
 
1027
        if (aaa < 0) {
-
 
1028
                aaa = -aaa;
-
 
1029
                ccc |= 0b0100;
-
 
1030
        }
-
 
1031
        if (bbb < 0) {
-
 
1032
                bbb = -bbb;
-
 
1033
                ccc |= 0x0011;
-
 
1034
        }
-
 
1035
        if (aaa > bbb) {
-
 
1036
                ccc ^= 0b0001;
-
 
1037
                int xxx = aaa;
-
 
1038
                aaa = bbb;
-
 
1039
                bbb = xxx;
-
 
1040
        }
-
 
1041
        if (aaa > 0) {
-
 
1042
                aaa = aaa << 10;
-
 
1043
                aaa /= bbb;
-
 
1044
                if (aaa != 0) {
-
 
1045
                        aaa = (aaa & 0xFFFF0000) | (FACTORY_C2D_LOOKUP[aaa - 1] & 0xFFFF);
-
 
1046
                        aaa = aaa << 9;
-
 
1047
                        bbb = 205888; // 205888/65536 == pi
-
 
1048
                        aaa /= bbb;
-
 
1049
                }
-
 
1050
        }
-
 
1051
        if ((ccc & 0b0001) != 0) {
-
 
1052
                aaa = -aaa;
-
 
1053
                aaa += 256;
-
 
1054
        }
-
 
1055
        if ((ccc & 0b0010) != 0) {
-
 
1056
                aaa += 256;
-
 
1057
        }
-
 
1058
        if ((ccc & 0b0100) != 0) {
-
 
1059
                aaa = -aaa;
-
 
1060
        }
-
 
1061
        return aaa;
-
 
1062
}
-
 
1063
 
420
value_type ff_c2d(value_type x,value_type y){
1064
value_type foundry_c2d(value_type x, value_type y) {
421
        // Behavior of FilterFoundry <1.7:
1065
        // Behavior of FilterFoundry <1.7:
422
        //return ff_c2d_negated(x,y);
1066
        //return foundry_c2d_negated(x,y);
423
 
1067
 
424
        // Behavior in FilterFoundry 1.7+: Matches FilterFactory
1068
        // Behavior in FilterFoundry 1.7+: Matches FilterFactory
425
        return (value_type)RINT(TO_FFANGLE(atan2(y,x)));
1069
        return (value_type)RINT(TO_FFANGLE(atan2(y, x)));
426
}
1070
}
427
 
1071
 
-
 
1072
value_type ff_c2d(value_type x, value_type y) {
-
 
1073
        #ifdef use_filterfactory_implementation_c2d
-
 
1074
        return factory_c2d(x, y);
-
 
1075
        #else
-
 
1076
        return foundry_c2d(x, y);
-
 
1077
        #endif
-
 
1078
}
-
 
1079
 
-
 
1080
// -------------------------------------------------------------------------------------------
-
 
1081
 
428
/* c2m(x,y) Magnitude displacement of the pixel at coordinates x,y */
1082
/* c2m(x,y) Magnitude displacement of the pixel at coordinates x,y */
-
 
1083
 
429
value_type ff_c2m(value_type x,value_type y){
1084
value_type factory_c2m(value_type x, value_type y) {
-
 
1085
        // https://misc.daniel-marschall.de/projects/filter_factory/function_c2m.html
-
 
1086
        int32_t aaa, bbb;
-
 
1087
        bbb = y < 0 ? -y : y;
-
 
1088
        aaa = x < 0 ? -x : x;
-
 
1089
        if (aaa == bbb) {
-
 
1090
                aaa = 27146; // 27146/65536 == sqrt(1)-1
-
 
1091
        }
-
 
1092
        else {
-
 
1093
                if (aaa > bbb) {
-
 
1094
                        int xxx = aaa;
-
 
1095
                        aaa = bbb;
-
 
1096
                        bbb = xxx;
-
 
1097
                }
-
 
1098
                aaa = aaa << 10;
-
 
1099
                aaa /= bbb;
-
 
1100
                aaa = FACTORY_C2M_LOOKUP[aaa];
-
 
1101
        }
-
 
1102
        aaa = ((int64_t)aaa * (int64_t)bbb) >> 16;
-
 
1103
        aaa += bbb;
-
 
1104
        return aaa;
-
 
1105
}
-
 
1106
 
-
 
1107
value_type foundry_c2m(value_type x, value_type y) {
430
        return isqrt((long)x*x + (long)y*y);
1108
        return isqrt((long)x * x + (long)y * y);
431
}
1109
}
432
 
1110
 
-
 
1111
value_type ff_c2m(value_type x, value_type y) {
-
 
1112
        #ifdef use_filterfactory_implementation_c2m
-
 
1113
        return factory_c2m(x, y);
-
 
1114
        #else
-
 
1115
        return foundry_c2m(x, y);
-
 
1116
        #endif
-
 
1117
}
-
 
1118
 
-
 
1119
// -------------------------------------------------------------------------------------------
-
 
1120
 
433
/* get(i) Returns the current cell value at i */
1121
/* get(i) Returns the current cell value at i */
434
value_type ff_get(value_type i){
1122
value_type ff_get(value_type i){
435
        // Filter Factory:
1123
        // Filter Factory:
436
        //return i>=0 && i<NUM_CELLS ? cell[i] : i;
1124
        //return i>=0 && i<NUM_CELLS ? cell[i] : i;
437
 
1125
 
438
        // Filter Foundry:
1126
        // Filter Foundry:
439
        return i>=0 && i<NUM_CELLS ? cell[i] : 0;
1127
        return i>=0 && i<NUM_CELLS ? cell[i] : 0;
440
}
1128
}
441
 
1129
 
-
 
1130
// -------------------------------------------------------------------------------------------
-
 
1131
 
442
/* put(v,i) Puts the new value v into cell i */
1132
/* put(v,i) Puts the new value v into cell i */
443
value_type ff_put(value_type v,value_type i){
1133
value_type ff_put(value_type v,value_type i){
444
        if(i>=0 && i<NUM_CELLS)
1134
        if(i>=0 && i<NUM_CELLS)
445
                cell[i] = v;
1135
                cell[i] = v;
446
        return v;
1136
        return v;
447
}
1137
}
448
 
1138
 
-
 
1139
// -------------------------------------------------------------------------------------------
-
 
1140
 
449
/* Convolve. Applies a convolution matrix and divides with d. */
1141
/* Convolve. Applies a convolution matrix and divides with d. */
450
value_type ff_cnv(value_type m11,value_type m12,value_type m13,
1142
value_type ff_cnv(value_type m11,value_type m12,value_type m13,
451
                  value_type m21,value_type m22,value_type m23,
1143
                  value_type m21,value_type m22,value_type m23,
452
                  value_type m31,value_type m32,value_type m33,
1144
                  value_type m31,value_type m32,value_type m33,
453
                  value_type d)
1145
                  value_type d)
Line 476... Line 1168...
476
 
1168
 
477
        return d ? total/d : 0;
1169
        return d ? total/d : 0;
478
        #endif
1170
        #endif
479
}
1171
}
480
 
1172
 
481
/* rst(i) sets a random seed and returns 0. (undocumented Filter Factory function).
1173
// -------------------------------------------------------------------------------------------
482
   Added by DM, 18 Dec 2018 */
-
 
483
value_type ff_rst(value_type seed){
-
 
484
        factory_rst(seed,&gFactoryRngState);
-
 
485
//      srand(seed);
-
 
486
        return 0;
-
 
487
}
-
 
488
 
1174
 
489
value_type zero_val = 0;
1175
value_type zero_val = 0;
490
value_type one_val = 1;
1176
value_type one_val = 1;
491
value_type max_channel_val = 255;
1177
value_type max_channel_val = 255;
492
 
1178