Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/strukturag/libheif
Browse files Browse the repository at this point in the history
  • Loading branch information
Dakantz committed Nov 4, 2023
2 parents 862415e + 82797ad commit 96587ac
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
10 changes: 10 additions & 0 deletions libheif/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,14 @@ inline std::ostream& operator<<(std::ostream& ostr, const Error& err)
return ostr;
}


template <typename T> class Result
{
public:
operator bool() const { return error.error_code == heif_error_Ok; }

T value;
Error error;
};

#endif
29 changes: 22 additions & 7 deletions libheif/hevc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "hevc.h"
#include "bitstream.h"
#include "error.h"

#include <cassert>
#include <cmath>
Expand Down Expand Up @@ -346,8 +347,10 @@ static double read_depth_rep_info_element(BitReader& reader)
}


static std::shared_ptr<SEIMessage> read_depth_representation_info(BitReader& reader)
static Result<std::shared_ptr<SEIMessage>> read_depth_representation_info(BitReader& reader)
{
Result<std::shared_ptr<SEIMessage>> result;

auto msg = std::make_shared<SEIMessage_depth_representation_info>();


Expand All @@ -369,9 +372,15 @@ static std::shared_ptr<SEIMessage> read_depth_representation_info(BitReader& rea

int rep_type;
if (!reader.get_uvlc(&rep_type)) {
// TODO error
result.error = {heif_error_Invalid_input, heif_suberror_Invalid_parameter_value, "invalid depth representation type in input"};
return result;
}

if (rep_type < 0 || rep_type > 3) {
result.error = {heif_error_Invalid_input, heif_suberror_Invalid_parameter_value, "input depth representation type out of range"};
return result;
}
// TODO: check rep_type range

msg->depth_representation_type = (enum heif_depth_representation_type) rep_type;

//printf("flags: %d %d %d %d\n",msg->has_z_near,msg->has_z_far,msg->has_d_min,msg->has_d_max);
Expand All @@ -380,7 +389,8 @@ static std::shared_ptr<SEIMessage> read_depth_representation_info(BitReader& rea
if (msg->has_d_min || msg->has_d_max) {
int ref_view;
if (!reader.get_uvlc(&ref_view)) {
// TODO error
result.error = {heif_error_Invalid_input, heif_suberror_Invalid_parameter_value, "invalid disparity_reference_view in input"};
return result;
}
msg->disparity_reference_view = ref_view;

Expand All @@ -403,7 +413,8 @@ static std::shared_ptr<SEIMessage> read_depth_representation_info(BitReader& rea
// TODO: load non-uniform response curve
}

return msg;
result.value = msg;
return result;
}


Expand Down Expand Up @@ -444,8 +455,12 @@ Error decode_hevc_aux_sei_messages(const std::vector<uint8_t>& data,

switch (payload_id) {
case 177: // depth_representation_info
std::shared_ptr<SEIMessage> sei = read_depth_representation_info(sei_reader);
msgs.push_back(sei);
Result<std::shared_ptr<SEIMessage>> seiResult = read_depth_representation_info(sei_reader);
if (seiResult.error) {
return seiResult.error;
}

msgs.push_back(seiResult.value);
break;
}
}
Expand Down

0 comments on commit 96587ac

Please sign in to comment.