home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Actualizar / Impressora_PDF / converter.exe / GPLGS / viewgif.ps < prev    next >
Text File  |  2003-04-13  |  5KB  |  161 lines

  1. %    Copyright (C) 1989, 1992, 1993, 1998 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: viewgif.ps,v 1.5 2003/04/12 18:08:18 ray Exp $
  14. % viewgif.ps
  15. % Display a GIF file.
  16.  
  17. /read1            % <file> read1 <int>
  18.  { read pop
  19.  } bind def
  20. /read2            % <file> read2 <int>
  21.  { dup read1 exch read1 8 bitshift add
  22.  } bind def
  23.  
  24. /readGIFheader        % <file> readGIFheader <dict>
  25.  { 20 dict begin
  26.    dup 6 string readstring pop
  27.    dup (GIF87a) eq exch (GIF89a) eq or not
  28.     { (Not a GIF file.\n) print cleartomark stop
  29.     } if
  30.    dup read2 /Width exch def
  31.    dup read2 /Height exch def
  32.    dup read1
  33.    dup 128 ge /GlobalColor exch def
  34.    dup -4 bitshift 7 and 1 add /BitsPerPixel exch def    %***BOGUS?***
  35.    dup 8 and 0 ne /PaletteSorted exch def
  36.    7 and 1 add dup /BitsPerPixel exch def
  37.      1 exch bitshift /PaletteSize exch def
  38.    dup read1 /BackgroundIndex exch def
  39.    dup read1 15 add 64 div /AspectRatio exch def
  40.    GlobalColor
  41.     { PaletteSize 3 mul string readstring pop
  42.       /GlobalPalette exch def
  43.     } if
  44.    currentdict end
  45.  } bind def
  46.  
  47. /readGIFimageHeader    % <file> readGIFimageHeader <dict>
  48.             % Note: GIF header must be on dict stack
  49.  { 10 dict begin
  50.     { dup read1
  51.       dup (!) 0 get ne { exit } if pop        % extension
  52.       dup read1 pop
  53.        { dup read1 dup 0 eq { pop exit } if { dup read1 pop } repeat
  54.        } loop
  55.     } loop
  56.    (,) 0 get ne
  57.     { (Not a GIF image.\n) print stop
  58.     } if
  59.    dup read2 /Left exch def
  60.    dup read2 /Top exch def
  61.    dup read2 /Width exch def
  62.    dup read2 /Height exch def
  63.    dup read1
  64.    dup 128 ge /LocalColor exch def
  65.    dup 64 and 0 ne /Interlaced exch def
  66.    LocalColor
  67.     { 7 and 1 add /BitsPerPixel exch def
  68.       1 BitsPerPixel bitshift 3 mul string readstring pop
  69.       /Palette exch def
  70.     }
  71.     { pop pop /Palette GlobalPalette def
  72.     }
  73.    ifelse
  74.    currentdict end
  75.  } bind def
  76.  
  77. /imageGIF        % <imagedict> imageGIF
  78.  { /ImageOut where
  79.     { pop
  80.         % We know BitsPerComponent = 8, Decode = [0 255].
  81.         % and there is only a single data source which is
  82.         % either a filter or a string whose size is exactly
  83.         % the width of the row.
  84.       dup /DataSource get dup type /stringtype eq
  85.        { ImageOut exch writestring
  86.        }
  87.        { pop dup /Width get string
  88.      1 index /Height get
  89.       { 1 index /DataSource get 1 index readstring pop
  90.         ImageOut exch writestring
  91.       }
  92.      repeat pop pop
  93.        }
  94.       ifelse 
  95.     }
  96.     { image
  97.     }
  98.    ifelse
  99.  } bind def
  100.  
  101. /viewGIF        % <file|string> viewGIF -
  102.  { save 20 dict begin
  103.    /saved exch def
  104.    dup type /stringtype eq { (r) file } if
  105.    /F exch def
  106.    /ImageOutFile where { /ImageOut ImageOutFile (w) file def } if
  107.    F readGIFheader /Header exch def
  108.      currentdict Header end begin begin
  109.    VGIFDEBUG { Header { exch == == } forall (----------------\n) print flush } if
  110.    F readGIFimageHeader /ImageHeader exch def
  111.      currentdict ImageHeader end begin begin
  112.    VGIFDEBUG { ImageHeader { exch == == } forall (----------------\n) print flush } if
  113.    /D F
  114.    <<    /InitialCodeLength F read1
  115.     /FirstBitLowOrder true
  116.     /BlockData true
  117.     /EarlyChange 0
  118.    >> /LZWDecode filter def
  119.  
  120.    [/Indexed /DeviceRGB 1 BitsPerPixel bitshift 1 sub Palette] setcolorspace
  121.    matrix currentmatrix
  122.    0 1 3 { 2 copy get dup 0 ne { dup abs div } if 3 copy put pop pop } for
  123.    setmatrix
  124.    <<    /ImageType 1
  125.     /ImageMatrix [1 0 0 -1 0 Height]
  126.     /BitsPerComponent 8
  127.     /Decode [0 255]
  128.    Interlaced
  129.     {    /Width Width   /Height 1
  130.     /row Width string def
  131.     /DataSource row
  132.       >> /I exch def
  133.       /inter        % <num> <denom> inter -
  134.        { /denom exch def   /num exch def
  135.          gsave
  136.      /lines Height denom 1 sub add num sub denom idiv def
  137.      0 1 lines 1 sub {
  138.        Height exch denom mul num add sub
  139.        I /ImageMatrix get 5 3 -1 roll put
  140.        D row readstring pop pop
  141.        I imageGIF
  142.      } for
  143.      grestore
  144.        }
  145.       bind def
  146.       0 8 inter
  147.       4 8 inter
  148.       2 4 inter
  149.       1 2 inter
  150.     }
  151.     {    /Width Width   /Height Height
  152.     /DataSource D
  153.       >> imageGIF
  154.     }
  155.    ifelse
  156.    saved end end end restore
  157.  } bind def   
  158.