home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2002 February / INTERNET88.ISO / pc / software / windows / bits / pdf995 / data1.cab / Program_Executable_Files / res / viewgif.ps < prev    next >
Encoding:
Text File  |  2001-12-08  |  4.8 KB  |  164 lines

  1. %    Copyright (C) 1989, 1992, 1993, 1998 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of GNU Ghostscript.
  3. % GNU Ghostscript is distributed in the hope that it will be useful, but
  4. % WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  5. % to anyone for the consequences of using it or for whether it serves any
  6. % particular purpose or works at all, unless he says so in writing.  Refer
  7. % to the GNU General Public License for full details.
  8. % Everyone is granted permission to copy, modify and redistribute GNU
  9. % Ghostscript, but only under the conditions described in the GNU General
  10. % Public License.  A copy of this license is supposed to have been given
  11. % to you along with GNU Ghostscript so you can know your rights and
  12. % responsibilities.  It should be in a file named COPYING.  Among other
  13. % things, the copyright notice and this notice must be preserved on all
  14. % copies.
  15.  
  16. % $RCSfile: viewgif.ps,v $ $Revision: 1.2.2.1 $
  17. % viewgif.ps
  18. % Display a GIF file.
  19.  
  20. /read1            % <file> read1 <int>
  21.  { read pop
  22.  } bind def
  23. /read2            % <file> read2 <int>
  24.  { dup read1 exch read1 8 bitshift add
  25.  } bind def
  26.  
  27. /readGIFheader        % <file> readGIFheader <dict>
  28.  { 20 dict begin
  29.    dup 6 string readstring pop
  30.    dup (GIF87a) eq exch (GIF89a) eq or not
  31.     { (Not a GIF file.\n) print cleartomark stop
  32.     } if
  33.    dup read2 /Width exch def
  34.    dup read2 /Height exch def
  35.    dup read1
  36.    dup 128 ge /GlobalColor exch def
  37.    dup -4 bitshift 7 and 1 add /BitsPerPixel exch def    %***BOGUS?***
  38.    dup 8 and 0 ne /PaletteSorted exch def
  39.    7 and 1 add dup /BitsPerPixel exch def
  40.      1 exch bitshift /PaletteSize exch def
  41.    dup read1 /BackgroundIndex exch def
  42.    dup read1 15 add 64 div /AspectRatio exch def
  43.    GlobalColor
  44.     { PaletteSize 3 mul string readstring pop
  45.       /GlobalPalette exch def
  46.     } if
  47.    currentdict end
  48.  } bind def
  49.  
  50. /readGIFimageHeader    % <file> readGIFimageHeader <dict>
  51.             % Note: GIF header must be on dict stack
  52.  { 10 dict begin
  53.     { dup read1
  54.       dup (!) 0 get ne { exit } if pop        % extension
  55.       dup read1 pop
  56.        { dup read1 dup 0 eq { pop exit } if { dup read1 pop } repeat
  57.        } loop
  58.     } loop
  59.    (,) 0 get ne
  60.     { (Not a GIF image.\n) print stop
  61.     } if
  62.    dup read2 /Left exch def
  63.    dup read2 /Top exch def
  64.    dup read2 /Width exch def
  65.    dup read2 /Height exch def
  66.    dup read1
  67.    dup 128 ge /LocalColor exch def
  68.    dup 64 and 0 ne /Interlaced exch def
  69.    LocalColor
  70.     { 7 and 1 add /BitsPerPixel exch def
  71.       1 BitsPerPixel bitshift 3 mul string readstring pop
  72.       /Palette exch def
  73.     }
  74.     { pop pop /Palette GlobalPalette def
  75.     }
  76.    ifelse
  77.    currentdict end
  78.  } bind def
  79.  
  80. /imageGIF        % <imagedict> imageGIF
  81.  { /ImageOut where
  82.     { pop
  83.         % We know BitsPerComponent = 8, Decode = [0 255].
  84.         % and there is only a single data source which is
  85.         % either a filter or a string whose size is exactly
  86.         % the width of the row.
  87.       dup /DataSource get dup type /stringtype eq
  88.        { ImageOut exch writestring
  89.        }
  90.        { pop dup /Width get string
  91.      1 index /Height get
  92.       { 1 index /DataSource get 1 index readstring pop
  93.         ImageOut exch writestring
  94.       }
  95.      repeat pop pop
  96.        }
  97.       ifelse 
  98.     }
  99.     { image
  100.     }
  101.    ifelse
  102.  } bind def
  103.  
  104. /viewGIF        % <file|string> viewGIF -
  105.  { save 20 dict begin
  106.    /saved exch def
  107.    dup type /stringtype eq { (r) file } if
  108.    /F exch def
  109.    /ImageOutFile where { /ImageOut ImageOutFile (w) file def } if
  110.    F readGIFheader /Header exch def
  111.      currentdict Header end begin begin
  112.    DEBUG { Header { exch == == } forall (----------------\n) print flush } if
  113.    F readGIFimageHeader /ImageHeader exch def
  114.      currentdict ImageHeader end begin begin
  115.    DEBUG { ImageHeader { exch == == } forall (----------------\n) print flush } if
  116.    /D F
  117.    <<    /InitialCodeLength F read1
  118.     /FirstBitLowOrder true
  119.     /BlockData true
  120.     /EarlyChange 0
  121.    >> /LZWDecode filter def
  122.  
  123.    [/Indexed /DeviceRGB 1 BitsPerPixel bitshift 1 sub Palette] setcolorspace
  124.    matrix currentmatrix
  125.    0 1 3 { 2 copy get dup 0 ne { dup abs div } if 3 copy put pop pop } for
  126.    setmatrix
  127.    <<    /ImageType 1
  128.     /ImageMatrix [1 0 0 -1 0 Height]
  129.     /BitsPerComponent 8
  130.     /Decode [0 255]
  131.    Interlaced
  132.     {    /Width Width   /Height 1
  133.     /row Width string def
  134.     /DataSource row
  135.       >> /I exch def
  136.       /inter        % <num> <denom> inter -
  137.        { /denom exch def   /num exch def
  138.          gsave
  139.      /lines Height denom 1 sub add num sub denom idiv def
  140.      0 1 lines 1 sub {
  141.        Height exch denom mul num add sub
  142.        I /ImageMatrix get 5 3 -1 roll put
  143.        D row readstring pop pop
  144.        I imageGIF
  145.      } for
  146.      grestore
  147.        }
  148.       bind def
  149.       0 8 inter
  150.       4 8 inter
  151.       2 4 inter
  152.       1 2 inter
  153.     }
  154.     {    /Width Width   /Height Height
  155.     /DataSource D
  156.       >> imageGIF
  157.     }
  158.    ifelse
  159.    saved end end end restore
  160.  } bind def   
  161.