--- a/SunRasterReader.st Fri Feb 25 14:11:30 1994 +0100
+++ b/SunRasterReader.st Fri Jun 03 02:54:11 1994 +0200
@@ -18,30 +18,52 @@
!
SunRasterReader comment:'
+COPYRIGHT (c) 1993 by Claus Gittinger
+ All Rights Reserved
+'!
-COPYRIGHT (c) 1993 by Claus Gittinger
+!SunRasterReader class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
-this class provides methods for loading Sun Raster file images
+ 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.
+"
+!
-$Header: /cvs/stx/stx/libview2/SunRasterReader.st,v 1.5 1994-01-08 17:16:04 claus Exp $
-written Summer 91 by claus
-'!
+version
+"
+$Header: /cvs/stx/stx/libview2/SunRasterReader.st,v 1.6 1994-06-03 00:53:47 claus Exp $
+"
+!
+
+documentation
+"
+ this class provides methods for loading Sun Raster file images
+"
+! !
!SunRasterReader class methodsFor:'testing'!
isValidImageFile:aFileName
"return true, if aFileName contains a sunraster image"
- |inStream|
+ |inStream nr|
inStream := self streamReadingFile:aFileName.
inStream isNil ifTrue:[^ false].
"try sun raster"
inStream binary.
- ((inStream nextWord = 16r59A6)
- and:[inStream nextWord = 16r6A95]) ifTrue: [
+ ((inStream nextWord == 16r59A6)
+ and:[inStream nextWord == 16r6A95]) ifTrue: [
inStream close.
^ true
].
@@ -49,22 +71,24 @@
"try sun bitmap image format"
inStream text.
inStream reset.
- (inStream skipToAll: 'idth') isNil ifTrue: [
+ (inStream skipThroughAll: 'idth') isNil ifTrue: [
inStream close.
^ false
].
- inStream skip: 5; skipSeparators.
- (Integer readFrom: inStream) <= 0 ifTrue: [
+ inStream next; skipSeparators.
+ nr := Integer readFrom: inStream.
+ (nr isNil or:[nr <= 0]) ifTrue: [
inStream close.
^ false
].
- (inStream skipToAll: 'eight') isNil ifTrue: [
+ (inStream skipThroughAll: 'eight') isNil ifTrue: [
inStream close.
^ false
].
- inStream skip: 6; skipSeparators.
- (Integer readFrom: inStream) <= 0 ifTrue: [
+ inStream next; skipSeparators.
+ nr := Integer readFrom: inStream.
+ (nr isNil or:[nr <= 0]) ifTrue: [
inStream close.
^ false
].
@@ -85,8 +109,8 @@
inStream binary.
- ((inStream nextWord = 16r59A6)
- and:[inStream nextWord = 16r6A95]) ifFalse: [
+ ((inStream nextWord == 16r59A6)
+ and:[inStream nextWord == 16r6A95]) ifFalse: [
inStream close.
^ self fromSunIconFile:aFilename
].
@@ -174,21 +198,40 @@
!
fromSunIconFile: aFilename
- | index word |
+ |index word
+ w "{ Class: SmallInteger }"
+ h "{ Class: SmallInteger }"|
inStream := self class streamReadingFile:aFilename.
inStream isNil ifTrue:[^ nil].
- (inStream skipToAll: 'idth') isNil ifTrue: [
- 'Not a Sun Raster/Icon File' printNewline.
+ (inStream skipThroughAll:'idth') isNil ifTrue: [
+ 'Not a Sun Raster/Icon File' errorPrintNewline.
+ inStream close.
^nil
].
- inStream skip: 5; skipSeparators.
- (width := Integer readFrom: inStream) <= 0 ifTrue: [^nil].
+ inStream next; skipSeparators. "skip $="
+ width := Integer readFrom: inStream.
+ (width isNil or:[width <= 0]) ifTrue: [
+ 'format error (expected number)' errorPrintNewline.
+ inStream close.
+ ^ nil
+ ].
+ w := width.
- (inStream skipToAll: 'eight') isNil ifTrue: [^nil].
- inStream skip: 6; skipSeparators.
- (height := Integer readFrom: inStream) <= 0 ifTrue: [^nil].
+ (inStream skipThroughAll:'eight') isNil ifTrue: [
+ 'format error (expected height)' errorPrintNewline.
+ inStream close.
+ ^ nil
+ ].
+ inStream next; skipSeparators. "skip $="
+ height := Integer readFrom: inStream.
+ (height isNil or:[height <= 0]) ifTrue: [
+ 'format error (expected number)' errorPrintNewline.
+ inStream close.
+ ^nil
+ ].
+ h := height.
data := ByteArray uninitializedNew:((width + 7 // 8) * height).
photometric := #whiteIs0.
@@ -196,14 +239,19 @@
bitsPerSample := #(1).
index := 0.
- 1 to: height do: [:row |
- 1 to: (width + 15 // 16) do: [:col |
- "rows are rounded up to next multiple of 16 bits"
- (inStream skipToAll: '0x') isNil ifTrue: [^nil]. inStream skip: 2.
- word := Integer readFrom: inStream radix: 16.
- data at: (index _ index + 1) put: (word bitShift:-8).
- data at: (index _ index + 1) put: (word bitAnd:16rFF).
- ]
+ 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).
+ ]
].
inStream close.
! !