author | Claus Gittinger <cg@exept.de> |
Thu, 06 Mar 1997 16:18:25 +0100 | |
changeset 497 | 6544ec670fe0 |
parent 461 | bacef118f54a |
child 554 | 514e020465c7 |
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 |
||
81 |
|code inStream ok| |
|
82 |
||
83 |
inStream := self streamReadingFile:aFileName. |
|
84 |
inStream isNil ifTrue:[^ false]. |
|
85 |
||
86 |
inStream binary. |
|
87 |
code := inStream nextWord. |
|
88 |
ok := (code == 1). |
|
89 |
inStream close. |
|
90 |
^ ok |
|
207 | 91 |
! ! |
92 |
||
93 |
!ST80FormReader methodsFor:'reading from file'! |
|
51 | 94 |
|
207 | 95 |
fromStream:aStream |
96 |
"read an image in my format from aStream" |
|
97 |
||
98 |
|nBytes code offsetX offsetY| |
|
99 |
||
100 |
inStream := aStream. |
|
101 |
inStream binary. |
|
51 | 102 |
|
207 | 103 |
code := inStream nextWord. |
104 |
code isNil ifTrue:[ |
|
105 |
^ nil |
|
106 |
]. |
|
107 |
||
108 |
width := aStream nextWord. |
|
109 |
height := aStream nextWord. |
|
110 |
offsetX := aStream nextWord. |
|
111 |
offsetY := aStream nextWord. |
|
51 | 112 |
|
207 | 113 |
nBytes := width + 15 // 16 * 2 * height. |
114 |
data := ByteArray new:nBytes. |
|
115 |
aStream nextBytes:nBytes into:data. |
|
116 |
||
117 |
photometric := #whiteIs0. |
|
118 |
samplesPerPixel := 1. |
|
119 |
bitsPerSample := #(1) |
|
120 |
||
121 |
"ST80FormReader fromFile:''" |
|
43 | 122 |
! ! |
123 |
||
13 | 124 |
!ST80FormReader methodsFor:'writing to file'! |
125 |
||
126 |
save:image onFile:aFileName |
|
207 | 127 |
"save image as XBM file on aFileName. |
128 |
This is obsolete - use the XBMReader directly." |
|
13 | 129 |
|
51 | 130 |
(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
|
131 |
^ Image cannotRepresentImageSignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
132 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
133 |
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
|
134 |
]. |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
135 |
|
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
136 |
image mask notNil ifTrue:[ |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
137 |
Image informationLostQuerySignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
138 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
139 |
errorString:('ST80Form format does not support an imageMask'). |
51 | 140 |
]. |
141 |
||
13 | 142 |
outStream := FileStream newFileNamed:aFileName. |
143 |
outStream isNil ifTrue:[ |
|
461
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
144 |
^ Image fileCreationErrorSignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
145 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
146 |
errorString:('file creation error: ' , aFileName asString). |
13 | 147 |
]. |
148 |
||
149 |
width := image width. |
|
150 |
height := image height. |
|
151 |
photometric := image photometric. |
|
152 |
samplesPerPixel := image samplesPerPixel. |
|
153 |
bitsPerSample := image bitsPerSample. |
|
154 |
colorMap := image colorMap. |
|
155 |
||
156 |
outStream binary. |
|
157 |
outStream nextPutWord:1. |
|
158 |
outStream nextPutWord:width. |
|
159 |
outStream nextPutWord:height. |
|
160 |
outStream nextPutWord:0. |
|
161 |
outStream nextPutWord:0. |
|
162 |
outStream nextPutBytes:(data size) from:data. |
|
163 |
||
164 |
outStream close |
|
165 |
||
166 |
"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
|
167 |
|
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
168 |
"Modified: 27.2.1997 / 12:46:00 / cg" |
13 | 169 |
! ! |
170 |
||
207 | 171 |
!ST80FormReader class methodsFor:'documentation'! |
13 | 172 |
|
207 | 173 |
version |
461
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
174 |
^ '$Header: /cvs/stx/stx/libview2/Attic/STFormRdr.st,v 1.17 1997-02-27 11:50:58 cg Exp $' |
13 | 175 |
! ! |
400 | 176 |
ST80FormReader initialize! |