Skip to content

Commit

Permalink
jpeg: add code comments for Ultra HDR integration
Browse files Browse the repository at this point in the history
Signed-off-by: loicvital <[email protected]>
  • Loading branch information
mugulmd committed Oct 18, 2024
1 parent 10ed1ab commit cbc301e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/jpeg.imageio/jpeg_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class JpgInput final : public ImageInput {
jvirt_barray_ptr* m_coeffs;
std::vector<unsigned char> m_cmyk_buf; // For CMYK translation
std::unique_ptr<ImageSpec> m_config; // Saved copy of configuration spec
bool m_is_uhdr;
bool m_is_uhdr; // Is interpreted as Ultra HDR image
#if defined(USE_UHDR)
uhdr_codec_private_t* m_uhdr_dec;
#endif
Expand Down
14 changes: 14 additions & 0 deletions src/jpeg.imageio/jpeginput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,22 +418,33 @@ bool
JpgInput::read_uhdr(Filesystem::IOProxy* ioproxy)
{
#if defined(USE_UHDR)
// Read entire file content into buffer.
const size_t buffer_size = ioproxy->size();
std::vector<unsigned char> buffer(buffer_size);
ioproxy->pread(buffer.data(), buffer_size, 0);

// Check if this is an actual Ultra HDR image.
const bool detect_uhdr = is_uhdr_image(buffer.data(), buffer.size());
if (!detect_uhdr)
return false;

// Create Ultra HDR decoder.
// Do not forget to release it once we don't need it,
// i.e if this function returns false
// or when we call close().
m_uhdr_dec = uhdr_create_decoder();

// Prepare decoder input.
// Note: we currently do not override any of the
// default settings.
uhdr_compressed_image_t uhdr_compressed;
uhdr_compressed.data = buffer.data();
uhdr_compressed.data_sz = buffer.size();
uhdr_compressed.capacity = buffer.size();
uhdr_dec_set_image(m_uhdr_dec, &uhdr_compressed);

// Decode Ultra HDR image
// and check for decoding errors.
uhdr_error_info_t err_info = uhdr_decode(m_uhdr_dec);

if (err_info.error_code != UHDR_CODEC_OK) {
Expand All @@ -445,6 +456,9 @@ JpgInput::read_uhdr(Filesystem::IOProxy* ioproxy)
return false;
}

// Update spec with decoded image properties.
// Note: we currently only support a subset of all possible
// Ultra HDR image formats.
uhdr_raw_image_t* uhdr_raw = uhdr_get_decoded_image(m_uhdr_dec);

int nchannels;
Expand Down

0 comments on commit cbc301e

Please sign in to comment.