Loading libs/jpegrecoverymap/include/jpegrecoverymap/jpegr.h +5 −1 Original line number Diff line number Diff line Loading @@ -206,6 +206,7 @@ public: * * @param compressed_jpegr_image compressed JPEGR image. * @param dest destination of the uncompressed JPEGR image. * @param max_display_boost (optional) the maximum available boost supported by a display * @param exif destination of the decoded EXIF metadata. The default value is NULL where the decoder will do nothing about it. If configured not NULL the decoder will write EXIF data into this structure. The format is defined in {@code jpegr_exif_struct} Loading Loading @@ -234,6 +235,7 @@ public: */ status_t decodeJPEGR(jr_compressed_ptr compressed_jpegr_image, jr_uncompressed_ptr dest, float max_display_boost = -1.0f, jr_exif_ptr exif = nullptr, jpegr_output_format output_format = JPEGR_OUTPUT_HDR_LINEAR, jr_uncompressed_ptr recovery_map = nullptr, Loading Loading @@ -281,6 +283,7 @@ protected: * @param output_format flag for setting output color format. if set to * {@code JPEGR_OUTPUT_SDR}, decoder will only decode the primary image * which is SDR. Default value is JPEGR_OUTPUT_HDR_LINEAR. * @param max_display_boost the maximum available boost supported by a display * @param dest reconstructed HDR image * @return NO_ERROR if calculation succeeds, error code if error occurs. */ Loading @@ -288,6 +291,7 @@ protected: jr_uncompressed_ptr uncompressed_recovery_map, jr_metadata_ptr metadata, jpegr_output_format output_format, float max_display_boost, jr_uncompressed_ptr dest); private: Loading libs/jpegrecoverymap/include/jpegrecoverymap/recoverymapmath.h +11 −0 Original line number Diff line number Diff line Loading @@ -135,6 +135,16 @@ struct RecoveryLUT { } } RecoveryLUT(jr_metadata_ptr metadata, float displayBoost) { float boostFactor = displayBoost > 0 ? displayBoost / metadata->maxContentBoost : 1.0f; for (int idx = 0; idx < kRecoveryFactorNumEntries; idx++) { float value = static_cast<float>(idx) / static_cast<float>(kRecoveryFactorNumEntries - 1); float logBoost = log2(metadata->minContentBoost) * (1.0f - value) + log2(metadata->maxContentBoost) * value; mRecoveryTable[idx] = exp2(logBoost * boostFactor); } } ~RecoveryLUT() { } Loading Loading @@ -357,6 +367,7 @@ uint8_t encodeRecovery(float y_sdr, float y_hdr, jr_metadata_ptr metadata); * value, with the given hdr ratio, to the given sdr input in the range [0, 1]. */ Color applyRecovery(Color e, float recovery, jr_metadata_ptr metadata); Color applyRecovery(Color e, float recovery, jr_metadata_ptr metadata, float displayBoost); Color applyRecoveryLUT(Color e, float recovery, RecoveryLUT& recoveryLUT); /* Loading libs/jpegrecoverymap/jpegr.cpp +11 −6 Original line number Diff line number Diff line Loading @@ -330,6 +330,7 @@ status_t JpegR::getJPEGRInfo(jr_compressed_ptr compressed_jpegr_image, jr_info_p /* Decode API */ status_t JpegR::decodeJPEGR(jr_compressed_ptr compressed_jpegr_image, jr_uncompressed_ptr dest, float max_display_boost, jr_exif_ptr exif, jpegr_output_format output_format, jr_uncompressed_ptr recovery_map, Loading Loading @@ -431,7 +432,7 @@ status_t JpegR::decodeJPEGR(jr_compressed_ptr compressed_jpegr_image, uncompressed_yuv_420_image.height = jpeg_decoder.getDecompressedImageHeight(); JPEGR_CHECK(applyRecoveryMap(&uncompressed_yuv_420_image, &map, &jr_metadata, output_format, dest)); max_display_boost, dest)); return NO_ERROR; } Loading Loading @@ -667,6 +668,7 @@ status_t JpegR::applyRecoveryMap(jr_uncompressed_ptr uncompressed_yuv_420_image, jr_uncompressed_ptr uncompressed_recovery_map, jr_metadata_ptr metadata, jpegr_output_format output_format, float max_display_boost, jr_uncompressed_ptr dest) { if (uncompressed_yuv_420_image == nullptr || uncompressed_recovery_map == nullptr Loading @@ -678,13 +680,15 @@ status_t JpegR::applyRecoveryMap(jr_uncompressed_ptr uncompressed_yuv_420_image, dest->width = uncompressed_yuv_420_image->width; dest->height = uncompressed_yuv_420_image->height; ShepardsIDW idwTable(kMapDimensionScaleFactor); RecoveryLUT recoveryLUT(metadata); float display_boost = max_display_boost > 0 ? std::min(max_display_boost, metadata->maxContentBoost) : metadata->maxContentBoost; RecoveryLUT recoveryLUT(metadata, display_boost); JobQueue jobQueue; std::function<void()> applyRecMap = [uncompressed_yuv_420_image, uncompressed_recovery_map, metadata, dest, &jobQueue, &idwTable, output_format, &recoveryLUT]() -> void { const float hdr_ratio = metadata->maxContentBoost; &recoveryLUT, display_boost]() -> void { size_t width = uncompressed_yuv_420_image->width; size_t height = uncompressed_yuv_420_image->height; Loading @@ -710,12 +714,13 @@ status_t JpegR::applyRecoveryMap(jr_uncompressed_ptr uncompressed_yuv_420_image, } else { recovery = sampleMap(uncompressed_recovery_map, map_scale_factor, x, y, idwTable); } #if USE_APPLY_RECOVERY_LUT Color rgb_hdr = applyRecoveryLUT(rgb_sdr, recovery, recoveryLUT); #else Color rgb_hdr = applyRecovery(rgb_sdr, recovery, metadata); Color rgb_hdr = applyRecovery(rgb_sdr, recovery, metadata, display_boost); #endif rgb_hdr = rgb_hdr / metadata->maxContentBoost; rgb_hdr = rgb_hdr / display_boost; size_t pixel_idx = x + y * width; switch (output_format) { Loading libs/jpegrecoverymap/recoverymapmath.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -463,6 +463,13 @@ Color applyRecovery(Color e, float recovery, jr_metadata_ptr metadata) { return e * recoveryFactor; } Color applyRecovery(Color e, float recovery, jr_metadata_ptr metadata, float displayBoost) { float logBoost = log2(metadata->minContentBoost) * (1.0f - recovery) + log2(metadata->maxContentBoost) * recovery; float recoveryFactor = exp2(logBoost * displayBoost / metadata->maxContentBoost); return e * recoveryFactor; } Color applyRecoveryLUT(Color e, float recovery, RecoveryLUT& recoveryLUT) { float recoveryFactor = recoveryLUT.getRecoveryFactor(recovery); return e * recoveryFactor; Loading libs/jpegrecoverymap/tests/jpegr_test.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -152,7 +152,8 @@ void JpegRBenchmark::BenchmarkApplyRecoveryMap(jr_uncompressed_ptr yuv420Image, timerStart(&applyRecMapTime); for (auto i = 0; i < kProfileCount; i++) { ASSERT_EQ(OK, applyRecoveryMap(yuv420Image, map, metadata, JPEGR_OUTPUT_HDR_HLG, dest)); ASSERT_EQ(OK, applyRecoveryMap(yuv420Image, map, metadata, JPEGR_OUTPUT_HDR_HLG, metadata->maxContentBoost /* displayBoost */, dest)); } timerStop(&applyRecMapTime); Loading @@ -170,7 +171,7 @@ TEST_F(JpegRTest, build) { jpegRCodec.encodeJPEGR(nullptr, nullptr, nullptr, static_cast<jpegr_transfer_function>(0), nullptr); jpegRCodec.encodeJPEGR(nullptr, nullptr, static_cast<jpegr_transfer_function>(0), nullptr); jpegRCodec.decodeJPEGR(nullptr, nullptr, nullptr); jpegRCodec.decodeJPEGR(nullptr, nullptr); } TEST_F(JpegRTest, writeXmpThenRead) { Loading Loading
libs/jpegrecoverymap/include/jpegrecoverymap/jpegr.h +5 −1 Original line number Diff line number Diff line Loading @@ -206,6 +206,7 @@ public: * * @param compressed_jpegr_image compressed JPEGR image. * @param dest destination of the uncompressed JPEGR image. * @param max_display_boost (optional) the maximum available boost supported by a display * @param exif destination of the decoded EXIF metadata. The default value is NULL where the decoder will do nothing about it. If configured not NULL the decoder will write EXIF data into this structure. The format is defined in {@code jpegr_exif_struct} Loading Loading @@ -234,6 +235,7 @@ public: */ status_t decodeJPEGR(jr_compressed_ptr compressed_jpegr_image, jr_uncompressed_ptr dest, float max_display_boost = -1.0f, jr_exif_ptr exif = nullptr, jpegr_output_format output_format = JPEGR_OUTPUT_HDR_LINEAR, jr_uncompressed_ptr recovery_map = nullptr, Loading Loading @@ -281,6 +283,7 @@ protected: * @param output_format flag for setting output color format. if set to * {@code JPEGR_OUTPUT_SDR}, decoder will only decode the primary image * which is SDR. Default value is JPEGR_OUTPUT_HDR_LINEAR. * @param max_display_boost the maximum available boost supported by a display * @param dest reconstructed HDR image * @return NO_ERROR if calculation succeeds, error code if error occurs. */ Loading @@ -288,6 +291,7 @@ protected: jr_uncompressed_ptr uncompressed_recovery_map, jr_metadata_ptr metadata, jpegr_output_format output_format, float max_display_boost, jr_uncompressed_ptr dest); private: Loading
libs/jpegrecoverymap/include/jpegrecoverymap/recoverymapmath.h +11 −0 Original line number Diff line number Diff line Loading @@ -135,6 +135,16 @@ struct RecoveryLUT { } } RecoveryLUT(jr_metadata_ptr metadata, float displayBoost) { float boostFactor = displayBoost > 0 ? displayBoost / metadata->maxContentBoost : 1.0f; for (int idx = 0; idx < kRecoveryFactorNumEntries; idx++) { float value = static_cast<float>(idx) / static_cast<float>(kRecoveryFactorNumEntries - 1); float logBoost = log2(metadata->minContentBoost) * (1.0f - value) + log2(metadata->maxContentBoost) * value; mRecoveryTable[idx] = exp2(logBoost * boostFactor); } } ~RecoveryLUT() { } Loading Loading @@ -357,6 +367,7 @@ uint8_t encodeRecovery(float y_sdr, float y_hdr, jr_metadata_ptr metadata); * value, with the given hdr ratio, to the given sdr input in the range [0, 1]. */ Color applyRecovery(Color e, float recovery, jr_metadata_ptr metadata); Color applyRecovery(Color e, float recovery, jr_metadata_ptr metadata, float displayBoost); Color applyRecoveryLUT(Color e, float recovery, RecoveryLUT& recoveryLUT); /* Loading
libs/jpegrecoverymap/jpegr.cpp +11 −6 Original line number Diff line number Diff line Loading @@ -330,6 +330,7 @@ status_t JpegR::getJPEGRInfo(jr_compressed_ptr compressed_jpegr_image, jr_info_p /* Decode API */ status_t JpegR::decodeJPEGR(jr_compressed_ptr compressed_jpegr_image, jr_uncompressed_ptr dest, float max_display_boost, jr_exif_ptr exif, jpegr_output_format output_format, jr_uncompressed_ptr recovery_map, Loading Loading @@ -431,7 +432,7 @@ status_t JpegR::decodeJPEGR(jr_compressed_ptr compressed_jpegr_image, uncompressed_yuv_420_image.height = jpeg_decoder.getDecompressedImageHeight(); JPEGR_CHECK(applyRecoveryMap(&uncompressed_yuv_420_image, &map, &jr_metadata, output_format, dest)); max_display_boost, dest)); return NO_ERROR; } Loading Loading @@ -667,6 +668,7 @@ status_t JpegR::applyRecoveryMap(jr_uncompressed_ptr uncompressed_yuv_420_image, jr_uncompressed_ptr uncompressed_recovery_map, jr_metadata_ptr metadata, jpegr_output_format output_format, float max_display_boost, jr_uncompressed_ptr dest) { if (uncompressed_yuv_420_image == nullptr || uncompressed_recovery_map == nullptr Loading @@ -678,13 +680,15 @@ status_t JpegR::applyRecoveryMap(jr_uncompressed_ptr uncompressed_yuv_420_image, dest->width = uncompressed_yuv_420_image->width; dest->height = uncompressed_yuv_420_image->height; ShepardsIDW idwTable(kMapDimensionScaleFactor); RecoveryLUT recoveryLUT(metadata); float display_boost = max_display_boost > 0 ? std::min(max_display_boost, metadata->maxContentBoost) : metadata->maxContentBoost; RecoveryLUT recoveryLUT(metadata, display_boost); JobQueue jobQueue; std::function<void()> applyRecMap = [uncompressed_yuv_420_image, uncompressed_recovery_map, metadata, dest, &jobQueue, &idwTable, output_format, &recoveryLUT]() -> void { const float hdr_ratio = metadata->maxContentBoost; &recoveryLUT, display_boost]() -> void { size_t width = uncompressed_yuv_420_image->width; size_t height = uncompressed_yuv_420_image->height; Loading @@ -710,12 +714,13 @@ status_t JpegR::applyRecoveryMap(jr_uncompressed_ptr uncompressed_yuv_420_image, } else { recovery = sampleMap(uncompressed_recovery_map, map_scale_factor, x, y, idwTable); } #if USE_APPLY_RECOVERY_LUT Color rgb_hdr = applyRecoveryLUT(rgb_sdr, recovery, recoveryLUT); #else Color rgb_hdr = applyRecovery(rgb_sdr, recovery, metadata); Color rgb_hdr = applyRecovery(rgb_sdr, recovery, metadata, display_boost); #endif rgb_hdr = rgb_hdr / metadata->maxContentBoost; rgb_hdr = rgb_hdr / display_boost; size_t pixel_idx = x + y * width; switch (output_format) { Loading
libs/jpegrecoverymap/recoverymapmath.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -463,6 +463,13 @@ Color applyRecovery(Color e, float recovery, jr_metadata_ptr metadata) { return e * recoveryFactor; } Color applyRecovery(Color e, float recovery, jr_metadata_ptr metadata, float displayBoost) { float logBoost = log2(metadata->minContentBoost) * (1.0f - recovery) + log2(metadata->maxContentBoost) * recovery; float recoveryFactor = exp2(logBoost * displayBoost / metadata->maxContentBoost); return e * recoveryFactor; } Color applyRecoveryLUT(Color e, float recovery, RecoveryLUT& recoveryLUT) { float recoveryFactor = recoveryLUT.getRecoveryFactor(recovery); return e * recoveryFactor; Loading
libs/jpegrecoverymap/tests/jpegr_test.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -152,7 +152,8 @@ void JpegRBenchmark::BenchmarkApplyRecoveryMap(jr_uncompressed_ptr yuv420Image, timerStart(&applyRecMapTime); for (auto i = 0; i < kProfileCount; i++) { ASSERT_EQ(OK, applyRecoveryMap(yuv420Image, map, metadata, JPEGR_OUTPUT_HDR_HLG, dest)); ASSERT_EQ(OK, applyRecoveryMap(yuv420Image, map, metadata, JPEGR_OUTPUT_HDR_HLG, metadata->maxContentBoost /* displayBoost */, dest)); } timerStop(&applyRecMapTime); Loading @@ -170,7 +171,7 @@ TEST_F(JpegRTest, build) { jpegRCodec.encodeJPEGR(nullptr, nullptr, nullptr, static_cast<jpegr_transfer_function>(0), nullptr); jpegRCodec.encodeJPEGR(nullptr, nullptr, static_cast<jpegr_transfer_function>(0), nullptr); jpegRCodec.decodeJPEGR(nullptr, nullptr, nullptr); jpegRCodec.decodeJPEGR(nullptr, nullptr); } TEST_F(JpegRTest, writeXmpThenRead) { Loading