Skip to content

Refactor fillGradientRectangle to avoid DPIUtil.autoScaleDown() #2284

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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2609,35 +2609,40 @@ static void buildDitheredGradientChannel(int from, int to, int steps,
* @param redBits the number of significant red bits, 0 for palette modes
* @param greenBits the number of significant green bits, 0 for palette modes
* @param blueBits the number of significant blue bits, 0 for palette modes
* @param zoom the zoom of gc drawer used
*/
static void fillGradientRectangle(GC gc, Device device,
int x, int y, int width, int height, boolean vertical,
RGB fromRGB, RGB toRGB,
int redBits, int greenBits, int blueBits) {
static void fillGradientRectangle(GC gc, Device device, int x, int y, int width, int height, boolean vertical,
RGB fromRGB, RGB toRGB, int redBits, int greenBits, int blueBits, int zoom) {
/* Create the bitmap and tile it */
ImageData band = createGradientBand(width, height, vertical,
fromRGB, toRGB, redBits, greenBits, blueBits);
Image image = new Image(device, band);
ImageDataProvider imageDataProvider = imageZoom -> {
float scaleFactor = imageZoom / 100.0f;
int scaledWidth = Math.round(width * scaleFactor);
int scaledHeight = Math.round(height * scaleFactor);
return createGradientBand(scaledWidth, scaledHeight, vertical, fromRGB, toRGB, redBits, greenBits,
blueBits);
};
Image image = new Image(device, imageDataProvider);
ImageData band = image.getImageData();
if ((band.width == 1) || (band.height == 1)) {
gc.drawImage(image, 0, 0, DPIUtil.autoScaleDown(band.width), DPIUtil.autoScaleDown(band.height),
DPIUtil.autoScaleDown(x), DPIUtil.autoScaleDown(y), DPIUtil.autoScaleDown(width),
DPIUtil.autoScaleDown(height));
gc.drawImage(image, 0, 0, DPIUtil.scaleDown(band.width, zoom), DPIUtil.scaleDown(band.height, zoom),
DPIUtil.scaleDown(x, zoom), DPIUtil.scaleDown(y, zoom), DPIUtil.scaleDown(width, zoom),
DPIUtil.scaleDown(height, zoom));
} else {
if (vertical) {
for (int dx = 0; dx < width; dx += band.width) {
int blitWidth = width - dx;
if (blitWidth > band.width) blitWidth = band.width;
gc.drawImage(image, 0, 0, DPIUtil.autoScaleDown(blitWidth), DPIUtil.autoScaleDown(band.height),
DPIUtil.autoScaleDown(dx + x), DPIUtil.autoScaleDown(y), DPIUtil.autoScaleDown(blitWidth),
DPIUtil.autoScaleDown(band.height));
gc.drawImage(image, 0, 0, DPIUtil.scaleDown(blitWidth, zoom), DPIUtil.scaleDown(band.height, zoom),
DPIUtil.scaleDown(dx + x, zoom), DPIUtil.scaleDown(y, zoom), DPIUtil.scaleDown(blitWidth, zoom),
DPIUtil.scaleDown(band.height, zoom));
}
} else {
for (int dy = 0; dy < height; dy += band.height) {
int blitHeight = height - dy;
if (blitHeight > band.height) blitHeight = band.height;
gc.drawImage(image, 0, 0, DPIUtil.autoScaleDown(band.width), DPIUtil.autoScaleDown(blitHeight),
DPIUtil.autoScaleDown(x), DPIUtil.autoScaleDown(dy + y), DPIUtil.autoScaleDown(band.width),
DPIUtil.autoScaleDown(blitHeight));
gc.drawImage(image, 0, 0, DPIUtil.scaleDown(band.width, zoom), DPIUtil.scaleDown(blitHeight, zoom),
DPIUtil.scaleDown(x, zoom), DPIUtil.scaleDown(dy + y, zoom), DPIUtil.scaleDown(band.width, zoom),
DPIUtil.scaleDown(blitHeight, zoom));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3183,7 +3183,7 @@ private void fillGradientRectangleInPixels(int x, int y, int width, int height,
final int bitResolution = (depth >= 24) ? 8 : (depth >= 15) ? 5 : 0;
ImageData.fillGradientRectangle(this, data.device,
x, y, width, height, vertical, fromRGB, toRGB,
bitResolution, bitResolution, bitResolution);
bitResolution, bitResolution, bitResolution, getZoom());
}

/**
Expand Down
Loading