home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / gs_l2img.ps < prev    next >
Text File  |  2002-02-22  |  6KB  |  185 lines

  1. %    Copyright (C) 1995, 1996 Aladdin Enterprises.  All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: gs_l2img.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
  14. % Emulate the Level 2 dictionary-based image operator in Level 1,
  15. % except for Interpolate (ignored) and MultipleDataSources = true;
  16. % also, we require that the data source be either a procedure of a
  17. % particular form or a stream, not a string or a general procedure.
  18.  
  19. % pdf2ps copies the portion of this file from %BEGIN to %END if Level 1
  20. % compatible output is requested.
  21.  
  22. /currentglobal where
  23.  { pop currentglobal { setglobal } true setglobal }
  24.  { { } }
  25. ifelse
  26.  
  27. /packedarray where
  28.  { pop }
  29.  { /packedarray { array astore readonly } bind def }
  30. ifelse
  31.  
  32. %BEGIN
  33.  
  34. 11 dict /.csncompdict 1 index def begin
  35.   /DeviceGray { 1 /setgray load } bind def
  36.   /DeviceRGB { 3 /setrgbcolor load } bind def
  37.   /DeviceCMYK { 4 /setcmykcolor load } bind def
  38.   /Indexed
  39.    { dup 1 index 1 get //.csncompdict exch get exec
  40.         % Stack: [/Indexed base hival map] ncomp basesetcolor
  41.      3 -1 roll 3 get mark 3 1 roll
  42.         % Stack: ncomp -mark- basesetcolor map
  43.      dup type /stringtype eq
  44.       {  { -
  45.         { exch round cvi get 255 div
  46.         }
  47.        -
  48.         { exch round cvi 3 mul 2 copy 2 copy get 255 div
  49.           3 1 roll 1 add get 255 div
  50.           4 2 roll 2 add get 255 div
  51.         }
  52.         { exch round cvi 4 mul 2 copy 2 copy 2 copy get 255 div
  53.           3 1 roll 1 add get 255 div
  54.           4 2 roll 2 add get 255 div
  55.           5 3 roll 3 add get 255 div
  56.         }
  57.      }
  58.     4 index get aload pop counttomark -1 roll
  59.       }
  60.       { /exec load 3 -1 roll
  61.         % Stack: -mark- mapproc --exec-- basesetcolor
  62.       }
  63.      ifelse .packtomark cvx
  64.      exch pop 1 exch
  65.    } bind def
  66.   /Separation
  67.    { dup 2 index //.csncompdict exch get exec
  68.         % Stack: [/Separation name alt xform] ncomp altsetcolor
  69.      3 -1 roll 3 get /exec load 3 -1 roll 3 array astore readonly cvx
  70.      exch pop 1 exch
  71.    } bind def
  72.     % Substitute device spaces for CIE spaces.
  73.   /CIEBasedA /DeviceGray load def
  74.   /CIEBasedABC /DeviceRGB load def
  75.   /CIEBasedDEF /DeviceRGB load def
  76.   /CIEBasedDEFG /DeviceCMYK load def
  77. end
  78.  
  79. /.packtomark { counttomark packedarray exch pop } bind def
  80.  
  81. /.csinextbits        % - .csinextbits <bits>
  82.             % Uses b, nnb, i, row, mask, BitsPerComponent;
  83.             % sets b, nnb, i.
  84.  { /nnb nnb BitsPerComponent add
  85.     { dup 0 le { exit } if
  86.       /b b 8 bitshift row i get add def
  87.       /i i 1 add def  8 sub
  88.     }
  89.    loop def
  90.    b nnb bitshift mask and
  91.  } bind def
  92.  
  93. % Note that the ColorSpace key must be present in the image dictionary.
  94. /.colorspaceimage        % <imagedict> .colorspaceimage -
  95.  { save exch
  96.    dup length 15 add dict begin { cvlit def } forall
  97.    ColorSpace dup dup type /nametype ne { 0 get } if
  98.    .csncompdict exch get exec
  99.      /setpixelcolor exch def  /ncomp exch def  pop
  100.    /row ncomp BitsPerComponent mul Width mul 7 add 8 idiv string def
  101.       /mask 1 BitsPerComponent bitshift 1 sub def
  102.       /nextbits BitsPerComponent 8 eq
  103.        { { row i get /i i 1 add def } }
  104.        { /.csinextbits load }
  105.       ifelse def
  106.       /nextpixel mark 0 2 ncomp 1 sub 2 mul
  107.        { /nextbits cvx exch
  108.      Decode exch 2 getinterval
  109.      dup aload pop exch sub
  110.      dup mask eq { pop } { mask div /mul load 3 -1 roll } ifelse
  111.      0 get dup 0 eq { pop } { /sub load 3 -1 roll } ifelse
  112.        }
  113.       for
  114.       /setpixelcolor load dup type /operatortype ne { /exec load } if
  115.       .packtomark cvx def
  116.       /readrow
  117.         /DataSource load dup type
  118.         dup /arraytype eq exch /packedarraytype eq or
  119.     {    % Must be { <file> <string> ... }
  120.       aload length 1 add array /pop load exch astore
  121.       dup 1 row put cvx
  122.     }
  123.     { pop
  124.         % Adobe requires readstring to signal an error if given
  125.         % an empty string.  Work around this nonsense here.
  126.           row length 0 eq
  127.        { { } }
  128.        { { DataSource row readstring pop pop } }
  129.       ifelse
  130.     }
  131.       ifelse def
  132.       ImageMatrix matrix invertmatrix concat
  133.       /imat matrix def
  134.       0 1 Height 1 sub
  135.        { imat 5 3 -1 roll neg put
  136.      readrow
  137.      /b 0 def  /nnb 0 def  /i 0 def
  138.      0 1 Width 1 sub
  139.       { imat 4 3 -1 roll neg put nextpixel
  140.         1 1 true imat {<80>} imagemask
  141.       }
  142.      for
  143.        }
  144.       for
  145.    end restore
  146.  } bind def
  147.  
  148. %END
  149. exec
  150. currentfile closefile
  151.  
  152. % Patch for testing.
  153. /.cincompdict 3 dict begin
  154.   1 { {0 1} {/DeviceGray} } def
  155.   3 { {0 1 0 1 0 1} {/DeviceRGB} } def
  156.   4 { {0 1 0 1 0 1 0 1} {/DeviceCMYK} } def
  157. currentdict end def
  158. /.imagekeys [
  159.   /Decode /DataSource /ImageMatrix /BitsPerComponent /Height /Width
  160. ] def
  161. /colorimage        % <width> <height> <bits/comp> <matrix>
  162.             %   <datasrc> false <ncomp> colorimage -
  163.  { 1 index { /colorimage load /rangecheck signalerror } if exch pop
  164.    //.cincompdict exch get exec
  165.    7 dict begin /ColorSpace exch cvlit def
  166.    .imagekeys { exch cvlit def } forall
  167.    currentdict end .colorspaceimage
  168.  } bind odef
  169. /image
  170.  { dup type /dicttype ne
  171.     { 7 dict begin /ColorSpace /DeviceGray def [0 1] 
  172.       .imagekeys { exch cvlit def } forall
  173.       currentdict end
  174.     }
  175.     { dup length 1 add dict .copydict dup /ColorSpace currentcolorspace put
  176.     }
  177.    ifelse
  178.    .colorspaceimage
  179.  } bind odef
  180.  
  181. exec
  182.