gxht.h 8.3 KB

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