'From Squeak4.1beta of 15 April 2010 [latest update: #9972] on 15 April 2010 at 6:23:23 pm'! !PNGReadWriter methodsFor: 'pixel copies' stamp: 'ul 4/15/2010 18:19'! copyPixelsGray: y "Handle non-interlaced grayscale color mode (colorType = 0)" | base bits | bitsPerChannel = 16 ifTrue: [ "Warning: This is extremely slow. Besides we are downsampling to 8 bits!!" | blitter | blitter := BitBlt current bitPokerToForm: form. 0 to: width - 1 do: [ :x | blitter pixelAt: x @ y put: 255 - (thisScanline at: x * 2 + 1) ]. ^self ]. "Just copy the bits" "This interesting technique (By Andreas Raab) is faster for very large images, but might be slower for small ones" "^self copyPixelsGrayWeirdBitBltHack: y ". "This interesting technique (By Yoshiki Ohshima) is faster for very large images, but might be slower for small ones" "form bits copyFromByteArray2: thisScanline to: y * (form width* bitsPerChannel // 32)". "This Smalltalk version might be easier to understand" base := y * form width * bitsPerChannel // 32 + 1. bits := form bits. 0 to: thisScanline size - 1 // 4 do: [ :i | | ii word | ii := i * 4. "This somewhat weird mixture of (#* and #+) with (#bitShift: and #bitOr:) is to make use of faster arithmetic bytecodes, but not of slow largeintegers." word := (((thisScanline at: ii + 1) * 256 + (thisScanline at: ii + 2) * 256 + (thisScanline at: ii + 3)) bitShift: 8) bitOr: (thisScanline at: ii + 4). bits at: base + i put: word ].! !