Skip to content

Commit

Permalink
use a different enum type for unci compression
Browse files Browse the repository at this point in the history
  • Loading branch information
farindk committed Oct 31, 2024
1 parent 0ab5e94 commit 4bf1e1f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
10 changes: 5 additions & 5 deletions examples/heif_enc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ std::string chroma_downsampling;
int tiled_image_width = 0;
int tiled_image_height = 0;
std::string tiling_method = "grid";
heif_metadata_compression unci_compression = heif_metadata_compression_brotli;
heif_unci_compression unci_compression = heif_unci_compression_brotli;
int add_pyramid_group = 0;

uint16_t nclx_colour_primaries = 1;
Expand Down Expand Up @@ -985,16 +985,16 @@ int main(int argc, char** argv)
case OPTION_UNCI_COMPRESSION: {
std::string option(optarg);
if (option == "none") {
unci_compression = heif_metadata_compression_off;
unci_compression = heif_unci_compression_off;
}
else if (option == "brotli") {
unci_compression = heif_metadata_compression_brotli;
unci_compression = heif_unci_compression_brotli;
}
else if (option == "deflate") {
unci_compression = heif_metadata_compression_deflate;
unci_compression = heif_unci_compression_deflate;
}
else if (option == "zlib") {
unci_compression = heif_metadata_compression_zlib;
unci_compression = heif_unci_compression_zlib;
}
else {
std::cerr << "Invalid unci compression method '" << option << "'\n";
Expand Down
15 changes: 14 additions & 1 deletion libheif/api/libheif/heif_experimental.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ struct heif_error heif_context_add_tiled_image(struct heif_context* ctx,

// --- 'unci' images

// This is similar to heif_metadata_compression. We should try to keep the integers compatible, but each enum will just
// contain the allowed values.
enum heif_unci_compression
{
heif_unci_compression_off = 0,
//heif_unci_compression_auto = 1,
//heif_unci_compression_unknown = 2, // only used when reading unknown method from input file
heif_unci_compression_deflate = 3,
heif_unci_compression_zlib = 4,
heif_unci_compression_brotli = 5
};


struct heif_unci_image_parameters {
int version;

Expand All @@ -159,7 +172,7 @@ struct heif_unci_image_parameters {
uint32_t tile_width;
uint32_t tile_height;

enum heif_metadata_compression compression; // TODO
enum heif_unci_compression compression; // TODO

// TODO: interleave type, padding
};
Expand Down
10 changes: 5 additions & 5 deletions libheif/image-items/unc_image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,23 +350,23 @@ Result<std::shared_ptr<ImageItem_uncompressed>> ImageItem_uncompressed::add_unci
static_cast<uint32_t>(parameters->image_height),
true);

if (parameters->compression != heif_metadata_compression_off) {
if (parameters->compression != heif_unci_compression_off) {
auto icef = std::make_shared<Box_icef>();
auto cmpC = std::make_shared<Box_cmpC>();
cmpC->set_compressed_unit_type(heif_cmpC_compressed_unit_type_image_tile);

if (false) {
}
#if HAVE_ZLIB
else if (parameters->compression == heif_metadata_compression_deflate) {
else if (parameters->compression == heif_unci_compression_deflate) {
cmpC->set_compression_type(fourcc("defl"));
}
else if (parameters->compression == heif_metadata_compression_zlib) {
else if (parameters->compression == heif_unci_compression_zlib) {
cmpC->set_compression_type(fourcc("zlib"));
}
#endif
#if HAVE_BROTLI
else if (parameters->compression == heif_metadata_compression_brotli) {
else if (parameters->compression == heif_unci_compression_brotli) {
cmpC->set_compression_type(fourcc("brot"));
}
#endif
Expand All @@ -380,7 +380,7 @@ Result<std::shared_ptr<ImageItem_uncompressed>> ImageItem_uncompressed::add_unci

// Create empty image. If we use compression, we append the data piece by piece.

if (parameters->compression == heif_metadata_compression_off) {
if (parameters->compression == heif_unci_compression_off) {
uint64_t tile_size = headers.uncC->compute_tile_data_size_bytes(parameters->image_width / headers.uncC->get_number_of_tile_columns(),
parameters->image_height / headers.uncC->get_number_of_tile_rows());

Expand Down

0 comments on commit 4bf1e1f

Please sign in to comment.