Fix compilation error of Cycles after recent py node removal
[blender-staging.git] / source / blender / blenpluginapi / intern / pluginapi.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  * Wrappers for the plugin api. This api is up for removal.
27  */
28
29 /** \file blender/blenpluginapi/intern/pluginapi.c
30  *  \ingroup blenpluginapi
31  */
32
33
34 /* There are four headers making up the plugin api:
35  * - floatpatch.h : Wraps math functions for mips platforms, no code
36  *                  required.
37  * - iff.h        : Defines, macros and functions for dealing
38  *                  with image buffer things.
39  * - plugin.h     : Wraps some plugin handling types, accesses noise
40  *                  functions.
41  * - util.h       : Useful defines, memory management.
42  */
43
44 #define PLUGIN_INTERN /* This tells the LIBEXPORT macro to compile with
45                        * dll export set on windows */
46
47 #ifdef WIN32
48 #include "blenpluginapi/util.h"
49 #else
50 #include "blenpluginapi/util.h"
51 #endif
52 #include "iff.h"
53 #include "plugin.h"
54 #include "MEM_guardedalloc.h"
55
56 #include "BLO_sys_types.h" // needed for intptr_t
57
58 #include "BLI_blenlib.h"  /* util and noise functions */
59 #include "BLI_threads.h"  /* For threadsfe guardedalloc malloc/calloc/free */
60 #include "IMB_imbuf.h"    /* image buffer stuff       */
61 #define GET_INT_FROM_POINTER(i) ((int)(intptr_t)(i)) /* should use BKE_utildefines.h */
62
63 /* -------------------------------------------------------------------------- */
64 /* stuff from util.h                                                          */ 
65 /* -------------------------------------------------------------------------- */
66
67 LIBEXPORT void *mallocN(int len, char *str)
68 {
69         return MEM_mallocN(len, str);
70 }
71
72 LIBEXPORT void *callocN(int len, char *str)
73 {
74         return MEM_callocN(len, str);
75 }
76
77 LIBEXPORT short freeN(void *vmemh)
78 {
79         return MEM_freeN(vmemh);
80 }
81
82 /* these are not needed anymore, mallocN/callocN/freeN is now threadsafe */
83 LIBEXPORT void *mallocT(int len, char *str)
84 {
85         return MEM_mallocN(len, str);
86 }
87
88 LIBEXPORT void *callocT(int len, char *str)
89 {
90         return MEM_callocN(len, str);
91 }
92
93 LIBEXPORT void freeT(void *vmemh)
94 {
95         MEM_freeN(vmemh);
96         return;
97 }
98
99
100 /* -------------------------------------------------------------------------- */
101 /* stuff from iff.h                                                           */ 
102 /* -------------------------------------------------------------------------- */
103
104 LIBEXPORT struct ImBuf *allocImBuf(short x,
105                                                  short y,
106                                                  uchar d,
107                                                  uint flags)
108 {
109         return IMB_allocImBuf(x, y, d, flags);
110 }
111
112
113 LIBEXPORT struct ImBuf *dupImBuf(struct ImBuf *ib)
114 {
115         return IMB_dupImBuf(ib);
116 }
117         
118 LIBEXPORT void freeImBuf(struct ImBuf* ib)
119 {
120         IMB_freeImBuf(ib);
121 }
122
123 LIBEXPORT short saveiff(struct ImBuf *ib,
124                           char *c,
125                           int i)
126 {
127         return IMB_saveiff(ib, c, i);
128 }
129
130 LIBEXPORT struct ImBuf *loadifffile(int a,
131                                                   int b)
132 {
133         return IMB_loadifffile(a, b, "loadifffile");
134 }
135
136 LIBEXPORT struct ImBuf *loadiffname(char *n,
137                                                   int flags)
138 {
139         return IMB_loadiffname(n, flags);
140 }
141         
142 LIBEXPORT struct ImBuf *testiffname(char *n,
143                                                   int flags)
144 {
145         return IMB_testiffname(n, flags);
146 }
147
148 LIBEXPORT struct ImBuf *onehalf(struct ImBuf *ib)
149 {
150         return IMB_onehalf(ib);
151 }
152
153 LIBEXPORT struct ImBuf *half_x(struct ImBuf *ib)
154 {
155         return IMB_half_x(ib);
156 }
157
158 LIBEXPORT struct ImBuf *half_y(struct ImBuf *ib)
159 {
160         return IMB_half_y(ib);
161 }
162
163 LIBEXPORT struct ImBuf *double_x(struct ImBuf *ib)
164 {
165         return IMB_double_x(ib);
166 }
167
168 LIBEXPORT struct ImBuf *double_y(struct ImBuf *ib)
169 {
170         return IMB_double_y(ib);
171 }
172
173 LIBEXPORT struct ImBuf *double_fast_x(struct ImBuf *ib)
174 {
175         return IMB_double_fast_x(ib);
176 }
177
178 LIBEXPORT struct ImBuf *double_fast_y(struct ImBuf *ib)
179 {
180         return IMB_double_fast_y(ib);
181 }
182
183 LIBEXPORT int ispic(char * name)
184 {
185         return IMB_ispic(name);
186 }
187
188 /* still the same name */
189 /*  void (*ditherfunc)(struct ImBuf *, short, short) {} */
190
191 LIBEXPORT struct ImBuf *scaleImBuf(struct ImBuf *ib,
192                                                  short nx,
193                                                  short ny)
194 {
195         return IMB_scaleImBuf(ib, nx, ny);
196 }
197
198 LIBEXPORT struct ImBuf *scalefastImBuf(struct ImBuf *ib,
199                                                          short x,
200                                                          short y)
201 {
202         return IMB_scalefastImBuf(ib, x, y);
203 }
204
205         /* Extra ones that some NaN (read Ton) plugins use,
206          * even though they aren't in the header
207          */
208
209 LIBEXPORT void interlace(struct ImBuf *ibuf)
210 {
211         IMB_interlace(ibuf);
212 }
213
214 LIBEXPORT void de_interlace(struct ImBuf *ib)
215 {
216         IMB_de_interlace(ib);
217 }
218
219 /* -------------------------------------------------------------------------- */
220 /* stuff from plugin.h                                                        */ 
221 /* -------------------------------------------------------------------------- */
222
223 /* These three need to be defined in the plugin itself. The plugin
224  * loader looks for these functions to check whether it can use the
225  * plugin. For sequences, something similar exists. */
226 /*  int plugin_tex_getversion(void); */
227 /*  int plugin_seq_getversion(void); */
228 /*  void plugin_getinfo(PluginInfo *); */
229
230 LIBEXPORT float hnoise(float noisesize,
231                          float x,
232                          float y,
233                          float z)
234 {
235         return BLI_hnoise(noisesize, x, y, z);
236 }
237
238 LIBEXPORT float hnoisep(float noisesize,
239                           float x,
240                           float y,
241                           float z)
242 {
243         return BLI_hnoisep(noisesize, x, y, z);
244 }
245
246 LIBEXPORT float turbulence(float noisesize,
247                                  float x,
248                                  float y,
249                                  float z,
250                                  int depth)
251 {
252         return BLI_turbulence(noisesize, x, y, z, depth);
253 }
254
255 LIBEXPORT float turbulence1(float noisesize,
256                                   float x,
257                                   float y,
258                                   float z,
259                                   int depth)
260 {
261         return BLI_turbulence1(noisesize, x, y, z, depth);
262 }
263
264 /* -------------------------------------------------------------------------- */
265
266         /* Stupid hack - force the inclusion of all of the
267          * above functions in the binary by 'using' each one...
268          * Otherwise they will not be imported from the archive
269          * library on Unix. -zr
270          */
271 int pluginapi_force_ref(void);
272
273 int pluginapi_force_ref(void)
274 {
275         return 
276                 GET_INT_FROM_POINTER(mallocN) +
277                 GET_INT_FROM_POINTER(callocN) +
278                 GET_INT_FROM_POINTER(freeN) +
279                 GET_INT_FROM_POINTER(mallocT) +
280                 GET_INT_FROM_POINTER(callocT) +
281                 GET_INT_FROM_POINTER(freeT) +
282                 GET_INT_FROM_POINTER(allocImBuf) +
283                 GET_INT_FROM_POINTER(dupImBuf) +
284                 GET_INT_FROM_POINTER(freeImBuf) +
285                 GET_INT_FROM_POINTER(saveiff) +
286                 GET_INT_FROM_POINTER(loadifffile) +
287                 GET_INT_FROM_POINTER(loadiffname) +
288                 GET_INT_FROM_POINTER(testiffname) +
289                 GET_INT_FROM_POINTER(onehalf) +
290                 GET_INT_FROM_POINTER(half_x) +
291                 GET_INT_FROM_POINTER(half_y) +
292                 GET_INT_FROM_POINTER(double_x) +
293                 GET_INT_FROM_POINTER(double_y) +
294                 GET_INT_FROM_POINTER(double_fast_x) +
295                 GET_INT_FROM_POINTER(double_fast_y) +
296                 GET_INT_FROM_POINTER(ispic) +
297                 GET_INT_FROM_POINTER(scaleImBuf) +
298                 GET_INT_FROM_POINTER(scalefastImBuf) +
299                 GET_INT_FROM_POINTER(hnoise) +
300                 GET_INT_FROM_POINTER(hnoisep) +
301                 GET_INT_FROM_POINTER(turbulence) +
302                 GET_INT_FROM_POINTER(turbulence1) +
303                 GET_INT_FROM_POINTER(de_interlace) +
304                 GET_INT_FROM_POINTER(interlace);
305 }