author | ca |
Fri, 08 Nov 2002 13:47:10 +0100 | |
changeset 1664 | 1c59afa95984 |
parent 647 | 6f26c76aa0c9 |
child 1740 | b692ce36d2e3 |
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:'' |
|
259 | 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:] |
|
234 | 45 |
Image Form Icon |
206 | 46 |
GIFReader FaceReader JPEGReader PBMReader PCXReader |
210 | 47 |
ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader |
209 | 48 |
XBMReader XPMReader XWDReader |
206 | 49 |
" |
50 |
! |
|
51 |
||
52 |
examples |
|
53 |
" |
|
54 |
Image fromFile:'.../.../48x48x1' |
|
55 |
" |
|
112 | 56 |
! ! |
57 |
||
58 |
!BlitImageReader class methodsFor:'initialization'! |
|
59 |
||
60 |
initialize |
|
206 | 61 |
"install myself in the Image classes fileFormat table |
62 |
for files named `48x48x1' (funny)." |
|
63 |
||
647 | 64 |
MIMETypes defineImageType:nil suffix:'48x48x1' reader:self |
112 | 65 |
|
66 |
" |
|
67 |
BlitImageReader initialize |
|
68 |
" |
|
69 |
||
398 | 70 |
"Modified: 1.2.1997 / 15:01:08 / cg" |
112 | 71 |
! ! |
72 |
||
113 | 73 |
!BlitImageReader class methodsFor:'special formats'! |
74 |
||
206 | 75 |
fromCompressedString:aString |
76 |
"given a compressed image string (such as present in mail headers), |
|
77 |
return a Depth1Image for it. |
|
78 |
Since I am not willing to port/include the uncompface stuff into ST/X, |
|
79 |
open a pipe to the uncompressor. |
|
80 |
If you dont have compface/uncompface, get it from your nearest ftp server." |
|
81 |
||
82 |
|f s img| |
|
83 |
||
84 |
f := Filename newTemporary. |
|
85 |
s := f writeStream. |
|
86 |
s nextPutAll:aString. |
|
87 |
s close. |
|
88 |
||
89 |
s := PipeStream readingFrom:('uncompface ' , f name). |
|
90 |
s isNil ifTrue:[ |
|
91 |
'BLITIMGREADER: no uncompface utility.' errorPrintNL. |
|
92 |
f delete. |
|
93 |
^ nil |
|
94 |
]. |
|
95 |
||
96 |
img := self fromStream:s. |
|
97 |
s close. |
|
98 |
f delete. |
|
99 |
^ img |
|
100 |
||
101 |
" |
|
102 |
|s| |
|
103 |
||
104 |
s := ' |
|
105 |
Iqsa(US9p?)Y^W |
|
106 |
+6Ff[Z]<t?\A!!eaL''DG{20*#{C1;''Ct&}L}B^/1(aYI@hP)4!!<}7D=2gm |
|
107 |
8!!$T`8QNfK<te\20%A\`wm*wa2' , Character doubleQuote asString , '^Up*Qs' , Character doubleQuote asString , |
|
108 |
'X}KeV*3XeB2te&sKp*t`N;^BDh[6=K{ZBE=O>rM' , Character doubleQuote asString , 'uFE) |
|
109 |
lFDjag1e]\/#2'. |
|
110 |
BlitImageReader fromCompressedString:s |
|
111 |
" |
|
112 |
||
113 |
"Created: 9.11.1995 / 17:55:19 / cg" |
|
114 |
"Modified: 9.11.1995 / 17:56:07 / cg" |
|
115 |
! |
|
116 |
||
118
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
117 |
uncompressString:aString |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
118 |
"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
|
119 |
return a string in 48x48x1 BlitImage fromat. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
120 |
Since I am not willing to port/include the uncompface stuff into ST/X, |
113 | 121 |
open a pipe to the uncompressor. |
122 |
If you dont have compface/uncompface, get it from your nearest ftp server." |
|
123 |
||
118
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
124 |
|f s str| |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
125 |
|
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
126 |
f := Filename newTemporary. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
127 |
s := f writeStream. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
128 |
s nextPutAll:aString. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
129 |
s close. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
130 |
|
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
131 |
s := PipeStream readingFrom:('uncompface ' , f name). |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
132 |
s isNil ifTrue:[ |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
133 |
'BLITIMGREADER: no uncompface utility.' errorPrintNL. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
134 |
f delete. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
135 |
^ nil |
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 |
|
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
138 |
str := s contents asString. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
139 |
s close. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
140 |
f delete. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
141 |
^ str |
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 |
" |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
144 |
|s| |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
145 |
|
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
146 |
s := ' |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
147 |
Iqsa(US9p?)Y^W |
141 | 148 |
+6Ff[Z]<t?\A!!eaL''DG{20*#{C1;''Ct&}L}B^/1(aYI@hP)4!!<}7D=2gm |
149 |
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
|
150 |
'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
|
151 |
lFDjag1e]\/#2'. |
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
152 |
BlitImageReader uncompressString:s |
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 |
|
7f0415d8308d
new method to uncompress blit-formatted strings
Claus Gittinger <cg@exept.de>
parents:
114
diff
changeset
|
155 |
"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
|
156 |
"Modified: 21.11.1995 / 19:28:41 / cg" |
113 | 157 |
! ! |
158 |
||
112 | 159 |
!BlitImageReader class methodsFor:'testing'! |
160 |
||
161 |
isValidImageFile:aFileName |
|
206 | 162 |
"return true, if aFileName contains a BlitImage image" |
112 | 163 |
|
164 |
^ aFileName = '48x48x1' |
|
165 |
||
166 |
"Created: 9.11.1995 / 17:04:29 / cg" |
|
206 | 167 |
"Modified: 23.4.1996 / 12:48:01 / cg" |
112 | 168 |
! ! |
169 |
||
170 |
!BlitImageReader methodsFor:'reading'! |
|
171 |
||
172 |
fromStream:aStream |
|
206 | 173 |
"read an image in my format from aStream" |
174 |
||
112 | 175 |
|line |
176 |
dstIndex "{ Class: SmallInteger }" |
|
177 |
bytesPerRow |
|
178 |
s words nm| |
|
179 |
||
113 | 180 |
width := height := 48. |
181 |
bytesPerRow := width // 8. |
|
112 | 182 |
|
183 |
data := ByteArray new:(bytesPerRow * height). |
|
184 |
dstIndex := 1. |
|
185 |
||
186 |
[aStream atEnd] whileFalse:[ |
|
206 | 187 |
line := aStream nextLine. |
188 |
line notNil ifTrue:[ |
|
189 |
words := (line asCollectionOfSubstringsSeparatedBy:$,) asOrderedCollection. |
|
190 |
words last isEmpty ifTrue:[ |
|
191 |
words removeLast |
|
192 |
]. |
|
193 |
words do:[:w | |
|
194 |
|s bits| |
|
112 | 195 |
|
206 | 196 |
s := w readStream. |
197 |
s skip:2. |
|
198 |
bits := Integer readFrom:s radix:16 onError:0. |
|
199 |
data at:dstIndex put:(bits bitShift:-8). |
|
200 |
data at:dstIndex+1 put:(bits bitAnd:16rFF). |
|
201 |
dstIndex := dstIndex + 2 |
|
202 |
] |
|
203 |
] |
|
112 | 204 |
]. |
205 |
||
206 |
||
207 |
photometric := #whiteIs0. |
|
208 |
samplesPerPixel := 1. |
|
209 |
bitsPerSample := #(1) |
|
210 |
||
211 |
" |
|
212 |
BlitImageReader fromFile:'/tmp/faces/facedir/facedir/misc./acsnet/48x48x1' |
|
213 |
" |
|
214 |
||
215 |
"Created: 9.11.1995 / 17:03:04 / cg" |
|
206 | 216 |
"Modified: 23.4.1996 / 12:48:15 / cg" |
112 | 217 |
! ! |
218 |
||
206 | 219 |
!BlitImageReader class methodsFor:'documentation'! |
220 |
||
221 |
version |
|
647 | 222 |
^ '$Header: /cvs/stx/stx/libview2/BlitImageReader.st,v 1.13 1997-06-30 20:55:45 cg Exp $' |
206 | 223 |
! ! |
112 | 224 |
BlitImageReader initialize! |