Top Related Projects
libheif is an HEIF and AVIF file format decoder and encoder.
libavif - Library for encoding and decoding .avif files
Free Lossless Audio Codec
A massively spiffy yet delicately unobtrusive compression library.
Main libjpeg-turbo repository
Mirror only. Please do not send pull requests. See https://chromium.googlesource.com/webm/libwebp/+/HEAD/CONTRIBUTING.md.
Quick Overview
The nokiatech/heif repository is an open-source implementation of the HEIF (High Efficiency Image File Format) standard. It provides a set of tools and libraries for encoding, decoding, and manipulating HEIF files, which are designed to offer improved compression and functionality compared to traditional image formats like JPEG.
Pros
- Supports advanced features of HEIF, including multi-image containers and image sequences
- Provides both encoding and decoding capabilities
- Cross-platform compatibility (Windows, macOS, Linux)
- Actively maintained with regular updates and bug fixes
Cons
- Limited documentation and examples for some advanced features
- Steeper learning curve compared to more established image format libraries
- Dependency on external libraries for certain functionalities
- Not as widely adopted as other image format libraries
Code Examples
- Reading an HEIF file:
#include "heifpp.h"
int main() {
heif::Context ctx;
ctx.readFromFile("image.heic");
auto handle = ctx.getTopLevelImage(0);
auto img = handle.decode(heif_colorspace_RGB, heif_chroma_interleaved_RGB);
// Process the image data
}
- Writing an HEIF file:
#include "heifpp.h"
int main() {
heif::Context ctx;
heif::Image image;
image.create(width, height, heif_colorspace_RGB, heif_chroma_interleaved_RGB);
// Fill image data
ctx.encodeImage(image, heif_compression_HEVC);
ctx.writeToFile("output.heic");
}
- Extracting metadata from an HEIF file:
#include "heifpp.h"
int main() {
heif::Context ctx;
ctx.readFromFile("image.heic");
auto handle = ctx.getTopLevelImage(0);
auto metadata = handle.getMetadata();
for (const auto& item : metadata) {
std::cout << "Type: " << item.type() << ", Size: " << item.data().size() << std::endl;
}
}
Getting Started
To use the nokiatech/heif library in your project:
- Clone the repository:
git clone https://github.com/nokiatech/heif.git
- Build the library using CMake:
cd heif mkdir build && cd build cmake .. make
- Include the necessary headers in your C++ project:
#include "heifpp.h"
- Link against the built library when compiling your project.
For more detailed instructions and advanced usage, refer to the documentation in the repository.
Competitor Comparisons
libheif is an HEIF and AVIF file format decoder and encoder.
Pros of libheif
- More actively maintained with frequent updates
- Broader platform support, including Windows and macOS
- Better documentation and examples for integration
Cons of libheif
- Slightly larger codebase, potentially more complex to understand
- May have a steeper learning curve for beginners
Code Comparison
libheif:
#include <libheif/heif.h>
heif_context* ctx = heif_context_alloc();
heif_context_read_from_file(ctx, "image.heic", nullptr);
heif_image_handle* handle;
heif_context_get_primary_image_handle(ctx, &handle);
heif:
#include "Heif.h"
using namespace HEIF;
Heif* heif = Heif::create();
heif->load("image.heic");
auto primaryImage = heif->getPrimaryItem();
Both libraries provide C++ APIs for working with HEIF files, but libheif offers a more C-style interface, while heif uses a more object-oriented approach. libheif's API is generally considered more flexible and easier to integrate into existing projects.
libavif - Library for encoding and decoding .avif files
Pros of libavif
- More active development with frequent updates and contributions
- Better documentation and examples for integration
- Wider industry support and adoption due to AV1 backing
Cons of libavif
- Larger file size for encoded images compared to HEIF
- Potentially slower encoding/decoding times for complex images
- Less mature ecosystem, as AVIF is a newer format
Code Comparison
libavif:
avifResult result = avifEncoderWrite(encoder, image, &raw);
if (result != AVIF_RESULT_OK) {
fprintf(stderr, "Failed to encode: %s\n", avifResultToString(result));
return 1;
}
heif:
auto context = heif::Context();
context.encode_image(image, encoder, options);
context.write(writer);
Both libraries offer straightforward APIs for encoding images, but libavif's approach is more C-style, while heif uses C++ with a more object-oriented design. The heif library generally requires less boilerplate code for basic operations.
Free Lossless Audio Codec
Pros of FLAC
- Lossless audio compression with excellent compression ratios
- Widely supported across many devices and platforms
- Open-source and royalty-free
Cons of FLAC
- Limited to audio compression only
- Larger file sizes compared to lossy formats like MP3
Code Comparison
FLAC (encoding example):
FLAC__StreamEncoder *encoder = FLAC__stream_encoder_new();
FLAC__stream_encoder_set_verify(encoder, true);
FLAC__stream_encoder_set_compression_level(encoder, 5);
FLAC__stream_encoder_init_file(encoder, output_filename, NULL, NULL);
HEIF (encoding example):
HeifContext context;
context.setOutputFile(output_filename);
context.setCompressionQuality(50);
context.addImage(input_image);
context.encode();
Summary
FLAC is a specialized lossless audio codec, while HEIF is a container format for images and image sequences. FLAC excels in audio compression and has widespread support, but is limited to audio. HEIF offers more versatility for image storage and compression but may have less universal support. The code examples show basic encoding setup for each format, highlighting their different focuses and APIs.
A massively spiffy yet delicately unobtrusive compression library.
Pros of zlib
- Widely adopted and battle-tested compression library
- Smaller codebase, easier to integrate and maintain
- Supports a broader range of programming languages and platforms
Cons of zlib
- Limited to general-purpose compression, not optimized for specific file formats
- Lacks modern features like multi-threading or GPU acceleration
Code Comparison
zlib (compression example):
z_stream strm;
deflateInit(&strm, Z_DEFAULT_COMPRESSION);
deflate(&strm, Z_FINISH);
deflateEnd(&strm);
heif (writing an image):
heif::Context ctx;
heif::ImageHandle handle;
heif::Image image;
ctx.encode_image(image, heif::Encoder(heif::Encoder::encoder_type::hevc), nullptr);
ctx.write_to_file("output.heif");
Summary
zlib is a versatile, widely-used compression library suitable for various applications. heif, on the other hand, is specifically designed for the HEIF image format, offering more specialized features but with a narrower focus. zlib's simplicity and broad compatibility make it easier to integrate, while heif provides more advanced functionality for working with modern image formats.
Main libjpeg-turbo repository
Pros of libjpeg-turbo
- Widely adopted and supported across various platforms and applications
- Offers significant performance improvements over standard libjpeg
- Maintains full compatibility with existing JPEG standards
Cons of libjpeg-turbo
- Limited to JPEG format, lacking support for modern image formats like HEIF
- Does not provide advanced features like HDR or multi-image containers
Code Comparison
libjpeg-turbo:
#include <turbojpeg.h>
tjhandle tjInstance = tjInitCompress();
tjCompress2(tjInstance, sourceBuffer, width, pitch, height,
TJPF_RGB, &jpegBuf, &jpegSize, TJSAMP_444, quality,
TJFLAG_FASTDCT);
heif:
#include <libheif/heif.h>
struct heif_context* ctx = heif_context_alloc();
heif_context_encode_image(ctx, image, encoder, nullptr, nullptr);
heif_context_get_primary_image_handle(ctx, &handle);
heif_image_handle_get_data(handle, &data, &size);
The code snippets demonstrate basic image compression operations for each library. libjpeg-turbo focuses on JPEG compression, while heif provides encoding capabilities for the HEIF format.
Mirror only. Please do not send pull requests. See https://chromium.googlesource.com/webm/libwebp/+/HEAD/CONTRIBUTING.md.
Pros of libwebp
- More mature and widely adopted, with broader browser and platform support
- Smaller file sizes for lossless compression in many cases
- Faster encoding and decoding performance
Cons of libwebp
- Limited support for advanced features like HDR and wide color gamut
- Less flexibility in terms of metadata and image sequences
Code Comparison
heif example:
HeifContext* ctx = heif_context_alloc();
heif_context_read_from_file(ctx, "image.heic", nullptr);
heif_image_handle* handle;
heif_context_get_primary_image_handle(ctx, &handle);
libwebp example:
WebPDecoderConfig config;
WebPInitDecoderConfig(&config);
WebPDecode(data, data_size, &config);
uint8_t* output = config.output.u.RGBA.rgba;
Summary
While libwebp offers better compression and wider support, heif provides more advanced features and flexibility. The choice between them depends on specific project requirements and target platforms.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
High Efficiency Image File Format (HEIF)
HEIF is a visual media container format standardized by the Moving Picture Experts Group (MPEG) for storage and sharing of images and image sequences. It is based on the well-known ISO Base Media File Format (ISOBMFF) standard. HEIF Reader/Writer Engine is an implementation of HEIF standard in order to demonstrate its powerful features and capabilities.
Please follow this link to access HEIF Web-Site. You can also check the Wiki pages for more information.
For MIAF specific code, please switch to the MIAF branch.
News:
[25.06.2020] v3.6.0 Release: Added support for several new properties, image items with decoding dependencies, Extended type box and Type combination box, associating properties for entity groups, and reader support for segmented tracks. Minor improvements and code cleanup.
[10.07.2019] v3.5.0 Release: Improved support for JPEGs and edit lists. Bug fixes, minor improvements and code cleanup.
[06.11.2018] v3.4.0 Release: Java API improvements. Bug fixes, code cleanup and robustness improvements.
[13.06.2018] v3.3.0 Release: Java desktop build added, Java API includes track and image sequence as well as entity grouping support.
[06.04.2018] v3.2 Release. Two new APIs added, a Java API which wraps the C++ libraries using JNI and a convenience C++ API (which is used by the Java API) that wraps the underlying reader and writer. The Java API is expected to remain relatively stable, however the new C++ API will most likely change in the future.
[14.03.2018] v3.1 Release. Reader API update, bug fixes and examples update.
[05.03.2018] Code updated and tagged v3.0. Writer executable replaced with writer library / API. Implementation is based on HEIF standard specification ISO/IEC 23008-12:2017 that is available from iso.org web pages.
[09.03.2017] ISO/IEC 23008-12 second edition includes support for the interchange of multi-layered images. The source code now includes structures that are specified in this second edition. Simple support for AVC is also added. Minor bug fixes are included in this update. Example configuration files for generating multi-layered streams can be found in the Wiki.
[24.02.2016] HEIF source code and website is updated to reflect the latest HEIF specification changes and various fixes. Please note that backwards compatibility is not maintained during this update.
[24.02.2016] HEIF conformance test candidate files can be found here
Features:
HEIF is a media container format. It is not an image or video encoder per se. Hence, the quality of the visual media depends highly on the proper usage of visual media encoder (e.g. HEVC). Current standard allows containing HEVC/AVC/JPEG encoded bitstreams. This can be easily extended to future visual media codecs. It has many powerful features which are currently not present in other image file formats. Some of these features are:
- Encapsulate images coded using HEVC/SHVC/MV-HEVC/AVC/JPEG.
- Encapsulate image sequences coded using HEVC/SHVC/MV-HEVC/AVC.
- Storage based on widely adopted ISO Base Media File Format (ISOBMFF)
- Supports efficient storage of image bursts and cinemagraphs
- Supports computational photography use cases
- Supports both lossy and lossless image data storage
- A better and easy way to distribute still images, image collections and related metadata.
Please follow this link to see HEIF file examples.
Contents of the Repository:
This repository contains the following items:
- ISO Base Media File Format (ISOBMFF) box parse/write source code (under srcs/common/)
- HEIF Reader API and Library (under srcs/api/reader/)
- HEIF Writer API and Library (under srcs/api/writer/)
- HEIF Reader/Writer Java API (under srcs/api-java/)
- HEIF Reader/Writer convenience C++ API (under srcs/api-cpp/)
- HEIF Reader API Usage Example Code (under srcs/examples/)
- HEIF Source Code Documentation (Doxygen generator under docs/)
- HEIF Web Site Content (in gh-pages branch)
- HEIF Reader JavaScript Implementation (in gh-pages branch)
Building source:
Prerequisites: cmake and compiler supporting C++11 in PATH.
cd heif/build
cmake --help
cmake ../srcs -G"<Generator listed by above command for your target platform>"
cmake --build .
Building Java API for Windows or Linux
Prerequisites: Java version 8 or newer, Gradle.
First build the C/C++ library as described above.
After that
cd heif/build/java-desktop
gradle build
Note that in order to run the Java API you need to have the HEIF JNI library built in the earlier step (heifjni.dll or heifjni.so) in the Java library search path.
Building Java API for Android:
Prerequisites: Android SDK & NDK Import the project files under heif/build/android into Android Studio and build the library
See wiki page for more information and platform specific instructions.
License:
Please see LICENSE.TXT file for the terms of use of the contents of this repository.
All the example media files (*.heic, *.png, *.jpg, *.gif) in this repository are under copyright © Nokia Technologies 2015-2021.
For more information/questions/source code/commercial licensing related issues, please contact: heif@nokia.com
Copyright (c) 2015-2021, Nokia Technologies Ltd.
All rights reserved.
Top Related Projects
libheif is an HEIF and AVIF file format decoder and encoder.
libavif - Library for encoding and decoding .avif files
Free Lossless Audio Codec
A massively spiffy yet delicately unobtrusive compression library.
Main libjpeg-turbo repository
Mirror only. Please do not send pull requests. See https://chromium.googlesource.com/webm/libwebp/+/HEAD/CONTRIBUTING.md.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot