Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract stream decoding to Decoder classes #1321

Merged
merged 39 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0922977
extract stream decoding to Decoder classes (HEVC, J2K)
farindk Oct 1, 2024
5f86fe3
move decode_single_frame_from_compressed_data() to Decoder
farindk Oct 1, 2024
957093a
revert: cmake OpenJPEG version check
farindk Oct 1, 2024
9d891b8
initialize Decoder in ImageItem::on_load_file()
farindk Oct 1, 2024
9f1156a
decode HEVC through Decoder_HEVC
farindk Oct 2, 2024
d1e662f
default implementation of ImageItem::get_luma_bits_per_pixel() just f…
farindk Oct 2, 2024
33d3870
move AVIF decoding into Decoder_AVIF
farindk Oct 2, 2024
6a5b62c
(change struct to class)
farindk Oct 2, 2024
1e64957
replace all get_item_type() with get_item_type_4cc()
farindk Oct 2, 2024
1bb435c
replace all fourcc-type strings with uint32_t constants
farindk Oct 2, 2024
fa791d0
rename 'to_fourcc()' to 'fourcc_to_string()'
farindk Oct 2, 2024
0eb4109
rename HeifFile::get_compressed_image_data() to HeifFile::get_uncompr…
farindk Oct 2, 2024
da93fdc
remove mutex from get_uncompressed_item_data() as it is not used for …
farindk Oct 2, 2024
e029ffc
add Decoder classes for VVC, AVC, JPEG
farindk Oct 3, 2024
ef58e35
(remove 'struct' forward declaration)
farindk Oct 3, 2024
11cf60d
JPEG: parse SOF for chroma format
farindk Oct 3, 2024
6295206
(minor edit)
farindk Oct 3, 2024
73fb313
add Decoder_uncompressed class
farindk Oct 3, 2024
497dc5b
uncompressed: separated codec from ImageItem
farindk Oct 3, 2024
6190b58
uncompressed: pulled AbstractDecoder into its own file
farindk Oct 3, 2024
77292c2
uncompressed: pulled ComponentInterleaveDecoder into its own file
farindk Oct 3, 2024
8cae3b0
uncompressed: pulled PixelInterleaveDecoder into its own file
farindk Oct 3, 2024
8b0dade
uncompressed: pulled MixedInterleaveDecoder into its own file
farindk Oct 3, 2024
b4a06be
uncompressed: pulled RowInterleaveDecoder into its own file
farindk Oct 3, 2024
ab2f694
uncompressed: pulled TileComponentInterleaveDecoder into its own file
farindk Oct 3, 2024
5ae88f6
uncompressed: (cleanup)
farindk Oct 3, 2024
cba01e8
uncompressed: simplify nAlignmentSkipBytes()
farindk Oct 3, 2024
901ce17
uncompressed: (cleanup includes)
farindk Oct 3, 2024
a1e388c
JPEG2000: use Decoder_JPEG2000 in ImageItem_JPEG2000
farindk Oct 3, 2024
6882bd6
extract AVIF and AVC boxes into their own files
farindk Oct 4, 2024
a47b217
remove dead code
farindk Oct 4, 2024
098da51
fix wrong AVIF chroma parsing
farindk Oct 4, 2024
c8715dd
extract HEVC boxes processing into its own file
farindk Oct 4, 2024
fd73fc3
extract JPEG boxes processing into its own file
farindk Oct 4, 2024
3117743
extract JPEG2000 boxes processing into its own file
farindk Oct 4, 2024
8e94574
extract VVC boxes processing into its own file
farindk Oct 4, 2024
0a423e9
scale vvenc encoder quality from 0-100 and invert, so that 100 is max…
farindk Oct 4, 2024
e127d20
move all ImageItem classes into its own directory
farindk Oct 4, 2024
562f826
add 'unci' to Decoder::alloc_for_infe_type()
farindk Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 68 additions & 26 deletions libheif/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,56 @@ set(libheif_sources
api/libheif/heif_items.cc
api/libheif/heif_experimental.h
api/libheif/heif_experimental.cc
codecs/hevc.cc
codecs/hevc.h
codecs/avif.cc
codecs/avif.h
codecs/jpeg.h
codecs/jpeg.cc
codecs/jpeg2000.h
codecs/jpeg2000.cc
codecs/vvc.h
codecs/vvc.cc
codecs/avc.h
codecs/avc.cc
codecs/mask_image.h
codecs/mask_image.cc
codecs/image_item.h
codecs/image_item.cc
codecs/grid.h
codecs/grid.cc
codecs/overlay.h
codecs/overlay.cc
codecs/iden.h
codecs/iden.cc
codecs/tild.h
codecs/tild.cc
codecs/decoder.h
codecs/decoder.cc
image-items/hevc.cc
image-items/hevc.h
codecs/hevc_boxes.cc
codecs/hevc_boxes.h
codecs/hevc_dec.cc
codecs/hevc_dec.h
image-items/avif.cc
image-items/avif.h
codecs/avif_dec.cc
codecs/avif_dec.h
codecs/avif_boxes.cc
codecs/avif_boxes.h
image-items/jpeg.h
image-items/jpeg.cc
codecs/jpeg_boxes.h
codecs/jpeg_boxes.cc
codecs/jpeg_dec.h
codecs/jpeg_dec.cc
image-items/jpeg2000.h
image-items/jpeg2000.cc
codecs/jpeg2000_dec.h
codecs/jpeg2000_dec.cc
codecs/jpeg2000_boxes.h
codecs/jpeg2000_boxes.cc
image-items/vvc.h
image-items/vvc.cc
codecs/vvc_dec.h
codecs/vvc_dec.cc
codecs/vvc_boxes.h
codecs/vvc_boxes.cc
image-items/avc.h
image-items/avc.cc
codecs/avc_boxes.h
codecs/avc_boxes.cc
codecs/avc_dec.h
codecs/avc_dec.cc
image-items/mask_image.h
image-items/mask_image.cc
image-items/image_item.h
image-items/image_item.cc
image-items/grid.h
image-items/grid.cc
image-items/overlay.h
image-items/overlay.cc
image-items/iden.h
image-items/iden.cc
image-items/tild.h
image-items/tild.cc
color-conversion/colorconversion.cc
color-conversion/colorconversion.h
color-conversion/rgb2yuv.cc
Expand Down Expand Up @@ -172,8 +198,24 @@ if (WITH_UNCOMPRESSED_CODEC)
target_sources(heif PRIVATE
codecs/uncompressed/unc_boxes.h
codecs/uncompressed/unc_boxes.cc
codecs/uncompressed/unc_image.h
codecs/uncompressed/unc_image.cc)
image-items/unc_image.h
image-items/unc_image.cc
codecs/uncompressed/unc_codec.h
codecs/uncompressed/unc_codec.cc
codecs/uncompressed/unc_dec.h
codecs/uncompressed/unc_dec.cc
codecs/uncompressed/decoder_abstract.h
codecs/uncompressed/decoder_abstract.cc
codecs/uncompressed/decoder_component_interleave.h
codecs/uncompressed/decoder_component_interleave.cc
codecs/uncompressed/decoder_pixel_interleave.h
codecs/uncompressed/decoder_pixel_interleave.cc
codecs/uncompressed/decoder_mixed_interleave.h
codecs/uncompressed/decoder_mixed_interleave.cc
codecs/uncompressed/decoder_row_interleave.h
codecs/uncompressed/decoder_row_interleave.cc
codecs/uncompressed/decoder_tile_component_interleave.h
codecs/uncompressed/decoder_tile_component_interleave.cc)
endif ()

write_basic_package_version_file(${PROJECT_NAME}-config-version.cmake COMPATIBILITY ExactVersion)
Expand Down
2 changes: 1 addition & 1 deletion libheif/api/libheif/api_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "context.h"

#include <memory>
#include <codecs/image_item.h>
#include "image-items/image_item.h"

struct heif_image_handle
{
Expand Down
28 changes: 17 additions & 11 deletions libheif/api/libheif/heif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
#include "error.h"
#include "bitstream.h"
#include "init.h"
#include "codecs/grid.h"
#include "codecs/overlay.h"
#include "codecs/tild.h"
#include "image-items/grid.h"
#include "image-items/overlay.h"
#include "image-items/tild.h"
#include <set>
#include <limits>

#if WITH_UNCOMPRESSED_CODEC
#include "codecs/uncompressed/unc_image.h"
#include "image-items/unc_image.h"
#endif

#if defined(__EMSCRIPTEN__) && !defined(__EMSCRIPTEN_STANDALONE_WASM__)
Expand Down Expand Up @@ -292,13 +292,13 @@ heif_brand2 heif_read_main_brand(const uint8_t* data, int len)
}


heif_brand2 heif_fourcc_to_brand(const char* fourcc)
heif_brand2 heif_fourcc_to_brand(const char* fourcc_string)
{
if (fourcc == nullptr || !fourcc[0] || !fourcc[1] || !fourcc[2] || !fourcc[3]) {
if (fourcc_string == nullptr || !fourcc_string[0] || !fourcc_string[1] || !fourcc_string[2] || !fourcc_string[3]) {
return 0;
}

return fourcc_to_uint32(fourcc);
return fourcc(fourcc_string);
}


Expand Down Expand Up @@ -337,7 +337,7 @@ int heif_has_compatible_brand(const uint8_t* data, int len, const char* brand_fo
return -2;
}

return ftyp->has_compatible_brand(fourcc_to_uint32(brand_fourcc)) ? 1 : 0;
return ftyp->has_compatible_brand(fourcc(brand_fourcc)) ? 1 : 0;
}


Expand Down Expand Up @@ -3478,7 +3478,7 @@ struct heif_error heif_context_add_image_tile(struct heif_context* ctx,
const struct heif_image* image,
struct heif_encoder* encoder)
{
if (tiled_image->image->get_infe_type() == std::string{"tili"}) {
if (tiled_image->image->get_infe_type() == fourcc("tili")) {
Error err = ctx->context->add_tild_image_tile(tiled_image->image->get_id(), tile_x, tile_y, image->image, encoder);
return err.error_struct(ctx->context.get());
}
Expand Down Expand Up @@ -3642,8 +3642,14 @@ struct heif_error heif_context_add_generic_metadata(struct heif_context* ctx,
const void* data, int size,
const char* item_type, const char* content_type)
{
if (item_type == nullptr || strlen(item_type) != 4) {
return {heif_error_Usage_error,
heif_suberror_Invalid_parameter_value,
"called heif_context_add_generic_metadata() with invalid 'item_type'."};
}

Error error = ctx->context->add_generic_metadata(image_handle->image, data, size,
item_type, content_type, nullptr, heif_metadata_compression_off, nullptr);
fourcc(item_type), content_type, nullptr, heif_metadata_compression_off, nullptr);
if (error != Error::Ok) {
return error.error_struct(ctx->context.get());
}
Expand All @@ -3660,7 +3666,7 @@ struct heif_error heif_context_add_generic_uri_metadata(struct heif_context* ctx
heif_item_id* out_item_id)
{
Error error = ctx->context->add_generic_metadata(image_handle->image, data, size,
"uri ", nullptr, item_uri_type, heif_metadata_compression_off, out_item_id);
fourcc("uri "), nullptr, item_uri_type, heif_metadata_compression_off, out_item_id);
if (error != Error::Ok) {
return error.error_struct(ctx->context.get());
}
Expand Down
4 changes: 3 additions & 1 deletion libheif/api/libheif/heif.h
Original file line number Diff line number Diff line change
Expand Up @@ -1141,16 +1141,18 @@ LIBHEIF_API
int heif_image_handle_is_premultiplied_alpha(const struct heif_image_handle*);

// Returns -1 on error, e.g. if this information is not present in the image.
// Only defined for images coded in the YCbCr colorspace.
LIBHEIF_API
int heif_image_handle_get_luma_bits_per_pixel(const struct heif_image_handle*);

// Returns -1 on error, e.g. if this information is not present in the image.
// Only defined for images coded in the YCbCr colorspace.
LIBHEIF_API
int heif_image_handle_get_chroma_bits_per_pixel(const struct heif_image_handle*);

// Return the colorspace that libheif proposes to use for decoding.
// Usually, these will be either YCbCr or Monochrome, but it may also propose RGB for images
// encoded with matrix_coefficients=0.
// encoded with matrix_coefficients=0 or for images coded natively in RGB.
// It may also return *_undefined if the file misses relevant information to determine this without decoding.
LIBHEIF_API
struct heif_error heif_image_handle_get_preferred_decoding_colorspace(const struct heif_image_handle* image_handle,
Expand Down
24 changes: 12 additions & 12 deletions libheif/api/libheif/heif_items.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@ int heif_context_get_list_of_item_IDs(const struct heif_context* ctx,

uint32_t heif_context_get_item_type(const struct heif_context* ctx, heif_item_id item_id)
{
auto type = ctx->context->get_heif_file()->get_item_type(item_id);
if (type.empty()) {
return 0;
}
else {
return fourcc(type.c_str());
}
return ctx->context->get_heif_file()->get_item_type_4cc(item_id);
}


Expand All @@ -88,7 +82,7 @@ const char* heif_context_get_mime_item_content_type(const struct heif_context* c
auto infe = ctx->context->get_heif_file()->get_infe_box(item_id);
if (!infe) { return nullptr; }

if (infe->get_item_type() != "mime") {
if (infe->get_item_type_4cc() != fourcc("mime")) {
return nullptr;
}

Expand All @@ -100,7 +94,7 @@ const char* heif_context_get_mime_item_content_encoding(const struct heif_contex
auto infe = ctx->context->get_heif_file()->get_infe_box(item_id);
if (!infe) { return nullptr; }

if (infe->get_item_type() != "mime") {
if (infe->get_item_type_4cc() != fourcc("mime")) {
return nullptr;
}

Expand All @@ -113,7 +107,7 @@ const char* heif_context_get_uri_item_uri_type(const struct heif_context* ctx, h
auto infe = ctx->context->get_heif_file()->get_infe_box(item_id);
if (!infe) { return nullptr; }

if (infe->get_item_type() != "uri ") {
if (infe->get_item_type_4cc() != fourcc("uri ")) {
return nullptr;
}

Expand Down Expand Up @@ -178,7 +172,7 @@ struct heif_error heif_context_get_item_data(struct heif_context* ctx,
void* out_data)
{
std::vector<uint8_t> data;
Error err = ctx->context->get_heif_file()->get_compressed_image_data(item_id, &data);
Error err = ctx->context->get_heif_file()->get_uncompressed_item_data(item_id, &data);

if (err) {
return err.error_struct(ctx->context.get());
Expand Down Expand Up @@ -244,7 +238,13 @@ struct heif_error heif_context_add_item(struct heif_context* ctx,
const void* data, int size,
heif_item_id* out_item_id)
{
Result<heif_item_id> result = ctx->context->get_heif_file()->add_infe(item_type, (const uint8_t*) data, size);
if (item_type == nullptr || strlen(item_type) != 4) {
return {heif_error_Usage_error,
heif_suberror_Invalid_parameter_value,
"called heif_context_add_item() with invalid 'item_type'."};
}

Result<heif_item_id> result = ctx->context->get_heif_file()->add_infe(fourcc(item_type), (const uint8_t*) data, size);

if (result && out_item_id) {
*out_item_id = result.value;
Expand Down
Loading
Loading