Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 37767 - Images have incorrect depth on 16-bit GTK (BBAWT)
Summary: Images have incorrect depth on 16-bit GTK (BBAWT)
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 2.1   Edit
Hardware: PC Linux-GTK
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 45571 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-05-16 10:08 EDT by Stef van Dijk CLA
Modified: 2017-01-13 04:37 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stef van Dijk CLA 2003-05-16 10:08:32 EDT
The SWT implementation on GTK supports only 24-bit color depth as is evident 
from the following lines in getImageData() in the Image class:

PaletteData palette = new PaletteData(0xFF0000, 0xFF00, 0xFF);
ImageData data = new ImageData(width, height, 24, palette);

This is particularly problematic for us as we need to be able to determine the 
device depth based on the pixel size of an image.

If you take a look at the Windows or Motif implementation, there are 
switch/case statements to deal with different color depths. For example, we 
tested (and it worked) on a 16-bit monitor with the following change-

PaletteData palette = new PaletteData(0x7C00, 0x03E0, 0x1F);
ImageData data = new ImageData(width, height, 16, palette);

These values are from our calculation and match with the Windows implementation 
of 16-bit color depth.
Comment 1 Silenio Quarti CLA 2003-05-16 12:41:21 EDT
I remember that code (since I wrote it a while back :-)). The code was
just written by creating a image and than getting the image detph/palette, 
because SWT did not have an API then (I believe SWT032).

You should call display.getDepth() and SWT should provide an API to get
the system palette.

PaletteData Device.getSystemPalette() {
...
}
Comment 2 Stef van Dijk CLA 2003-05-20 16:06:50 EDT
Oops, I thought I'd already responded. Guess I forgot.

The problem is it's not up to us to simply call getDepth(). The TCK for 
Personal Profile does as I described in my email to you and there's nothing we 
can do about that. Sorry I should have included the information from that email 
here. Here it is:

This problem gets into a lot of detail about how much of the graphics tests 
work in the Personal Profile TCK. The bottom line is that AWT doesn't have an 
obvious method for determining the screen depth (like SWT's Device.getDepth()). 
Rather, it creates an image, gets it's color model and asks for the pixel size. 
It is very important that when running on low depth displays, that the tests be 
able to detect this through the method I just outlined. However, in the current 
GTK implementation, image palettes are always created as 24-bit color.
Comment 3 Silenio Quarti CLA 2003-05-22 04:00:01 EDT
I thought AWT programs would call java.awt.Toolkit.getColorModel() to figure 
out the depth/palette of the screen. That is why for me it would be enough 
just to provide Device.getSystemPalette().

It is kind of wrong to expect that images will always be on the depth of the 
screen. Right now, GTK is always 24/(0xFF0000, 0xFF00, 0xFF), Carbon is always 
32/(0xFF0000,0xFF00,0xFF) and Photon is 24/(0xFF0000,0xFF00,0xFF).

On Photon, images may have other depths if created using the constructor Image
(Display,ImageData).

How does AWT creates the image? Is it calling Image(Display,ImageData) or Image
(Display,int,int)?

Comment 4 Stef van Dijk CLA 2003-05-22 10:04:29 EDT
You may well be right that that's what AWT programs could/should be doing. 
However, it is not what the Personal Profile TCK does and there's little we can 
do about that. Specifically, what they are doing is something like this (I 
say "something" since I can't look at the exact source ;-)).

GraphicsEnvironment ge= GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd= ge.getDefaultScreenDevice();
GraphicsConfiguration gc= gd.getDefaultConfiguration();
BufferedImage bi= gc.createCompatibleImage(100,100);
int depth= bi.getColorModel().getPixelSize();

Why they go through all this trouble as opposed to doing 
Toolkit.getDefaultToolkit().getColorModel().getPixelSize() is beyond me, but 
they may well have their reasons.

Anyway, the more complicated path works on Win32, PocketPC and Motif, but 
results in an incorrect depth on GTK. Carbon isn't and may never be an issue 
for us, but Photon is an interesting heads up for us as well. I'll have to look 
into the details of how we implement this code path to see if we can't leverage 
Device.getSystemPalette() to make this work.

From the code, it seems we get the ColorModel (as returned by 
Toolkit.getColorModel) as follows:
- create an image by using Image(getDisplay(), 1, 1)
- get the paletteData from the imageData taken from that image
- we then construct either an AWT DirectColorModel or IndexColorModel based on 
whether the paletteData isDirect using (among other arguments) imageData.depth.

So that's how we create an image for determining the color model. However AWT 
creates images using both of those constructors depending on the circumstances 
in other parts of the code.
Comment 5 Silenio Quarti CLA 2003-11-11 14:00:11 EST
*** Bug 45571 has been marked as a duplicate of this bug. ***
Comment 6 Alexander Kurtakov CLA 2016-04-15 14:50:44 EDT
I'm probably going to close this bug unless someone gives a good reason not to. This sounds as not useful nowadays. Nor even has an idea what this Personal Profile TCK is about.
Comment 7 Alexander Kurtakov CLA 2017-01-13 04:37:43 EST
No reply in 9 months closing.