FaceReader.st
author claus
Sat, 11 Dec 1993 02:28:10 +0100
changeset 8 0a804f13c332
parent 5 4d55b551dc57
child 15 51f58761f657
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.
"

ImageReader subclass:#FaceReader
         instanceVariableNames:''
         classVariableNames:''
         poolDictionaries:''
         category:'Graphics-Support'
!

FaceReader comment:'

COPYRIGHT (c) 1993 by Claus Gittinger
              All Rights Reserved

this class knows how to read face files.

$Header: /cvs/stx/stx/libview2/FaceReader.st,v 1.4 1993-12-11 01:28:10 claus Exp $

written spring 93 by claus
'!

!FaceReader methodsFor:'reading from file'!

fromFile:aFileName
    |line 
     index    "{ Class: SmallInteger }"
     dstIndex "{ Class: SmallInteger }"
     bytesPerRow
     lo       "{ Class: SmallInteger }"
     hi       "{ Class: SmallInteger }"
     val      "{ Class: SmallInteger }"
     inHeader s depth|

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

    line := inStream nextLine.
    line isNil ifTrue:[
        inStream close.
        ^ nil
    ].

    inHeader := true.
    [inHeader] whileTrue:[
        (line startsWith:'Image:') ifTrue:[
            s := ReadStream on:line.
            s position:7.
            width := Number readFrom:s.
            height := Number readFrom:s.
            depth := Number readFrom:s.
            inHeader := false.
        ].
        line := inStream nextLine
    ].

    depth == 8 ifFalse:[
        self error:'only depth 8 supported'
    ].

    [line isEmpty] whileTrue:[
        line := inStream nextLine.
    ].

    bytesPerRow := width * depth // 8.
    ((width * depth \\ 8) ~~ 0) ifTrue:[
        bytesPerRow := bytesPerRow + 1
    ].

    data := ByteArray uninitializedNew:(bytesPerRow * height).
    dstIndex := data size.

    [line notNil] whileTrue:[
        1 to:(line size) by:2 do:[:cI |
            hi := (line at:cI) digitValue.
            lo := (line at:(cI + 1)) digitValue.
            val := (hi bitShift:4) bitOr:lo.
            data at:dstIndex put:val.
            dstIndex := dstIndex - 1
        ].
        line := inStream nextLine
    ].
    photometric := #whiteIs0.
    samplesPerPixel := 1.
    bitsPerSample := #(8)

    "FaceReader fromFile:'../goodies/faces/next.com/steve.face'"
    "this is NOT steve jobs :-)"
! !