author | Claus Gittinger <cg@exept.de> |
Thu, 25 Apr 1996 18:32:07 +0200 | |
changeset 221 | ea942fe5dc04 |
parent 210 | 5405de794686 |
child 234 | b6352d13e792 |
permissions | -rw-r--r-- |
118
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
1 |
" |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
3 |
All Rights Reserved |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
4 |
|
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
5 |
This software is furnished under a license and may be used |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
6 |
only in accordance with the terms of that license and with the |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
7 |
inclusion of the above copyright notice. This software may not |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
8 |
be provided or otherwise made available to, or used by, any |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
9 |
other person. No title to or ownership of the software is |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
10 |
hereby transferred. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
11 |
" |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
12 |
|
112 | 13 |
ImageReader subclass:#BlitImageReader |
206 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Graphics-Images support' |
|
112 | 18 |
! |
19 |
||
20 |
!BlitImageReader class methodsFor:'documentation'! |
|
21 |
||
118
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
22 |
copyright |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
23 |
" |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
24 |
COPYRIGHT (c) 1995 by Claus Gittinger |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
25 |
All Rights Reserved |
112 | 26 |
|
118
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
27 |
This software is furnished under a license and may be used |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
28 |
only in accordance with the terms of that license and with the |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
29 |
inclusion of the above copyright notice. This software may not |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
30 |
be provided or otherwise made available to, or used by, any |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
31 |
other person. No title to or ownership of the software is |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
32 |
hereby transferred. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
33 |
" |
206 | 34 |
! |
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
A q&d hack to read 48x48x1 Blit images (faces) |
|
39 |
A variation of this format is also used to pass face-icons in mail headers |
|
40 |
(X-face: header line). |
|
41 |
To support those, images can also be read from a string which is |
|
42 |
encoded in that format (see: #fromCompressedString:). |
|
43 |
||
44 |
[See also:] |
|
45 |
GIFReader FaceReader JPEGReader PBMReader PCXReader |
|
210 | 46 |
ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader |
209 | 47 |
XBMReader XPMReader XWDReader |
206 | 48 |
" |
49 |
! |
|
50 |
||
51 |
examples |
|
52 |
" |
|
53 |
Image fromFile:'.../.../48x48x1' |
|
54 |
" |
|
112 | 55 |
! ! |
56 |
||
57 |
!BlitImageReader class methodsFor:'initialization'! |
|
58 |
||
59 |
initialize |
|
206 | 60 |
"install myself in the Image classes fileFormat table |
61 |
for files named `48x48x1' (funny)." |
|
62 |
||
112 | 63 |
Image fileFormats at:'48x48x1' put:self. |
64 |
||
65 |
" |
|
66 |
BlitImageReader initialize |
|
67 |
" |
|
68 |
||
206 | 69 |
"Modified: 23.4.1996 / 12:47:48 / cg" |
112 | 70 |
! ! |
71 |
||
113 | 72 |
!BlitImageReader class methodsFor:'special formats'! |
73 |
||
206 | 74 |
fromCompressedString:aString |
75 |
"given a compressed image string (such as present in mail headers), |
|
76 |
return a Depth1Image for it. |
|
77 |
Since I am not willing to port/include the uncompface stuff into ST/X, |
|
78 |
open a pipe to the uncompressor. |
|
79 |
If you dont have compface/uncompface, get it from your nearest ftp server." |
|
80 |
||
81 |
|f s img| |
|
82 |
||
83 |
f := Filename newTemporary. |
|
84 |
s := f writeStream. |
|
85 |
s nextPutAll:aString. |
|
86 |
s close. |
|
87 |
||
88 |
s := PipeStream readingFrom:('uncompface ' , f name). |
|
89 |
s isNil ifTrue:[ |
|
90 |
'BLITIMGREADER: no uncompface utility.' errorPrintNL. |
|
91 |
f delete. |
|
92 |
^ nil |
|
93 |
]. |
|
94 |
||
95 |
img := self fromStream:s. |
|
96 |
s close. |
|
97 |
f delete. |
|
98 |
^ img |
|
99 |
||
100 |
" |
|
101 |
|s| |
|
102 |
||
103 |
s := ' |
|
104 |
Iqsa(US9p?)Y^W |
|
105 |
+6Ff[Z]<t?\A!!eaL''DG{20*#{C1;''Ct&}L}B^/1(aYI@hP)4!!<}7D=2gm |
|
106 |
8!!$T`8QNfK<te\20%A\`wm*wa2' , Character doubleQuote asString , '^Up*Qs' , Character doubleQuote asString , |
|
107 |
'X}KeV*3XeB2te&sKp*t`N;^BDh[6=K{ZBE=O>rM' , Character doubleQuote asString , 'uFE) |
|
108 |
lFDjag1e]\/#2'. |
|
109 |
BlitImageReader fromCompressedString:s |
|
110 |
" |
|
111 |
||
112 |
"Created: 9.11.1995 / 17:55:19 / cg" |
|
113 |
"Modified: 9.11.1995 / 17:56:07 / cg" |
|
114 |
! |
|
115 |
||
118
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
116 |
uncompressString:aString |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
117 |
"given a compressed string (as present in mail-headers), |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
118 |
return a string in 48x48x1 BlitImage fromat. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
119 |
Since I am not willing to port/include the uncompface stuff into ST/X, |
113 | 120 |
open a pipe to the uncompressor. |
121 |
If you dont have compface/uncompface, get it from your nearest ftp server." |
|
122 |
||
118
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
123 |
|f s str| |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
124 |
|
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
125 |
f := Filename newTemporary. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
126 |
s := f writeStream. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
127 |
s nextPutAll:aString. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
128 |
s close. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
129 |
|
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
130 |
s := PipeStream readingFrom:('uncompface ' , f name). |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
131 |
s isNil ifTrue:[ |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
132 |
'BLITIMGREADER: no uncompface utility.' errorPrintNL. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
133 |
f delete. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
134 |
^ nil |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
135 |
]. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
136 |
|
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
137 |
str := s contents asString. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
138 |
s close. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
139 |
f delete. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
140 |
^ str |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
141 |
|
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
142 |
" |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
143 |
|s| |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
144 |
|
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
145 |
s := ' |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
146 |
Iqsa(US9p?)Y^W |
141 | 147 |
+6Ff[Z]<t?\A!!eaL''DG{20*#{C1;''Ct&}L}B^/1(aYI@hP)4!!<}7D=2gm |
148 |
8!!$T`8QNfK<te\20%A\`wm*wa2' , Character doubleQuote asString , '^Up*Qs' , Character doubleQuote asString , |
|
118
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
149 |
'X}KeV*3XeB2te&sKp*t`N;^BDh[6=K{ZBE=O>rM' , Character doubleQuote asString , 'uFE) |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
150 |
lFDjag1e]\/#2'. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
151 |
BlitImageReader uncompressString:s |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
152 |
" |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
153 |
|
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
154 |
"Created: 9.11.1995 / 17:55:19 / cg" |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
155 |
"Modified: 21.11.1995 / 19:28:41 / cg" |
113 | 156 |
! ! |
157 |
||
112 | 158 |
!BlitImageReader class methodsFor:'testing'! |
159 |
||
160 |
isValidImageFile:aFileName |
|
206 | 161 |
"return true, if aFileName contains a BlitImage image" |
112 | 162 |
|
163 |
^ aFileName = '48x48x1' |
|
164 |
||
165 |
"Created: 9.11.1995 / 17:04:29 / cg" |
|
206 | 166 |
"Modified: 23.4.1996 / 12:48:01 / cg" |
112 | 167 |
! ! |
168 |
||
169 |
!BlitImageReader methodsFor:'reading'! |
|
170 |
||
171 |
fromStream:aStream |
|
206 | 172 |
"read an image in my format from aStream" |
173 |
||
112 | 174 |
|line |
175 |
dstIndex "{ Class: SmallInteger }" |
|
176 |
bytesPerRow |
|
177 |
s words nm| |
|
178 |
||
113 | 179 |
width := height := 48. |
180 |
bytesPerRow := width // 8. |
|
112 | 181 |
|
182 |
data := ByteArray new:(bytesPerRow * height). |
|
183 |
dstIndex := 1. |
|
184 |
||
185 |
[aStream atEnd] whileFalse:[ |
|
206 | 186 |
line := aStream nextLine. |
187 |
line notNil ifTrue:[ |
|
188 |
words := (line asCollectionOfSubstringsSeparatedBy:$,) asOrderedCollection. |
|
189 |
words last isEmpty ifTrue:[ |
|
190 |
words removeLast |
|
191 |
]. |
|
192 |
words do:[:w | |
|
193 |
|s bits| |
|
112 | 194 |
|
206 | 195 |
s := w readStream. |
196 |
s skip:2. |
|
197 |
bits := Integer readFrom:s radix:16 onError:0. |
|
198 |
data at:dstIndex put:(bits bitShift:-8). |
|
199 |
data at:dstIndex+1 put:(bits bitAnd:16rFF). |
|
200 |
dstIndex := dstIndex + 2 |
|
201 |
] |
|
202 |
] |
|
112 | 203 |
]. |
204 |
||
205 |
||
206 |
photometric := #whiteIs0. |
|
207 |
samplesPerPixel := 1. |
|
208 |
bitsPerSample := #(1) |
|
209 |
||
210 |
" |
|
211 |
BlitImageReader fromFile:'/tmp/faces/facedir/facedir/misc./acsnet/48x48x1' |
|
212 |
" |
|
213 |
||
214 |
"Created: 9.11.1995 / 17:03:04 / cg" |
|
206 | 215 |
"Modified: 23.4.1996 / 12:48:15 / cg" |
112 | 216 |
! ! |
217 |
||
206 | 218 |
!BlitImageReader class methodsFor:'documentation'! |
219 |
||
220 |
version |
|
210 | 221 |
^ '$Header: /cvs/stx/stx/libview2/BlitImageReader.st,v 1.9 1996-04-23 11:05:45 cg Exp $' |
206 | 222 |
! ! |
112 | 223 |
BlitImageReader initialize! |