102 |
102 |
103 !GIFReader methodsFor:'reading from file'! |
103 !GIFReader methodsFor:'reading from file'! |
104 |
104 |
105 readColorMap:colorMapSize |
105 readColorMap:colorMapSize |
106 "get gif colormap consisting of colorMapSize entries" |
106 "get gif colormap consisting of colorMapSize entries" |
|
107 |
|
108 |sz "{ Class: SmallInteger }"| |
107 |
109 |
108 "/ redMap := Array new:colorMapSize. |
110 "/ redMap := Array new:colorMapSize. |
109 "/ greenMap := Array new:colorMapSize. |
111 "/ greenMap := Array new:colorMapSize. |
110 "/ blueMap := Array new:colorMapSize. |
112 "/ blueMap := Array new:colorMapSize. |
111 redMap := ByteArray uninitializedNew:colorMapSize. |
113 redMap := ByteArray uninitializedNew:colorMapSize. |
112 greenMap := ByteArray uninitializedNew:colorMapSize. |
114 greenMap := ByteArray uninitializedNew:colorMapSize. |
113 blueMap := ByteArray uninitializedNew:colorMapSize. |
115 blueMap := ByteArray uninitializedNew:colorMapSize. |
114 1 to:colorMapSize do:[:i | |
116 sz := colorMapSize. |
|
117 1 to:sz do:[:i | |
115 redMap at:i put:(inStream nextByte). |
118 redMap at:i put:(inStream nextByte). |
116 greenMap at:i put:(inStream nextByte). |
119 greenMap at:i put:(inStream nextByte). |
117 blueMap at:i put:(inStream nextByte) |
120 blueMap at:i put:(inStream nextByte) |
118 ] |
121 ] |
119 ! |
122 ! |
144 |byte index flag count |
147 |byte index flag count |
145 colorMapSize bitsPerPixel scrWidth scrHeight |
148 colorMapSize bitsPerPixel scrWidth scrHeight |
146 hasColorMap hasLocalColorMap interlaced id |
149 hasColorMap hasLocalColorMap interlaced id |
147 leftOffs topOffs codeLen |
150 leftOffs topOffs codeLen |
148 compressedData compressedSize |
151 compressedData compressedSize |
149 tmp srcOffset dstOffset| |
152 tmp srcOffset dstOffset |
|
153 h "{ Class: SmallInteger }"| |
150 |
154 |
151 inStream := aStream. |
155 inStream := aStream. |
152 aStream binary. |
156 aStream binary. |
153 |
157 |
154 "GIF-files are always lsb (intel-world)" |
158 "GIF-files are always lsb (intel-world)" |
256 tmp := ByteArray new:(data size). |
261 tmp := ByteArray new:(data size). |
257 |
262 |
258 "phase 1: 0, 8, 16, 24, ..." |
263 "phase 1: 0, 8, 16, 24, ..." |
259 |
264 |
260 srcOffset := 1. |
265 srcOffset := 1. |
261 0 to:(height - 1) by:8 do:[:dstRow | |
266 0 to:(h - 1) by:8 do:[:dstRow | |
262 dstOffset := dstRow * width + 1. |
267 dstOffset := dstRow * width + 1. |
263 tmp replaceFrom:dstOffset to:(dstOffset + width - 1) |
268 tmp replaceFrom:dstOffset to:(dstOffset + width - 1) |
264 with:data startingAt:srcOffset. |
269 with:data startingAt:srcOffset. |
265 srcOffset := srcOffset + width. |
270 srcOffset := srcOffset + width. |
266 ]. |
271 ]. |
267 |
272 |
268 "phase 2: 4, 12, 20, 28, ..." |
273 "phase 2: 4, 12, 20, 28, ..." |
269 |
274 |
270 4 to:(height - 1) by:8 do:[:dstRow | |
275 4 to:(h - 1) by:8 do:[:dstRow | |
271 dstOffset := dstRow * width + 1. |
276 dstOffset := dstRow * width + 1. |
272 tmp replaceFrom:dstOffset to:(dstOffset + width - 1) |
277 tmp replaceFrom:dstOffset to:(dstOffset + width - 1) |
273 with:data startingAt:srcOffset. |
278 with:data startingAt:srcOffset. |
274 srcOffset := srcOffset + width. |
279 srcOffset := srcOffset + width. |
275 ]. |
280 ]. |
276 |
281 |
277 "phase 3: 2, 6, 10, 14, ..." |
282 "phase 3: 2, 6, 10, 14, ..." |
278 |
283 |
279 2 to:(height - 1) by:4 do:[:dstRow | |
284 2 to:(h - 1) by:4 do:[:dstRow | |
280 dstOffset := dstRow * width + 1. |
285 dstOffset := dstRow * width + 1. |
281 tmp replaceFrom:dstOffset to:(dstOffset + width - 1) |
286 tmp replaceFrom:dstOffset to:(dstOffset + width - 1) |
282 with:data startingAt:srcOffset. |
287 with:data startingAt:srcOffset. |
283 srcOffset := srcOffset + width. |
288 srcOffset := srcOffset + width. |
284 ]. |
289 ]. |
285 |
290 |
286 "phase 4: 1, 3, 5, 7, ..." |
291 "phase 4: 1, 3, 5, 7, ..." |
287 |
292 |
288 1 to:(height - 1) by:2 do:[:dstRow | |
293 1 to:(h - 1) by:2 do:[:dstRow | |
289 dstOffset := dstRow * width + 1. |
294 dstOffset := dstRow * width + 1. |
290 tmp replaceFrom:dstOffset to:(dstOffset + width - 1) |
295 tmp replaceFrom:dstOffset to:(dstOffset + width - 1) |
291 with:data startingAt:srcOffset. |
296 with:data startingAt:srcOffset. |
292 srcOffset := srcOffset + width. |
297 srcOffset := srcOffset + width. |
293 ]. |
298 ]. |