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