From bdd6380b7354e6bbff796473ea931f8f7d79e513 Mon Sep 17 00:00:00 2001 From: dukesook Date: Fri, 31 May 2024 08:09:53 -0600 Subject: [PATCH] misc cleanup --- libheif/heif.cc | 27 ++++++++++++++------------- libheif/heif.h | 6 +++--- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/libheif/heif.cc b/libheif/heif.cc index b99bfd8a33..99942e41a1 100644 --- a/libheif/heif.cc +++ b/libheif/heif.cc @@ -2708,7 +2708,7 @@ struct heif_error heif_context_encode_image(struct heif_context* ctx, struct heif_error heif_context_encode_grid(struct heif_context* ctx, - struct heif_image** input_images, // array of tile images + struct heif_image** tiles, // array of tile images uint16_t columns, uint16_t rows, struct heif_encoder* encoder, @@ -2720,6 +2720,7 @@ struct heif_error heif_context_encode_grid(struct heif_context* ctx, heif_suberror_Null_pointer_argument).error_struct(ctx->context.get()); } + // TODO: Don't repeat this code from heif_context_encode_image() heif_encoding_options options; heif_color_profile_nclx nclx; set_default_options(options); @@ -2727,7 +2728,7 @@ struct heif_error heif_context_encode_grid(struct heif_context* ctx, copy_options(options, *input_options); if (options.output_nclx_profile == nullptr) { - auto input_nclx = input_images[0]->image->get_color_profile_nclx(); + auto input_nclx = tiles[0]->image->get_color_profile_nclx(); if (input_nclx) { options.output_nclx_profile = &nclx; nclx.version = 1; @@ -2739,32 +2740,32 @@ struct heif_error heif_context_encode_grid(struct heif_context* ctx, } } - std::shared_ptr image; - Error error; - - std::vector> pixel_images; + // Convert heif_images to a vector of HeifPixelImages + std::vector> pixel_tiles; for (int i=0; iimage); + pixel_tiles.push_back(tiles[i]->image); } - error = ctx->context->encode_grid(pixel_images, + // Encode Grid + Error error; + std::shared_ptr out_grid; + error = ctx->context->encode_grid(pixel_tiles, rows, columns, encoder, options, - image); + out_grid); if (error != Error::Ok) { return error.error_struct(ctx->context.get()); } - // mark the new image as primary image - + // Mark as primary image if (ctx->context->is_primary_image_set() == false) { - ctx->context->set_primary_image(image); + ctx->context->set_primary_image(out_grid); } if (out_image_handle) { *out_image_handle = new heif_image_handle; - (*out_image_handle)->image = image; + (*out_image_handle)->image = out_grid; (*out_image_handle)->context = ctx->context; } diff --git a/libheif/heif.h b/libheif/heif.h index 0273b9a191..0a33a3fb66 100644 --- a/libheif/heif.h +++ b/libheif/heif.h @@ -2041,17 +2041,17 @@ struct heif_error heif_context_encode_image(struct heif_context*, * @brief Encodes an array of images into a grid. * * @param ctx The file context - * @param input_images User allocated array of tile images. + * @param tiles User allocated array of images that will form the grid. * @param rows The number of rows in the grid. * @param columns The number of columns in the grid. * @param encoder Defines the encoder to use. See heif_context_get_encoder_for_format() * @param input_options Optional, may be nullptr. - * @param out_image_handle + * @param out_image_handle Returns a handle to the grid. The caller is responsible for freeing it. * @return struct heif_error */ LIBHEIF_API struct heif_error heif_context_encode_grid(struct heif_context* ctx, - struct heif_image** input_images, + struct heif_image** tiles, uint16_t rows, uint16_t columns, struct heif_encoder* encoder,