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