libheif
Loading...
Searching...
No Matches
heif_encoding.h
Go to the documentation of this file.
1/*
2 * HEIF codec.
3 * Copyright (c) 2017-2025 Dirk Farin <dirk.farin@gmail.com>
4 *
5 * This file is part of libheif.
6 *
7 * libheif is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * libheif is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with libheif. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef LIBHEIF_HEIF_ENCODING_H
22#define LIBHEIF_HEIF_ENCODING_H
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28#include <stddef.h>
29#include <stdint.h>
30
32#include <libheif/heif_image.h>
33#include <libheif/heif_context.h>
34#include <libheif/heif_brands.h>
35#include <libheif/heif_color.h>
36
37// Forward declaration. The full definition lives in heif_uncompressed.h.
38// heif_encoding_options only stores a pointer, so a forward typedef is enough here
39// and avoids a circular include (heif_uncompressed.h pulls in heif.h, which pulls in this header).
41
42
43// ----- encoder -----
44
49
50// A description of the encoder's capabilities and name.
52
53// A configuration parameter of the encoder. Each encoder implementation may have a different
54// set of parameters. For the most common settings (e.q. quality), special functions to set
55// the parameters are provided.
57
58
59// Quick check whether there is an enoder available for the given format.
60// Note that the encoder may be limited to a certain subset of features (e.g. only 8 bit, only lossy).
61// You will have to query the specific capabilities further.
62LIBHEIF_API
63int heif_have_encoder_for_format(heif_compression_format format);
64
65// Get a list of available encoders. You can filter the encoders by compression format and name.
66// Use format_filter==heif_compression_undefined and name_filter==NULL as wildcards.
67// The returned list of encoders is sorted by their priority (which is a plugin property).
68// The number of encoders is returned, which are not more than 'count' if (out_encoders != nullptr).
69// By setting out_encoders==nullptr, you can query the number of encoders, 'count' is ignored.
70// Note: to get the actual encoder from the descriptors returned here, use heif_context_get_encoder().
71LIBHEIF_API
72int heif_get_encoder_descriptors(heif_compression_format format_filter,
73 const char* name_filter,
74 const heif_encoder_descriptor** out_encoders,
75 int count);
76
77// Return a long, descriptive name of the encoder (including version information).
78LIBHEIF_API
80
81// Return a short, symbolic name for identifying the encoder.
82// This name should stay constant over different encoder versions.
83LIBHEIF_API
85
86LIBHEIF_API
87heif_compression_format
89
90LIBHEIF_API
92
93LIBHEIF_API
95
96
97// Get an encoder instance that can be used to actually encode images from a descriptor.
98LIBHEIF_API
101 heif_encoder** out_encoder);
102
103// Get an encoder for the given compression format. If there are several encoder plugins
104// for this format, the encoder with the highest plugin priority will be returned.
105LIBHEIF_API
107 heif_compression_format format,
108 heif_encoder**);
109
113LIBHEIF_API
115
116// Get the encoder name from the encoder itself.
117LIBHEIF_API
119
120
121// --- Encoder Parameters ---
122
123// Libheif supports settings parameters through specialized functions and through
124// generic functions by parameter name. Sometimes, the same parameter can be set
125// in both ways.
126// We consider it best practice to use the generic parameter functions only in
127// dynamically generated user interfaces, as no guarantees are made that some specific
128// parameter names are supported by all plugins.
129
130
131// Set a 'quality' factor (0-100). How this is mapped to actual encoding parameters is
132// encoder dependent.
133LIBHEIF_API
135
136LIBHEIF_API
138
139// level should be between 0 (= none) to 4 (= full)
140LIBHEIF_API
142
143// Get a generic list of encoder parameters.
144// Each encoder may define its own, additional set of parameters.
145// You do not have to free the returned list.
146LIBHEIF_API
148
149// Return the parameter name.
150LIBHEIF_API
152
153
160
161// Return the parameter type.
162LIBHEIF_API
164
165// DEPRECATED. Use heif_encoder_parameter_get_valid_integer_values() instead.
166LIBHEIF_API
168 int* have_minimum_maximum,
169 int* minimum, int* maximum);
170
171// If integer is limited by a range, have_minimum and/or have_maximum will be != 0 and *minimum, *maximum is set.
172// If integer is limited by a fixed set of values, *num_valid_values will be >0 and *out_integer_array is set.
173LIBHEIF_API
175 int* have_minimum, int* have_maximum,
176 int* minimum, int* maximum,
177 int* num_valid_values,
178 const int** out_integer_array);
179
180LIBHEIF_API
182 const char* const** out_stringarray);
183
184
185LIBHEIF_API
187 const char* parameter_name,
188 int value);
189
190LIBHEIF_API
192 const char* parameter_name,
193 int* value);
194
195// TODO: name should be changed to heif_encoder_get_valid_integer_parameter_range
196LIBHEIF_API // DEPRECATED.
198 const char* parameter_name,
199 int* have_minimum_maximum,
200 int* minimum, int* maximum);
201
202LIBHEIF_API
204 const char* parameter_name,
205 int value);
206
207LIBHEIF_API
209 const char* parameter_name,
210 int* value);
211
212LIBHEIF_API
214 const char* parameter_name,
215 const char* value);
216
217LIBHEIF_API
219 const char* parameter_name,
220 char* value, int value_size);
221
222// returns a NULL-terminated list of valid strings or NULL if all values are allowed
223LIBHEIF_API
225 const char* parameter_name,
226 const char* const** out_stringarray);
227
228LIBHEIF_API
230 const char* parameter_name,
231 int* have_minimum, int* have_maximum,
232 int* minimum, int* maximum,
233 int* num_valid_values,
234 const int** out_integer_array);
235
236// Set a parameter of any type to the string value.
237// Integer values are parsed from the string.
238// Boolean values can be "true"/"false"/"1"/"0"
239//
240// x265 encoder specific note:
241// When using the x265 encoder, you may pass any of its parameters by
242// prefixing the parameter name with 'x265:'. Hence, to set the 'ctu' parameter,
243// you will have to set 'x265:ctu' in libheif.
244// Note that there is no checking for valid parameters when using the prefix.
245LIBHEIF_API
247 const char* parameter_name,
248 const char* value);
249
250// Get the current value of a parameter of any type as a human readable string.
251// The returned string is compatible with heif_encoder_set_parameter().
252LIBHEIF_API
254 const char* parameter_name,
255 char* value_ptr, int value_size);
256
257// Query whether a specific parameter has a default value.
258LIBHEIF_API
260 const char* parameter_name);
261
262
263// The orientation values are defined equal to the EXIF Orientation tag.
275
276
277LIBHEIF_API
279
280
282{
283 uint8_t version;
284
285 // version 1 options
286
287 uint8_t save_alpha_channel; // default: true
288
289 // version 2 options
290
291 // DEPRECATED. This option is not required anymore. Its value will be ignored.
293
294 // version 3 options
295
297
298 // version 4 options
299
300 // Set this to the NCLX parameters to be used in the output image or set to NULL
301 // when the same parameters as in the input image should be used.
302 heif_color_profile_nclx* output_nclx_profile;
303
305
306 // version 5 options
307
308 // libheif will generate irot/imir boxes to match these orientations
310
311 // version 6 options
312
313 heif_color_conversion_options color_conversion_options;
314
315 // version 7 options
316
317 // Set this to true to use compressed form of uncC where possible.
319
320 // version 8 options
321
322 // Optional 'unci'-specific encoding parameters (compression method, and future fields
323 // such as interleave type and padding).
324 //
325 // Default: nullptr
327
328 // TODO: we should add a flag to force MIAF compatible outputs. E.g. this will put restrictions on grid tile sizes and
329 // might add a clap box when the grid output size does not match the color subsampling factors.
330 // Since some of these constraints have to be known before actually encoding the image, "forcing MIAF compatibility"
331 // could also be a flag in the heif_context.
333
334LIBHEIF_API
336
337LIBHEIF_API
339
340LIBHEIF_API
342
343
344// Compress the input image.
345// Returns a handle to the coded image in 'out_image_handle' unless out_image_handle = NULL.
346// 'options' should be NULL for now.
347// The first image added to the context is also automatically set the primary image, but
348// you can change the primary image later with heif_context_set_primary_image().
349LIBHEIF_API
351 const heif_image* image,
352 heif_encoder* encoder,
353 const heif_encoding_options* options,
354 heif_image_handle** out_image_handle);
355
356// offsets[] should either be NULL (all offsets==0) or an array of size 2*nImages with x;y offset pairs.
357// If background_rgba is NULL, the background is transparent.
358LIBHEIF_API
360 uint32_t image_width,
361 uint32_t image_height,
362 uint16_t nImages,
363 const heif_item_id* image_ids,
364 int32_t* offsets,
365 const uint16_t background_rgba[4],
366 heif_image_handle** out_iovl_image_handle);
367
368LIBHEIF_API
370 heif_image_handle* image_handle);
371
372// Set the major brand of the file.
373// If this function is not called, the major brand is determined automatically from
374// the image or sequence content.
375LIBHEIF_API
377 heif_brand2 major_brand);
378
379// Add a compatible brand that is now added automatically by libheif when encoding images (e.g. some application brands like 'geo1').
380LIBHEIF_API
382 heif_brand2 compatible_brand);
383
394LIBHEIF_API
396
397// --- deprecated functions ---
398
399// DEPRECATED, typo in function name
400LIBHEIF_API
402
403// DEPRECATED, typo in function name
404LIBHEIF_API
406
407// DEPRECATED: use heif_get_encoder_descriptors() instead.
408// Get a list of available encoders. You can filter the encoders by compression format and name.
409// Use format_filter==heif_compression_undefined and name_filter==NULL as wildcards.
410// The returned list of encoders is sorted by their priority (which is a plugin property).
411// The number of encoders is returned, which are not more than 'count' if (out_encoders != nullptr).
412// By setting out_encoders==nullptr, you can query the number of encoders, 'count' is ignored.
413// Note: to get the actual encoder from the descriptors returned here, use heif_context_get_encoder().
414LIBHEIF_API
415int heif_context_get_encoder_descriptors(heif_context*, // TODO: why do we need this parameter?
416 heif_compression_format format_filter,
417 const char* name_filter,
418 const heif_encoder_descriptor** out_encoders,
419 int count);
420
421#ifdef __cplusplus
422}
423#endif
424
425#endif
const char * heif_encoder_parameter_get_name(const heif_encoder_parameter *)
void heif_context_add_compatible_brand(heif_context *ctx, heif_brand2 compatible_brand)
heif_error heif_encoder_parameter_get_valid_integer_range(const heif_encoder_parameter *, int *have_minimum_maximum, int *minimum, int *maximum)
heif_error heif_context_add_overlay_image(heif_context *ctx, uint32_t image_width, uint32_t image_height, uint16_t nImages, const heif_item_id *image_ids, int32_t *offsets, const uint16_t background_rgba[4], heif_image_handle **out_iovl_image_handle)
void heif_context_set_major_brand(heif_context *ctx, heif_brand2 major_brand)
struct heif_encoder_parameter heif_encoder_parameter
Definition heif_encoding.h:56
heif_error heif_encoder_get_parameter(heif_encoder *, const char *parameter_name, char *value_ptr, int value_size)
const heif_encoder_parameter *const * heif_encoder_list_parameters(heif_encoder *)
int heif_have_encoder_for_format(heif_compression_format format)
heif_error heif_encoder_parameter_integer_valid_values(heif_encoder *, const char *parameter_name, int *have_minimum, int *have_maximum, int *minimum, int *maximum, int *num_valid_values, const int **out_integer_array)
heif_error heif_context_set_primary_image(heif_context *, heif_image_handle *image_handle)
void heif_encoding_options_free(heif_encoding_options *)
int heif_get_encoder_descriptors(heif_compression_format format_filter, const char *name_filter, const heif_encoder_descriptor **out_encoders, int count)
heif_error heif_encoder_get_parameter_string(heif_encoder *, const char *parameter_name, char *value, int value_size)
struct heif_unci_image_parameters heif_unci_image_parameters
Definition heif_encoding.h:40
heif_error heif_encoder_get_parameter_integer(heif_encoder *, const char *parameter_name, int *value)
heif_error heif_context_encode_image(heif_context *, const heif_image *image, heif_encoder *encoder, const heif_encoding_options *options, heif_image_handle **out_image_handle)
heif_orientation
Definition heif_encoding.h:265
@ heif_orientation_rotate_180
Definition heif_encoding.h:268
@ heif_orientation_rotate_90_cw_then_flip_horizontally
Definition heif_encoding.h:270
@ heif_orientation_rotate_90_cw_then_flip_vertically
Definition heif_encoding.h:272
@ heif_orientation_flip_vertically
Definition heif_encoding.h:269
@ heif_orientation_rotate_270_cw
Definition heif_encoding.h:273
@ heif_orientation_flip_horizontally
Definition heif_encoding.h:267
@ heif_orientation_normal
Definition heif_encoding.h:266
@ heif_orientation_rotate_90_cw
Definition heif_encoding.h:271
heif_error heif_encoder_set_lossless(heif_encoder *, int enable)
heif_error heif_encoder_set_logging_level(heif_encoder *, int level)
const char * heif_encoder_descriptor_get_name(const heif_encoder_descriptor *)
struct heif_encoder_descriptor heif_encoder_descriptor
Definition heif_encoding.h:51
heif_error heif_encoder_parameter_get_valid_string_values(const heif_encoder_parameter *, const char *const **out_stringarray)
int heif_encoder_descriptor_supportes_lossy_compression(const heif_encoder_descriptor *)
heif_error heif_encoder_parameter_integer_valid_range(heif_encoder *, const char *parameter_name, int *have_minimum_maximum, int *minimum, int *maximum)
int heif_encoder_has_default(heif_encoder *, const char *parameter_name)
heif_error heif_encoder_set_parameter(heif_encoder *, const char *parameter_name, const char *value)
heif_encoding_options * heif_encoding_options_alloc(void)
const char * heif_encoder_descriptor_get_id_name(const heif_encoder_descriptor *)
heif_error heif_encoder_set_parameter_string(heif_encoder *, const char *parameter_name, const char *value)
void heif_context_set_unif(heif_context *ctx, int flag)
Enable the unified ID namespace ('unif' brand).
int heif_context_get_encoder_descriptors(heif_context *, heif_compression_format format_filter, const char *name_filter, const heif_encoder_descriptor **out_encoders, int count)
void heif_encoding_options_copy(heif_encoding_options *dst, const heif_encoding_options *src)
void heif_encoder_release(heif_encoder *)
Release the encoder object after use.
int heif_encoder_descriptor_supportes_lossless_compression(const heif_encoder_descriptor *)
int heif_encoder_descriptor_supports_lossy_compression(const heif_encoder_descriptor *)
heif_error heif_encoder_set_lossy_quality(heif_encoder *, int quality)
int heif_encoder_descriptor_supports_lossless_compression(const heif_encoder_descriptor *)
heif_error heif_encoder_parameter_string_valid_values(heif_encoder *, const char *parameter_name, const char *const **out_stringarray)
heif_orientation heif_orientation_concat(heif_orientation first, heif_orientation second)
heif_compression_format heif_encoder_descriptor_get_compression_format(const heif_encoder_descriptor *)
heif_error heif_encoder_set_parameter_boolean(heif_encoder *, const char *parameter_name, int value)
const char * heif_encoder_get_name(const heif_encoder *)
struct heif_encoder heif_encoder
Opaque object that represents the encoder used to code the images.
Definition heif_encoding.h:48
heif_error heif_context_get_encoder_for_format(heif_context *context, heif_compression_format format, heif_encoder **)
heif_error heif_encoder_set_parameter_integer(heif_encoder *, const char *parameter_name, int value)
heif_error heif_encoder_get_parameter_boolean(heif_encoder *, const char *parameter_name, int *value)
heif_error heif_encoder_parameter_get_valid_integer_values(const heif_encoder_parameter *, int *have_minimum, int *have_maximum, int *minimum, int *maximum, int *num_valid_values, const int **out_integer_array)
heif_error heif_context_get_encoder(heif_context *context, const heif_encoder_descriptor *, heif_encoder **out_encoder)
enum heif_encoder_parameter_type heif_encoder_parameter_get_type(const heif_encoder_parameter *)
heif_encoder_parameter_type
Definition heif_encoding.h:155
@ heif_encoder_parameter_type_boolean
Definition heif_encoding.h:157
@ heif_encoder_parameter_type_integer
Definition heif_encoding.h:156
@ heif_encoder_parameter_type_string
Definition heif_encoding.h:158
struct heif_image_handle heif_image_handle
Definition heif_library.h:90
uint32_t heif_item_id
Definition heif_library.h:92
struct heif_context heif_context
Definition heif_library.h:89
Definition heif_encoding.h:282
uint8_t prefer_uncC_short_form
Definition heif_encoding.h:318
uint8_t save_alpha_channel
Definition heif_encoding.h:287
heif_color_profile_nclx * output_nclx_profile
Definition heif_encoding.h:302
uint8_t version
Definition heif_encoding.h:283
uint8_t macOS_compatibility_workaround_no_nclx_profile
Definition heif_encoding.h:304
uint8_t macOS_compatibility_workaround
Definition heif_encoding.h:292
heif_orientation image_orientation
Definition heif_encoding.h:309
uint8_t save_two_colr_boxes_when_ICC_and_nclx_available
Definition heif_encoding.h:296
const heif_unci_image_parameters * unci_parameters
Definition heif_encoding.h:326
heif_color_conversion_options color_conversion_options
Definition heif_encoding.h:313