The Trunk: Graphics-eem.321.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Graphics-eem.321.mcz

commits-2
Eliot Miranda uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-eem.321.mcz

==================== Summary ====================

Name: Graphics-eem.321
Author: eem
Time: 16 January 2016, 9:43:19.481889 am
UUID: 63221468-923b-4e2d-a262-1fb47958bb0c
Ancestors: Graphics-eem.320

Rewrite Color>>pixelValueForDepth: to avoid need for normalization and for creating 4-byte LargeIntegers in 64-bits.

=============== Diff against Graphics-eem.320 ===============

Item was changed:
  ----- Method: Color>>pixelValueForDepth: (in category 'conversions') -----
  pixelValueForDepth: d
+ "Answers 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
+ answer 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."
- "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 |
+ d > 8 ifTrue: "most common case"
+ [d = 32 ifTrue: "eight bits per component; top 8 bits set to all ones (opaque alpha)"
+ ["this subexpression is a SmallInteger in both 32- and 64-bits."
+ val := ((rgb bitShift: -6) bitAnd: 16rFF0000) bitOr:
+ (((rgb bitShift: -4) bitAnd: 16rFF00) bitOr:
+ ((rgb bitShift: -2) bitAnd: 16rFF)).
+ "16rFF000000 & 16rFF000001 are LargeIntegers in 32-bits, SmallIntegers in 64-bits."
+ ^val = 0 ifTrue: [16rFF000001] ifFalse: [16rFF000000 + val]].
+
+ d = 16 ifTrue: "five bits per component; top bits ignored"
+ [val := (((rgb bitShift: -15) bitAnd: 16r7C00) bitOr:
- d > 8 "most common case"
- ifTrue:
- [d = 32 ifTrue: [
- "eight bits per component; top 8 bits set to all ones (opaque alpha)"
- val := (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]].
-
- 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 = 0 ifTrue: [1] ifFalse: [val]].
- ^val < 1 ifTrue: [1] ifFalse: [val]].
 
+ d = 12 ifTrue: "for indexing a color map with 4 bits per color component"
+ [val := (((rgb bitShift: -18) bitAnd: 16r0F00) bitOr:
- 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 = 0 ifTrue: [1] ifFalse: [val]].
- ^val < 1 ifTrue: [1] ifFalse: [val]].
 
+ 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 = 0 ifTrue: [1] ifFalse: [val]]].
- 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]]].
  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
  !