This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: java.awt.image.ColorModel normalize/denormalize scaling error


In attempting to get non-24-bit displays to show the right colors with xlib,
I discovered that the getUnnormalizedComponents and getNormalizedComponents
methods in java.awt.image.ColorModel generate or expect one too many bits.
I have not extensively tested the change, but my colors look about right now
when using these functions, and debug printouts show, for example, 0-255
values when I'm using 8-bits per color.  My patch is against release 3.2.1
(sorry).

Index: libjava/ChangeLog
from  Scott Gilbertson  <scottg@mantatest.com>

 * java/awt/image/ColorModel.java (getUnnormalizedComponents and
getNormalizedComponents): fix calculation which
    was using one too many bits in the unnormalized format.

diff -r -up gcc.orig/libjava/java/awt/image/ColorModel.java
gcc/libjava/java/awt/image/ColorModel.java
--- gcc.orig/libjava/java/awt/image/ColorModel.java 2002-11-19
16:52:25.000000000 -0500
+++ gcc/libjava/java/awt/image/ColorModel.java 2002-11-27
19:21:22.000000000 -0500
@@ -424,7 +424,7 @@ public abstract class ColorModel impleme
     for (int i=0; i<numComponents; i++)
     {
       float in = normComponents[normOffset++];
-      int out = (int) (in * ((2<<getComponentSize(i)) - 1));
+      int out = (int) (in * ((1<<getComponentSize(i)) - 1));
       components[offset++] = out;
     }
     return components;
@@ -447,7 +447,7 @@ public abstract class ColorModel impleme
     for (int i=0; i<numComponents; i++)
     {
       float in = components[offset++];
-      float out = in / ((2<<getComponentSize(i)) - 1);
+      float out = in / ((1<<getComponentSize(i)) - 1);
       normComponents[normOffset++] = out;
     }
     return normComponents;



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]