Levente Uzonyi uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-ul.175.mcz ==================== Summary ==================== Name: Graphics-ul.175 Author: ul Time: 9 January 2011, 3:01:23.719 pm UUID: ecdffa9c-6063-d44c-9c86-ac5387806de3 Ancestors: Graphics-cmm.174 - a naive fix for PNGReadWriterTest >> #testGrayScale =============== Diff against Graphics-cmm.174 =============== Item was changed: ----- Method: PNGReadWriter>>copyPixelsGray: (in category 'pixel copies') ----- copyPixelsGray: y "Handle non-interlaced grayscale color mode (colorType = 0)" + | base bits bytesLeft word | - | 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 Smalltalk version might be easier to understand than the others below." base := y * form width * bitsPerChannel // 32 + 1. bits := form bits. + 0 to: thisScanline size // 4 - 1 do: [ :i | + | ii | - 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 ]. + (bytesLeft := thisScanline size bitAnd: 3) = 0 ifFalse: [ + word := 0. + thisScanline size - bytesLeft + 1 to: thisScanline size do: [ :ii | + word := word * 256 + (thisScanline at: ii) ]. + word := word bitShift: 8 * (4 - bytesLeft). + bits at: base + (thisScanline size // 4) put: word ]. + - "This interesting technique (By Andreas Raab) is faster for very large images, but might be slower for small ones" "^self copyPixelsGrayWeirdBitBltHack: y ". "It uses the following method: PNGReadWriter >> copyPixelsGrayWeirdBitBltHack: y ""Handle non-interlaced black and white color mode (colorType = 0) By Andreas Raab"" | source dest cmap | source := Form extent: 1 @ (thisScanline size // 4) depth: 32 bits: thisScanline. dest := Form extent: 1 @ (form bits size) depth: 32 bits: form bits. cmap := Smalltalk isLittleEndian ifTrue:[ColorMap shifts: #(-24 -8 8 24) masks: #(16rFF000000 16r00FF0000 16r0000FF00 16r000000FF)]. (BitBlt toForm: dest) sourceForm: source; destX: 0 destY: (y * form width*bitsPerChannel//32) width: 1 height: (form width+31*bitsPerChannel//32); colorMap: cmap; combinationRule: 3; copyBits." "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)". "It uses the following method: BitMap >> copyFromByteArray2: byteArray to: i ""This method should work with either byte orderings"" | myHack byteHack | myHack := Form new hackBits: self. byteHack := Form new hackBits: byteArray. Smalltalk isLittleEndian ifTrue: [byteHack swapEndianness]. byteHack displayOn: myHack at: 0@i"! |
Free forum by Nabble | Edit this page |