BlitImageReader.st
author Claus Gittinger <cg@exept.de>
Thu, 09 Nov 1995 17:10:26 +0100
changeset 112 9b59ed94db13
child 113 465cc202f0fe
permissions -rw-r--r--
q&d hack (for Blit faces)

'From Smalltalk/X, Version:2.10.8 on 9-nov-1995 at 17:08:48'                    !

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

!BlitImageReader class methodsFor:'documentation'!

version
"
$Header: /cvs/stx/stx/libview2/BlitImageReader.st,v 1.1 1995-11-09 16:10:26 cg Exp $
"

    "Created: 9.11.1995 / 17:08:06 / cg"
!

documentation
"
    A q&d hack to read 48x48x1 Blit images (faces)
"

    "Created: 9.11.1995 / 17:08:06 / cg"
    "Modified: 9.11.1995 / 17:08:26 / cg"
!

examples
"
    Image fromFile:'.../.../48x48x1'
"

    "Created: 9.11.1995 / 17:08:06 / cg"
    "Modified: 9.11.1995 / 17:08:42 / cg"
!

history

    "Created: 9.11.1995 / 17:08:06 / cg"
    "Modified: 9.11.1995 / 17:08:06 / cg"
! !

!BlitImageReader class methodsFor:'initialization'!

initialize
    Image fileFormats at:'48x48x1'  put:self.

    "
     BlitImageReader initialize
    "

    "Created: 9.11.1995 / 17:05:04 / cg"
    "Modified: 9.11.1995 / 17:06:28 / cg"
! !

!BlitImageReader class methodsFor:'testing'!

isValidImageFile:aFileName
    "return true, if aFileName contains a GIF image"

    ^ aFileName = '48x48x1'

    "Created: 9.11.1995 / 17:04:29 / cg"
! !

!BlitImageReader methodsFor:'reading'!

fromStream:aStream
    |line 
     dstIndex "{ Class: SmallInteger }"
     bytesPerRow
     s words nm|

    "/
    "/ extract its size from the name
    "/ kludge
    "/
    aStream pathName notNil ifTrue:[
        nm := aStream pathName asFilename baseName.
        ('[0-9][0-9]x[0-9][0-9]x1' match:nm) ifTrue:[
            width := Integer readFromString:(nm copyFrom:1 to:2).
            height := Integer readFromString:(nm copyFrom:4 to:5).
        ].
    ].
    width isNil ifTrue:[
        ^ nil
    ].

    bytesPerRow := width // 8.
    ((width \\ 8) ~~ 0) ifTrue:[
        bytesPerRow := bytesPerRow + 1
    ].
    data := ByteArray new:(bytesPerRow * height).
    dstIndex := 1.

    [aStream atEnd] whileFalse:[
        line := aStream nextLine.
        line notNil ifTrue:[
            words := (line asCollectionOfSubstringsSeparatedBy:$,) asOrderedCollection.
            words last isEmpty ifTrue:[
                words removeLast
            ].
            words do:[:w |
                |s bits|

                s := w readStream.
                s skip:2.
                bits := Integer readFrom:s radix:16 onError:0. 
                data at:dstIndex put:(bits bitShift:-8).
                data at:dstIndex+1 put:(bits bitAnd:16rFF).
                dstIndex := dstIndex + 2
            ]
        ]
    ].


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

    "
     BlitImageReader fromFile:'/tmp/faces/facedir/facedir/misc./acsnet/48x48x1'
    "

    "Created: 9.11.1995 / 17:03:04 / cg"
! !

BlitImageReader initialize!