[Pkg] The Trunk: Graphics-nice.292.mcz
commits at source.squeak.org
commits at source.squeak.org
Sat May 10 13:22:29 UTC 2014
Nicolas Cellier uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-nice.292.mcz
==================== Summary ====================
Name: Graphics-nice.292
Author: nice
Time: 10 May 2014, 3:20:49.939 pm
UUID: 2d2a1654-5de9-4d4c-9fcf-f5650bc6199b
Ancestors: Graphics-nice.291
Fix transparency when reading PNG RGB forms
- Form paint did not overwrite the background, use Form over
- the transparentPixelValue was not correctly read, fix it
- the 16 bitsPerChannel handling of transparency was not correct, fix it
=============== Diff against Graphics-nice.291 ===============
Item was changed:
----- Method: PNGReadWriter>>copyPixelsRGB: (in category 'pixel copies') -----
copyPixelsRGB: y
"Handle non-interlaced RGB color mode (colorType = 2)"
| i pixel tempForm tempBits |
(transparentPixelValue isNil and: [ bitsPerChannel = 8 ]) ifTrue: [ "Do the same trick as in #copyPixelsRGBA:"
| targetIndex |
tempBits := ByteArray new: thisScanline size * 4 // 3 withAll: 16rFF.
tempForm := Form extent: width at 1 depth: 32 bits: tempBits.
targetIndex := 1.
1 to: thisScanline size by: 3 do: [ :index |
tempBits
at: targetIndex put: (thisScanline at: index);
at: targetIndex + 1 put: (thisScanline at: index + 1);
at: targetIndex + 2 put: (thisScanline at: index + 2).
targetIndex := targetIndex + 4 ].
cachedDecoderMap
ifNil:[cachedDecoderMap := self rgbaDecoderMapForDepth: depth].
(BitBlt toForm: form)
sourceForm: tempForm;
destOrigin: 0 at y;
combinationRule: Form over;
colorMap: cachedDecoderMap;
copyBits.
^self ].
tempForm := Form extent: width at 1 depth: 32.
tempBits := tempForm bits.
pixel := LargePositiveInteger new: 4.
pixel at: 4 put: 16rFF.
+ bitsPerChannel = 8
+ ifTrue:
+ [i := 1.
+ 1 to: width do:
+ [ :x |
+ pixel
+ at: 3 put: (thisScanline at: i);
+ at: 2 put: (thisScanline at: i+1);
+ at: 1 put: (thisScanline at: i+2).
+ tempBits at: x put: pixel.
+ i := i + 3].
+ transparentPixelValue
+ ifNotNil:
+ [1 to: width do: [ :x |
+ (tempBits at: x) = transparentPixelValue
+ ifTrue: [tempBits at: x put: 0]]]]
+ ifFalse:
+ [i := 1.
+ 1 to: width do:
+ [ :x |
+ (transparentPixelValue == nil or: [(1 to: 6) anySatisfy: [:k | (transparentPixelValue digitAt: k) ~= (thisScanline at: i + 6 - k)]])
+ ifTrue:
+ [pixel
+ at: 3 put: (thisScanline at: i);
+ at: 2 put: (thisScanline at: i+2);
+ at: 1 put: (thisScanline at: i+4).
+ tempBits at: x put: pixel]
+ ifFalse:
+ [tempBits at: x put: 0].
+ i := i + 6]].
+
+ tempForm displayOn: form at: 0 at y rule: Form over.
- bitsPerChannel = 8 ifTrue: [
- i := 1.
- 1 to: width do: [ :x |
- pixel
- at: 3 put: (thisScanline at: i);
- at: 2 put: (thisScanline at: i+1);
- at: 1 put: (thisScanline at: i+2).
- tempBits at: x put: pixel.
- i := i + 3.
- ]
- ] ifFalse: [
- i := 1.
- 1 to: width do: [ :x |
- pixel
- at: 3 put: (thisScanline at: i);
- at: 2 put: (thisScanline at: i+2);
- at: 1 put: (thisScanline at: i+4).
- tempBits at: x put: pixel.
- i := i + 6.
- ]
- ].
- transparentPixelValue ifNotNil: [
- 1 to: width do: [ :x |
- (tempBits at: x) = transparentPixelValue ifTrue: [
- tempBits at: x put: 0.
- ].
- ].
- ].
- tempForm displayOn: form at: 0 at y rule: Form paint.
!
Item was changed:
----- Method: PNGReadWriter>>copyPixelsRGB:at:by: (in category 'pixel copies') -----
copyPixelsRGB: y at: startX by: incX
"Handle interlaced RGB color mode (colorType = 2)"
| i pixel tempForm tempBits xx loopsToDo |
tempForm := Form extent: width at 1 depth: 32.
tempBits := tempForm bits.
pixel := LargePositiveInteger new: 4.
pixel at: 4 put: 16rFF.
loopsToDo := width - startX + incX - 1 // incX.
+ bitsPerChannel = 8
+ ifTrue:
+ [i := (startX // incX * 3) + 1.
+ xx := startX+1.
+ 1 to: loopsToDo do:
+ [ :j |
+ pixel
+ at: 3 put: (thisScanline at: i);
+ at: 2 put: (thisScanline at: i+1);
+ at: 1 put: (thisScanline at: i+2).
+ tempBits at: xx put: pixel.
+ i := i + 3.
+ xx := xx + incX].
+ transparentPixelValue
+ ifNotNil: [startX to: width-1 by: incX do: [ :x |
+ (tempBits at: x+1) = transparentPixelValue
+ ifTrue: [ tempBits at: x+1 put: 0]]]]
+ ifFalse:
+ [i := (startX // incX * 6) + 1.
+ xx := startX+1.
+ 1 to: loopsToDo do:
+ [ :j |
+ (transparentPixelValue == nil or: [(1 to: 6) anySatisfy: [:k | (transparentPixelValue digitAt: k) ~= (thisScanline at: i + 6 - k)]])
+ ifTrue:
+ [pixel
+ at: 3 put: (thisScanline at: i);
+ at: 2 put: (thisScanline at: i+2);
+ at: 1 put: (thisScanline at: i+4).
+ tempBits at: xx put: pixel.]
+ ifFalse:
+ [tempBits at: xx put: 0].
+ i := i + 6.
+ xx := xx + incX]].
+ tempForm displayOn: form at: 0 at y rule: Form over.
- bitsPerChannel = 8 ifTrue: [
- i := (startX // incX * 3) + 1.
- xx := startX+1.
- 1 to: loopsToDo do: [ :j |
- pixel
- at: 3 put: (thisScanline at: i);
- at: 2 put: (thisScanline at: i+1);
- at: 1 put: (thisScanline at: i+2).
- tempBits at: xx put: pixel.
- i := i + 3.
- xx := xx + incX.
- ]
- ] ifFalse: [
- i := (startX // incX * 6) + 1.
- xx := startX+1.
- 1 to: loopsToDo do: [ :j |
- pixel
- at: 3 put: (thisScanline at: i);
- at: 2 put: (thisScanline at: i+2);
- at: 1 put: (thisScanline at: i+4).
- tempBits at: xx put: pixel.
- i := i + 6.
- xx := xx + incX.
- ].
- ].
- transparentPixelValue ifNotNil: [
- startX to: width-1 by: incX do: [ :x |
- (tempBits at: x+1) = transparentPixelValue ifTrue: [
- tempBits at: x+1 put: 0.
- ].
- ].
- ].
- tempForm displayOn: form at: 0 at y rule: Form paint.
!
Item was changed:
----- Method: PNGReadWriter>>processTransparencyChunk (in category 'chunks') -----
processTransparencyChunk
- | red green blue |
-
"Transcript show: ' TRANSPARENCY ',chunk printString."
+ colorType = 0
+ ifTrue:
+ [transparentPixelValue := chunk unsignedShortAt: 1 bigEndian: true.
+ bitsPerChannel <= 8
+ ifTrue: [palette at: transparentPixelValue + 1 put: Color transparent]
+ ifFalse: [palette at: 1 put: Color transparent].
+ ^self].
+ colorType = 2
+ ifTrue:
+ [| red green blue |
+ red := chunk unsignedShortAt: 1 bigEndian: true.
+ green := chunk unsignedShortAt: 3 bigEndian: true.
+ blue := chunk unsignedShortAt: 5 bigEndian: true.
+ transparentPixelValue := bitsPerChannel <= 8
+ ifTrue: [16rFF00 + red << 8 + green << 8 + blue]
+ ifFalse: [red << 16 + green << 16 + blue].
+ ^self].
+ colorType = 3
+ ifTrue:
+ [chunk withIndexDo: [ :alpha :index |
+ palette at: index put: ((palette at: index) alpha: alpha/255)].
+ ^self].
- colorType = 0 ifTrue: [
- transparentPixelValue := chunk unsignedShortAt: 1 bigEndian: true.
- bitsPerChannel <= 8
- ifTrue: [palette at: transparentPixelValue + 1 put: Color transparent]
- ifFalse: [palette at: 1 put: Color transparent].
- ^self
- ].
- colorType = 2 ifTrue: [
- red := chunk at: 2.
- green := chunk at: 2.
- blue := chunk at: 2.
- transparentPixelValue := 16rFF00 + red << 8 + green << 8 + blue.
- ^self
- ].
- colorType = 3 ifTrue: [
- chunk withIndexDo: [ :alpha :index |
- palette at: index put: ((palette at: index) alpha: alpha/255)
- ].
- ^self
- ].
!
More information about the Packages
mailing list