Skip to content

Resilient handling of Images with non-linearly-scaled ImageData #313

@HeikoKlare

Description

@HeikoKlare

Description
When images are created with an ImageDataProvider that returns image data for different zooms that are not linearly scaled according to their zoom (in particular, if the data is always the same, no matter at which zoom), this can break at different places as there is the implicit assumption that the data of an image is linearly scaled with the zoom.
For example, if one would provide the same image data at 100% and 150% and none at 125%, retrieving the 125% version would either scale up from 100% or scale down from 150% yielding image data is scaled in a completely different way than the values provided by the ImageDataProvider.

One actual issue arises when drawing the image with a GC via the GC#drawImage() method that accepts source/destination position and size. Such a call can fail with an SWTError if not at 100% monitor zoom.

Idea: add a strict check for ensuring that 200% image data is double the size of 100% image data

Reproduction

One specific issue can be reproduced with the following snippet executed on, e.g., 125% monitor zoom (at least it must not be 100%):

	Display display = new Display ();
	ImageDataProvider wrongDataProvider = (zoom) -> new ImageData(16, 16, 32, new PaletteData());
	Image image = new Image(display, wrongDataProvider);
	GC gc = new GC(display);
	gc.drawImage(image, 0, 0, 16, 16, 0, 0, 16, 16);
	gc.dispose();
	image.dispose();

This will yield:

Exception in thread "main" java.lang.IllegalArgumentException: Argument not valid
	at org.eclipse.swt.SWT.error(SWT.java:4926)
	at org.eclipse.swt.SWT.error(SWT.java:4860)
	at org.eclipse.swt.SWT.error(SWT.java:4831)
	at org.eclipse.swt.graphics.GC.drawImage(GC.java:1044)
	at org.eclipse.swt.graphics.GC.drawImage(GC.java:994)

Expected Behavior
The drawImage() call should not throw an error.

Necessary configuration:
Primary monitor scaling: 125%

Metadata

Metadata

Assignees

No one assigned

    Labels

    HiDPIA HiDPI-Related Issue or FeatureSWTIssue for SWT

    Type

    No type

    Projects

    Status

    👀 In Review

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions