42
|
1 |
'From Smalltalk/X, Version:2.10.4 on 18-feb-1995 at 3:27:03 am'!
|
|
2 |
|
|
3 |
ImageReader subclass:#XWDReader
|
|
4 |
instanceVariableNames:''
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Graphics-Images support'
|
|
8 |
!
|
|
9 |
|
|
10 |
!XWDReader methodsFor:'image reading'!
|
|
11 |
|
|
12 |
fromStream: aStream
|
|
13 |
"read an image in XWD (X Window Dump) format."
|
|
14 |
|
|
15 |
|header nColors palette res colors pad srcRowByteSize bitsPerPixel mask colormapSize depth |
|
|
16 |
|
|
17 |
aStream binary.
|
|
18 |
|
|
19 |
header := (1 to: 25) collect: [:i | aStream nextLong].
|
|
20 |
|
|
21 |
"skip ..."
|
|
22 |
101 to:(header at: 1) do: [:i | aStream next].
|
|
23 |
|
|
24 |
depth := header at: 4.
|
|
25 |
width := header at: 5.
|
|
26 |
height := header at: 6.
|
|
27 |
pad := header at: 11.
|
|
28 |
bitsPerPixel := header at: 12.
|
|
29 |
bitsPerPixel == 24 ifTrue:[
|
|
30 |
bitsPerSample := #(8 8 8).
|
|
31 |
samplesPerPixel := 3.
|
|
32 |
photometric := #rgb
|
|
33 |
] ifFalse:[
|
|
34 |
bitsPerSample := Array with:bitsPerPixel.
|
|
35 |
samplesPerPixel := 1.
|
|
36 |
photometric := #palette
|
|
37 |
].
|
|
38 |
|
|
39 |
colormapSize := header at: 19.
|
|
40 |
nColors := header at: 20.
|
|
41 |
|
|
42 |
colorMap := Array new:depth * depth.
|
|
43 |
|
|
44 |
1 to:nColors do:[:i |
|
|
45 |
|clr|
|
|
46 |
|
|
47 |
aStream nextLong.
|
|
48 |
clr := Color scaledRed: (aStream nextWord bitShift: -3)
|
|
49 |
scaledGreen: (aStream nextWord bitShift: -3)
|
|
50 |
scaledBlue: (aStream nextWord bitShift: -3).
|
|
51 |
colorMap at:i put:clr.
|
|
52 |
aStream nextWord.
|
|
53 |
].
|
|
54 |
|
|
55 |
nColors+1 to:(depth * depth) do: [:i | colorMap at:i put:Color black].
|
|
56 |
|
|
57 |
srcRowByteSize := width * bitsPerPixel + pad - 1 // pad * (pad / 8).
|
|
58 |
data := ByteArray uninitializedNew: srcRowByteSize * height.
|
|
59 |
aStream nextBytes:srcRowByteSize * height into:data.
|
|
60 |
|
|
61 |
"
|
|
62 |
XWDReader fromFile:'/phys/clam/claus/smalltalk/private_classes/hpdst/pixmaps/bike.xwd'
|
|
63 |
"
|
|
64 |
! !
|
|
65 |
|