Skip to content

Commit

Permalink
check that image bit depth is supported by Kvazaar (#1384)
Browse files Browse the repository at this point in the history
  • Loading branch information
farindk committed Nov 19, 2024
1 parent c5cba31 commit 5db5b85
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions libheif/plugins/encoder_kvazaar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,11 @@ static struct heif_error kvazaar_encode_image(void* encoder_raw, const struct he
bool isGreyscale = (heif_image_get_colorspace(image) == heif_colorspace_monochrome);
heif_chroma chroma = heif_image_get_chroma_format(image);

const kvz_api* api = kvz_api_get(bit_depth);
if (api == nullptr) {
// Kvazaar uses a hard-coded bit depth (https://github.com/ultravideo/kvazaar/issues/399).
// Check whether this matches to the image bit depth.
// TODO: we should check the bit depth supported by the encoder (like query_input_colorspace2()) and output a warning
// if we have to encode at a different bit depth than requested.
if (bit_depth != KVZ_BIT_DEPTH) {
struct heif_error err = {
heif_error_Encoder_plugin_error,
heif_suberror_Unsupported_bit_depth,
Expand All @@ -385,6 +388,16 @@ static struct heif_error kvazaar_encode_image(void* encoder_raw, const struct he
return err;
}

const kvz_api* api = kvz_api_get(bit_depth);
if (api == nullptr) {
struct heif_error err = {
heif_error_Encoder_plugin_error,
heif_suberror_Unspecified,
"Could not initialize Kvazaar API"
};
return err;
}

auto uconfig = make_guard(api->config_alloc(), [api](kvz_config* cfg) { api->config_destroy(cfg); });
kvz_config* config = uconfig.get();
api->config_init(config); // param, encoder->preset.c_str(), encoder->tune.c_str());
Expand Down

0 comments on commit 5db5b85

Please sign in to comment.