equal
deleted
inserted
replaced
14 XWDReader>>save:onFile: |
14 XWDReader>>save:onFile: |
15 which was written by Brad Schoening <brad@boole.com> |
15 which was written by Brad Schoening <brad@boole.com> |
16 who placed it into the public domain. |
16 who placed it into the public domain. |
17 " |
17 " |
18 |
18 |
|
19 "{ Package: 'stx:libview2' }" |
|
20 |
19 ImageReader subclass:#XWDReader |
21 ImageReader subclass:#XWDReader |
20 instanceVariableNames:'' |
22 instanceVariableNames:'' |
21 classVariableNames:'' |
23 classVariableNames:'' |
22 poolDictionaries:'' |
24 poolDictionaries:'' |
23 category:'Graphics-Images-Support' |
25 category:'Graphics-Images-Support' |
80 ^ true |
82 ^ true |
81 ! ! |
83 ! ! |
82 |
84 |
83 !XWDReader methodsFor:'image reading'! |
85 !XWDReader methodsFor:'image reading'! |
84 |
86 |
85 fromStream:aStream |
87 readImage |
86 "read an image in XWD (X Window Dump) format from aStream." |
88 "read an image in XWD (X Window Dump) format from my inStream." |
87 |
89 |
88 |header nColors pad |
90 |header nColors pad |
89 srcRowByteSize bytesPerRow bitsPerPixel colormapSize depth |
91 srcRowByteSize bytesPerRow bitsPerPixel colormapSize depth |
90 dstIndex| |
92 dstIndex| |
91 |
93 |
92 aStream binary. |
94 inStream binary. |
93 |
95 |
94 header := (1 to: 25) collect: [:i | aStream nextLong]. |
96 header := (1 to: 25) collect: [:i | inStream nextLong]. |
95 |
97 |
96 "skip ..." |
98 "skip ..." |
97 101 to:(header at: 1) do: [:i | aStream next]. |
99 101 to:(header at: 1) do: [:i | inStream next]. |
98 |
100 |
99 depth := header at: 4. |
101 depth := header at: 4. |
100 width := header at: 5. |
102 width := header at: 5. |
101 height := header at: 6. |
103 height := header at: 6. |
102 pad := header at: 11. |
104 pad := header at: 11. |
119 colorMap := Array new:colormapSize. |
121 colorMap := Array new:colormapSize. |
120 |
122 |
121 1 to:nColors do:[:i | |
123 1 to:nColors do:[:i | |
122 |clr r g b| |
124 |clr r g b| |
123 |
125 |
124 aStream nextLong. |
126 inStream nextLong. |
125 r := aStream nextUnsignedShortMSB:true. |
127 r := inStream nextUnsignedShortMSB:true. |
126 g := aStream nextUnsignedShortMSB:true. |
128 g := inStream nextUnsignedShortMSB:true. |
127 b := aStream nextUnsignedShortMSB:true. |
129 b := inStream nextUnsignedShortMSB:true. |
128 clr := ColorValue scaledRed: (r bitShift: -3) |
130 clr := ColorValue scaledRed: (r bitShift: -3) |
129 scaledGreen: (g bitShift: -3) |
131 scaledGreen: (g bitShift: -3) |
130 scaledBlue: (b bitShift: -3). |
132 scaledBlue: (b bitShift: -3). |
131 colorMap at:i put:clr. |
133 colorMap at:i put:clr. |
132 aStream nextWord. |
134 inStream nextWord. |
133 ]. |
135 ]. |
134 |
136 |
135 nColors+1 to:colormapSize do: [:i | colorMap at:i put:Color black]. |
137 nColors+1 to:colormapSize do: [:i | colorMap at:i put:Color black]. |
136 |
138 |
137 bytesPerRow := width * bitsPerPixel // 8. |
139 bytesPerRow := width * bitsPerPixel // 8. |
140 ]. |
142 ]. |
141 srcRowByteSize := width * bitsPerPixel + pad - 1 // pad * (pad / 8). |
143 srcRowByteSize := width * bitsPerPixel + pad - 1 // pad * (pad / 8). |
142 |
144 |
143 data := ByteArray uninitializedNew: srcRowByteSize * height. |
145 data := ByteArray uninitializedNew: srcRowByteSize * height. |
144 srcRowByteSize == bytesPerRow ifTrue:[ |
146 srcRowByteSize == bytesPerRow ifTrue:[ |
145 aStream nextBytes:srcRowByteSize * height into:data. |
147 inStream nextBytes:srcRowByteSize * height into:data. |
146 ] ifFalse:[ |
148 ] ifFalse:[ |
147 dstIndex := 1. |
149 dstIndex := 1. |
148 1 to:height do:[:y | |
150 1 to:height do:[:y | |
149 aStream nextBytes:bytesPerRow into:data startingAt:dstIndex. |
151 inStream nextBytes:bytesPerRow into:data startingAt:dstIndex. |
150 aStream next:(srcRowByteSize - bytesPerRow). |
152 inStream next:(srcRowByteSize - bytesPerRow). |
151 dstIndex := dstIndex + bytesPerRow. |
153 dstIndex := dstIndex + bytesPerRow. |
152 ]. |
154 ]. |
153 ] |
155 ] |
|
156 |
154 " |
157 " |
155 XWDReader fromFile:'testfile.xwd' |
158 XWDReader fromFile:'testfile.xwd' |
156 " |
159 " |
157 " |
160 " |
158 XWDReader save:(Image fromUser) onFile: '/tmp/st.xwd' |
161 XWDReader save:(Image fromUser) onFile: '/tmp/st.xwd' |
294 ! ! |
297 ! ! |
295 |
298 |
296 !XWDReader class methodsFor:'documentation'! |
299 !XWDReader class methodsFor:'documentation'! |
297 |
300 |
298 version |
301 version |
299 ^ '$Header: /cvs/stx/stx/libview2/XWDReader.st,v 1.21 1997-06-30 20:56:45 cg Exp $' |
302 ^ '$Header: /cvs/stx/stx/libview2/XWDReader.st,v 1.22 2003-04-04 17:07:10 cg Exp $' |
300 ! ! |
303 ! ! |
|
304 |
301 XWDReader initialize! |
305 XWDReader initialize! |