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.133 date: 2024/04/22 17:40:09
user: stefan
file: GIFReader.st directory: libview2
module: stx stc-classLibrary: libview2

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.

copyright

COPYRIGHT (c) 1991 by Claus Gittinger All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

class 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  hasValidImageHeader: someHeaderBytes
return true, if someHeaderBytes
(which does not need to be the whole data, but large enough
to detect the header) contains a valid GIF image header

o  isValidImageStream: inStream
return true, if inStream possibly contains a GIF image.
The stream is left open and position undefined afterwards


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  makeGrayscale
not yet implemented/needed

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: aFilenameOrFilenameString
save image as GIF file on aFileName

Usage example(s):

     |i|

     i := Image fromFile:'bitmaps/gifImages/garfield.gif'.
     GIFReader save:i onFile:'foo.gif'.
     (Image fromFile:'foo.gif') inspect

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

Usage example(s):

     |i|

     i := Image fromFile:'bitmaps/gifImages/garfield.gif'.
     GIFReader save:i onFile:'foo.gif'.
     (Image fromFile:'./foo.gif') inspect


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 openAndWaitUntilVisible.
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.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Thu, 21 Nov 2024 11:34:01 GMT