Update of /cvsroot/freenet/freenet/src/freenet/support/graph
In directory sc8-pr-cvs1:/tmp/cvs-serv24380/src/freenet/support/graph

Modified Files:
        Color.java 
Log Message:
Added color operations 'add' and 'subract'

Index: Color.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/support/graph/Color.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -r1.3 -r1.4
--- Color.java  30 Oct 2003 13:09:58 -0000      1.3
+++ Color.java  3 Nov 2003 15:23:59 -0000       1.4
@@ -19,6 +19,17 @@
         b = (byte) blue;
     }
     
+    public void subtract(Color other){
+       r = (byte)Math.max(0,getRedAsInt()-other.getRedAsInt());
+               g = (byte)Math.max(0,getGreenAsInt()-other.getGreenAsInt());
+               b = (byte)Math.max(0,getBlueAsInt()-other.getBlueAsInt());
+    }
+       public void add(Color other){
+               r = (byte)Math.min(255,getRedAsInt()+other.getRedAsInt());
+               g = (byte)Math.min(255,getGreenAsInt()+other.getGreenAsInt());
+               b = (byte)Math.min(255,getBlueAsInt()+other.getBlueAsInt());
+       }
+    
     /**
      * get the color value as a an int, in the blue-green-red-reserved format
      * used by windows DIB pallettes
@@ -55,16 +66,26 @@
        if(o instanceof Color) {
            Color c = (Color)o;
            return r == c.r && g == c.g && b == c.b;
-       } else return false;
+               } else
+                       return false;
+       }
+    public int getRedAsInt(){
+       return (int)(r & 0xFF);
+    }
+       public int getGreenAsInt(){
+       return (int)(g & 0xFF);
+       }
+       public int getBlueAsInt(){
+               return (int)(b & 0xFF);
     }
     public String toHexString(){
-       String sr = Integer.toHexString((int)(r & 0xFF));
+       String sr = Integer.toHexString(getRedAsInt());
        if(sr.length() == 1)
                sr = "0"+sr;
-               String sg = Integer.toHexString((int)(g & 0xFF));
+               String sg = Integer.toHexString(getGreenAsInt());
                if(sg.length() == 1)
                        sg = "0"+sg;
-               String sb = Integer.toHexString((int)(b & 0xFF));
+               String sb = Integer.toHexString(getBlueAsInt());
                if(sb.length() == 1)
                        sb = "0"+sb;
        return sr+sg+sb;

_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to