"
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-Images support'
!
!FaceReader 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/FaceReader.st,v 1.14 1995-11-22 15:14:27 cg Exp $'
!
documentation
"
this class knows how to read face files.
(this format is used for people's faces - which can be optained from some
ftp-servers, to improve mail- and/or newsreaders :-)
Other than above, that format is not used often.
The file format is (ascii):
...
FirstName: ...
LastName: ...
E-mail: ...
PicData: ...
Image: <width> <height> <depth>
bits; encoded in uppercase hex ascii; 2 chars/pixel
pixel values are greyscale-value; 0..255
only 8-bit greyscale is supported - I have never encountered
any other face-file-format.
Notice, that face files come in two formats: the one implemented here,
and the blitImage file format, which only supports 48x48x1 images.
The latter is supported by the BlitImageReader class.
"
! !
!FaceReader class methodsFor:'initialization'!
initialize
Image fileFormats at:'.face' put:self.
! !
!FaceReader methodsFor:'reading from file'!
fromStream:aStream
|line
dstIndex "{ Class: SmallInteger }"
bytesPerRow
lo "{ Class: SmallInteger }"
hi "{ Class: SmallInteger }"
val "{ Class: SmallInteger }"
inHeader s depth|
inStream := aStream.
line := aStream nextLine.
line isNil ifTrue:[
^ 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 := aStream nextLine
].
depth == 8 ifFalse:[
self error:'only depth 8 supported'
].
[line isEmpty] whileTrue:[
line := aStream 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 := aStream nextLine
].
photometric := #blackIs0.
samplesPerPixel := 1.
bitsPerSample := #(8)
"
FaceReader fromFile:'../goodies/faces/next.com/steve.face'
"
"this is NOT steve jobs :-)"
! !