[squeak-dev] The Trunk: Graphics-nice.283.mcz
commits at source.squeak.org
commits at source.squeak.org
Fri Dec 20 15:47:30 UTC 2013
Nicolas Cellier uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-nice.283.mcz
==================== Summary ====================
Name: Graphics-nice.283
Author: nice
Time: 20 December 2013, 4:44:38.963 pm
UUID: 9c1ca167-6d02-42ea-a0e5-f16543358768
Ancestors: Graphics-nice.282
Oups, fix my recent breakage of Color>>pixelValueForDepth: it was not at all obvious to factor out the minimum pixel value.
=============== Diff against Graphics-nice.282 ===============
Item was changed:
----- Method: Color>>pixelValueForDepth: (in category 'conversions') -----
pixelValueForDepth: d
"Returns an integer representing the bits that appear in a single pixel of this color in a Form of the given depth. The depth must be one of 1, 2, 4, 8, 16, or 32. Contrast with pixelWordForDepth: and bitPatternForDepth:, which return either a 32-bit word packed with the given pixel value or a multiple-word Bitmap containing a pattern. The inverse is the class message colorFromPixelValue:depth:"
"Details: For depths of 8 or less, the result is a colorMap index. For depths of 16 and 32, it is a direct color value with 5 or 8 bits per color component."
"Transparency: The pixel value zero is reserved for transparent. For depths greater than 8, black maps to the darkest possible blue."
+ | val |
- | rgbVal |
d > 8 "most common case"
+ ifTrue:
+ [d = 32 ifTrue: [
- ifTrue:
- [rgbVal := rgb = 0
- ifTrue: [1] "closest black that is not transparent in RGB"
- ifFalse: [rgb].
-
- d = 32 ifTrue: [
"eight bits per component; top 8 bits set to all ones (opaque alpha)"
+ val := (LargePositiveInteger new: 4)
- ^(LargePositiveInteger new: 4)
at: 4 put: 16rFF;
+ at: 3 put: ((rgb bitShift: -22) bitAnd: 16rFF);
+ at: 2 put: ((rgb bitShift: -12) bitAnd: 16rFF);
+ at: 1 put: ((rgb bitShift: -2) bitAnd: 16rFF);
+ normalize. "normalize is not necessary as long as SmallInteger maxVal highBit < 32, but let's be future proof"
+ ^val < 16rFF000001 ifTrue: [16rFF000001] ifFalse: [val]].
- at: 3 put: ((rgbVal bitShift: -22) bitAnd: 16rFF);
- at: 2 put: ((rgbVal bitShift: -12) bitAnd: 16rFF);
- at: 1 put: ((rgbVal bitShift: -2) bitAnd: 16rFF);
- normalize "normalize is not necessary as long as SmallInteger maxVal highBit < 32, but let's be future proof"].
d = 16 ifTrue: [
"five bits per component; top bits ignored"
+ val := (((rgb bitShift: -15) bitAnd: 16r7C00) bitOr:
+ ((rgb bitShift: -10) bitAnd: 16r03E0)) bitOr:
+ ((rgb bitShift: -5) bitAnd: 16r001F).
+ ^val < 1 ifTrue: [1] ifFalse: [val]].
- ^(((rgbVal bitShift: -15) bitAnd: 16r7C00) bitOr:
- ((rgbVal bitShift: -10) bitAnd: 16r03E0)) bitOr:
- ((rgbVal bitShift: -5) bitAnd: 16r001F)].
d = 12 ifTrue: [ "for indexing a color map with 4 bits per color component"
+ val := (((rgb bitShift: -18) bitAnd: 16r0F00) bitOr:
+ ((rgb bitShift: -12) bitAnd: 16r00F0)) bitOr:
+ ((rgb bitShift: -6) bitAnd: 16r000F).
+ ^val < 1 ifTrue: [1] ifFalse: [val]].
- ^(((rgbVal bitShift: -18) bitAnd: 16r0F00) bitOr:
- ((rgbVal bitShift: -12) bitAnd: 16r00F0)) bitOr:
- ((rgbVal bitShift: -6) bitAnd: 16r000F)].
d = 9 ifTrue: [ "for indexing a color map with 3 bits per color component"
+ val := (((rgb bitShift: -21) bitAnd: 16r01C0) bitOr:
+ ((rgb bitShift: -14) bitAnd: 16r0038)) bitOr:
+ ((rgb bitShift: -7) bitAnd: 16r0007).
+ ^val < 1 ifTrue: [1] ifFalse: [val]]].
- ^(((rgbVal bitShift: -21) bitAnd: 16r01C0) bitOr:
- ((rgbVal bitShift: -14) bitAnd: 16r0038)) bitOr:
- ((rgbVal bitShift: -7) bitAnd: 16r0007)]].
d = 8 ifTrue: [^ self closestPixelValue8].
d = 4 ifTrue: [^ self closestPixelValue4].
d = 2 ifTrue: [^ self closestPixelValue2]..
d = 1 ifTrue: [^ self closestPixelValue1].
self error: 'unknown pixel depth: ', d printString
!
More information about the Squeak-dev
mailing list
|