author | Claus Gittinger <cg@exept.de> |
Thu, 24 Oct 2002 21:16:06 +0200 | |
changeset 1646 | da8d044c7c0d |
parent 894 | 35cbe1ab4484 |
child 1745 | 4fa0fad2a463 |
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 |
||
647 | 60 |
MIMETypes defineImageType:nil suffix:'form' reader:self. |
400 | 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 |
|
894
35cbe1ab4484
use #nextUnsignedShortMSB: instead of #nextWord
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
112 |
code := inStream nextUnsignedShortMSB:true. |
207 | 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:[ |
812
01d6b05a1276
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
117 |
^ self fileFormatError:'expected magic 1'. |
554
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
118 |
]. |
207 | 119 |
|
894
35cbe1ab4484
use #nextUnsignedShortMSB: instead of #nextWord
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
120 |
width := aStream nextUnsignedShortMSB:true. |
35cbe1ab4484
use #nextUnsignedShortMSB: instead of #nextWord
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
121 |
height := aStream nextUnsignedShortMSB:true. |
554
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
122 |
((width == 0) or:[height == 0]) ifTrue:[ |
812
01d6b05a1276
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
123 |
^ self fileFormatError:'zero width/height'. |
554
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
124 |
]. |
894
35cbe1ab4484
use #nextUnsignedShortMSB: instead of #nextWord
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
125 |
offsetX := aStream nextUnsignedShortMSB:true. |
35cbe1ab4484
use #nextUnsignedShortMSB: instead of #nextWord
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
126 |
offsetY := aStream nextUnsignedShortMSB:true. |
51 | 127 |
|
207 | 128 |
nBytes := width + 15 // 16 * 2 * height. |
129 |
data := ByteArray new:nBytes. |
|
130 |
aStream nextBytes:nBytes into:data. |
|
131 |
||
132 |
photometric := #whiteIs0. |
|
133 |
samplesPerPixel := 1. |
|
134 |
bitsPerSample := #(1) |
|
135 |
||
554
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
136 |
"ST80FormReader fromFile:''" |
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
137 |
|
894
35cbe1ab4484
use #nextUnsignedShortMSB: instead of #nextWord
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
138 |
"Modified: / 4.4.1998 / 18:24:40 / cg" |
43 | 139 |
! ! |
140 |
||
13 | 141 |
!ST80FormReader methodsFor:'writing to file'! |
142 |
||
143 |
save:image onFile:aFileName |
|
207 | 144 |
"save image as XBM file on aFileName. |
145 |
This is obsolete - use the XBMReader directly." |
|
13 | 146 |
|
51 | 147 |
(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
|
148 |
^ Image cannotRepresentImageSignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
149 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
150 |
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
|
151 |
]. |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
152 |
|
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
153 |
image mask notNil ifTrue:[ |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
154 |
Image informationLostQuerySignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
155 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
156 |
errorString:('ST80Form format does not support an imageMask'). |
51 | 157 |
]. |
158 |
||
13 | 159 |
outStream := FileStream newFileNamed:aFileName. |
160 |
outStream isNil ifTrue:[ |
|
461
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
161 |
^ Image fileCreationErrorSignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
162 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
163 |
errorString:('file creation error: ' , aFileName asString). |
13 | 164 |
]. |
165 |
||
166 |
width := image width. |
|
167 |
height := image height. |
|
168 |
photometric := image photometric. |
|
169 |
samplesPerPixel := image samplesPerPixel. |
|
170 |
bitsPerSample := image bitsPerSample. |
|
171 |
colorMap := image colorMap. |
|
172 |
||
173 |
outStream binary. |
|
174 |
outStream nextPutWord:1. |
|
175 |
outStream nextPutWord:width. |
|
176 |
outStream nextPutWord:height. |
|
177 |
outStream nextPutWord:0. |
|
178 |
outStream nextPutWord:0. |
|
179 |
outStream nextPutBytes:(data size) from:data. |
|
180 |
||
181 |
outStream close |
|
182 |
||
183 |
"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
|
184 |
|
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
185 |
"Modified: 27.2.1997 / 12:46:00 / cg" |
13 | 186 |
! ! |
187 |
||
207 | 188 |
!ST80FormReader class methodsFor:'documentation'! |
13 | 189 |
|
207 | 190 |
version |
894
35cbe1ab4484
use #nextUnsignedShortMSB: instead of #nextWord
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
191 |
^ '$Header: /cvs/stx/stx/libview2/ST80FormReader.st,v 1.21 1998-04-06 08:34:39 cg Exp $' |
13 | 192 |
! ! |
400 | 193 |
ST80FormReader initialize! |