Bug 340256 - Inconsistencies when painting images using different interpolation modes on Windows
Summary: Inconsistencies when painting images using different interpolation modes on W...
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks: 124506
  Show dependency tree
 
Reported: 2011-03-16 18:36 EDT by Alexander Nyßen CLA
Modified: 2019-11-08 04:39 EST (History)
0 users

See Also:


Attachments
Image file used by the test case (place in the same package as the test file) (28.74 KB, image/jpeg)
2011-03-16 18:36 EDT, Alexander Nyßen CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Nyßen CLA 2011-03-16 18:36:58 EDT
Created attachment 191364 [details]
Image file used by the test case (place in the same package as the test file)

The following test case is an SWT-only version of org.eclipse.draw2d.test.AdvancedGraphicsTests#testInterpolation(), which can be used to reproduce the SWT issue underlying GEF bug #124506 (attached find the image file, which is used in the test case). 

The test fails on Windows (tested with Windows XP), while it successfully passes on other platforms (verified with Mac Cocoa):

/*******************************************************************************
 * Copyright (c) 2004, 2010 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package swt.bugs;

import java.io.InputStream;
import java.util.Stack;

import junit.framework.TestCase;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.Path;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Resource;
import org.eclipse.swt.graphics.Transform;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class AdvancedGraphicsTestsInterpolationSWTOnly extends TestCase {

	static final Image depth_24;

	static {
		InputStream is = AdvancedGraphicsTestsInterpolationSWTOnly.class
				.getResourceAsStream("bits24.jpg");
		depth_24 = new Image(null, is);
		try {
			is.close();
		} catch (Exception e) {
		}
	}
	private static final int PREVIEW_DELAY = 250;

	private Image image;
	private GC imageGC;
	private Path path1;
	private Path path2;
	private Stack resources = new Stack();

	private void assertImageEquality(int width, int height) {
		ImageData data = image.getImageData();
		int src, dst;
		PaletteData palette = data.palette;
		for (int y = 0; y < height; y++)
			for (int x = 0; x < width; x++) {
				src = data.getPixel(x, y);
				dst = data.getPixel(x, y + height);

				if (src != dst) {
					RGB rgb1 = palette.getRGB(src);
					RGB rgb2 = palette.getRGB(dst);
					// RGB values may differ by 1 (rounding effects?)
					if (Math.abs(rgb1.red - rgb2.red) > 1
							|| Math.abs(rgb1.green - rgb2.green) > 1
							|| Math.abs(rgb1.blue - rgb2.blue) > 1)
						assertEquals("Discrepancy at coordinates <" + x + ", "
								+ y + ">", rgb1, rgb2);
				}
			}
	}

	private void displayImage() {
		final Shell shell = new Shell(SWT.DIALOG_TRIM);
		shell.addPaintListener(new PaintListener() {
			public void paintControl(PaintEvent e) {
				e.gc.drawImage(image, 0, 0);
			}
		});
		shell.setBounds(100, 100, 800, 600);
		shell.open();
		Display d = shell.getDisplay();
		d.timerExec(PREVIEW_DELAY, new Runnable() {
			public void run() {
				if (!shell.isDisposed())
					shell.close();
			}
		});
		while (!shell.isDisposed())
			while (!d.readAndDispatch())
				d.sleep();

	}

	private void performTestcase(Runnable painter, Runnable tests[]) {
		Transform t = new Transform(imageGC.getDevice());
		for (int i = 0; i < tests.length; i++) {
			t.translate(100, 0);
			imageGC.setTransform(t);
			tests[i].run();
			painter.run();
		}

		t.dispose();
		t = new Transform(imageGC.getDevice());
		t.translate(0, 100);
		imageGC.setTransform(t);

		for (int i = 0; i < tests.length; i++) {
			t.translate(100, 0);
			imageGC.setTransform(t);
			tests[i].run();
			painter.run();
		}
		t.dispose();

		displayImage();
		assertImageEquality(100 * tests.length, 100);
	}

	protected void setUp() throws Exception {
		path1 = new Path(null);
		path1.moveTo(20, 5);
		path1.quadTo(40, 5, 50, 25);
		path1.quadTo(20, 25, 20, 45);
		path1.lineTo(0, 25);
		path1.close();

		path2 = new Path(null);
		path2.moveTo(15, 30);
		path2.cubicTo(50, 0, 50, 30, 20, 60);
		path2.close();

		image = new Image(Display.getDefault(), 800, 600);
		imageGC = new GC(image, SWT.NONE);

		resources.push(path1);
		resources.push(path2);
		resources.push(image);
		resources.push(imageGC);
	}

	protected void tearDown() throws Exception {
		while (!resources.isEmpty())
			((Resource) resources.pop()).dispose();
	}

	public void testInterpolation() {
		class InterpolationSettings implements Runnable {
			private final int level;

			InterpolationSettings(int level) {
				this.level = level;
			}

			public void run() {
				imageGC.setInterpolation(level);
			}
		}

		Runnable tests[] = new Runnable[4];
		tests[0] = new InterpolationSettings(SWT.HIGH);
		tests[1] = new InterpolationSettings(SWT.LOW);
		tests[2] = new InterpolationSettings(SWT.NONE);
		tests[3] = new InterpolationSettings(SWT.DEFAULT);
		performTestcase(new Runnable() {
			public void run() {
				imageGC.drawImage(depth_24, 0, 0, 400, 400, 0, 0, 75, 75);
			}
		}, tests);
	}
}
Comment 1 Lars Vogel CLA 2019-11-08 04:39:40 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

If the bug is still relevant please remove the stalebug whiteboard tag.