Initial revision
authorclaus
Sat, 11 Dec 1993 02:38:34 +0100
changeset 13 f6d396b2bcff
parent 12 6804b4ee340c
child 14 20638e830834
Initial revision
ST80FormReader.st
STFormRdr.st
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ST80FormReader.st	Sat Dec 11 02:38:34 1993 +0100
@@ -0,0 +1,134 @@
+"
+ COPYRIGHT (c) 1993 by Claus Gittinger
+              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
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+
+ImageReader subclass:#ST80FormReader
+         instanceVariableNames:''
+         classVariableNames:''
+         poolDictionaries:''
+         category:'Graphics-Support'
+!
+
+ST80FormReader comment:'
+
+COPYRIGHT (c) 1993 by Claus Gittinger
+              All Rights Reserved
+
+this class provides methods for loading and saving st80-bitmap-file images.
+
+$Header: /cvs/stx/stx/libview2/ST80FormReader.st,v 1.1 1993-12-11 01:38:34 claus Exp $
+written Nov 93 by claus
+'!
+
+!ST80FormReader methodsFor:'writing to file'!
+
+save:image onFile:aFileName
+    "save image as XBM file on aFileName"
+
+    |reverseBits bits srcIndex rowBytes|
+
+    outStream := FileStream newFileNamed:aFileName.
+    outStream isNil ifTrue:[
+        'create error' printNewline. 
+        ^ nil
+    ].
+
+    width := image width.
+    height := image height.
+    photometric := image photometric.
+    samplesPerPixel := image samplesPerPixel.
+    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.
+    outStream nextPutWord:height.
+    outStream nextPutWord:0.
+    outStream nextPutWord:0.
+    outStream nextPutBytes:(data size) from:data.
+
+    outStream close
+
+    "ST80FormReader save:(Image fromFile:'bitmaps/SBrowser.xbm') onFile:'test.form'"
+! !
+
+!ST80FormReader class methodsFor:'testing'!
+
+isValidImageFile:aFileName
+    "return true, if aFileName contains an st80-bitmap-file image"
+
+    |line inStream index1 index2 keyword|
+
+    inStream := FileStream readonlyFileNamed:aFileName.
+    inStream isNil ifTrue:[^ false].
+
+    inStream binary.
+    code := inStream nextWord.
+    code == 1 ifFalse:[
+        inStream close.
+        ^ false
+    ].
+    inStream close.
+    ^ true
+! !
+
+!ST80FormReader methodsFor:'reading from file'!
+
+fromFile:aFileName
+    |code 
+     offsetX offsetY
+     index    "{ Class: SmallInteger }"
+     dstIndex "{ Class: SmallInteger }"
+     bytesPerRow
+     lo       "{ Class: SmallInteger }"
+     hi       "{ Class: SmallInteger }"
+     val      "{ Class: SmallInteger }"
+     reverseBits|
+
+    inStream := FileStream readonlyFileNamed:aFileName.
+    inStream isNil ifTrue:[
+        'open error' printNewline.
+        ^ nil
+    ].
+
+    inStream binary.
+    code := inStream nextWord.
+    code isNil ifTrue:[
+        inStream close.
+        ^ nil
+    ].
+
+    width := inStream nextWord.
+    height := inStream nextWord.
+    offsetX := inStream nextWord.
+    offsetY := inStream nextWord.
+
+    nBytes := width + 15 // 16 * 2 * height.
+    data := ByteArray new:nBytes.
+    inStream nextBytes:nBytes.
+
+    inStream close.
+
+    photometric := #whiteIs0.
+    samplesPerPixel := 1.
+    bitsPerSample := #(1)
+
+    "ST80FormReader fromFile:''" 
+! !
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/STFormRdr.st	Sat Dec 11 02:38:34 1993 +0100
@@ -0,0 +1,134 @@
+"
+ COPYRIGHT (c) 1993 by Claus Gittinger
+              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
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+
+ImageReader subclass:#ST80FormReader
+         instanceVariableNames:''
+         classVariableNames:''
+         poolDictionaries:''
+         category:'Graphics-Support'
+!
+
+ST80FormReader comment:'
+
+COPYRIGHT (c) 1993 by Claus Gittinger
+              All Rights Reserved
+
+this class provides methods for loading and saving st80-bitmap-file images.
+
+$Header: /cvs/stx/stx/libview2/Attic/STFormRdr.st,v 1.1 1993-12-11 01:38:34 claus Exp $
+written Nov 93 by claus
+'!
+
+!ST80FormReader methodsFor:'writing to file'!
+
+save:image onFile:aFileName
+    "save image as XBM file on aFileName"
+
+    |reverseBits bits srcIndex rowBytes|
+
+    outStream := FileStream newFileNamed:aFileName.
+    outStream isNil ifTrue:[
+        'create error' printNewline. 
+        ^ nil
+    ].
+
+    width := image width.
+    height := image height.
+    photometric := image photometric.
+    samplesPerPixel := image samplesPerPixel.
+    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.
+    outStream nextPutWord:height.
+    outStream nextPutWord:0.
+    outStream nextPutWord:0.
+    outStream nextPutBytes:(data size) from:data.
+
+    outStream close
+
+    "ST80FormReader save:(Image fromFile:'bitmaps/SBrowser.xbm') onFile:'test.form'"
+! !
+
+!ST80FormReader class methodsFor:'testing'!
+
+isValidImageFile:aFileName
+    "return true, if aFileName contains an st80-bitmap-file image"
+
+    |line inStream index1 index2 keyword|
+
+    inStream := FileStream readonlyFileNamed:aFileName.
+    inStream isNil ifTrue:[^ false].
+
+    inStream binary.
+    code := inStream nextWord.
+    code == 1 ifFalse:[
+        inStream close.
+        ^ false
+    ].
+    inStream close.
+    ^ true
+! !
+
+!ST80FormReader methodsFor:'reading from file'!
+
+fromFile:aFileName
+    |code 
+     offsetX offsetY
+     index    "{ Class: SmallInteger }"
+     dstIndex "{ Class: SmallInteger }"
+     bytesPerRow
+     lo       "{ Class: SmallInteger }"
+     hi       "{ Class: SmallInteger }"
+     val      "{ Class: SmallInteger }"
+     reverseBits|
+
+    inStream := FileStream readonlyFileNamed:aFileName.
+    inStream isNil ifTrue:[
+        'open error' printNewline.
+        ^ nil
+    ].
+
+    inStream binary.
+    code := inStream nextWord.
+    code isNil ifTrue:[
+        inStream close.
+        ^ nil
+    ].
+
+    width := inStream nextWord.
+    height := inStream nextWord.
+    offsetX := inStream nextWord.
+    offsetY := inStream nextWord.
+
+    nBytes := width + 15 // 16 * 2 * height.
+    data := ByteArray new:nBytes.
+    inStream nextBytes:nBytes.
+
+    inStream close.
+
+    photometric := #whiteIs0.
+    samplesPerPixel := 1.
+    bitsPerSample := #(1)
+
+    "ST80FormReader fromFile:''" 
+! !