author | tz |
Mon, 11 May 1998 22:56:57 +0200 | |
changeset 919 | d0e28bc28b25 |
parent 883 | 5e3c3d895f7d |
child 1745 | 4fa0fad2a463 |
permissions | -rw-r--r-- |
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:[ |
|
810
93a9f3c4d8ec
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
111 |
^ self fileFormatError:'bad magic number'. |
527 | 112 |
]. |
113 |
||
114 |
type := inStream nextShortMSB:true. |
|
115 |
dim := inStream nextShortMSB:true. |
|
116 |
width := inStream nextShortMSB:true. |
|
117 |
height := inStream nextShortMSB:true. |
|
118 |
bytesPerPixel := inStream nextShortMSB:true. |
|
119 |
||
120 |
isRLE := (type bitAnd:16rFF00) == 16r0100. |
|
121 |
bpp := type bitAnd:16r00FF. |
|
122 |
bpp ~~ 1 ifTrue:[ |
|
810
93a9f3c4d8ec
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
123 |
^ self fileFormatError:'only 1byte/pixel channel supported'. |
527 | 124 |
]. |
125 |
bytesPerPixel ~~ 3 ifTrue:[ |
|
810
93a9f3c4d8ec
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
126 |
^ self fileFormatError:'can only read 3-channel images'. |
527 | 127 |
]. |
128 |
||
129 |
isRLE ifTrue:[ |
|
130 |
self readRLEData |
|
131 |
] ifFalse:[ |
|
810
93a9f3c4d8ec
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
132 |
^ self fileFormatError:'currently, only RLE encoding supported'. |
883 | 133 |
"/ self readVerbatimData |
527 | 134 |
]. |
135 |
||
136 |
photometric := #rgb. |
|
137 |
samplesPerPixel := 3. |
|
138 |
bitsPerSample := #(8 8 8). |
|
139 |
||
140 |
" |
|
141 |
IrisRGBReader fromFile:'/home2/cg/capture.rgb' |
|
142 |
" |
|
143 |
||
810
93a9f3c4d8ec
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
144 |
"Created: / 14.4.1997 / 15:38:51 / cg" |
883 | 145 |
"Modified: / 1.4.1998 / 14:28:51 / cg" |
527 | 146 |
! |
147 |
||
148 |
readRLEData |
|
149 |
"read RLE compressed data" |
|
150 |
||
151 |
|rleBufferLen tableLen startTable lengthTable rleData |
|
919 | 152 |
tblIdx dstIdx| |
527 | 153 |
|
154 |
rleBufferLen := width * 2 + 10. |
|
155 |
tableLen := height * bytesPerPixel. |
|
156 |
||
157 |
startTable := Array new:tableLen. |
|
158 |
lengthTable := Array new:tableLen. |
|
159 |
rleData := ByteArray uninitializedNew:rleBufferLen. |
|
160 |
||
161 |
"/ read rowStart & length table |
|
162 |
||
163 |
inStream position:512+1. |
|
164 |
1 to:tableLen do:[:i | |
|
165 |
startTable at:i put:(inStream nextLongMSB:true). |
|
166 |
]. |
|
167 |
1 to:tableLen do:[:i | |
|
168 |
lengthTable at:i put:(inStream nextLongMSB:true). |
|
169 |
]. |
|
170 |
||
171 |
data := ByteArray uninitializedNew:(width*height*3). |
|
172 |
||
173 |
dstIdx := width * (height-1) * 3 + 1. |
|
174 |
||
175 |
0 to:(height-1) do:[:y | |
|
176 |
0 to:(bytesPerPixel-1) do:[:z | |
|
177 |
|start length| |
|
178 |
||
179 |
tblIdx := y + (z*height) + 1. |
|
180 |
||
181 |
start := startTable at:tblIdx. |
|
182 |
length := lengthTable at:tblIdx. |
|
183 |
||
184 |
inStream position:(start + 1). |
|
185 |
(inStream nextBytes:length into:rleData startingAt:1) ~~ length ifTrue:[ |
|
186 |
self halt:'short read' |
|
187 |
]. |
|
188 |
(rleData at:length) ~~ 0 ifTrue:[ |
|
189 |
self halt. |
|
190 |
]. |
|
559 | 191 |
|
192 |
self class |
|
193 |
decompressRLEFrom:rleData at:1 |
|
194 |
into:data at:dstIdx+z increment:3. |
|
195 |
||
196 |
"/ self expandRow:rleData to:dstIdx+z. "/ (3-z). |
|
527 | 197 |
]. |
198 |
dstIdx := dstIdx - (width * 3). |
|
199 |
]. |
|
200 |
||
201 |
" |
|
202 |
IrisRGBReader fromFile:'/home2/cg/capture.rgb' |
|
203 |
" |
|
204 |
||
559 | 205 |
"Modified: 23.4.1997 / 18:59:11 / cg" |
527 | 206 |
! ! |
207 |
||
208 |
!IrisRGBReader methodsFor:'testing '! |
|
209 |
||
210 |
canRepresent:anImage |
|
211 |
"return true, if anImage can be represented in my file format. |
|
212 |
Currently only B&W and Depth8 images are supported." |
|
213 |
||
919 | 214 |
"/ |depth| |
215 |
"/ |
|
527 | 216 |
"/ anImage photometric == #rgb ifTrue:[ |
217 |
"/ ^ false "/ not yet implemented |
|
218 |
"/ ]. |
|
219 |
"/ (depth := anImage depth) == 1 ifTrue:[^ true]. |
|
220 |
"/ depth == 8 ifTrue:[^ true]. |
|
221 |
^ false |
|
222 |
||
223 |
"Created: 14.4.1997 / 15:38:51 / cg" |
|
224 |
"Modified: 14.4.1997 / 15:58:20 / cg" |
|
225 |
! ! |
|
226 |
||
227 |
!IrisRGBReader class methodsFor:'documentation'! |
|
228 |
||
229 |
version |
|
919 | 230 |
^ '$Header: /cvs/stx/stx/libview2/IrisRGBReader.st,v 1.7 1998-05-11 20:56:57 tz Exp $' |
527 | 231 |
! ! |
232 |
IrisRGBReader initialize! |