Skip to content

Commit 199f024

Browse files
authored
heifsave: expose libheif/aom auto_tiles feature (#4191)
Allows the aom encoder to determine the optimum tile count based on the output dimensions and available threads. This can improve multi-core utilisation, reducing processing time and/or memory usage at the cost of slightly increased file sizes.
1 parent 19b499d commit 199f024

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

cplusplus/include/vips/VImage8.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3446,6 +3446,7 @@ class VImage : public VObject {
34463446
* - **effort** -- CPU effort, int.
34473447
* - **subsample_mode** -- Select chroma subsample operation mode, VipsForeignSubsample.
34483448
* - **encoder** -- Select encoder to use, VipsForeignHeifEncoder.
3449+
* - **auto_tiles** -- Determine optimum tile count, bool.
34493450
* - **keep** -- Which metadata to retain, VipsForeignKeep.
34503451
* - **background** -- Background value, std::vector<double>.
34513452
* - **page_height** -- Set page height for multipage save, int.
@@ -3467,6 +3468,7 @@ class VImage : public VObject {
34673468
* - **effort** -- CPU effort, int.
34683469
* - **subsample_mode** -- Select chroma subsample operation mode, VipsForeignSubsample.
34693470
* - **encoder** -- Select encoder to use, VipsForeignHeifEncoder.
3471+
* - **auto_tiles** -- Determine optimum tile count, bool.
34703472
* - **keep** -- Which metadata to retain, VipsForeignKeep.
34713473
* - **background** -- Background value, std::vector<double>.
34723474
* - **page_height** -- Set page height for multipage save, int.
@@ -3488,6 +3490,7 @@ class VImage : public VObject {
34883490
* - **effort** -- CPU effort, int.
34893491
* - **subsample_mode** -- Select chroma subsample operation mode, VipsForeignSubsample.
34903492
* - **encoder** -- Select encoder to use, VipsForeignHeifEncoder.
3493+
* - **auto_tiles** -- Determine optimum tile count, bool.
34913494
* - **keep** -- Which metadata to retain, VipsForeignKeep.
34923495
* - **background** -- Background value, std::vector<double>.
34933496
* - **page_height** -- Set page height for multipage save, int.

libvips/foreign/foreign.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,6 +2366,7 @@ vips_heifload_source(VipsSource *source, VipsImage **out, ...)
23662366
* * @effort: %gint, encoding effort
23672367
* * @subsample_mode: #VipsForeignSubsample, chroma subsampling mode
23682368
* * @encoder: #VipsForeignHeifEncoder, select encoder to use
2369+
* * @auto_tiles: %gboolean, determine optimum tile count
23692370
*
23702371
* Write a VIPS image to a file in HEIF format.
23712372
*
@@ -2389,6 +2390,11 @@ vips_heifload_source(VipsSource *source, VipsImage **out, ...)
23892390
*
23902391
* Use @encoder to set the encode library to use, e.g. aom, SVT-AV1, rav1e etc.
23912392
*
2393+
* When using the aom encoder, set @auto_tiles to determine the optimum
2394+
* number of tiles based on dimensions and available threads. This can
2395+
* improve multi-core utilisation and/or reduce peak memory consumption
2396+
* at the expense of slightly increased file size.
2397+
*
23922398
* See also: vips_image_write_to_file(), vips_heifload().
23932399
*
23942400
* Returns: 0 on success, -1 on error.
@@ -2422,6 +2428,7 @@ vips_heifsave(VipsImage *in, const char *filename, ...)
24222428
* * @effort: %gint, encoding effort
24232429
* * @subsample_mode: #VipsForeignSubsample, chroma subsampling mode
24242430
* * @encoder: #VipsForeignHeifEncoder, select encoder to use
2431+
* * @auto_tiles: %gboolean, determine optimum tile count
24252432
*
24262433
* As vips_heifsave(), but save to a memory buffer.
24272434
*
@@ -2476,6 +2483,7 @@ vips_heifsave_buffer(VipsImage *in, void **buf, size_t *len, ...)
24762483
* * @effort: %gint, encoding effort
24772484
* * @subsample_mode: #VipsForeignSubsample, chroma subsampling mode
24782485
* * @encoder: #VipsForeignHeifEncoder, select encoder to use
2486+
* * @auto_tiles: %gboolean, determine optimum tile count
24792487
*
24802488
* As vips_heifsave(), but save to a target.
24812489
*

libvips/foreign/heifsave.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ typedef struct _VipsForeignSaveHeif {
130130
*/
131131
int speed;
132132

133+
/* Auto tiles (currently aom only).
134+
*/
135+
gboolean auto_tiles;
136+
133137
} VipsForeignSaveHeif;
134138

135139
typedef VipsForeignSaveClass VipsForeignSaveHeifClass;
@@ -648,6 +652,14 @@ vips_foreign_save_heif_build(VipsObject *object)
648652
}
649653
#endif /*HAVE_HEIF_ENCODER_PARAMETER_GET_VALID_INTEGER_VALUES*/
650654

655+
error = heif_encoder_set_parameter_boolean(heif->encoder,
656+
"auto-tiles", heif->auto_tiles);
657+
if (error.code &&
658+
error.subcode != heif_suberror_Unsupported_parameter) {
659+
vips__heif_error(&error);
660+
return -1;
661+
}
662+
651663
/* TODO .. support extra per-encoder params with
652664
* heif_encoder_list_parameters().
653665
*/
@@ -807,6 +819,13 @@ vips_foreign_save_heif_class_init(VipsForeignSaveHeifClass *class)
807819
G_STRUCT_OFFSET(VipsForeignSaveHeif, selected_encoder),
808820
VIPS_TYPE_FOREIGN_HEIF_ENCODER,
809821
VIPS_FOREIGN_HEIF_ENCODER_AUTO);
822+
823+
VIPS_ARG_BOOL(class, "auto_tiles", 19,
824+
_("Auto-tiles"),
825+
_("Determine optimum tile count"),
826+
VIPS_ARGUMENT_OPTIONAL_INPUT,
827+
G_STRUCT_OFFSET(VipsForeignSaveHeif, auto_tiles),
828+
FALSE);
810829
}
811830

812831
static void

0 commit comments

Comments
 (0)