Merge of trunk into blender 2.5:
[blender.git] / source / blender / blenpluginapi / intern / pluginapi.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (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 Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  * Wrappers for the plugin api. This api is up for removal.
29  */
30
31 /* There are four headers making up the plugin api:
32  * - floatpatch.h : Wraps math functions for mips platforms, no code
33  *                  required.
34  * - iff.h        : Defines, macros and functions for dealing
35  *                  with image buffer things.
36  * - plugin.h     : Wraps some plugin handling types, accesses noise
37  *                  functions.
38  * - util.h       : Useful defines, memory management.
39  */
40
41 #define PLUGIN_INTERN /* This tells the LIBEXPORT macro to compile with
42         dll export set on windows */
43
44 #ifdef WIN32
45 #include "blenpluginapi/util.h"
46 #else
47 #include "blenpluginapi/util.h"
48 #endif
49 #include "iff.h"
50 #include "plugin.h"
51 #include "MEM_guardedalloc.h"
52
53 #include "BLO_sys_types.h" // needed for intptr_t
54
55 #include "BLI_blenlib.h"  /* util and noise functions */
56 #include "BLI_threads.h"  /* For threadsfe guardedalloc malloc/calloc/free */
57 #include "IMB_imbuf.h"    /* image buffer stuff       */
58 #define GET_INT_FROM_POINTER(i) ((int)(intptr_t)(i)) /* should use BKE_utildefines.h */
59
60 /* -------------------------------------------------------------------------- */
61 /* stuff from util.h                                                          */ 
62 /* -------------------------------------------------------------------------- */
63
64 LIBEXPORT void *mallocN(int len, char *str)
65 {
66         return MEM_mallocN(len, str);
67 }
68
69 LIBEXPORT void *callocN(int len, char *str)
70 {
71         return MEM_callocN(len, str);
72 }
73
74 LIBEXPORT short freeN(void *vmemh)
75 {
76         return MEM_freeN(vmemh);
77 }
78
79 /* these are not needed anymore, mallocN/callocN/freeN is now threadsafe */
80 LIBEXPORT void *mallocT(int len, char *str)
81 {
82         return MEM_mallocN(len, str);
83 }
84
85 LIBEXPORT void *callocT(int len, char *str)
86 {
87         return MEM_callocN(len, str);
88 }
89
90 LIBEXPORT void freeT(void *vmemh)
91 {
92         MEM_freeN(vmemh);
93         return;
94 }
95
96
97 /* -------------------------------------------------------------------------- */
98 /* stuff from iff.h                                                           */ 
99 /* -------------------------------------------------------------------------- */
100
101 LIBEXPORT struct ImBuf *allocImBuf(short x,
102                                                  short y,
103                                                  uchar d,
104                                                  uint flags,
105                                                  uchar bitmap)
106 {
107         return IMB_allocImBuf(x, y, d, flags, bitmap);
108 }
109
110
111 LIBEXPORT struct ImBuf *dupImBuf(struct ImBuf *ib)
112 {
113         return IMB_dupImBuf(ib);
114 }
115         
116 LIBEXPORT void freeImBuf(struct ImBuf* ib)
117 {
118         IMB_freeImBuf(ib);
119 }
120
121 LIBEXPORT short converttocmap(struct ImBuf* ibuf)
122 {
123         return IMB_converttocmap(ibuf);
124 }
125
126 LIBEXPORT short saveiff(struct ImBuf *ib,
127                           char *c,
128                           int i)
129 {
130         return IMB_saveiff(ib, c, i);
131 }
132
133 LIBEXPORT struct ImBuf *loadiffmem(int *mem,int flags)
134 {
135         return IMB_loadiffmem(mem, flags);
136 }
137         
138 LIBEXPORT struct ImBuf *loadifffile(int a,
139                                                   int b)
140 {
141         return IMB_loadifffile(a, b);
142 }
143
144 LIBEXPORT struct ImBuf *loadiffname(char *n,
145                                                   int flags)
146 {
147         return IMB_loadiffname(n, flags);
148 }
149         
150 LIBEXPORT struct ImBuf *testiffname(char *n,
151                                                   int flags)
152 {
153         return IMB_testiffname(n, flags);
154 }
155
156 LIBEXPORT struct ImBuf *onehalf(struct ImBuf *ib)
157 {
158         return IMB_onehalf(ib);
159 }
160
161 LIBEXPORT struct ImBuf *onethird(struct ImBuf *ib)
162 {
163         return IMB_onethird(ib);
164 }
165
166 LIBEXPORT struct ImBuf *halflace(struct ImBuf *ib)
167 {
168         return IMB_halflace(ib);
169 }
170
171 LIBEXPORT struct ImBuf *half_x(struct ImBuf *ib)
172 {
173         return IMB_half_x(ib);
174 }
175
176 LIBEXPORT struct ImBuf *half_y(struct ImBuf *ib)
177 {
178         return IMB_half_y(ib);
179 }
180
181 LIBEXPORT struct ImBuf *double_x(struct ImBuf *ib)
182 {
183         return IMB_double_x(ib);
184 }
185
186 LIBEXPORT struct ImBuf *double_y(struct ImBuf *ib)
187 {
188         return IMB_double_y(ib);
189 }
190
191 LIBEXPORT struct ImBuf *double_fast_x(struct ImBuf *ib)
192 {
193         return IMB_double_fast_x(ib);
194 }
195
196 LIBEXPORT struct ImBuf *double_fast_y(struct ImBuf *ib)
197 {
198         return IMB_double_fast_y(ib);
199 }
200
201 LIBEXPORT int ispic(char * name)
202 {
203         return IMB_ispic(name);
204 }
205
206 LIBEXPORT void dit2(struct ImBuf *ib,
207                    short a,
208                    short b)
209 {
210         IMB_dit2(ib, a, b);
211 }
212
213 LIBEXPORT void dit0(struct ImBuf *ib,
214                    short a,
215                    short b)
216 {
217         IMB_dit0(ib, a, b);
218 }
219
220 /* still the same name */
221 /*  void (*ditherfunc)(struct ImBuf *, short, short){} */
222
223 LIBEXPORT struct ImBuf *scaleImBuf(struct ImBuf *ib,
224                                                  short nx,
225                                                  short ny)
226 {
227         return IMB_scaleImBuf(ib, nx, ny);
228 }
229
230 LIBEXPORT struct ImBuf *scalefastImBuf(struct ImBuf *ib,
231                                                          short x,
232                                                          short y)
233 {
234         return IMB_scalefastImBuf(ib, x, y);
235 }
236
237
238 LIBEXPORT struct ImBuf *scalefieldImBuf(struct ImBuf *ib,
239                                                           short x,
240                                                           short y)
241 {
242         return IMB_scalefieldImBuf(ib, x, y);
243 }
244
245 LIBEXPORT struct ImBuf *scalefastfieldImBuf(struct ImBuf *ib,
246                                                                   short x,
247                                                                   short y)
248 {
249         return IMB_scalefastfieldImBuf(ib, x, y);
250 }
251
252         /* Extra ones that some NaN (read Ton) plugins use,
253          * even though they aren't in the header
254          */
255
256 LIBEXPORT void interlace(struct ImBuf *ibuf)
257 {
258         IMB_interlace(ibuf);
259 }
260
261 LIBEXPORT void gamwarp(struct ImBuf *ibuf, double gamma)
262 {
263         IMB_gamwarp(ibuf,gamma);
264 }
265          
266 LIBEXPORT void de_interlace(struct ImBuf *ib)
267 {
268         IMB_de_interlace(ib);
269 }
270
271 /* -------------------------------------------------------------------------- */
272 /* stuff from plugin.h                                                        */ 
273 /* -------------------------------------------------------------------------- */
274
275 /* These three need to be defined in the plugion itself. The plugin
276  * loader looks for these functions to check whether it can use the
277  * plugin. For sequences, something similar exists. */
278 /*  int plugin_tex_getversion(void); */
279 /*  int plugin_seq_getversion(void); */
280 /*  void plugin_getinfo(PluginInfo *); */
281
282 LIBEXPORT float hnoise(float noisesize,
283                          float x,
284                          float y,
285                          float z)
286 {
287         return BLI_hnoise(noisesize, x, y, z);
288 }
289
290 LIBEXPORT float hnoisep(float noisesize,
291                           float x,
292                           float y,
293                           float z)
294 {
295         return BLI_hnoisep(noisesize, x, y, z);
296 }
297
298 LIBEXPORT float turbulence(float noisesize,
299                                  float x,
300                                  float y,
301                                  float z,
302                                  int depth)
303 {
304         return BLI_turbulence(noisesize, x, y, z, depth);
305 }
306
307 LIBEXPORT float turbulence1(float noisesize,
308                                   float x,
309                                   float y,
310                                   float z,
311                                   int depth)
312 {
313         return BLI_turbulence1(noisesize, x, y, z, depth);
314 }
315
316 /* -------------------------------------------------------------------------- */
317
318         /* Stupid hack - force the inclusion of all of the
319          * above functions in the binary by 'using' each one...
320          * Otherwise they will not be imported from the archive
321          * library on Unix. -zr
322          */
323 int pluginapi_force_ref(void); 
324
325 int pluginapi_force_ref(void) 
326 {
327         return 
328                 GET_INT_FROM_POINTER( mallocN ) +
329                 GET_INT_FROM_POINTER( callocN ) +
330                 GET_INT_FROM_POINTER( freeN ) +
331                 GET_INT_FROM_POINTER( mallocT ) +
332                 GET_INT_FROM_POINTER( callocT ) +
333                 GET_INT_FROM_POINTER( freeT ) +
334                 GET_INT_FROM_POINTER( allocImBuf ) +
335                 GET_INT_FROM_POINTER( dupImBuf ) +
336                 GET_INT_FROM_POINTER( freeImBuf ) +
337                 GET_INT_FROM_POINTER( converttocmap ) +
338                 GET_INT_FROM_POINTER( saveiff ) +
339                 GET_INT_FROM_POINTER( loadiffmem ) +
340                 GET_INT_FROM_POINTER( loadifffile ) +
341                 GET_INT_FROM_POINTER( loadiffname ) +
342                 GET_INT_FROM_POINTER( testiffname ) +
343                 GET_INT_FROM_POINTER( onehalf ) +
344                 GET_INT_FROM_POINTER( onethird ) +
345                 GET_INT_FROM_POINTER( halflace ) +
346                 GET_INT_FROM_POINTER( half_x ) +
347                 GET_INT_FROM_POINTER( half_y ) +
348                 GET_INT_FROM_POINTER( double_x ) +
349                 GET_INT_FROM_POINTER( double_y ) +
350                 GET_INT_FROM_POINTER( double_fast_x ) +
351                 GET_INT_FROM_POINTER( double_fast_y ) +
352                 GET_INT_FROM_POINTER( ispic ) +
353                 GET_INT_FROM_POINTER( dit2 ) +
354                 GET_INT_FROM_POINTER( dit0 ) +
355                 GET_INT_FROM_POINTER( scaleImBuf ) +
356                 GET_INT_FROM_POINTER( scalefastImBuf ) +
357                 GET_INT_FROM_POINTER( scalefieldImBuf ) +
358                 GET_INT_FROM_POINTER( scalefastfieldImBuf ) +
359                 GET_INT_FROM_POINTER( hnoise ) +
360                 GET_INT_FROM_POINTER( hnoisep ) +
361                 GET_INT_FROM_POINTER( turbulence ) +
362                 GET_INT_FROM_POINTER( turbulence1 ) +
363                 GET_INT_FROM_POINTER( de_interlace ) +
364                 GET_INT_FROM_POINTER( interlace ) +
365                 GET_INT_FROM_POINTER( gamwarp );
366 }