'From VisualWorks(R) Release 2.0 of 4 August 1994 on 1 June 1995 at 5:00:07 pm'! !GIFImageReader methodsFor: 'private'! constructGrouping: aNumber "Answer the interlace grouping array for an image aNumber pixels high" | grouping j i | grouping := Array new: height. j := 0. i := 1. [i <= height] whileTrue: [j := j + 1. grouping at: j put: i. i := i + 8]. i := 5. [i <= height] whileTrue: [j := j + 1. grouping at: j put: i. i := i + 8]. i := 3. [i <= height] whileTrue: [j := j + 1. grouping at: j put: i. i := i + 4]. i := 2. [i <= height] whileTrue: [j := j + 1. grouping at: j put: i. i := i + 2]. ^grouping! ! !GIFImageReader methodsFor: 'initialize-release'! readImageData "read next image" | len flags codeSize reader row interlace grouping y | [ioStream peek = 33] whileTrue: [ioStream next; next. [(len := ioStream next) = 0] whileFalse: [ioStream skip: len]]. ioStream peek = 59 ifTrue: [^nil]. (ioStream peekFor: 44) ifFalse: [self error: 'unknown GIF tag.']. self nextLSBUnsignedShort; nextLSBUnsignedShort. width := self nextLSBUnsignedShort. height := self nextLSBUnsignedShort. flags := ioStream next. "Is this image interlaced? If so, construct a grouping array" interlace := ((flags bitAt: 7) ~= 0). interlace ifTrue: [ grouping := self constructGrouping: height]. (flags anyMask: 128) ifTrue: [bitsPerPixel := (flags bitAnd: 7) + 1. self readPalette]. codeSize := ioStream next. reader := GIFLZWReader on: (GIFDataBlockReader on: ioStream). reader initCodeSize: codeSize+1; bitMask: palette maxIndex. self initializeImage. row := ByteArray new: width. 1 to: image height do: [:r | y := r. interlace ifTrue: [ y := grouping at: r]. y := y -1. reader next: width into: row startingAt: 1. image rowAt: y putAll: row].! !