0
|
1 |
'From Smalltalk/X, Version:2.6.4 on 30-Apr-1993 at 18:40:58'!
|
|
2 |
|
|
3 |
ImageReader subclass:#FaceReader
|
|
4 |
instanceVariableNames:''
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Graphics-Support'
|
|
8 |
!
|
|
9 |
|
|
10 |
!FaceReader methodsFor:'reading from file'!
|
|
11 |
|
|
12 |
fromFile:aFileName
|
|
13 |
|line
|
|
14 |
index "{ Class: SmallInteger }"
|
|
15 |
dstIndex "{ Class: SmallInteger }"
|
|
16 |
bytesPerRow
|
|
17 |
lo "{ Class: SmallInteger }"
|
|
18 |
hi "{ Class: SmallInteger }"
|
|
19 |
val "{ Class: SmallInteger }"
|
|
20 |
inHeader s depth|
|
|
21 |
|
|
22 |
inStream := FileStream readonlyFileNamed:aFileName.
|
|
23 |
inStream isNil ifTrue:[
|
|
24 |
'open error' printNewline.
|
|
25 |
^ nil
|
|
26 |
].
|
|
27 |
|
|
28 |
line := inStream nextLine.
|
|
29 |
line isNil ifTrue:[
|
|
30 |
inStream close.
|
|
31 |
^ nil
|
|
32 |
].
|
|
33 |
|
|
34 |
inHeader := true.
|
|
35 |
[inHeader] whileTrue:[
|
|
36 |
(line startsWith:'Image:') ifTrue:[
|
|
37 |
s := ReadStream on:line.
|
|
38 |
s position:7.
|
|
39 |
width := Number readFrom:s.
|
|
40 |
height := Number readFrom:s.
|
|
41 |
depth := Number readFrom:s.
|
|
42 |
inHeader := false.
|
|
43 |
].
|
|
44 |
line := inStream nextLine
|
|
45 |
].
|
|
46 |
|
|
47 |
depth == 8 ifFalse:[
|
|
48 |
self error:'only depth 8 supported'
|
|
49 |
].
|
|
50 |
|
|
51 |
[line isEmpty] whileTrue:[
|
|
52 |
line := inStream nextLine.
|
|
53 |
].
|
|
54 |
|
|
55 |
bytesPerRow := width * depth // 8.
|
|
56 |
((width * depth \\ 8) ~~ 0) ifTrue:[
|
|
57 |
bytesPerRow := bytesPerRow + 1
|
|
58 |
].
|
|
59 |
|
1
|
60 |
data := ByteArray uninitializedNew:(bytesPerRow * height).
|
0
|
61 |
dstIndex := data size.
|
|
62 |
|
|
63 |
[line notNil] whileTrue:[
|
|
64 |
1 to:(line size) by:2 do:[:cI |
|
|
65 |
hi := (line at:cI) digitValue.
|
|
66 |
lo := (line at:(cI + 1)) digitValue.
|
|
67 |
val := (hi bitShift:4) bitOr:lo.
|
|
68 |
data at:dstIndex put:val.
|
|
69 |
dstIndex := dstIndex - 1
|
|
70 |
].
|
|
71 |
line := inStream nextLine
|
|
72 |
].
|
|
73 |
photometric := #whiteIs0.
|
|
74 |
samplesPerPixel := 1.
|
|
75 |
bitsPerSample := #(8)
|
|
76 |
|
|
77 |
"FaceReader fromFile:'../goodies/faces/next.com/steve.face'"
|
|
78 |
"this is NOT steve jobs :-)"
|
|
79 |
! !
|