author | Claus Gittinger <cg@exept.de> |
Thu, 10 Apr 2003 16:26:11 +0200 | |
changeset 1745 | 4fa0fad2a463 |
parent 1737 | a1ed08195ee7 |
child 1756 | 7c4f38c59b2a |
permissions | -rw-r--r-- |
27 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by 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 |
||
1562
3b444efb61ee
bug fix: palette is padded after RLE data.
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
13 |
"{ Package: 'stx:libview2' }" |
3b444efb61ee
bug fix: palette is padded after RLE data.
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
14 |
|
27 | 15 |
ImageReader subclass:#PCXReader |
1737 | 16 |
instanceVariableNames:'header buffer nBuffer bufferIndex sourceBytesPerRow' |
201 | 17 |
classVariableNames:'' |
18 |
poolDictionaries:'' |
|
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
19 |
category:'Graphics-Images-Readers' |
27 | 20 |
! |
21 |
||
29 | 22 |
!PCXReader class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1994 by 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 |
" |
|
102 | 40 |
this class provides methods for loading 8-plane PCX bitmap files. |
201 | 41 |
|
29 | 42 |
Due to not having too many examples for testing, this could fail |
201 | 43 |
to read some files. |
44 |
(especially, I have no uncompressed files for testing). |
|
45 |
||
46 |
Only 8-bit (i.e. 256 color) PCX images are supported. |
|
47 |
Image writing is not supported. |
|
48 |
||
49 |
[See also:] |
|
531 | 50 |
Image Form Icon |
51 |
BlitImageReader FaceReader GIFReader JPEGReader PBMReader |
|
52 |
ST80FormReader SunRasterReader TargaReader TIFFReader WindowsIconReader |
|
53 |
XBMReader XPMReader XWDReader |
|
29 | 54 |
" |
1737 | 55 |
! |
56 |
||
57 |
examples |
|
58 |
" |
|
59 |
Image fromFile:'/usr/share/lilo/suse_640x480.pcx' |
|
60 |
" |
|
29 | 61 |
! ! |
62 |
||
43 | 63 |
!PCXReader class methodsFor:'initialization'! |
64 |
||
65 |
initialize |
|
201 | 66 |
"tell Image-class, that a new fileReader is present |
398 | 67 |
for the '.pcx' extension." |
43 | 68 |
|
647 | 69 |
MIMETypes defineImageType:'image/x-pcx' suffix:'pcx' reader:self. |
201 | 70 |
|
630 | 71 |
"Modified: 27.6.1997 / 18:39:23 / cg" |
43 | 72 |
! ! |
73 |
||
27 | 74 |
!PCXReader class methodsFor:'testing'! |
75 |
||
76 |
isValidImageFile:aFilename |
|
77 |
"return true, if aFilename contains a PCX image" |
|
78 |
||
29 | 79 |
|count header inStream| |
27 | 80 |
|
81 |
inStream := self streamReadingFile:aFilename. |
|
82 |
inStream isNil ifTrue:[^ false]. |
|
83 |
inStream binary. |
|
84 |
||
85 |
header := ByteArray uninitializedNew:128. |
|
29 | 86 |
count := inStream nextBytes:128 into:header. |
27 | 87 |
inStream close. |
88 |
||
29 | 89 |
((count == 128) and:[self isValidPCXHeader:header]) ifFalse:[ |
27 | 90 |
^ false |
91 |
]. |
|
92 |
^ true |
|
102 | 93 |
|
94 |
"Modified: 17.9.1995 / 17:32:07 / claus" |
|
201 | 95 |
! |
96 |
||
97 |
isValidPCXHeader:aHeader |
|
98 |
"return true, if aHeader looks like a PCX image header" |
|
99 |
||
530 | 100 |
"check magic number" |
201 | 101 |
((aHeader at:1) ~~ 16r0A) ifTrue:[ |
531 | 102 |
^ false |
201 | 103 |
]. |
104 |
||
105 |
"check version" |
|
106 |
(#(0 2 3 5) includes:(aHeader at:2)) ifFalse:[ |
|
531 | 107 |
^ false |
201 | 108 |
]. |
109 |
||
110 |
^ true |
|
530 | 111 |
|
112 |
"Modified: 16.4.1997 / 22:24:32 / cg" |
|
27 | 113 |
! ! |
114 |
||
115 |
!PCXReader methodsFor:'reading from file'! |
|
116 |
||
1737 | 117 |
extractColorMap16 |
118 |
"extract the 16-entry colormap from the header" |
|
119 |
||
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
120 |
|rawMap| |
1737 | 121 |
|
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
122 |
rawMap := header copyFrom:17 to:(17 + (16*3) - 1). |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
123 |
^ Colormap rgbVector:rawMap |
1737 | 124 |
|
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
125 |
"/ |rawMap srcIndex rMap gMap bMap| |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
126 |
"/ |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
127 |
"/ rawMap := ByteArray uninitializedNew:(16*3). |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
128 |
"/ rawMap replaceFrom:1 to:(16*3) with:header startingAt:17. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
129 |
"/ rMap := ByteArray new:16. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
130 |
"/ gMap := ByteArray new:16. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
131 |
"/ bMap := ByteArray new:16. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
132 |
"/ srcIndex := 1. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
133 |
"/ 1 to:16 do:[:i | |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
134 |
"/ |r g b| |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
135 |
"/ |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
136 |
"/ r := rawMap at:srcIndex. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
137 |
"/ g := rawMap at:srcIndex+1. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
138 |
"/ b := rawMap at:srcIndex+2. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
139 |
"/ |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
140 |
"/ rMap at:i put:r. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
141 |
"/ gMap at:i put:g. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
142 |
"/ bMap at:i put:b. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
143 |
"/ srcIndex := srcIndex + 3. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
144 |
"/ ]. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
145 |
"/ ^ Colormap redVector:rMap greenVector:gMap blueVector:bMap. |
1737 | 146 |
! |
147 |
||
148 |
nextByteFromBufferOrStream |
|
149 |
|byte| |
|
150 |
||
151 |
nBuffer ~~ 0 ifTrue:[ |
|
152 |
byte := buffer at:bufferIndex. |
|
153 |
bufferIndex := bufferIndex + 1. nBuffer := nBuffer - 1. |
|
154 |
] ifFalse:[ |
|
155 |
byte := inStream next |
|
156 |
]. |
|
157 |
^ byte |
|
158 |
! |
|
159 |
||
160 |
readColorMap256 |
|
161 |
|rawMap mapSize rMap gMap bMap srcIndex| |
|
162 |
||
163 |
rawMap := ByteArray uninitializedNew:(256*3). |
|
164 |
nBuffer ~~ 0 ifTrue:[ |
|
165 |
mapSize := buffer size - bufferIndex + 1. |
|
166 |
mapSize := mapSize min:(256*3). |
|
167 |
rawMap replaceFrom:1 to:mapSize with:buffer startingAt:bufferIndex. |
|
168 |
nBuffer < (256*3) ifTrue:[ |
|
169 |
inStream nextBytes:((256*3)-nBuffer) into:rawMap startingAt:nBuffer+1 |
|
170 |
] |
|
171 |
] ifFalse:[ |
|
172 |
inStream nextBytes:(256*3) into:rawMap. |
|
173 |
]. |
|
174 |
||
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
175 |
^ Colormap rgbVector:rawMap |
1737 | 176 |
|
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
177 |
"/ rMap := Array new:256. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
178 |
"/ gMap := Array new:256. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
179 |
"/ bMap := Array new:256. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
180 |
"/ srcIndex := 1. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
181 |
"/ |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
182 |
"/ 1 to:256 do:[:i | |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
183 |
"/ |r g b| |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
184 |
"/ |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
185 |
"/ r := rawMap at:srcIndex. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
186 |
"/ g := rawMap at:srcIndex+1. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
187 |
"/ b := rawMap at:srcIndex+2. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
188 |
"/ |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
189 |
"/ rMap at:i put:r. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
190 |
"/ gMap at:i put:g. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
191 |
"/ bMap at:i put:b. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
192 |
"/ srcIndex := srcIndex + 3. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
193 |
"/ ]. |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
194 |
"/ |
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
195 |
"/ ^ Colormap redVector:rMap greenVector:gMap blueVector:bMap. |
1737 | 196 |
! |
197 |
||
198 |
readCompressedData |
|
199 |
|bendIndex rowIndex dstIndex endIndex byte nByte value idx2 |
|
200 |
srcIndex| |
|
201 |
||
202 |
data := ByteArray uninitializedNew:(height * sourceBytesPerRow). |
|
203 |
||
204 |
buffer := ByteArray uninitializedNew:4096. |
|
205 |
bufferIndex := 1. |
|
206 |
bendIndex := 1. |
|
201 | 207 |
|
1737 | 208 |
rowIndex := 1. |
209 |
1 to:height do:[:row | |
|
210 |
dstIndex := rowIndex. |
|
211 |
endIndex := dstIndex + sourceBytesPerRow. |
|
212 |
[dstIndex < endIndex] whileTrue:[ |
|
213 |
bufferIndex == bendIndex ifTrue:[ |
|
214 |
nBuffer := inStream nextBytes:4096 into:buffer. |
|
215 |
bufferIndex := 1. |
|
216 |
bendIndex := nBuffer + 1. |
|
217 |
]. |
|
218 |
byte := buffer at:bufferIndex. |
|
219 |
bufferIndex := bufferIndex + 1. |
|
220 |
((byte bitAnd:2r11000000) ~~ 2r11000000) ifTrue:[ |
|
221 |
data at:dstIndex put:byte. |
|
222 |
dstIndex := dstIndex + 1. |
|
223 |
] ifFalse:[ |
|
224 |
nByte := byte bitAnd:2r00111111. |
|
225 |
bufferIndex == bendIndex ifTrue:[ |
|
226 |
nBuffer := inStream nextBytes:4096 into:buffer. |
|
227 |
bufferIndex := 1. |
|
228 |
bendIndex := nBuffer + 1. |
|
229 |
]. |
|
230 |
value := buffer at:bufferIndex. |
|
231 |
bufferIndex := bufferIndex + 1. |
|
232 |
idx2 := ((dstIndex + nByte) min:endIndex) - 1. |
|
233 |
data from:dstIndex to:idx2 put:value. |
|
234 |
dstIndex := dstIndex + nByte. |
|
235 |
]. |
|
236 |
]. |
|
237 |
rowIndex := endIndex. |
|
238 |
]. |
|
239 |
||
240 |
"/ have to compress - above code reads sourceBytesPerRow |
|
241 |
"/ (to keep in sync with RLE); but we want width bytesPerRow |
|
242 |
"/ Can compress in the data-area; leftover pixels are simply ignored |
|
243 |
"/ by other image processing code |
|
244 |
"/ |
|
245 |
sourceBytesPerRow ~~ width ifTrue:[ |
|
246 |
dstIndex := width + 1. |
|
247 |
srcIndex := sourceBytesPerRow + 1. |
|
248 |
2 to:height do:[:row | |
|
249 |
data replaceFrom:dstIndex to:dstIndex+width-1 with:data startingAt:srcIndex. |
|
250 |
dstIndex := dstIndex + width. |
|
251 |
srcIndex := srcIndex + sourceBytesPerRow |
|
252 |
] |
|
253 |
]. |
|
254 |
nBuffer := endIndex - bufferIndex. |
|
255 |
! |
|
256 |
||
257 |
readImage |
|
258 |
"read an image in pcx format from inStream" |
|
201 | 259 |
|
260 |
inStream binary. |
|
261 |
||
1737 | 262 |
header := ByteArray uninitializedNew:128. |
263 |
(inStream nextBytes:128 into:header) == 128 ifFalse:[ |
|
812
01d6b05a1276
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
264 |
^ self fileFormatError:'short file'. |
201 | 265 |
]. |
266 |
||
267 |
(self class isValidPCXHeader:header) ifFalse:[ |
|
812
01d6b05a1276
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
268 |
^ self fileFormatError:'wrong header'. |
201 | 269 |
]. |
270 |
||
1737 | 271 |
self readRestAfterHeader. |
201 | 272 |
! |
273 |
||
1737 | 274 |
readRestAfterHeader |
201 | 275 |
"read an raw image in pcx format from aStream. |
276 |
The header has already been read into the header argument." |
|
277 |
||
27 | 278 |
| inDepth version compression nPlanes xmin ymin xmax ymax |
1737 | 279 |
paletteType |
280 |
byte "{Class: SmallInteger }" |
|
281 |
nMaxPad| |
|
27 | 282 |
|
531 | 283 |
"/ typedef struct { /*header for PCX bitmap files*/ |
566 | 284 |
"/ unsigned char signature; /*1 PCX file identifier*/ |
285 |
"/ unsigned char version; /*2 version compatibility level*/ |
|
286 |
"/ unsigned char encoding; /*3 encoding method*/ |
|
287 |
"/ unsigned char bitsperpix; /*4 bits per pixel, or depth*/ |
|
288 |
"/ unsigned short Xleft; /*5 X position of left edge*/ |
|
289 |
"/ unsigned short Ytop; /*7 Y position of top edge*/ |
|
290 |
"/ unsigned short Xright; /*9 X position of right edge*/ |
|
291 |
"/ unsigned short Ybottom; /*11 Y position of bottom edge*/ |
|
292 |
"/ unsigned short Xscreensize; /*13 X screen res of source image*/ |
|
293 |
"/ unsigned short Yscreensize; /*15 Y screen res of source image*/ |
|
294 |
"/ unsigned char PCXpalette[16][3]; /*17 PCX color map*/ |
|
295 |
"/ unsigned char reserved1; /*17+48 should be 0, 1 if std res fax*/ |
|
296 |
"/ unsigned char planes; /*66 bit planes in image*/ |
|
297 |
"/ unsigned short linesize; /*67 byte delta between scanlines */ |
|
531 | 298 |
"/ unsigned short paletteinfo; /*0 == undef |
299 |
"/ 1 == color |
|
300 |
"/ 2 == grayscale*/ |
|
301 |
"/ unsigned char reserved2[58]; /*fill to struct size of 128*/ |
|
302 |
"/ } PCX_HEADER; |
|
303 |
||
27 | 304 |
version := header at:2. |
305 |
"/ 'version=' print. version printNL. |
|
306 |
compression := header at:3. |
|
307 |
"/ 'compression=' print. compression printNL. |
|
308 |
(#(0 1) includes:compression) ifFalse:[ |
|
812
01d6b05a1276
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
309 |
^ self fileFormatError:'unknown compression'. |
27 | 310 |
]. |
530 | 311 |
|
27 | 312 |
inDepth := header at:4. |
313 |
"/ 'depth=' print. inDepth printNL. |
|
314 |
nPlanes := header at:66. |
|
315 |
"/ 'planes=' print. nPlanes printNL. |
|
1737 | 316 |
sourceBytesPerRow := header wordAt:67 MSB:false. |
83 | 317 |
"/ 'srcBytesPerRow=' print. srcBytesPerRow printNL. |
27 | 318 |
paletteType := header at:69. |
319 |
||
320 |
" |
|
321 |
although it would be easy to implement ... |
|
322 |
I have no test pictures for other formats. |
|
323 |
So its not (yet) implemented |
|
324 |
" |
|
325 |
((inDepth ~~ 8) or:[nPlanes ~~ 1]) ifTrue:[ |
|
812
01d6b05a1276
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
326 |
"/ 'PCXReader: depth: ' errorPrint. inDepth errorPrint. |
01d6b05a1276
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
327 |
"/ ' planes:' errorPrint. nPlanes errorPrintNL. |
01d6b05a1276
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
328 |
^ self fileFormatError:'can only handle 1-plane 256 color images'. |
27 | 329 |
]. |
330 |
||
83 | 331 |
xmin := header wordAt:5 MSB:false. |
332 |
ymin := header wordAt:7 MSB:false. |
|
333 |
xmax := header wordAt:9 MSB:false. |
|
334 |
ymax := header wordAt:11 MSB:false. |
|
27 | 335 |
|
336 |
width := (xmax - xmin + 1). |
|
337 |
height := (ymax - ymin + 1). |
|
338 |
"/ 'width=' print. width printNL. |
|
339 |
"/ 'height=' print. width printNL. |
|
340 |
||
341 |
(version == 2) ifTrue:[ |
|
1737 | 342 |
colorMap := self extractColorMap16. |
27 | 343 |
]. |
344 |
||
29 | 345 |
compression == 1 ifTrue:[ |
1737 | 346 |
self readCompressedData |
27 | 347 |
] ifFalse:[ |
1737 | 348 |
self readUncompressedData |
27 | 349 |
]. |
350 |
||
351 |
(version == 5) ifTrue:[ |
|
1562
3b444efb61ee
bug fix: palette is padded after RLE data.
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
352 |
"/ RLE data is padded - skip over zeros for the 0C-byte |
3b444efb61ee
bug fix: palette is padded after RLE data.
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
353 |
nMaxPad := 15. |
1737 | 354 |
byte := self nextByteFromBufferOrStream. |
355 |
||
1562
3b444efb61ee
bug fix: palette is padded after RLE data.
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
356 |
[(byte ~~ 16r0C) and:[nMaxPad > 0]] whileTrue:[ |
1737 | 357 |
byte := self nextByteFromBufferOrStream. |
561 | 358 |
]. |
1562
3b444efb61ee
bug fix: palette is padded after RLE data.
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
359 |
(byte == 16r0C) ifFalse:[ |
3b444efb61ee
bug fix: palette is padded after RLE data.
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
360 |
'PCXREADER: no valid 256-entry palette (got' errorPrint. |
3b444efb61ee
bug fix: palette is padded after RLE data.
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
361 |
byte errorPrint. '; expected ' errorPrint. 16rC0 errorPrint. ')' errorPrintCR. |
3b444efb61ee
bug fix: palette is padded after RLE data.
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
362 |
]. |
3b444efb61ee
bug fix: palette is padded after RLE data.
Claus Gittinger <cg@exept.de>
parents:
812
diff
changeset
|
363 |
|
1737 | 364 |
colorMap := self readColorMap256. |
27 | 365 |
]. |
366 |
||
367 |
photometric := #palette. |
|
368 |
samplesPerPixel := 1. |
|
369 |
bitsPerSample := #(8). |
|
370 |
||
371 |
" |
|
372 |
|i f| |
|
29 | 373 |
i := Image fromFile:'somefile.pcx'. |
374 |
i inspect. |
|
27 | 375 |
" |
499 | 376 |
|
812
01d6b05a1276
use common fileFormatError reporter
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
377 |
"Modified: / 3.2.1998 / 17:59:03 / cg" |
1737 | 378 |
! |
379 |
||
380 |
readUncompressedData |
|
381 |
|dstIndex| |
|
382 |
||
383 |
" |
|
384 |
actually untested ... |
|
385 |
" |
|
386 |
data := ByteArray uninitializedNew:(height * width). |
|
387 |
sourceBytesPerRow ~~ width ifTrue:[ |
|
388 |
dstIndex := 1. |
|
389 |
1 to:height do:[:row | |
|
390 |
inStream nextBytes:width into:data startingAt:dstIndex. |
|
391 |
dstIndex := dstIndex + width. |
|
392 |
inStream skip:(sourceBytesPerRow - width). |
|
393 |
] |
|
394 |
] ifFalse:[ |
|
395 |
inStream nextBytes:(height * width) into:data. |
|
396 |
]. |
|
397 |
nBuffer := 0. |
|
27 | 398 |
! ! |
399 |
||
201 | 400 |
!PCXReader class methodsFor:'documentation'! |
401 |
||
402 |
version |
|
1745
4fa0fad2a463
code cleanup (colorMap handling)
Claus Gittinger <cg@exept.de>
parents:
1737
diff
changeset
|
403 |
^ '$Header: /cvs/stx/stx/libview2/PCXReader.st,v 1.28 2003-04-10 14:25:57 cg Exp $' |
201 | 404 |
! ! |
1737 | 405 |
|
27 | 406 |
PCXReader initialize! |