From bea5f4b47def81a669f1bc0c1415f02a8b9f595b Mon Sep 17 00:00:00 2001 From: Dirk Farin Date: Thu, 5 Oct 2023 12:02:47 +0200 Subject: [PATCH] provide a default heif_error_success (#970) --- libheif/heif.cc | 102 +++++++++++++++++++++++------------------------- libheif/heif.h | 3 ++ 2 files changed, 52 insertions(+), 53 deletions(-) diff --git a/libheif/heif.cc b/libheif/heif.cc index c8b8f16825..f1c41769dc 100644 --- a/libheif/heif.cc +++ b/libheif/heif.cc @@ -58,7 +58,7 @@ #include -static struct heif_error error_Ok = {heif_error_Ok, heif_suberror_Unspecified, kSuccess}; +struct heif_error heif_error_success = {heif_error_Ok, heif_suberror_Unspecified, kSuccess}; static struct heif_error error_unsupported_parameter = {heif_error_Usage_error, heif_suberror_Unsupported_parameter, "Unsupported encoder parameter"}; @@ -333,7 +333,7 @@ struct heif_error heif_list_compatible_brands(const uint8_t* data, int len, heif (*out_brands)[i] = brands[i]; } - return {heif_error_Ok, heif_suberror_Unspecified, Error::kSuccess}; + return heif_error_success; } @@ -603,7 +603,7 @@ struct heif_error heif_context_get_image_handle(struct heif_context* ctx, (*imgHdl)->image = image; (*imgHdl)->context = ctx->context; - return {heif_error_Ok, heif_suberror_Unspecified, Error::kSuccess}; + return heif_error_success; } @@ -715,7 +715,7 @@ struct heif_error heif_image_handle_get_auxiliary_type(const struct heif_image_h strcpy(buf, auxType.c_str()); *out_type = buf; - return {heif_error_Ok, heif_suberror_Unspecified, Error::kSuccess}; + return heif_error_success; } @@ -822,7 +822,7 @@ struct heif_error heif_image_handle_get_preferred_decoding_colorspace(const stru return err.error_struct(image_handle->image.get()); } - return error_Ok; + return heif_error_success; } @@ -1086,8 +1086,7 @@ struct heif_error heif_image_create(int width, int height, *image = img; - struct heif_error err = {heif_error_Ok, heif_suberror_Unspecified, Error::kSuccess}; - return err; + return heif_error_success; } int heif_image_get_decoding_warnings(struct heif_image* image, @@ -1205,7 +1204,7 @@ struct heif_error heif_mastering_display_colour_volume_decode(const struct heif_ out->min_display_mastering_luminance = in->min_display_mastering_luminance * 0.0001; } - return error_Ok; + return heif_error_success; } @@ -1301,7 +1300,7 @@ heif_error heif_image_crop(struct heif_image* img, img->image = out_img; - return heif_error{heif_error_Ok, heif_suberror_Unspecified, Error::kSuccess}; + return heif_error_success; } @@ -1333,8 +1332,7 @@ struct heif_error heif_image_add_plane(struct heif_image* image, return err; } else { - struct heif_error err = {heif_error_Ok, heif_suberror_Unspecified, Error::kSuccess}; - return err; + return heif_error_success; } } @@ -1395,7 +1393,7 @@ struct heif_error heif_image_extend_padding_to_size(struct heif_image* image, in "Cannot allocate image memory."}; } else { - return heif_error{heif_error_Ok, heif_suberror_Unspecified, Error::kSuccess}; + return heif_error_success; } } @@ -1441,8 +1439,7 @@ struct heif_error heif_image_set_raw_color_profile(struct heif_image* image, image->image->set_color_profile_icc(color_profile); - struct heif_error err = {heif_error_Ok, heif_suberror_Unspecified, Error::kSuccess}; - return err; + return heif_error_success; } @@ -1458,7 +1455,7 @@ struct heif_error heif_image_set_nclx_color_profile(struct heif_image* image, image->image->set_color_profile_nclx(nclx); - return error_Ok; + return heif_error_success; } @@ -1994,7 +1991,7 @@ struct heif_error heif_item_get_property_user_description(const struct heif_cont *out = udes_c; - return error_Ok; + return heif_error_success; } @@ -2020,7 +2017,7 @@ struct heif_error heif_item_add_property_user_description(const struct heif_cont *out_propertyId = id; } - return error_Ok; + return heif_error_success; } @@ -2136,7 +2133,7 @@ struct heif_error heif_register_decoder_plugin(const heif_decoder_plugin* decode } register_decoder(decoder_plugin); - return error_Ok; + return heif_error_success; } struct heif_error heif_register_encoder_plugin(const heif_encoder_plugin* encoder_plugin) @@ -2149,7 +2146,7 @@ struct heif_error heif_register_encoder_plugin(const heif_encoder_plugin* encode } register_encoder(encoder_plugin); - return error_Ok; + return heif_error_success; } @@ -2483,8 +2480,7 @@ struct heif_error heif_encoder_set_logging_level(struct heif_encoder* encoder, i return encoder->plugin->set_parameter_logging_level(encoder->encoder, level); } - struct heif_error err = {heif_error_Ok, heif_suberror_Unspecified, kSuccess}; - return err; + return heif_error_success; } @@ -2584,7 +2580,7 @@ heif_encoder_parameter_get_valid_integer_range(const struct heif_encoder_paramet *have_minimum_maximum = param->integer.have_minimum_maximum; } - return error_Ok; + return heif_error_success; } LIBHEIF_API @@ -2632,7 +2628,7 @@ struct heif_error heif_encoder_parameter_get_valid_integer_values(const struct h *num_valid_values = param->integer.num_valid_values; } - return error_Ok; + return heif_error_success; } @@ -2648,7 +2644,7 @@ heif_encoder_parameter_get_valid_string_values(const struct heif_encoder_paramet *out_stringarray = param->string.valid_values; } - return error_Ok; + return heif_error_success; } struct heif_error heif_encoder_parameter_integer_valid_range(struct heif_encoder* encoder, @@ -2771,7 +2767,7 @@ struct heif_error heif_encoder_set_parameter(struct heif_encoder* encoder, break; } - return error_Ok; + return heif_error_success; } } @@ -2824,7 +2820,7 @@ struct heif_error heif_encoder_get_parameter(struct heif_encoder* encoder, break; } - return error_Ok; + return heif_error_success; } } @@ -2965,7 +2961,7 @@ struct heif_error heif_context_encode_image(struct heif_context* ctx, (*out_image_handle)->context = ctx->context; } - return error_Ok; + return heif_error_success; } @@ -3027,7 +3023,7 @@ struct heif_error heif_context_encode_thumbnail(struct heif_context* ctx, } } - return error_Ok; + return heif_error_success; } @@ -3036,7 +3032,7 @@ struct heif_error heif_context_set_primary_image(struct heif_context* ctx, { ctx->context->set_primary_image(image_handle->image); - return error_Ok; + return heif_error_success; } @@ -3049,7 +3045,7 @@ struct heif_error heif_context_add_exif_metadata(struct heif_context* ctx, return error.error_struct(ctx->context.get()); } else { - return error_Ok; + return heif_error_success; } } @@ -3073,7 +3069,7 @@ struct heif_error heif_context_add_XMP_metadata2(struct heif_context* ctx, return error.error_struct(ctx->context.get()); } else { - return error_Ok; + return heif_error_success; } } @@ -3089,7 +3085,7 @@ struct heif_error heif_context_add_generic_metadata(struct heif_context* ctx, return error.error_struct(ctx->context.get()); } else { - return error_Ok; + return heif_error_success; } } @@ -3142,7 +3138,7 @@ struct heif_error heif_context_get_region_item(const struct heif_context* contex item->region_item = r; *out = item; - return error_Ok; + return heif_error_success; } @@ -3212,7 +3208,7 @@ struct heif_error heif_image_handle_add_region_item(struct heif_image_handle* im *out_region_item = item; } - return error_Ok; + return heif_error_success; } @@ -3241,7 +3237,7 @@ struct heif_error heif_region_item_add_region_point(struct heif_region_item* ite *out_region = create_region(region, item); } - return error_Ok; + return heif_error_success; } @@ -3262,7 +3258,7 @@ struct heif_error heif_region_item_add_region_rectangle(struct heif_region_item* *out_region = create_region(region, item); } - return error_Ok; + return heif_error_success; } @@ -3283,7 +3279,7 @@ struct heif_error heif_region_item_add_region_ellipse(struct heif_region_item* i *out_region = create_region(region, item); } - return error_Ok; + return heif_error_success; } @@ -3307,7 +3303,7 @@ struct heif_error heif_region_item_add_region_polygon(struct heif_region_item* i *out_region = create_region(region, item); } - return error_Ok; + return heif_error_success; } @@ -3331,7 +3327,7 @@ struct heif_error heif_region_item_add_region_polyline(struct heif_region_item* *out_region = create_region(region, item); } - return error_Ok; + return heif_error_success; } @@ -3361,7 +3357,7 @@ struct heif_error heif_region_item_add_region_referenced_mask(struct heif_region std::shared_ptr ctx = item->context; ctx->add_region_referenced_mask_ref(item->region_item->item_id, mask_item_id); - return error_Ok; + return heif_error_success; } @@ -3386,7 +3382,7 @@ struct heif_error heif_region_item_add_region_inline_mask_data(struct heif_regio *out_region = create_region(region, item); } - return error_Ok; + return heif_error_success; } struct heif_error heif_region_item_add_region_inline_mask(struct heif_region_item* item, @@ -3428,7 +3424,7 @@ struct heif_error heif_region_item_add_region_inline_mask(struct heif_region_ite *out_region = create_region(region, item); } - return error_Ok; + return heif_error_success; } @@ -3461,7 +3457,7 @@ struct heif_error heif_region_get_point(const struct heif_region* region, int32_ if (point) { *x = point->x; *y = point->y; - return heif_error_ok; + return heif_error_success; } return heif_error_invalid_parameter_value; @@ -3484,7 +3480,7 @@ struct heif_error heif_region_get_point_transformed(const struct heif_region* re *x = p.x; *y = p.y; - return heif_error_ok; + return heif_error_success; } return heif_error_invalid_parameter_value; @@ -3501,7 +3497,7 @@ struct heif_error heif_region_get_rectangle(const struct heif_region* region, *y = rect->y; *width = rect->width; *height = rect->height; - return heif_error_ok; + return heif_error_success; } return heif_error_invalid_parameter_value; @@ -3526,7 +3522,7 @@ struct heif_error heif_region_get_rectangle_transformed(const struct heif_region *y = p.y; *width = e.x; *height = e.y; - return heif_error_ok; + return heif_error_success; } return heif_error_invalid_parameter_value; @@ -3543,7 +3539,7 @@ struct heif_error heif_region_get_ellipse(const struct heif_region* region, *y = ellipse->y; *radius_x = ellipse->radius_x; *radius_y = ellipse->radius_y; - return heif_error_ok; + return heif_error_success; } return heif_error_invalid_parameter_value; @@ -3568,7 +3564,7 @@ struct heif_error heif_region_get_ellipse_transformed(const struct heif_region* *y = p.y; *radius_x = e.x; *radius_y = e.y; - return heif_error_ok; + return heif_error_success; } return heif_error_invalid_parameter_value; @@ -3609,7 +3605,7 @@ static struct heif_error heif_region_get_poly_points(const struct heif_region* r pts[2 * i + 0] = poly->points[i].x; pts[2 * i + 1] = poly->points[i].y; } - return heif_error_ok; + return heif_error_success; } return heif_error_invalid_parameter_value; } @@ -3646,7 +3642,7 @@ static struct heif_error heif_region_get_poly_points_scaled(const struct heif_re pts[2 * i + 0] = p.x; pts[2 * i + 1] = p.y; } - return heif_error_ok; + return heif_error_success; } return heif_error_invalid_parameter_value; } @@ -3680,7 +3676,7 @@ struct heif_error heif_region_get_referenced_mask_ID(const struct heif_region* r *width = mask->width; *height = mask->height; *mask_item_id = mask->referenced_item; - return heif_error_ok; + return heif_error_success; } return heif_error_invalid_parameter_value; } @@ -3712,7 +3708,7 @@ struct heif_error heif_region_get_inline_mask_data(const struct heif_region* reg *width = mask->width; *height = mask->height; memcpy(data, mask->mask_data.data(), mask->mask_data.size()); - return heif_error_ok; + return heif_error_success; } return heif_error_invalid_parameter_value; } @@ -3763,7 +3759,7 @@ static struct heif_error heif_region_get_inline_mask_image(const struct heif_reg pixel_index++; } } - return heif_error_ok; + return heif_error_success; } return heif_error_invalid_parameter_value; } diff --git a/libheif/heif.h b/libheif/heif.h index a499ff2dad..71097b2e62 100644 --- a/libheif/heif.h +++ b/libheif/heif.h @@ -323,6 +323,9 @@ struct heif_error const char* message; }; +// Default success return value. Intended for use in user-supplied callback functions. +LIBHEIF_API extern struct heif_error heif_error_success; + typedef uint32_t heif_item_id; typedef uint32_t heif_property_id;