Skip to content
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

Add support for image cropping #248

Merged
merged 1 commit into from Aug 15, 2018
Merged

Conversation

@application-developer-DA
Copy link
Contributor

application-developer-DA commented Aug 14, 2018

This change is Reviewable

@@ -121,6 +122,10 @@ impl CGImageRef {
};
data_provider.copy_data()
}

pub fn cropped(&self, rect: CGRect) -> CGImage {
unsafe { CGImage::from_ptr(CGImageCreateWithImageInRect(self.as_ptr(), rect)) }

This comment has been minimized.

@jdm

jdm Aug 14, 2018

Member

This can return null if the rect defines an area that is not in the image: https://developer.apple.com/documentation/coregraphics/1454683-cgimagecreatewithimageinrect .

This comment has been minimized.

@application-developer-DA

application-developer-DA Aug 15, 2018

Author Contributor

Ah, you're totally right. Somehow I've missed that.

@application-developer-DA application-developer-DA force-pushed the snapview:cg-extensions branch from 080a424 to e6cd2a0 Aug 15, 2018
@application-developer-DA
Copy link
Contributor Author

application-developer-DA commented Aug 15, 2018

Updated the pull request to take into account the null value which CGImageCreateWithImageInRect() may return.

@jdm
Copy link
Member

jdm commented Aug 15, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Aug 15, 2018

📌 Commit e6cd2a0 has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Aug 15, 2018

Testing commit e6cd2a0 with merge f323ee0...

bors-servo added a commit that referenced this pull request Aug 15, 2018
Add support for image cropping

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/248)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Aug 15, 2018

☀️ Test successful - status-travis
Approved by: jdm
Pushing f323ee0 to master...

@bors-servo bors-servo merged commit e6cd2a0 into servo:master Aug 15, 2018
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

/// Returns a cropped image. If the `rect` specifies a rectangle which lies outside of the
/// image bounds, the `None` is returned.
pub fn cropped(&self, rect: CGRect) -> Option<CGImage> {

This comment has been minimized.

@jrmuizel

jrmuizel Aug 15, 2018

Collaborator

It might be good to include the fact that this uses CGImageCreateWithImageInRect and I'm pretty sure that makes it so that the underlying storage is shared between the two images.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.