Skip to content

Commit

Permalink
- Added features to compile libheif source-code form GitHub and lin…
Browse files Browse the repository at this point in the history
…k it statically.

- Deleted deriving `Copy` and `Clone` for structs with pointers
- Updated "bindings.rs" to correspond `libheif 1.18.2`.
  • Loading branch information
Cykooz committed Nov 6, 2024
1 parent d8e840f commit 1ca3b64
Show file tree
Hide file tree
Showing 10 changed files with 1,423 additions and 1,131 deletions.
26 changes: 11 additions & 15 deletions .github/workflows/check_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch: {}
workflow_dispatch: { }


env:
Expand All @@ -15,47 +15,43 @@ env:
jobs:
run_tests_on_linux:
name: Test `cargo check/test` on Ubuntu
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: root suid tar
run: sudo chown root:sudo /bin/tar && sudo chmod u+s /bin/tar

- name: Cache APT
id: cache-apt
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
/etc/apt
/var/lib/apt
key: ${{ runner.os }}-apt

- name: Add libheif PPA
if: steps.cache-apt.outputs.cache-hit != 'true'
run: sudo add-apt-repository -y ppa:strukturag/libheif

- name: Install libheif
- name: Install libheif dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libheif-dev libdav1d-dev
version: 1.16.2
packages: libheif-dev libdav1d-dev libnuma-dev
version: 1.18.2

- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: "true"

- name: Run tests
run: |
cargo check -p libheif-sys
cargo test
cargo check -p libheif-sys --features use-bindgen,embedded-libheif-plugins
cargo test --features use-bindgen,embedded-libheif-plugins
run_tests_on_windows:
name: Test `cargo check/test` on Windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Cache rust artifacts
uses: Swatinem/rust-cache@v2
Expand All @@ -65,7 +61,7 @@ jobs:

- name: Cache vcpkg
id: cache-vcpkg
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: "target/vcpkg"
key: ${{ runner.os }}-vcpkg
Expand Down
115 changes: 115 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,120 @@
# Change Log

## [Unreleased] - ReleaseDate

### Added

- Added features to compile `libheif` source-code form GitHub and
link it statically (not supported for Windows):
- `compile-libheif`
- `embedded-libheif-plugins`
- Updated "bindings.rs" to correspond `libheif 1.18.2`:
- added new values into `heif_suberror_code` "enum':
- `heif_suberror_code_heif_suberror_No_ispe_property`
- `heif_suberror_code_heif_suberror_Camera_intrinsic_matrix_undefined`
- `heif_suberror_code_heif_suberror_Camera_extrinsic_matrix_undefined`
- `heif_suberror_code_heif_suberror_Invalid_J2K_codestream`
- `heif_suberror_code_heif_suberror_No_vvcC_box`
- `heif_suberror_code_heif_suberror_No_icbr_box`
- `heif_suberror_code_heif_suberror_Decompression_invalid_data`
- `heif_suberror_code_heif_suberror_Compression_initialisation_error`
- `heif_suberror_code_heif_suberror_Unsupported_generic_compression_method`
- `heif_suberror_code_heif_suberror_No_matching_decoder_installed`
- added new values into `heif_compression_format` "enum':
- `heif_compression_format_heif_compression_HTJ2K`
- added new values into `heif_metadata_compression` "enum':
- `heif_metadata_compression_heif_metadata_compression_zlib`
- `heif_metadata_compression_heif_metadata_compression_brotli`
- added field `prefer_uncC_short_form` into struct `heif_encoding_options`
- added structs:
- `heif_camera_intrinsic_matrix`
- `heif_property_user_description`
- `heif_region_item`
- `heif_region`
- added enums:
- `heif_item_property_type`
- `heif_transform_mirror_direction`
- `heif_region_type`
- added functions:
- `heif_has_compatible_filetype`
- `heif_context_add_compatible_brand`
- `heif_context_encode_grid`
- `heif_context_add_generic_uri_metadata`
- `heif_context_get_number_of_items`
- `heif_context_get_list_of_item_IDs`
- `heif_item_get_item_type`
- `heif_item_is_item_hidden`
- `heif_item_get_mime_item_content_type`
- `heif_item_get_mime_item_content_encoding`
- `heif_item_get_uri_item_uri_type`
- `heif_item_get_item_name`
- `heif_item_set_item_name`
- `heif_item_get_item_data`
- `heif_release_item_data`
- `heif_context_get_item_references`
- `heif_release_item_references`
- `heif_context_add_item_reference`
- `heif_context_add_item_references`
- `heif_context_add_item`
- `heif_context_add_mime_item`
- `heif_context_add_precompressed_mime_item`
- `heif_context_add_uri_item`
- `heif_item_get_properties_of_type`
- `heif_item_get_transformation_properties`
- `heif_item_get_property_type`
- `heif_item_get_property_user_description`
- `heif_item_add_property_user_description`
- `heif_property_user_description_release`
- `heif_item_get_property_transform_mirror`
- `heif_item_get_property_transform_rotation_ccw`
- `heif_item_get_property_transform_crop_borders`
- `heif_item_add_raw_property`
- `heif_item_get_property_raw_size`
- `heif_item_get_property_raw_data`
- `heif_image_handle_get_number_of_region_items`
- `heif_image_handle_get_list_of_region_item_ids`
- `heif_context_get_region_item`
- `heif_region_item_get_id`
- `heif_region_item_release`
- `heif_region_item_get_reference_size`
- `heif_region_item_get_number_of_regions`
- `heif_region_item_get_list_of_regions`
- `heif_region_release`
- `heif_region_release_many`
- `heif_region_get_type`
- `heif_region_get_point`
- `heif_region_get_point_transformed`
- `heif_region_get_rectangle`
- `heif_region_get_rectangle_transformed`
- `heif_region_get_ellipse`
- `heif_region_get_ellipse_transformed`
- `heif_region_get_polygon_num_points`
- `heif_region_get_polygon_points`
- `heif_region_get_polygon_points_transformed`
- `heif_region_get_polyline_num_points`
- `heif_region_get_polyline_points`
- `heif_region_get_polyline_points_transformed`
- `heif_region_get_referenced_mask_ID`
- `heif_region_get_inline_mask_data_len`
- `heif_region_get_inline_mask_data`
- `heif_region_get_mask_image`
- `heif_image_handle_add_region_item`
- `heif_region_item_add_region_point`
- `heif_region_item_add_region_rectangle`
- `heif_region_item_add_region_ellipse`
- `heif_region_item_add_region_polygon`
- `heif_region_item_add_region_polyline`
- `heif_region_item_add_region_referenced_mask`
- `heif_region_item_add_region_inline_mask_data`
- `heif_region_item_add_region_inline_mask`

### Fixed

- **BREAKING**: Deleted deriving `Copy` and `Clone` for structs with pointers:
- `heif_plugin_info`
- `heif_decoding_options`
- `heif_encoding_options`

## [2.1.1] - 2024-05-08

- Fixed minimal required version of `libheif` specified in `build.rs`.
Expand Down
10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ libc = "0.2"
default = ["use-bindgen"]
# Use bindgen to generate bindings for libheif,
# instead using of pre-generated bindings.rs.
use-bindgen = ["dep:bindgen"]
use-bindgen = ["dep:bindgen", "dep:prettyplease"]
compile-libheif = ["dep:cmake"]
embedded-libheif-plugins = ["compile-libheif"]


[build-dependencies]
bindgen = { version = "0.69", optional = true }
pkg-config = "0.3"
prettyplease = { version = "0.2", optional = true }
bindgen = { version = "0.70.1", optional = true }
cmake = { version = "0.1.50", optional = true }


[target.'cfg(windows)'.build-dependencies]
Expand All @@ -36,7 +40,7 @@ walkdir = "2"

[package.metadata.vcpkg]
git = "https://github.com/microsoft/vcpkg"
tag = "2023.11.20"
tag = "2024.10.21"
dependencies = ["libheif"]


Expand Down
52 changes: 39 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,38 @@

## System dependencies

- `libheif-dev` >= 1.17.0 (any version if `use-bindgen` feature is enabled)
- `libheif-dev` >= 1.18.0 (any version if `use-bindgen` feature is enabled).
- `clang` - to generate rust bindings for `libheif`.
[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 `bindgen` crate.

<div class="warning">

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

</div>

### Linux

The crate uses `pkg-confing` to find installed `libheif`.

Also, you can enable all or one of next features to compile `libheif` from
`GitHub` and link it statically:

- `compile-libheif`
- `embedded-libheif-plugins`

<div class="warning">

Note: Static linked version of `libheif` doesn't have statically linked
it dependencies, such as `libde256`, `libaom` and other.

</div>

### Windows

The crate uses [vcpkg crate](https://crates.io/crates/vcpkg)
Expand All @@ -35,7 +52,7 @@ cargo vcpkg -v build
packages from scratch. It merges package requirements specified in
the `Cargo.toml` of crates in the dependency tree.

## Example of reading and decoding of HEIF-image
## Example of reading and decoding HEIF-image

```rust
use std::ffi;
Expand All @@ -49,43 +66,52 @@ fn read_and_decode_heic_file() {
lh::heif_init(ptr::null_mut());

let ctx = lh::heif_context_alloc();
assert_ne!(ctx, ptr::null_mut());
assert!(!ctx.is_null());

let c_name = ffi::CString::new("data/test.heif").unwrap();
let err = lh::heif_context_read_from_file(ctx, c_name.as_ptr(), ptr::null());
assert_eq!(err.code, 0);
let err = lh::heif_context_read_from_file(
ctx,
c_name.as_ptr(),
ptr::null()
);
assert_eq!(err.code, lh::heif_error_code_heif_error_Ok);

let mut handle = ptr::null_mut();
let err = lh::heif_context_get_primary_image_handle(ctx, &mut handle);
assert_eq!(err.code, 0);
assert_eq!(err.code, lh::heif_error_code_heif_error_Ok);
assert!(!handle.is_null());

let width = lh::heif_image_handle_get_width(handle);
assert_eq!(width, 4032);
let height = lh::heif_image_handle_get_height(handle);
assert_eq!(height, 3024);

let options = lh::heif_decoding_options_alloc();

let mut image = ptr::null_mut();
let options = lh::heif_decoding_options_alloc();
let err = lh::heif_decode_image(
handle,
&mut image,
lh::heif_colorspace_heif_colorspace_RGB,
lh::heif_chroma_heif_chroma_444,
lh::heif_chroma_heif_chroma_interleaved_RGB,
options,
);
lh::heif_decoding_options_free(options);
assert_eq!(err.code, 0);
assert_eq!(err.code, lh::heif_error_code_heif_error_Ok);
assert!(!image.is_null());

let colorspace = lh::heif_image_get_colorspace(image);
assert_eq!(colorspace, lh::heif_colorspace_heif_colorspace_RGB);
let chroma_format = lh::heif_image_get_chroma_format(image);
assert_eq!(chroma_format, lh::heif_chroma_heif_chroma_444);
let width = lh::heif_image_get_width(image, lh::heif_channel_heif_channel_R);
assert_eq!(chroma_format, lh::heif_chroma_heif_chroma_interleaved_RGB);
let width = lh::heif_image_get_width(
image,
lh::heif_channel_heif_channel_interleaved
);
assert_eq!(width, 4032);
let height = lh::heif_image_get_height(image, lh::heif_channel_heif_channel_R);
let height = lh::heif_image_get_height(
image,
lh::heif_channel_heif_channel_interleaved
);
assert_eq!(height, 3024);

lh::heif_context_free(ctx);
Expand Down
Loading

0 comments on commit 1ca3b64

Please sign in to comment.