Skip to content

Commit 3035e8f

Browse files
committed
Refactor fillGradientRectangle to avoid DPIUtil.autoScaleDown()
This PR replaces the use of DPIUtil.autoScaleDown() with DPIUtil.scaleDown() in the fillGradientRectangle method. Additionally, it refactors the image creation logic 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 0d3622a commit 3035e8f

File tree

2 files changed

+22
-17
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT

2 files changed

+22
-17
lines changed

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,35 +2609,40 @@ static void buildDitheredGradientChannel(int from, int to, int steps,
26092609
* @param redBits the number of significant red bits, 0 for palette modes
26102610
* @param greenBits the number of significant green bits, 0 for palette modes
26112611
* @param blueBits the number of significant blue bits, 0 for palette modes
2612+
* @param zoom the zoom of gc drawer used
26122613
*/
2613-
static void fillGradientRectangle(GC gc, Device device,
2614-
int x, int y, int width, int height, boolean vertical,
2615-
RGB fromRGB, RGB toRGB,
2616-
int redBits, int greenBits, int blueBits) {
2614+
static void fillGradientRectangle(GC gc, Device device, int x, int y, int width, int height, boolean vertical,
2615+
RGB fromRGB, RGB toRGB, int redBits, int greenBits, int blueBits, int zoom) {
26172616
/* Create the bitmap and tile it */
2618-
ImageData band = createGradientBand(width, height, vertical,
2619-
fromRGB, toRGB, redBits, greenBits, blueBits);
2620-
Image image = new Image(device, band);
2617+
ImageDataProvider imageDataProvider = imageZoom -> {
2618+
float scaleFactor = imageZoom / 100.0f;
2619+
int scaledWidth = Math.round(width * scaleFactor);
2620+
int scaledHeight = Math.round(height * scaleFactor);
2621+
return createGradientBand(scaledWidth, scaledHeight, vertical, fromRGB, toRGB, redBits, greenBits,
2622+
blueBits);
2623+
};
2624+
Image image = new Image(device, imageDataProvider);
2625+
ImageData band = image.getImageData();
26212626
if ((band.width == 1) || (band.height == 1)) {
2622-
gc.drawImage(image, 0, 0, DPIUtil.autoScaleDown(band.width), DPIUtil.autoScaleDown(band.height),
2623-
DPIUtil.autoScaleDown(x), DPIUtil.autoScaleDown(y), DPIUtil.autoScaleDown(width),
2624-
DPIUtil.autoScaleDown(height));
2627+
gc.drawImage(image, 0, 0, DPIUtil.scaleDown(band.width, zoom), DPIUtil.scaleDown(band.height, zoom),
2628+
DPIUtil.scaleDown(x, zoom), DPIUtil.scaleDown(y, zoom), DPIUtil.scaleDown(width, zoom),
2629+
DPIUtil.scaleDown(height, zoom));
26252630
} else {
26262631
if (vertical) {
26272632
for (int dx = 0; dx < width; dx += band.width) {
26282633
int blitWidth = width - dx;
26292634
if (blitWidth > band.width) blitWidth = band.width;
2630-
gc.drawImage(image, 0, 0, DPIUtil.autoScaleDown(blitWidth), DPIUtil.autoScaleDown(band.height),
2631-
DPIUtil.autoScaleDown(dx + x), DPIUtil.autoScaleDown(y), DPIUtil.autoScaleDown(blitWidth),
2632-
DPIUtil.autoScaleDown(band.height));
2635+
gc.drawImage(image, 0, 0, DPIUtil.scaleDown(blitWidth, zoom), DPIUtil.scaleDown(band.height, zoom),
2636+
DPIUtil.scaleDown(dx + x, zoom), DPIUtil.scaleDown(y, zoom), DPIUtil.scaleDown(blitWidth, zoom),
2637+
DPIUtil.scaleDown(band.height, zoom));
26332638
}
26342639
} else {
26352640
for (int dy = 0; dy < height; dy += band.height) {
26362641
int blitHeight = height - dy;
26372642
if (blitHeight > band.height) blitHeight = band.height;
2638-
gc.drawImage(image, 0, 0, DPIUtil.autoScaleDown(band.width), DPIUtil.autoScaleDown(blitHeight),
2639-
DPIUtil.autoScaleDown(x), DPIUtil.autoScaleDown(dy + y), DPIUtil.autoScaleDown(band.width),
2640-
DPIUtil.autoScaleDown(blitHeight));
2643+
gc.drawImage(image, 0, 0, DPIUtil.scaleDown(band.width, zoom), DPIUtil.scaleDown(blitHeight, zoom),
2644+
DPIUtil.scaleDown(x, zoom), DPIUtil.scaleDown(dy + y, zoom), DPIUtil.scaleDown(band.width, zoom),
2645+
DPIUtil.scaleDown(blitHeight, zoom));
26412646
}
26422647
}
26432648
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3183,7 +3183,7 @@ private void fillGradientRectangleInPixels(int x, int y, int width, int height,
31833183
final int bitResolution = (depth >= 24) ? 8 : (depth >= 15) ? 5 : 0;
31843184
ImageData.fillGradientRectangle(this, data.device,
31853185
x, y, width, height, vertical, fromRGB, toRGB,
3186-
bitResolution, bitResolution, bitResolution);
3186+
bitResolution, bitResolution, bitResolution, getZoom());
31873187
}
31883188

31893189
/**

0 commit comments

Comments
 (0)