gs_dpnxt.ps 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. % Copyright (C) 1997, 1998 Aladdin Enterprises. All rights reserved.
  2. %
  3. % This file is part of AFPL Ghostscript.
  4. %
  5. % AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  6. % distributor accepts any responsibility for the consequences of using it, or
  7. % for whether it serves any particular purpose or works at all, unless he or
  8. % she says so in writing. Refer to the Aladdin Free Public License (the
  9. % "License") for full details.
  10. %
  11. % Every copy of AFPL Ghostscript must include a copy of the License, normally
  12. % in a plain ASCII text file named PUBLIC. The License grants you the right
  13. % to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14. % conditions described in the License. Among other things, the License
  15. % requires that the copyright notice and this notice be preserved on all
  16. % copies.
  17. % $Id: gs_dpnxt.ps,v 1.2 2000/09/19 18:29:11 lpd Exp $
  18. % gs_dpnxt.ps
  19. % NeXT Display PostScript extensions
  20. % Define the operation values for compositing. These must match the values
  21. % in gsdpnext.h, which also are the ones from the NeXT documentation.
  22. % We put them in systemdict, which seems like as good a place as any.
  23. mark
  24. /Clear /Copy /Sover /Sin /Sout /Satop /Dover /Din /Dout /Datop /Xor
  25. /PlusD /PlusL /Highlight % not sure about Highlight
  26. counttomark { counttomark 1 sub def } repeat pop
  27. % We implement readimage and sizeimage using the following 3 otherwise
  28. % undocumented lower-level operators:
  29. %
  30. % <x> <y> <width> <height> <matrix> .sizeimagebox
  31. % <dev_x> <dev_y> <dev_width> <dev_height> <matrix>
  32. %
  33. % - .sizeimageparams <bits/sample> <multiproc> <ncolors>
  34. %
  35. % <device> <x> <y> <width> <max_height> <alpha?> <std_depth|null>
  36. % <string> .getbitsrect <height> <substring>
  37. %
  38. % NOTE: These operators are subject to change without notice!
  39. % Implement readimage using .getbitsrect. Experimentation on a NeXT system
  40. % shows that the data is always returned in order of increasing device Y,
  41. % regardless of the CTM.
  42. %
  43. % Note that we can't make stack protection work for this operator,
  44. % because it must remove its operands from the stack before calling
  45. % the supplied procedure(s).
  46. /readimage { % <x> <y> <width> <height> <proc> [... <procN-1>]
  47. % <string> <alpha?> readimage -
  48. .sizeimageparams exch {
  49. % multiproc = true. If N > 1, store the procedures in an array.
  50. exch pop 1 index { 1 add } if
  51. % Stack: ... string alpha? nprocs
  52. dup 1 eq {
  53. pop false % only 1 procedure, multiproc is irrelevant
  54. } {
  55. dup array 4 1 roll 3 add 2 roll astore 3 1 roll true
  56. } ifelse
  57. } {
  58. % multiproc = false.
  59. pop pop false
  60. } ifelse
  61. % Map the rectangle to device coordinates.
  62. % Stack: x y w h proc(s) str alpha? multi?
  63. 8 -4 roll matrix .sizeimagebox pop 8 4 roll
  64. % Make sure we allocate the operand array in local VM
  65. % to avoid a possible invalidaccess.
  66. .currentglobal false .setglobal 9 1 roll
  67. exch { 1 } { 0 } ifelse exch % alpha is last, if present
  68. exch 4 1 roll 8 array astore exch .setglobal
  69. { % Read out a block of scan lines and pass them to the procedure.
  70. % Stack: [x y w h alpha? proc(s) str multi?] -- we must consume this.
  71. dup 3 get 0 eq { pop exit } if
  72. aload 9 1 roll pop exch pop currentdevice 7 1 roll
  73. % Always read out the data as standard (not native) pixels.
  74. .sizeimageparams pop pop exch .getbitsrect
  75. % Stack: [x y w h alpha? proc(s) str multi?] hread substr
  76. 3 -1 roll
  77. % Stack: hread substr [x y w h alpha? proc(s) str multi?]
  78. dup 1 2 copy get 5 index add put
  79. % Stack: hread substr [x y' w h alpha? proc(s) str multi?]
  80. dup 3 2 copy get 6 -1 roll sub put
  81. % Stack: substr [x y' w h' alpha? proc(s) str multi?]
  82. dup 5 get exch 7 get {
  83. % multiproc = true, pass each plane to a different procedure.
  84. % Stack: substr procs
  85. 0 1 2 index length 1 sub {
  86. % Push 1 plane and its procedure under the top 2 elements.
  87. % Stack: ... substr procs plane#
  88. 2 index length 2 index length idiv % bytes per plane
  89. dup 2 index mul exch
  90. % Stack: ... substr procs plane# start length
  91. 4 index 3 1 roll getinterval 4 1 roll
  92. 2 copy get 4 1 roll pop
  93. } for
  94. exch pop length 2 mul .execn
  95. } {
  96. % multiproc = false, just call the procedure.
  97. exec
  98. } ifelse
  99. } //systemdict /exec get 3 packedarray cvx loop
  100. } bind odef
  101. % Implement sizeimage using lower-level operators.
  102. /sizeimage { % <x> <y> <width> <height> <matrix> sizeimage
  103. % <devwidth> <devheight> <bits/sample> <matrix>
  104. % <multiproc> <ncolors>
  105. .sizeimagebox 5 -2 roll pop pop
  106. .sizeimageparams 3 -1 roll 4 1 roll
  107. } bind odef