gsovrc.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /* Copyright (C) 2002 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: gsovrc.h,v 1.4 2004/09/22 00:37:12 dan Exp $ */
  14. /* overprint/overprint mode compositor interface */
  15. #ifndef gsovrc_INCLUDED
  16. # define gsovrc_INCLUDED
  17. #include "gsstype.h"
  18. #include "gxcomp.h"
  19. /*
  20. * Overprint compositor.
  21. *
  22. * The overprint and overprint mode capability allow drawing operations
  23. * to affect a subset of the set of color model components, rather than
  24. * all components. The overprint feature allows the set of affected
  25. * components to be determined by the color space, but independently of
  26. * the drawing color. Overprint mode allows both the color space and
  27. * drawing color to determine which components are affected.
  28. *
  29. * The significance of the overprint feature for a device is dependent on
  30. * the extent of rendering that is to be performed for that device:
  31. *
  32. * 1. High level devices, such as the PDFWrite and PSWrite devices,
  33. * do not, in principle, require the graphic library to convert
  34. * between color spaces and color models. These devices can accept
  35. * color space descriptions, so conversion to a color model can be
  36. * left to whatever application uses the generated file.
  37. *
  38. * For these devices, overprint and overprint mode are just
  39. * additional state parameters that are incorporated into the output
  40. * file, which may or may not be supported on the eventual target
  41. * application.
  42. *
  43. * Note that the current implementation of PDFWrite and PSWrite
  44. * do require the graphic library to convert between color spaces
  45. * and a color model, for all objects except images. To implement
  46. * the overprint feature under this design, the devices would
  47. * have to support the get_bits_rectangle method, which means they
  48. * would need to function as low-level devices. Since that defeats
  49. * the purpose of having a high-level device, for the time being
  50. * overprint and overprint mode are not fully supported for the
  51. * PDFWrite and PSWrite devices.
  52. *
  53. * 2. Low level devices require the graphic library to convert between
  54. * color spaces and color models, and perform actual rendering. For
  55. * these devices both overprint and overprint mode require a form
  56. * of mixing of the drawing color with any existing output. This
  57. * mixing is mechanically similar to that required for transparency
  58. * or raster op support, but differs from these because it affects
  59. * different color components differently (transparency and raster
  60. * operations are applied uniformly to all color components).
  61. *
  62. * Because the implementation of overprint for high level devices is
  63. * either trivial or essentially impossible (short of dealing with them
  64. * as low level devices), the discussion below is restricted to the
  65. * implementation for low level devices.
  66. *
  67. * In principle, the effects of overprint and overprint mode are
  68. * modified by changes to the current color, the current color space,
  69. * and the process color model.
  70. *
  71. * In most situation, the process color model cannot be changed without
  72. * discarding any existing graphic output, so within a given page this
  73. * affect may be ignored. An exception arises when emulating features
  74. * such as the "overprint preview" mode of Acrobat 5.0. This mode uses
  75. * a "fully dynamic" color model: any named color component is consider
  76. * to exist in the process color model (its conversion to a "real" color
  77. * is determined by the tint transform function associated with its
  78. * initial invocation). In this situation, the process color model may
  79. * "monotonically increase" as a page is processed. Since any such
  80. * change is associated with a change of color space, we need not be
  81. * concerned with independent changes in the process color model.
  82. *
  83. * For typical graphic operations such as line drawing or area filling,
  84. * both the current color and the current color space remain constant.
  85. * Overprint and overprint mode are significant for these operations
  86. * only if the output page contained data prior to the operation. If
  87. * this is not the case, overprint is irrelevant, as the initial state
  88. * of any retained color components, and the state of these components
  89. * in the drawing color, will be the same.
  90. *
  91. * Aside from the devices that generate output, Ghostscript makes use
  92. * of two additional types of the devices for rendering. Forwarding
  93. * devices do not generate output of their own; they merely forward
  94. * rendering commands to a target device. Accumulating devices render
  95. * output to a special buffer (often part of clipping or a caching
  96. * operation), which is subsequently sent to the primary output device
  97. * in a lower-level form.
  98. *
  99. * It is conceivable that a forwarding device could be dependent on the
  100. * overprint feature (e.g.: an "inking" filter to determine how much
  101. * of each colorant is required in each area of the output), but this
  102. * is unlikely and, in practice, never seems to arise (in practice,
  103. * inking filters scan the fully generated output). Hence, we ignore
  104. * this possibility, and need not be concerned with overprint when
  105. * installing or removing forwarding devices.
  106. *
  107. * Overprint is of interest to accumulating devices only if these
  108. * devices either begin operation with a non-empty output buffer, or if
  109. * the current color or color space can change during the lifetime of
  110. * an instantiation of the device. Most instantiations of accumulating
  111. * devices live only for the rendering of a single graphic object, for
  112. * which neither the color or color space can change. There are a few
  113. * exceptions:
  114. *
  115. * - Though images and shaded fills are single graphic objects, they
  116. * involve (potentially) many colors. Conveniently, overprint mode
  117. * does not apply to either images or shaded fills, so these cause
  118. * no difficulty. For the same reason PatternType 2 patterns do
  119. * not cause difficulty, though it is necessary to create/update
  120. * the overprint compositor to reflect the colorspace included
  121. * in the shading dictionary.
  122. *
  123. * - The gs_pdf14_device, which implements the PDF 1.4 transparency
  124. * facilities, is an accumulating device that supports only
  125. * the high-level rendering methods (fill_path, etc.). Actual
  126. * rendering is done with a separate marking device, an instance
  127. * of which is created for each graphic object rendered. The
  128. * marking device renders into the output buffer of the
  129. * gs_pdf14_device, which contains the results of prior rendering
  130. * operations. Thus, overprint is significant to the marking
  131. * device. The interaction of transparency and overprint are,
  132. * however, more complex than can be captured by a simple
  133. * compositor. The gs_pdf14_device and the corresponding device
  134. * (will) implement overprint and overprint mode directly. These
  135. * devices discard attempts to build an overprint compositor.
  136. *
  137. * - The most essential exception involves colored tiling patterns.
  138. * Both the color and color space may change multiple times
  139. * during the rendering of a colored pattern. If a colored
  140. * pattern is cached, an accurate implementation would require
  141. * the cache to included compositor creation instructions.
  142. * This is not possible in the current Ghostscript pattern
  143. * cache (which has other problems independent of overprint).
  144. * The best that can be done is to keep the overprint compositor
  145. * current during the caching operation itself. For single level
  146. * patterns, this will allow the tile instance to be rendered
  147. * accurately, even if the tile does not properly overprint
  148. * the output raster.
  149. *
  150. * Based on this reasoning, we can limit application of the overprint
  151. * compositor to a small numer of situations:
  152. *
  153. * 1. When the overprint or overprint mode parameter of the current
  154. * graphic state is changed (the overprint mode parameter is
  155. * ignored if overprint is set to false).
  156. *
  157. * 2. When the current color space changes, if overprint is set to true
  158. * (the colorspace cannot be relevant if the overprint is false).
  159. * There are a few exceptions to this rule for uncolored caches
  160. * (user paths, FontType 3 fonts) and anti-alias super-sampling.
  161. *
  162. * 3. If the current device color changes, if overprint is true and
  163. * overprint mode is 1.
  164. *
  165. * 4. If the device in the graphic state is changed, or if this device is
  166. * reopened after having been closed (e.g.: due to the action of
  167. * put_params), if the overprint parameter is set to true.
  168. *
  169. * 5. During grestore or setgstate (because the overprint/overprint
  170. * mode parameters might change without the current device changing).
  171. *
  172. * 6. When creating the pattern accumulator device, if overprint is
  173. * set to true.
  174. *
  175. * In PostScript and PDF, a change of the color space always has an
  176. * associated change of the current color, so it is possible to
  177. * exclude color space changes from the list above. We do not do this,
  178. * however, because changes in the color space are usually less frequent
  179. * than changes in the current color, and the latter are only significant
  180. * if overprint mode is 1.
  181. *
  182. * Unlike the other compositors used by Ghostscript (the alpha-channel
  183. * compositor and the implemented but not used raster operation
  184. * compositor), once created, the overprint compositor is made part of the
  185. * current graphic state, and assumes the lifetime and open/close
  186. * status of the device to which it is applied. In effect, the device to
  187. * which the compositor is applied will, for purposes of the graphic
  188. * state, cease to exist as as independent item. The only way to discard
  189. * the compositor is to change the current device.
  190. *
  191. * Subsequent invocations of create_compositor will not create a new
  192. * compositor. Rather, they change the parameters of the existing
  193. * compositor device. The compositor functions with only a small
  194. * performance penalty if overprint is disabled, so there is no reason
  195. * to discard the compositor if oveprint is turned off.
  196. *
  197. * The compositor device will emulate the open/close state of the device
  198. * to which it is applied. This is accomplished by forwarding all open
  199. * and close requests. In addition, the compositor device will check the
  200. * status of the device to which it is applied after each put_params call,
  201. * and will change its own status to reflect this status. The underlying
  202. * device is required to close itself if an invocation of put_params
  203. * changes in the process color model.
  204. *
  205. * NB: It is not possible, without an excessive performance delay, for
  206. * the compositor to detect all cases in which the device to which
  207. * it is applied may close itself due to an error condition. We
  208. * believe this will never cause difficulty in practice, as the
  209. * closing of a device is not itself used as an error indication.
  210. */
  211. #ifndef gs_overprint_params_t_DEFINED
  212. # define gs_overprint_params_t_DEFINED
  213. typedef struct gs_overprint_params_s gs_overprint_params_t;
  214. #endif
  215. struct gs_overprint_params_s {
  216. /*
  217. * Are any component values to be retained?
  218. *
  219. * If this is false (overprint off), all other fields in the compositor
  220. * are ignored, and the compositor does nothing with respect to rendering
  221. * (it doesn't even impose a performance penalty).
  222. *
  223. * If this field is true, the retain_spot_comps and potentially the
  224. * retained_comps fields should be initialized.
  225. *
  226. * Note that this field may be false even if overprint is true. This
  227. * would be the case if the current color space was a Separation color
  228. * space with the component "All".
  229. */
  230. bool retain_any_comps;
  231. /*
  232. * Are spot (non-process) color component values retained?
  233. *
  234. * If overprint is true, this field will be true for all color spaces
  235. * other than Separation/DeviceN color spaces.
  236. *
  237. * The overprint compositor will itself determine what constitutes a
  238. * process color. This is done by using the color space mapping
  239. * routines for the target device for all three standard device
  240. * color spaces (DeviceGray, DeviceRGB, and DeviceCMYK) and the
  241. * set of all possible colors with individual components either 0
  242. * or 1. Any color model component which is mapped to 0 for all of
  243. * these cases is considered a spot color.
  244. *
  245. * If this field is true, the drawn_comps field (see below) is ignored.
  246. *
  247. * NB: This field should not be used if the DeviceCMYK color space
  248. * is being used with a DeviceCMYK color model (which may have
  249. * additional spot colors). Such a color model must explicitly
  250. * list the set of drawn components, so as to support overprint
  251. * mode.
  252. */
  253. bool retain_spot_comps;
  254. /*
  255. * The list of color model compoents to be retained (i.e.: that are
  256. * not affected by drawing operations). The field is bit-encoded;
  257. * the bit corresponding to component i is (1 << i). This bit will be
  258. * 1 if the corresponding component is set from the drawing color, 0 if
  259. * it is to be left unaffected.
  260. */
  261. gx_color_index drawn_comps;
  262. };
  263. /*
  264. * The overprint compositor structure. This is exactly analogous to other
  265. * compositor structures, consisting of a the compositor common elements
  266. * and the overprint-specific parameters.
  267. */
  268. typedef struct gs_overprint_s {
  269. gs_composite_common;
  270. gs_overprint_params_t params;
  271. } gs_overprint_t;
  272. /*
  273. * In a modest violation of good coding practice, the gs_composite_common
  274. * fields are "known" to be simple (contain no pointers to garbage
  275. * collected memory), and we also know the gs_overprint_params_t structure
  276. * to be simple, so we just create a trivial structure descriptor for the
  277. * entire gs_overprint_s structure.
  278. */
  279. #define private_st_gs_overprint_t() /* In gsovrc.c */\
  280. gs_private_st_simple(st_overprint, gs_overprint_t, "gs_overprint_t");
  281. /* some elementary macros for manipulating drawn_comps */
  282. #define gs_overprint_set_drawn_comp(drawn_comps, i) \
  283. ((drawn_comps) |= (gx_color_index)1 << (i))
  284. #define gs_overprint_clear_drawn_comp(drawn_comps, i) \
  285. ((drawn_comps) &= ~((gx_color_index)1 << 1))
  286. #define gs_overprint_clear_all_drawn_comps(drawn_comps) \
  287. ((drawn_comps) = 0)
  288. #define gs_overprint_get_drawn_comp(drawn_comps, i) \
  289. (((drawn_comps) & ((gx_color_index)1 << (i))) != 0)
  290. /*
  291. * In the unlikely event that the overprint parameters will ever be
  292. * allocated on the heap, we provide GC structure descriptors for
  293. * them.
  294. */
  295. extern_st(st_overprint_params);
  296. #define public_st_overprint_params_t /* in gsovrc.c */ \
  297. gs_public_st_simple( st_overprint_params, \
  298. gs_overprint_params_t, \
  299. "gs_overprint_params_t" )
  300. /* create an overprint composition object */
  301. extern int gs_create_overprint(
  302. gs_composite_t ** ppct,
  303. const gs_overprint_params_t * pparams,
  304. gs_memory_t * mem );
  305. /* verify that a compositor is the overprint compositor */
  306. extern bool gs_is_overprint_compositor(const gs_composite_t * pct);
  307. #endif /* gsovrc_INCLUDED */