fixedPalette has more functionality
authorClaus Gittinger <cg@exept.de>
Mon, 07 Jun 2004 11:22:03 +0200
changeset 4185 cc96d1c1e28c
parent 4184 1b6a082d98e2
child 4186 2ac5f5cb7944
fixedPalette has more functionality
Colormap.st
--- a/Colormap.st	Fri Jun 04 19:39:46 2004 +0200
+++ b/Colormap.st	Mon Jun 07 11:22:03 2004 +0200
@@ -223,9 +223,9 @@
     |r g b idx "{ Class: SmallInteger }" |
 
     idx := index.
-    r := redVector at:idx.
-    g := greenVector at:idx.
-    b := blueVector at:idx.
+    r := self redByteAt:idx.
+    g := self greenByteAt:idx.
+    b := self blueByteAt:idx.
 
     ^ Color redByte:r greenByte:g blueByte:b
 
@@ -244,9 +244,9 @@
     b := (aColor blue * 255 / 100) rounded.
 
     idx := index.
-    redVector at:idx put:r.
-    greenVector at:idx put:g.
-    blueVector at:idx put:b.
+    self redByteAt:idx put:r.
+    self greenByteAt:idx put:g.
+    self blueByteAt:idx put:b.
     ^ aColor
 
     "Modified: 2.5.1996 / 17:29:29 / cg"
@@ -262,9 +262,10 @@
 blueAt:index
     "return the blue component for some index.
      The returned value is scaled from the internal 0.. 255 to
-     a percentage value 0..100"
+     a percentage value 0..100.
+     Notice that index range is 1..."
 
-    ^ (blueVector at:index) * 100 / 255
+    ^ (self blueByteAt:index) * 100 / 255
 
     "Modified: 2.5.1996 / 17:29:17 / cg"
 !
@@ -302,9 +303,10 @@
 greenAt:index
     "return the green component for some index.
      The returned value is scaled from the internal 0.. 255 to
-     a percentage value 0..100"
+     a percentage value 0..100.
+     Notice that index range is 1..."
 
-    ^ (greenVector at:index) * 100 / 255
+    ^ (self greenByteAt:index) * 100 / 255
 
     "Modified: 2.5.1996 / 17:29:36 / cg"
 !
@@ -312,15 +314,31 @@
 redAt:index
     "return the red component for some index.
      The returned value is scaled from the internal 0.. 255 to
-     a percentage value 0..100"
+     a percentage value 0..100.
+     Notice that index range is 1..."
 
-    ^ (redVector at:index) * 100 / 255
+    ^ (self redByteAt:index) * 100 / 255
 
     "Modified: 2.5.1996 / 17:29:44 / cg"
 ! !
 
 !Colormap methodsFor:'accessing-internals'!
 
+blueByteAt:index
+    "return the blueByte component for some index.
+     The returned value is from the internal 0.. 255"
+
+    ^ (blueVector at:index)
+!
+
+blueByteAt:index put:anInteger
+    "change the internal blueByte component for some index.
+     The argument, anInteger should be from the internal 0.. 255.
+     Notice that index range is 1..."
+
+    ^ blueVector at:index put:anInteger
+!
+
 blueVector
     "return the blueVector"
 
@@ -335,6 +353,21 @@
     blueVector := something.
 !
 
+greenByteAt:index
+    "return the greenByte component for some index.
+     The returned value is from the internal 0.. 255"
+
+    ^ (greenVector at:index)
+!
+
+greenByteAt:index put:anInteger
+    "change the internal greenByte component for some index.
+     The argument, anInteger should be from the internal 0.. 255.
+     Notice that index range is 1..."
+
+    ^ greenVector at:index put:anInteger
+!
+
 greenVector
     "return greenVector"
 
@@ -347,6 +380,21 @@
     greenVector := something.
 !
 
+redByteAt:index
+    "return the redByte component for some index.
+     The returned value is from the internal 0.. 255"
+
+    ^ (redVector at:index)
+!
+
+redByteAt:index put:anInteger
+    "change the internal redByte component for some index.
+     The argument, anInteger should be from the internal 0.. 255.
+     Notice that index range is 1..."
+
+    ^ redVector at:index put:anInteger
+!
+
 redVector
     "return redVector"
 
@@ -377,14 +425,14 @@
     |r g b n "{ Class: SmallInteger }" 
      scale array|
 
-    n := redVector size.
+    n := self size.
     array := Array new:n.
     scale := Color scalingValue / 255.0.
 
     1 to:n do:[:idx |
-        r := redVector at:idx.
-        g := greenVector at:idx.
-        b := blueVector at:idx.
+        r := self redByteAt:idx.
+        g := self greenByteAt:idx.
+        b := self blueByteAt:idx.
 
         array at:idx put:(Color
                             scaledRed:(r * scale) rounded
@@ -417,7 +465,7 @@
 !Colormap methodsFor:'misc'!
 
 grow:howBig
-    "change the receivers size - not allowed"
+    "change the receivers size"
 
     |t|
 
@@ -432,7 +480,6 @@
     t := greenVector. greenVector := ByteArray new:howBig. greenVector replaceFrom:1 to:t size with:t startingAt:1.
     t := blueVector. blueVector := ByteArray new:howBig. blueVector replaceFrom:1 to:t size with:t startingAt:1.
     ^ self
-
 !
 
 scaleValuesBy:scaleFactor
@@ -490,6 +537,10 @@
     "Created: 6.3.1997 / 15:45:39 / cg"
 !
 
+isFixedPalette
+    ^ false
+!
+
 isGreyscaleColormap
     "return true, if the receiver is actually a greymap.
      Could be used to convert images as read from imageFiles
@@ -498,12 +549,12 @@
     |sz "{ Class: SmallInteger }"
      redVal|
 
-    sz := redVector size.
+    sz := self size.
 
     1 to:sz do:[:i |
-        redVal := redVector at:i.
-        redVal ~~ (greenVector at:i) ifTrue:[^ false].
-        redVal ~~ (blueVector at:i) ifTrue:[^ false].
+        redVal := self redByteAt:i.
+        redVal ~~ (self greenByteAt:i) ifTrue:[^ false].
+        redVal ~~ (self blueByteAt:i) ifTrue:[^ false].
     ].
     ^ true
 !
@@ -519,5 +570,5 @@
 !Colormap class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Colormap.st,v 1.37 2004-05-13 18:54:52 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Colormap.st,v 1.38 2004-06-07 09:22:03 cg Exp $'
 ! !