• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/workflows/H16-Dec-2020-378310

cmake/modules/H16-Dec-2020-436385

examples/H03-May-2022-3,7262,510

extra/H16-Dec-2020-452280

fuzzing/H03-May-2022-43

gdk-pixbuf/H03-May-2022-229161

gnome/H16-Dec-2020-3630

go/H16-Dec-2020-1,6841,301

libheif/H03-May-2022-25,28717,299

m4/H16-Dec-2020-219199

scripts/H03-May-2022-7,2764,779

tests/H16-Dec-2020-17,29513,127

third-party/H16-Dec-2020-4329

.gitignoreH A D16-Dec-2020474 4139

COPYINGH A D16-Dec-202043.3 KiB872703

CPPLINT.cfgH A D16-Dec-202050 32

Makefile.amH A D16-Dec-2020434 2824

README.mdH A D16-Dec-20207.7 KiB239159

appveyor.ymlH A D16-Dec-2020787 3022

autogen.shH A D16-Dec-20201.2 KiB4319

build-emscripten.shH A D16-Dec-20202 KiB6252

configure.acH A D16-Dec-202011.5 KiB334294

libheif.pc.inH A D16-Dec-2020466 1917

README.md

1# libheif
2
3[![Build Status](https://github.com/strukturag/libheif/workflows/build/badge.svg)](https://github.com/strukturag/libheif/actions) [![Build Status](https://ci.appveyor.com/api/projects/status/github/strukturag/libheif?svg=true)](https://ci.appveyor.com/project/strukturag/libheif) [![Coverity Scan Build Status](https://scan.coverity.com/projects/16641/badge.svg)](https://scan.coverity.com/projects/strukturag-libheif)
4
5
6libheif is an ISO/IEC 23008-12:2017 HEIF and AVIF (AV1 Image File Format) file format decoder and encoder.
7
8HEIF and AVIF are new image file formats employing HEVC (h.265) or AV1 image coding, respectively, for the
9best compression ratios currently possible.
10
11libheif makes use of [libde265](https://github.com/strukturag/libde265) for HEIF image decoding and x265 for encoding.
12For AVIF, libaom, dav1d, or rav1e are used as codecs.
13
14
15## Supported features
16
17libheif has support for decoding
18* tiled images
19* alpha channels
20* thumbnails
21* reading EXIF and XMP metadata
22* reading the depth channel
23* multiple images in a file
24* image transformations (crop, mirror, rotate)
25* overlay images
26* plugin interface to add alternative codecs for additional formats (AVC, JPEG)
27* decoding of files while downloading (e.g. extract image size before file has been completely downloaded)
28* reading color profiles
29* heix images (10 and 12 bit, chroma 4:2:2)
30
31The encoder supports:
32* lossy compression with adjustable quality
33* lossless compression
34* alpha channels
35* thumbnails
36* save multiple images to a file
37* save EXIF and XMP metadata
38* writing color profiles
39* 10 and 12 bit images
40* monochrome images
41
42## API
43
44The library has a C API for easy integration and wide language support.
45Note that the API is still work in progress and may still change.
46
47The decoder automatically supports both HEIF and AVIF through the same API. No changes are required to existing code to support AVIF.
48The encoder can be switched between HEIF and AVIF simply by setting `heif_compression_HEVC` or `heif_compression_AV1`
49to `heif_context_get_encoder_for_format()`.
50
51Loading the primary image in an HEIF file is as easy as this:
52
53```C
54heif_context* ctx = heif_context_alloc();
55heif_context_read_from_file(ctx, input_filename, nullptr);
56
57// get a handle to the primary image
58heif_image_handle* handle;
59heif_context_get_primary_image_handle(ctx, &handle);
60
61// decode the image and convert colorspace to RGB, saved as 24bit interleaved
62heif_image* img;
63heif_decode_image(handle, &img, heif_colorspace_RGB, heif_chroma_interleaved_RGB, nullptr);
64
65int stride;
66const uint8_t* data = heif_image_get_plane_readonly(img, heif_channel_interleaved, &stride);
67```
68
69Writing an HEIF file can be done like this:
70
71```C
72heif_context* ctx = heif_context_alloc();
73
74// get the default encoder
75heif_encoder* encoder;
76heif_context_get_encoder_for_format(ctx, heif_compression_HEVC, &encoder);
77
78// set the encoder parameters
79heif_encoder_set_lossy_quality(encoder, 50);
80
81// encode the image
82heif_image* image; // code to fill in the image omitted in this example
83heif_context_encode_image(ctx, image, encoder, nullptr, nullptr);
84
85heif_encoder_release(encoder);
86
87heif_context_write_to_file(context, "output.heic");
88```
89
90See the header file `heif.h` for the complete C API.
91
92There is also a C++ API which is a header-only wrapper to the C API.
93Hence, you can use the C++ API and still be binary compatible.
94Code using the C++ API is much less verbose than using the C API directly.
95
96There is also an experimental Go API, but this is not stable yet.
97
98
99## Compiling
100
101This library uses either a standard autoconf/automake build system or CMake.
102
103When using autoconf, run `./autogen.sh` to build the configuration scripts,
104then call `./configure` and `make`.
105Make sure that you compile and install [libde265](https://github.com/strukturag/libde265)
106first, so that the configuration script will find this.
107Preferably, download the `frame-parallel` branch of libde265, as this uses a
108more recent API than the version in the `master` branch.
109Also install x265 and its development files if you want to use HEIF encoding.
110
111For AVIF support, make sure that libaom is installed.
112
113### macOS
114
1151. Install dependencies with Homebrew
116
117    ```
118    brew install automake make pkg-config x265 libde265 libjpeg
119    ```
120
121
1221. Configure and build project
123
124    ```
125    ./autogen.sh
126    ./configure
127    make
128    ```
129
130### Windows
131
132Libheif is included in [Vcpkg](https://github.com/Microsoft/vcpkg/).
133
134
135### Adding rav1e encoder for AVIF
136
137* Install `cargo`.
138* Install `cargo-c` by executing
139```
140cargo install --force cargo-c
141```
142* Run the `rav1e.cmd` script in directory `third-party` to download rav1e and compile it.
143
144When running `cmake` or `configure`, make sure that the environment variable
145`PKG_CONFIG_PATH` includes the absolute path to `third-party/rav1e/dist/lib/pkgconfig`.
146
147
148### Adding dav1d decoder for AVIF
149
150* Install [`meson`](https://mesonbuild.com/).
151* Run the `dav1d.cmd` script in directory `third-party` to download dav1d and compile it.
152
153When running `cmake` or `configure`, make sure that the environment variable
154`PKG_CONFIG_PATH` includes the absolute path to `third-party/dav1d/dist/lib/x86_64-linux-gnu/pkgconfig`.
155
156
157## Language bindings
158
159* .NET Platform (C#, F#, and other languages): [libheif-sharp](https://github.com/0xC0000054/libheif-sharp)
160* C++: part of libheif
161* Go: part of libheif
162* JavaScript: by compilation with emscripten (see below)
163* NodeJS module: [libheif-js](https://www.npmjs.com/package/libheif-js)
164* Python: [pyheif](https://pypi.org/project/pyheif/)
165* Rust: [libheif-sys](https://github.com/Cykooz/libheif-sys)
166
167Languages that can directly interface with C libraries (e.g., Swift, C#) should work out of the box.
168
169
170## Compiling to JavaScript
171
172libheif can also be compiled to JavaScript using
173[emscripten](http://kripken.github.io/emscripten-site/).
174See the `build-emscripten.sh` for further information.
175
176
177## Online demo
178
179Check out this [online demo](https://strukturag.github.io/libheif/).
180This is `libheif` running in JavaScript in your browser.
181
182
183## Example programs
184
185Some example programs are provided in the `examples` directory.
186The program `heif-convert` converts all images stored in an HEIF/AVIF file to JPEG or PNG.
187`heif-enc` lets you convert JPEG files to HEIF/AVIF.
188The program `heif-info` is a simple, minimal decoder that dumps the file structure to the console.
189
190For example convert `example.heic` to JPEGs and one of the JPEGs back to HEIF:
191
192```
193cd examples/
194./heif-convert example.heic example.jpeg
195./heif-enc example-1.jpeg -o example.heif
196```
197
198In order to convert `example-1.jpeg` to AVIF use:
199```
200./heif-enc example-1.jpeg -A -o example.avif
201```
202
203There is also a GIMP plugin using libheif [here](https://github.com/strukturag/heif-gimp-plugin).
204
205
206## HEIF/AVIF thumbnails for the Gnome desktop
207
208The program `heif-thumbnailer` can be used as an HEIF/AVIF thumbnailer for the Gnome desktop.
209The matching Gnome configuration files are in the `gnome` directory.
210Place the files `heif.xml` and 'avif.xml' into `/usr/share/mime/packages` and `heif.thumbnailer` into `/usr/share/thumbnailers`.
211You may have to run `update-mime-database /usr/share/mime` to update the list of known MIME types.
212
213
214## gdk-pixbuf loader
215
216libheif also includes a gdk-pixbuf loader for HEIF/AVIF images. 'make install' will copy the plugin
217into the system directories. However, you will still have to run `gdk-pixbuf-query-loaders --update-cache`
218to update the gdk-pixbuf loader database.
219
220
221## Software using libheif
222
223* GIMP
224* Krita
225* ImageMagick
226* digiKam 7.0.0
227* libvips
228* [Kodi HEIF image decoder plugin](https://kodi.wiki/view/Add-on:HEIF_image_decoder)
229
230
231## License
232
233The libheif is distributed under the terms of the GNU Lesser General Public License.
234The sample applications are distributed under the terms of the MIT License.
235
236See COPYING for more details.
237
238Copyright (c) 2017-2020 Struktur AG Contact: Dirk Farin farin@struktur.de
239