Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 101799 - Enabling advanced graphics will cause alpha gradient to be applied
Summary: Enabling advanced graphics will cause alpha gradient to be applied
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: 3.2 M1   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-26 17:17 EDT by Rob Grzywinski CLA
Modified: 2006-03-19 01:15 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rob Grzywinski CLA 2005-06-26 17:17:27 EDT
If advanced graphics (GC.setAdvanced(true)) is enabled on a graphics context
then calling GC.drawImage(Image image, int srcX, int srcY, int srcWidth, int
srcHeight, int destX, int destY, int destWidth, int destHeight) where the
destination width and/or height is greater than that of the source image will
draw an image with an alpha gradient.  Specially, the drawn image will be the
desired color at its center but have an alpha graient applied towards its edges
(as if the act of stretching implies an alpha shift).

An example can be quickly cooked up using SWT image snippet #112:

    public static void main (String [] args) {
        Display display = new Display ();
        final Image image = new Image(display, 2, 10);
            final Color color = display.getSystemColor(SWT.COLOR_BLUE);
            final GC gc = new GC (image);
                gc.setBackground(color);
                gc.fillRectangle(image.getBounds());
            gc.dispose ();
            color.dispose ();

        Shell shell = new Shell (display);
        shell.setLayout (new FillLayout ());
        Group group = new Group (shell, SWT.NONE);
        group.setLayout (new FillLayout ());
        group.setText ("a square");
        Canvas canvas = new Canvas (group, SWT.NONE);
        canvas.addPaintListener (new PaintListener () {
            public void paintControl (PaintEvent e) {
                // NOTE: turning on advanced graphics here (regardless of any
                //       alpha value set) will cause the stretched image to have
                //       an alpha gradient applied
                // NOTE: this same effect can be seen by performing any function
                //       that would enabled advanced graphics such as:
                //           e.gc.setAlpha(0xFE);
                //       or:
                //           e.gc.setAntialias(SWT.ON);
                e.gc.setAdvanced(true);
                // NOTE: the image is stretched in both dimensions
                e.gc.drawImage(image, 0, 0, 2, 10, 0, 0, 300, 300);
            }
        });

        shell.pack ();
        shell.open ();
        while (!shell.isDisposed ()) {
            if (!display.readAndDispatch ())
                display.sleep ();
        }
        image.dispose ();
        display.dispose ();
    }

This gradient occurs regardless of the source of the source image (e.g. a loaded
image or a created image as in the snippet above).

(This bug becomes more severe with the use of GEF as there is no way to disable
the use of advanced graphics on a Graphics object after it has been enabled. 
(And it hasn't been shown that disabling advanced graphics will even solve the
problem.))
Comment 1 Silenio Quarti CLA 2005-07-11 16:34:01 EDT
Fixed > 20050711.
Comment 2 Randy Hudson CLA 2005-07-11 17:05:10 EDT
(In reply to comment #0)
> (This bug becomes more severe with the use of GEF as there is no way to 
disable
> the use of advanced graphics on a Graphics object after it has been enabled. 

You can use push, pop, and restoreState() on Graphics to get back to a non-
advanced mode.
Comment 3 Rob Grzywinski CLA 2005-07-11 17:21:16 EDT
For the default GraphicsSource (BufferedGraphicsSource) this is true.  I guess 
I should have said that there is no *explicit* way to disable the use of 
advanced graphics (which there really shouldn't be).  Unfortunately I am using 
a custom GraphicsSource that was on a GC with advanced graphics enabled.

Thanks for the tip though.  I may be moving back to the default GraphicsSource 
now that most of these bugs are ironed out.

Thanks for the bug fix Silenio Quarti.
Comment 4 David Walser CLA 2006-03-19 01:02:50 EST
This bug seems to have sort of come back.  The differences are that the artifact on the edges of the image are now always only 1 pixel wide and happen on the opposite sides of the image: the top and left as opposed to the bottom and right.

I don't know if you can see the problem with the snippet referenced in this bug, but you can see it with the attachment I made to Bug 103973.
Comment 5 David Walser CLA 2006-03-19 01:15:24 EST
Just a note on that attachment I just referenced...the colorize method should be changed as follows to work around Bug 103691:

	private static void colorize(ImageData data) {
		int blue = data.palette.getPixel(new RGB(0, 0, 255));
		for (int y=0;y < data.height;y++)
			for (int x=0;x < data.width;x++) {
				int pixel = data.getPixel(x, y);
				int alpha = data.getAlpha(x, y);
				if (pixel == data.transparentPixel || alpha == 0) {
					data.setPixel(x, y, blue);
					continue;
				}
			}
	}