author | Claus Gittinger <cg@exept.de> |
Wed, 08 Feb 2017 00:50:25 +0100 | |
changeset 3864 | 37f4e48a35e7 |
parent 3097 | b067905c1c89 |
child 3855 | 1db7742d33ad |
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 |
" |
|
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
919
diff
changeset
|
12 |
"{ Package: 'stx:libview2' }" |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
919
diff
changeset
|
13 |
|
527 | 14 |
ImageReader subclass:#IrisRGBReader |
15 |
instanceVariableNames:'bytesPerPixel' |
|
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
919
diff
changeset
|
18 |
category:'Graphics-Images-Readers' |
527 | 19 |
! |
20 |
||
21 |
!IrisRGBReader class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
39 |
this class provides methods for loading Iris RGB format images. |
|
40 |
Only 3-byte/pixel format is supported. |
|
41 |
Writing is not (yet) supported. |
|
42 |
||
43 |
[author:] |
|
44 |
Claus Gittinger |
|
45 |
||
46 |
[See also:] |
|
47 |
Image Form Icon |
|
48 |
BlitImageReader FaceReader GIFReader JPEGReader PCXReader |
|
49 |
ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader |
|
50 |
XBMReader XPMReader XWDReader |
|
51 |
" |
|
52 |
! ! |
|
53 |
||
54 |
!IrisRGBReader class methodsFor:'initialization'! |
|
55 |
||
56 |
initialize |
|
57 |
"install myself in the Image classes fileFormat table |
|
58 |
for the `.rgb' extension." |
|
59 |
||
647 | 60 |
MIMETypes defineImageType:'image/x-rgb' suffix:'rgb' reader:self. |
527 | 61 |
|
62 |
"Modified: 14.4.1997 / 15:49:19 / cg" |
|
63 |
! ! |
|
64 |
||
65 |
!IrisRGBReader class methodsFor:'testing'! |
|
66 |
||
67 |
isValidImageFile:aFileName |
|
68 |
"return true, if aFileName contains an IRIS_RGB image" |
|
69 |
||
70 |
|inStream magic type bpp dim w h bytesPerPixel| |
|
71 |
||
72 |
inStream := self streamReadingFile:aFileName. |
|
73 |
inStream isNil ifTrue:[^ false]. |
|
74 |
||
75 |
inStream binary. |
|
76 |
||
77 |
magic := inStream nextShortMSB:true. |
|
78 |
type := inStream nextShortMSB:true. |
|
79 |
dim := inStream nextShortMSB:true. |
|
80 |
w := inStream nextShortMSB:true. |
|
81 |
h := inStream nextShortMSB:true. |
|
82 |
bytesPerPixel := inStream nextShortMSB:true. |
|
83 |
inStream close. |
|
84 |
||
85 |
magic ~~ 8r0732 ifTrue:[^ false]. |
|
86 |
bpp := type bitAnd:16r00FF. |
|
87 |
bpp ~~ 1 ifTrue:[^ false]. |
|
88 |
bytesPerPixel ~~ 3 ifTrue:[^ false]. |
|
89 |
||
90 |
^ true |
|
91 |
||
92 |
" |
|
93 |
IrisRGBReader isValidImageFile:'/home2/cg/capture.rgb' |
|
94 |
" |
|
95 |
||
96 |
"Modified: 14.4.1997 / 16:51:58 / cg" |
|
97 |
! ! |
|
98 |
||
1848 | 99 |
!IrisRGBReader methodsFor:'private-reading'! |
527 | 100 |
|
101 |
readRLEData |
|
2726 | 102 |
"read RLE compressed data." |
527 | 103 |
|
104 |
|rleBufferLen tableLen startTable lengthTable rleData |
|
919 | 105 |
tblIdx dstIdx| |
527 | 106 |
|
107 |
rleBufferLen := width * 2 + 10. |
|
108 |
tableLen := height * bytesPerPixel. |
|
109 |
||
110 |
startTable := Array new:tableLen. |
|
111 |
lengthTable := Array new:tableLen. |
|
112 |
rleData := ByteArray uninitializedNew:rleBufferLen. |
|
113 |
||
114 |
"/ read rowStart & length table |
|
115 |
||
1753 | 116 |
inStream position1Based:512+1. |
527 | 117 |
1 to:tableLen do:[:i | |
118 |
startTable at:i put:(inStream nextLongMSB:true). |
|
119 |
]. |
|
120 |
1 to:tableLen do:[:i | |
|
121 |
lengthTable at:i put:(inStream nextLongMSB:true). |
|
122 |
]. |
|
123 |
||
2726 | 124 |
data := ByteArray uninitializedNew:(width*height*bytesPerPixel). |
527 | 125 |
|
2726 | 126 |
dstIdx := width * (height-1) * bytesPerPixel + 1. |
527 | 127 |
|
128 |
0 to:(height-1) do:[:y | |
|
129 |
0 to:(bytesPerPixel-1) do:[:z | |
|
130 |
|start length| |
|
131 |
||
132 |
tblIdx := y + (z*height) + 1. |
|
133 |
||
134 |
start := startTable at:tblIdx. |
|
135 |
length := lengthTable at:tblIdx. |
|
136 |
||
1753 | 137 |
inStream position1Based:(start + 1). |
527 | 138 |
(inStream nextBytes:length into:rleData startingAt:1) ~~ length ifTrue:[ |
139 |
self halt:'short read' |
|
140 |
]. |
|
141 |
(rleData at:length) ~~ 0 ifTrue:[ |
|
3097 | 142 |
self halt:'lengthTable not 0 terminated'. |
527 | 143 |
]. |
559 | 144 |
|
145 |
self class |
|
146 |
decompressRLEFrom:rleData at:1 |
|
2726 | 147 |
into:data at:dstIdx+z increment:bytesPerPixel. |
559 | 148 |
|
149 |
"/ self expandRow:rleData to:dstIdx+z. "/ (3-z). |
|
527 | 150 |
]. |
2726 | 151 |
dstIdx := dstIdx - (width * bytesPerPixel). |
527 | 152 |
]. |
153 |
||
154 |
" |
|
155 |
IrisRGBReader fromFile:'/home2/cg/capture.rgb' |
|
156 |
" |
|
157 |
||
559 | 158 |
"Modified: 23.4.1997 / 18:59:11 / cg" |
527 | 159 |
! ! |
160 |
||
1848 | 161 |
!IrisRGBReader methodsFor:'reading'! |
162 |
||
163 |
fromStream:aStream |
|
164 |
| magic type dim isRLE bpp| |
|
165 |
||
166 |
inStream := aStream. |
|
167 |
inStream binary. |
|
168 |
||
169 |
magic := inStream nextShortMSB:true. |
|
170 |
magic ~~ 8r0732 ifTrue:[ |
|
171 |
^ self fileFormatError:'bad magic number'. |
|
172 |
]. |
|
173 |
||
174 |
type := inStream nextShortMSB:true. |
|
175 |
dim := inStream nextShortMSB:true. |
|
176 |
width := inStream nextShortMSB:true. |
|
177 |
height := inStream nextShortMSB:true. |
|
178 |
bytesPerPixel := inStream nextShortMSB:true. |
|
179 |
||
180 |
isRLE := (type bitAnd:16rFF00) == 16r0100. |
|
181 |
bpp := type bitAnd:16r00FF. |
|
182 |
bpp ~~ 1 ifTrue:[ |
|
183 |
^ self fileFormatError:'only 1byte/pixel channel supported'. |
|
184 |
]. |
|
2726 | 185 |
(bytesPerPixel ~~ 3 and:[ bytesPerPixel ~~ 4 ]) ifTrue:[ |
186 |
^ self fileFormatError:'can only read 3- and 4-channel images'. |
|
1848 | 187 |
]. |
188 |
||
189 |
self reportDimension. |
|
190 |
||
191 |
isRLE ifTrue:[ |
|
192 |
self readRLEData |
|
193 |
] ifFalse:[ |
|
2726 | 194 |
"/ self readVerbatimData |
1848 | 195 |
^ self fileFormatError:'currently, only RLE encoding supported'. |
196 |
]. |
|
197 |
||
2726 | 198 |
photometric := #rgba. |
199 |
samplesPerPixel := 4. |
|
200 |
bitsPerSample := #(8 8 8 8). |
|
1848 | 201 |
|
202 |
" |
|
203 |
IrisRGBReader fromFile:'/home2/cg/capture.rgb' |
|
204 |
" |
|
205 |
||
206 |
"Created: / 14.4.1997 / 15:38:51 / cg" |
|
207 |
"Modified: / 1.4.1998 / 14:28:51 / cg" |
|
208 |
! ! |
|
209 |
||
527 | 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 |
|
3097 | 232 |
^ '$Header: /cvs/stx/stx/libview2/IrisRGBReader.st,v 1.14 2013-03-06 09:01:16 cg Exp $' |
527 | 233 |
! ! |
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
919
diff
changeset
|
234 |
|
3097 | 235 |
|
527 | 236 |
IrisRGBReader initialize! |