Skip to content

A strict check 200% image data is double the size of 100% image data #2249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arunjose696
Copy link
Contributor

@arunjose696 arunjose696 commented Jun 18, 2025

A strict check to be used only for debugging means, this ensures the imageData is scaled linearly for 100 and 200 zooms.

Steps to reproduce

Out of the blow snippets. Snippet1 which uses an image data provider that always returns the same image, when executed with the VM argument -Dorg.eclipse.swt.internal.enableStrictChecks=True, logs the error` "ImageData should be linearly scaled across zooms." to stdout. Whereas snippet 2 which scales ImageData linearly runs without this error log.

snippet 1
package org.eclipse.swt.snippets;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
public class TestImageProvider {
    public static void main(String[] args) {
        Display display = new Display();
        ImageDataProvider provider = (zoom) -> new ImageData(
            16, 16, 32,
            new PaletteData((new RGB(255, 0, 0)))
        );
        Image image = new Image(display, provider);
        System.out.println("Done execution");
    }
}
snippet 2
package org.eclipse.swt.snippets;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
public class TestImageProvider {
    public static void main(String[] args) {
        Display display = new Display();
        ImageDataProvider provider = (zoom) -> new ImageData(
            16*zoom/100, 16*zoom/100, 32,
            new PaletteData((new RGB(255, 0, 0)))
        );
        Image image = new Image(display, provider);  
        System.out.println("Done execution");
    }
}

The below examples demonstrate testing this again with PNG images. In the first snippet, the ImageDataProvider returns the image data from the same file for both 100% and 200% zoom levels without scaling, which causes the error message "ImageData should be linearly scaled across zooms." to be printed to stdout. In the second snippet it provides properly scaled image data at 200% zoom (using a scaled image), so it executes without logging this error.
To run these snippets, download the following PNG files and place them in your working directory:
pause.png

[email protected]

snippet 1
package org.eclipse.swt.snippets;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
public class TestImageProvider {
    public static void main(String[] args) {
    	System.out.println("Working directory: " + System.getProperty("user.dir"));
        Display display = new Display();

        ImageDataProvider provider = zoom -> {
            if (zoom == 100) {
                return new ImageData("pause.png");
            }
            else if (zoom == 200) {
                return new ImageData("pause.png");
            }
            else {
                return null;
            }
        };

        Image image = new Image(display, provider);
        System.out.println("Done execution");
    }
}
snippet 2
package org.eclipse.swt.snippets;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
public class TestImageProvider {
    public static void main(String[] args) {
    	System.out.println("Working directory: " + System.getProperty("user.dir"));
        Display display = new Display();

        ImageDataProvider provider = zoom -> {
            if (zoom == 100) {
                return new ImageData("pause.png");
            }
            else if (zoom == 200) {
                return new ImageData("[email protected]");
            }
            else {
                return null;
            }
        };

        Image image = new Image(display, provider);
        System.out.println("Done execution");
    }
}

Copy link
Contributor

github-actions bot commented Jun 18, 2025

Test Results

   539 files   -  6     539 suites   - 6   27m 41s ⏱️ - 1m 13s
 4 369 tests  - 37   4 353 ✅  - 35   15 💤  - 3  0 ❌ ±0  1 🔥 +1 
16 708 runs   - 37  16 568 ✅  - 35  139 💤  - 3  0 ❌ ±0  1 🔥 +1 

For more details on these errors, see this check.

Results for commit c40fee2. ± Comparison against base commit 6842283.

This pull request removes 37 tests.
AllWin32Tests org.eclipse.swt.graphics.ImageWin32Tests ‑ testImageDataForDifferentFractionalZoomsShouldBeDifferent
AllWin32Tests org.eclipse.swt.graphics.ImageWin32Tests ‑ testImageShouldHaveDimesionAsPerZoomLevel
AllWin32Tests org.eclipse.swt.tests.win32.Test_org_eclipse_swt_dnd_DND ‑ testByteArrayTransfer
AllWin32Tests org.eclipse.swt.tests.win32.Test_org_eclipse_swt_dnd_DND ‑ testFileTransfer
AllWin32Tests org.eclipse.swt.tests.win32.Test_org_eclipse_swt_dnd_DND ‑ testHtmlTransfer
AllWin32Tests org.eclipse.swt.tests.win32.Test_org_eclipse_swt_dnd_DND ‑ testImageTransfer_fromCopiedImage
AllWin32Tests org.eclipse.swt.tests.win32.Test_org_eclipse_swt_dnd_DND ‑ testImageTransfer_fromImage
AllWin32Tests org.eclipse.swt.tests.win32.Test_org_eclipse_swt_dnd_DND ‑ testImageTransfer_fromImageData
AllWin32Tests org.eclipse.swt.tests.win32.Test_org_eclipse_swt_dnd_DND ‑ testImageTransfer_fromImageDataFromImage
AllWin32Tests org.eclipse.swt.tests.win32.Test_org_eclipse_swt_dnd_DND ‑ testRtfTransfer
…

♻️ This comment has been updated with latest results.

@arunjose696 arunjose696 force-pushed the arunjose696/313/StrictCheck branch from 085c1c6 to d78d6ae Compare June 23, 2025 11:33
@arunjose696 arunjose696 force-pushed the arunjose696/313/StrictCheck branch 2 times, most recently from db68f87 to 1403084 Compare July 1, 2025 09:55
@arunjose696
Copy link
Contributor Author

In CI failing checks I have the below error, Dont think this has anything to do with my changes.

[2025-07-01T10:06:14.756Z] [ERROR] Failed to execute goal org.eclipse.tycho.extras:tycho-p2-extras-plugin:5.0.0-SNAPSHOT:compare-version-with-baselines (compare-attached-artifacts-with-release) on project org.eclipse.swt.tools: Baseline and reactor have the same fully qualified version, but different content
[2025-07-01T10:06:14.756Z] [ERROR] different
[2025-07-01T10:06:14.756Z] [ERROR]    META-INF/ECLIPSE_.RSA: present in baseline only
[2025-07-01T10:06:14.756Z] [ERROR]    META-INF/ECLIPSE_.SF: present in baseline only
[2025-07-01T10:06:14.756Z] [ERROR] -> [Help 1]
[2025-07-01T10:06:14.756Z] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.eclipse.tycho.extras:tycho-p2-extras-plugin:5.0.0-SNAPSHOT:compare-version-with-baselines (compare-attached-artifacts-with-release) on project org.eclipse.swt.tools: Baseline and reactor have the same fully qualified version, but different content
[2025-07-01T10:06:14.756Z] different
[2025-07-01T10:06:14.756Z]    META-INF/ECLIPSE_.RSA: present in baseline only
[2025-07-01T10:06:14.756Z]    META-INF/ECLIPSE_.SF: present in baseline only

Copy link
Contributor

@fedejeanne fedejeanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments before I move to the testing phase

@arunjose696 arunjose696 force-pushed the arunjose696/313/StrictCheck branch 3 times, most recently from 8b2a4c3 to 73e1a6c Compare July 3, 2025 15:24
@fedejeanne fedejeanne force-pushed the arunjose696/313/StrictCheck branch 2 times, most recently from 982ab6d to a6d4f74 Compare July 4, 2025 10:05
}

if (scaledImageData.width != scaleFactor * baseImageData.width || scaledImageData.height != scaleFactor * baseImageData.height) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT, null, "ImageData should be linearly scaled across zooms.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why throw an exception here? I thought this check was only for debugging purposes like other checks we added before (#1979, #1803, #1753)

@akoch-yatta ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced exception with a System.err.println()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case you'll have to remove the 2 new tests since there is no way to test that something was written to the console

Copy link
Contributor

@fedejeanne fedejeanne Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And you should adapt the text of this PR since nothing fails, one simply sees some output in the console. Please also add a snippet to test by providing 2 image files, one of them (the _@2x) having the wrong size.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve updated the PR text . I also added the two snippets one with an ImageDataProvider that scales the image data correctly and one that doesn’t.

To keep the setup simple, I didn’t use actual image files (e.g. SVGs), since that would require uploading multiple files and slightly complicate the example. Let me know if including real images is still necessary

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is necessary, that is a valid use case and it should be tested too.

Copy link
Contributor Author

@arunjose696 arunjose696 Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In PR text I’ve now added tests using actual .png image files in addition to the earlier code snippets.

I’m still a bit unclear on why this was necessary, as I thought the original snippets already demonstrated the intended behavior with the case where ImageData is unscaled. That said, I’ve still added a snippet with real images as requested. Please let me know if this is what you had in mind, or if there’s another use case I should be covering.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I had the wrong expectation about this PR.

FTR what I wanted to test is in JFace and you could see it for example by adding a modified version of validateLinearScaling that takes ImageDescriptor as a parameter and calling it at the end of org.eclipse.jface.tests.images.FileImageDescriptorTest.testAdaptToURL(). If you do that and provide a second file that adds @2x to the end of the file but it does not have double the size then the check would fail.

Since I'm not on Windows at the moment, I can't test this PR- I'll get back to it later this week.

@arunjose696 arunjose696 force-pushed the arunjose696/313/StrictCheck branch 4 times, most recently from 7762a2a to bc5eaca Compare July 4, 2025 11:46
A strict check to be used only for debugging means, this ensures the
imageData is scaled linearly for 100 and 200 zooms.
@arunjose696 arunjose696 force-pushed the arunjose696/313/StrictCheck branch from bc5eaca to c40fee2 Compare July 4, 2025 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resilient handling of Images with non-linearly-scaled ImageData
4 participants