--- a/XBMReader.st Mon Oct 10 03:32:51 1994 +0100
+++ b/XBMReader.st Mon Oct 10 03:34:22 1994 +0100
@@ -1,6 +1,6 @@
"
COPYRIGHT (c) 1992 by Claus Gittinger
- All Rights Reserved
+ 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
@@ -11,17 +11,17 @@
"
ImageReader subclass:#XBMReader
- instanceVariableNames:''
- classVariableNames:''
- poolDictionaries:''
- category:'Graphics-Support'
+ instanceVariableNames:''
+ classVariableNames:''
+ poolDictionaries:''
+ category:'Graphics-Support'
!
XBMReader comment:'
COPYRIGHT (c) 1992 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
-$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.7 1994-08-05 01:16:28 claus Exp $
+$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.8 1994-10-10 02:34:18 claus Exp $
'!
!XBMReader class methodsFor:'documentation'!
@@ -29,7 +29,7 @@
copyright
"
COPYRIGHT (c) 1992 by Claus Gittinger
- All Rights Reserved
+ 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
@@ -42,7 +42,7 @@
version
"
-$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.7 1994-08-05 01:16:28 claus Exp $
+$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.8 1994-10-10 02:34:18 claus Exp $
"
!
@@ -56,6 +56,12 @@
"
! !
+!XBMReader class methodsFor:'initialization'!
+
+initialize
+ Image fileFormats at:'.xbm' put:self.
+! !
+
!XBMReader methodsFor:'writing to file'!
save:image onFile:aFileName
@@ -65,8 +71,8 @@
outStream := FileStream newFileNamed:aFileName.
outStream isNil ifTrue:[
- 'create error' errorPrintNL.
- ^ nil
+ 'create error' errorPrintNL.
+ ^ nil
].
width := image width.
@@ -79,9 +85,9 @@
((samplesPerPixel ~~ 1)
or:[((bitsPerSample at:1) ~~ 1)
or:[(photometric ~~ #blackIs0) and:[photometric ~~ #whiteIs0]]]) ifTrue:[
- self error:'can only save Depth1Images'.
- outStream close.
- ^ nil.
+ self error:'can only save Depth1Images'.
+ outStream close.
+ ^ nil.
].
outStream nextPutAll: '#define xbm_width '.
@@ -99,13 +105,13 @@
srcIndex := 1.
height timesRepeat:[
- rowBytes timesRepeat:[
- outStream nextPutAll: '0x'.
- bits := data at:srcIndex. srcIndex := srcIndex + 1.
- (reverseBits at:(bits + 1)) printOn:outStream radix:16.
- outStream nextPutAll: ', '.
- ].
- outStream cr
+ rowBytes timesRepeat:[
+ outStream nextPutAll: '0x'.
+ bits := data at:srcIndex. srcIndex := srcIndex + 1.
+ (reverseBits at:(bits + 1)) printOn:outStream radix:16.
+ outStream nextPutAll: ', '.
+ ].
+ outStream cr
].
outStream nextPutAll: '};'; cr.
outStream close
@@ -125,25 +131,25 @@
line := inStream nextLine.
line isNil ifTrue:[
- inStream close.
- ^ false
+ inStream close.
+ ^ false
].
[line startsWith:'#'] whileFalse:[
- line := inStream nextLine.
- line isNil ifTrue:[
- inStream close.
- ^ false
- ]
+ line := inStream nextLine.
+ line isNil ifTrue:[
+ inStream close.
+ ^ false
+ ]
].
index1 := line indexOf:(Character space).
index2 := line indexOf:(Character space) startingAt:(index1 + 1).
(index2 == 0) ifTrue:[
- inStream close.
- ^ false
+ inStream close.
+ ^ false
].
keyword := line copyFrom:index1 to:(index2 - 1).
(keyword endsWith:'_width') ifFalse:[
- ^ false
+ ^ false
].
inStream close.
^ true
@@ -166,31 +172,31 @@
line := inStream nextLine.
line isNil ifTrue:[
- inStream close.
- ^ nil
+ inStream close.
+ ^ nil
].
[line startsWith:'#'] whileFalse:[
- line := inStream nextLine
+ line := inStream nextLine
].
(line startsWith:'#define') ifFalse:[
- 'format error (expected #define)' errorPrintNL.
- inStream close.
- ^ nil
+ 'format error (expected #define)' errorPrintNL.
+ inStream close.
+ ^ nil
].
index := line indexOf:(Character space).
index := line indexOf:(Character space) startingAt:(index + 1).
(index == 0) ifTrue:[
- 'format error' errorPrintNL.
- inStream close.
- ^ nil
+ 'format error' errorPrintNL.
+ inStream close.
+ ^ nil
].
((line copyTo:index - 1) endsWith:'width') ifFalse:[
- 'format error (expected width)' errorPrintNL.
- inStream close.
- ^ nil
+ 'format error (expected width)' errorPrintNL.
+ inStream close.
+ ^ nil
].
line := line copyFrom:(index + 1).
width := Number readFromString:line.
@@ -199,21 +205,21 @@
index := line indexOf:(Character space).
index := line indexOf:(Character space) startingAt:(index + 1).
(index == 0) ifTrue:[
- 'format error' errorPrintNL.
- inStream close.
- ^ nil
+ 'format error' errorPrintNL.
+ inStream close.
+ ^ nil
].
((line copyTo:index - 1) endsWith:'height') ifFalse:[
- 'format error (expected height)' errorPrintNL.
- inStream close.
- ^ nil
+ 'format error (expected height)' errorPrintNL.
+ inStream close.
+ ^ nil
].
line := line copyFrom:(index + 1).
height := Number readFromString:line.
bytesPerRow := width // 8.
((width \\ 8) ~~ 0) ifTrue:[
- bytesPerRow := bytesPerRow + 1
+ bytesPerRow := bytesPerRow + 1
].
reverseBits := self class reverseBits.
@@ -223,25 +229,25 @@
line := inStream nextLine.
[line startsWith:'#'] whileTrue:[
- line := inStream nextLine
+ line := inStream nextLine
].
line := inStream nextLine.
[line notNil] whileTrue:[
- index := 1.
- [index ~~ 0] whileTrue:[
- index := line indexOf:$x startingAt:index.
- (index ~~ 0) ifTrue:[
- index := index + 1.
- hi := (line at:index) digitValue.
- index := index + 1.
- lo := (line at:index) digitValue.
- val := (hi bitShift:4) bitOr:lo.
- data at:dstIndex put:(reverseBits at:(val + 1)).
- dstIndex := dstIndex + 1
- ]
- ].
- line := inStream nextLine
+ index := 1.
+ [index ~~ 0] whileTrue:[
+ index := line indexOf:$x startingAt:index.
+ (index ~~ 0) ifTrue:[
+ index := index + 1.
+ hi := (line at:index) digitValue.
+ index := index + 1.
+ lo := (line at:index) digitValue.
+ val := (hi bitShift:4) bitOr:lo.
+ data at:dstIndex put:(reverseBits at:(val + 1)).
+ dstIndex := dstIndex + 1
+ ]
+ ].
+ line := inStream nextLine
].
photometric := #whiteIs0.
samplesPerPixel := 1.