gxpcolor.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /* Copyright (C) 1993, 1995, 1996, 1997, 1999 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: gxpcolor.h,v 1.9 2003/08/20 19:53:11 igor Exp $ */
  14. /* Pattern color and tile structures and procedures */
  15. /* Requires gsmatrix.h, gxcolor2.h, gxdcolor.h */
  16. #ifndef gxpcolor_INCLUDED
  17. # define gxpcolor_INCLUDED
  18. #include "gspcolor.h"
  19. #include "gxcspace.h"
  20. #include "gxdevice.h"
  21. #include "gxdevmem.h"
  22. #include "gxpcache.h"
  23. /*
  24. * Define the type of a Pattern, also used with Pattern instances.
  25. */
  26. #ifndef gs_pattern_type_DEFINED
  27. # define gs_pattern_type_DEFINED
  28. typedef struct gs_pattern_type_s gs_pattern_type_t;
  29. #endif
  30. struct gs_pattern_type_s {
  31. int PatternType;
  32. struct pp_ {
  33. /*
  34. * Define whether a Pattern uses the base color space in its color
  35. * space, requiring setcolor to provide values for the base color
  36. * space. Currently this is true for uncolored PatternType 1
  37. * patterns, false for all others.
  38. */
  39. #define pattern_proc_uses_base_space(proc)\
  40. bool proc(const gs_pattern_template_t *)
  41. pattern_proc_uses_base_space((*uses_base_space));
  42. /*
  43. * Make an instance of a Pattern.
  44. */
  45. #define pattern_proc_make_pattern(proc)\
  46. int proc(gs_client_color *, const gs_pattern_template_t *,\
  47. const gs_matrix *, gs_state *, gs_memory_t *)
  48. pattern_proc_make_pattern((*make_pattern));
  49. /*
  50. * Get the template from a Pattern instance.
  51. */
  52. #define pattern_proc_get_pattern(proc)\
  53. const gs_pattern_template_t *proc(const gs_pattern_instance_t *)
  54. pattern_proc_get_pattern((*get_pattern));
  55. /*
  56. * Remap a Pattern color to a device color.
  57. * cs_proc_remap_color is defined in gxcspace.h.
  58. */
  59. #define pattern_proc_remap_color(proc)\
  60. cs_proc_remap_color(proc)
  61. pattern_proc_remap_color((*remap_color));
  62. /*
  63. * Perform any special actions required when a pattern instance
  64. * is made the current color "color" (i.e.: at setcolor time).
  65. * This is primarily useful for PatternType2 patterns, where the
  66. * pattern instance specifies a color space.
  67. */
  68. #define pattern_proc_set_color(proc)\
  69. int proc(const gs_client_color *, gs_state *)
  70. pattern_proc_set_color((*set_color));
  71. } procs;
  72. };
  73. /*
  74. * Initialize the common part of a pattern template. This procedure is for
  75. * the use of gs_pattern*_init implementations, not clients.
  76. */
  77. void gs_pattern_common_init(gs_pattern_template_t *,
  78. const gs_pattern_type_t *);
  79. /*
  80. * Do the generic work for makepattern: allocate the instance and the
  81. * saved graphics state, and fill in the common members.
  82. */
  83. int gs_make_pattern_common(gs_client_color *, const gs_pattern_template_t *,
  84. const gs_matrix *, gs_state *, gs_memory_t *,
  85. gs_memory_type_ptr_t);
  86. /* Declare the freeing procedure for Pattern instances. */
  87. extern rc_free_proc(rc_free_pattern_instance);
  88. /* Declare the Pattern color space type. */
  89. extern const gs_color_space_type gs_color_space_type_Pattern;
  90. /*
  91. * Define the (PatternType 1) Pattern device color types. There is one type
  92. * for colored patterns, and one uncolored pattern type for each non-Pattern
  93. * device color type.
  94. */
  95. extern const gx_device_color_type_t
  96. gx_dc_pattern,
  97. gx_dc_pure_masked, gx_dc_binary_masked, gx_dc_colored_masked;
  98. #define gx_dc_type_pattern (&gx_dc_pattern)
  99. /*
  100. * These device color methods are shared amongst pattern types.
  101. */
  102. extern dev_color_proc_save_dc(gx_dc_pattern_save_dc);
  103. extern dev_color_proc_write(gx_dc_pattern_write);
  104. extern dev_color_proc_read(gx_dc_pattern_read);
  105. /*
  106. * For shading and colored tiling patterns, it is not possible to say
  107. * which color components have non-zero values.
  108. */
  109. extern dev_color_proc_get_nonzero_comps(gx_dc_pattern_get_nonzero_comps);
  110. /*
  111. * Define a color tile, an entry in the rendered Pattern cache (and
  112. * eventually in the colored halftone cache). Note that the depth is
  113. * not sufficient to ensure that the rendering matches a given device;
  114. * however, we don't currently have an object that represents the
  115. * abstraction of a 'color representation'.
  116. */
  117. struct gx_color_tile_s {
  118. /* ------ The following are the 'key' in the cache. ------ */
  119. /* Note that the id is a generated instance ID, */
  120. /* and has no relation to the template's gs_uid. */
  121. gx_bitmap_id id;
  122. int depth;
  123. /* We do, however, copy the template's gs_uid, */
  124. /* for use in selective cache purging. */
  125. gs_uid uid;
  126. /* ------ The following are the cache 'value'. ------ */
  127. /* Note that if tbits and tmask both have data != 0, */
  128. /* both must have the same rep_shift. */
  129. /****** NON-ZERO shift VALUES ARE NOT SUPPORTED YET. ******/
  130. int tiling_type; /* TilingType */
  131. gs_matrix step_matrix; /* tiling space -> device space, */
  132. /* see gxcolor2.h for details */
  133. gs_rect bbox; /* bbox of tile in tiling space */
  134. gx_strip_bitmap tbits; /* data = 0 if uncolored */
  135. gx_strip_bitmap tmask; /* data = 0 if no mask */
  136. /* (i.e., the mask is all 1's) */
  137. bool is_simple; /* true if xstep/ystep = tile size */
  138. bool is_dummy; /* if true, the device manages the pattern,
  139. and the content of the tile is empty. */
  140. /* The following is neither key nor value. */
  141. uint index; /* the index of the tile within */
  142. /* the cache (for GC) */
  143. };
  144. #define private_st_color_tile() /* in gxpcmap.c */\
  145. gs_private_st_ptrs2(st_color_tile, gx_color_tile, "gx_color_tile",\
  146. color_tile_enum_ptrs, color_tile_reloc_ptrs, tbits.data, tmask.data)
  147. #define private_st_color_tile_element() /* in gxpcmap.c */\
  148. gs_private_st_element(st_color_tile_element, gx_color_tile,\
  149. "gx_color_tile[]", color_tile_elt_enum_ptrs, color_tile_elt_reloc_ptrs,\
  150. st_color_tile)
  151. /* Define the Pattern cache. */
  152. /*#include "gxpcache.h" *//* (above) */
  153. /* Allocate a Pattern cache. */
  154. /* We shorten the procedure names because some VMS compilers */
  155. /* truncate names to 23 characters. */
  156. uint gx_pat_cache_default_tiles(void);
  157. ulong gx_pat_cache_default_bits(void);
  158. gx_pattern_cache *gx_pattern_alloc_cache(gs_memory_t *, uint, ulong);
  159. /* Get or set the Pattern cache in a gstate. */
  160. gx_pattern_cache *gstate_pattern_cache(gs_state *);
  161. void gstate_set_pattern_cache(gs_state *, gx_pattern_cache *);
  162. /*
  163. * Define a device for accumulating the rendering of a Pattern.
  164. * This is actually a wrapper for two other devices: one that accumulates
  165. * the actual pattern image (if this is a colored pattern), and one that
  166. * accumulates a mask defining which pixels in the image are set.
  167. */
  168. typedef struct gx_device_pattern_accum_s {
  169. gx_device_forward_common;
  170. /* Client sets these before opening */
  171. gs_memory_t *bitmap_memory;
  172. const gs_pattern1_instance_t *instance;
  173. /* open sets these */
  174. gx_device_memory *bits; /* target also points to bits */
  175. gx_device_memory *mask;
  176. } gx_device_pattern_accum;
  177. #define private_st_device_pattern_accum() /* in gxpcmap.c */\
  178. gs_private_st_suffix_add3_final(st_device_pattern_accum,\
  179. gx_device_pattern_accum, "pattern accumulator", pattern_accum_enum,\
  180. pattern_accum_reloc, gx_device_finalize, st_device_forward,\
  181. instance, bits, mask)
  182. /* Allocate a pattern accumulator. */
  183. gx_device_pattern_accum *gx_pattern_accum_alloc(gs_memory_t * memory, client_name_t);
  184. /* Add an accumulated pattern to the cache. */
  185. /* Note that this does not free any of the data in the accumulator */
  186. /* device, but it may zero out the bitmap_memory pointers to prevent */
  187. /* the accumulated bitmaps from being freed when the device is closed. */
  188. int gx_pattern_cache_add_entry(gs_imager_state *, gx_device_pattern_accum *,
  189. gx_color_tile **);
  190. /* Add a dummy Pattern cache entry. Stubs a pattern tile for interpreter when
  191. device handles high level patterns. */
  192. int gx_pattern_cache_add_dummy_entry(gs_imager_state *pis, gs_pattern1_instance_t *pinst,
  193. int depth);
  194. /* Look up a pattern color in the cache. */
  195. bool gx_pattern_cache_lookup(gx_device_color *, const gs_imager_state *,
  196. gx_device *, gs_color_select_t);
  197. /* Purge selected entries from the pattern cache. */
  198. void gx_pattern_cache_winnow(gx_pattern_cache *,
  199. bool (*)(gx_color_tile *, void *),
  200. void *);
  201. #endif /* gxpcolor_INCLUDED */