1 /* VIPS function dispatch. 2 * 3 * J. Cupitt, 8/4/93. 4 */ 5 6 /* 7 8 This file is part of VIPS. 9 10 VIPS is free software; you can redistribute it and/or modify 11 it under the terms of the GNU Lesser General Public License as published by 12 the Free Software Foundation; either version 2 of the License, or 13 (at your option) any later version. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU Lesser General Public License for more details. 19 20 You should have received a copy of the GNU Lesser General Public License 21 along with this program; if not, write to the Free Software 22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 02110-1301 USA 24 25 */ 26 27 /* 28 29 These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk 30 31 */ 32 33 #ifndef IM_DISPATCH_H 34 #define IM_DISPATCH_H 35 36 #include <glib-object.h> 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif /*__cplusplus*/ 41 42 #include <vips/vips.h> 43 #include <vips/util.h> 44 45 /* Type names. You may define your own, but if you use one of these, then 46 * you should use the built-in VIPS type converters. 47 */ 48 #define IM_TYPE_IMAGEVEC "imagevec" /* im_object is ptr to IMAGE[] */ 49 #define IM_TYPE_DOUBLEVEC "doublevec" /* im_object is ptr to double[] */ 50 #define IM_TYPE_INTVEC "intvec" /* im_object is ptr to int[] */ 51 #define IM_TYPE_DOUBLE "double" /* im_object is ptr to double */ 52 #define IM_TYPE_INT "integer" /* 32-bit integer */ 53 #define IM_TYPE_COMPLEX "complex" /* Pair of doubles */ 54 #define IM_TYPE_STRING "string" /* Zero-terminated char array */ 55 #define IM_TYPE_IMASK "intmask" /* Integer mask type */ 56 #define IM_TYPE_DMASK "doublemask" /* Double mask type */ 57 #define IM_TYPE_IMAGE "image" /* IMAGE descriptor */ 58 #define IM_TYPE_DISPLAY "display" /* Display descriptor */ 59 #define IM_TYPE_GVALUE "gvalue" /* GValue wrapper */ 60 #define IM_TYPE_INTERPOLATE "interpolate"/* A subclass of VipsInterpolate */ 61 typedef char *im_arg_type; /* Type of argument id */ 62 63 /* Internal representation of an argument to an image processing function. 64 */ 65 typedef void *im_object; 66 67 /* These bits are ored together to make the flags in a type descriptor. 68 * 69 * IM_TYPE_OUTPUT: set to indicate output, otherwise input. If the IM_TYPE_RW 70 * bit is set and IM_TYPE_OUTPUT is not set, both input and output (ie. the 71 * operation side-effects this argument). 72 * 73 * IM_TYPE_ARG: Two ways of making an im_object --- with and without a 74 * command-line string to help you along. Arguments with a string are thing 75 * like IMAGE descriptors, which require a filename to initialise. 76 * Arguments without are things like output numbers, where making the object 77 * simply involves allocating storage. 78 */ 79 typedef enum { 80 IM_TYPE_NONE = 0, /* No flags */ 81 IM_TYPE_OUTPUT = 0x1, /* Output/input object */ 82 IM_TYPE_ARG = 0x2, /* Uses a str arg in construction */ 83 IM_TYPE_RW = 0x4 /* Read-write */ 84 } im_type_flags; 85 86 /* Initialise, destroy and write objects. The "str" argument to the 87 * init function will not be supplied if this is not an ARG type. The 88 * write function writes to the GString. 89 */ 90 typedef int (*im_init_obj_fn)( im_object *obj, char *str ); 91 typedef int (*im_dest_obj_fn)( im_object obj ); 92 93 /* Describe a VIPS type. 94 */ 95 typedef struct { 96 im_arg_type type; /* Type of argument */ 97 int size; /* sizeof( im_object repres. ) */ 98 im_type_flags flags; /* Flags */ 99 im_init_obj_fn init; /* Operation functions */ 100 im_dest_obj_fn dest; /* Destroy object */ 101 } im_type_desc; 102 103 /* Success on an argument. This is called if the image processing function 104 * succeeds and should be used to (for example) print output. 105 */ 106 typedef int (*im_print_obj_fn)( im_object obj ); 107 108 /* Describe a VIPS command argument. 109 */ 110 typedef struct { 111 char *name; /* eg. "width" */ 112 im_type_desc *desc; /* Type description */ 113 im_print_obj_fn print; /* Print some output objects */ 114 } im_arg_desc; 115 116 /* Type of VIPS dispatch funtion. 117 */ 118 typedef int (*im_dispatch_fn)( im_object *argv ); 119 120 /* Maximum size of arg table. 121 */ 122 #define IM_MAX_ARGS (1000) 123 124 /* Flags for functions. These are for information only, and more may be 125 * added. 126 */ 127 typedef enum { 128 IM_FN_NONE = 0, /* No flags set */ 129 IM_FN_PIO = 0x1, /* Is a partial function */ 130 IM_FN_TRANSFORM = 0x2, /* Performs coordinate transformations */ 131 IM_FN_PTOP = 0x4, /* Point-to-point ... can be done with a LUT */ 132 IM_FN_NOCACHE = 0x8 /* Result should not be cached */ 133 } im_fn_flags; 134 135 /* Describe a VIPS function. 136 */ 137 typedef struct { 138 char *name; /* eg "im_invert" */ 139 char *desc; /* Description - eg "photographic negative" */ 140 im_fn_flags flags; /* Flags for this function */ 141 im_dispatch_fn disp; /* Dispatch */ 142 int argc; /* Number of args */ 143 im_arg_desc *argv; /* Arg table */ 144 } im_function; 145 146 /* A set of VIPS functions forming a package. 147 */ 148 typedef struct { 149 char *name; /* Package name (eg "arithmetic") */ 150 int nfuncs; /* Number of functions in package */ 151 im_function **table; /* Array of function descriptors */ 152 } im_package; 153 154 /* Externs for dispatch. 155 */ 156 157 /* Struct for mask IO to a file. 158 */ 159 typedef struct { 160 char *name; /* Command-line name in */ 161 void *mask; /* Mask --- DOUBLE or INT */ 162 } im_mask_object; 163 164 /* Struct for doublevec IO 165 */ 166 typedef struct { 167 int n; /* Vector length */ 168 double *vec; /* Vector */ 169 } im_doublevec_object; 170 171 /* Struct for intvec IO 172 */ 173 typedef struct { 174 int n; /* Vector length */ 175 int *vec; /* Vector */ 176 } im_intvec_object; 177 178 /* Struct for imagevec IO 179 */ 180 typedef struct { 181 int n; /* Vector length */ 182 IMAGE **vec; /* Vector */ 183 } im_imagevec_object; 184 185 /* Built-in VIPS types. 186 */ 187 extern im_type_desc im__input_int; 188 extern im_type_desc im__input_intvec; 189 extern im_type_desc im__input_imask; 190 extern im_type_desc im__output_int; 191 extern im_type_desc im__output_intvec; 192 extern im_type_desc im__output_imask; 193 194 extern im_type_desc im__input_double; 195 extern im_type_desc im__input_doublevec; 196 extern im_type_desc im__input_dmask; 197 extern im_type_desc im__output_double; 198 extern im_type_desc im__output_doublevec; 199 extern im_type_desc im__output_dmask; 200 extern im_type_desc im__output_dmask_screen; 201 202 extern im_type_desc im__output_complex; 203 204 extern im_type_desc im__input_string; 205 extern im_type_desc im__output_string; 206 207 extern im_type_desc im__input_imagevec; 208 extern im_type_desc im__input_image; 209 extern im_type_desc im__output_image; 210 extern im_type_desc im__rw_image; 211 212 extern im_type_desc im__input_display; 213 extern im_type_desc im__output_display; 214 215 extern im_type_desc im__input_gvalue; 216 extern im_type_desc im__output_gvalue; 217 218 extern im_type_desc im__input_interpolate; 219 220 /* VIPS print functions. 221 */ 222 int im__iprint( im_object obj ); /* int */ 223 int im__ivprint( im_object obj ); /* intvec */ 224 int im__dprint( im_object obj ); /* double */ 225 int im__dvprint( im_object obj ); /* doublevec */ 226 int im__dmsprint( im_object obj ); /* DOUBLEMASK as stats */ 227 int im__cprint( im_object obj ); /* complex */ 228 int im__sprint( im_object obj ); /* string */ 229 int im__displayprint( im_object obj ); /* im_col_display */ 230 int im__gprint( im_object obj ); /* GValue */ 231 232 /* Macros for convenient creation. 233 */ 234 #define IM_INPUT_INT( S ) { S, &im__input_int, NULL } 235 #define IM_INPUT_INTVEC( S ) { S, &im__input_intvec, NULL } 236 #define IM_INPUT_IMASK( S ) { S, &im__input_imask, NULL } 237 #define IM_OUTPUT_INT( S ) { S, &im__output_int, im__iprint } 238 #define IM_OUTPUT_INTVEC( S ) { S, &im__output_intvec, im__ivprint } 239 #define IM_OUTPUT_IMASK( S ) { S, &im__output_imask, NULL } 240 241 #define IM_INPUT_DOUBLE( S ) { S, &im__input_double, NULL } 242 #define IM_INPUT_DOUBLEVEC( S ) { S, &im__input_doublevec, NULL } 243 #define IM_INPUT_DMASK( S ) { S, &im__input_dmask, NULL } 244 #define IM_OUTPUT_DOUBLE( S ) { S, &im__output_double, im__dprint } 245 #define IM_OUTPUT_DOUBLEVEC( S ) { S, &im__output_doublevec, im__dvprint } 246 #define IM_OUTPUT_DMASK( S ) { S, &im__output_dmask, NULL } 247 #define IM_OUTPUT_DMASK_STATS( S ) { S, &im__output_dmask_screen, im__dmsprint } 248 249 #define IM_OUTPUT_COMPLEX( S ) { S, &im__output_complex, im__cprint } 250 251 #define IM_INPUT_STRING( S ) { S, &im__input_string, NULL } 252 #define IM_OUTPUT_STRING( S ) { S, &im__output_string, im__sprint } 253 254 #define IM_INPUT_IMAGE( S ) { S, &im__input_image, NULL } 255 #define IM_INPUT_IMAGEVEC( S ) { S, &im__input_imagevec, NULL } 256 #define IM_OUTPUT_IMAGE( S ) { S, &im__output_image, NULL } 257 #define IM_RW_IMAGE( S ) { S, &im__rw_image, NULL } 258 259 #define IM_INPUT_DISPLAY( S ) { S, &im__input_display, NULL } 260 #define IM_OUTPUT_DISPLAY( S ) { S, &im__output_display, im__displayprint } 261 262 #define IM_INPUT_GVALUE( S ) { S, &im__input_gvalue, NULL } 263 #define IM_OUTPUT_GVALUE( S ) { S, &im__output_gvalue, im__gprint } 264 265 #define IM_INPUT_INTERPOLATE( S ) { S, &im__input_interpolate, NULL } 266 267 /* Add a plug-in package. 268 */ 269 im_package *im_load_plugin( const char *name ); 270 int im_load_plugins( const char *fmt, ... ) 271 __attribute__((format(printf, 1, 2))); 272 273 /* Close all plug-ins. 274 */ 275 int im_close_plugins( void ); 276 277 /* Loop over all loaded packages. 278 */ 279 void *im_map_packages( VipsSListMap2Fn fn, void *a ); 280 281 /* Convenience functions for finding packages, functions, etc. 282 */ 283 im_function *im_find_function( const char *name ); 284 im_package *im_find_package( const char *name ); 285 im_package *im_package_of_function( const char *name ); 286 287 /* Allocate space for, and free im_object argument lists. 288 */ 289 int im_free_vargv( im_function *fn, im_object *vargv ); 290 int im_allocate_vargv( im_function *fn, im_object *vargv ); 291 292 /* Run a VIPS command by name. 293 */ 294 int im_run_command( char *name, int argc, char **argv ); 295 296 int vips__input_interpolate_init( im_object *obj, char *str ); 297 298 #ifdef __cplusplus 299 } 300 #endif /*__cplusplus*/ 301 302 #endif /*IM_DISPATCH_H*/ 303