class: Colormap
authorClaus Gittinger <cg@exept.de>
Tue, 04 Mar 2014 23:17:24 +0100
changeset 6307 e2c71f8b5878
parent 6306 a3bbe514829e
child 6308 6e4008b97f64
class: Colormap added: #at:putRGB: #at:putRGBTriple:
Colormap.st
--- a/Colormap.st	Sun Mar 02 15:39:22 2014 +0100
+++ b/Colormap.st	Tue Mar 04 23:17:24 2014 +0100
@@ -251,6 +251,39 @@
     "Modified: / 22-07-2007 / 15:28:32 / cg"
 !
 
+at:index putRGB:rgbValue
+    "set the color for an index, given rrggbb as an integer (8bits each, red in high bits).
+     Notice that the index range is 1..."
+
+    |r g b idx "{ Class: SmallInteger }" |
+
+    r := (rgbValue bitShift:-16) bitAnd:16rFF.
+    g := (rgbValue bitShift:-8) bitAnd:16rFF.
+    b := rgbValue bitAnd:16rFF.
+
+    idx := index.
+    self redByteAt:idx put:r.
+    self greenByteAt:idx put:g.
+    self blueByteAt:idx put:b.
+!
+
+at:index putRGBTriple:aTriple
+    "set the color for an index from an rgb triple.
+     The components are r,g,b; each 0..1.
+     Notice that the index range is 1..."
+
+    |r g b idx "{ Class: SmallInteger }" |
+
+    r := ((aTriple at:1) * 255) rounded.
+    g := ((aTriple at:2) * 255) rounded.
+    b := ((aTriple at:3) * 255) rounded.
+
+    idx := index.
+    self redByteAt:idx put:(r max:0).
+    self greenByteAt:idx put:(g max:0).
+    self blueByteAt:idx put:(b max:0).
+!
+
 atPixelValue:pixelValue 
     "return the color for a pixelValue. 
      Notice that pixelValue range is 0...nColors-1"
@@ -578,6 +611,6 @@
 !Colormap class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Colormap.st,v 1.41 2013-11-05 11:31:53 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Colormap.st,v 1.42 2014-03-04 22:17:24 cg Exp $'
 ! !