author | Claus Gittinger <cg@exept.de> |
Thu, 07 Dec 1995 11:34:06 +0100 | |
changeset 134 | f83c245371c2 |
parent 120 | 719d6c8c3b39 |
child 196 | a3153c2b1d27 |
permissions | -rw-r--r-- |
5 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
26 | 3 |
All Rights Reserved |
5 | 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 |
|
26 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
32 | 17 |
category:'Graphics-Images support' |
0 | 18 |
! |
19 |
||
21 | 20 |
!FaceReader class methodsFor:'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
26 | 25 |
All Rights Reserved |
5 | 26 |
|
21 | 27 |
This software is furnished under a license and may be used |
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
5 | 35 |
|
21 | 36 |
version |
120 | 37 |
^ '$Header: /cvs/stx/stx/libview2/FaceReader.st,v 1.14 1995-11-22 15:14:27 cg Exp $' |
21 | 38 |
! |
5 | 39 |
|
21 | 40 |
documentation |
41 |
" |
|
42 |
this class knows how to read face files. |
|
120 | 43 |
(this format is used for people's faces - which can be optained from some |
21 | 44 |
ftp-servers, to improve mail- and/or newsreaders :-) |
120 | 45 |
Other than above, that format is not used often. |
46 |
||
47 |
The file format is (ascii): |
|
48 |
... |
|
49 |
FirstName: ... |
|
50 |
LastName: ... |
|
51 |
E-mail: ... |
|
52 |
PicData: ... |
|
53 |
Image: <width> <height> <depth> |
|
54 |
||
55 |
bits; encoded in uppercase hex ascii; 2 chars/pixel |
|
56 |
pixel values are greyscale-value; 0..255 |
|
57 |
||
58 |
only 8-bit greyscale is supported - I have never encountered |
|
59 |
any other face-file-format. |
|
114
e577a2f332d0
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
60 |
|
e577a2f332d0
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
61 |
Notice, that face files come in two formats: the one implemented here, |
e577a2f332d0
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
62 |
and the blitImage file format, which only supports 48x48x1 images. |
e577a2f332d0
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
63 |
The latter is supported by the BlitImageReader class. |
21 | 64 |
" |
65 |
! ! |
|
5 | 66 |
|
26 | 67 |
!FaceReader class methodsFor:'initialization'! |
68 |
||
69 |
initialize |
|
70 |
Image fileFormats at:'.face' put:self. |
|
71 |
! ! |
|
72 |
||
0 | 73 |
!FaceReader methodsFor:'reading from file'! |
74 |
||
43 | 75 |
fromStream:aStream |
0 | 76 |
|line |
77 |
dstIndex "{ Class: SmallInteger }" |
|
78 |
bytesPerRow |
|
79 |
lo "{ Class: SmallInteger }" |
|
80 |
hi "{ Class: SmallInteger }" |
|
81 |
val "{ Class: SmallInteger }" |
|
82 |
inHeader s depth| |
|
83 |
||
43 | 84 |
inStream := aStream. |
0 | 85 |
|
43 | 86 |
line := aStream nextLine. |
0 | 87 |
line isNil ifTrue:[ |
26 | 88 |
^ nil |
0 | 89 |
]. |
90 |
||
91 |
inHeader := true. |
|
92 |
[inHeader] whileTrue:[ |
|
26 | 93 |
(line startsWith:'Image:') ifTrue:[ |
94 |
s := ReadStream on:line. |
|
95 |
s position:7. |
|
96 |
width := Number readFrom:s. |
|
97 |
height := Number readFrom:s. |
|
98 |
depth := Number readFrom:s. |
|
99 |
inHeader := false. |
|
100 |
]. |
|
43 | 101 |
line := aStream nextLine |
0 | 102 |
]. |
103 |
||
104 |
depth == 8 ifFalse:[ |
|
26 | 105 |
self error:'only depth 8 supported' |
0 | 106 |
]. |
107 |
||
108 |
[line isEmpty] whileTrue:[ |
|
43 | 109 |
line := aStream nextLine. |
0 | 110 |
]. |
111 |
||
112 |
bytesPerRow := width * depth // 8. |
|
113 |
((width * depth \\ 8) ~~ 0) ifTrue:[ |
|
26 | 114 |
bytesPerRow := bytesPerRow + 1 |
0 | 115 |
]. |
116 |
||
1 | 117 |
data := ByteArray uninitializedNew:(bytesPerRow * height). |
0 | 118 |
dstIndex := data size. |
119 |
||
120 |
[line notNil] whileTrue:[ |
|
26 | 121 |
1 to:(line size) by:2 do:[:cI | |
122 |
hi := (line at:cI) digitValue. |
|
123 |
lo := (line at:(cI + 1)) digitValue. |
|
124 |
val := (hi bitShift:4) bitOr:lo. |
|
125 |
data at:dstIndex put:val. |
|
126 |
dstIndex := dstIndex - 1 |
|
127 |
]. |
|
43 | 128 |
line := aStream nextLine |
0 | 129 |
]. |
120 | 130 |
photometric := #blackIs0. |
0 | 131 |
samplesPerPixel := 1. |
132 |
bitsPerSample := #(8) |
|
133 |
||
120 | 134 |
" |
135 |
FaceReader fromFile:'../goodies/faces/next.com/steve.face' |
|
136 |
" |
|
0 | 137 |
"this is NOT steve jobs :-)" |
138 |
! ! |