author | Claus Gittinger <cg@exept.de> |
Sat, 11 Nov 1995 17:05:49 +0100 | |
changeset 114 | e577a2f332d0 |
parent 99 | a656b0c9dd21 |
child 120 | 719d6c8c3b39 |
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 |
114
e577a2f332d0
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
37 |
^ '$Header: /cvs/stx/stx/libview2/FaceReader.st,v 1.13 1995-11-11 16:04:27 cg Exp $' |
21 | 38 |
! |
5 | 39 |
|
21 | 40 |
documentation |
41 |
" |
|
42 |
this class knows how to read face files. |
|
43 |
(this format is used for peoples faces - which can be optained from some |
|
44 |
ftp-servers, to improve mail- and/or newsreaders :-) |
|
114
e577a2f332d0
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
45 |
|
e577a2f332d0
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
46 |
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
|
47 |
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
|
48 |
The latter is supported by the BlitImageReader class. |
21 | 49 |
" |
50 |
! ! |
|
5 | 51 |
|
26 | 52 |
!FaceReader class methodsFor:'initialization'! |
53 |
||
54 |
initialize |
|
55 |
Image fileFormats at:'.face' put:self. |
|
56 |
! ! |
|
57 |
||
0 | 58 |
!FaceReader methodsFor:'reading from file'! |
59 |
||
43 | 60 |
fromStream:aStream |
0 | 61 |
|line |
62 |
dstIndex "{ Class: SmallInteger }" |
|
63 |
bytesPerRow |
|
64 |
lo "{ Class: SmallInteger }" |
|
65 |
hi "{ Class: SmallInteger }" |
|
66 |
val "{ Class: SmallInteger }" |
|
67 |
inHeader s depth| |
|
68 |
||
43 | 69 |
inStream := aStream. |
0 | 70 |
|
43 | 71 |
line := aStream nextLine. |
0 | 72 |
line isNil ifTrue:[ |
26 | 73 |
^ nil |
0 | 74 |
]. |
75 |
||
76 |
inHeader := true. |
|
77 |
[inHeader] whileTrue:[ |
|
26 | 78 |
(line startsWith:'Image:') ifTrue:[ |
79 |
s := ReadStream on:line. |
|
80 |
s position:7. |
|
81 |
width := Number readFrom:s. |
|
82 |
height := Number readFrom:s. |
|
83 |
depth := Number readFrom:s. |
|
84 |
inHeader := false. |
|
85 |
]. |
|
43 | 86 |
line := aStream nextLine |
0 | 87 |
]. |
88 |
||
89 |
depth == 8 ifFalse:[ |
|
26 | 90 |
self error:'only depth 8 supported' |
0 | 91 |
]. |
92 |
||
93 |
[line isEmpty] whileTrue:[ |
|
43 | 94 |
line := aStream nextLine. |
0 | 95 |
]. |
96 |
||
97 |
bytesPerRow := width * depth // 8. |
|
98 |
((width * depth \\ 8) ~~ 0) ifTrue:[ |
|
26 | 99 |
bytesPerRow := bytesPerRow + 1 |
0 | 100 |
]. |
101 |
||
1 | 102 |
data := ByteArray uninitializedNew:(bytesPerRow * height). |
0 | 103 |
dstIndex := data size. |
104 |
||
105 |
[line notNil] whileTrue:[ |
|
26 | 106 |
1 to:(line size) by:2 do:[:cI | |
107 |
hi := (line at:cI) digitValue. |
|
108 |
lo := (line at:(cI + 1)) digitValue. |
|
109 |
val := (hi bitShift:4) bitOr:lo. |
|
110 |
data at:dstIndex put:val. |
|
111 |
dstIndex := dstIndex - 1 |
|
112 |
]. |
|
43 | 113 |
line := aStream nextLine |
0 | 114 |
]. |
115 |
photometric := #whiteIs0. |
|
116 |
samplesPerPixel := 1. |
|
117 |
bitsPerSample := #(8) |
|
118 |
||
119 |
"FaceReader fromFile:'../goodies/faces/next.com/steve.face'" |
|
120 |
"this is NOT steve jobs :-)" |
|
121 |
! ! |