gxht.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /* Copyright (C) 1993, 1995, 1996, 1997, 1998 Aladdin Enterprises. 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: gxht.h,v 1.9 2004/08/04 19:36:12 stefan Exp $ */
  14. /* Rest of (client) halftone definitions */
  15. #ifndef gxht_INCLUDED
  16. # define gxht_INCLUDED
  17. #include "gsht1.h"
  18. #include "gsrefct.h"
  19. #include "gxhttype.h"
  20. #include "gxtmap.h"
  21. #include "gscspace.h"
  22. /*
  23. * Halftone types. Note that for this implementation there are only
  24. * spot functions, thresholds, and multi-component halftones; the peculiar
  25. * colored halftones supported by PostScript (HalftoneType's 2 and 4) are
  26. * not supported.
  27. *
  28. * NB1: While this code supports relocation of the client data, it will not
  29. * free that data when the halftone is released. The client must handle
  30. * that task directly.
  31. *
  32. * NB2: The garbage collection code will deal with the user provided data as
  33. * a structure pointer allocated on the heap. The client must make
  34. * certain this is the case.
  35. *
  36. * There is, somewhat unfortunately, no identifier applied to these
  37. * halftones. This reflects the origin of this graphics library as a set
  38. * of routines for use by a PostScript interpreter.
  39. *
  40. * In PostScript, halftone objects do not exist in an identified form outside
  41. * of the graphic state. Though Level 2 and PostScript 3 support halftone
  42. * dictionaries, these are neither read-only structures nor tagged
  43. * by a unique identifier. Hence, they are not suitable for use as cache keys.
  44. * Caching of halftones for PostScript is confined to the graphic state,
  45. * and this holds true for the graphic library as well.
  46. *
  47. * Note also that implementing a generalized halftone cache is not trivial,
  48. * as the device-specific representation of spot halftones depends on the
  49. * default transformation for the device, and more generally the device
  50. * specific representation of halftones may depend on the sense of the device
  51. * (additive or subtract). Hence, a halftone cache would need to be keyed
  52. * by device. (This is not an issue when caching halftones in the graphic
  53. * state as the device is also a component of the graphic state).
  54. */
  55. /*
  56. * Note that the transfer_closure members will replace transfer sometime
  57. * in the future. For the moment, transfer_closure is only used if
  58. * transfer = 0.
  59. */
  60. /* Type 1 halftone. This is just a Level 1 halftone with */
  61. /* a few extra members. */
  62. typedef struct gs_spot_halftone_s {
  63. gs_screen_halftone screen;
  64. bool accurate_screens;
  65. gs_mapping_proc transfer; /* OBSOLETE */
  66. gs_mapping_closure_t transfer_closure;
  67. } gs_spot_halftone;
  68. #define st_spot_halftone_max_ptrs st_screen_halftone_max_ptrs + 1
  69. /* Define common elements for Type 3 and extended Type 3 halftones. */
  70. #define GS_THRESHOLD_HALFTONE_COMMON\
  71. int width;\
  72. int height;\
  73. gs_mapping_closure_t transfer_closure
  74. typedef struct gs_threshold_halftone_common_s {
  75. GS_THRESHOLD_HALFTONE_COMMON;
  76. } gs_threshold_halftone_common;
  77. /* Type 3 halftone. */
  78. typedef struct gs_threshold_halftone_s {
  79. GS_THRESHOLD_HALFTONE_COMMON; /* must be first */
  80. gs_const_string thresholds;
  81. gs_mapping_proc transfer; /* OBSOLETE */
  82. } gs_threshold_halftone;
  83. #define st_threshold_halftone_max_ptrs 2
  84. /* Extended Type 3 halftone. */
  85. typedef struct gs_threshold2_halftone_s {
  86. GS_THRESHOLD_HALFTONE_COMMON; /* must be first */
  87. int width2;
  88. int height2;
  89. int bytes_per_sample; /* 1 or 2 */
  90. gs_const_bytestring thresholds; /* nota bene */
  91. } gs_threshold2_halftone;
  92. /* Client-defined halftone that generates a halftone order. */
  93. typedef struct gs_client_order_halftone_s gs_client_order_halftone;
  94. #ifndef gx_ht_order_DEFINED
  95. # define gx_ht_order_DEFINED
  96. typedef struct gx_ht_order_s gx_ht_order;
  97. #endif
  98. typedef struct gs_client_order_ht_procs_s {
  99. /*
  100. * Allocate and fill in the order. gx_ht_alloc_client_order
  101. * (see gzht.h) does everything but fill in the actual data.
  102. */
  103. int (*create_order) (gx_ht_order * porder,
  104. gs_state * pgs,
  105. const gs_client_order_halftone * phcop,
  106. gs_memory_t * mem);
  107. } gs_client_order_ht_procs_t;
  108. struct gs_client_order_halftone_s {
  109. int width;
  110. int height;
  111. int num_levels;
  112. const gs_client_order_ht_procs_t *procs;
  113. const void *client_data;
  114. gs_mapping_closure_t transfer_closure;
  115. };
  116. #define st_client_order_halftone_max_ptrs 2
  117. /* Define the elements of a Type 5 halftone. */
  118. typedef struct gs_halftone_component_s {
  119. int comp_number;
  120. int cname;
  121. gs_halftone_type type;
  122. union {
  123. gs_spot_halftone spot; /* Type 1 */
  124. gs_threshold_halftone threshold; /* Type 3 */
  125. gs_threshold2_halftone threshold2; /* Extended Type 3 */
  126. gs_client_order_halftone client_order; /* client order */
  127. } params;
  128. } gs_halftone_component;
  129. extern_st(st_halftone_component);
  130. #define public_st_halftone_component() /* in gsht1.c */\
  131. gs_public_st_composite(st_halftone_component, gs_halftone_component,\
  132. "gs_halftone_component", halftone_component_enum_ptrs,\
  133. halftone_component_reloc_ptrs)
  134. extern_st(st_ht_component_element);
  135. #define public_st_ht_component_element() /* in gsht1.c */\
  136. gs_public_st_element(st_ht_component_element, gs_halftone_component,\
  137. "gs_halftone_component[]", ht_comp_elt_enum_ptrs, ht_comp_elt_reloc_ptrs,\
  138. st_halftone_component)
  139. #define st_halftone_component_max_ptrs\
  140. max(max(st_spot_halftone_max_ptrs, st_threshold_halftone_max_ptrs),\
  141. st_client_order_halftone_max_ptrs)
  142. /* Define the Type 5 halftone itself. */
  143. typedef struct gs_multiple_halftone_s {
  144. gs_halftone_component *components;
  145. uint num_comp;
  146. int (*get_colorname_string)(const gs_memory_t *mem, gs_separation_name colorname_index,
  147. unsigned char **ppstr, unsigned int *pname_size);
  148. } gs_multiple_halftone;
  149. #define st_multiple_halftone_max_ptrs 1
  150. /*
  151. * The halftone stored in the graphics state is the union of
  152. * setscreen, setcolorscreen, Type 1, Type 3, and Type 5.
  153. *
  154. * NOTE: it is assumed that all subsidiary structures of halftones (the
  155. * threshold array(s) for Type 3 halftones or halftone components, and the
  156. * components array for Type 5 halftones) are allocated with the same
  157. * allocator as the halftone structure itself.
  158. */
  159. struct gs_halftone_s {
  160. gs_halftone_type type;
  161. rc_header rc;
  162. union {
  163. gs_screen_halftone screen; /* setscreen */
  164. gs_colorscreen_halftone colorscreen; /* setcolorscreen */
  165. gs_spot_halftone spot; /* Type 1 */
  166. gs_threshold_halftone threshold; /* Type 3 */
  167. gs_threshold2_halftone threshold2; /* Extended Type 3 */
  168. gs_client_order_halftone client_order; /* client order */
  169. gs_multiple_halftone multiple; /* Type 5 */
  170. } params;
  171. };
  172. extern_st(st_halftone);
  173. #define public_st_halftone() /* in gsht.c */\
  174. gs_public_st_composite(st_halftone, gs_halftone, "gs_halftone",\
  175. halftone_enum_ptrs, halftone_reloc_ptrs)
  176. #define st_halftone_max_ptrs\
  177. max(max(st_screen_halftone_max_ptrs, st_colorscreen_halftone_max_ptrs),\
  178. max(max(st_spot_halftone_max_ptrs, st_threshold_halftone_max_ptrs),\
  179. max(st_client_order_halftone_max_ptrs,\
  180. st_multiple_halftone_max_ptrs)))
  181. /* Procedural interface for AccurateScreens */
  182. /*
  183. * Set/get the default AccurateScreens value (for set[color]screen).
  184. * Note that this value is stored in a static variable.
  185. */
  186. void gs_setaccuratescreens(bool);
  187. bool gs_currentaccuratescreens(void);
  188. /*
  189. * Set/get the value for UseWTS. Also a static, but it's going away.
  190. */
  191. void gs_setusewts(bool);
  192. bool gs_currentusewts(void);
  193. /* Initiate screen sampling with optional AccurateScreens. */
  194. int gs_screen_init_memory(gs_screen_enum *, gs_state *,
  195. gs_screen_halftone *, bool, gs_memory_t *);
  196. #define gs_screen_init_accurate(penum, pgs, phsp, accurate)\
  197. gs_screen_init_memory(penum, pgs, phsp, accurate, pgs->memory)
  198. /* Procedural interface for MinScreenLevels (a Ghostscript extension) */
  199. /*
  200. * Set/get the MinScreenLevels value.
  201. *
  202. * Note that this value is stored in a static variable.
  203. */
  204. void gs_setminscreenlevels(uint);
  205. uint gs_currentminscreenlevels(void);
  206. #endif /* gxht_INCLUDED */