dispatch.h 9.6 KB

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