44
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1995 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 |
"
|
42
|
12 |
|
|
13 |
ImageReader subclass:#XWDReader
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Graphics-Images support'
|
|
18 |
!
|
|
19 |
|
44
|
20 |
XWDReader comment:'
|
|
21 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
22 |
All Rights Reserved
|
|
23 |
|
|
24 |
$Header: /cvs/stx/stx/libview2/XWDReader.st,v 1.2 1995-02-18 17:56:08 claus Exp $
|
|
25 |
'!
|
|
26 |
|
|
27 |
!XWDReader class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
32 |
All Rights Reserved
|
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
|
45 |
$Header: /cvs/stx/stx/libview2/XWDReader.st,v 1.2 1995-02-18 17:56:08 claus Exp $
|
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
this class provides methods for loading x-window dump (xwd) images.
|
|
52 |
"
|
|
53 |
! !
|
|
54 |
|
42
|
55 |
!XWDReader methodsFor:'image reading'!
|
|
56 |
|
|
57 |
fromStream: aStream
|
44
|
58 |
"read an image in XWD (X Window Dump) format."
|
42
|
59 |
|
44
|
60 |
|header nColors palette res colors pad
|
|
61 |
srcRowByteSize bytesPerRow bitsPerPixel mask colormapSize depth
|
|
62 |
dstIndex|
|
42
|
63 |
|
|
64 |
aStream binary.
|
|
65 |
|
|
66 |
header := (1 to: 25) collect: [:i | aStream nextLong].
|
|
67 |
|
|
68 |
"skip ..."
|
|
69 |
101 to:(header at: 1) do: [:i | aStream next].
|
|
70 |
|
|
71 |
depth := header at: 4.
|
|
72 |
width := header at: 5.
|
|
73 |
height := header at: 6.
|
|
74 |
pad := header at: 11.
|
|
75 |
bitsPerPixel := header at: 12.
|
|
76 |
bitsPerPixel == 24 ifTrue:[
|
44
|
77 |
bitsPerSample := #(8 8 8).
|
|
78 |
samplesPerPixel := 3.
|
|
79 |
photometric := #rgb
|
42
|
80 |
] ifFalse:[
|
44
|
81 |
bitsPerSample := Array with:bitsPerPixel.
|
|
82 |
samplesPerPixel := 1.
|
|
83 |
photometric := #palette
|
42
|
84 |
].
|
|
85 |
|
|
86 |
colormapSize := header at: 19.
|
|
87 |
nColors := header at: 20.
|
|
88 |
|
44
|
89 |
colorMap := Array new:colormapSize.
|
42
|
90 |
|
|
91 |
1 to:nColors do:[:i |
|
44
|
92 |
|clr|
|
|
93 |
|
|
94 |
aStream nextLong.
|
|
95 |
clr := ColorValue scaledRed: (aStream nextWord bitShift: -3)
|
|
96 |
scaledGreen: (aStream nextWord bitShift: -3)
|
|
97 |
scaledBlue: (aStream nextWord bitShift: -3).
|
|
98 |
colorMap at:i put:clr.
|
|
99 |
aStream nextWord.
|
|
100 |
].
|
|
101 |
|
|
102 |
nColors+1 to:colormapSize do: [:i | colorMap at:i put:Color black].
|
42
|
103 |
|
44
|
104 |
bytesPerRow := width * bitsPerPixel // 8.
|
|
105 |
((width * bitsPerPixel \\ 8) ~~ 0) ifTrue:[
|
|
106 |
bytesPerRow := bytesPerRow + 1
|
|
107 |
].
|
|
108 |
srcRowByteSize := width * bitsPerPixel + pad - 1 // pad * (pad / 8).
|
42
|
109 |
|
|
110 |
data := ByteArray uninitializedNew: srcRowByteSize * height.
|
44
|
111 |
srcRowByteSize == bytesPerRow ifTrue:[
|
|
112 |
aStream nextBytes:srcRowByteSize * height into:data.
|
|
113 |
] ifFalse:[
|
|
114 |
dstIndex := 1.
|
|
115 |
1 to:height do:[:y |
|
|
116 |
aStream nextBytes:bytesPerRow into:data startingAt:dstIndex.
|
|
117 |
aStream next:(srcRowByteSize - bytesPerRow).
|
|
118 |
dstIndex := dstIndex + bytesPerRow.
|
|
119 |
].
|
|
120 |
self halt.
|
|
121 |
]
|
42
|
122 |
"
|
44
|
123 |
XWDReader fromFile:'testfile.xwd'
|
42
|
124 |
"
|
|
125 |
! !
|
|
126 |
|