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