Skip to content

Commit

Permalink
misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dukesook committed May 31, 2024
1 parent fce23a6 commit bdd6380
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
27 changes: 14 additions & 13 deletions libheif/heif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -2720,14 +2720,15 @@ 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);
if (input_options) {
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;
Expand All @@ -2739,32 +2740,32 @@ struct heif_error heif_context_encode_grid(struct heif_context* ctx,
}
}

std::shared_ptr<HeifContext::Image> image;
Error error;

std::vector<std::shared_ptr<HeifPixelImage>> pixel_images;
// Convert heif_images to a vector of HeifPixelImages
std::vector<std::shared_ptr<HeifPixelImage>> pixel_tiles;
for (int i=0; i<rows*columns; i++) {
pixel_images.push_back(input_images[i]->image);
pixel_tiles.push_back(tiles[i]->image);
}

error = ctx->context->encode_grid(pixel_images,
// Encode Grid
Error error;
std::shared_ptr<HeifContext::Image> 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;
}

Expand Down
6 changes: 3 additions & 3 deletions libheif/heif.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bdd6380

Please sign in to comment.