--- a/PBMReader.st Thu Mar 23 17:51:31 1995 +0100
+++ b/PBMReader.st Thu Mar 23 17:54:02 1995 +0100
@@ -21,7 +21,7 @@
COPYRIGHT (c) 1992 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libview2/PBMReader.st,v 1.9 1995-02-22 01:18:55 claus Exp $
+$Header: /cvs/stx/stx/libview2/PBMReader.st,v 1.10 1995-03-23 16:52:41 claus Exp $
'!
!PBMReader class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
version
"
-$Header: /cvs/stx/stx/libview2/PBMReader.st,v 1.9 1995-02-22 01:18:55 claus Exp $
+$Header: /cvs/stx/stx/libview2/PBMReader.st,v 1.10 1995-03-23 16:52:41 claus Exp $
"
!
@@ -116,6 +116,22 @@
^self skipXPMJunkOn: aStream.
! !
+!PBMReader methodsFor:'testing '!
+
+canRepresent:anImage
+ "return true, if anImage can be represented in my file format.
+ Currently only B&W and Depth8 images are supported."
+
+ |depth|
+
+ anImage photometric == #rgb ifTrue:[
+ ^ false "/ not yet implemented
+ ].
+ (depth := anImage depth) == 1 ifTrue:[^ true].
+ depth == 8 ifTrue:[^ true].
+ ^ false
+! !
+
!PBMReader methodsFor:'writing to file'!
save:image onFile:aFileName
--- a/ST80FormReader.st Thu Mar 23 17:51:31 1995 +0100
+++ b/ST80FormReader.st Thu Mar 23 17:54:02 1995 +0100
@@ -23,7 +23,7 @@
COPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libview2/ST80FormReader.st,v 1.6 1995-02-18 15:58:02 claus Exp $
+$Header: /cvs/stx/stx/libview2/ST80FormReader.st,v 1.7 1995-03-23 16:52:52 claus Exp $
'!
!ST80FormReader class methodsFor:'documentation'!
@@ -44,7 +44,7 @@
version
"
-$Header: /cvs/stx/stx/libview2/ST80FormReader.st,v 1.6 1995-02-18 15:58:02 claus Exp $
+$Header: /cvs/stx/stx/libview2/ST80FormReader.st,v 1.7 1995-03-23 16:52:52 claus Exp $
"
!
@@ -73,6 +73,17 @@
ok := (code == 1).
inStream close.
^ ok
+!
+
+canRepresent:anImage
+ "return true, if anImage can be represented in my file format.
+ Only B&Wimages are supported."
+
+ |photometric|
+
+ anImage depth ~~ 1 ifTrue:[^ false].
+ (((photometric := anImage photometric) ~~ #blackIs0) and:[photometric ~~ #whiteIs0]) ifTrue:[^ false.].
+ ^ true
! !
!ST80FormReader methodsFor:'writing to file'!
@@ -80,6 +91,11 @@
save:image onFile:aFileName
"save image as XBM file on aFileName"
+ (self class canRepresent:image) ifFalse:[
+ self error:'can only save Depth1Images'.
+ ^ nil.
+ ].
+
outStream := FileStream newFileNamed:aFileName.
outStream isNil ifTrue:[
'create error' printNewline.
@@ -93,14 +109,6 @@
bitsPerSample := image bitsPerSample.
colorMap := image colorMap.
- ((samplesPerPixel ~~ 1)
- or:[((bitsPerSample at:1) ~~ 1)
- or:[(photometric ~~ #blackIs0) and:[photometric ~~ #whiteIs0]]]) ifTrue:[
- self error:'can only save Depth1Images'.
- outStream close.
- ^ nil.
- ].
-
outStream binary.
outStream nextPutWord:1.
outStream nextPutWord:width.
@@ -124,7 +132,7 @@
code := inStream nextWord.
code isNil ifTrue:[
- ^ nil
+ ^ nil
].
width := aStream nextWord.
--- a/STFormRdr.st Thu Mar 23 17:51:31 1995 +0100
+++ b/STFormRdr.st Thu Mar 23 17:54:02 1995 +0100
@@ -23,7 +23,7 @@
COPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libview2/Attic/STFormRdr.st,v 1.6 1995-02-18 15:58:02 claus Exp $
+$Header: /cvs/stx/stx/libview2/Attic/STFormRdr.st,v 1.7 1995-03-23 16:52:52 claus Exp $
'!
!ST80FormReader class methodsFor:'documentation'!
@@ -44,7 +44,7 @@
version
"
-$Header: /cvs/stx/stx/libview2/Attic/STFormRdr.st,v 1.6 1995-02-18 15:58:02 claus Exp $
+$Header: /cvs/stx/stx/libview2/Attic/STFormRdr.st,v 1.7 1995-03-23 16:52:52 claus Exp $
"
!
@@ -73,6 +73,17 @@
ok := (code == 1).
inStream close.
^ ok
+!
+
+canRepresent:anImage
+ "return true, if anImage can be represented in my file format.
+ Only B&Wimages are supported."
+
+ |photometric|
+
+ anImage depth ~~ 1 ifTrue:[^ false].
+ (((photometric := anImage photometric) ~~ #blackIs0) and:[photometric ~~ #whiteIs0]) ifTrue:[^ false.].
+ ^ true
! !
!ST80FormReader methodsFor:'writing to file'!
@@ -80,6 +91,11 @@
save:image onFile:aFileName
"save image as XBM file on aFileName"
+ (self class canRepresent:image) ifFalse:[
+ self error:'can only save Depth1Images'.
+ ^ nil.
+ ].
+
outStream := FileStream newFileNamed:aFileName.
outStream isNil ifTrue:[
'create error' printNewline.
@@ -93,14 +109,6 @@
bitsPerSample := image bitsPerSample.
colorMap := image colorMap.
- ((samplesPerPixel ~~ 1)
- or:[((bitsPerSample at:1) ~~ 1)
- or:[(photometric ~~ #blackIs0) and:[photometric ~~ #whiteIs0]]]) ifTrue:[
- self error:'can only save Depth1Images'.
- outStream close.
- ^ nil.
- ].
-
outStream binary.
outStream nextPutWord:1.
outStream nextPutWord:width.
@@ -124,7 +132,7 @@
code := inStream nextWord.
code isNil ifTrue:[
- ^ nil
+ ^ nil
].
width := aStream nextWord.
--- a/TIFFRdr.st Thu Mar 23 17:51:31 1995 +0100
+++ b/TIFFRdr.st Thu Mar 23 17:54:02 1995 +0100
@@ -27,7 +27,7 @@
COPYRIGHT (c) 1991 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libview2/Attic/TIFFRdr.st,v 1.16 1995-02-18 15:32:43 claus Exp $
+$Header: /cvs/stx/stx/libview2/Attic/TIFFRdr.st,v 1.17 1995-03-23 16:53:03 claus Exp $
'!
!TIFFReader class methodsFor:'documentation'!
@@ -48,7 +48,7 @@
version
"
-$Header: /cvs/stx/stx/libview2/Attic/TIFFRdr.st,v 1.16 1995-02-18 15:32:43 claus Exp $
+$Header: /cvs/stx/stx/libview2/Attic/TIFFRdr.st,v 1.17 1995-03-23 16:53:03 claus Exp $
"
!
@@ -105,6 +105,13 @@
(version ~~ 42) ifTrue:[^ false].
^ true
+!
+
+canRepresent:anImage
+ "return true, if anImage can be represented in my file format.
+ Any image is supported."
+
+ ^ true
! !
!TIFFReader methodsFor:'reading from file'!
@@ -290,7 +297,6 @@
compression := 1. "none"
data := image bits.
-
currentOffset := 0.
(byteOrder == #msb) ifTrue:[
--- a/TIFFReader.st Thu Mar 23 17:51:31 1995 +0100
+++ b/TIFFReader.st Thu Mar 23 17:54:02 1995 +0100
@@ -27,7 +27,7 @@
COPYRIGHT (c) 1991 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libview2/TIFFReader.st,v 1.16 1995-02-18 15:32:43 claus Exp $
+$Header: /cvs/stx/stx/libview2/TIFFReader.st,v 1.17 1995-03-23 16:53:03 claus Exp $
'!
!TIFFReader class methodsFor:'documentation'!
@@ -48,7 +48,7 @@
version
"
-$Header: /cvs/stx/stx/libview2/TIFFReader.st,v 1.16 1995-02-18 15:32:43 claus Exp $
+$Header: /cvs/stx/stx/libview2/TIFFReader.st,v 1.17 1995-03-23 16:53:03 claus Exp $
"
!
@@ -105,6 +105,13 @@
(version ~~ 42) ifTrue:[^ false].
^ true
+!
+
+canRepresent:anImage
+ "return true, if anImage can be represented in my file format.
+ Any image is supported."
+
+ ^ true
! !
!TIFFReader methodsFor:'reading from file'!
@@ -290,7 +297,6 @@
compression := 1. "none"
data := image bits.
-
currentOffset := 0.
(byteOrder == #msb) ifTrue:[
--- a/XBMReader.st Thu Mar 23 17:51:31 1995 +0100
+++ b/XBMReader.st Thu Mar 23 17:54:02 1995 +0100
@@ -23,7 +23,7 @@
COPYRIGHT (c) 1992 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.10 1995-02-18 15:52:48 claus Exp $
+$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.11 1995-03-23 16:53:49 claus Exp $
'!
!XBMReader class methodsFor:'documentation'!
@@ -44,7 +44,7 @@
version
"
-$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.10 1995-02-18 15:52:48 claus Exp $
+$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.11 1995-03-23 16:53:49 claus Exp $
"
!
@@ -99,6 +99,16 @@
].
inStream close.
^ true
+!
+
+canRepresent:anImage
+ "return true, if anImage can be represented in my file format"
+
+ |photometric|
+
+ (anImage depth ~~ 1) ifTrue:[^ false.].
+ (((photometric := anImage photometric) ~~ #blackIs0) and:[photometric ~~ #whiteIs0]) ifTrue:[^ false.].
+ ^ true
! !
!XBMReader methodsFor:'reading from file'!
@@ -117,28 +127,28 @@
line := aStream nextLine.
line isNil ifTrue:[
- 'XBMReader: short file' errorPrintNL.
- ^ nil
+ 'XBMReader: short file' errorPrintNL.
+ ^ nil
].
[line startsWith:'#'] whileFalse:[
- line := aStream nextLine
+ line := aStream nextLine
].
(line startsWith:'#define') ifFalse:[
- 'XBMReader: format error (expected #define)' errorPrintNL.
- ^ nil
+ 'XBMReader: format error (expected #define)' errorPrintNL.
+ ^ nil
].
index := line indexOf:(Character space).
index := line indexOf:(Character space) startingAt:(index + 1).
(index == 0) ifTrue:[
- 'XBMReader: format error' errorPrintNL.
- ^ nil
+ 'XBMReader: format error' errorPrintNL.
+ ^ nil
].
((line copyTo:index - 1) endsWith:'width') ifFalse:[
- 'XBMReader: format error (expected width)' errorPrintNL.
- ^ nil
+ 'XBMReader: format error (expected width)' errorPrintNL.
+ ^ nil
].
line := line copyFrom:(index + 1).
width := Number readFromString:line.
@@ -147,19 +157,19 @@
index := line indexOf:(Character space).
index := line indexOf:(Character space) startingAt:(index + 1).
(index == 0) ifTrue:[
- 'XBMReader: format error' errorPrintNL.
- ^ nil
+ 'XBMReader: format error' errorPrintNL.
+ ^ nil
].
((line copyTo:index - 1) endsWith:'height') ifFalse:[
- 'XBMReader: format error (expected height)' errorPrintNL.
- ^ nil
+ 'XBMReader: format error (expected height)' errorPrintNL.
+ ^ 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.
@@ -169,25 +179,25 @@
line := aStream nextLine.
[line startsWith:'#'] whileTrue:[
- line := aStream nextLine
+ line := aStream nextLine
].
line := aStream 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 := aStream 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 := aStream nextLine
].
photometric := #whiteIs0.
samplesPerPixel := 1.
@@ -207,6 +217,11 @@
srcIndex "{ Class: SmallInteger }"
rowBytes "{ Class: SmallInteger }" |
+ (self class canRepresent:image) ifFalse:[
+ self error:'can only save depth 1 B&W images'.
+ ^ nil.
+ ].
+
outStream := FileStream newFileNamed:aFileName.
outStream isNil ifTrue:[
'create error' errorPrintNL.
@@ -220,14 +235,6 @@
bitsPerSample := image bitsPerSample.
colorMap := image colorMap.
- ((samplesPerPixel ~~ 1)
- or:[((bitsPerSample at:1) ~~ 1)
- or:[(photometric ~~ #blackIs0) and:[photometric ~~ #whiteIs0]]]) ifTrue:[
- self error:'can only save Depth1Images'.
- outStream close.
- ^ nil.
- ].
-
outStream nextPutAll: '#define xbm_width '.
outStream nextPutAll:(width printString).
outStream cr.
@@ -246,6 +253,9 @@
rowBytes timesRepeat:[
outStream nextPutAll: '0x'.
bits := data at:srcIndex. srcIndex := srcIndex + 1.
+ photometric == #blackIs0 ifTrue:[
+ bits := bits bitInvert bitAnd:16rFF
+ ].
byte := (reverseBits at:(bits + 1)).
byte < 16 ifTrue:[
outStream nextPut:$0
--- a/XWDReader.st Thu Mar 23 17:51:31 1995 +0100
+++ b/XWDReader.st Thu Mar 23 17:54:02 1995 +0100
@@ -8,6 +8,11 @@
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
+
+
+ The above copyright does not apply to:
+ XWDReader>>save:onFile:
+ which is in the public domain.
"
ImageReader subclass:#XWDReader
@@ -21,7 +26,7 @@
COPYRIGHT (c) 1995 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libview2/XWDReader.st,v 1.5 1995-03-18 05:13:10 claus Exp $
+$Header: /cvs/stx/stx/libview2/XWDReader.st,v 1.6 1995-03-23 16:54:02 claus Exp $
'!
!XWDReader class methodsFor:'documentation'!
@@ -37,12 +42,17 @@
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
+
+
+ The above copyright does not apply to:
+ XWDReader>>save:onFile:
+ which is in the public domain.
"
!
version
"
-$Header: /cvs/stx/stx/libview2/XWDReader.st,v 1.5 1995-03-18 05:13:10 claus Exp $
+$Header: /cvs/stx/stx/libview2/XWDReader.st,v 1.6 1995-03-23 16:54:02 claus Exp $
"
!
@@ -53,6 +63,17 @@
"
! !
+!XWDReader class methodsFor:'queries'!
+
+canRepresent:anImage
+ "return true, if anImage can be represented in my file format.
+ Only depth8 palette images are supported."
+
+ anImage depth ~~ 8 ifTrue:[^ false].
+ anImage photometric ~~ #palette ifTrue:[^ false].
+ ^ true
+! !
+
!XWDReader methodsFor:'image reading'!
fromStream: aStream
@@ -154,16 +175,14 @@
DISTRIBUTION world
VERSION 1.0
DATE July 1993
+
+ thanks to Brad for giving us the base for this mehtod.
"
- | aStream rgbColor paletteColors ncolors cindex dumpName headerSize |
+ |aStream rgbColor paletteColors ncolors cindex dumpName headerSize|
- image bitsPerPixel ~~ 8 ifTrue:[
- self error:'XWD format only supports 8bit images'.
- ^ nil
- ].
- image photometric ~~ #palette ifTrue:[
- self error:'XWD format only supports palette images'.
+ (self class canRepresent:image) ifFalse:[
+ self error:'XWD format only supports 8bit palette images'.
^ nil
].
@@ -249,4 +268,3 @@
(Image fromFile: '/tmp/st.xwd') inspect
"
! !
-