527
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1997 by eXept Software AG / 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:#IrisRGBReader
|
|
14 |
instanceVariableNames:'bytesPerPixel'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Graphics-Images-Support'
|
|
18 |
!
|
|
19 |
|
|
20 |
!IrisRGBReader class methodsFor:'documentation'!
|
|
21 |
|
|
22 |
copyright
|
|
23 |
"
|
|
24 |
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger
|
|
25 |
All Rights Reserved
|
|
26 |
|
|
27 |
This software is furnished under a license and may be used
|
|
28 |
only in accordance with the terms of that license and with the
|
|
29 |
inclusion of the above copyright notice. This software may not
|
|
30 |
be provided or otherwise made available to, or used by, any
|
|
31 |
other person. No title to or ownership of the software is
|
|
32 |
hereby transferred.
|
|
33 |
"
|
|
34 |
!
|
|
35 |
|
|
36 |
documentation
|
|
37 |
"
|
|
38 |
this class provides methods for loading Iris RGB format images.
|
|
39 |
Only 3-byte/pixel format is supported.
|
|
40 |
Writing is not (yet) supported.
|
|
41 |
|
|
42 |
[author:]
|
|
43 |
Claus Gittinger
|
|
44 |
|
|
45 |
[See also:]
|
|
46 |
Image Form Icon
|
|
47 |
BlitImageReader FaceReader GIFReader JPEGReader PCXReader
|
|
48 |
ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader
|
|
49 |
XBMReader XPMReader XWDReader
|
|
50 |
"
|
|
51 |
! !
|
|
52 |
|
|
53 |
!IrisRGBReader class methodsFor:'initialization'!
|
|
54 |
|
|
55 |
initialize
|
|
56 |
"install myself in the Image classes fileFormat table
|
|
57 |
for the `.rgb' extension."
|
|
58 |
|
647
|
59 |
MIMETypes defineImageType:'image/x-rgb' suffix:'rgb' reader:self.
|
527
|
60 |
|
|
61 |
"Modified: 14.4.1997 / 15:49:19 / cg"
|
|
62 |
! !
|
|
63 |
|
|
64 |
!IrisRGBReader class methodsFor:'testing'!
|
|
65 |
|
|
66 |
isValidImageFile:aFileName
|
|
67 |
"return true, if aFileName contains an IRIS_RGB image"
|
|
68 |
|
|
69 |
|inStream magic type bpp dim w h bytesPerPixel|
|
|
70 |
|
|
71 |
inStream := self streamReadingFile:aFileName.
|
|
72 |
inStream isNil ifTrue:[^ false].
|
|
73 |
|
|
74 |
inStream binary.
|
|
75 |
|
|
76 |
magic := inStream nextShortMSB:true.
|
|
77 |
type := inStream nextShortMSB:true.
|
|
78 |
dim := inStream nextShortMSB:true.
|
|
79 |
w := inStream nextShortMSB:true.
|
|
80 |
h := inStream nextShortMSB:true.
|
|
81 |
bytesPerPixel := inStream nextShortMSB:true.
|
|
82 |
inStream close.
|
|
83 |
|
|
84 |
magic ~~ 8r0732 ifTrue:[^ false].
|
|
85 |
bpp := type bitAnd:16r00FF.
|
|
86 |
bpp ~~ 1 ifTrue:[^ false].
|
|
87 |
bytesPerPixel ~~ 3 ifTrue:[^ false].
|
|
88 |
|
|
89 |
^ true
|
|
90 |
|
|
91 |
"
|
|
92 |
IrisRGBReader isValidImageFile:'/home2/cg/capture.rgb'
|
|
93 |
"
|
|
94 |
|
|
95 |
"Modified: 14.4.1997 / 16:51:58 / cg"
|
|
96 |
! !
|
|
97 |
|
|
98 |
!IrisRGBReader methodsFor:'reading from file'!
|
|
99 |
|
|
100 |
fromStream:aStream
|
|
101 |
"read a Portable bitmap file format as of Jeff Poskanzers Portable Bitmap Package.
|
|
102 |
supported are IRIS_RGB, PGB and PNM files."
|
|
103 |
|
|
104 |
| magic type dim isRLE bpp|
|
|
105 |
|
|
106 |
inStream := aStream.
|
|
107 |
inStream binary.
|
|
108 |
|
|
109 |
magic := inStream nextShortMSB:true.
|
|
110 |
magic ~~ 8r0732 ifTrue:[
|
|
111 |
'IrisRGBReader [warning]: bad magic' errorPrintCR.
|
|
112 |
^nil
|
|
113 |
].
|
|
114 |
|
|
115 |
type := inStream nextShortMSB:true.
|
|
116 |
dim := inStream nextShortMSB:true.
|
|
117 |
width := inStream nextShortMSB:true.
|
|
118 |
height := inStream nextShortMSB:true.
|
|
119 |
bytesPerPixel := inStream nextShortMSB:true.
|
|
120 |
|
|
121 |
isRLE := (type bitAnd:16rFF00) == 16r0100.
|
|
122 |
bpp := type bitAnd:16r00FF.
|
|
123 |
bpp ~~ 1 ifTrue:[
|
|
124 |
'IrisRGBReader [warning]: not 1byte/pixel chan' errorPrintCR.
|
|
125 |
^nil
|
|
126 |
].
|
|
127 |
bytesPerPixel ~~ 3 ifTrue:[
|
|
128 |
'IrisRGBReader [warning]: can only read 3-channel images' errorPrintCR.
|
|
129 |
^nil
|
|
130 |
].
|
|
131 |
|
|
132 |
isRLE ifTrue:[
|
|
133 |
self readRLEData
|
|
134 |
] ifFalse:[
|
|
135 |
self readVerbatimData
|
|
136 |
].
|
|
137 |
|
|
138 |
photometric := #rgb.
|
|
139 |
samplesPerPixel := 3.
|
|
140 |
bitsPerSample := #(8 8 8).
|
|
141 |
|
|
142 |
"
|
|
143 |
IrisRGBReader fromFile:'/home2/cg/capture.rgb'
|
|
144 |
"
|
|
145 |
|
|
146 |
"Created: 14.4.1997 / 15:38:51 / cg"
|
|
147 |
"Modified: 14.4.1997 / 17:06:05 / cg"
|
|
148 |
!
|
|
149 |
|
|
150 |
readRLEData
|
|
151 |
"read RLE compressed data"
|
|
152 |
|
|
153 |
|rleBufferLen tableLen startTable lengthTable rleData
|
|
154 |
cur badOrder y z pos tblIdx dstIdx|
|
|
155 |
|
|
156 |
rleBufferLen := width * 2 + 10.
|
|
157 |
tableLen := height * bytesPerPixel.
|
|
158 |
|
|
159 |
startTable := Array new:tableLen.
|
|
160 |
lengthTable := Array new:tableLen.
|
|
161 |
rleData := ByteArray uninitializedNew:rleBufferLen.
|
|
162 |
|
|
163 |
"/ read rowStart & length table
|
|
164 |
|
|
165 |
inStream position:512+1.
|
|
166 |
1 to:tableLen do:[:i |
|
|
167 |
startTable at:i put:(inStream nextLongMSB:true).
|
|
168 |
].
|
|
169 |
1 to:tableLen do:[:i |
|
|
170 |
lengthTable at:i put:(inStream nextLongMSB:true).
|
|
171 |
].
|
|
172 |
|
|
173 |
data := ByteArray uninitializedNew:(width*height*3).
|
|
174 |
|
|
175 |
dstIdx := width * (height-1) * 3 + 1.
|
|
176 |
|
|
177 |
0 to:(height-1) do:[:y |
|
|
178 |
0 to:(bytesPerPixel-1) do:[:z |
|
|
179 |
|start length|
|
|
180 |
|
|
181 |
tblIdx := y + (z*height) + 1.
|
|
182 |
|
|
183 |
start := startTable at:tblIdx.
|
|
184 |
length := lengthTable at:tblIdx.
|
|
185 |
|
|
186 |
inStream position:(start + 1).
|
|
187 |
(inStream nextBytes:length into:rleData startingAt:1) ~~ length ifTrue:[
|
|
188 |
self halt:'short read'
|
|
189 |
].
|
|
190 |
(rleData at:length) ~~ 0 ifTrue:[
|
|
191 |
self halt.
|
|
192 |
].
|
559
|
193 |
|
|
194 |
self class
|
|
195 |
decompressRLEFrom:rleData at:1
|
|
196 |
into:data at:dstIdx+z increment:3.
|
|
197 |
|
|
198 |
"/ self expandRow:rleData to:dstIdx+z. "/ (3-z).
|
527
|
199 |
].
|
|
200 |
dstIdx := dstIdx - (width * 3).
|
|
201 |
].
|
|
202 |
|
|
203 |
"
|
|
204 |
IrisRGBReader fromFile:'/home2/cg/capture.rgb'
|
|
205 |
"
|
|
206 |
|
559
|
207 |
"Modified: 23.4.1997 / 18:59:11 / cg"
|
527
|
208 |
! !
|
|
209 |
|
|
210 |
!IrisRGBReader methodsFor:'testing '!
|
|
211 |
|
|
212 |
canRepresent:anImage
|
|
213 |
"return true, if anImage can be represented in my file format.
|
|
214 |
Currently only B&W and Depth8 images are supported."
|
|
215 |
|
|
216 |
|depth|
|
|
217 |
|
|
218 |
"/ anImage photometric == #rgb ifTrue:[
|
|
219 |
"/ ^ false "/ not yet implemented
|
|
220 |
"/ ].
|
|
221 |
"/ (depth := anImage depth) == 1 ifTrue:[^ true].
|
|
222 |
"/ depth == 8 ifTrue:[^ true].
|
|
223 |
^ false
|
|
224 |
|
|
225 |
"Created: 14.4.1997 / 15:38:51 / cg"
|
|
226 |
"Modified: 14.4.1997 / 15:58:20 / cg"
|
|
227 |
! !
|
|
228 |
|
|
229 |
!IrisRGBReader class methodsFor:'documentation'!
|
|
230 |
|
|
231 |
version
|
647
|
232 |
^ '$Header: /cvs/stx/stx/libview2/IrisRGBReader.st,v 1.4 1997-06-30 20:55:55 cg Exp $'
|
527
|
233 |
! !
|
|
234 |
IrisRGBReader initialize!
|