gxcspace.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /* Copyright (C) 1996, 2000 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: gxcspace.h,v 1.13 2004/08/04 19:36:12 stefan Exp $ */
  14. /* Implementation of color spaces */
  15. /* Requires gsstruct.h */
  16. #ifndef gxcspace_INCLUDED
  17. # define gxcspace_INCLUDED
  18. #include "gscspace.h" /* client interface */
  19. #include "gsccolor.h"
  20. #include "gscsel.h"
  21. #include "gxfrac.h" /* for concrete colors */
  22. /* Define opaque types. */
  23. #ifndef gx_device_color_DEFINED
  24. # define gx_device_color_DEFINED
  25. typedef struct gx_device_color_s gx_device_color;
  26. #endif
  27. #ifndef gx_device_DEFINED
  28. # define gx_device_DEFINED
  29. typedef struct gx_device_s gx_device;
  30. #endif
  31. #ifndef stream_DEFINED
  32. # define stream_DEFINED
  33. typedef struct stream_s stream;
  34. #endif
  35. /* Color space types (classes): */
  36. /*typedef struct gs_color_space_type_s gs_color_space_type; */
  37. struct gs_color_space_type_s {
  38. gs_color_space_index index;
  39. /*
  40. * Define whether the space can be the base space for an Indexed
  41. * color space or the alternate space for a Separation or DeviceN
  42. * color space.
  43. */
  44. bool can_be_base_space;
  45. bool can_be_alt_space;
  46. /*
  47. * Define the true structure type for this variant of the color
  48. * space union.
  49. */
  50. gs_memory_type_ptr_t stype;
  51. /* ------ Procedures ------ */
  52. /*
  53. * Define the number of components in a color of this space. For
  54. * Pattern spaces, where the number of components depends on the
  55. * underlying space, this value is -1 for colored Patterns,
  56. * -N-1 for uncolored Patterns, where N is the number of components
  57. * in the base space.
  58. */
  59. #define cs_proc_num_components(proc)\
  60. int proc(const gs_color_space *)
  61. #define cs_num_components(pcs)\
  62. (*(pcs)->type->num_components)(pcs)
  63. cs_proc_num_components((*num_components));
  64. /*
  65. * Return the base or alternate color space underlying this one.
  66. * Only defined for Indexed, Separation, DeviceN, and
  67. * uncolored Pattern spaces; returns NULL for all others.
  68. */
  69. #define cs_proc_base_space(proc)\
  70. const gs_color_space *proc(const gs_color_space *)
  71. #define cs_base_space(pcs)\
  72. (*(pcs)->type->base_space)(pcs)
  73. cs_proc_base_space((*base_space));
  74. /* Construct the initial color value for this space. */
  75. #define cs_proc_init_color(proc)\
  76. void proc(gs_client_color *, const gs_color_space *)
  77. #define cs_init_color(pcc, pcs)\
  78. (*(pcs)->type->init_color)(pcc, pcs)
  79. #define cs_full_init_color(pcc, pcs)\
  80. ((pcc)->pattern = 0, cs_init_color(pcc, pcs))
  81. cs_proc_init_color((*init_color));
  82. /* Force a client color into its legal range. */
  83. #define cs_proc_restrict_color(proc)\
  84. void proc(gs_client_color *, const gs_color_space *)
  85. #define cs_restrict_color(pcc, pcs)\
  86. ((pcs)->type->restrict_color(pcc, pcs))
  87. cs_proc_restrict_color((*restrict_color));
  88. /* Return the concrete color space underlying this one. */
  89. /* (Not defined for Pattern spaces.) */
  90. #define cs_proc_concrete_space(proc)\
  91. const gs_color_space *proc(const gs_color_space *,\
  92. const gs_imager_state *)
  93. #define cs_concrete_space(pcs, pis)\
  94. (*(pcs)->type->concrete_space)(pcs, pis)
  95. cs_proc_concrete_space((*concrete_space));
  96. /*
  97. * Reduce a color to a concrete color. A concrete color is one
  98. * that the device can handle directly (possibly with halftoning):
  99. * a DeviceGray/RGB/CMYK/Pixel color, or a Separation or DeviceN
  100. * color that does not use the alternate space.
  101. * (Not defined for Pattern spaces.)
  102. */
  103. #define cs_proc_concretize_color(proc)\
  104. int proc(const gs_client_color *, const gs_color_space *,\
  105. frac *, const gs_imager_state *)
  106. #define cs_concretize_color(pcc, pcs, values, pis)\
  107. (*(pcs)->type->concretize_color)(pcc, pcs, values, pis)
  108. cs_proc_concretize_color((*concretize_color));
  109. /* Map a concrete color to a device color. */
  110. /* (Only defined for concrete color spaces.) */
  111. #define cs_proc_remap_concrete_color(proc)\
  112. int proc(const frac *, const gs_color_space * pcs, gx_device_color *,\
  113. const gs_imager_state *, gx_device *, gs_color_select_t)
  114. cs_proc_remap_concrete_color((*remap_concrete_color));
  115. /* Map a color directly to a device color. */
  116. #define cs_proc_remap_color(proc)\
  117. int proc(const gs_client_color *, const gs_color_space *,\
  118. gx_device_color *, const gs_imager_state *, gx_device *,\
  119. gs_color_select_t)
  120. cs_proc_remap_color((*remap_color));
  121. /* Install the color space in a graphics state. */
  122. #define cs_proc_install_cspace(proc)\
  123. int proc(const gs_color_space *, gs_state *)
  124. cs_proc_install_cspace((*install_cspace));
  125. /*
  126. * Push the appropriate overprint compositor onto the current device.
  127. * This is distinct from install_cspace as it may need to be called
  128. * when the overprint parameter is changed.
  129. *
  130. * This routine need only be called if:
  131. * 1. The color space or color model has changed, and overprint
  132. * is true.
  133. * 2. The overprint mode setting has changed, and overprint is true.
  134. * 3. The overprint mode setting has changed.
  135. */
  136. #define cs_proc_set_overprint(proc)\
  137. int proc(const gs_color_space *, gs_state *)
  138. cs_proc_set_overprint((*set_overprint));
  139. /* Adjust reference counts of indirect color space components. */
  140. #define cs_proc_adjust_cspace_count(proc)\
  141. void proc(const gs_color_space *, int)
  142. #define cs_adjust_cspace_count(pgs, delta)\
  143. (*(pgs)->color_space->type->adjust_cspace_count)((pgs)->color_space, delta)
  144. cs_proc_adjust_cspace_count((*adjust_cspace_count));
  145. /* Adjust reference counts of indirect color components. */
  146. /*
  147. * Note: the color space argument may be NULL, which indicates that the
  148. * caller warrants that any subsidiary colors don't have allocation
  149. * issues. This is a hack for an application that needs to be able to
  150. * release Pattern colors.
  151. */
  152. #define cs_proc_adjust_color_count(proc)\
  153. void proc(const gs_client_color *, const gs_color_space *, int)
  154. #define cs_adjust_color_count(pgs, delta)\
  155. (*(pgs)->color_space->type->adjust_color_count)\
  156. ((pgs)->ccolor, (pgs)->color_space, delta)
  157. cs_proc_adjust_color_count((*adjust_color_count));
  158. /* Adjust both reference counts. */
  159. #define cs_adjust_counts(pgs, delta)\
  160. (cs_adjust_color_count(pgs, delta), cs_adjust_cspace_count(pgs, delta))
  161. /* Serialization. */
  162. /*
  163. * Note : We don't include *(pcs)->type into serialization,
  164. * because we assume it is a static constant to be processed separately.
  165. */
  166. #define cs_proc_serialize(proc)\
  167. int proc(const gs_color_space *, stream *)
  168. #define cs_serialize(pcs, s)\
  169. (*(pcs)->type->serialize)(pcs, s)
  170. cs_proc_serialize((*serialize));
  171. /* A color mapping linearity check. */
  172. #define cs_proc_is_linear(proc)\
  173. int proc(gs_direct_color_space *cs, const gs_imager_state * pis,\
  174. gx_device *dev,\
  175. const gs_client_color *c0, const gs_client_color *c1,\
  176. const gs_client_color *c2, const gs_client_color *c3,\
  177. float smoothness)
  178. #define cs_is_linear(pcs, pis, dev, c0, c1, c2, c3, smoothness)\
  179. (*(pcs)->type->is_linear)(pcs, pis, dev, c0, c1, c2, c3, smoothness)
  180. cs_proc_is_linear((*is_linear));
  181. };
  182. /* Standard color space structure types */
  183. extern_st(st_base_color_space);
  184. #define public_st_base_color_space() /* in gscspace.c */\
  185. gs_public_st_simple(st_base_color_space, gs_base_color_space,\
  186. "gs_base_color_space")
  187. /*extern_st(st_paint_color_space); *//* (not needed) */
  188. /* Standard color space procedures */
  189. cs_proc_num_components(gx_num_components_1);
  190. cs_proc_num_components(gx_num_components_3);
  191. cs_proc_num_components(gx_num_components_4);
  192. cs_proc_base_space(gx_no_base_space);
  193. cs_proc_init_color(gx_init_paint_1);
  194. cs_proc_init_color(gx_init_paint_3);
  195. cs_proc_init_color(gx_init_paint_4);
  196. cs_proc_restrict_color(gx_restrict01_paint_1);
  197. cs_proc_restrict_color(gx_restrict01_paint_3);
  198. cs_proc_restrict_color(gx_restrict01_paint_4);
  199. cs_proc_concrete_space(gx_no_concrete_space);
  200. cs_proc_concrete_space(gx_same_concrete_space);
  201. cs_proc_concretize_color(gx_no_concretize_color);
  202. cs_proc_remap_color(gx_default_remap_color);
  203. cs_proc_install_cspace(gx_no_install_cspace);
  204. cs_proc_set_overprint(gx_spot_colors_set_overprint);
  205. cs_proc_adjust_cspace_count(gx_no_adjust_cspace_count);
  206. cs_proc_adjust_color_count(gx_no_adjust_color_count);
  207. cs_proc_serialize(gx_serialize_cspace_type);
  208. cs_proc_is_linear(gx_cspace_no_linear);
  209. cs_proc_is_linear(gx_cspace_is_linear_default);
  210. /*
  211. * Define the implementation procedures for the standard device color
  212. * spaces. These are implemented in gxcmap.c.
  213. */
  214. cs_proc_remap_color(gx_remap_DeviceGray);
  215. cs_proc_concretize_color(gx_concretize_DeviceGray);
  216. cs_proc_remap_concrete_color(gx_remap_concrete_DGray);
  217. cs_proc_remap_color(gx_remap_DeviceRGB);
  218. cs_proc_concretize_color(gx_concretize_DeviceRGB);
  219. cs_proc_remap_concrete_color(gx_remap_concrete_DRGB);
  220. cs_proc_remap_color(gx_remap_DeviceCMYK);
  221. cs_proc_concretize_color(gx_concretize_DeviceCMYK);
  222. cs_proc_remap_concrete_color(gx_remap_concrete_DCMYK);
  223. /* Define the allocator type for color spaces. */
  224. extern_st(st_color_space);
  225. /*
  226. * Initialize the type and memory fields of a color space, possibly
  227. * allocating it first. This is only used by color space implementations.
  228. */
  229. void gs_cspace_init(gs_color_space *pcs,
  230. const gs_color_space_type *pcstype,
  231. gs_memory_t *mem, bool isheap);
  232. int gs_cspace_alloc(gs_color_space **ppcspace,
  233. const gs_color_space_type *pcstype,
  234. gs_memory_t *mem);
  235. #endif /* gxcspace_INCLUDED */