author | Claus Gittinger <cg@exept.de> |
Fri, 28 Jun 2019 09:04:27 +0200 | |
changeset 4285 | 86c48debecd5 |
parent 3587 | f6156f8918ea |
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 |
" |
|
3587 | 12 |
"{ Package: 'stx:libview2' }" |
13 | 13 |
|
3587 | 14 |
"{ NameSpace: Smalltalk }" |
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
894
diff
changeset
|
15 |
|
13 | 16 |
ImageReader subclass:#ST80FormReader |
207 | 17 |
instanceVariableNames:'' |
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
894
diff
changeset
|
20 |
category:'Graphics-Images-Readers' |
13 | 21 |
! |
22 |
||
21 | 23 |
!ST80FormReader class methodsFor:'documentation'! |
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
32 | 28 |
All Rights Reserved |
13 | 29 |
|
21 | 30 |
This software is furnished under a license and may be used |
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
13 | 38 |
|
21 | 39 |
documentation |
40 |
" |
|
41 |
this class provides methods for loading and saving st80-bitmap-file images. |
|
207 | 42 |
|
32 | 43 |
I am not sure, if this format is still supported/used by newer ST-80 |
207 | 44 |
versions; it used to be in 2.x versions |
45 |
(from what can be deduced by some bitmaps found in the manchester goodies). |
|
46 |
||
32 | 47 |
No writing is supported by this class. |
207 | 48 |
|
49 |
[See also:] |
|
234 | 50 |
Image Form Icon |
207 | 51 |
BlitImageReader FaceReader JPEGReader GIFReader PBMReader PCXReader |
210 | 52 |
SunRasterReader TargaReader TIFFReader WindowsIconReader |
209 | 53 |
XBMReader XPMReader XWDReader |
21 | 54 |
" |
55 |
! ! |
|
13 | 56 |
|
400 | 57 |
!ST80FormReader class methodsFor:'initialization'! |
58 |
||
59 |
initialize |
|
60 |
"install myself in the Image classes fileFormat table |
|
61 |
for the `.form' extension." |
|
62 |
||
647 | 63 |
MIMETypes defineImageType:nil suffix:'form' reader:self. |
400 | 64 |
|
65 |
"Created: 1.2.1997 / 15:09:49 / cg" |
|
66 |
! ! |
|
67 |
||
43 | 68 |
!ST80FormReader class methodsFor:'testing'! |
69 |
||
207 | 70 |
canRepresent:anImage |
71 |
"return true, if anImage can be represented in my file format. |
|
72 |
Only B&Wimages are supported." |
|
73 |
||
74 |
|photometric| |
|
75 |
||
76 |
anImage depth ~~ 1 ifTrue:[^ false]. |
|
77 |
(((photometric := anImage photometric) ~~ #blackIs0) and:[photometric ~~ #whiteIs0]) ifTrue:[^ false.]. |
|
78 |
^ true |
|
79 |
! |
|
80 |
||
43 | 81 |
isValidImageFile:aFileName |
82 |
"return true, if aFileName contains an st80-bitmap-file image" |
|
83 |
||
554
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
84 |
|code inStream ok w h| |
43 | 85 |
|
86 |
inStream := self streamReadingFile:aFileName. |
|
87 |
inStream isNil ifTrue:[^ false]. |
|
88 |
||
89 |
inStream binary. |
|
3587 | 90 |
code := inStream nextUnsignedInt16MSB:true. |
43 | 91 |
ok := (code == 1). |
554
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
92 |
|
3587 | 93 |
w := inStream nextUnsignedInt16MSB:true. |
94 |
h := inStream nextUnsignedInt16MSB:true. |
|
554
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
95 |
((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
|
96 |
ok := false |
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
97 |
]. |
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
98 |
|
43 | 99 |
inStream close. |
100 |
^ ok |
|
554
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
101 |
|
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
102 |
"Modified: 21.4.1997 / 19:48:56 / cg" |
207 | 103 |
! ! |
104 |
||
1805 | 105 |
!ST80FormReader methodsFor:'reading'! |
51 | 106 |
|
207 | 107 |
fromStream:aStream |
108 |
"read an image in my format from aStream" |
|
109 |
||
110 |
|nBytes code offsetX offsetY| |
|
111 |
||
112 |
inStream := aStream. |
|
113 |
inStream binary. |
|
51 | 114 |
|
894
35cbe1ab4484
use #nextUnsignedShortMSB: instead of #nextWord
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
115 |
code := inStream nextUnsignedShortMSB:true. |
207 | 116 |
code isNil ifTrue:[ |
117 |
^ nil |
|
118 |
]. |
|
554
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
119 |
code ~~ 1 ifTrue:[ |
812
01d6b05a1276
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
120 |
^ 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
|
121 |
]. |
207 | 122 |
|
894
35cbe1ab4484
use #nextUnsignedShortMSB: instead of #nextWord
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
123 |
width := aStream nextUnsignedShortMSB:true. |
35cbe1ab4484
use #nextUnsignedShortMSB: instead of #nextWord
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
124 |
height := aStream nextUnsignedShortMSB:true. |
554
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
125 |
((width == 0) or:[height == 0]) ifTrue:[ |
812
01d6b05a1276
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
126 |
^ 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
|
127 |
]. |
894
35cbe1ab4484
use #nextUnsignedShortMSB: instead of #nextWord
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
128 |
offsetX := aStream nextUnsignedShortMSB:true. |
35cbe1ab4484
use #nextUnsignedShortMSB: instead of #nextWord
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
129 |
offsetY := aStream nextUnsignedShortMSB:true. |
1846 | 130 |
self reportDimension. |
51 | 131 |
|
207 | 132 |
nBytes := width + 15 // 16 * 2 * height. |
133 |
data := ByteArray new:nBytes. |
|
134 |
aStream nextBytes:nBytes into:data. |
|
135 |
||
136 |
photometric := #whiteIs0. |
|
137 |
samplesPerPixel := 1. |
|
138 |
bitsPerSample := #(1) |
|
139 |
||
554
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
140 |
"ST80FormReader fromFile:''" |
514e020465c7
look at useful width & height, before interpreting image data
Claus Gittinger <cg@exept.de>
parents:
461
diff
changeset
|
141 |
|
894
35cbe1ab4484
use #nextUnsignedShortMSB: instead of #nextWord
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
142 |
"Modified: / 4.4.1998 / 18:24:40 / cg" |
43 | 143 |
! ! |
144 |
||
1805 | 145 |
!ST80FormReader methodsFor:'writing'! |
13 | 146 |
|
1813
aa74c7bd22ad
image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents:
1805
diff
changeset
|
147 |
save:image onStream:aStream |
aa74c7bd22ad
image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents:
1805
diff
changeset
|
148 |
"save image as XBM file on aStream." |
13 | 149 |
|
51 | 150 |
(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
|
151 |
^ Image cannotRepresentImageSignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
152 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
153 |
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
|
154 |
]. |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
155 |
|
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
156 |
image mask notNil ifTrue:[ |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
157 |
Image informationLostQuerySignal |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
158 |
raiseWith:image |
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
159 |
errorString:('ST80Form format does not support an imageMask'). |
51 | 160 |
]. |
161 |
||
1813
aa74c7bd22ad
image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents:
1805
diff
changeset
|
162 |
outStream := aStream. |
13 | 163 |
|
164 |
width := image width. |
|
165 |
height := image height. |
|
166 |
photometric := image photometric. |
|
167 |
samplesPerPixel := image samplesPerPixel. |
|
168 |
bitsPerSample := image bitsPerSample. |
|
169 |
colorMap := image colorMap. |
|
170 |
||
171 |
outStream binary. |
|
172 |
outStream nextPutWord:1. |
|
173 |
outStream nextPutWord:width. |
|
174 |
outStream nextPutWord:height. |
|
175 |
outStream nextPutWord:0. |
|
176 |
outStream nextPutWord:0. |
|
177 |
outStream nextPutBytes:(data size) from:data. |
|
178 |
||
1813
aa74c7bd22ad
image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents:
1805
diff
changeset
|
179 |
" |
aa74c7bd22ad
image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents:
1805
diff
changeset
|
180 |
ST80FormReader save:(Image fromFile:'bitmaps/SBrowser.xbm') onFile:'test.form' |
aa74c7bd22ad
image saving - use save:onStream:
Claus Gittinger <cg@exept.de>
parents:
1805
diff
changeset
|
181 |
" |
461
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
182 |
|
bacef118f54a
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
183 |
"Modified: 27.2.1997 / 12:46:00 / cg" |
13 | 184 |
! ! |
185 |
||
207 | 186 |
!ST80FormReader class methodsFor:'documentation'! |
13 | 187 |
|
207 | 188 |
version |
3587 | 189 |
^ '$Header$' |
13 | 190 |
! ! |
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
894
diff
changeset
|
191 |
|
3587 | 192 |
|
400 | 193 |
ST80FormReader initialize! |