Skip to content

Fix: CGImageCreateWithImageInRect reports the cropped size - #31

Open
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:fix/cgimage-subimage-crop-size
Open

Fix: CGImageCreateWithImageInRect reports the cropped size#31
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:fix/cgimage-subimage-crop-size

Conversation

@DTW-Thalion

Copy link
Copy Markdown
Contributor

CGImageCreateWithImageInRect stored the crop rect but left the image's width and height at the full source size, so CGImageGetWidth and CGImageGetHeight reported the whole image rather than the crop (a 1x1 sub-image reported the parent's size). Drawing already honours the crop via the source rect, so only the reported size was wrong.

Return the crop size from CGImageGetWidth/CGImageGetHeight when a crop is set, and build the backing surface from the full source size (opal_CGImageGetSurfaceForImage) so the crop keeps being applied as the source rect at draw time. Verified by cropping the blue pixel out of a red|blue image: the sub-image reports 1x1 and draws blue.

Makes the sub-image size check in the CGImage tests (#30) pass. Checked against Apple CoreGraphics on a macOS runner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant