--- a/FaceReader.st Sat Feb 18 16:52:56 1995 +0100
+++ b/FaceReader.st Sat Feb 18 16:58:20 1995 +0100
@@ -21,7 +21,7 @@
COPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libview2/FaceReader.st,v 1.9 1994-11-17 14:29:23 claus Exp $
+$Header: /cvs/stx/stx/libview2/FaceReader.st,v 1.10 1995-02-18 15:56:56 claus Exp $
'!
!FaceReader class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
version
"
-$Header: /cvs/stx/stx/libview2/FaceReader.st,v 1.9 1994-11-17 14:29:23 claus Exp $
+$Header: /cvs/stx/stx/libview2/FaceReader.st,v 1.10 1995-02-18 15:56:56 claus Exp $
"
!
@@ -62,7 +62,7 @@
!FaceReader methodsFor:'reading from file'!
-fromFile:aFileName
+fromStream:aStream
|line
dstIndex "{ Class: SmallInteger }"
bytesPerRow
@@ -71,12 +71,10 @@
val "{ Class: SmallInteger }"
inHeader s depth|
- inStream := self class streamReadingFile:aFileName.
- inStream isNil ifTrue:[^ nil].
+ inStream := aStream.
- line := inStream nextLine.
+ line := aStream nextLine.
line isNil ifTrue:[
- inStream close.
^ nil
].
@@ -90,7 +88,7 @@
depth := Number readFrom:s.
inHeader := false.
].
- line := inStream nextLine
+ line := aStream nextLine
].
depth == 8 ifFalse:[
@@ -98,7 +96,7 @@
].
[line isEmpty] whileTrue:[
- line := inStream nextLine.
+ line := aStream nextLine.
].
bytesPerRow := width * depth // 8.
@@ -117,7 +115,7 @@
data at:dstIndex put:val.
dstIndex := dstIndex - 1
].
- line := inStream nextLine
+ line := aStream nextLine
].
photometric := #whiteIs0.
samplesPerPixel := 1.
--- a/GIFReader.st Sat Feb 18 16:52:56 1995 +0100
+++ b/GIFReader.st Sat Feb 18 16:58:20 1995 +0100
@@ -10,6 +10,8 @@
hereby transferred.
"
+'From Smalltalk/X, Version:2.10.4 on 18-feb-1995 at 2:18:24 am'!
+
ImageReader subclass:#GIFReader
instanceVariableNames:'redMap greenMap blueMap'
classVariableNames:''
@@ -21,7 +23,7 @@
COPYRIGHT (c) 1991 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.12 1995-02-06 00:36:28 claus Exp $
+$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.13 1995-02-18 15:57:13 claus Exp $
'!
!GIFReader class methodsFor:'documentation'!
@@ -42,7 +44,7 @@
version
"
-$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.12 1995-02-06 00:36:28 claus Exp $
+$Header: /cvs/stx/stx/libview2/GIFReader.st,v 1.13 1995-02-18 15:57:13 claus Exp $
"
!
@@ -100,188 +102,6 @@
!GIFReader methodsFor:'reading from file'!
-fromFile:aFileName
- "read a GIF file"
-
- |byte index flag count
- colorMapSize bitsPerPixel scrWidth scrHeight
- hasColorMap hasLocalColorMap interlaced id
- leftOffs topOffs codeLen
- compressedData compressedSize
- tmp srcOffset dstOffset|
-
- inStream := self class streamReadingFile:aFileName.
- inStream isNil ifTrue:[^ nil].
-
- inStream binary.
-
- "GIF-files are always lsb (intel-world)"
- byteOrder := #lsb.
-
- id := String new:6.
- inStream nextBytes:6 into:id.
-
- "all I had for testing where GIF87a files;
- I hope later versions work too ..."
-
- (id ~= 'GIF87a') ifTrue:[
- (id startsWith:'GIF') ifFalse:[
- 'GIFReader: not a gif file' errorPrintNL.
- inStream close.
- ^ nil
- ].
- 'GIFReader: not a GIF87a file - hope that works' errorPrintNL.
- ].
-
- "get screen dimensions (not used)"
-
- scrWidth := inStream nextShortMSB:false.
- scrHeight := inStream nextShortMSB:false.
-
- "get flag byte"
- flag := inStream nextByte.
- hasColorMap := (flag bitAnd:2r10000000) ~~ 0.
- "bitsPerRGB := ((flag bitAnd:2r01110000) bitShift:-4) + 1. "
- "colorMapSorted := ((flag bitAnd:2r00001000) ~~ 0. "
- bitsPerPixel := (flag bitAnd:2r00000111) + 1.
- colorMapSize := 1 bitShift:bitsPerPixel.
-
- "get background (not used)"
- inStream nextByte.
-
- "aspect ratio (not used)"
- inStream nextByte.
-
- "get colorMap"
- hasColorMap ifTrue:[
- self readColorMap:colorMapSize
- ].
-
- "image separator"
- byte := inStream nextByte.
- (byte ~~ 16r2C) ifTrue:[
- 'GIFReader: corrupted gif file (no imgSep)' errorPrintNL.
- ^ nil
- ].
-
- "get image data"
- leftOffs := inStream nextShortMSB:false.
- topOffs := inStream nextShortMSB:false.
- width := inStream nextShortMSB:false.
- height := inStream nextShortMSB:false.
-
-"
-'width ' print. width printNewline.
-'height ' print. height printNewline.
-"
-
- "another flag byte"
- flag := inStream nextByte.
- interlaced := (flag bitAnd:2r01000000) ~~ 0.
- hasLocalColorMap := (flag bitAnd:2r10000000) ~~ 0.
- "localColorMapSorted := (flag bitAnd:2r00100000) ~~ 0. "
-
- "if image has a local colormap, this one is used"
-
- hasLocalColorMap ifTrue:[
- "local descr. overwrites"
- bitsPerPixel := (flag bitAnd:2r00000111) + 1.
- colorMapSize := 1 bitShift:bitsPerPixel.
-" 'local colormap' printNewline. "
- "overwrite colormap"
- self readColorMap:colorMapSize
- ].
-
- "get codelen for decompression"
- codeLen := inStream nextByte.
-
- compressedData := ByteArray uninitializedNew:(inStream size).
-
- "get compressed data"
- index := 1.
- count := inStream nextByte.
- [count notNil and:[count ~~ 0]] whileTrue:[
- inStream nextBytes:count into:compressedData startingAt:index.
- index := index + count.
- count := inStream nextByte
- ].
- compressedSize := index - 1.
- inStream close.
-
- data := ByteArray new:((width + 1) * (height + 1)).
- 'GIFReader: decompressing ...' errorPrintNL.
-
- self class decompressGIFFrom:compressedData
- count:compressedSize
- into:data
- startingAt:1
- codeLen:(codeLen + 1).
-
- interlaced ifTrue:[
- Transcript showCr:'deinterlacing'.
- tmp := ByteArray new:(data size).
-
- "phase 1: 0, 8, 16, 24, ..."
-
- srcOffset := 1.
- 0 to:(height - 1) by:8 do:[:dstRow |
- dstOffset := dstRow * width + 1.
- tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
- with:data startingAt:srcOffset.
- srcOffset := srcOffset + width.
- ].
-
- "phase 2: 4, 12, 20, 28, ..."
-
- 4 to:(height - 1) by:8 do:[:dstRow |
- dstOffset := dstRow * width + 1.
- tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
- with:data startingAt:srcOffset.
- srcOffset := srcOffset + width.
- ].
-
- "phase 3: 2, 6, 10, 14, ..."
-
- 2 to:(height - 1) by:4 do:[:dstRow |
- dstOffset := dstRow * width + 1.
- tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
- with:data startingAt:srcOffset.
- srcOffset := srcOffset + width.
- ].
-
- "phase 4: 1, 3, 5, 7, ..."
-
- 1 to:(height - 1) by:2 do:[:dstRow |
- dstOffset := dstRow * width + 1.
- tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
- with:data startingAt:srcOffset.
- srcOffset := srcOffset + width.
- ].
-
- data := tmp.
- tmp := nil
- ].
-
- photometric := #palette.
- samplesPerPixel := 1.
- bitsPerSample := #(8).
-
- "check if only grey values are used,
- could make it a greyscale image if so (currently not done)"
-
- self checkGreyscaleColormap ifTrue:[
- self makeGreyscale
- ].
-
-"/ colorMap := Array with:redMap with:greenMap with:blueMap.
- colorMap := Colormap redVector:redMap greenVector:greenMap blueVector:blueMap.
-
- "
- GIFReader fromFile:'../fileIn/bitmaps/claus.gif
- GIFReader fromFile:'../fileIn/bitmaps/garfield.gif'
- "
-!
-
readColorMap:colorMapSize
"get gif colormap consisting of colorMapSize entries"
@@ -316,4 +136,183 @@
makeGreyscale
"not yet implemented/needed"
+!
+
+fromStream:aStream
+ "read a GIF file"
+
+ |byte index flag count
+ colorMapSize bitsPerPixel scrWidth scrHeight
+ hasColorMap hasLocalColorMap interlaced id
+ leftOffs topOffs codeLen
+ compressedData compressedSize
+ tmp srcOffset dstOffset|
+
+ inStream := aStream.
+ aStream binary.
+
+ "GIF-files are always lsb (intel-world)"
+ byteOrder := #lsb.
+
+ id := String new:6.
+ aStream nextBytes:6 into:id.
+
+ "all I had for testing where GIF87a files;
+ I hope later versions work too ..."
+
+ (id ~= 'GIF87a') ifTrue:[
+ (id startsWith:'GIF') ifFalse:[
+ 'GIFReader: not a gif file' errorPrintNL.
+ ^ nil
+ ].
+ 'GIFReader: not a GIF87a file - hope that works' errorPrintNL.
+ ].
+
+ "get screen dimensions (not used)"
+
+ scrWidth := aStream nextShortMSB:false.
+ scrHeight := aStream nextShortMSB:false.
+
+ "get flag byte"
+ flag := aStream nextByte.
+ hasColorMap := (flag bitAnd:2r10000000) ~~ 0.
+ "bitsPerRGB := ((flag bitAnd:2r01110000) bitShift:-4) + 1. "
+ "colorMapSorted := ((flag bitAnd:2r00001000) ~~ 0. "
+ bitsPerPixel := (flag bitAnd:2r00000111) + 1.
+ colorMapSize := 1 bitShift:bitsPerPixel.
+
+ "get background (not used)"
+ aStream nextByte.
+
+ "aspect ratio (not used)"
+ aStream nextByte.
+
+ "get colorMap"
+ hasColorMap ifTrue:[
+ self readColorMap:colorMapSize
+ ].
+
+ "image separator"
+ byte := aStream nextByte.
+ (byte ~~ 16r2C) ifTrue:[
+ 'GIFReader: corrupted gif file (no imgSep)' errorPrintNL.
+ ^ nil
+ ].
+
+ "get image data"
+ leftOffs := aStream nextShortMSB:false.
+ topOffs := aStream nextShortMSB:false.
+ width := aStream nextShortMSB:false.
+ height := aStream nextShortMSB:false.
+
+"
+'width ' print. width printNewline.
+'height ' print. height printNewline.
+"
+
+ "another flag byte"
+ flag := aStream nextByte.
+ interlaced := (flag bitAnd:2r01000000) ~~ 0.
+ hasLocalColorMap := (flag bitAnd:2r10000000) ~~ 0.
+ "localColorMapSorted := (flag bitAnd:2r00100000) ~~ 0. "
+
+ "if image has a local colormap, this one is used"
+
+ hasLocalColorMap ifTrue:[
+ "local descr. overwrites"
+ bitsPerPixel := (flag bitAnd:2r00000111) + 1.
+ colorMapSize := 1 bitShift:bitsPerPixel.
+" 'local colormap' printNewline. "
+ "overwrite colormap"
+ self readColorMap:colorMapSize
+ ].
+
+ "get codelen for decompression"
+ codeLen := aStream nextByte.
+
+ compressedData := ByteArray uninitializedNew:(aStream size).
+
+ "get compressed data"
+ index := 1.
+ count := aStream nextByte.
+ [count notNil and:[count ~~ 0]] whileTrue:[
+ aStream nextBytes:count into:compressedData startingAt:index.
+ index := index + count.
+ count := aStream nextByte
+ ].
+ compressedSize := index - 1.
+
+ data := ByteArray new:((width + 1) * (height + 1)).
+ 'GIFReader: decompressing ...' errorPrintNL.
+
+ self class decompressGIFFrom:compressedData
+ count:compressedSize
+ into:data
+ startingAt:1
+ codeLen:(codeLen + 1).
+
+ interlaced ifTrue:[
+ Transcript showCr:'deinterlacing'.
+ tmp := ByteArray new:(data size).
+
+ "phase 1: 0, 8, 16, 24, ..."
+
+ srcOffset := 1.
+ 0 to:(height - 1) by:8 do:[:dstRow |
+ dstOffset := dstRow * width + 1.
+ tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
+ with:data startingAt:srcOffset.
+ srcOffset := srcOffset + width.
+ ].
+
+ "phase 2: 4, 12, 20, 28, ..."
+
+ 4 to:(height - 1) by:8 do:[:dstRow |
+ dstOffset := dstRow * width + 1.
+ tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
+ with:data startingAt:srcOffset.
+ srcOffset := srcOffset + width.
+ ].
+
+ "phase 3: 2, 6, 10, 14, ..."
+
+ 2 to:(height - 1) by:4 do:[:dstRow |
+ dstOffset := dstRow * width + 1.
+ tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
+ with:data startingAt:srcOffset.
+ srcOffset := srcOffset + width.
+ ].
+
+ "phase 4: 1, 3, 5, 7, ..."
+
+ 1 to:(height - 1) by:2 do:[:dstRow |
+ dstOffset := dstRow * width + 1.
+ tmp replaceFrom:dstOffset to:(dstOffset + width - 1)
+ with:data startingAt:srcOffset.
+ srcOffset := srcOffset + width.
+ ].
+
+ data := tmp.
+ tmp := nil
+ ].
+
+ photometric := #palette.
+ samplesPerPixel := 1.
+ bitsPerSample := #(8).
+
+ "check if only grey values are used,
+ could make it a greyscale image if so (currently not done)"
+
+ self checkGreyscaleColormap ifTrue:[
+ self makeGreyscale
+ ].
+
+ colorMap := Colormap redVector:redMap greenVector:greenMap blueVector:blueMap.
+
+ "
+ GIFReader fromFile:'../fileIn/bitmaps/claus.gif
+ GIFReader fromFile:'../fileIn/bitmaps/garfield.gif'
+ "
! !
+
+GIFReader initialize!
--- a/JPEGReader.st Sat Feb 18 16:52:56 1995 +0100
+++ b/JPEGReader.st Sat Feb 18 16:58:20 1995 +0100
@@ -21,7 +21,7 @@
COPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libview2/JPEGReader.st,v 1.7 1994-11-17 14:29:35 claus Exp $
+$Header: /cvs/stx/stx/libview2/JPEGReader.st,v 1.8 1995-02-18 15:57:36 claus Exp $
'!
!JPEGReader class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
version
"
-$Header: /cvs/stx/stx/libview2/JPEGReader.st,v 1.7 1994-11-17 14:29:35 claus Exp $
+$Header: /cvs/stx/stx/libview2/JPEGReader.st,v 1.8 1995-02-18 15:57:36 claus Exp $
"
!
@@ -65,7 +65,7 @@
Image fileFormats at:'.JPG' put:self.
! !
-!JPEGReader methodsFor:'reading from file'!
+!JPEGReader class methodsFor:'reading from file'!
fromFile:aFileName
"make it the easy way: let djpeg convert it to gif,
--- a/PCXReader.st Sat Feb 18 16:52:56 1995 +0100
+++ b/PCXReader.st Sat Feb 18 16:58:20 1995 +0100
@@ -10,7 +10,7 @@
hereby transferred.
"
-'From Smalltalk/X, Version:2.10.3 on 22-sep-1994 at 7:31:01 pm'!
+'From Smalltalk/X, Version:2.10.4 on 18-feb-1995 at 2:18:45 am'!
ImageReader subclass:#PCXReader
instanceVariableNames:''
@@ -23,7 +23,7 @@
COPYRIGHT (c) 1994 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libview2/PCXReader.st,v 1.4 1995-02-06 00:37:36 claus Exp $
+$Header: /cvs/stx/stx/libview2/PCXReader.st,v 1.5 1995-02-18 15:57:51 claus Exp $
'!
!PCXReader class methodsFor:'documentation'!
@@ -44,7 +44,7 @@
version
"
-$Header: /cvs/stx/stx/libview2/PCXReader.st,v 1.4 1995-02-06 00:37:36 claus Exp $
+$Header: /cvs/stx/stx/libview2/PCXReader.st,v 1.5 1995-02-18 15:57:51 claus Exp $
"
!
@@ -57,6 +57,14 @@
"
! !
+!PCXReader class methodsFor:'initialization'!
+
+initialize
+ "tell Image-class, that a new fileReader is present"
+
+ Image fileFormats at:'.pcx' put:self.
+! !
+
!PCXReader class methodsFor:'testing'!
isValidPCXHeader:aHeader
@@ -95,14 +103,6 @@
^ true
! !
-!PCXReader class methodsFor:'initialization'!
-
-initialize
- "tell Image-class, that a new fileReader is present"
-
- Image fileFormats at:'.pcx' put:self.
-! !
-
!PCXReader methodsFor:'reading from file'!
fromStreamWithHeader:header
@@ -128,8 +128,8 @@
compression := header at:3.
"/ 'compression=' print. compression printNL.
(#(0 1) includes:compression) ifFalse:[
- self error:'PCXREADER: unknown compression'.
- ^ nil
+ self error:'PCXREADER: unknown compression'.
+ ^ nil
].
inDepth := header at:4.
"/ 'depth=' print. inDepth printNL.
@@ -145,8 +145,8 @@
So its not (yet) implemented
"
((inDepth ~~ 8) or:[nPlanes ~~ 1]) ifTrue:[
- 'PCXReader: can only handle 1-plane 256 color images' errorPrintNL.
- ^ nil
+ 'PCXReader: can only handle 1-plane 256 color images' errorPrintNL.
+ ^ nil
].
xmin := header wordAt:5.
@@ -160,66 +160,66 @@
"/ 'height=' print. width printNL.
(version == 2) ifTrue:[
- "read the 16-entry colormap"
+ "read the 16-entry colormap"
- rawMap := ByteArray uninitializedNew:(16*3).
- rawMap replaceFrom:1 to:(16*3) with:header startingAt:17.
- rMap := Array new:16.
- gMap := Array new:16.
- bMap := Array new:16.
- srcIndex := 1.
- 1 to:16 do:[:i |
- rMap at:i put:(rawMap at:srcIndex).
- srcIndex := srcIndex + 1.
- gMap at:i put:(rawMap at:srcIndex).
- srcIndex := srcIndex + 1.
- bMap at:i put:(rawMap at:srcIndex).
- srcIndex := srcIndex + 1.
- ].
+ rawMap := ByteArray uninitializedNew:(16*3).
+ rawMap replaceFrom:1 to:(16*3) with:header startingAt:17.
+ rMap := Array new:16.
+ gMap := Array new:16.
+ bMap := Array new:16.
+ srcIndex := 1.
+ 1 to:16 do:[:i |
+ rMap at:i put:(rawMap at:srcIndex).
+ srcIndex := srcIndex + 1.
+ gMap at:i put:(rawMap at:srcIndex).
+ srcIndex := srcIndex + 1.
+ bMap at:i put:(rawMap at:srcIndex).
+ srcIndex := srcIndex + 1.
+ ].
].
compression == 1 ifTrue:[
- data := dataBytes := ByteArray new:(height * bytesPerRow).
+ data := dataBytes := ByteArray new:(height * bytesPerRow).
- buffer := ByteArray new:4096.
- bufferIndex := 1.
- bendIndex := 1.
+ buffer := ByteArray new:4096.
+ bufferIndex := 1.
+ bendIndex := 1.
- rowIndex := 1.
- h := height.
- 1 to:h do:[:row |
- dstIndex := rowIndex.
- endIndex := dstIndex + bytesPerRow.
- [dstIndex < endIndex] whileTrue:[
- bufferIndex == bendIndex ifTrue:[
- nBuffer := inStream nextBytes:4096 into:buffer.
- bufferIndex := 1.
- bendIndex := nBuffer + 1.
- ].
- byte := buffer at:bufferIndex.
- bufferIndex := bufferIndex + 1. "/ nBuffer := nBuffer - 1.
- ((byte bitAnd:2r11000000) ~~ 2r11000000) ifTrue:[
- dataBytes at:dstIndex put:byte.
- dstIndex := dstIndex + 1.
- ] ifFalse:[
- nByte := byte bitAnd:2r00111111.
- bufferIndex == bendIndex ifTrue:[
- nBuffer := inStream nextBytes:4096 into:buffer.
- bufferIndex := 1.
- bendIndex := nBuffer + 1.
- ].
- value := buffer at:bufferIndex.
- bufferIndex := bufferIndex + 1. "/ nBuffer := nBuffer - 1.
- value notNil ifTrue:[
- idx2 := endIndex min:(dstIndex + nByte - 1).
- dataBytes from:dstIndex to:idx2 put:value.
- dstIndex := dstIndex + nByte.
- ]
- ].
- ].
- rowIndex := rowIndex + bytesPerRow
- ].
- nBuffer := endIndex - bufferIndex.
+ rowIndex := 1.
+ h := height.
+ 1 to:h do:[:row |
+ dstIndex := rowIndex.
+ endIndex := dstIndex + bytesPerRow.
+ [dstIndex < endIndex] whileTrue:[
+ bufferIndex == bendIndex ifTrue:[
+ nBuffer := inStream nextBytes:4096 into:buffer.
+ bufferIndex := 1.
+ bendIndex := nBuffer + 1.
+ ].
+ byte := buffer at:bufferIndex.
+ bufferIndex := bufferIndex + 1. "/ nBuffer := nBuffer - 1.
+ ((byte bitAnd:2r11000000) ~~ 2r11000000) ifTrue:[
+ dataBytes at:dstIndex put:byte.
+ dstIndex := dstIndex + 1.
+ ] ifFalse:[
+ nByte := byte bitAnd:2r00111111.
+ bufferIndex == bendIndex ifTrue:[
+ nBuffer := inStream nextBytes:4096 into:buffer.
+ bufferIndex := 1.
+ bendIndex := nBuffer + 1.
+ ].
+ value := buffer at:bufferIndex.
+ bufferIndex := bufferIndex + 1. "/ nBuffer := nBuffer - 1.
+ value notNil ifTrue:[
+ idx2 := endIndex min:(dstIndex + nByte - 1).
+ dataBytes from:dstIndex to:idx2 put:value.
+ dstIndex := dstIndex + nByte.
+ ]
+ ].
+ ].
+ rowIndex := rowIndex + bytesPerRow
+ ].
+ nBuffer := endIndex - bufferIndex.
"/ rowIndex := 1.
"/ h := height.
@@ -244,55 +244,54 @@
"/ rowIndex := rowIndex + bytesPerRow
"/ ]
] ifFalse:[
- "
- actually untested ...
- "
- data := dataBytes := ByteArray uninitializedNew:(height * bytesPerRow).
- inStream nextBytes:(height * bytesPerRow) into:data.
- nBuffer := 0.
+ "
+ actually untested ...
+ "
+ data := dataBytes := ByteArray uninitializedNew:(height * bytesPerRow).
+ inStream nextBytes:(height * bytesPerRow) into:data.
+ nBuffer := 0.
].
(version == 5) ifTrue:[
- "read the 256-entry colormap"
+ "read the 256-entry colormap"
- nBuffer ~~ 0 ifTrue:[
- byte := buffer at:bufferIndex.
- bufferIndex := bufferIndex + 1. nBuffer := nBuffer - 1.
- ] ifFalse:[
- byte := inStream next
- ].
+ nBuffer ~~ 0 ifTrue:[
+ byte := buffer at:bufferIndex.
+ bufferIndex := bufferIndex + 1. nBuffer := nBuffer - 1.
+ ] ifFalse:[
+ byte := inStream next
+ ].
- byte == 16rC0 ifFalse:[
- 'PCXREADER: no valid 256-entry palette (got' errorPrint.
- byte errorPrint. '; expected ' errorPrint. 16rC0 errorPrint. ')' errorPrintNL.
- ].
- rawMap := ByteArray uninitializedNew:(256*3).
- nBuffer ~~ 0 ifTrue:[
- rawMap replaceFrom:1 to:(256*3) with:buffer startingAt:bufferIndex.
- nBuffer < (256*3) ifTrue:[
- inStream nextBytes:((256*3)-nBuffer) into:rawMap startingAt:nBuffer+1
- ]
- ] ifFalse:[
- inStream nextBytes:(256*3) into:rawMap.
- ].
- rMap := Array new:256.
- gMap := Array new:256.
- bMap := Array new:256.
- srcIndex := 1.
- 1 to:256 do:[:i |
- rMap at:i put:(rawMap at:srcIndex).
- srcIndex := srcIndex + 1.
- gMap at:i put:(rawMap at:srcIndex).
- srcIndex := srcIndex + 1.
- bMap at:i put:(rawMap at:srcIndex).
- srcIndex := srcIndex + 1.
- ].
+ byte == 16rC0 ifFalse:[
+ 'PCXREADER: no valid 256-entry palette (got' errorPrint.
+ byte errorPrint. '; expected ' errorPrint. 16rC0 errorPrint. ')' errorPrintNL.
+ ].
+ rawMap := ByteArray uninitializedNew:(256*3).
+ nBuffer ~~ 0 ifTrue:[
+ rawMap replaceFrom:1 to:(256*3) with:buffer startingAt:bufferIndex.
+ nBuffer < (256*3) ifTrue:[
+ inStream nextBytes:((256*3)-nBuffer) into:rawMap startingAt:nBuffer+1
+ ]
+ ] ifFalse:[
+ inStream nextBytes:(256*3) into:rawMap.
+ ].
+ rMap := Array new:256.
+ gMap := Array new:256.
+ bMap := Array new:256.
+ srcIndex := 1.
+ 1 to:256 do:[:i |
+ rMap at:i put:(rawMap at:srcIndex).
+ srcIndex := srcIndex + 1.
+ gMap at:i put:(rawMap at:srcIndex).
+ srcIndex := srcIndex + 1.
+ bMap at:i put:(rawMap at:srcIndex).
+ srcIndex := srcIndex + 1.
+ ].
].
photometric := #palette.
samplesPerPixel := 1.
bitsPerSample := #(8).
-"/ colorMap := Array with:rMap with:gMap with:bMap.
colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
"
@@ -302,32 +301,28 @@
"
!
-fromFile:aFilename
+fromStream:aStream
| fileSize header img |
- inStream := self class streamReadingFile:aFilename.
- inStream isNil ifTrue:[^ nil].
+ inStream := aStream.
inStream binary.
- fileSize := inStream size.
+ fileSize := aStream size.
fileSize < 128 ifTrue:[
- inStream close.
- self error:'PCXREADER: short file'.
- ^ nil
+ self error:'PCXREADER: short file'.
+ ^ nil
].
header := ByteArray uninitializedNew:128.
- inStream nextBytes:128 into:header.
+ aStream nextBytes:128 into:header.
(self class isValidPCXHeader:header) ifFalse:[
- inStream close.
- self error:'PCXREADER: wrong header'.
- ^ nil
+ self error:'PCXREADER: wrong header'.
+ ^ nil
].
img := self fromStreamWithHeader:header.
- inStream close.
^ img
! !
--- a/ST80FormReader.st Sat Feb 18 16:52:56 1995 +0100
+++ b/ST80FormReader.st Sat Feb 18 16:58:20 1995 +0100
@@ -10,6 +10,8 @@
hereby transferred.
"
+'From Smalltalk/X, Version:2.10.4 on 18-feb-1995 at 2:18:48 am'!
+
ImageReader subclass:#ST80FormReader
instanceVariableNames:''
classVariableNames:''
@@ -21,7 +23,7 @@
COPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libview2/ST80FormReader.st,v 1.5 1994-11-17 14:29:42 claus Exp $
+$Header: /cvs/stx/stx/libview2/ST80FormReader.st,v 1.6 1995-02-18 15:58:02 claus Exp $
'!
!ST80FormReader class methodsFor:'documentation'!
@@ -42,7 +44,7 @@
version
"
-$Header: /cvs/stx/stx/libview2/ST80FormReader.st,v 1.5 1994-11-17 14:29:42 claus Exp $
+$Header: /cvs/stx/stx/libview2/ST80FormReader.st,v 1.6 1995-02-18 15:58:02 claus Exp $
"
!
@@ -56,6 +58,23 @@
"
! !
+!ST80FormReader class methodsFor:'testing'!
+
+isValidImageFile:aFileName
+ "return true, if aFileName contains an st80-bitmap-file image"
+
+ |code inStream ok|
+
+ inStream := self streamReadingFile:aFileName.
+ inStream isNil ifTrue:[^ false].
+
+ inStream binary.
+ code := inStream nextWord.
+ ok := (code == 1).
+ inStream close.
+ ^ ok
+! !
+
!ST80FormReader methodsFor:'writing to file'!
save:image onFile:aFileName
@@ -95,53 +114,27 @@
"ST80FormReader save:(Image fromFile:'bitmaps/SBrowser.xbm') onFile:'test.form'"
! !
-!ST80FormReader class methodsFor:'testing'!
-
-isValidImageFile:aFileName
- "return true, if aFileName contains an st80-bitmap-file image"
-
- |code inStream|
-
- inStream := self streamReadingFile:aFileName.
- inStream isNil ifTrue:[^ false].
-
- inStream binary.
- code := inStream nextWord.
- code == 1 ifFalse:[
- inStream close.
- ^ false
- ].
- inStream close.
- ^ true
-! !
-
!ST80FormReader methodsFor:'reading from file'!
-fromFile:aFileName
+fromStream:aStream
|nBytes code offsetX offsetY|
- inStream := self class streamReadingFile:aFileName.
- inStream isNil ifTrue:[
- 'open error' printNewline.
- ^ nil
+ inStream := aStream.
+ inStream binary.
+
+ code := inStream nextWord.
+ code isNil ifTrue:[
+ ^ nil
].
- inStream binary.
- code := inStream nextWord.
- code isNil ifTrue:[
- inStream close.
- ^ nil
- ].
-
- width := inStream nextWord.
- height := inStream nextWord.
- offsetX := inStream nextWord.
- offsetY := inStream nextWord.
+ width := aStream nextWord.
+ height := aStream nextWord.
+ offsetX := aStream nextWord.
+ offsetY := aStream nextWord.
nBytes := width + 15 // 16 * 2 * height.
data := ByteArray new:nBytes.
- inStream nextBytes:nBytes into:data.
- inStream close.
+ aStream nextBytes:nBytes into:data.
photometric := #whiteIs0.
samplesPerPixel := 1.
@@ -149,3 +142,4 @@
"ST80FormReader fromFile:''"
! !
+
--- a/STFormRdr.st Sat Feb 18 16:52:56 1995 +0100
+++ b/STFormRdr.st Sat Feb 18 16:58:20 1995 +0100
@@ -10,6 +10,8 @@
hereby transferred.
"
+'From Smalltalk/X, Version:2.10.4 on 18-feb-1995 at 2:18:48 am'!
+
ImageReader subclass:#ST80FormReader
instanceVariableNames:''
classVariableNames:''
@@ -21,7 +23,7 @@
COPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libview2/Attic/STFormRdr.st,v 1.5 1994-11-17 14:29:42 claus Exp $
+$Header: /cvs/stx/stx/libview2/Attic/STFormRdr.st,v 1.6 1995-02-18 15:58:02 claus Exp $
'!
!ST80FormReader class methodsFor:'documentation'!
@@ -42,7 +44,7 @@
version
"
-$Header: /cvs/stx/stx/libview2/Attic/STFormRdr.st,v 1.5 1994-11-17 14:29:42 claus Exp $
+$Header: /cvs/stx/stx/libview2/Attic/STFormRdr.st,v 1.6 1995-02-18 15:58:02 claus Exp $
"
!
@@ -56,6 +58,23 @@
"
! !
+!ST80FormReader class methodsFor:'testing'!
+
+isValidImageFile:aFileName
+ "return true, if aFileName contains an st80-bitmap-file image"
+
+ |code inStream ok|
+
+ inStream := self streamReadingFile:aFileName.
+ inStream isNil ifTrue:[^ false].
+
+ inStream binary.
+ code := inStream nextWord.
+ ok := (code == 1).
+ inStream close.
+ ^ ok
+! !
+
!ST80FormReader methodsFor:'writing to file'!
save:image onFile:aFileName
@@ -95,53 +114,27 @@
"ST80FormReader save:(Image fromFile:'bitmaps/SBrowser.xbm') onFile:'test.form'"
! !
-!ST80FormReader class methodsFor:'testing'!
-
-isValidImageFile:aFileName
- "return true, if aFileName contains an st80-bitmap-file image"
-
- |code inStream|
-
- inStream := self streamReadingFile:aFileName.
- inStream isNil ifTrue:[^ false].
-
- inStream binary.
- code := inStream nextWord.
- code == 1 ifFalse:[
- inStream close.
- ^ false
- ].
- inStream close.
- ^ true
-! !
-
!ST80FormReader methodsFor:'reading from file'!
-fromFile:aFileName
+fromStream:aStream
|nBytes code offsetX offsetY|
- inStream := self class streamReadingFile:aFileName.
- inStream isNil ifTrue:[
- 'open error' printNewline.
- ^ nil
+ inStream := aStream.
+ inStream binary.
+
+ code := inStream nextWord.
+ code isNil ifTrue:[
+ ^ nil
].
- inStream binary.
- code := inStream nextWord.
- code isNil ifTrue:[
- inStream close.
- ^ nil
- ].
-
- width := inStream nextWord.
- height := inStream nextWord.
- offsetX := inStream nextWord.
- offsetY := inStream nextWord.
+ width := aStream nextWord.
+ height := aStream nextWord.
+ offsetX := aStream nextWord.
+ offsetY := aStream nextWord.
nBytes := width + 15 // 16 * 2 * height.
data := ByteArray new:nBytes.
- inStream nextBytes:nBytes into:data.
- inStream close.
+ aStream nextBytes:nBytes into:data.
photometric := #whiteIs0.
samplesPerPixel := 1.
@@ -149,3 +142,4 @@
"ST80FormReader fromFile:''"
! !
+
--- a/SunRasterReader.st Sat Feb 18 16:52:56 1995 +0100
+++ b/SunRasterReader.st Sat Feb 18 16:58:20 1995 +0100
@@ -10,6 +10,8 @@
hereby transferred.
"
+'From Smalltalk/X, Version:2.10.4 on 18-feb-1995 at 2:18:51 am'!
+
ImageReader subclass:#SunRasterReader
instanceVariableNames:''
classVariableNames:''
@@ -21,7 +23,7 @@
COPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libview2/SunRasterReader.st,v 1.10 1995-02-06 00:37:51 claus Exp $
+$Header: /cvs/stx/stx/libview2/SunRasterReader.st,v 1.11 1995-02-18 15:58:11 claus Exp $
'!
!SunRasterReader class methodsFor:'documentation'!
@@ -42,7 +44,7 @@
version
"
-$Header: /cvs/stx/stx/libview2/SunRasterReader.st,v 1.10 1995-02-06 00:37:51 claus Exp $
+$Header: /cvs/stx/stx/libview2/SunRasterReader.st,v 1.11 1995-02-18 15:58:11 claus Exp $
"
!
@@ -114,138 +116,135 @@
!SunRasterReader methodsFor:'reading from file'!
-fromFile: aFilename
+fromStream: aStream
| rasterType mapType mapBytes imageWords form depth
rMap gMap bMap mapLen
- bits a b c index|
+ bits a b c index pos|
- inStream := self class streamReadingFile:aFilename.
- inStream isNil ifTrue:[^ nil].
+ inStream := aStream.
+
+ aStream binary.
- inStream binary.
-
- ((inStream nextWord == 16r59A6)
- and:[inStream nextWord == 16r6A95]) ifFalse: [
- inStream close.
- ^ self fromSunIconFile:aFilename
+ pos := aStream position.
+ ((aStream nextWord == 16r59A6)
+ and:[aStream nextWord == 16r6A95]) ifFalse: [
+ 'SUNReader: not a SunRaster file' errorPrintNL.
+ aStream position:pos.
+ ^ self fromSunIconStream:aStream
].
- width := inStream nextLong.
- height := inStream nextLong.
+ width := aStream nextLong.
+ height := aStream nextLong.
- depth := inStream nextLong.
- inStream nextLong. "Ignore the image length since I can't rely on it anyway."
- rasterType _ inStream nextLong.
- mapType := inStream nextLong. "Ignore the raster maptype."
- mapBytes := inStream nextLong.
+ depth := aStream nextLong.
+ aStream nextLong. "Ignore the image length since I can't rely on it anyway."
+ rasterType := aStream nextLong.
+ mapType := aStream nextLong. "Ignore the raster maptype."
+ mapBytes := aStream nextLong.
depth = 8 ifTrue: [
- mapLen := (mapBytes // 3).
- rMap := ByteArray uninitializedNew:mapLen.
- gMap := ByteArray uninitializedNew:mapLen.
- bMap := ByteArray uninitializedNew:mapLen.
- inStream nextBytes:mapLen into:rMap.
- inStream nextBytes:mapLen into:gMap.
- inStream nextBytes:mapLen into:bMap.
+ mapLen := (mapBytes // 3).
+ rMap := ByteArray uninitializedNew:mapLen.
+ gMap := ByteArray uninitializedNew:mapLen.
+ bMap := ByteArray uninitializedNew:mapLen.
+ aStream nextBytes:mapLen into:rMap.
+ aStream nextBytes:mapLen into:gMap.
+ aStream nextBytes:mapLen into:bMap.
- data := ByteArray uninitializedNew:(width * height).
- inStream nextBytes:(width * height) into:data.
+ data := ByteArray uninitializedNew:(width * height).
+ aStream nextBytes:(width * height) into:data.
- photometric := #palette.
- samplesPerPixel := 1.
- bitsPerSample := #(8).
-"/ colorMap := Array with:rMap with:gMap with:bMap.
- colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
- inStream close.
- ^ self
+ photometric := #palette.
+ samplesPerPixel := 1.
+ bitsPerSample := #(8).
+ colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
+ ^ self
].
depth ~~ 1 ifTrue: [
- inStream close.
- self error: 'Raster file is not monochrome'
+ 'SUNReader: Raster file is not monochrome' errorPrintNL.
+ ^ nil
].
form := nil.
- inStream skip: mapBytes. "Skip the color map."
- imageWords _ (width / 16) ceiling * height.
+ aStream skip: mapBytes. "Skip the color map."
+ imageWords := (width / 16) ceiling * height.
data := ByteArray uninitializedNew:(imageWords * 2).
(rasterType between: 0 and: 2) ifFalse: [
- inStream close.
- self error: 'Unknown raster file rasterType'
+ 'SUNReader: Unknown raster file rasterType' errorPrintNL.
+ ^ nil
].
(rasterType = 2) ifFalse: [
- "no compression of bytes"
- inStream nextBytes:(imageWords * 2) into:data
+ "no compression of bytes"
+ aStream nextBytes:(imageWords * 2) into:data
] ifTrue: [
- "run length compression of bytes"
+ "run length compression of bytes"
- bits _ ByteArray uninitializedNew: imageWords * 2.
- index := 1.
- a _ inStream next.
- [a notNil] whileTrue: [
- (a = 128) ifFalse: [
- bits at:index put: a.
- index := index + 1
- ] ifTrue: [
- b _ inStream next.
- b = 0 ifTrue: [
- bits at:index put:128 .
- index := index + 1
- ] ifFalse: [
- c := inStream next.
- 1 to:(b+1) do:[:i |
- bits at:index put:c.
- index := index + 1
- ]
- ]
- ].
- a _ inStream next
- ].
- 1 to: imageWords do: [:i | form bitsWordAt: i put: (bits wordAt: i)]
+ index := 1.
+ a := aStream next.
+ [a notNil] whileTrue: [
+ (a = 128) ifFalse: [
+ data at:index put: a.
+ index := index + 1
+ ] ifTrue: [
+ b := aStream next.
+ b = 0 ifTrue: [
+ data at:index put:128 .
+ index := index + 1
+ ] ifFalse: [
+ c := aStream next.
+ 1 to:(b+1) do:[:i |
+ data at:index put:c.
+ index := index + 1
+ ]
+ ]
+ ].
+ a := aStream next
+ ].
].
photometric := #whiteIs0.
samplesPerPixel := 1.
bitsPerSample := #(1).
- inStream close
- "Image fromFile:'../fileIn/bitmaps/founders.im8'"
+ "
+ Image fromFile:'bitmaps/founders.im8'
+ Image fromFile:'bitmaps/bf.im8'
+ SunRasterReader fromStream:'bitmaps/founders.im8' asFilename readStream
+ SunRasterReader fromStream:'bitmaps/bf.im8' asFilename readStream
+ "
+
!
-fromSunIconFile: aFilename
+fromSunIconStream: aStream
|index word
w "{ Class: SmallInteger }"
h "{ Class: SmallInteger }"|
- inStream := self class streamReadingFile:aFilename.
- inStream isNil ifTrue:[^ nil].
+ inStream := aStream.
- (inStream skipThroughAll:'idth') isNil ifTrue: [
- 'Not a Sun Raster/Icon File' errorPrintNewline.
- inStream close.
- ^nil
+ (aStream skipThroughAll:'idth') isNil ifTrue: [
+ 'SUNReader: Not a Sun Raster/Icon File' errorPrintNL.
+ ^nil
].
- inStream next; skipSeparators. "skip $="
- width := Integer readFrom: inStream.
+ aStream next; skipSeparators. "skip $="
+ width := Integer readFrom: aStream.
(width isNil or:[width <= 0]) ifTrue: [
- 'format error (expected number)' errorPrintNewline.
- inStream close.
- ^ nil
+ 'SUNReader: format error (expected number)' errorPrintNL.
+ ^ nil
].
w := width.
- (inStream skipThroughAll:'eight') isNil ifTrue: [
- 'format error (expected height)' errorPrintNewline.
- inStream close.
- ^ nil
+ (aStream skipThroughAll:'eight') isNil ifTrue: [
+ 'SUNReader: format error (expected height)' errorPrintNL.
+ ^ nil
].
- inStream next; skipSeparators. "skip $="
- height := Integer readFrom: inStream.
+ aStream next; skipSeparators. "skip $="
+ height := Integer readFrom: aStream.
(height isNil or:[height <= 0]) ifTrue: [
- 'format error (expected number)' errorPrintNewline.
- inStream close.
- ^nil
+ 'SUNReader: format error (expected number)' errorPrintNL.
+ ^nil
].
h := height.
@@ -256,18 +255,18 @@
index := 0.
1 to:h do: [:row |
- 1 to: (w + 15 // 16) do: [:col |
- "rows are rounded up to next multiple of 16 bits"
- (inStream skipThroughAll:'0x') isNil ifTrue: [^ nil].
- word := Integer readFrom:inStream radix:16.
- word isNil ifTrue:[
- 'format error' errorPrintNewline.
- inStream close.
- ^ nil
- ].
- data at: (index _ index + 1) put: (word bitShift:-8).
- data at: (index _ index + 1) put: (word bitAnd:16rFF).
- ]
+ 1 to: (w + 15 // 16) do: [:col |
+ "rows are rounded up to next multiple of 16 bits"
+ (aStream skipThroughAll:'0x') isNil ifTrue: [^ nil].
+ word := Integer readFrom:aStream radix:16.
+ word isNil ifTrue:[
+ 'SUNReader: format error' errorPrintNL.
+ ^ nil
+ ].
+ data at: (index _ index + 1) put: (word bitShift:-8).
+ data at: (index _ index + 1) put: (word bitAnd:16rFF).
+ ]
].
- inStream close.
! !
+
+SunRasterReader initialize!
--- a/SunReader.st Sat Feb 18 16:52:56 1995 +0100
+++ b/SunReader.st Sat Feb 18 16:58:20 1995 +0100
@@ -10,6 +10,8 @@
hereby transferred.
"
+'From Smalltalk/X, Version:2.10.4 on 18-feb-1995 at 2:18:51 am'!
+
ImageReader subclass:#SunRasterReader
instanceVariableNames:''
classVariableNames:''
@@ -21,7 +23,7 @@
COPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libview2/Attic/SunReader.st,v 1.10 1995-02-06 00:37:51 claus Exp $
+$Header: /cvs/stx/stx/libview2/Attic/SunReader.st,v 1.11 1995-02-18 15:58:11 claus Exp $
'!
!SunRasterReader class methodsFor:'documentation'!
@@ -42,7 +44,7 @@
version
"
-$Header: /cvs/stx/stx/libview2/Attic/SunReader.st,v 1.10 1995-02-06 00:37:51 claus Exp $
+$Header: /cvs/stx/stx/libview2/Attic/SunReader.st,v 1.11 1995-02-18 15:58:11 claus Exp $
"
!
@@ -114,138 +116,135 @@
!SunRasterReader methodsFor:'reading from file'!
-fromFile: aFilename
+fromStream: aStream
| rasterType mapType mapBytes imageWords form depth
rMap gMap bMap mapLen
- bits a b c index|
+ bits a b c index pos|
- inStream := self class streamReadingFile:aFilename.
- inStream isNil ifTrue:[^ nil].
+ inStream := aStream.
+
+ aStream binary.
- inStream binary.
-
- ((inStream nextWord == 16r59A6)
- and:[inStream nextWord == 16r6A95]) ifFalse: [
- inStream close.
- ^ self fromSunIconFile:aFilename
+ pos := aStream position.
+ ((aStream nextWord == 16r59A6)
+ and:[aStream nextWord == 16r6A95]) ifFalse: [
+ 'SUNReader: not a SunRaster file' errorPrintNL.
+ aStream position:pos.
+ ^ self fromSunIconStream:aStream
].
- width := inStream nextLong.
- height := inStream nextLong.
+ width := aStream nextLong.
+ height := aStream nextLong.
- depth := inStream nextLong.
- inStream nextLong. "Ignore the image length since I can't rely on it anyway."
- rasterType _ inStream nextLong.
- mapType := inStream nextLong. "Ignore the raster maptype."
- mapBytes := inStream nextLong.
+ depth := aStream nextLong.
+ aStream nextLong. "Ignore the image length since I can't rely on it anyway."
+ rasterType := aStream nextLong.
+ mapType := aStream nextLong. "Ignore the raster maptype."
+ mapBytes := aStream nextLong.
depth = 8 ifTrue: [
- mapLen := (mapBytes // 3).
- rMap := ByteArray uninitializedNew:mapLen.
- gMap := ByteArray uninitializedNew:mapLen.
- bMap := ByteArray uninitializedNew:mapLen.
- inStream nextBytes:mapLen into:rMap.
- inStream nextBytes:mapLen into:gMap.
- inStream nextBytes:mapLen into:bMap.
+ mapLen := (mapBytes // 3).
+ rMap := ByteArray uninitializedNew:mapLen.
+ gMap := ByteArray uninitializedNew:mapLen.
+ bMap := ByteArray uninitializedNew:mapLen.
+ aStream nextBytes:mapLen into:rMap.
+ aStream nextBytes:mapLen into:gMap.
+ aStream nextBytes:mapLen into:bMap.
- data := ByteArray uninitializedNew:(width * height).
- inStream nextBytes:(width * height) into:data.
+ data := ByteArray uninitializedNew:(width * height).
+ aStream nextBytes:(width * height) into:data.
- photometric := #palette.
- samplesPerPixel := 1.
- bitsPerSample := #(8).
-"/ colorMap := Array with:rMap with:gMap with:bMap.
- colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
- inStream close.
- ^ self
+ photometric := #palette.
+ samplesPerPixel := 1.
+ bitsPerSample := #(8).
+ colorMap := Colormap redVector:rMap greenVector:gMap blueVector:bMap.
+ ^ self
].
depth ~~ 1 ifTrue: [
- inStream close.
- self error: 'Raster file is not monochrome'
+ 'SUNReader: Raster file is not monochrome' errorPrintNL.
+ ^ nil
].
form := nil.
- inStream skip: mapBytes. "Skip the color map."
- imageWords _ (width / 16) ceiling * height.
+ aStream skip: mapBytes. "Skip the color map."
+ imageWords := (width / 16) ceiling * height.
data := ByteArray uninitializedNew:(imageWords * 2).
(rasterType between: 0 and: 2) ifFalse: [
- inStream close.
- self error: 'Unknown raster file rasterType'
+ 'SUNReader: Unknown raster file rasterType' errorPrintNL.
+ ^ nil
].
(rasterType = 2) ifFalse: [
- "no compression of bytes"
- inStream nextBytes:(imageWords * 2) into:data
+ "no compression of bytes"
+ aStream nextBytes:(imageWords * 2) into:data
] ifTrue: [
- "run length compression of bytes"
+ "run length compression of bytes"
- bits _ ByteArray uninitializedNew: imageWords * 2.
- index := 1.
- a _ inStream next.
- [a notNil] whileTrue: [
- (a = 128) ifFalse: [
- bits at:index put: a.
- index := index + 1
- ] ifTrue: [
- b _ inStream next.
- b = 0 ifTrue: [
- bits at:index put:128 .
- index := index + 1
- ] ifFalse: [
- c := inStream next.
- 1 to:(b+1) do:[:i |
- bits at:index put:c.
- index := index + 1
- ]
- ]
- ].
- a _ inStream next
- ].
- 1 to: imageWords do: [:i | form bitsWordAt: i put: (bits wordAt: i)]
+ index := 1.
+ a := aStream next.
+ [a notNil] whileTrue: [
+ (a = 128) ifFalse: [
+ data at:index put: a.
+ index := index + 1
+ ] ifTrue: [
+ b := aStream next.
+ b = 0 ifTrue: [
+ data at:index put:128 .
+ index := index + 1
+ ] ifFalse: [
+ c := aStream next.
+ 1 to:(b+1) do:[:i |
+ data at:index put:c.
+ index := index + 1
+ ]
+ ]
+ ].
+ a := aStream next
+ ].
].
photometric := #whiteIs0.
samplesPerPixel := 1.
bitsPerSample := #(1).
- inStream close
- "Image fromFile:'../fileIn/bitmaps/founders.im8'"
+ "
+ Image fromFile:'bitmaps/founders.im8'
+ Image fromFile:'bitmaps/bf.im8'
+ SunRasterReader fromStream:'bitmaps/founders.im8' asFilename readStream
+ SunRasterReader fromStream:'bitmaps/bf.im8' asFilename readStream
+ "
+
!
-fromSunIconFile: aFilename
+fromSunIconStream: aStream
|index word
w "{ Class: SmallInteger }"
h "{ Class: SmallInteger }"|
- inStream := self class streamReadingFile:aFilename.
- inStream isNil ifTrue:[^ nil].
+ inStream := aStream.
- (inStream skipThroughAll:'idth') isNil ifTrue: [
- 'Not a Sun Raster/Icon File' errorPrintNewline.
- inStream close.
- ^nil
+ (aStream skipThroughAll:'idth') isNil ifTrue: [
+ 'SUNReader: Not a Sun Raster/Icon File' errorPrintNL.
+ ^nil
].
- inStream next; skipSeparators. "skip $="
- width := Integer readFrom: inStream.
+ aStream next; skipSeparators. "skip $="
+ width := Integer readFrom: aStream.
(width isNil or:[width <= 0]) ifTrue: [
- 'format error (expected number)' errorPrintNewline.
- inStream close.
- ^ nil
+ 'SUNReader: format error (expected number)' errorPrintNL.
+ ^ nil
].
w := width.
- (inStream skipThroughAll:'eight') isNil ifTrue: [
- 'format error (expected height)' errorPrintNewline.
- inStream close.
- ^ nil
+ (aStream skipThroughAll:'eight') isNil ifTrue: [
+ 'SUNReader: format error (expected height)' errorPrintNL.
+ ^ nil
].
- inStream next; skipSeparators. "skip $="
- height := Integer readFrom: inStream.
+ aStream next; skipSeparators. "skip $="
+ height := Integer readFrom: aStream.
(height isNil or:[height <= 0]) ifTrue: [
- 'format error (expected number)' errorPrintNewline.
- inStream close.
- ^nil
+ 'SUNReader: format error (expected number)' errorPrintNL.
+ ^nil
].
h := height.
@@ -256,18 +255,18 @@
index := 0.
1 to:h do: [:row |
- 1 to: (w + 15 // 16) do: [:col |
- "rows are rounded up to next multiple of 16 bits"
- (inStream skipThroughAll:'0x') isNil ifTrue: [^ nil].
- word := Integer readFrom:inStream radix:16.
- word isNil ifTrue:[
- 'format error' errorPrintNewline.
- inStream close.
- ^ nil
- ].
- data at: (index _ index + 1) put: (word bitShift:-8).
- data at: (index _ index + 1) put: (word bitAnd:16rFF).
- ]
+ 1 to: (w + 15 // 16) do: [:col |
+ "rows are rounded up to next multiple of 16 bits"
+ (aStream skipThroughAll:'0x') isNil ifTrue: [^ nil].
+ word := Integer readFrom:aStream radix:16.
+ word isNil ifTrue:[
+ 'SUNReader: format error' errorPrintNL.
+ ^ nil
+ ].
+ data at: (index _ index + 1) put: (word bitShift:-8).
+ data at: (index _ index + 1) put: (word bitAnd:16rFF).
+ ]
].
- inStream close.
! !
+
+SunRasterReader initialize!
--- a/TargaReader.st Sat Feb 18 16:52:56 1995 +0100
+++ b/TargaReader.st Sat Feb 18 16:58:20 1995 +0100
@@ -37,7 +37,7 @@
version
"
-$Header: /cvs/stx/stx/libview2/TargaReader.st,v 1.1 1995-02-06 00:41:26 claus Exp $
+$Header: /cvs/stx/stx/libview2/TargaReader.st,v 1.2 1995-02-18 15:58:20 claus Exp $
"
!
@@ -68,27 +68,27 @@
isValidImageFile:aFileName
"return true, if aFileName contains a targa-file image"
- |inStream w h depth flags|
+ |aStream w h depth flags|
- inStream := self streamReadingFile:aFileName.
- inStream isNil ifTrue:[inStream close. ^ false].
- inStream binary.
- inStream skip:12. "/ skip 12 bytes
+ aStream := self streamReadingFile:aFileName.
+ aStream isNil ifTrue:[^ false].
+ aStream binary.
+ aStream skip:12. "/ skip 12 bytes
- w := inStream nextShortMSB:false.
- h := inStream nextShortMSB:false.
+ w := aStream nextShortMSB:false.
+ h := aStream nextShortMSB:false.
- depth := inStream next.
- flags := inStream next.
+ depth := aStream next.
+ flags := aStream next.
(#("8" 24) includes:depth) ifFalse:[
- inStream close. ^ false
+ aStream close. ^ false
].
flags ~~ 16r20 ifTrue:[
- inStream close. ^ false
+ aStream close. ^ false
].
- inStream close.
+ aStream close.
^ true
"
@@ -99,34 +99,30 @@
!TargaReader methodsFor:'reading from file'!
-fromFile:aFileName
+fromStream:aStream
"read a targa-image from aFileName. return the receiver (with all
relevant instance variables set for the image) or nil on error"
|depth flags|
- inStream := self class streamReadingFile:aFileName.
- inStream isNil ifTrue:[
- 'TARGA: file open error' errorPrintNL.
+ inStream := aStream.
+ aStream binary.
+
+ aStream skip:12.
+ width := aStream nextShortMSB:false.
+ height := aStream nextShortMSB:false.
+ depth := aStream next.
+ depth ~~ 24 ifTrue:[
+ 'TARGA: unsupported depth' errorPrintNL.
^ nil
].
- inStream binary.
- inStream skip:12.
- width := inStream nextShortMSB:false.
- height := inStream nextShortMSB:false.
- depth := inStream next.
- depth ~~ 24 ifTrue:[
- 'TARGA: unsupported depth' errorPrintNL.
- inStream close.
- ^ nil
- ].
- flags := inStream next.
+ flags := aStream next.
flags ~~ 16r20 ifTrue:[
^ false
].
data := ByteArray new:(width * height * (depth / 8)).
- inStream nextBytes:(data size) into:data.
+ aStream nextBytes:(data size) into:data.
"
mhmh - order is blue-green-red
"