ST80FormReader.st
changeset 51 ac84315b8181
parent 43 e85c7d392833
child 96 948318b2fbd4
--- 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.