GIFPARSE and GIFBUILD: New Parse the contents of a GIF file (includes LZW decompression)

Автор: Rex Swain

Дата: 1999

Источник: www.rexswain.com

The REXX program GIFPARSE.REX reads and parses the contents of a GIF file, writing to an INI-like output file. It includes a subroutine to do LZW decompression.

  • For example, executing gifparse new.gif new.ini
    reads the file new.gif (which looks like this: )
    and writes the file new.ini (shown below)

The program GIFBUILD.REX reads a file generated by GIFPARSE and builds a new GIF file accordingly. It includes a subroutine to do LZW* compression.

  • For example, executing gifbuild new.ini new2.gif
    reads the file new.ini
    and writes the file new2.gif

So, for example, if you wanted to change the shading color of new.gif from yellow-ish to cyan, you could:

  1. gifparse new.gif new.ini
  2. Edit new.ini, and in the [Global Color Table] section, change
    GCT 1 = FF D6 00 to
    GCT 1 = 00 FF FF
  3. gifbuild new.ini new2.gif

and get new2.gif (which looks like this: )


new.ini

[File]
File name = new.gif
File size = 111
[Header]
Signature = GIF
Version = 89a
[Logical Screen Descriptor]
Logical Screen Width = 28
Logical Screen Height = 11
Global Color Table Flag = 1
Color Resolution = 3
Sort Flag = 0
Size of Global Color Table = 4
Background Color Index = 0
Pixel Aspect Ratio = 0
[Global Color Table]
GCT 0 = 00 00 00
GCT 1 = FF D6 00
GCT 2 = FF FF FF
GCT 3 = 00 00 00
[Extension]
Function Code = F9
Block 1 Size = 4
Block 1 Data = 01 00 00 02
[Graphic Control Extension]
Reserved Bits = 000
Disposal Method = 0
User Input Flag = 0
Transparent Color Flag = 1
Delay time = 0
Transparent Color Index = 2
[Image Descriptor]
Image Left Origin = 0
Image Top Origin = 0
Image Width = 28
Image Height = 11
; Pixels: 308
Local Color Table Flag = 0
Interlace Flag = 0
Sort Flag = 0
Reserved Bits = 00
Size of Local Color Table = 0
[Raster Data]
Code Size = 2
Block 1 data = 94 8F A9 6B 11 E7 1E 8A D0 A9 00 24 8E 3C C3 4C 35 80 B7 8D E6 D6 39 9E 88 66 60 04 C6 AA 24 B4 E5 F8 D8 F6 97 E3 2F EB EA D1 36 40 8E CA 45 B2 34 94 35 8C E9 65 AC AD 18 46 66 22 C4 C8 6A 0B
; Compressed data: 65 bytes
[Decompressed Raster Data]
; Decompressed data: 308 bytes
; Decompressed/Compressed Ratio: 4.7
Row  1 = 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
Row  2 = 02 02 01 01 02 02 02 01 01 01 02 02 02 02 02 01 01 01 02 02 02 01 01 01 02 02 02 02
Row  3 = 02 02 01 00 01 02 02 01 00 01 01 01 01 01 01 01 00 01 02 02 02 01 00 01 01 01 01 02
Row  4 = 02 02 01 00 00 01 02 01 00 01 00 00 00 00 00 01 00 01 01 01 01 01 00 01 01 00 01 02
Row  5 = 02 02 01 00 01 00 01 01 00 01 00 01 01 01 01 01 00 01 01 00 01 01 00 01 01 00 01 02
Row  6 = 02 02 01 00 01 01 00 01 00 01 00 00 00 01 02 01 00 01 01 00 01 01 00 01 01 00 01 02
Row  7 = 02 02 01 00 01 02 01 00 00 01 00 01 01 01 02 02 01 00 01 00 01 00 01 02 01 00 01 02
Row  8 = 02 02 01 00 01 02 02 01 00 01 00 01 01 01 01 01 01 00 00 01 00 00 01 02 01 01 01 02
Row  9 = 02 02 01 01 01 02 02 02 01 01 00 00 00 00 00 01 01 01 01 01 01 01 01 02 01 00 01 02
Row 10 = 02 02 02 02 02 02 02 02 02 01 01 01 01 01 01 01 02 02 02 02 02 02 02 02 01 01 01 02
Row 11 = 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
[Trailer]
; No extraneous bytes remaining