commentary
authorClaus Gittinger <cg@exept.de>
Tue, 23 Apr 1996 12:38:49 +0200
changeset 202 651db5018d9c
parent 201 c707ed0db1d0
child 203 a38debd57097
commentary
XBMReader.st
--- a/XBMReader.st	Tue Apr 23 12:36:29 1996 +0200
+++ b/XBMReader.st	Tue Apr 23 12:38:49 1996 +0200
@@ -50,7 +50,12 @@
 !XBMReader class methodsFor:'initialization'!
 
 initialize
+    "tell Image-class, that a new fileReader is present
+     for the '.xbm' extension."
+
     Image fileFormats at:'.xbm'  put:self.
+
+    "Modified: 23.4.1996 / 12:37:30 / cg"
 ! !
 
 !XBMReader class methodsFor:'testing'!
@@ -103,6 +108,8 @@
 !XBMReader methodsFor:'reading from file'!
 
 fromStream:aStream
+    "read an image in xbm format from aStream"
+
     |line 
      index    "{ Class: SmallInteger }"
      dstIndex "{ Class: SmallInteger }"
@@ -116,28 +123,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.
@@ -146,19 +153,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.
@@ -168,29 +175,29 @@
 
     line := aStream nextLine.
     [line startsWith:'#'] whileTrue:[
-	line := aStream nextLine.
+        line := aStream nextLine.
     ].
 
     [line notNil and:[(line startsWith:'static') not]] 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.
@@ -198,13 +205,16 @@
 
     "
      XBMReader fromFile:'bitmaps/globe1.xbm'
-    " 
+    "
+
+    "Modified: 23.4.1996 / 12:38:05 / cg"
 ! !
 
 !XBMReader methodsFor:'writing to file'!
 
 save:image onFile:aFileName
-    "save image as XBM file on aFileName"
+    "save image as XBM file on aFileName.
+     Only depth1 b&w images can be represented in this format."
 
     |reverseBits bits byte
      h        "{ Class: SmallInteger }"
@@ -212,14 +222,14 @@
      rowBytes "{ Class: SmallInteger }" |
 
     (self class canRepresent:image) ifFalse:[
-	self error:'can only save depth 1 B&W images'.
-	^ nil.
+        self error:'can only save depth 1 B&W images'.
+        ^ nil.
     ].
 
     outStream := FileStream newFileNamed:aFileName.
     outStream isNil ifTrue:[
-	'XBMReader: create error' errorPrintNL. 
-	^ nil
+        'XBMReader: create error' errorPrintNL. 
+        ^ nil
     ].
 
     width := image width.
@@ -245,20 +255,20 @@
 
     h := height.
     h timesRepeat:[
-	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
-	    ].
-	    byte printOn:outStream radix:16.
-	    outStream nextPutAll: ', '.
-	].
-	outStream cr
+        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
+            ].
+            byte printOn:outStream radix:16.
+            outStream nextPutAll: ', '.
+        ].
+        outStream cr
     ].
     outStream nextPutAll: '};'; cr.
     outStream close
@@ -271,11 +281,13 @@
 
      XBMReader save:(Image fromFile:'bitmaps/hello_world.icon') onFile:'test.xbm'
     "
+
+    "Modified: 23.4.1996 / 12:38:30 / cg"
 ! !
 
 !XBMReader class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.20 1996-04-23 10:25:50 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.21 1996-04-23 10:38:49 cg Exp $'
 ! !
 XBMReader initialize!