author | Claus Gittinger <cg@exept.de> |
Mon, 21 Apr 1997 19:50:12 +0200 | |
changeset 554 | 514e020465c7 |
parent 461 | bacef118f54a |
child 647 | 6f26c76aa0c9 |
permissions | -rw-r--r-- |
13 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
32 | 3 |
All Rights Reserved |
13 | 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 |
" |
|
12 |
||
13 |
ImageReader subclass:#ST80FormReader |
|
207 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
259 | 17 |
category:'Graphics-Images-Support' |
13 | 18 |
! |
19 |
||
21 | 20 |
!ST80FormReader class methodsFor:'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
32 | 25 |
All Rights Reserved |
13 | 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 |
! |
|
13 | 35 |
|
21 | 36 |
documentation |
37 |
" |
|
38 |
this class provides methods for loading and saving st80-bitmap-file images. |
|
207 | 39 |
|
32 | 40 |
I am not sure, if this format is still supported/used by newer ST-80 |
207 | 41 |
versions; it used to be in 2.x versions |
42 |
(from what can be deduced by some bitmaps found in the manchester goodies). |
|
43 |
||
32 | 44 |
No writing is supported by this class. |
207 | 45 |
|
46 |
[See also:] |
|
234 | 47 |
Image Form Icon |
207 | 48 |
BlitImageReader FaceReader JPEGReader GIFReader PBMReader PCXReader |
210 | 49 |
SunRasterReader TargaReader TIFFReader WindowsIconReader |
209 | 50 |
XBMReader XPMReader XWDReader |
21 | 51 |
" |
52 |
! ! |
|
13 | 53 |
|
400 | 54 |
!ST80FormReader class methodsFor:'initialization'! |
55 |
||
56 |
initialize |
|
57 |
"install myself in the Image classes fileFormat table |
|
58 |
for the `.form' extension." |
|
59 |
||
60 |
Image addReader:self suffix:'form'. |
|
61 |
||
62 |
"Created: 1.2.1997 / 15:09:49 / cg" |
|
63 |
! ! |
|
64 |
||
43 | 65 |
!ST80FormReader class methodsFor:'testing'! |
66 |
||
207 | 67 |
canRepresent:anImage |
68 |
"return true, if anImage can be represented in my file format. |
|
69 |
Only B&Wimages are supported." |
|
70 |
||
71 |
|photometric| |
|
72 |
||
73 |
anImage depth ~~ 1 ifTrue:[^ false]. |
|
74 |
(((photometric := anImage photometric) ~~ #blackIs0) and:[photometric ~~ #whiteIs0]) ifTrue:[^ false.]. |
|
75 |
^ true |
|
76 |
! |
|
77 |
||
43 | 78 |
isValidImageFile:aFileName |
79 |
"return true, if aFileName contains an st80-bitmap-file image" |
|
80 |
||
554
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
81 |
|code inStream ok w h| |
43 | 82 |
|
83 |
inStream := self streamReadingFile:aFileName. |
|
84 |
inStream isNil ifTrue:[^ false]. |
|
85 |
||
86 |
inStream binary. |
|
87 |
code := inStream nextWord. |
|
88 |
ok := (code == 1). |
|
554
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
89 |
|
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
90 |
w := inStream nextWord. |
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
91 |
h := inStream nextWord. |
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
92 |
((w == 0) or:[h == 0]) ifTrue:[ |
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
93 |
ok := false |
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
94 |
]. |
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
95 |
|
43 | 96 |
inStream close. |
97 |
^ ok |
|
554
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
98 |
|
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
99 |
"Modified: 21.4.1997 / 19:48:56 / cg" |
207 | 100 |
! ! |
101 |
||
102 |
!ST80FormReader methodsFor:'reading from file'! |
|
51 | 103 |
|
207 | 104 |
fromStream:aStream |
105 |
"read an image in my format from aStream" |
|
106 |
||
107 |
|nBytes code offsetX offsetY| |
|
108 |
||
109 |
inStream := aStream. |
|
110 |
inStream binary. |
|
51 | 111 |
|
207 | 112 |
code := inStream nextWord. |
113 |
code isNil ifTrue:[ |
|
114 |
^ nil |
|
115 |
]. |
|
554
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
116 |
code ~~ 1 ifTrue:[ |
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
117 |
'ST80FormReader [warning]: expected magic 1' errorPrintCR. |
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
118 |
^ nil |
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
119 |
]. |
207 | 120 |
|
121 |
width := aStream nextWord. |
|
122 |
height := aStream nextWord. |
|
554
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
123 |
((width == 0) or:[height == 0]) ifTrue:[ |
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
124 |
'ST80FormReader [warning]: zero width/height' errorPrintCR. |
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
125 |
^ nil |
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
126 |
]. |
207 | 127 |
offsetX := aStream nextWord. |
128 |
offsetY := aStream nextWord. |
|
51 | 129 |
|
207 | 130 |
nBytes := width + 15 // 16 * 2 * height. |
131 |
data := ByteArray new:nBytes. |
|
132 |
aStream nextBytes:nBytes into:data. |
|
133 |
||
134 |
photometric := #whiteIs0. |
|
135 |
samplesPerPixel := 1. |
|
136 |
bitsPerSample := #(1) |
|
137 |
||
554
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
138 |
"ST80FormReader fromFile:''" |
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
139 |
|
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
140 |
"Modified: 21.4.1997 / 19:47:43 / cg" |
43 | 141 |
! ! |
142 |
||
13 | 143 |
!ST80FormReader methodsFor:'writing to file'! |
144 |
||
145 |
save:image onFile:aFileName |
|
207 | 146 |
"save image as XBM file on aFileName. |
147 |
This is obsolete - use the XBMReader directly." |
|
13 | 148 |
|
51 | 149 |
(self class canRepresent:image) ifFalse:[ |
461
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
150 |
^ Image cannotRepresentImageSignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
151 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
152 |
errorString:('ST80Form format only supports monochrome images'). |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
153 |
]. |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
154 |
|
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
155 |
image mask notNil ifTrue:[ |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
156 |
Image informationLostQuerySignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
157 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
158 |
errorString:('ST80Form format does not support an imageMask'). |
51 | 159 |
]. |
160 |
||
13 | 161 |
outStream := FileStream newFileNamed:aFileName. |
162 |
outStream isNil ifTrue:[ |
|
461
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
163 |
^ Image fileCreationErrorSignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
164 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
165 |
errorString:('file creation error: ' , aFileName asString). |
13 | 166 |
]. |
167 |
||
168 |
width := image width. |
|
169 |
height := image height. |
|
170 |
photometric := image photometric. |
|
171 |
samplesPerPixel := image samplesPerPixel. |
|
172 |
bitsPerSample := image bitsPerSample. |
|
173 |
colorMap := image colorMap. |
|
174 |
||
175 |
outStream binary. |
|
176 |
outStream nextPutWord:1. |
|
177 |
outStream nextPutWord:width. |
|
178 |
outStream nextPutWord:height. |
|
179 |
outStream nextPutWord:0. |
|
180 |
outStream nextPutWord:0. |
|
181 |
outStream nextPutBytes:(data size) from:data. |
|
182 |
||
183 |
outStream close |
|
184 |
||
185 |
"ST80FormReader save:(Image fromFile:'bitmaps/SBrowser.xbm') onFile:'test.form'" |
|
461
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
186 |
|
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
187 |
"Modified: 27.2.1997 / 12:46:00 / cg" |
13 | 188 |
! ! |
189 |
||
207 | 190 |
!ST80FormReader class methodsFor:'documentation'! |
13 | 191 |
|
207 | 192 |
version |
554
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
193 |
^ '$Header: /cvs/stx/stx/libview2/ST80FormReader.st,v 1.18 1997-04-21 17:50:12 cg Exp $' |
13 | 194 |
! ! |
400 | 195 |
ST80FormReader initialize! |