Skip to content

Commit 8b3b399

Browse files
committed
- Added features v1_17 and v1_18 to choose a minimal
version of supported `libheif`. - Added feature `embedded-libheif` to compile and then link statically the embedded sources of `libheif` from the `libheif-sys` crate. - **BREAKING**: Features `compile-libheif`, `embedded-libheif-plugins` and `use-bindgen` were removed. - `libheif-sys` updated to version 4.0.0+1.19.7. - `vcpkg` updated to version 2025.03.19.
1 parent 725d7ae commit 8b3b399

15 files changed

+340
-170
lines changed

.github/workflows/check_and_test.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,15 @@ jobs:
4444
with:
4545
cache-on-failure: "true"
4646

47-
- name: Run tests
47+
- name: Run tests for v1.17
4848
run: |
49-
cargo check -p libheif-rs --features embedded-libheif-plugins
50-
cargo test --features embedded-libheif-plugins
49+
cargo check -p libheif-rs --features embedded-libheif,v1_17
50+
cargo test --features embedded-libheif,v1_17
51+
52+
- name: Run tests for v1.18
53+
run: |
54+
cargo check -p libheif-rs --features embedded-libheif,v1_18
55+
cargo test --features embedded-libheif,v1_18
5156
5257
5358
# run_tests_on_windows:

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# Change Log
22

3+
## [Unreleased] - ReleaseDate
4+
5+
### Added
6+
7+
- Added features `v1_17` and `v1_18` to choose a minimal
8+
version of supported `libheif`.
9+
- Added feature `embedded-libheif` to compile and then link statically
10+
the embedded sources of `libheif` from the `libheif-sys` crate.
11+
12+
### Changes
13+
14+
- **BREAKING**: Features `compile-libheif`, `embedded-libheif-plugins` and
15+
`use-bindgen` were removed.
16+
- `libheif-sys` updated to version 4.0.0+1.19.7.
17+
- `vcpkg` updated to version 2025.03.19.
18+
319
## [1.1.0] - 2025-01-23
420

521
### Added

Cargo.toml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,24 @@ documentation = "https://docs.rs/crate/libheif-rs"
1212

1313

1414
[dependencies]
15+
cfg-if = "1.0"
1516
enumn = "0.1.14"
1617
four-cc = "0.4"
17-
libc = "0.2.169"
18-
libheif-sys = { version = "3.1", default-features = false }
18+
libc = "0.2.171"
19+
libheif-sys = "4.0"
1920

2021

2122
[features]
22-
compile-libheif = ["libheif-sys/compile-libheif"]
23-
embedded-libheif-plugins = ["libheif-sys/embedded-libheif-plugins"]
24-
# Use bindgen to generate bindings for libheif,
25-
# instead using of pre-generated bindings.rs.
26-
use-bindgen = ["libheif-sys/use-bindgen"]
23+
default = ["latest"]
24+
v1_17 = ["libheif-sys/v1_17"]
25+
v1_18 = ["v1_17", "libheif-sys/v1_18"]
26+
latest = ["v1_18"]
27+
embedded-libheif = ["libheif-sys/embedded-libheif"]
2728

2829

2930
[dev-dependencies]
3031
kamadak-exif = "0.6.1"
31-
tempfile = "3.15"
32+
tempfile = "3.19"
3233

3334

3435
[profile.release]
@@ -42,7 +43,7 @@ codegen-units = 1
4243

4344
[package.metadata.vcpkg]
4445
git = "https://github.com/microsoft/vcpkg"
45-
tag = "2025.01.13"
46+
tag = "2025.03.19"
4647
dependencies = ["libheif"]
4748

4849

README.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,47 @@
11
# libheif-rs
22

3-
Safe wrapper around the libheif-sys crate for parsing heif/heic files.
3+
Safe wrapper around the [libheif-sys](https://github.com/Cykooz/libheif-sys)
4+
crate for parsing heif/heic files.
45

56
[CHANGELOG](https://github.com/Cykooz/libheif-rs/blob/master/CHANGELOG.md)
67

78
## System dependencies
89

9-
- `libheif-dev` >= 1.18.0
10+
- `libheif-dev` >= 1.17.0
11+
12+
## Minimal supported libheif version
13+
14+
Minimal supported version of `libheif` library is 1.17.
15+
But there are some functions in the crate that require a newer version of
16+
`libheif` library.
17+
18+
You may specify a minimal version of `libheif` library that is required for you.
19+
To do this, enable the corresponding feature `v1_17` or `v1_18`.
20+
21+
Example:
22+
23+
```toml
24+
[dependencies]
25+
libheif = { version = "2.0", default-features = false, features = ["v1_17"] }
26+
```
27+
28+
There is also the `latest` feature. It always corresponds to
29+
the maximal supported by the crate version of `libheif` API.
30+
This feature is enabled by default.
1031

1132
### Linux
1233

13-
Crate `libheif-sys` uses `pkg-confing` to find installed `libheif`.
34+
Crate `libheif-sys` uses `pkg-confing` command to find installed `libheif`.
35+
36+
You can also enable `embedded-libheif` feature to compile `libheif` from
37+
embedded into `libheif-sys` crate sources and then link it statically.
38+
39+
<div class="warning">
40+
41+
Note: Static linked version of `libheif` doesn't have statically linked
42+
it dependencies, such as `libde256`, `libaom` and other.
43+
44+
</div>
1445

1546
### Windows
1647

@@ -29,7 +60,7 @@ packages from scratch. It merges package requirements specified in
2960
the `Cargo.toml` of crates in the dependency tree.
3061

3162
PS: I tried build `libheif` for Windows, but `libheif-rs` tests
32-
filed because `libheif` doesn't have any encoder plugins available.
63+
failed because `libheif` for Windows doesn't have any encoder plugins available.
3364

3465
## Examples
3566

rustfmt.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
unstable_features = true
2+
3+
imports_granularity = "Module"
4+
group_imports = "StdExternalCrate"

src/context.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use std::ffi;
1+
#[cfg(feature = "v1_18")]
22
use std::num::NonZeroU16;
33
use std::os::raw::c_void;
4-
use std::ptr;
4+
use std::{ffi, ptr};
55

66
use four_cc::FourCC;
77
use libheif_sys as lh;
@@ -71,7 +71,8 @@ impl HeifContext<'static> {
7171

7272
/// # Safety
7373
///
74-
/// The given pointer must be valid.
74+
/// The given pointer must be valid.
75+
#[cfg(feature = "v1_18")]
7576
pub(crate) unsafe fn from_ptr(ctx: *mut lh::heif_context) -> HeifContext<'static> {
7677
HeifContext {
7778
inner: ctx,
@@ -80,7 +81,7 @@ impl HeifContext<'static> {
8081
}
8182
}
8283

83-
impl<'a> HeifContext<'a> {
84+
impl HeifContext<'_> {
8485
/// Create a new context from bytes.
8586
///
8687
/// The provided memory buffer is not copied.
@@ -259,6 +260,8 @@ impl<'a> HeifContext<'a> {
259260
/// * `encoding_options` - Optional, may be None.
260261
///
261262
/// Returns an error if `tiles` slice is empty.
263+
#[cfg(feature = "v1_18")]
264+
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
262265
pub fn encode_grid(
263266
&mut self,
264267
tiles: &[Image],
@@ -385,10 +388,10 @@ impl<'a> HeifContext<'a> {
385388
}
386389
}
387390

388-
impl<'a> Drop for HeifContext<'a> {
391+
impl Drop for HeifContext<'_> {
389392
fn drop(&mut self) {
390393
unsafe { lh::heif_context_free(self.inner) };
391394
}
392395
}
393396

394-
unsafe impl<'a> Send for HeifContext<'a> {}
397+
unsafe impl Send for HeifContext<'_> {}

src/encoder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ pub enum CompressionFormat {
3939
Uncompressed = lh::heif_compression_format_heif_compression_uncompressed as _,
4040
/// Rust equivalent of [lh::heif_compression_format_heif_compression_mask]
4141
Mask = lh::heif_compression_format_heif_compression_mask as _,
42+
#[cfg(feature = "v1_18")]
43+
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
4244
/// Rust equivalent of [lh::heif_compression_format_heif_compression_HTJ2K]
4345
HtJ2k = lh::heif_compression_format_heif_compression_HTJ2K as _,
4446
}

src/errors.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,39 @@ pub enum HeifErrorSubCode {
105105
EncoderEncoding = lh::heif_suberror_code_heif_suberror_Encoder_encoding as _,
106106
EncoderCleanup = lh::heif_suberror_code_heif_suberror_Encoder_cleanup as _,
107107
TooManyRegions = lh::heif_suberror_code_heif_suberror_Too_many_regions as _,
108+
#[cfg(feature = "v1_18")]
109+
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
108110
NoIspeProperty = lh::heif_suberror_code_heif_suberror_No_ispe_property as _,
111+
#[cfg(feature = "v1_18")]
112+
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
109113
CameraIntrinsicMatrixUndefined =
110114
lh::heif_suberror_code_heif_suberror_Camera_intrinsic_matrix_undefined as _,
115+
#[cfg(feature = "v1_18")]
116+
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
111117
CameraExtrinsicMatrixUndefined =
112118
lh::heif_suberror_code_heif_suberror_Camera_extrinsic_matrix_undefined as _,
119+
#[cfg(feature = "v1_18")]
120+
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
113121
InvalidJ2kCodeStream = lh::heif_suberror_code_heif_suberror_Invalid_J2K_codestream as _,
122+
#[cfg(feature = "v1_18")]
123+
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
114124
NoVvccBox = lh::heif_suberror_code_heif_suberror_No_vvcC_box as _,
125+
#[cfg(feature = "v1_18")]
126+
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
115127
NoIcbrBox = lh::heif_suberror_code_heif_suberror_No_icbr_box as _,
128+
#[cfg(feature = "v1_18")]
129+
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
116130
DecompressionInvalidData = lh::heif_suberror_code_heif_suberror_Decompression_invalid_data as _,
131+
#[cfg(feature = "v1_18")]
132+
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
117133
CompressionInitialisationError =
118134
lh::heif_suberror_code_heif_suberror_Compression_initialisation_error as _,
135+
#[cfg(feature = "v1_18")]
136+
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
119137
UnsupportedGenericCompressionMethod =
120138
lh::heif_suberror_code_heif_suberror_Unsupported_generic_compression_method as _,
139+
#[cfg(feature = "v1_18")]
140+
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
121141
NoMatchingDecoderInstalled =
122142
lh::heif_suberror_code_heif_suberror_No_matching_decoder_installed as _,
123143
/// This value is used when library `libheif` returns unknown value of error sub-code.

src/image_handle.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
use four_cc::FourCC;
2-
use libheif_sys as lh;
31
use std::ffi::CString;
42
use std::mem::MaybeUninit;
53
use std::os::raw::c_char;
64
use std::ptr;
75

8-
use crate::regions::RegionItem;
6+
use four_cc::FourCC;
7+
use libheif_sys as lh;
8+
99
use crate::utils::cstr_to_str;
1010
use crate::{
11-
ColorProfileNCLX, ColorProfileRaw, ColorProfileType, ColorSpace, HeifContext, HeifError,
12-
HeifErrorCode, HeifErrorSubCode, ImageMetadata, Result,
11+
ColorProfileNCLX, ColorProfileRaw, ColorProfileType, ColorSpace, HeifError, HeifErrorCode,
12+
HeifErrorSubCode, ImageMetadata, Result,
1313
};
1414

15+
cfg_if::cfg_if! {
16+
if #[cfg(feature = "v1_18")] {
17+
use crate::regions::RegionItem;
18+
use crate::HeifContext;
19+
}
20+
}
21+
1522
/// Encoded image.
1623
pub struct ImageHandle {
1724
pub(crate) inner: *mut lh::heif_image_handle,
@@ -24,6 +31,7 @@ impl ImageHandle {
2431
ImageHandle { inner: handle }
2532
}
2633

34+
#[cfg(feature = "v1_18")]
2735
fn context(&self) -> HeifContext {
2836
unsafe { HeifContext::from_ptr(lh::heif_image_handle_get_context(self.inner)) }
2937
}
@@ -357,6 +365,8 @@ impl ImageHandle {
357365
///
358366
/// The concept is to add the region item, then add one or more regions
359367
/// to the region item.
368+
#[cfg(feature = "v1_18")]
369+
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
360370
pub fn add_region_item(
361371
&mut self,
362372
reference_width: u32,
@@ -380,6 +390,8 @@ impl ImageHandle {
380390
Ok(RegionItem::new(item_ptr))
381391
}
382392

393+
#[cfg(feature = "v1_18")]
394+
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
383395
/// Get the region items attached to the image.
384396
pub fn region_items(&self) -> Vec<RegionItem> {
385397
let num_items = unsafe { lh::heif_image_handle_get_number_of_region_items(self.inner) };

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ mod image;
2424
mod image_handle;
2525
mod metadata;
2626
mod reader;
27+
#[cfg(feature = "v1_18")]
28+
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
2729
pub mod regions;
2830
mod utils;

0 commit comments

Comments
 (0)