星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gs_dpnxt.ps 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. % Copyright (C) 1997, 1998 Aladdin Enterprises. All rights reserved.
  2. %
  3. % This software is provided AS-IS with no warranty, either express or
  4. % implied.
  5. %
  6. % This software is distributed under license and may not be copied,
  7. % modified or distributed except as expressly authorized under the terms
  8. % of the license contained in the file LICENSE in this distribution.
  9. %
  10. % For more information about licensing, please refer to
  11. % http://www.ghostscript.com/licensing/. For information on
  12. % commercial licensing, go to http://www.artifex.com/licensing/ or
  13. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  14. % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  15. % $Id: gs_dpnxt.ps 9246 2008-11-27 01:58:54Z alexcher $
  16. % gs_dpnxt.ps
  17. % NeXT Display PostScript extensions
  18. % Define the operation values for compositing. These must match the values
  19. % in gsdpnext.h, which also are the ones from the NeXT documentation.
  20. % We put them in systemdict, which seems like as good a place as any.
  21. mark
  22. /Clear /Copy /Sover /Sin /Sout /Satop /Dover /Din /Dout /Datop /Xor
  23. /PlusD /PlusL /Highlight % not sure about Highlight
  24. counttomark { counttomark 1 sub def } repeat pop
  25. % We implement readimage and sizeimage using the following 3 otherwise
  26. % undocumented lower-level operators:
  27. %
  28. % <x> <y> <width> <height> <matrix> .sizeimagebox
  29. % <dev_x> <dev_y> <dev_width> <dev_height> <matrix>
  30. %
  31. % - .sizeimageparams <bits/sample> <multiproc> <ncolors>
  32. %
  33. % <device> <x> <y> <width> <max_height> <alpha?> <std_depth|null>
  34. % <string> .getbitsrect <height> <substring>
  35. %
  36. % NOTE: These operators are subject to change without notice!
  37. % Implement readimage using .getbitsrect. Experimentation on a NeXT system
  38. % shows that the data is always returned in order of increasing device Y,
  39. % regardless of the CTM.
  40. %
  41. % Note that we can't make stack protection work for this operator,
  42. % because it must remove its operands from the stack before calling
  43. % the supplied procedure(s).
  44. /readimage { % <x> <y> <width> <height> <proc> [... <procN-1>]
  45. % <string> <alpha?> readimage -
  46. .sizeimageparams exch {
  47. % multiproc = true. If N > 1, store the procedures in an array.
  48. exch pop 1 index { 1 add } if
  49. % Stack: ... string alpha? nprocs
  50. dup 1 eq {
  51. pop false % only 1 procedure, multiproc is irrelevant
  52. } {
  53. dup array 4 1 roll 3 add 2 roll astore 3 1 roll true
  54. } ifelse
  55. } {
  56. % multiproc = false.
  57. pop pop false
  58. } ifelse
  59. % Map the rectangle to device coordinates.
  60. % Stack: x y w h proc(s) str alpha? multi?
  61. 8 -4 roll matrix .sizeimagebox pop 8 4 roll
  62. % Make sure we allocate the operand array in local VM
  63. % to avoid a possible invalidaccess.
  64. .currentglobal false .setglobal 9 1 roll
  65. exch { 1 } { 0 } ifelse exch % alpha is last, if present
  66. exch 4 1 roll 8 array astore exch .setglobal
  67. { % Read out a block of scan lines and pass them to the procedure.
  68. % Stack: [x y w h alpha? proc(s) str multi?] -- we must consume this.
  69. dup 3 get 0 eq { pop exit } if
  70. aload 9 1 roll pop exch pop currentdevice 7 1 roll
  71. % Always read out the data as standard (not native) pixels.
  72. .sizeimageparams pop pop exch .getbitsrect
  73. % Stack: [x y w h alpha? proc(s) str multi?] hread substr
  74. 3 -1 roll
  75. % Stack: hread substr [x y w h alpha? proc(s) str multi?]
  76. dup 1 2 copy get 5 index add put
  77. % Stack: hread substr [x y' w h alpha? proc(s) str multi?]
  78. dup 3 2 copy get 6 -1 roll sub put
  79. % Stack: substr [x y' w h' alpha? proc(s) str multi?]
  80. dup 5 get exch 7 get {
  81. % multiproc = true, pass each plane to a different procedure.
  82. % Stack: substr procs
  83. 0 1 2 index length 1 sub {
  84. % Push 1 plane and its procedure under the top 2 elements.
  85. % Stack: ... substr procs plane#
  86. 2 index length 2 index length idiv % bytes per plane
  87. dup 2 index mul exch
  88. % Stack: ... substr procs plane# start length
  89. 4 index 3 1 roll getinterval 4 1 roll
  90. 2 copy get 4 1 roll pop
  91. } for
  92. exch pop length 2 mul .execn
  93. } {
  94. % multiproc = false, just call the procedure.
  95. exec
  96. } ifelse
  97. } //systemdict /exec get 3 packedarray cvx loop
  98. } bind odef
  99. %
  100. % <w> <h> <bpc> <mtx> <dsrc0> ... <multi> <ncomp> alphaimage -
  101. %
  102. img_utils_dict begin
  103. /.alphaimage where
  104. {
  105. pop
  106. .currentglobal true .setglobal
  107. /alphaimage
  108. {
  109. //true
  110. //.colorimage
  111. stopped
  112. { /alphaimage .systemvar $error /errorname get signalerror }
  113. if
  114. }
  115. .bind systemdict begin odef end
  116. .setglobal
  117. }
  118. if
  119. end
  120. % Implement sizeimage using lower-level operators.
  121. /sizeimage { % <x> <y> <width> <height> <matrix> sizeimage
  122. % <devwidth> <devheight> <bits/sample> <matrix>
  123. % <multiproc> <ncolors>
  124. .sizeimagebox 5 -2 roll pop pop
  125. .sizeimageparams 3 -1 roll 4 1 roll
  126. } bind odef