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.

151 lines
5.7 KiB

1 month ago
  1. % Copyright (C) 2001-2023 Artifex Software, Inc.
  2. % All Rights Reserved.
  3. %
  4. % This software is provided AS-IS with no warranty, either express or
  5. % implied.
  6. %
  7. % This software is distributed under license and may not be copied,
  8. % modified or distributed except as expressly authorized under the terms
  9. % of the license contained in the file LICENSE in this distribution.
  10. %
  11. % Refer to licensing information at http://www.artifex.com or contact
  12. % Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  13. % CA 94129, USA, for further information.
  14. %
  15. % viewrgb.ps
  16. % Display a raw RGB file created by -sDEVICE=bitrgb.
  17. % If SCALE is defined, maps input pixels to output pixels with that scale;
  18. % if SCALE is undefined, scales the image to fit the page.
  19. % If BITS is defined, it is the number of bits per sample (1,2,8,12).
  20. % NB: BITS=4 (corresponding to -dGrayValues=16) is not supported.
  21. % if BITS is undefined, its default value is 1.
  22. /viewrgb { % <filename> <width> viewrgb -
  23. 20 dict begin
  24. /w exch def
  25. /fname exch def
  26. /bpc /BITS where { pop BITS } { 1 } ifelse def
  27. /f fname (r) file def
  28. mark fname status pop pop pop /flen exch def cleartomark
  29. /h flen
  30. w [ 0 4 8 0 0 0 0 0 24 ] bpc get
  31. dup 0 eq {
  32. (*** -dBITS=) print bpc =print ( is not supported. ***) = flush
  33. quit
  34. } if
  35. mul 7 add 8 idiv idiv def
  36. QUIET not { (Dimensions: ) print [w h] == flush } if
  37. % Set up scaling.
  38. /SCALE where {
  39. pop
  40. % Map pixels SCALE-for-1. Assume orthogonal transformation.
  41. SCALE 1 0 dtransform add abs div
  42. SCALE 0 1 dtransform add abs div
  43. } {
  44. % Scale the image (uniformly) to fit the page.
  45. clippath pathbbox pop pop translate
  46. pathbbox 3 -1 roll sub h div
  47. 3 1 roll exch sub w div .min dup
  48. } ifelse scale
  49. bpc 1 eq {
  50. [ /Indexed /DeviceRGB 15 <
  51. 000000
  52. 0000FF
  53. 00FF00
  54. 00FFFF
  55. FF0000
  56. FF00FF
  57. FFFF00
  58. FFFFFF
  59. 000000
  60. 0000FF
  61. 00FF00
  62. 00FFFF
  63. FF0000
  64. FF00FF
  65. FFFF00
  66. FFFFFF
  67. >
  68. ] setcolorspace
  69. /BPC 4 def % change to 4 bit indexed
  70. } {
  71. bpc 2 eq {
  72. [ /Indexed /DeviceRGB 255 <
  73. 000000 000055 0000AA 0000FF
  74. 005500 005555 0055AA 0055FF
  75. 00AA00 00AA55 00AAAA 00AAFF
  76. 00FF00 00FF55 00FFAA 00FFFF
  77. 550000 550055 5500AA 5500FF
  78. 555500 555555 5555AA 5555FF
  79. 55AA00 55AA55 55AAAA 55AAFF
  80. 55FF00 55FF55 55FFAA 55FFFF
  81. AA0000 AA0055 AA00AA AA00FF
  82. AA5500 AA5555 AA55AA AA55FF
  83. AAAA00 AAAA55 AAAAAA AAAAFF
  84. AAFF00 AAFF55 AAFFAA AAFFFF
  85. FF0000 FF0055 FF00AA FF00FF
  86. FF5500 FF5555 FF55AA FF55FF
  87. FFAA00 FFAA55 FFAAAA FFAAFF
  88. FFFF00 FFFF55 FFFFAA FFFFFF
  89. 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
  90. 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
  91. 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
  92. 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
  93. 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
  94. 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
  95. 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
  96. 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
  97. 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
  98. 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
  99. 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
  100. 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
  101. 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
  102. 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
  103. 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
  104. 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
  105. >
  106. ] setcolorspace
  107. /BPC 8 def % change to 4 bit indexed
  108. } {
  109. /DeviceRGB setcolorspace
  110. /BPC bpc def
  111. }
  112. ifelse
  113. }
  114. ifelse
  115. << /ImageType 1
  116. /Width w
  117. /Height h
  118. /BitsPerComponent BPC
  119. /ImageMatrix [1 0 0 -1 0 h]
  120. /DataSource f
  121. /MultipleDataSources false
  122. bpc 4 lt { /Decode [ 0 [ 0 15 255 ] bpc get ] } { /Decode [ 0 1 0 1 0 1 ] } ifelse
  123. >> image
  124. showpage
  125. f closefile
  126. end
  127. } bind def
  128. % If the program was invoked from the command line, run it now.
  129. [ .shellarguments {
  130. counttomark 2 eq {
  131. cvi viewrgb
  132. } {
  133. cleartomark
  134. (\nUsage: gs -- viewrgb.ps filename.rgb width\n) print
  135. ( e.g.: gs -- viewrgb.ps my.rgb 2550\n) print flush
  136. ( -dSCALE=### sets specific scaling \(default = 1.0\)) = flush
  137. ( -dBITS=# sets the BitsPerComponent \(1, 2, 8, 12] \(default = 1\)) = flush
  138. (From version 9.50 you must supply permissions for this program to read the input file(s)\n) print flush
  139. (either by using -dNOSAFER or by supplying --permit-file-read=<filename>\n) = flush
  140. } ifelse
  141. } {
  142. pop
  143. } ifelse