112
|
1 |
'From Smalltalk/X, Version:2.10.8 on 9-nov-1995 at 17:08:48' !
|
|
2 |
|
|
3 |
ImageReader subclass:#BlitImageReader
|
|
4 |
instanceVariableNames:''
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Graphics-Images support'
|
|
8 |
!
|
|
9 |
|
|
10 |
!BlitImageReader class methodsFor:'documentation'!
|
|
11 |
|
|
12 |
version
|
|
13 |
"
|
|
14 |
$Header: /cvs/stx/stx/libview2/BlitImageReader.st,v 1.1 1995-11-09 16:10:26 cg Exp $
|
|
15 |
"
|
|
16 |
|
|
17 |
"Created: 9.11.1995 / 17:08:06 / cg"
|
|
18 |
!
|
|
19 |
|
|
20 |
documentation
|
|
21 |
"
|
|
22 |
A q&d hack to read 48x48x1 Blit images (faces)
|
|
23 |
"
|
|
24 |
|
|
25 |
"Created: 9.11.1995 / 17:08:06 / cg"
|
|
26 |
"Modified: 9.11.1995 / 17:08:26 / cg"
|
|
27 |
!
|
|
28 |
|
|
29 |
examples
|
|
30 |
"
|
|
31 |
Image fromFile:'.../.../48x48x1'
|
|
32 |
"
|
|
33 |
|
|
34 |
"Created: 9.11.1995 / 17:08:06 / cg"
|
|
35 |
"Modified: 9.11.1995 / 17:08:42 / cg"
|
|
36 |
!
|
|
37 |
|
|
38 |
history
|
|
39 |
|
|
40 |
"Created: 9.11.1995 / 17:08:06 / cg"
|
|
41 |
"Modified: 9.11.1995 / 17:08:06 / cg"
|
|
42 |
! !
|
|
43 |
|
|
44 |
!BlitImageReader class methodsFor:'initialization'!
|
|
45 |
|
|
46 |
initialize
|
|
47 |
Image fileFormats at:'48x48x1' put:self.
|
|
48 |
|
|
49 |
"
|
|
50 |
BlitImageReader initialize
|
|
51 |
"
|
|
52 |
|
|
53 |
"Created: 9.11.1995 / 17:05:04 / cg"
|
|
54 |
"Modified: 9.11.1995 / 17:06:28 / cg"
|
|
55 |
! !
|
|
56 |
|
|
57 |
!BlitImageReader class methodsFor:'testing'!
|
|
58 |
|
|
59 |
isValidImageFile:aFileName
|
|
60 |
"return true, if aFileName contains a GIF image"
|
|
61 |
|
|
62 |
^ aFileName = '48x48x1'
|
|
63 |
|
|
64 |
"Created: 9.11.1995 / 17:04:29 / cg"
|
|
65 |
! !
|
|
66 |
|
|
67 |
!BlitImageReader methodsFor:'reading'!
|
|
68 |
|
|
69 |
fromStream:aStream
|
|
70 |
|line
|
|
71 |
dstIndex "{ Class: SmallInteger }"
|
|
72 |
bytesPerRow
|
|
73 |
s words nm|
|
|
74 |
|
|
75 |
"/
|
|
76 |
"/ extract its size from the name
|
|
77 |
"/ kludge
|
|
78 |
"/
|
|
79 |
aStream pathName notNil ifTrue:[
|
|
80 |
nm := aStream pathName asFilename baseName.
|
|
81 |
('[0-9][0-9]x[0-9][0-9]x1' match:nm) ifTrue:[
|
|
82 |
width := Integer readFromString:(nm copyFrom:1 to:2).
|
|
83 |
height := Integer readFromString:(nm copyFrom:4 to:5).
|
|
84 |
].
|
|
85 |
].
|
|
86 |
width isNil ifTrue:[
|
|
87 |
^ nil
|
|
88 |
].
|
|
89 |
|
|
90 |
bytesPerRow := width // 8.
|
|
91 |
((width \\ 8) ~~ 0) ifTrue:[
|
|
92 |
bytesPerRow := bytesPerRow + 1
|
|
93 |
].
|
|
94 |
data := ByteArray new:(bytesPerRow * height).
|
|
95 |
dstIndex := 1.
|
|
96 |
|
|
97 |
[aStream atEnd] whileFalse:[
|
|
98 |
line := aStream nextLine.
|
|
99 |
line notNil ifTrue:[
|
|
100 |
words := (line asCollectionOfSubstringsSeparatedBy:$,) asOrderedCollection.
|
|
101 |
words last isEmpty ifTrue:[
|
|
102 |
words removeLast
|
|
103 |
].
|
|
104 |
words do:[:w |
|
|
105 |
|s bits|
|
|
106 |
|
|
107 |
s := w readStream.
|
|
108 |
s skip:2.
|
|
109 |
bits := Integer readFrom:s radix:16 onError:0.
|
|
110 |
data at:dstIndex put:(bits bitShift:-8).
|
|
111 |
data at:dstIndex+1 put:(bits bitAnd:16rFF).
|
|
112 |
dstIndex := dstIndex + 2
|
|
113 |
]
|
|
114 |
]
|
|
115 |
].
|
|
116 |
|
|
117 |
|
|
118 |
photometric := #whiteIs0.
|
|
119 |
samplesPerPixel := 1.
|
|
120 |
bitsPerSample := #(1)
|
|
121 |
|
|
122 |
"
|
|
123 |
BlitImageReader fromFile:'/tmp/faces/facedir/facedir/misc./acsnet/48x48x1'
|
|
124 |
"
|
|
125 |
|
|
126 |
"Created: 9.11.1995 / 17:03:04 / cg"
|
|
127 |
! !
|
|
128 |
|
|
129 |
BlitImageReader initialize!
|