zcssepr.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* Copyright (C) 1994, 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: zcssepr.c,v 1.16 2004/08/19 19:33:09 stefan Exp $ */
  14. /* Separation color space support */
  15. #include "memory_.h"
  16. #include "ghost.h"
  17. #include "oper.h"
  18. #include "gsstruct.h"
  19. #include "gscolor.h"
  20. #include "gsmatrix.h" /* for gxcolor2.h */
  21. #include "gxcspace.h"
  22. #include "gxfixed.h" /* ditto */
  23. #include "gxcolor2.h"
  24. #include "estack.h"
  25. #include "ialloc.h"
  26. #include "icsmap.h"
  27. #include "ifunc.h"
  28. #include "igstate.h"
  29. #include "iname.h"
  30. #include "ivmspace.h"
  31. #include "store.h"
  32. #include "gscsepr.h"
  33. #include "gscdevn.h"
  34. #include "gxcdevn.h"
  35. #include "zht2.h"
  36. /* Imported from gscsepr.c */
  37. extern const gs_color_space_type gs_color_space_type_Separation;
  38. /* Imported from gscdevn.c */
  39. extern const gs_color_space_type gs_color_space_type_DeviceN;
  40. /*
  41. * Adobe first created the separation colorspace type and then later created
  42. * the DeviceN colorspace. Logically the separation colorspace is the same
  43. * as a DeviceN colorspace with a single component, except for the /None and
  44. * /All parameter values. We treat the separation colorspace as a DeviceN
  45. * colorspace except for the /All case.
  46. */
  47. /* <array> .setseparationspace - */
  48. /* The current color space is the alternate space for the separation space. */
  49. private int
  50. zsetseparationspace(i_ctx_t *i_ctx_p)
  51. {
  52. os_ptr op = osp;
  53. const ref *pcsa;
  54. gs_color_space cs;
  55. const gs_color_space * pacs;
  56. ref_colorspace cspace_old;
  57. ref sname, name_none, name_all;
  58. gs_device_n_map *pmap = NULL;
  59. gs_function_t *pfn = NULL;
  60. separation_type sep_type;
  61. int code;
  62. const gs_memory_t * mem = imemory;
  63. /* Verify that we have an array as our input parameter */
  64. check_read_type(*op, t_array);
  65. if (r_size(op) != 4)
  66. return_error(e_rangecheck);
  67. /* The alternate color space has been selected as the current color space */
  68. pacs = gs_currentcolorspace(igs);
  69. cs = *pacs;
  70. if (!cs.type->can_be_alt_space)
  71. return_error(e_rangecheck);
  72. /*
  73. * pcsa is a pointer to element 1 (2nd element) in the Separation colorspace
  74. * description array. Thus pcsa[2] is element #3 (4th element) which is the
  75. * tint transform.
  76. */
  77. pcsa = op->value.const_refs + 1;
  78. sname = *pcsa;
  79. switch (r_type(&sname)) {
  80. default:
  81. return_error(e_typecheck);
  82. case t_string:
  83. code = name_from_string(mem, &sname, &sname);
  84. if (code < 0)
  85. return code;
  86. /* falls through */
  87. case t_name:
  88. break;
  89. }
  90. if ((code = name_ref(mem, (const byte *)"All", 3, &name_all, 0)) < 0)
  91. return code;
  92. if ((code = name_ref(mem, (const byte *)"None", 4, &name_none, 0)) < 0)
  93. return code;
  94. sep_type = ( name_eq(&sname, &name_all) ? SEP_ALL :
  95. name_eq(&sname, &name_none) ? SEP_NONE : SEP_OTHER);
  96. /* Check tint transform procedure. */
  97. /* See comment above about psca */
  98. check_proc(pcsa[2]);
  99. pfn = ref_function(pcsa + 2);
  100. if (pfn == NULL)
  101. return_error(e_rangecheck);
  102. cspace_old = istate->colorspace;
  103. /* See zcsindex.c for why we use memmove here. */
  104. memmove(&cs.params.separation.alt_space, &cs,
  105. sizeof(cs.params.separation.alt_space));
  106. /* Now set the current color space as Separation */
  107. code = gs_build_Separation(&cs, pacs, imemory);
  108. if (code < 0)
  109. return code;
  110. pmap = cs.params.separation.map;
  111. gs_cspace_init(&cs, &gs_color_space_type_Separation, imemory, false);
  112. cs.params.separation.sep_type = sep_type;
  113. cs.params.separation.sep_name = name_index(mem, &sname);
  114. cs.params.separation.get_colorname_string = gs_get_colorname_string;
  115. istate->colorspace.procs.special.separation.layer_name = pcsa[0];
  116. istate->colorspace.procs.special.separation.tint_transform = pcsa[2];
  117. if (code >= 0)
  118. code = gs_cspace_set_sepr_function(&cs, pfn);
  119. if (code >= 0)
  120. code = gs_setcolorspace(igs, &cs);
  121. if (code < 0) {
  122. istate->colorspace = cspace_old;
  123. ifree_object(pmap, ".setseparationspace(pmap)");
  124. return code;
  125. }
  126. rc_decrement(pmap, ".setseparationspace(pmap)"); /* build sets rc = 1 */
  127. pop(1);
  128. return 0;
  129. }
  130. /* - currentoverprint <bool> */
  131. private int
  132. zcurrentoverprint(i_ctx_t *i_ctx_p)
  133. {
  134. os_ptr op = osp;
  135. push(1);
  136. make_bool(op, gs_currentoverprint(igs));
  137. return 0;
  138. }
  139. /* <bool> setoverprint - */
  140. private int
  141. zsetoverprint(i_ctx_t *i_ctx_p)
  142. {
  143. os_ptr op = osp;
  144. check_type(*op, t_boolean);
  145. gs_setoverprint(igs, op->value.boolval);
  146. pop(1);
  147. return 0;
  148. }
  149. /* - .currentoverprintmode <int> */
  150. private int
  151. zcurrentoverprintmode(i_ctx_t *i_ctx_p)
  152. {
  153. os_ptr op = osp;
  154. push(1);
  155. make_int(op, gs_currentoverprintmode(igs));
  156. return 0;
  157. }
  158. /* <int> .setoverprintmode - */
  159. private int
  160. zsetoverprintmode(i_ctx_t *i_ctx_p)
  161. {
  162. os_ptr op = osp;
  163. int param;
  164. int code = int_param(op, max_int, &param);
  165. if (code < 0 || (code = gs_setoverprintmode(igs, param)) < 0)
  166. return code;
  167. pop(1);
  168. return 0;
  169. }
  170. /* ------ Initialization procedure ------ */
  171. const op_def zcssepr_l2_op_defs[] =
  172. {
  173. op_def_begin_level2(),
  174. {"0currentoverprint", zcurrentoverprint},
  175. {"0.currentoverprintmode", zcurrentoverprintmode},
  176. {"1setoverprint", zsetoverprint},
  177. {"1.setoverprintmode", zsetoverprintmode},
  178. {"1.setseparationspace", zsetseparationspace},
  179. op_def_end(0)
  180. };