Skip to content

Commit f497de4

Browse files
committed
create Image with ImageDataProvider instead of ImageData in
fillGradientRectangle() This PR refactors the image creation logic in fillGradientRectangle() by using an ImageDataProvider instead of directly creating ImageData. There is no visual impact for the changes the behavior should remain as before.
1 parent 95b46b6 commit f497de4

File tree

1 file changed

+9
-3
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics

1 file changed

+9
-3
lines changed

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,9 +2616,15 @@ static void fillGradientRectangle(GC gc, Device device,
26162616
RGB fromRGB, RGB toRGB,
26172617
int redBits, int greenBits, int blueBits, int zoom) {
26182618
/* Create the bitmap and tile it */
2619-
ImageData band = createGradientBand(width, height, vertical,
2620-
fromRGB, toRGB, redBits, greenBits, blueBits);
2621-
Image image = new Image(device, band);
2619+
ImageDataProvider imageDataProvider = imageZoom -> {
2620+
float scaleFactor = imageZoom / 100.0f;
2621+
int scaledWidth = Math.round(width * scaleFactor);
2622+
int scaledHeight = Math.round(height * scaleFactor);
2623+
return createGradientBand(scaledWidth, scaledHeight, vertical, fromRGB, toRGB, redBits, greenBits,
2624+
blueBits);
2625+
};
2626+
Image image = new Image(device, imageDataProvider);
2627+
ImageData band = image.getImageData();
26222628
if ((band.width == 1) || (band.height == 1)) {
26232629
gc.drawImage(image, 0, 0, DPIUtil.pixelToPoint(band.width, zoom), DPIUtil.pixelToPoint(band.height, zoom),
26242630
DPIUtil.pixelToPoint(x, zoom), DPIUtil.pixelToPoint(y, zoom), DPIUtil.pixelToPoint(width, zoom),

0 commit comments

Comments
 (0)