Blender  V2.59
pluginapi.c
Go to the documentation of this file.
00001 /*
00002  * $Id: pluginapi.c 35244 2011-02-27 20:32:12Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  * Wrappers for the plugin api. This api is up for removal.
00029  */
00030 
00036 /* There are four headers making up the plugin api:
00037  * - floatpatch.h : Wraps math functions for mips platforms, no code
00038  *                  required.
00039  * - iff.h        : Defines, macros and functions for dealing
00040  *                  with image buffer things.
00041  * - plugin.h     : Wraps some plugin handling types, accesses noise
00042  *                  functions.
00043  * - util.h       : Useful defines, memory management.
00044  */
00045 
00046 #define PLUGIN_INTERN /* This tells the LIBEXPORT macro to compile with
00047         dll export set on windows */
00048 
00049 #ifdef WIN32
00050 #include "blenpluginapi/util.h"
00051 #else
00052 #include "blenpluginapi/util.h"
00053 #endif
00054 #include "iff.h"
00055 #include "plugin.h"
00056 #include "MEM_guardedalloc.h"
00057 
00058 #include "BLO_sys_types.h" // needed for intptr_t
00059 
00060 #include "BLI_blenlib.h"  /* util and noise functions */
00061 #include "BLI_threads.h"  /* For threadsfe guardedalloc malloc/calloc/free */
00062 #include "IMB_imbuf.h"    /* image buffer stuff       */
00063 #define GET_INT_FROM_POINTER(i) ((int)(intptr_t)(i)) /* should use BKE_utildefines.h */
00064 
00065 /* -------------------------------------------------------------------------- */
00066 /* stuff from util.h                                                          */ 
00067 /* -------------------------------------------------------------------------- */
00068 
00069 LIBEXPORT void *mallocN(int len, char *str)
00070 {
00071         return MEM_mallocN(len, str);
00072 }
00073 
00074 LIBEXPORT void *callocN(int len, char *str)
00075 {
00076         return MEM_callocN(len, str);
00077 }
00078 
00079 LIBEXPORT short freeN(void *vmemh)
00080 {
00081         return MEM_freeN(vmemh);
00082 }
00083 
00084 /* these are not needed anymore, mallocN/callocN/freeN is now threadsafe */
00085 LIBEXPORT void *mallocT(int len, char *str)
00086 {
00087         return MEM_mallocN(len, str);
00088 }
00089 
00090 LIBEXPORT void *callocT(int len, char *str)
00091 {
00092         return MEM_callocN(len, str);
00093 }
00094 
00095 LIBEXPORT void freeT(void *vmemh)
00096 {
00097         MEM_freeN(vmemh);
00098         return;
00099 }
00100 
00101 
00102 /* -------------------------------------------------------------------------- */
00103 /* stuff from iff.h                                                           */ 
00104 /* -------------------------------------------------------------------------- */
00105 
00106 LIBEXPORT struct ImBuf *allocImBuf(short x,
00107                                                  short y,
00108                                                  uchar d,
00109                                                  uint flags)
00110 {
00111         return IMB_allocImBuf(x, y, d, flags);
00112 }
00113 
00114 
00115 LIBEXPORT struct ImBuf *dupImBuf(struct ImBuf *ib)
00116 {
00117         return IMB_dupImBuf(ib);
00118 }
00119         
00120 LIBEXPORT void freeImBuf(struct ImBuf* ib)
00121 {
00122         IMB_freeImBuf(ib);
00123 }
00124 
00125 LIBEXPORT short saveiff(struct ImBuf *ib,
00126                           char *c,
00127                           int i)
00128 {
00129         return IMB_saveiff(ib, c, i);
00130 }
00131 
00132 LIBEXPORT struct ImBuf *loadifffile(int a,
00133                                                   int b)
00134 {
00135         return IMB_loadifffile(a, b);
00136 }
00137 
00138 LIBEXPORT struct ImBuf *loadiffname(char *n,
00139                                                   int flags)
00140 {
00141         return IMB_loadiffname(n, flags);
00142 }
00143         
00144 LIBEXPORT struct ImBuf *testiffname(char *n,
00145                                                   int flags)
00146 {
00147         return IMB_testiffname(n, flags);
00148 }
00149 
00150 LIBEXPORT struct ImBuf *onehalf(struct ImBuf *ib)
00151 {
00152         return IMB_onehalf(ib);
00153 }
00154 
00155 LIBEXPORT struct ImBuf *half_x(struct ImBuf *ib)
00156 {
00157         return IMB_half_x(ib);
00158 }
00159 
00160 LIBEXPORT struct ImBuf *half_y(struct ImBuf *ib)
00161 {
00162         return IMB_half_y(ib);
00163 }
00164 
00165 LIBEXPORT struct ImBuf *double_x(struct ImBuf *ib)
00166 {
00167         return IMB_double_x(ib);
00168 }
00169 
00170 LIBEXPORT struct ImBuf *double_y(struct ImBuf *ib)
00171 {
00172         return IMB_double_y(ib);
00173 }
00174 
00175 LIBEXPORT struct ImBuf *double_fast_x(struct ImBuf *ib)
00176 {
00177         return IMB_double_fast_x(ib);
00178 }
00179 
00180 LIBEXPORT struct ImBuf *double_fast_y(struct ImBuf *ib)
00181 {
00182         return IMB_double_fast_y(ib);
00183 }
00184 
00185 LIBEXPORT int ispic(char * name)
00186 {
00187         return IMB_ispic(name);
00188 }
00189 
00190 /* still the same name */
00191 /*  void (*ditherfunc)(struct ImBuf *, short, short){} */
00192 
00193 LIBEXPORT struct ImBuf *scaleImBuf(struct ImBuf *ib,
00194                                                  short nx,
00195                                                  short ny)
00196 {
00197         return IMB_scaleImBuf(ib, nx, ny);
00198 }
00199 
00200 LIBEXPORT struct ImBuf *scalefastImBuf(struct ImBuf *ib,
00201                                                          short x,
00202                                                          short y)
00203 {
00204         return IMB_scalefastImBuf(ib, x, y);
00205 }
00206 
00207         /* Extra ones that some NaN (read Ton) plugins use,
00208          * even though they aren't in the header
00209          */
00210 
00211 LIBEXPORT void interlace(struct ImBuf *ibuf)
00212 {
00213         IMB_interlace(ibuf);
00214 }
00215 
00216 LIBEXPORT void de_interlace(struct ImBuf *ib)
00217 {
00218         IMB_de_interlace(ib);
00219 }
00220 
00221 /* -------------------------------------------------------------------------- */
00222 /* stuff from plugin.h                                                        */ 
00223 /* -------------------------------------------------------------------------- */
00224 
00225 /* These three need to be defined in the plugion itself. The plugin
00226  * loader looks for these functions to check whether it can use the
00227  * plugin. For sequences, something similar exists. */
00228 /*  int plugin_tex_getversion(void); */
00229 /*  int plugin_seq_getversion(void); */
00230 /*  void plugin_getinfo(PluginInfo *); */
00231 
00232 LIBEXPORT float hnoise(float noisesize,
00233                          float x,
00234                          float y,
00235                          float z)
00236 {
00237         return BLI_hnoise(noisesize, x, y, z);
00238 }
00239 
00240 LIBEXPORT float hnoisep(float noisesize,
00241                           float x,
00242                           float y,
00243                           float z)
00244 {
00245         return BLI_hnoisep(noisesize, x, y, z);
00246 }
00247 
00248 LIBEXPORT float turbulence(float noisesize,
00249                                  float x,
00250                                  float y,
00251                                  float z,
00252                                  int depth)
00253 {
00254         return BLI_turbulence(noisesize, x, y, z, depth);
00255 }
00256 
00257 LIBEXPORT float turbulence1(float noisesize,
00258                                   float x,
00259                                   float y,
00260                                   float z,
00261                                   int depth)
00262 {
00263         return BLI_turbulence1(noisesize, x, y, z, depth);
00264 }
00265 
00266 /* -------------------------------------------------------------------------- */
00267 
00268         /* Stupid hack - force the inclusion of all of the
00269          * above functions in the binary by 'using' each one...
00270          * Otherwise they will not be imported from the archive
00271          * library on Unix. -zr
00272          */
00273 int pluginapi_force_ref(void); 
00274 
00275 int pluginapi_force_ref(void) 
00276 {
00277         return 
00278                 GET_INT_FROM_POINTER( mallocN ) +
00279                 GET_INT_FROM_POINTER( callocN ) +
00280                 GET_INT_FROM_POINTER( freeN ) +
00281                 GET_INT_FROM_POINTER( mallocT ) +
00282                 GET_INT_FROM_POINTER( callocT ) +
00283                 GET_INT_FROM_POINTER( freeT ) +
00284                 GET_INT_FROM_POINTER( allocImBuf ) +
00285                 GET_INT_FROM_POINTER( dupImBuf ) +
00286                 GET_INT_FROM_POINTER( freeImBuf ) +
00287                 GET_INT_FROM_POINTER( saveiff ) +
00288                 GET_INT_FROM_POINTER( loadifffile ) +
00289                 GET_INT_FROM_POINTER( loadiffname ) +
00290                 GET_INT_FROM_POINTER( testiffname ) +
00291                 GET_INT_FROM_POINTER( onehalf ) +
00292                 GET_INT_FROM_POINTER( half_x ) +
00293                 GET_INT_FROM_POINTER( half_y ) +
00294                 GET_INT_FROM_POINTER( double_x ) +
00295                 GET_INT_FROM_POINTER( double_y ) +
00296                 GET_INT_FROM_POINTER( double_fast_x ) +
00297                 GET_INT_FROM_POINTER( double_fast_y ) +
00298                 GET_INT_FROM_POINTER( ispic ) +
00299                 GET_INT_FROM_POINTER( scaleImBuf ) +
00300                 GET_INT_FROM_POINTER( scalefastImBuf ) +
00301                 GET_INT_FROM_POINTER( hnoise ) +
00302                 GET_INT_FROM_POINTER( hnoisep ) +
00303                 GET_INT_FROM_POINTER( turbulence ) +
00304                 GET_INT_FROM_POINTER( turbulence1 ) +
00305                 GET_INT_FROM_POINTER( de_interlace ) +
00306                 GET_INT_FROM_POINTER( interlace );
00307 }