--- a/Color.st Tue Aug 29 20:01:09 2017 +0200
+++ b/Color.st Tue Aug 29 20:08:35 2017 +0200
@@ -3716,27 +3716,32 @@
(segments size < numColors) ifTrue:[
segmentColors := segments
collect:[:eachSegment |
- |n sumRed sumGreen sumBlue centerRed centerGreen centerBlue|
+ |sumWeight sumRed sumGreen sumBlue centerRed centerGreen centerBlue|
"/ compute central point
"/ as center of mass (taking count per box as weight)
"/ this central point will be placed into the colormap.
sumRed := sumGreen := sumBlue := 0.
- n := eachSegment size.
-
+
+ sumWeight := 0.
eachSegment do:[:rgbOfBoxInSegment |
- |r g b|
+ |r g b idx count|
r := (rgbOfBoxInSegment rightShift:(numBits+numBits)) bitAnd:boxMax.
g := (rgbOfBoxInSegment rightShift:numBits) bitAnd:boxMax.
b := (rgbOfBoxInSegment) bitAnd:boxMax.
- sumRed :=sumRed + r.
+
+ idx := (((r * (boxMax+1))+g)*(boxMax+1))+b+1.
+ count := bigCube at:idx.
+
+ sumRed := sumRed + r.
sumGreen := sumGreen + g.
sumBlue := sumBlue + b.
+ sumWeight := sumWeight + count.
].
- centerRed := (sumRed / n) rounded.
- centerGreen := (sumGreen / n) rounded.
- centerBlue := (sumBlue / n) rounded.
+ centerRed := (sumRed / sumWeight) rounded.
+ centerGreen := (sumGreen / sumWeight) rounded.
+ centerBlue := (sumBlue / sumWeight) rounded.
centerRed := (centerRed bitShift:(8-numBits))
bitOr:(centerRed bitShift:(8-numBits-numBits)).
@@ -3790,7 +3795,7 @@
"
"Created: / 29-08-2017 / 14:31:19 / cg"
- "Modified (comment): / 29-08-2017 / 20:00:32 / cg"
+ "Modified: / 29-08-2017 / 20:04:36 / cg"
!
browserColors