author | Claus Gittinger <cg@exept.de> |
Tue, 23 Apr 1996 12:26:04 +0200 | |
changeset 197 | 50812e81d86f |
parent 114 | e577a2f332d0 |
child 207 | ae381eaf10d4 |
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 |
||
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 |
114
e577a2f332d0
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
39 |
^ '$Header: /cvs/stx/stx/libview2/Attic/STFormRdr.st,v 1.10 1995-11-11 16:04:58 cg Exp $' |
21 | 40 |
! |
41 |
||
42 |
documentation |
|
43 |
" |
|
44 |
this class provides methods for loading and saving st80-bitmap-file images. |
|
32 | 45 |
I am not sure, if this format is still supported/used by newer ST-80 |
46 |
versions; it used to be in 2.x versions (from what can be deduced by some |
|
47 |
bitmaps found in the manchester goodies). |
|
48 |
No writing is supported by this class. |
|
21 | 49 |
" |
50 |
! ! |
|
13 | 51 |
|
43 | 52 |
!ST80FormReader class methodsFor:'testing'! |
53 |
||
54 |
isValidImageFile:aFileName |
|
55 |
"return true, if aFileName contains an st80-bitmap-file image" |
|
56 |
||
57 |
|code inStream ok| |
|
58 |
||
59 |
inStream := self streamReadingFile:aFileName. |
|
60 |
inStream isNil ifTrue:[^ false]. |
|
61 |
||
62 |
inStream binary. |
|
63 |
code := inStream nextWord. |
|
64 |
ok := (code == 1). |
|
65 |
inStream close. |
|
66 |
^ ok |
|
51 | 67 |
! |
68 |
||
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 |
|
43 | 78 |
! ! |
79 |
||
13 | 80 |
!ST80FormReader methodsFor:'writing to file'! |
81 |
||
82 |
save:image onFile:aFileName |
|
83 |
"save image as XBM file on aFileName" |
|
84 |
||
51 | 85 |
(self class canRepresent:image) ifFalse:[ |
86 |
self error:'can only save Depth1Images'. |
|
87 |
^ nil. |
|
88 |
]. |
|
89 |
||
13 | 90 |
outStream := FileStream newFileNamed:aFileName. |
91 |
outStream isNil ifTrue:[ |
|
32 | 92 |
'create error' printNewline. |
93 |
^ nil |
|
13 | 94 |
]. |
95 |
||
96 |
width := image width. |
|
97 |
height := image height. |
|
98 |
photometric := image photometric. |
|
99 |
samplesPerPixel := image samplesPerPixel. |
|
100 |
bitsPerSample := image bitsPerSample. |
|
101 |
colorMap := image colorMap. |
|
102 |
||
103 |
outStream binary. |
|
104 |
outStream nextPutWord:1. |
|
105 |
outStream nextPutWord:width. |
|
106 |
outStream nextPutWord:height. |
|
107 |
outStream nextPutWord:0. |
|
108 |
outStream nextPutWord:0. |
|
109 |
outStream nextPutBytes:(data size) from:data. |
|
110 |
||
111 |
outStream close |
|
112 |
||
113 |
"ST80FormReader save:(Image fromFile:'bitmaps/SBrowser.xbm') onFile:'test.form'" |
|
114 |
! ! |
|
115 |
||
116 |
!ST80FormReader methodsFor:'reading from file'! |
|
117 |
||
43 | 118 |
fromStream:aStream |
16 | 119 |
|nBytes code offsetX offsetY| |
13 | 120 |
|
43 | 121 |
inStream := aStream. |
122 |
inStream binary. |
|
123 |
||
124 |
code := inStream nextWord. |
|
125 |
code isNil ifTrue:[ |
|
51 | 126 |
^ nil |
13 | 127 |
]. |
128 |
||
43 | 129 |
width := aStream nextWord. |
130 |
height := aStream nextWord. |
|
131 |
offsetX := aStream nextWord. |
|
132 |
offsetY := aStream nextWord. |
|
13 | 133 |
|
134 |
nBytes := width + 15 // 16 * 2 * height. |
|
135 |
data := ByteArray new:nBytes. |
|
43 | 136 |
aStream nextBytes:nBytes into:data. |
13 | 137 |
|
138 |
photometric := #whiteIs0. |
|
139 |
samplesPerPixel := 1. |
|
140 |
bitsPerSample := #(1) |
|
141 |
||
142 |
"ST80FormReader fromFile:''" |
|
143 |
! ! |
|
43 | 144 |