author | ca |
Fri, 23 Nov 2007 14:06:49 +0100 | |
changeset 2357 | 918859a27b27 |
parent 1848 | 864ca2cd4e71 |
child 2726 | de3b045610a0 |
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 |
||
1848 | 100 |
!IrisRGBReader methodsFor:'private-reading'! |
527 | 101 |
|
102 |
readRLEData |
|
103 |
"read RLE compressed data" |
|
104 |
||
105 |
|rleBufferLen tableLen startTable lengthTable rleData |
|
919 | 106 |
tblIdx dstIdx| |
527 | 107 |
|
108 |
rleBufferLen := width * 2 + 10. |
|
109 |
tableLen := height * bytesPerPixel. |
|
110 |
||
111 |
startTable := Array new:tableLen. |
|
112 |
lengthTable := Array new:tableLen. |
|
113 |
rleData := ByteArray uninitializedNew:rleBufferLen. |
|
114 |
||
115 |
"/ read rowStart & length table |
|
116 |
||
1753 | 117 |
inStream position1Based:512+1. |
527 | 118 |
1 to:tableLen do:[:i | |
119 |
startTable at:i put:(inStream nextLongMSB:true). |
|
120 |
]. |
|
121 |
1 to:tableLen do:[:i | |
|
122 |
lengthTable at:i put:(inStream nextLongMSB:true). |
|
123 |
]. |
|
124 |
||
125 |
data := ByteArray uninitializedNew:(width*height*3). |
|
126 |
||
127 |
dstIdx := width * (height-1) * 3 + 1. |
|
128 |
||
129 |
0 to:(height-1) do:[:y | |
|
130 |
0 to:(bytesPerPixel-1) do:[:z | |
|
131 |
|start length| |
|
132 |
||
133 |
tblIdx := y + (z*height) + 1. |
|
134 |
||
135 |
start := startTable at:tblIdx. |
|
136 |
length := lengthTable at:tblIdx. |
|
137 |
||
1753 | 138 |
inStream position1Based:(start + 1). |
527 | 139 |
(inStream nextBytes:length into:rleData startingAt:1) ~~ length ifTrue:[ |
140 |
self halt:'short read' |
|
141 |
]. |
|
142 |
(rleData at:length) ~~ 0 ifTrue:[ |
|
143 |
self halt. |
|
144 |
]. |
|
559 | 145 |
|
146 |
self class |
|
147 |
decompressRLEFrom:rleData at:1 |
|
148 |
into:data at:dstIdx+z increment:3. |
|
149 |
||
150 |
"/ self expandRow:rleData to:dstIdx+z. "/ (3-z). |
|
527 | 151 |
]. |
152 |
dstIdx := dstIdx - (width * 3). |
|
153 |
]. |
|
154 |
||
155 |
" |
|
156 |
IrisRGBReader fromFile:'/home2/cg/capture.rgb' |
|
157 |
" |
|
158 |
||
559 | 159 |
"Modified: 23.4.1997 / 18:59:11 / cg" |
527 | 160 |
! ! |
161 |
||
1848 | 162 |
!IrisRGBReader methodsFor:'reading'! |
163 |
||
164 |
fromStream:aStream |
|
165 |
"read a Portable bitmap file format as of Jeff Poskanzers Portable Bitmap Package. |
|
166 |
supported are IRIS_RGB, PGB and PNM files." |
|
167 |
||
168 |
| magic type dim isRLE bpp| |
|
169 |
||
170 |
inStream := aStream. |
|
171 |
inStream binary. |
|
172 |
||
173 |
magic := inStream nextShortMSB:true. |
|
174 |
magic ~~ 8r0732 ifTrue:[ |
|
175 |
^ self fileFormatError:'bad magic number'. |
|
176 |
]. |
|
177 |
||
178 |
type := inStream nextShortMSB:true. |
|
179 |
dim := inStream nextShortMSB:true. |
|
180 |
width := inStream nextShortMSB:true. |
|
181 |
height := inStream nextShortMSB:true. |
|
182 |
bytesPerPixel := inStream nextShortMSB:true. |
|
183 |
||
184 |
isRLE := (type bitAnd:16rFF00) == 16r0100. |
|
185 |
bpp := type bitAnd:16r00FF. |
|
186 |
bpp ~~ 1 ifTrue:[ |
|
187 |
^ self fileFormatError:'only 1byte/pixel channel supported'. |
|
188 |
]. |
|
189 |
bytesPerPixel ~~ 3 ifTrue:[ |
|
190 |
^ self fileFormatError:'can only read 3-channel images'. |
|
191 |
]. |
|
192 |
||
193 |
self reportDimension. |
|
194 |
||
195 |
isRLE ifTrue:[ |
|
196 |
self readRLEData |
|
197 |
] ifFalse:[ |
|
198 |
^ self fileFormatError:'currently, only RLE encoding supported'. |
|
199 |
"/ self readVerbatimData |
|
200 |
]. |
|
201 |
||
202 |
photometric := #rgb. |
|
203 |
samplesPerPixel := 3. |
|
204 |
bitsPerSample := #(8 8 8). |
|
205 |
||
206 |
" |
|
207 |
IrisRGBReader fromFile:'/home2/cg/capture.rgb' |
|
208 |
" |
|
209 |
||
210 |
"Created: / 14.4.1997 / 15:38:51 / cg" |
|
211 |
"Modified: / 1.4.1998 / 14:28:51 / cg" |
|
212 |
! ! |
|
213 |
||
527 | 214 |
!IrisRGBReader methodsFor:'testing '! |
215 |
||
216 |
canRepresent:anImage |
|
217 |
"return true, if anImage can be represented in my file format. |
|
218 |
Currently only B&W and Depth8 images are supported." |
|
219 |
||
919 | 220 |
"/ |depth| |
221 |
"/ |
|
527 | 222 |
"/ anImage photometric == #rgb ifTrue:[ |
223 |
"/ ^ false "/ not yet implemented |
|
224 |
"/ ]. |
|
225 |
"/ (depth := anImage depth) == 1 ifTrue:[^ true]. |
|
226 |
"/ depth == 8 ifTrue:[^ true]. |
|
227 |
^ false |
|
228 |
||
229 |
"Created: 14.4.1997 / 15:38:51 / cg" |
|
230 |
"Modified: 14.4.1997 / 15:58:20 / cg" |
|
231 |
! ! |
|
232 |
||
233 |
!IrisRGBReader class methodsFor:'documentation'! |
|
234 |
||
235 |
version |
|
1848 | 236 |
^ '$Header: /cvs/stx/stx/libview2/IrisRGBReader.st,v 1.12 2003-11-19 15:38:49 cg Exp $' |
527 | 237 |
! ! |
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
919
diff
changeset
|
238 |
|
527 | 239 |
IrisRGBReader initialize! |