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 |
|
43
|
13 |
'From Smalltalk/X, Version:2.10.4 on 18-feb-1995 at 2:18:48 am'!
|
|
14 |
|
13
|
15 |
ImageReader subclass:#ST80FormReader
|
32
|
16 |
instanceVariableNames:''
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Graphics-Images support'
|
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 |
version
|
|
39 |
"
|
99
|
40 |
$Header: /cvs/stx/stx/libview2/ST80FormReader.st,v 1.9 1995-08-30 17:54:15 claus Exp $
|
21
|
41 |
"
|
|
42 |
!
|
|
43 |
|
|
44 |
documentation
|
|
45 |
"
|
|
46 |
this class provides methods for loading and saving st80-bitmap-file images.
|
32
|
47 |
I am not sure, if this format is still supported/used by newer ST-80
|
|
48 |
versions; it used to be in 2.x versions (from what can be deduced by some
|
|
49 |
bitmaps found in the manchester goodies).
|
|
50 |
No writing is supported by this class.
|
21
|
51 |
"
|
|
52 |
! !
|
13
|
53 |
|
43
|
54 |
!ST80FormReader class methodsFor:'testing'!
|
|
55 |
|
|
56 |
isValidImageFile:aFileName
|
|
57 |
"return true, if aFileName contains an st80-bitmap-file image"
|
|
58 |
|
|
59 |
|code inStream ok|
|
|
60 |
|
|
61 |
inStream := self streamReadingFile:aFileName.
|
|
62 |
inStream isNil ifTrue:[^ false].
|
|
63 |
|
|
64 |
inStream binary.
|
|
65 |
code := inStream nextWord.
|
|
66 |
ok := (code == 1).
|
|
67 |
inStream close.
|
|
68 |
^ ok
|
51
|
69 |
!
|
|
70 |
|
|
71 |
canRepresent:anImage
|
|
72 |
"return true, if anImage can be represented in my file format.
|
|
73 |
Only B&Wimages are supported."
|
|
74 |
|
|
75 |
|photometric|
|
|
76 |
|
|
77 |
anImage depth ~~ 1 ifTrue:[^ false].
|
|
78 |
(((photometric := anImage photometric) ~~ #blackIs0) and:[photometric ~~ #whiteIs0]) ifTrue:[^ false.].
|
|
79 |
^ true
|
43
|
80 |
! !
|
|
81 |
|
13
|
82 |
!ST80FormReader methodsFor:'writing to file'!
|
|
83 |
|
|
84 |
save:image onFile:aFileName
|
|
85 |
"save image as XBM file on aFileName"
|
|
86 |
|
51
|
87 |
(self class canRepresent:image) ifFalse:[
|
|
88 |
self error:'can only save Depth1Images'.
|
|
89 |
^ nil.
|
|
90 |
].
|
|
91 |
|
13
|
92 |
outStream := FileStream newFileNamed:aFileName.
|
|
93 |
outStream isNil ifTrue:[
|
32
|
94 |
'create error' printNewline.
|
|
95 |
^ nil
|
13
|
96 |
].
|
|
97 |
|
|
98 |
width := image width.
|
|
99 |
height := image height.
|
|
100 |
photometric := image photometric.
|
|
101 |
samplesPerPixel := image samplesPerPixel.
|
|
102 |
bitsPerSample := image bitsPerSample.
|
|
103 |
colorMap := image colorMap.
|
|
104 |
|
|
105 |
outStream binary.
|
|
106 |
outStream nextPutWord:1.
|
|
107 |
outStream nextPutWord:width.
|
|
108 |
outStream nextPutWord:height.
|
|
109 |
outStream nextPutWord:0.
|
|
110 |
outStream nextPutWord:0.
|
|
111 |
outStream nextPutBytes:(data size) from:data.
|
|
112 |
|
|
113 |
outStream close
|
|
114 |
|
|
115 |
"ST80FormReader save:(Image fromFile:'bitmaps/SBrowser.xbm') onFile:'test.form'"
|
|
116 |
! !
|
|
117 |
|
|
118 |
!ST80FormReader methodsFor:'reading from file'!
|
|
119 |
|
43
|
120 |
fromStream:aStream
|
16
|
121 |
|nBytes code offsetX offsetY|
|
13
|
122 |
|
43
|
123 |
inStream := aStream.
|
|
124 |
inStream binary.
|
|
125 |
|
|
126 |
code := inStream nextWord.
|
|
127 |
code isNil ifTrue:[
|
51
|
128 |
^ nil
|
13
|
129 |
].
|
|
130 |
|
43
|
131 |
width := aStream nextWord.
|
|
132 |
height := aStream nextWord.
|
|
133 |
offsetX := aStream nextWord.
|
|
134 |
offsetY := aStream nextWord.
|
13
|
135 |
|
|
136 |
nBytes := width + 15 // 16 * 2 * height.
|
|
137 |
data := ByteArray new:nBytes.
|
43
|
138 |
aStream nextBytes:nBytes into:data.
|
13
|
139 |
|
|
140 |
photometric := #whiteIs0.
|
|
141 |
samplesPerPixel := 1.
|
|
142 |
bitsPerSample := #(1)
|
|
143 |
|
|
144 |
"ST80FormReader fromFile:''"
|
|
145 |
! !
|
43
|
146 |
|