Skip to content

Commit

Permalink
- Added method assign_thumbnail for HeifContext structure.
Browse files Browse the repository at this point in the history
- **BREAKING**: Added default feature `use-bindgen` to control that type of
  binding will be used by `libheif-sys` crate (pre-generated or
  generated on the fly by `bindgen`)
- Fixed creating instance of `ColorProfileType` from instance of
  `heif_color_profile_type` on Windows.
  • Loading branch information
Cykooz committed Sep 12, 2023
1 parent 09eea1d commit 862be95
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Change Log

## [Unreleased] - ReleaseDate

### Added

- Added method `assign_thumbnail` for `HeifContext` structure.
- **BREAKING**: Added default feature `use-bindgen` to control that type of
binding will be used by `libheif-sys` crate (pre-generated or
generated on the fly by `bindgen`)

### Fixed

- Fixed creating instance of `ColorProfileType` from instance of
`heif_color_profile_type` on Windows.

## [0.21.0] - 2023-09-08

### Added
Expand Down
10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ four-cc = "0.3"
libc = "0.2"


[features]
default = ["use-bindgen"]
# Use bindgen to generate bindings for libheif,
# instead using of pre-generated bindings.rs.
use-bindgen = ["libheif-sys/use-bindgen"]


[dependencies.libheif-sys]
version = "1.16"
version = "2"
default-features = false


[dev-dependencies]
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ Safe wrapper around the libheif-sys crate for parsing heif/heic files.

## System dependencies

- libheif-dev >= 1.16.0
- `libheif-dev` >= 1.16.0
- `clang` - to generate rust bindings for `libheif` in `libheif-sys` crate.
[See bindgen requirements.](https://rust-lang.github.io/rust-bindgen/requirements.html)

`clang` wouldn't be needed if you disable `use-bindgen` feature.
In this case the pre-generated file `bindings.rs` will be used
instead of generating it on the fly with help of `binden` crate.

Warning: `bindings.rs` file was generated under x64 linux and may
not work as expected under x32 architectures or other operating systems.

### Linux

Expand Down
16 changes: 16 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,22 @@ impl<'a> HeifContext<'a> {
Ok(Some(ImageHandle::new(handle)))
}

/// Assign `master_image_handle` as the thumbnail image of `thumbnail_image_handle`.
pub fn assign_thumbnail(
&mut self,
master_image_handle: &ImageHandle,
thumbnail_image_handle: &ImageHandle,
) -> Result<()> {
unsafe {
let err = lh::heif_context_assign_thumbnail(
self.inner,
master_image_handle.inner,
thumbnail_image_handle.inner,
);
HeifError::from_heif_error(err)
}
}

pub fn set_primary_image(&mut self, image_handle: &mut ImageHandle) -> Result<()> {
unsafe {
let err = lh::heif_context_set_primary_image(self.inner, image_handle.inner);
Expand Down
3 changes: 2 additions & 1 deletion src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ impl Image {
result.set_len(size);
}
let c_profile_type = unsafe { lh::heif_image_get_color_profile_type(self.inner) };
let profile_type = ColorProfileType::from(c_profile_type);
// `c_profile_type` on Windows will be i32, so we need to cast it to u32
let profile_type = ColorProfileType::from(c_profile_type as u32);

Some(ColorProfileRaw {
typ: profile_type,
Expand Down
3 changes: 2 additions & 1 deletion src/image_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ impl ImageHandle {
result.set_len(size);
}
let c_profile_type = unsafe { lh::heif_image_handle_get_color_profile_type(self.inner) };
let profile_type = ColorProfileType::from(c_profile_type);
// `c_profile_type` on Windows will be i32, so we need to cast it to u32
let profile_type = ColorProfileType::from(c_profile_type as u32);

Some(ColorProfileRaw {
typ: profile_type,
Expand Down

0 comments on commit 862be95

Please sign in to comment.