Skip to content

Conversation

@ptziegler
Copy link
Contributor

On Linux, loading an Image from an InputStream is internally handled via an ImageDataAtSizeProvider.

When loading ImageData by zoom, this interface requires a proper implementation of the getDefaultSize() method, which in return requires the ImageData be loaded at 100% zoom, even when the source data is dynamically sizable. To avoid loading the same resource twice, this data is then used when requesting the ImageData with default size.

The tests have been updated to test the loading of an Image from an InputStream and to also check the size of the ImageData at 100% zoom.

Closes #3011

@github-actions
Copy link
Contributor

github-actions bot commented Jan 26, 2026

Test Results (macos)

   54 files  ±0     54 suites  ±0   7m 48s ⏱️ -8s
4 519 tests +1  4 276 ✅ +1  243 💤 ±0  0 ❌ ±0 
  104 runs  ±0    104 ✅ ±0    0 💤 ±0  0 ❌ ±0 

Results for commit 5058445. ± Comparison against base commit 100fbc6.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 26, 2026

Test Results (linux)

   88 files  ±0     88 suites  ±0   14m 25s ⏱️ -3s
4 563 tests +1  4 343 ✅ +1  220 💤 ±0  0 ❌ ±0 
  211 runs  ±0    208 ✅ ±0    3 💤 ±0  0 ❌ ±0 

Results for commit 5058445. ± Comparison against base commit 100fbc6.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 26, 2026

Test Results

  176 files    176 suites   28m 12s ⏱️
4 681 tests 4 659 ✅ 22 💤 0 ❌
  485 runs    479 ✅  6 💤 0 ❌

Results for commit 5058445.

♻️ This comment has been updated with latest results.

Comment on lines 1528 to 1542
Point defaultSize = new Point(imageData.width, imageData.height);
ImageDataAtSizeProvider imageDataAtSizeProvider = new ImageDataAtSizeProvider() {
@Override
public Point getDefaultSize() {
return defaultSize;
}

@Override
public ImageData getImageData(int width, int height) {
if (width == defaultSize.x && height == defaultSize.y) {
return imageData;
}
return ImageDataLoader.loadBySize(new ByteArrayInputStream(streamData), width, height);
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This should work, still I would propose to just implement the getImageData(zoom) method instead of the getDefaultSize() method because of two reasons:

  • You avoid loading the 100% image data even though you potentially do not need the data (but just the size)
  • In general, the advice is to overwrite getImageData(zoom) in case the provider (the file) specifies the default 100% size and getDefaultSize() in case the consumer does it. In this case, you want to have the provider (the file) specify the 100% size, which is why simply loading the file in the existing by-zoom way is most appropriate. In the current proposa, the provider specifies the size, still getDefaultSize() is overwritten, which makes this workaround of loading the data at 100% to extract the provider size which is then passed by the consumer again necessary.
Suggested change
Point defaultSize = new Point(imageData.width, imageData.height);
ImageDataAtSizeProvider imageDataAtSizeProvider = new ImageDataAtSizeProvider() {
@Override
public Point getDefaultSize() {
return defaultSize;
}
@Override
public ImageData getImageData(int width, int height) {
if (width == defaultSize.x && height == defaultSize.y) {
return imageData;
}
return ImageDataLoader.loadBySize(new ByteArrayInputStream(streamData), width, height);
}
};
ImageDataAtSizeProvider imageDataAtSizeProvider = new ImageDataAtSizeProvider() {
@Override
public ImageData getImageData(int zoom) {
return ImageDataLoader.loadByZoom(new ByteArrayInputStream(streamData), FileFormat.DEFAULT_ZOOM, zoom).element();
}
@Override
public ImageData getImageData(int width, int height) {
return ImageDataLoader.loadBySize(new ByteArrayInputStream(streamData), width, height);
}
};

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 wasn't really sure which of the default methods to override, but that makes sense, of course. The call to getDefaultSize() no longer returns a meaningful size, but that's probably not releveant for an instance that is only used internally.

@ptziegler ptziegler force-pushed the issue3011 branch 5 times, most recently from 7d7de55 to 9ec8bcc Compare January 27, 2026 07:56
…-platform#3011

On Linux and MacOS, loading an `Image` from an `InputStream` is
internally handled via an `ImageDataAtSizeProvider`.

When loading `ImageData` by zoom, this interface requires a proper
implementation of the `getDefaultSize()` or `getImageData(int)` method.
Otherwise an `ImageData` of size 1x1 is returned at 100% zoom, otherwise
`null`.

The tests have been updated to test the loading of an `Image` from an
`InputStream` and to also check the size of the `ImageData` at 100%
zoom.

Closes eclipse-platform#3011
Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

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

Thank you, @ptziegler!
The fix is sound and works fine on both MacOS and Linux.

@HeikoKlare HeikoKlare merged commit 52d4524 into eclipse-platform:master Jan 27, 2026
37 of 39 checks passed
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.

ImageData reports wrong size for Image created from SVG InputStream

2 participants