author | Claus Gittinger <cg@exept.de> |
Thu, 10 Apr 2003 16:26:11 +0200 | |
changeset 1745 | 4fa0fad2a463 |
parent 919 | d0e28bc28b25 |
child 1753 | aa246112438a |
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 |
||
100 |
!IrisRGBReader methodsFor:'reading from file'! |
|
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" |
527 | 148 |
! |
149 |
||
150 |
readRLEData |
|
151 |
"read RLE compressed data" |
|
152 |
||
153 |
|rleBufferLen tableLen startTable lengthTable rleData |
|
919 | 154 |
tblIdx dstIdx| |
527 | 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 |
||
919 | 216 |
"/ |depth| |
217 |
"/ |
|
527 | 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 |
|
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
919
diff
changeset
|
232 |
^ '$Header: /cvs/stx/stx/libview2/IrisRGBReader.st,v 1.8 2003-04-10 14:25:31 cg Exp $' |
527 | 233 |
! ! |
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
919
diff
changeset
|
234 |
|
527 | 235 |
IrisRGBReader initialize! |