|
Class: GIFReader
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
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.
copyrightCOPYRIGHT (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 initialization
-
initialize
-
install myself in the Image classes fileFormat table
for the `.gif' extensions.
testing
-
canRepresent: anImage
-
return true, if anImage can be represented in my file format.
GIF supports depth 8 images only.
-
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
-
isValidImageStream: inStream
-
return true, if inStream possibly contains a GIF image.
The stream is left open and position undefined afterwards
image reading
-
fromStream: aStream
-
read a stream containing a GIF image (or an image sequence).
Leave image description in instance variables.
private-reading
-
makeGrayscale
-
not yet implemented/needed
-
makeGreyscale
-
not yet implemented/needed
-
readColorMap: colorMapSize
-
get a gif colormap consisting of colorMapSize entries
-
readExtension: aStream
-
get gif89 extension
-
readImage: aStream
-
read a single image from aStream.
private-writing
-
assignTransparentPixelIn: image
-
find an usused pixelValue in the colorMap (or image).
-
checkCodeSize
-
-
flushBits
-
-
flushBuffer
-
-
flushCode
-
-
nextBitsPut: anInteger
-
-
nextBytePut: aByte
-
-
readPixelFrom: bits
-
-
setParameters: bitsPerPixel
-
-
updatePixelPosition
-
-
writeBitDataFor: image
-
using modified Lempel-Ziv Welch algorithm.
-
writeCode: aCode
-
-
writeCodeAndCheckCodeSize: t1
-
-
writeHeaderFor: image
-
write the gif header
-
writeMaskExtensionHeaderFor: image
-
write an extension header for the transparent pixel
writing to file
-
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
|
-
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
|
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'
|
|