-
Notifications
You must be signed in to change notification settings - Fork 184
[GTK] Fix scaling of image copies and stylings #2653
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -278,16 +278,16 @@ public Image(Device device, Image srcImage, int flag) { | |||||
| if (flag != SWT.IMAGE_DISABLE) transparentPixel = srcImage.transparentPixel; | ||||||
|
|
||||||
| long imageSurface = srcImage.surface; | ||||||
| int width = this.width = srcImage.width; | ||||||
| int height = this.height = srcImage.height; | ||||||
| this.width = srcImage.width; | ||||||
| this.height = srcImage.height; | ||||||
| int format = Cairo.cairo_surface_get_content(imageSurface) == Cairo.CAIRO_CONTENT_COLOR ? Cairo.CAIRO_FORMAT_RGB24 : Cairo.CAIRO_FORMAT_ARGB32; | ||||||
| boolean hasAlpha = format == Cairo.CAIRO_FORMAT_ARGB32; | ||||||
| surface = Cairo.cairo_image_surface_create(format, width, height); | ||||||
| int dataWidth = DPIUtil.pointToPixel(this.width, DPIUtil.getDeviceZoom()); | ||||||
| int dataHeight= DPIUtil.pointToPixel(this.height, DPIUtil.getDeviceZoom()); | ||||||
| surface = Cairo.cairo_image_surface_create(format, dataWidth, dataHeight); | ||||||
| if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES); | ||||||
| if (DPIUtil.getDeviceZoom() != currentDeviceZoom) { | ||||||
| double scaleFactor = DPIUtil.getDeviceZoom() / 100f; | ||||||
| Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor); | ||||||
| } | ||||||
| double scaleFactor = DPIUtil.getDeviceZoom() / 100f; | ||||||
| Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor); | ||||||
|
Comment on lines
+289
to
+290
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is setting the scale still necessary? I don't get what the purpose is when the surface already has the correct size. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is necessary. Otherwise it will look like this: In my understanding, you need to do two things (which are the two places I adapted):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am still not able to understand a slight detail on how the images were drawn fully (although blurrily scaled) before, as the height and width of the surface was in points I would expect to the surface to have only data in half width and height or the image to be partially cut off, when the zoom is 200% There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's because the surface scale was usually set to 1 as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| long cairo = Cairo.cairo_create(surface); | ||||||
| if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES); | ||||||
| Cairo.cairo_set_operator(cairo, Cairo.CAIRO_OPERATOR_SOURCE); | ||||||
|
|
@@ -306,9 +306,9 @@ public Image(Device device, Image srcImage, int flag) { | |||||
| switch (flag) { | ||||||
| case SWT.IMAGE_DISABLE: { | ||||||
| byte[] line = new byte[stride]; | ||||||
| for (int y=0; y<height; y++) { | ||||||
| for (int y=0; y<dataHeight; y++) { | ||||||
| C.memmove(line, data + (y * stride), stride); | ||||||
| for (int x = 0, offset = 0; x < width; x++, offset += 4) { | ||||||
| for (int x = 0, offset = 0; x < dataWidth; x++, offset += 4) { | ||||||
| int a = line[offset + oa] & 0xFF; | ||||||
| int r = line[offset + or] & 0xFF; | ||||||
| int g = line[offset + og] & 0xFF; | ||||||
|
|
@@ -339,9 +339,9 @@ public Image(Device device, Image srcImage, int flag) { | |||||
| } | ||||||
| case SWT.IMAGE_GRAY: { | ||||||
| byte[] line = new byte[stride]; | ||||||
| for (int y=0; y<height; y++) { | ||||||
| for (int y=0; y<dataHeight; y++) { | ||||||
| C.memmove(line, data + (y * stride), stride); | ||||||
| for (int x=0, offset = 0; x<width; x++, offset += 4) { | ||||||
| for (int x=0, offset = 0; x<dataWidth; x++, offset += 4) { | ||||||
| int a = line[offset + oa] & 0xFF; | ||||||
| int r = line[offset + or] & 0xFF; | ||||||
| int g = line[offset + og] & 0xFF; | ||||||
|
|
||||||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is copy of the image it's best to fetch the scale (cairo gives separate x/y scale factors) of the image copied.