plug-ins: prefer AOM encoder for AVIF export

Name of the used encoder is printed during export,
It can be: aom, rav1e, x265
This commit is contained in:
Daniel Novomesky
2021-10-25 17:11:37 +02:00
committed by Daniel Novomeský
parent 398dbbe01b
commit 1d44b45f09

View File

@ -1240,23 +1240,25 @@ save_image (GFile *file,
GError **error, GError **error,
enum heif_compression_format compression) enum heif_compression_format compression)
{ {
struct heif_image *image = NULL; struct heif_image *image = NULL;
struct heif_context *context = heif_context_alloc (); struct heif_context *context = heif_context_alloc ();
struct heif_encoder *encoder = NULL; struct heif_encoder *encoder = NULL;
struct heif_image_handle *handle = NULL; const struct heif_encoder_descriptor *encoder_descriptor;
struct heif_writer writer; const char *encoder_name;
struct heif_error err; struct heif_image_handle *handle = NULL;
GOutputStream *output; struct heif_writer writer;
GeglBuffer *buffer; struct heif_error err;
const gchar *encoding; GOutputStream *output;
const Babl *format; GeglBuffer *buffer;
const Babl *space = NULL; const gchar *encoding;
guint8 *data; const Babl *format;
gint stride; const Babl *space = NULL;
gint width; guint8 *data;
gint height; gint stride;
gboolean has_alpha; gint width;
gboolean out_linear = FALSE; gint height;
gboolean has_alpha;
gboolean out_linear = FALSE;
if (!context) if (!context)
{ {
@ -1265,8 +1267,50 @@ save_image (GFile *file,
return FALSE; return FALSE;
} }
gimp_progress_init_printf (_("Exporting '%s'"), if (compression == heif_compression_HEVC)
g_file_get_parse_name (file)); {
if (heif_context_get_encoder_descriptors (context,
heif_compression_HEVC,
NULL,
&encoder_descriptor, 1) == 1)
{
encoder_name = heif_encoder_descriptor_get_id_name (encoder_descriptor);
}
else
{
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
"Unable to find suitable HEIF encoder");
heif_context_free (context);
return FALSE;
}
}
else /* AV1 compression */
{
if (heif_context_get_encoder_descriptors (context,
compression,
"aom", /* we prefer aom rather than rav1e */
&encoder_descriptor, 1) == 1)
{
encoder_name = heif_encoder_descriptor_get_id_name (encoder_descriptor);
}
else if (heif_context_get_encoder_descriptors (context,
compression,
NULL,
&encoder_descriptor, 1) == 1)
{
encoder_name = heif_encoder_descriptor_get_id_name (encoder_descriptor);
}
else
{
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
"Unable to find suitable AVIF encoder");
heif_context_free (context);
return FALSE;
}
}
gimp_progress_init_printf (_("Exporting '%s' using %s encoder"),
g_file_get_parse_name (file), encoder_name);
width = gimp_drawable_width (drawable_ID); width = gimp_drawable_width (drawable_ID);
height = gimp_drawable_height (drawable_ID); height = gimp_drawable_height (drawable_ID);
@ -1523,14 +1567,14 @@ save_image (GFile *file,
/* encode to HEIF file */ /* encode to HEIF file */
err = heif_context_get_encoder_for_format (context, err = heif_context_get_encoder (context,
compression, encoder_descriptor,
&encoder); &encoder);
if (err.code != 0) if (err.code != 0)
{ {
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
"Unable to find suitable HEIF encoder"); "Unable to get an encoder instance");
heif_image_release (image); heif_image_release (image);
heif_context_free (context); heif_context_free (context);
return FALSE; return FALSE;
@ -1556,7 +1600,7 @@ save_image (GFile *file,
err = heif_encoder_set_parameter_string (encoder, "chroma", "444"); err = heif_encoder_set_parameter_string (encoder, "chroma", "444");
if (err.code != 0) if (err.code != 0)
{ {
g_printerr ("Failed to set chroma=444 for %s encoder: %s", heif_encoder_get_name (encoder), err.message); g_printerr ("Failed to set chroma=444 for %s encoder: %s", encoder_name, err.message);
} }
} }
#endif #endif