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: XGraphicsConfiguration,XToolkit: display colors properly in 16-bit display modes


This patch gets correct colors to display in non-24-bit graphics modes with
xlib.  It's a bit nasty, in that it requires floating point to translate the
colors.  That may be because I completely misunderstand something, but the
fix works fine (besides imposing a little performance penalty).  To test it,
I compiled an application which puts a lot of colors on the screen, and
confirmed that it looked the same on 2 machines, one with 16-bit color and
one with 24-bit color.

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

 * gnu.awt.xlib.XGraphicsConfiguration, gnu.awt.xlib.XToolkit: Changed color
mapping to work with 16-bit display modes,
    with a performance penalty due to the use of floating point

diff -r -up gcc.patched/libjava/gnu/awt/xlib/XGraphicsConfiguration.java
gcc/libjava/gnu/awt/xlib/XGraphicsConfiguration.java
--- gcc.patched/libjava/gnu/awt/xlib/XGraphicsConfiguration.java 2002-12-02
13:04:44.000000000 -0500
+++ gcc/libjava/gnu/awt/xlib/XGraphicsConfiguration.java 2002-12-02
13:06:35.000000000 -0500
@@ -353,15 +353,31 @@ public class XGraphicsConfiguration exte

   int getPixel(Color color)
   {
+    /* FIXME: consider an integer technique whenever
+     * the ColorModel is 8 bits per color.
+     * The problem with using integers is that it doesn't work unless
+     * the colors are 8 bits each (as in the array), since
ColorModel.getDataElement(int[],int)
+     * expects non-normalized values.  For example, in a 16-bit display
mode, you
+     * would typically have 5 bits each for red and blue, and 6 bits for
green.
     int[] components =
-        {
-   color.getRed(),
-   color.getGreen(),
-   color.getBlue(),
-   0xff
- };
-
-    ColorModel cm = getColorModel();
-    return cm.getDataElement(components, 0);
+    {
+      color.getRed (),
+      color.getGreen (),
+      color.getBlue (),
+      0xff
+    };
+     */
+
+    float[] normalizedComponents =
+    {
+      ((float)color.getRed ()) / 255F,
+      ((float)color.getGreen ()) / 255F,
+      ((float)color.getBlue ()) / 255F,
+      1
+    };
+    int[] unnormalizedComponents = { 0, 0, 0, 0xff };
+    ColorModel cm = getColorModel ();
+
cm.getUnnormalizedComponents(normalizedComponents,0,unnormalizedComponents,0
);
+    return cm.getDataElement (unnormalizedComponents, 0);
   }
 }
diff -r -up gcc.patched/libjava/gnu/awt/xlib/XToolkit.java
gcc/libjava/gnu/awt/xlib/XToolkit.java
--- gcc.patched/libjava/gnu/awt/xlib/XToolkit.java 2002-12-02
11:45:17.000000000 -0500
+++ gcc/libjava/gnu/awt/xlib/XToolkit.java 2002-11-27
12:51:58.000000000 -0500
@@ -169,7 +169,7 @@ public class XToolkit extends Toolkit

   public java.awt.image.ColorModel getColorModel()
   {
-    throw new UnsupportedOperationException("not implemented yet");
+    return getDefaultXGraphicsConfiguration().getColorModel();
   }

   public String[] getFontList()



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