Skip to content

Commit

Permalink
fix versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Feb 26, 2025
1 parent ef04aaa commit 700f14f
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 3 deletions.
7 changes: 5 additions & 2 deletions cidre/src/cg/image/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub type AnimationBlock = blocks::EscBlock<fn(index: usize, image: &cg::Image, s
pub mod err {
use crate::os::Error;

/// NULL or invalid parameter passed to API
/// None/null or invalid parameter passed to API
#[doc(alias = "kCGImageAnimationStatus_ParameterError")]
pub const PARAM_ERR: Error = Error::new_unchecked(-22140);

Expand All @@ -27,7 +27,10 @@ pub mod err {
pub const ALLOC_FAILURE: Error = Error::new_unchecked(-22143);
}

define_cf_type!(OptKey(cf::String));
define_cf_type!(
#[doc(alias = "CGImageAnimationOptions")]
OptKey(cf::String)
);

pub type Opts = cf::DictionaryOf<OptKey, cf::Number>;

Expand Down
1 change: 1 addition & 0 deletions cidre/src/cm/format_description.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,7 @@ unsafe extern "C-unwind" {
format_description_out: *mut Option<arc::R<FormatDesc>>,
) -> os::Status;

#[cfg(feature = "cv")]
fn CMVideoFormatDescriptionCreateForImageBuffer(
allocator: Option<&cf::Allocator>,
image_buffer: &cv::ImageBuf,
Expand Down
1 change: 1 addition & 0 deletions cidre/src/cm/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ impl Tag {
Self::new(category, TagDataType::Flags, TagValue(val))
}

#[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)]
pub fn with_cf_dictionary(dict: &cf::Dictionary) -> Self {
unsafe { CMTagMakeFromDictionary(dict) }
}
Expand Down
84 changes: 83 additions & 1 deletion cidre/src/cm/tag_collection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{cf, define_cf_type};
use crate::{api, arc, cf, cm, define_cf_type, os};

/// Errors returned from the cm::TagCollection routines.
#[doc(alias = "CMTagCollectionError")]
Expand Down Expand Up @@ -58,13 +58,95 @@ define_cf_type!(

impl TagCollection {
#[doc(alias = "CMTagCollectionGetTypeID")]
#[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)]
#[inline]
pub fn type_id() -> cf::TypeId {
unsafe { CMTagCollectionGetTypeID() }
}

#[doc(alias = "CMTagCollectionCreate")]
#[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)]
pub unsafe fn create_in(
tags: *const cm::Tag,
tag_count: cm::ItemCount,
out: *mut Option<arc::R<Self>>,
allocator: Option<&cf::Allocator>,
) -> os::Status {
unsafe { CMTagCollectionCreate(allocator, tags, tag_count, out) }
}

#[doc(alias = "CMTagCollectionCreate")]
#[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)]
pub fn with_tags(tags: &[cm::Tag]) -> Result<arc::R<Self>, os::Error> {
unsafe {
let mut res = None;
Self::create_in(tags.as_ptr(), tags.len() as _, &mut res, None).result()?;
Ok(res.unwrap_unchecked())
}
}

#[doc(alias = "CMTagCollectionGetCount")]
#[inline]
#[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)]
pub fn count(&self) -> cm::ItemCount {
unsafe { CMTagCollectionGetCount(self) }
}

#[inline]
#[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)]
pub fn len(&self) -> usize {
self.count() as _
}

#[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)]
#[inline]
pub fn is_empty(&self) -> bool {
// for versions below available self.len() is unsafe
#[allow(unused_unsafe)]
unsafe {
self.len() == 0
}
}

#[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)]
#[inline]
pub fn contains(&self, val: cm::Tag) -> bool {
unsafe { CMTagCollectionContainsTag(self, val) }
}
}

#[link(name = "CoreMedia", kind = "framework")]
#[api::weak]
unsafe extern "C-unwind" {

#[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)]
fn CMTagCollectionGetTypeID() -> cf::TypeId;

#[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)]
fn CMTagCollectionCreate(
allocator: Option<&cf::Allocator>,
tags: *const cm::Tag,
tag_count: cm::ItemCount,
collection_out: *mut Option<arc::R<cm::TagCollection>>,
) -> os::Status;

#[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)]
fn CMTagCollectionGetCount(tag_collection: &TagCollection) -> cm::ItemCount;

#[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)]
fn CMTagCollectionContainsTag(tag_collection: &TagCollection, val: cm::Tag) -> bool;
}

#[cfg(test)]
mod tests {
use crate::cm;

#[test]
fn basics() {
let empty = cm::TagCollection::with_tags(&[]).unwrap();
assert!(empty.is_empty());

let tag = cm::Tag::with_f64(cm::TagCategory::MediaType, 0.0);
assert!(!empty.contains(tag));
}
}

0 comments on commit 700f14f

Please # to comment.