@@ -418,22 +418,33 @@ bool
418418JpgInput::read_uhdr (Filesystem::IOProxy* ioproxy)
419419{
420420#if defined(USE_UHDR)
421+ // Read entire file content into buffer.
421422 const size_t buffer_size = ioproxy->size ();
422423 std::vector<unsigned char > buffer (buffer_size);
423424 ioproxy->pread (buffer.data (), buffer_size, 0 );
424425
426+ // Check if this is an actual Ultra HDR image.
425427 const bool detect_uhdr = is_uhdr_image (buffer.data (), buffer.size ());
426428 if (!detect_uhdr)
427429 return false ;
428430
431+ // Create Ultra HDR decoder.
432+ // Do not forget to release it once we don't need it,
433+ // i.e if this function returns false
434+ // or when we call close().
429435 m_uhdr_dec = uhdr_create_decoder ();
430436
437+ // Prepare decoder input.
438+ // Note: we currently do not override any of the
439+ // default settings.
431440 uhdr_compressed_image_t uhdr_compressed;
432441 uhdr_compressed.data = buffer.data ();
433442 uhdr_compressed.data_sz = buffer.size ();
434443 uhdr_compressed.capacity = buffer.size ();
435444 uhdr_dec_set_image (m_uhdr_dec, &uhdr_compressed);
436445
446+ // Decode Ultra HDR image
447+ // and check for decoding errors.
437448 uhdr_error_info_t err_info = uhdr_decode (m_uhdr_dec);
438449
439450 if (err_info.error_code != UHDR_CODEC_OK) {
@@ -445,6 +456,9 @@ JpgInput::read_uhdr(Filesystem::IOProxy* ioproxy)
445456 return false ;
446457 }
447458
459+ // Update spec with decoded image properties.
460+ // Note: we currently only support a subset of all possible
461+ // Ultra HDR image formats.
448462 uhdr_raw_image_t * uhdr_raw = uhdr_get_decoded_image (m_uhdr_dec);
449463
450464 int nchannels;
0 commit comments