home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 September / PCWK996.iso / sharewar / 95 / narzedzi / ambra / ambr32a1.exe / FILE / ARCHIVE.Z / ACROBAT / VIEWER32.EXE / PSPROCSET / 9 < prev   
Text File  |  1996-02-22  |  5KB  |  156 lines

  1. %%BeginFile: pdfimg1c.prc
  2. %%Copyright: Copyright 1987-1993 Adobe Systems Incorporated. All Rights Reserved.
  3. % PDF Image Operators for Level 1 (Color)
  4. % This code is based on Glenn Reid's and Scott Byer's emulation of the
  5. % colorimage operator. This particular version of the code does not handle
  6. % multiple data sources and uses a less efficient but more accurate conversion
  7. % between RGB and CMYK values to gray space. The original code used the
  8. % following formulas:
  9. %    gray = 0.25R + 0.5G + 0.25B    gray = 1 - (C+M+Y+K)/4
  10. % The recommended conversions on page 304-305 of the PLRM are as follows:
  11. %    gray = 0.3R + 0.59G + 0.11B    gray = 1 - min(1, 0.3C+0.59M+0.11Y+K) 
  12. % Using these formulas results in a better representation of the image.
  13. % In fact, the image will look the same as if it was drawn on a B/W device
  14. % that has the colorimage operator available albeit *millions* of times slower.
  15.  
  16. PDF /PDFImage get begin
  17.  
  18. Level2? not StartLoad {
  19. % Install the image DeviceRGB Handler
  20. /DeviceRGB [ 3 
  21.     { 
  22.         Width Height BitsPerComponent ImageMatrix ImageFilter 3 
  23.         ColorImage
  24.     } bind
  25. ] InstallImage
  26. % Install the image DeviceCMYK Handler
  27. /DeviceCMYK [ 4
  28.     { 
  29.         Width Height BitsPerComponent ImageMatrix ImageFilter 4 
  30.         ColorImage
  31.     } bind
  32. ] InstallImage
  33.  
  34. % Utility function: ColorImage?
  35. % ColorImage? contains true if the colorimage operator is defined, 
  36. % false otherwise
  37. /ColorImage? /colorimage where { pop true } { false } ifelse def
  38. % /ColorImage? false def
  39.  
  40. % Depending on the machine, color image may or may not be available.
  41. % We will want to provide an emulation if it is not.
  42. ColorImage? StartLoad {
  43.     /ColorImage { false exch colorimage } bd
  44. } EndLoad    % ColorImage?
  45. ColorImage? not StartLoad {
  46.     % Utility procedures
  47.     /SetupColorImage {
  48.         /CIConv 255 2 BitsPerComponent exp 1 sub div pv    % Threshold
  49.         /CIMask 0 not BitsPerComponent bitshift not pv     % Mask off bits
  50.         /CIBSelect BitsPerComponent 1 sub not 7 and pv
  51.         /CIBufferExp CIWidth string pv
  52.     } bd
  53.  
  54.     /rgbtogray {    % r g b rgbtogray gray
  55.         0.11 mul exch 0.59 mul add exch 0.3 mul add round cvi
  56.     } bd
  57.     /cmyktogray {    % c m y k cmyktogray gray
  58.         exch 0.11 mul add exch 0.59 mul add exch 0.3 mul add round cvi
  59.         dup 255 gt { pop 255 } if
  60.         255 exch sub    
  61.     } bd
  62.  
  63.     % Optimized for 8 bits / sample for RGB
  64.     /FastRGB {
  65.         CIDataProc dup                        % str str
  66.         0 3 2 index length 3 sub 
  67.         {                                    % str str loopcnt
  68.             dup 3 idiv                        % str str loopcnt idx
  69.             2 index 2 index get                % str str loopcnt idx r
  70.             3 index 3 index 1 add get        % str str loopcnt idx r g
  71.             4 index 4 index 2 add get        % str str loopcnt idx r g b
  72.             rgbtogray                        % str str loopcnt idx gray
  73.             3 -1 roll pop put dup            % str str
  74.         } for
  75.         0 exch length 3 idiv getinterval % str'
  76.     } bd
  77.     % Optimized for 8 bits / sample for CMYK
  78.     /FastCMYK {
  79.         CIDataProc dup                % str str
  80.         0 4 2 index length 4 sub {        % str str loopcnt
  81.             dup 4 idiv                    % str str loopcnt idx 
  82.             2 index 2 index get            % str str loopcnt idx c
  83.             3 index 3 index 1 add get    % str str loopcnt idx c m
  84.             4 index 4 index 2 add get    % str str loopcnt idx c m y
  85.             5 index 5 index 3 add get    % str str loopcnt idx c m y k
  86.             cmyktogray                    % str str loopcnt idx gray
  87.             3 -1 roll pop put dup        % str str
  88.         } for
  89.         0 exch length 4 idiv getinterval % str'
  90.     } bd
  91.     % Slower emulation for 1, 2, and 4 bits / sample
  92.     /SlowRGB  {
  93.         CIDataProc pop                    % Get scan line
  94.         % Loop over each sample
  95.         0 1 CIWidth 1 sub {                            % samp                    
  96.             % Loop over each component
  97.             0 1 2 {                                        % samp src 
  98.                 1 index 3 mul add CIBPC mul            % samp src nbit
  99.                 CIBSelect 1 index 1 index and sub        % samp src nbit bit
  100.                 exch 8 idiv                                % samp src bit byte
  101.                 CIBuffer exch get                     % samp src bit val
  102.                 exch neg bitshift CIMask and CIConv mul    exch
  103.             } for
  104.             4 1 roll rgbtogray                            % samp gray
  105.             CIBufferExp 3 1 roll put
  106.         } for 
  107.         CIBufferExp
  108.     } bd
  109.     % Slower emulation for CMYK 1, 2, and 4 bits / sample
  110.     /SlowCMYK  {
  111.         CIDataProc pop                    % Get first sample string
  112.         % Loop over each sample
  113.         0 1 CIWidth 1 sub {                            % samp                    
  114.             % Loop over each component of each sample
  115.             0 1 3 {                                        % samp src 
  116.                 1 index 4 mul add CIBPC mul            % samp src nbit
  117.                 CIBSelect 1 index 1 index and sub        % samp src nbit bit
  118.                 exch 8 idiv                                % samp src bit byte
  119.                 CIBuffer exch get                     % samp src bit val
  120.                 exch neg bitshift CIMask and CIConv mul    exch
  121.             } for
  122.             5 1 roll cmyktogray                            % samp gray
  123.             CIBufferExp 3 1 roll put
  124.         } for 
  125.         CIBufferExp
  126.     } bd
  127.  
  128.     /ColorImage {    % w h bpc im if #comps 
  129.         % This emulation does not handle multiple sources.
  130.         /CINumComps exch pv
  131.         /CIDataProc exch pv
  132.         /CIIMatrix exch pv
  133.         /CIBPC exch pv
  134.         /CIHeight exch pv
  135.         /CIWidth exch pv
  136.         
  137.         CIWidth CIHeight 8 CIIMatrix
  138.         % Load the correct data acquisition procedure, depends on the 
  139.         % number of color components, and the number of bits per component.
  140.         CINumComps 1 eq { /CIDataProc } {
  141.             CINumComps 3 eq {
  142.                 CIBPC 8 eq { /FastRGB 
  143.                 } { SetupColorImage /SlowRGB } ifelse
  144.             } {
  145.                 CIBPC 8 eq { /FastCMYK 
  146.                 } { SetupColorImage /SlowCMYK } ifelse
  147.             } ifelse
  148.         } ifelse
  149.         load image
  150.     } bd            
  151. } EndLoad
  152.  
  153. } EndLoad % Level2? not
  154.  
  155. end % PDFImage
  156. %%EndFile