13
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
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
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Graphics-Support'
|
|
18 |
!
|
|
19 |
|
|
20 |
ST80FormReader comment:'
|
21
|
21 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
22 |
All Rights Reserved
|
|
23 |
'!
|
13
|
24 |
|
21
|
25 |
!ST80FormReader class methodsFor:'documentation'!
|
|
26 |
|
|
27 |
copyright
|
|
28 |
"
|
|
29 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
13
|
30 |
All Rights Reserved
|
|
31 |
|
21
|
32 |
This software is furnished under a license and may be used
|
|
33 |
only in accordance with the terms of that license and with the
|
|
34 |
inclusion of the above copyright notice. This software may not
|
|
35 |
be provided or otherwise made available to, or used by, any
|
|
36 |
other person. No title to or ownership of the software is
|
|
37 |
hereby transferred.
|
|
38 |
"
|
|
39 |
!
|
13
|
40 |
|
21
|
41 |
version
|
|
42 |
"
|
|
43 |
$Header: /cvs/stx/stx/libview2/Attic/STFormRdr.st,v 1.3 1994-06-03 00:53:35 claus Exp $
|
|
44 |
"
|
|
45 |
!
|
|
46 |
|
|
47 |
documentation
|
|
48 |
"
|
|
49 |
this class provides methods for loading and saving st80-bitmap-file images.
|
|
50 |
"
|
|
51 |
! !
|
13
|
52 |
|
|
53 |
!ST80FormReader methodsFor:'writing to file'!
|
|
54 |
|
|
55 |
save:image onFile:aFileName
|
|
56 |
"save image as XBM file on aFileName"
|
|
57 |
|
|
58 |
outStream := FileStream newFileNamed:aFileName.
|
|
59 |
outStream isNil ifTrue:[
|
|
60 |
'create error' printNewline.
|
|
61 |
^ nil
|
|
62 |
].
|
|
63 |
|
|
64 |
width := image width.
|
|
65 |
height := image height.
|
|
66 |
photometric := image photometric.
|
|
67 |
samplesPerPixel := image samplesPerPixel.
|
|
68 |
bitsPerSample := image bitsPerSample.
|
|
69 |
colorMap := image colorMap.
|
|
70 |
|
|
71 |
((samplesPerPixel ~~ 1)
|
|
72 |
or:[((bitsPerSample at:1) ~~ 1)
|
|
73 |
or:[(photometric ~~ #blackIs0) and:[photometric ~~ #whiteIs0]]]) ifTrue:[
|
|
74 |
self error:'can only save Depth1Images'.
|
|
75 |
outStream close.
|
|
76 |
^ nil.
|
|
77 |
].
|
|
78 |
|
|
79 |
outStream binary.
|
|
80 |
outStream nextPutWord:1.
|
|
81 |
outStream nextPutWord:width.
|
|
82 |
outStream nextPutWord:height.
|
|
83 |
outStream nextPutWord:0.
|
|
84 |
outStream nextPutWord:0.
|
|
85 |
outStream nextPutBytes:(data size) from:data.
|
|
86 |
|
|
87 |
outStream close
|
|
88 |
|
|
89 |
"ST80FormReader save:(Image fromFile:'bitmaps/SBrowser.xbm') onFile:'test.form'"
|
|
90 |
! !
|
|
91 |
|
|
92 |
!ST80FormReader class methodsFor:'testing'!
|
|
93 |
|
|
94 |
isValidImageFile:aFileName
|
|
95 |
"return true, if aFileName contains an st80-bitmap-file image"
|
|
96 |
|
16
|
97 |
|code inStream|
|
13
|
98 |
|
21
|
99 |
inStream := self streamReadingFile:aFileName.
|
13
|
100 |
inStream isNil ifTrue:[^ false].
|
|
101 |
|
|
102 |
inStream binary.
|
|
103 |
code := inStream nextWord.
|
|
104 |
code == 1 ifFalse:[
|
|
105 |
inStream close.
|
|
106 |
^ false
|
|
107 |
].
|
|
108 |
inStream close.
|
|
109 |
^ true
|
|
110 |
! !
|
|
111 |
|
|
112 |
!ST80FormReader methodsFor:'reading from file'!
|
|
113 |
|
|
114 |
fromFile:aFileName
|
16
|
115 |
|nBytes code offsetX offsetY|
|
13
|
116 |
|
21
|
117 |
inStream := self class streamReadingFile:aFileName.
|
13
|
118 |
inStream isNil ifTrue:[
|
|
119 |
'open error' printNewline.
|
|
120 |
^ nil
|
|
121 |
].
|
|
122 |
|
|
123 |
inStream binary.
|
|
124 |
code := inStream nextWord.
|
|
125 |
code isNil ifTrue:[
|
|
126 |
inStream close.
|
|
127 |
^ nil
|
|
128 |
].
|
|
129 |
|
|
130 |
width := inStream nextWord.
|
|
131 |
height := inStream nextWord.
|
|
132 |
offsetX := inStream nextWord.
|
|
133 |
offsetY := inStream nextWord.
|
|
134 |
|
|
135 |
nBytes := width + 15 // 16 * 2 * height.
|
|
136 |
data := ByteArray new:nBytes.
|
16
|
137 |
inStream nextBytes:nBytes into:data.
|
13
|
138 |
inStream close.
|
|
139 |
|
|
140 |
photometric := #whiteIs0.
|
|
141 |
samplesPerPixel := 1.
|
|
142 |
bitsPerSample := #(1)
|
|
143 |
|
|
144 |
"ST80FormReader fromFile:''"
|
|
145 |
! !
|