5
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
0
|
12 |
|
|
13 |
ImageReader subclass:#FaceReader
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Graphics-Support'
|
|
18 |
!
|
|
19 |
|
5
|
20 |
FaceReader comment:'
|
|
21 |
|
|
22 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
23 |
All Rights Reserved
|
|
24 |
|
|
25 |
this class knows how to read face files.
|
|
26 |
|
15
|
27 |
$Header: /cvs/stx/stx/libview2/FaceReader.st,v 1.5 1994-01-08 17:12:56 claus Exp $
|
5
|
28 |
|
|
29 |
written spring 93 by claus
|
|
30 |
'!
|
|
31 |
|
0
|
32 |
!FaceReader methodsFor:'reading from file'!
|
|
33 |
|
|
34 |
fromFile:aFileName
|
|
35 |
|line
|
|
36 |
dstIndex "{ Class: SmallInteger }"
|
|
37 |
bytesPerRow
|
|
38 |
lo "{ Class: SmallInteger }"
|
|
39 |
hi "{ Class: SmallInteger }"
|
|
40 |
val "{ Class: SmallInteger }"
|
|
41 |
inHeader s depth|
|
|
42 |
|
8
|
43 |
inStream := self class streamReadingFile:aFileName.
|
|
44 |
inStream isNil ifTrue:[^ nil].
|
0
|
45 |
|
|
46 |
line := inStream nextLine.
|
|
47 |
line isNil ifTrue:[
|
|
48 |
inStream close.
|
|
49 |
^ nil
|
|
50 |
].
|
|
51 |
|
|
52 |
inHeader := true.
|
|
53 |
[inHeader] whileTrue:[
|
|
54 |
(line startsWith:'Image:') ifTrue:[
|
|
55 |
s := ReadStream on:line.
|
|
56 |
s position:7.
|
|
57 |
width := Number readFrom:s.
|
|
58 |
height := Number readFrom:s.
|
|
59 |
depth := Number readFrom:s.
|
|
60 |
inHeader := false.
|
|
61 |
].
|
|
62 |
line := inStream nextLine
|
|
63 |
].
|
|
64 |
|
|
65 |
depth == 8 ifFalse:[
|
|
66 |
self error:'only depth 8 supported'
|
|
67 |
].
|
|
68 |
|
|
69 |
[line isEmpty] whileTrue:[
|
|
70 |
line := inStream nextLine.
|
|
71 |
].
|
|
72 |
|
|
73 |
bytesPerRow := width * depth // 8.
|
|
74 |
((width * depth \\ 8) ~~ 0) ifTrue:[
|
|
75 |
bytesPerRow := bytesPerRow + 1
|
|
76 |
].
|
|
77 |
|
1
|
78 |
data := ByteArray uninitializedNew:(bytesPerRow * height).
|
0
|
79 |
dstIndex := data size.
|
|
80 |
|
|
81 |
[line notNil] whileTrue:[
|
|
82 |
1 to:(line size) by:2 do:[:cI |
|
|
83 |
hi := (line at:cI) digitValue.
|
|
84 |
lo := (line at:(cI + 1)) digitValue.
|
|
85 |
val := (hi bitShift:4) bitOr:lo.
|
|
86 |
data at:dstIndex put:val.
|
|
87 |
dstIndex := dstIndex - 1
|
|
88 |
].
|
|
89 |
line := inStream nextLine
|
|
90 |
].
|
|
91 |
photometric := #whiteIs0.
|
|
92 |
samplesPerPixel := 1.
|
|
93 |
bitsPerSample := #(8)
|
|
94 |
|
|
95 |
"FaceReader fromFile:'../goodies/faces/next.com/steve.face'"
|
|
96 |
"this is NOT steve jobs :-)"
|
|
97 |
! !
|