Skip to content
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

Image.getImageData() sometimes returns the active ImageData #1694

Open
TuxPaper opened this issue Dec 23, 2024 · 0 comments
Open

Image.getImageData() sometimes returns the active ImageData #1694

TuxPaper opened this issue Dec 23, 2024 · 0 comments

Comments

@TuxPaper
Copy link

Describe the bug
Image.getImageData() is supposed to return an ImageData where, according to the javadocs, "Modifications made to this ImageData will not affect the Image."

In some cases, it DOES return the ImageData that will affect the Image upon modification.

This is because org.eclipse.swt.internal.DPIUtil#scaleImageData(org.eclipse.swt.graphics.Device, org.eclipse.swt.graphics.ImageData, int, int) returns the live imageData variable directly if certain criteria is met (targetZoom == currentZoom) Line Source. When that criteria isn't met, it correctly returns a copy (because it creates a scaled version)

Expected behavior
Image.getImageData() should always return a duplicate of ImageData and not the actual ImageData of the Image.

Environment:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
  1. SWT
    Seen on SWT 4.34 (4967r8) on Windows, but probably present on all OS since DPIUtil is cross platform

Workaround (or) Additional context
Lazy workaround is to call scaleTo with same dimensions, ensuring an ImageData that won't modify the original image:

ImageData imageData = image.getImageData();
imageData = imageData.scaledTo(imageData.width, imageData.height);
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

No branches or pull requests

1 participant