Skip to content

Commit

Permalink
cg image props example
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Oct 30, 2024
1 parent 3caef6d commit 6e91a0e
Show file tree
Hide file tree
Showing 3 changed files with 326 additions and 4 deletions.
26 changes: 26 additions & 0 deletions cidre/examples/cg-image-props/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::path::PathBuf;

use cidre::{cf, cg};
use clap::Parser;

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
/// Image file path to analyse
path: PathBuf,
}

fn main() {
let args = Args::parse();
let url = cf::Url::with_path(&args.path, false).unwrap();
let src = cg::ImageSrc::with_url(&url, None).unwrap();
let count = src.count();
println!("images count: {count}");
let props = src.props(None).unwrap();
props.show();

for i in 0..count {
let img = src.image_at(i, None).unwrap();
img.show();
}
}
67 changes: 65 additions & 2 deletions cidre/src/cg/image/source.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{arc, cf, define_cf_type};
use crate::{arc, cf, cg, define_cf_type};

#[repr(i32)]
pub enum Status {
Expand All @@ -24,11 +24,13 @@ impl Src {
unsafe { CGImageSourceCopyTypeIdentifiers() }
}

#[doc(alias = "CGImageSourceCreateWithData")]
#[inline]
pub fn with_data(data: &cf::Data, options: Option<&cf::Dictionary>) -> Option<arc::R<Src>> {
unsafe { CGImageSourceCreateWithData(data, options) }
}

#[doc(alias = "CGImageSourceCreateWithURL")]
#[inline]
pub fn with_url(url: &cf::Url, options: Option<&cf::Dictionary>) -> Option<arc::R<Src>> {
unsafe { CGImageSourceCreateWithURL(url, options) }
Expand All @@ -40,19 +42,57 @@ impl Src {
}

/// Return the number of images (not including thumbnails) in the image source
#[doc(alias = "CGImageSourceGetCount")]
#[inline]
pub fn count(&self) -> usize {
unsafe { CGImageSourceGetCount(self) }
}

#[doc(alias = "CGImageSourceGetStatus")]
#[inline]
pub fn status(&self) -> Status {
unsafe { CGImageSourceGetStatus(self) }
}

#[doc(alias = "CGImageSourceCopyProperties")]
#[inline]
pub fn props(&self, options: Option<&cf::Dictionary>) -> Option<arc::R<cf::Dictionary>> {
unsafe { CGImageSourceCopyProperties(self, options) }
}

#[doc(alias = "CGImageSourceCopyPropertiesAtIndex")]
#[inline]
pub fn props_at(
&self,
index: usize,
options: Option<&cf::Dictionary>,
) -> Option<arc::R<cf::Dictionary>> {
unsafe { CGImageSourceCopyPropertiesAtIndex(self, index, options) }
}

#[doc(alias = "CGImageSourceCreateImageAtIndex")]
#[inline]
pub fn image_at(
&self,
index: usize,
options: Option<&cf::Dictionary>,
) -> Option<arc::R<cg::Image>> {
unsafe { CGImageSourceCreateImageAtIndex(self, index, options) }
}

#[doc(alias = "CGImageSourceCreateThumbnailAtIndex")]
#[inline]
pub fn thumbnail_at(
&self,
index: usize,
options: Option<&cf::Dictionary>,
) -> Option<arc::R<cg::Image>> {
unsafe { CGImageSourceCreateThumbnailAtIndex(self, index, options) }
}
}

#[link(name = "ImageIO", kind = "framework")]
extern "C" {
extern "C-unwind" {
fn CGImageSourceGetTypeID() -> cf::TypeId;
fn CGImageSourceCopyTypeIdentifiers() -> arc::R<cf::ArrayOf<cf::String>>;

Expand All @@ -71,6 +111,29 @@ extern "C" {
fn CGImageSourceGetCount(isrc: &Src) -> usize;

fn CGImageSourceGetStatus(isrc: &Src) -> Status;

fn CGImageSourceCopyProperties(
isrc: &Src,
options: Option<&cf::Dictionary>,
) -> Option<arc::R<cf::Dictionary>>;

fn CGImageSourceCopyPropertiesAtIndex(
isrc: &Src,
index: usize,
options: Option<&cf::Dictionary>,
) -> Option<arc::R<cf::Dictionary>>;

fn CGImageSourceCreateImageAtIndex(
isrc: &Src,
index: usize,
options: Option<&cf::Dictionary>,
) -> Option<arc::R<cg::Image>>;

fn CGImageSourceCreateThumbnailAtIndex(
isrc: &Src,
index: usize,
options: Option<&cf::Dictionary>,
) -> Option<arc::R<cg::Image>>;
}

#[cfg(test)]
Expand Down
Loading

0 comments on commit 6e91a0e

Please sign in to comment.