zdps.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /* Copyright (C) 1997, 2000 Aladdin Enterprises. All rights reserved.
  2. This file is part of AFPL Ghostscript.
  3. AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  4. distributor accepts any responsibility for the consequences of using it, or
  5. for whether it serves any particular purpose or works at all, unless he or
  6. she says so in writing. Refer to the Aladdin Free Public License (the
  7. "License") for full details.
  8. Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. in a plain ASCII text file named PUBLIC. The License grants you the right
  10. to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. conditions described in the License. Among other things, the License
  12. requires that the copyright notice and this notice be preserved on all
  13. copies.
  14. */
  15. /*$Id: zdps.c,v 1.4 2000/09/19 19:00:53 lpd Exp $ */
  16. /* Display PostScript extensions */
  17. #include "ghost.h"
  18. #include "oper.h"
  19. #include "gsstate.h"
  20. #include "gsdps.h"
  21. #include "gsimage.h"
  22. #include "gsiparm2.h"
  23. #include "gxalloc.h" /* for names_array in allocator */
  24. #include "gxfixed.h" /* for gxpath.h */
  25. #include "gxpath.h"
  26. #include "btoken.h" /* for user_names_p */
  27. #include "iddict.h"
  28. #include "idparam.h"
  29. #include "igstate.h"
  30. #include "iimage2.h"
  31. #include "iname.h"
  32. #include "store.h"
  33. /* Import the procedure for constructing user paths. */
  34. extern int make_upath(P5(i_ctx_t *, ref *, const gs_state *, gx_path *, bool));
  35. /* ------ Graphics state ------ */
  36. /* <screen_index> <x> <y> .setscreenphase - */
  37. private int
  38. zsetscreenphase(i_ctx_t *i_ctx_p)
  39. {
  40. os_ptr op = osp;
  41. int code;
  42. long x, y;
  43. check_type(op[-2], t_integer);
  44. check_type(op[-1], t_integer);
  45. check_type(*op, t_integer);
  46. x = op[-1].value.intval;
  47. y = op->value.intval;
  48. if (x != (int)x || y != (int)y ||
  49. op[-2].value.intval < -1 ||
  50. op[-2].value.intval >= gs_color_select_count
  51. )
  52. return_error(e_rangecheck);
  53. code = gs_setscreenphase(igs, (int)x, (int)y,
  54. (gs_color_select_t) op[-2].value.intval);
  55. if (code >= 0)
  56. pop(3);
  57. return code;
  58. }
  59. /* <screen_index> .currentscreenphase <x> <y> */
  60. private int
  61. zcurrentscreenphase(i_ctx_t *i_ctx_p)
  62. {
  63. os_ptr op = osp;
  64. gs_int_point phase;
  65. int code;
  66. check_type(*op, t_integer);
  67. if (op->value.intval < -1 ||
  68. op->value.intval >= gs_color_select_count
  69. )
  70. return_error(e_rangecheck);
  71. code = gs_currentscreenphase(igs, &phase,
  72. (gs_color_select_t)op->value.intval);
  73. if (code < 0)
  74. return code;
  75. push(1);
  76. make_int(op - 1, phase.x);
  77. make_int(op, phase.y);
  78. return 0;
  79. }
  80. /* ------ Device-source images ------ */
  81. /* <dict> .image2 - */
  82. private int
  83. zimage2(i_ctx_t *i_ctx_p)
  84. {
  85. os_ptr op = osp;
  86. int code;
  87. check_type(*op, t_dictionary);
  88. check_dict_read(*op);
  89. {
  90. gs_image2_t image;
  91. ref *pDataSource;
  92. gs_image2_t_init(&image);
  93. if ((code = dict_matrix_param(op, "ImageMatrix",
  94. &image.ImageMatrix)) < 0 ||
  95. (code = dict_find_string(op, "DataSource", &pDataSource)) < 0 ||
  96. (code = dict_float_param(op, "XOrigin", 0.0,
  97. &image.XOrigin)) != 0 ||
  98. (code = dict_float_param(op, "YOrigin", 0.0,
  99. &image.YOrigin)) != 0 ||
  100. (code = dict_float_param(op, "Width", 0.0,
  101. &image.Width)) != 0 ||
  102. image.Width <= 0 ||
  103. (code = dict_float_param(op, "Height", 0.0,
  104. &image.Height)) != 0 ||
  105. image.Height <= 0 ||
  106. (code = dict_bool_param(op, "PixelCopy", false,
  107. &image.PixelCopy)) < 0
  108. )
  109. return (code < 0 ? code : gs_note_error(e_rangecheck));
  110. check_stype(*pDataSource, st_igstate_obj);
  111. image.DataSource = igstate_ptr(pDataSource);
  112. {
  113. ref *ignoref;
  114. if (dict_find_string(op, "UnpaintedPath", &ignoref) > 0) {
  115. check_dict_write(*op);
  116. image.UnpaintedPath = gx_path_alloc(imemory,
  117. ".image2 UnpaintedPath");
  118. if (image.UnpaintedPath == 0)
  119. return_error(e_VMerror);
  120. } else
  121. image.UnpaintedPath = 0;
  122. }
  123. code = process_non_source_image(i_ctx_p,
  124. (const gs_image_common_t *)&image,
  125. ".image2");
  126. if (image.UnpaintedPath) {
  127. ref rupath;
  128. if (code < 0)
  129. return code;
  130. if (gx_path_is_null(image.UnpaintedPath))
  131. make_null(&rupath);
  132. else
  133. code = make_upath(i_ctx_p, &rupath, igs, image.UnpaintedPath,
  134. false);
  135. gx_path_free(image.UnpaintedPath, ".image2 UnpaintedPath");
  136. if (code < 0)
  137. return code;
  138. code = idict_put_string(op, "UnpaintedPath", &rupath);
  139. }
  140. }
  141. if (code >= 0)
  142. pop(1);
  143. return code;
  144. }
  145. /* ------ View clipping ------ */
  146. /* - viewclip - */
  147. private int
  148. zviewclip(i_ctx_t *i_ctx_p)
  149. {
  150. return gs_viewclip(igs);
  151. }
  152. /* - eoviewclip - */
  153. private int
  154. zeoviewclip(i_ctx_t *i_ctx_p)
  155. {
  156. return gs_eoviewclip(igs);
  157. }
  158. /* - initviewclip - */
  159. private int
  160. zinitviewclip(i_ctx_t *i_ctx_p)
  161. {
  162. return gs_initviewclip(igs);
  163. }
  164. /* - viewclippath - */
  165. private int
  166. zviewclippath(i_ctx_t *i_ctx_p)
  167. {
  168. return gs_viewclippath(igs);
  169. }
  170. /* ------ User names ------ */
  171. /* <index> <name> defineusername - */
  172. private int
  173. zdefineusername(i_ctx_t *i_ctx_p)
  174. {
  175. os_ptr op = osp;
  176. ref uname;
  177. check_int_ltu(op[-1], max_array_size);
  178. check_type(*op, t_name);
  179. if (user_names_p == 0) {
  180. int code = create_names_array(&user_names_p, imemory_local,
  181. "defineusername");
  182. if (code < 0)
  183. return code;
  184. }
  185. if (array_get(user_names_p, op[-1].value.intval, &uname) >= 0) {
  186. switch (r_type(&uname)) {
  187. case t_null:
  188. break;
  189. case t_name:
  190. if (name_eq(&uname, op))
  191. goto ret;
  192. /* falls through */
  193. default:
  194. return_error(e_invalidaccess);
  195. }
  196. } else { /* Expand the array. */
  197. ref new_array;
  198. uint old_size = r_size(user_names_p);
  199. uint new_size = (uint) op[-1].value.intval + 1;
  200. if (new_size < 100)
  201. new_size = 100;
  202. else if (new_size > max_array_size / 2)
  203. new_size = max_array_size;
  204. else if (new_size >> 1 < old_size)
  205. new_size = (old_size > max_array_size / 2 ? max_array_size :
  206. old_size << 1);
  207. else
  208. new_size <<= 1;
  209. /*
  210. * The user name array is allocated in stable local VM,
  211. * because it must be immune to save/restore.
  212. */
  213. {
  214. gs_ref_memory_t *slmem =
  215. (gs_ref_memory_t *)gs_memory_stable(imemory_local);
  216. int code;
  217. code = gs_alloc_ref_array(slmem, &new_array, a_all, new_size,
  218. "defineusername(new)");
  219. if (code < 0)
  220. return code;
  221. refcpy_to_new(new_array.value.refs, user_names_p->value.refs,
  222. old_size, idmemory);
  223. refset_null(new_array.value.refs + old_size,
  224. new_size - old_size);
  225. if (old_size)
  226. gs_free_ref_array(slmem, user_names_p, "defineusername(old)");
  227. }
  228. ref_assign(user_names_p, &new_array);
  229. }
  230. ref_assign(user_names_p->value.refs + op[-1].value.intval, op);
  231. ret:
  232. pop(2);
  233. return 0;
  234. }
  235. /* ------ Initialization procedure ------ */
  236. const op_def zdps_op_defs[] =
  237. {
  238. /* Graphics state */
  239. {"1.currentscreenphase", zcurrentscreenphase},
  240. {"3.setscreenphase", zsetscreenphase},
  241. /* Device-source images */
  242. {"1.image2", zimage2},
  243. /* View clipping */
  244. {"0eoviewclip", zeoviewclip},
  245. {"0initviewclip", zinitviewclip},
  246. {"0viewclip", zviewclip},
  247. {"0viewclippath", zviewclippath},
  248. /* User names */
  249. {"2defineusername", zdefineusername},
  250. op_def_end(0)
  251. };