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