Hello all,
While playing with the great html work from Roman and others I found out
that we must have missed another LE/BE issue with graphics handling. The
badge.png drawn in the html demo looked very ugly to me, purple instead
of the known brown/yellow.
I know this type of error so I fixed it.
Is it ok? Can a LE user please verify if I did not break anything there?
Thanks,
Andreas
2006-11-11 Andreas Tobler <[EMAIL PROTECTED]>
* gnu/java/awt/peer/gtk/GtkImageConsumer.java (setPixels): Handle data
from big endian systems correctly.
Index: gnu/java/awt/peer/gtk/GtkImageConsumer.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GtkImageConsumer.java,v
retrieving revision 1.5
diff -u -r1.5 GtkImageConsumer.java
--- gnu/java/awt/peer/gtk/GtkImageConsumer.java 17 Jul 2006 22:41:03 -0000
1.5
+++ gnu/java/awt/peer/gtk/GtkImageConsumer.java 11 Nov 2006 21:12:50 -0000
@@ -42,6 +42,7 @@
import java.awt.image.ImageConsumer;
import java.awt.image.ImageProducer;
import java.awt.image.MemoryImageSource;
+import java.nio.ByteOrder;
import java.util.Hashtable;
/**
@@ -103,7 +104,7 @@
scansize);
}
- public synchronized void setPixels (int x, int y, int width, int height,
+ public synchronized void setPixels (int x, int y, int width, int height,
ColorModel cm, int[] pixels,
int offset, int scansize)
{
@@ -117,18 +118,34 @@
width);
else
{
- for (int i = 0; i < height; i++)
- for (int j = 0; j < width; j++)
- {
- // get in AARRGGBB and convert to AABBGGRR
- int pix = cm.getRGB(pixels[offset + (i * scansize) + x + j]);
- byte b = (byte)(pix & 0xFF);
- byte r = (byte)(((pix & 0x00FF0000) >> 16) & 0xFF);
- pix &= 0xFF00FF00;
- pix |= ((b & 0xFF) << 16);
- pix |= (r & 0xFF);
- pixelCache[(y + i) * this.width + x + j] = pix;
- }
+ if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)
+ {
+ for (int i = 0; i < height; i++)
+ for (int j = 0; j < width; j++)
+ {
+ // get in RRGGBBAA and convert to AARRGGBB
+ int pix = cm.getRGB(pixels[offset + (i * scansize) + x + j]);
+ int a = ((pix & 0xFF000000) >> 24) & 0xFF;
+ int rgb = (pix & 0x00FFFFFF) << 8;
+ pix = rgb | a;
+ pixelCache[(y + i) * this.width + x + j] = pix;
+ }
+ }
+ else
+ {
+ for (int i = 0; i < height; i++)
+ for (int j = 0; j < width; j++)
+ {
+ // get in AARRGGBB and convert to AABBGGRR
+ int pix = cm.getRGB(pixels[offset + (i * scansize) + x + j]);
+ byte b = (byte)(pix & 0xFF);
+ byte r = (byte)(((pix & 0x00FF0000) >> 16) & 0xFF);
+ pix &= 0xFF00FF00;
+ pix |= ((b & 0xFF) << 16);
+ pix |= (r & 0xFF);
+ pixelCache[(y + i) * this.width + x + j] = pix;
+ }
+ }
}
}