Auto merge of #248 - snapview:cg-extensions, r=jdm
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 -->
This commit is contained in:
@@ -5,6 +5,7 @@ use core_foundation::base::{CFRetain, CFTypeID};
|
||||
use core_foundation::data::CFData;
|
||||
use color_space::CGColorSpace;
|
||||
use data_provider::{CGDataProviderRef, CGDataProvider};
|
||||
use geometry::CGRect;
|
||||
use libc::size_t;
|
||||
use foreign_types::{ForeignType, ForeignTypeRef};
|
||||
|
||||
@@ -121,6 +122,17 @@ impl CGImageRef {
|
||||
};
|
||||
data_provider.copy_data()
|
||||
}
|
||||
|
||||
/// 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> {
|
||||
let image_ptr = unsafe { CGImageCreateWithImageInRect(self.as_ptr(), rect) };
|
||||
if !image_ptr.is_null() {
|
||||
Some(unsafe { CGImage::from_ptr(image_ptr) })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[link(name = "CoreGraphics", kind = "framework")]
|
||||
@@ -146,6 +158,7 @@ extern {
|
||||
shouldInterpolate: bool,
|
||||
intent: u32)
|
||||
-> ::sys::CGImageRef;
|
||||
fn CGImageCreateWithImageInRect(image: ::sys::CGImageRef, rect: CGRect) -> ::sys::CGImageRef;
|
||||
|
||||
//fn CGImageGetAlphaInfo(image: ::sys::CGImageRef) -> CGImageAlphaInfo;
|
||||
//fn CGImageCreateCopyWithColorSpace(image: ::sys::CGImageRef, space: ::sys::CGColorSpaceRef) -> ::sys::CGImageRef
|
||||
|
||||
Reference in New Issue
Block a user