ST80FormReader.st
author claus
Sat, 18 Feb 1995 16:58:20 +0100
changeset 43 e85c7d392833
parent 32 6bdcb6da4d4f
child 51 ac84315b8181
permissions -rw-r--r--
*** empty log message ***

"
 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.
"

'From Smalltalk/X, Version:2.10.4 on 18-feb-1995 at 2:18:48 am'!

ImageReader subclass:#ST80FormReader
	 instanceVariableNames:''
	 classVariableNames:''
	 poolDictionaries:''
	 category:'Graphics-Images support'
!

ST80FormReader comment:'
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 $
'!

!ST80FormReader class methodsFor:'documentation'!

copyright
"
 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.
"
!

version
"
$Header: /cvs/stx/stx/libview2/ST80FormReader.st,v 1.6 1995-02-18 15:58:02 claus Exp $
"
!

documentation
"
    this class provides methods for loading and saving st80-bitmap-file images.
    I am not sure, if this format is still supported/used by newer ST-80
    versions; it used to be in 2.x versions (from what can be deduced by some
    bitmaps found in the manchester goodies).
    No writing is supported by this class.
"
! !

!ST80FormReader class methodsFor:'testing'!

isValidImageFile:aFileName
    "return true, if aFileName contains an st80-bitmap-file image"

    |code inStream ok|

    inStream := self streamReadingFile:aFileName.
    inStream isNil ifTrue:[^ false].

    inStream binary.
    code := inStream nextWord.
    ok := (code == 1).
    inStream close.
    ^ ok
! !

!ST80FormReader methodsFor:'writing to file'!

save:image onFile:aFileName
    "save image as XBM file on aFileName"

    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 methodsFor:'reading from file'!

fromStream:aStream
    |nBytes code offsetX offsetY|

    inStream := aStream.
    inStream binary.

    code := inStream nextWord.
    code isNil ifTrue:[
        ^ nil
    ].

    width := aStream nextWord.
    height := aStream nextWord.
    offsetX := aStream nextWord.
    offsetY := aStream nextWord.

    nBytes := width + 15 // 16 * 2 * height.
    data := ByteArray new:nBytes.
    aStream nextBytes:nBytes into:data.

    photometric := #whiteIs0.
    samplesPerPixel := 1.
    bitsPerSample := #(1)

    "ST80FormReader fromFile:''" 
! !