home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / inne / gs300ini / viewgif.ps < prev    next >
Encoding:
Text File  |  1994-08-02  |  4.1 KB  |  138 lines

  1. %    Copyright (C) 1989, 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % viewgif.ps
  16. % Display a GIF file.
  17.  
  18. /read1            % <file> read1 <int>
  19.  { read pop
  20.  } bind def
  21. /read2            % <file> read2 <int>
  22.  { dup read1 exch read1 8 bitshift add
  23.  } bind def
  24.  
  25. /readGIFheader        % <file> readGIFheader <dict>
  26.  { 20 dict begin
  27.    dup 6 string readstring pop
  28.    dup (GIF87a) eq exch (GIF89a) eq or not
  29.     { (Not a GIF file.\n) print cleartomark stop
  30.     } if
  31.    dup read2 /Width exch def
  32.    dup read2 /Height exch def
  33.    dup read1
  34.    dup 128 ge /GlobalColor exch def
  35.    dup -4 bitshift 7 and 1 add /BitsPerPixel exch def    %***BOGUS?***
  36.    dup 8 and 0 ne /PaletteSorted exch def
  37.    7 and 1 add dup /BitsPerPixel exch def
  38.      1 exch bitshift /PaletteSize exch def
  39.    dup read1 /BackgroundIndex exch def
  40.    dup read1 15 add 64 div /AspectRatio exch def
  41.    GlobalColor
  42.     { PaletteSize 3 mul string readstring pop
  43.       /GlobalPalette exch def
  44.     } if
  45.    currentdict end
  46.  } bind def
  47.  
  48. /readGIFimageHeader    % <file> readGIFimageHeader <dict>
  49.             % Note: GIF header must be on dict stack
  50.  { 10 dict begin
  51.     { dup read1
  52.       dup (!) 0 get ne { exit } if pop        % extension
  53.       dup read1 pop
  54.        { dup read1 dup 0 eq { pop exit } if { dup read1 pop } repeat
  55.        } loop
  56.     } loop
  57.    (,) 0 get ne
  58.     { (Not a GIF image.\n) print stop
  59.     } if
  60.    dup read2 /Left exch def
  61.    dup read2 /Top exch def
  62.    dup read2 /Width exch def
  63.    dup read2 /Height exch def
  64.    dup read1
  65.    dup 128 ge /LocalColor exch def
  66.    dup 64 and 0 ne /Interlaced exch def
  67.    LocalColor
  68.     { 7 and 1 add /BitsPerPixel exch def
  69.       1 BitsPerPixel bitshift 3 mul string readstring pop
  70.       /Palette exch def
  71.     }
  72.     { pop pop /Palette GlobalPalette def
  73.     }
  74.    ifelse
  75.    currentdict end
  76.  } bind def
  77.  
  78. /viewGIF        % <file|string> viewGIF -
  79.  { save 20 dict begin
  80.    /saved exch def
  81.    dup type /stringtype eq { (r) file } if
  82.    /F exch def
  83.    F readGIFheader /Header exch def
  84.      currentdict Header end begin begin
  85.    DEBUG { Header { exch == == } forall (----------------\n) print flush } if
  86.    F readGIFimageHeader /ImageHeader exch def
  87.      currentdict ImageHeader end begin begin
  88.    DEBUG { ImageHeader { exch == == } forall (----------------\n) print flush } if
  89.    /D F
  90.    <<    /InitialCodeLength F read1
  91.     /FirstBitLowOrder true
  92.     /BlockData true
  93.     /EarlyChange 0
  94.    >> /LZWDecode filter def
  95.  
  96.    [/Indexed /DeviceRGB 1 BitsPerPixel bitshift 1 sub Palette] setcolorspace
  97.    matrix currentmatrix
  98.    0 1 3 { 2 copy get dup 0 ne { dup abs div } if 3 copy put pop pop } for
  99.    setmatrix
  100.    <<    /ImageType 1
  101.     /ImageMatrix [1 0 0 -1 0 Height]
  102.     /BitsPerComponent 8
  103.     /Decode [0 255]
  104.    Interlaced
  105.     {    /Width Width   /Height 1
  106.     /row Width string def
  107.     /DataSource row
  108.       >> /I exch def
  109.       /inter        % <num> <denom> inter -
  110.        { /denom exch def   /num exch def
  111.          gsave
  112.      /lines Height denom 1 sub add num sub denom idiv def
  113.      0 num neg translate
  114.      /delta denom neg def
  115.      lines
  116.       { D row readstring pop pop
  117.         I image
  118.         0 delta translate
  119.       } repeat
  120.      grestore
  121.        }
  122.       bind def
  123.       0 8 inter
  124.       4 8 inter
  125.       2 4 inter
  126.       1 2 inter
  127.     }
  128.     {    /Width Width   /Height Height
  129.     /DataSource D
  130.       >> image
  131.     }
  132.    ifelse
  133.    saved end end end restore
  134.  } bind def   
  135.