gdevdsp.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /* Copyright (C) 2001-2005, Ghostgum Software Pty Ltd. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: gdevdsp.h,v 1.12 2005/03/04 22:00:22 ghostgum Exp $ */
  14. /* gdevdsp.h - callback structure for DLL based display device */
  15. #ifndef gdevdsp_INCLUDED
  16. # define gdevdsp_INCLUDED
  17. /*
  18. * The callback structure must be provided by calling the
  19. * Ghostscript APIs in the following order:
  20. * gsapi_new_instance(&minst);
  21. * gsapi_set_display_callback(minst, callback);
  22. * gsapi_init_with_args(minst, argc, argv);
  23. *
  24. * Supported parameters and default values are:
  25. * -sDisplayHandle=16#04d2 or 1234 string
  26. * Caller supplied handle as a decimal or hexadecimal number
  27. * in a string. On 32-bit platforms, it may be set
  28. * using -dDisplayHandle=1234 for backward compatibility.
  29. * Included as first parameter of all callback functions.
  30. *
  31. * -dDisplayFormat=0 long
  32. * Color format specified using bitfields below.
  33. * Included as argument of display_size() and display_presize()
  34. * These can only be changed when the device is closed.
  35. *
  36. * The second parameter of all callback functions "void *device"
  37. * is the address of the Ghostscript display device instance.
  38. * The arguments "void *handle" and "void *device" together
  39. * uniquely identify an instance of the display device.
  40. *
  41. * A typical sequence of callbacks would be
  42. * open, presize, memalloc, size, sync, page
  43. * presize, memfree, memalloc, size, sync, page
  44. * preclose, memfree, close
  45. * The caller should not access the image buffer:
  46. * - before the first sync
  47. * - between presize and size
  48. * - after preclose
  49. * If opening the device fails, you might see the following:
  50. * open, presize, memalloc, memfree, close
  51. *
  52. */
  53. #define DISPLAY_VERSION_MAJOR 2
  54. #define DISPLAY_VERSION_MINOR 0
  55. #define DISPLAY_VERSION_MAJOR_V1 1 /* before separation format was added */
  56. #define DISPLAY_VERSION_MINOR_V1 0
  57. /* The display format is set by a combination of the following bitfields */
  58. /* Define the color space alternatives */
  59. typedef enum {
  60. DISPLAY_COLORS_NATIVE = (1<<0),
  61. DISPLAY_COLORS_GRAY = (1<<1),
  62. DISPLAY_COLORS_RGB = (1<<2),
  63. DISPLAY_COLORS_CMYK = (1<<3),
  64. DISPLAY_COLORS_SEPARATION = (1<<19)
  65. } DISPLAY_FORMAT_COLOR;
  66. #define DISPLAY_COLORS_MASK 0x8000fL
  67. /* Define whether alpha information, or an extra unused bytes is included */
  68. /* DISPLAY_ALPHA_FIRST and DISPLAY_ALPHA_LAST are not implemented */
  69. typedef enum {
  70. DISPLAY_ALPHA_NONE = (0<<4),
  71. DISPLAY_ALPHA_FIRST = (1<<4),
  72. DISPLAY_ALPHA_LAST = (1<<5),
  73. DISPLAY_UNUSED_FIRST = (1<<6), /* e.g. Mac xRGB */
  74. DISPLAY_UNUSED_LAST = (1<<7) /* e.g. Windows BGRx */
  75. } DISPLAY_FORMAT_ALPHA;
  76. #define DISPLAY_ALPHA_MASK 0x00f0L
  77. /* Define the depth per component for DISPLAY_COLORS_GRAY,
  78. * DISPLAY_COLORS_RGB and DISPLAY_COLORS_CMYK,
  79. * or the depth per pixel for DISPLAY_COLORS_NATIVE
  80. * DISPLAY_DEPTH_2 and DISPLAY_DEPTH_12 have not been tested.
  81. */
  82. typedef enum {
  83. DISPLAY_DEPTH_1 = (1<<8),
  84. DISPLAY_DEPTH_2 = (1<<9),
  85. DISPLAY_DEPTH_4 = (1<<10),
  86. DISPLAY_DEPTH_8 = (1<<11),
  87. DISPLAY_DEPTH_12 = (1<<12),
  88. DISPLAY_DEPTH_16 = (1<<13)
  89. /* unused (1<<14) */
  90. /* unused (1<<15) */
  91. } DISPLAY_FORMAT_DEPTH;
  92. #define DISPLAY_DEPTH_MASK 0xff00L
  93. /* Define whether Red/Cyan should come first,
  94. * or whether Blue/Black should come first
  95. */
  96. typedef enum {
  97. DISPLAY_BIGENDIAN = (0<<16), /* Red/Cyan first */
  98. DISPLAY_LITTLEENDIAN = (1<<16) /* Blue/Black first */
  99. } DISPLAY_FORMAT_ENDIAN;
  100. #define DISPLAY_ENDIAN_MASK 0x00010000L
  101. /* Define whether the raster starts at the top or bottom of the bitmap */
  102. typedef enum {
  103. DISPLAY_TOPFIRST = (0<<17), /* Unix, Mac */
  104. DISPLAY_BOTTOMFIRST = (1<<17) /* Windows */
  105. } DISPLAY_FORMAT_FIRSTROW;
  106. #define DISPLAY_FIRSTROW_MASK 0x00020000L
  107. /* Define whether packing RGB in 16-bits should use 555
  108. * or 565 (extra bit for green)
  109. */
  110. typedef enum {
  111. DISPLAY_NATIVE_555 = (0<<18),
  112. DISPLAY_NATIVE_565 = (1<<18)
  113. } DISPLAY_FORMAT_555;
  114. #define DISPLAY_555_MASK 0x00040000L
  115. /* Define the row alignment, which must be equal to or greater than
  116. * the size of a pointer.
  117. * The default (DISPLAY_ROW_ALIGN_DEFAULT) is the size of a pointer,
  118. * 4 bytes (DISPLAY_ROW_ALIGN_4) on 32-bit systems or 8 bytes
  119. * (DISPLAY_ROW_ALIGN_8) on 64-bit systems.
  120. */
  121. typedef enum {
  122. DISPLAY_ROW_ALIGN_DEFAULT = (0<<20),
  123. /* DISPLAY_ROW_ALIGN_1 = (1<<20), */ /* not currently possible */
  124. /* DISPLAY_ROW_ALIGN_2 = (2<<20), */ /* not currently possible */
  125. DISPLAY_ROW_ALIGN_4 = (3<<20),
  126. DISPLAY_ROW_ALIGN_8 = (4<<20),
  127. DISPLAY_ROW_ALIGN_16 = (5<<20),
  128. DISPLAY_ROW_ALIGN_32 = (6<<20),
  129. DISPLAY_ROW_ALIGN_64 = (7<<20)
  130. } DISPLAY_FORMAT_ROW_ALIGN;
  131. #define DISPLAY_ROW_ALIGN_MASK 0x00700000L
  132. #ifndef display_callback_DEFINED
  133. #define display_callback_DEFINED
  134. typedef struct display_callback_s display_callback;
  135. #endif
  136. /*
  137. * Note that for Windows, the display callback functions are
  138. * cdecl, not stdcall. This differs from those in iapi.h.
  139. */
  140. struct display_callback_s {
  141. /* Size of this structure */
  142. /* Used for checking if we have been handed a valid structure */
  143. int size;
  144. /* Major version of this structure */
  145. /* The major version number will change if this structure changes. */
  146. int version_major;
  147. /* Minor version of this structure */
  148. /* The minor version number will change if new features are added
  149. * without changes to this structure. For example, a new color
  150. * format.
  151. */
  152. int version_minor;
  153. /* New device has been opened */
  154. /* This is the first event from this device. */
  155. int (*display_open)(void *handle, void *device);
  156. /* Device is about to be closed. */
  157. /* Device will not be closed until this function returns. */
  158. int (*display_preclose)(void *handle, void *device);
  159. /* Device has been closed. */
  160. /* This is the last event from this device. */
  161. int (*display_close)(void *handle, void *device);
  162. /* Device is about to be resized. */
  163. /* Resize will only occur if this function returns 0. */
  164. /* raster is byte count of a row. */
  165. int (*display_presize)(void *handle, void *device,
  166. int width, int height, int raster, unsigned int format);
  167. /* Device has been resized. */
  168. /* New pointer to raster returned in pimage */
  169. int (*display_size)(void *handle, void *device, int width, int height,
  170. int raster, unsigned int format, unsigned char *pimage);
  171. /* flushpage */
  172. int (*display_sync)(void *handle, void *device);
  173. /* showpage */
  174. /* If you want to pause on showpage, then don't return immediately */
  175. int (*display_page)(void *handle, void *device, int copies, int flush);
  176. /* Notify the caller whenever a portion of the raster is updated. */
  177. /* This can be used for cooperative multitasking or for
  178. * progressive update of the display.
  179. * This function pointer may be set to NULL if not required.
  180. */
  181. int (*display_update)(void *handle, void *device, int x, int y,
  182. int w, int h);
  183. /* Allocate memory for bitmap */
  184. /* This is provided in case you need to create memory in a special
  185. * way, e.g. shared. If this is NULL, the Ghostscript memory device
  186. * allocates the bitmap. This will only called to allocate the
  187. * image buffer. The first row will be placed at the address
  188. * returned by display_memalloc.
  189. */
  190. void *(*display_memalloc)(void *handle, void *device, unsigned long size);
  191. /* Free memory for bitmap */
  192. /* If this is NULL, the Ghostscript memory device will free the bitmap */
  193. int (*display_memfree)(void *handle, void *device, void *mem);
  194. /* Added in V2 */
  195. /* When using separation color space (DISPLAY_COLORS_SEPARATION),
  196. * give a mapping for one separation component.
  197. * This is called for each new component found.
  198. * It may be called multiple times for each component.
  199. * It may be called at any time between display_size
  200. * and display_close.
  201. * The client uses this to map from the separations to CMYK
  202. * and hence to RGB for display.
  203. * GS must only use this callback if version_major >= 2.
  204. * The unsigned short c,m,y,k values are 65535 = 1.0.
  205. * This function pointer may be set to NULL if not required.
  206. */
  207. int (*display_separation)(void *handle, void *device,
  208. int component, const char *component_name,
  209. unsigned short c, unsigned short m,
  210. unsigned short y, unsigned short k);
  211. };
  212. /* This is the V1 structure, before separation format was added */
  213. struct display_callback_v1_s {
  214. int size;
  215. int version_major;
  216. int version_minor;
  217. int (*display_open)(void *handle, void *device);
  218. int (*display_preclose)(void *handle, void *device);
  219. int (*display_close)(void *handle, void *device);
  220. int (*display_presize)(void *handle, void *device,
  221. int width, int height, int raster, unsigned int format);
  222. int (*display_size)(void *handle, void *device, int width, int height,
  223. int raster, unsigned int format, unsigned char *pimage);
  224. int (*display_sync)(void *handle, void *device);
  225. int (*display_page)(void *handle, void *device, int copies, int flush);
  226. int (*display_update)(void *handle, void *device, int x, int y,
  227. int w, int h);
  228. void *(*display_memalloc)(void *handle, void *device, unsigned long size);
  229. int (*display_memfree)(void *handle, void *device, void *mem);
  230. };
  231. #define DISPLAY_CALLBACK_V1_SIZEOF sizeof(struct display_callback_v1_s)
  232. #endif /* gdevdsp_INCLUDED */