XBMReader.st
changeset 41 66edc847b9c8
parent 33 be90784ee668
child 51 ac84315b8181
--- a/XBMReader.st	Sat Feb 18 16:32:43 1995 +0100
+++ b/XBMReader.st	Sat Feb 18 16:52:52 1995 +0100
@@ -10,6 +10,8 @@
  hereby transferred.
 "
 
+'From Smalltalk/X, Version:2.10.4 on 18-feb-1995 at 2:23:58 am'!
+
 ImageReader subclass:#XBMReader
 	 instanceVariableNames:''
 	 classVariableNames:''
@@ -21,7 +23,7 @@
 COPYRIGHT (c) 1992 by Claus Gittinger
 	      All Rights Reserved
 
-$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.9 1994-11-17 14:31:40 claus Exp $
+$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.10 1995-02-18 15:52:48 claus Exp $
 '!
 
 !XBMReader class methodsFor:'documentation'!
@@ -42,7 +44,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.9 1994-11-17 14:31:40 claus Exp $
+$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.10 1995-02-18 15:52:48 claus Exp $
 "
 !
 
@@ -62,6 +64,140 @@
     Image fileFormats at:'.xbm'  put:self.
 ! !
 
+!XBMReader class methodsFor:'testing'!
+
+isValidImageFile:aFileName
+    "return true, if aFileName contains an x-bitmap-file image"
+
+    |line inStream index1 index2 keyword|
+
+    inStream := self streamReadingFile:aFileName.
+    inStream isNil ifTrue:[^ false].
+
+    line := inStream nextLine.
+    line isNil ifTrue:[
+	inStream close.
+	^ false
+    ].
+    [line startsWith:'#'] whileFalse:[
+	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
+    ].
+    keyword := line copyFrom:index1 to:(index2 - 1).
+    (keyword endsWith:'_width') ifFalse:[
+	inStream close.
+	^ false
+    ].
+    inStream close.
+    ^ true
+! !
+
+!XBMReader methodsFor:'reading from file'!
+
+fromStream:aStream
+    |line 
+     index    "{ Class: SmallInteger }"
+     dstIndex "{ Class: SmallInteger }"
+     bytesPerRow
+     lo       "{ Class: SmallInteger }"
+     hi       "{ Class: SmallInteger }"
+     val      "{ Class: SmallInteger }"
+     reverseBits|
+
+    inStream := aStream.
+
+    line := aStream nextLine.
+    line isNil ifTrue:[
+        'XBMReader: short file' errorPrintNL.
+        ^ nil
+    ].
+
+    [line startsWith:'#'] whileFalse:[
+        line := aStream nextLine
+    ].
+
+    (line startsWith:'#define') ifFalse:[
+        '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
+    ].
+    ((line copyTo:index - 1) endsWith:'width') ifFalse:[
+        'XBMReader: format error (expected width)' errorPrintNL.
+        ^ nil
+    ].
+    line := line copyFrom:(index + 1).
+    width := Number readFromString:line.
+
+    line := aStream nextLine.
+    index := line indexOf:(Character space).
+    index := line indexOf:(Character space) startingAt:(index + 1).
+    (index == 0) ifTrue:[
+        'XBMReader: format error' errorPrintNL.
+        ^ nil
+    ].
+    ((line copyTo:index - 1) endsWith:'height') ifFalse:[
+        '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
+    ].
+
+    reverseBits := self class reverseBits.
+
+    data := ByteArray new:(bytesPerRow * height).
+    dstIndex := 1.
+
+    line := aStream nextLine.
+    [line startsWith:'#'] whileTrue:[
+        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
+    ].
+    photometric := #whiteIs0.
+    samplesPerPixel := 1.
+    bitsPerSample := #(1).
+
+    "
+     XBMReader fromFile:'bitmaps/globe1.xbm'
+    " 
+! !
+
 !XBMReader methodsFor:'writing to file'!
 
 save:image onFile:aFileName
@@ -132,139 +268,4 @@
     "
 ! !
 
-!XBMReader class methodsFor:'testing'!
-
-isValidImageFile:aFileName
-    "return true, if aFileName contains an x-bitmap-file image"
-
-    |line inStream index1 index2 keyword|
-
-    inStream := self streamReadingFile:aFileName.
-    inStream isNil ifTrue:[^ false].
-
-    line := inStream nextLine.
-    line isNil ifTrue:[
-	inStream close.
-	^ false
-    ].
-    [line startsWith:'#'] whileFalse:[
-	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
-    ].
-    keyword := line copyFrom:index1 to:(index2 - 1).
-    (keyword endsWith:'_width') ifFalse:[
-	^ false
-    ].
-    inStream close.
-    ^ true
-! !
-
-!XBMReader methodsFor:'reading from file'!
-
-fromFile:aFileName
-    |line 
-     index    "{ Class: SmallInteger }"
-     dstIndex "{ Class: SmallInteger }"
-     bytesPerRow
-     lo       "{ Class: SmallInteger }"
-     hi       "{ Class: SmallInteger }"
-     val      "{ Class: SmallInteger }"
-     reverseBits|
-
-    inStream := self class streamReadingFile:aFileName.
-    inStream isNil ifTrue:[^ nil].
-
-    line := inStream nextLine.
-    line isNil ifTrue:[
-	inStream close.
-	^ nil
-    ].
-
-    [line startsWith:'#'] whileFalse:[
-	line := inStream nextLine
-    ].
-
-    (line startsWith:'#define') ifFalse:[
-	'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
-    ].
-    ((line copyTo:index - 1) endsWith:'width') ifFalse:[
-	'format error (expected width)' errorPrintNL.
-	inStream close.
-	^ nil
-    ].
-    line := line copyFrom:(index + 1).
-    width := Number readFromString:line.
-
-    line := inStream nextLine.
-    index := line indexOf:(Character space).
-    index := line indexOf:(Character space) startingAt:(index + 1).
-    (index == 0) ifTrue:[
-	'format error' errorPrintNL.
-	inStream close.
-	^ nil
-    ].
-    ((line copyTo:index - 1) endsWith:'height') ifFalse:[
-	'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
-    ].
-
-    reverseBits := self class reverseBits.
-
-    data := ByteArray new:(bytesPerRow * height).
-    dstIndex := 1.
-
-    line := inStream nextLine.
-    [line startsWith:'#'] whileTrue:[
-	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
-    ].
-    photometric := #whiteIs0.
-    samplesPerPixel := 1.
-    bitsPerSample := #(1).
-
-    "XBMReader fromFile:'bitmaps/globe1.xbm'" 
-! !
+XBMReader initialize!