eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'GIFReader':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: GIFReader


Inheritance:

   Object
   |
   +--ImageReader
      |
      +--GIFReader

Package:
stx:libview2
Category:
Graphics-Images-Readers
Version:
rev: 1.119 date: 2018/06/03 07:28:06
user: cg
file: GIFReader.st directory: libview2
module: stx stc-classLibrary: libview2
Author:
Claus Gittinger

Description:


this class provides methods for loading and saving GIF pictures.
It has been tested with some different GIF87a pictures, I don't
know, if it works with other GIF versions.
GIF extension blocks are not handled.

legal stuff extracted from GIF87a documentation:

CompuServe Incorporated hereby grants a limited, non-exclusive, royalty-free
license for the use of the Graphics Interchange Format(sm) in computer
software; computer software utilizing GIF(sm) must acknowledge ownership of the
Graphics Interchange Format and its Service Mark by CompuServe Incorporated, in
User and Technical Documentation.

  The Graphics Interchange Format(c) is the Copyright property of
  CompuServe Incorporated. GIF(sm) is a Service Mark property of
  CompuServe Incorporated.

Notice:
    there has been some annoyance regarding a patent on the compression algorithm
    used in gif. There is no warranty from exept, regarding any legal problems, when using GIF.
    We therefore highly recommend to use newer (and especially: royalty-free) formats, such as PNG.

    This patent is now obsolete: 
        The United States LZW patent expired on 20 June 2003. 
        The counterpart patents in the United Kingdom, France, Germany and Italy 
        expired on 18 June 2004, the Japanese patents expired on 20 June 2004, 
        and the Canadian patent expired on 7 July 2004.
        Consequently, the GIF format may now be used freely.


Related information:

    Image
    Form
    Icon
    BlitImageReader
    FaceReader
    JPEGReader
    MacOSXIconReader
    PBMReader
    PCXReader
    PNGReader
    ST80FormReader
    SunRasterReader
    TargaReader
    TIFFReader
    WindowsIconReader
    XBMReader
    XPMReader
    XWDReader

Class protocol:

initialization
o  initialize
install myself in the Image classes fileFormat table
for the `.gif' extensions.

testing
o  canRepresent: anImage
return true, if anImage can be represented in my file format.
GIF supports depth 8 images only.

o  isValidImageFile: aFileName
return true, if aFileName contains a GIF image


Instance protocol:

image reading
o  fromStream: aStream
read a stream containing a GIF image (or an image sequence).
Leave image description in instance variables.

private-reading
o  makeGreyscale
not yet implemented/needed

o  readColorMap: colorMapSize
get a gif colormap consisting of colorMapSize entries

o  readExtension: aStream
get gif89 extension

o  readImage: aStream
read a single image from aStream.

private-writing
o  assignTransparentPixelIn: image
find an usused pixelValue in the colorMap (or image).

o  checkCodeSize

o  flushBits

o  flushBuffer

o  flushCode

o  nextBitsPut: anInteger

o  nextBytePut: aByte

o  readPixelFrom: bits

o  setParameters: bitsPerPixel

o  updatePixelPosition

o  writeBitDataFor: image
using modified Lempel-Ziv Welch algorithm.

o  writeCode: aCode

o  writeCodeAndCheckCodeSize: t1

o  writeHeaderFor: image
write the gif header

o  writeMaskExtensionHeaderFor: image
write an extension header for the transparent pixel

writing to file
o  save: image onFile: aFileName
save image as GIF file on aFileName

o  save: image onStream: aStream
save image in GIF-file-format onto aStream


Examples:


saving an animated gif sequence: a view showing rainfall:
|BG CLR N1 H W v WIND drops gen newDrops draw remove move buffer|

BG := Color black.
CLR := Color blue lightened.
H := 100.
W := 100.
N1 := 10.
WIND := 0.
drops := OrderedCollection new.

gen := [:n | ((1 to:n) collect:[:i | Random nextIntegerBetween:1 and:W] as:Set) collect:[:x | x@0]].
newDrops := [drops addAll:(gen value:N1)].
draw := [buffer fill:BG; paint:CLR. drops do:[:d | buffer displayPoint:d]].
remove := [drops := drops reject:[:d | d y > H]].
move := [:wind | drops := drops collect:[:d| (d x + wind)\\W @ (d y + 1)]].
v := View new openAndWait.
buffer := Form extent:(v extent) depth:24 onDevice:v device.

[
    [v shown] whileTrue:[
        draw value.
        v displayForm:buffer.
        move value:WIND.
        remove value.
        newDrops value.
        WIND := (WIND+(Random nextBetween:-1 and:1)) clampBetween:-5 and:5.
        Delay waitForSeconds:0.1.
    ]
] fork.
saving those images:
|seq img BG CLR N1 H W v drops gen gen1 buffer|

BG := Color black.
CLR := Color blue lightened.
H := 100.
W := 100.
N1 := 10.
WIND := 0.
drops := OrderedCollection new.

gen := [:n | ((1 to:n) collect:[:i | Random nextIntegerBetween:1 and:W] as:Set) collect:[:x | x@0]].
newDrops := [drops addAll:(gen value:N1)].
draw := [buffer fill:BG; paint:CLR. drops do:[:d | buffer displayPoint:d]].
remove := [drops := drops reject:[:d | d y > H]].
move := [:wind | drops := drops collect:[:d| (d x + wind)\\W @ (d y + 1)]].
buffer := Form extent:W@H depth:8 onDevice:Display.

seq := OrderedCollection new.
500 timesRepeat:[
    move value:WIND.
    remove value.
    newDrops value.
    draw value.
    seq add:(ImageFrame new delay:100; image:(Depth8Image fromForm:buffer)).
    WIND := (WIND+(Random nextBetween:-1 and:1)) clampBetween:-5 and:5.
].

img := seq first image.
img imageSequence:(seq copyFrom:2).
img imageSequence do:[:each | each image colorMap:img colorMap].
GIFReader save:img onFile:'/tmp/img.gif'


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Sat, 27 Apr 2024 01:37:51 GMT