Add RecoveryMapMath tests; also some fixes.
Add thorough tests for recovery map math. Also, the following fixes for
issues discovered along the way:
* Added proper scaling of luminances during map generation
* Corrected some luminance and color conversions using incorrect
luminance/luma cooeficients
* Corrected PQ inverse OETF
* Corrected clipping of gain when encoding recovery
* Corrected sampleMap to use a better, working sampling algorithm
instead of the previous bad and incorrect one
* Clarified expected ranges in and out of some transformation
functions
* Clarified references for a bunch of transformations
Bug: 252835416
Test: builds, new tests pass
Change-Id: I3c2192e840b784774c60cf212aaf188501915340
diff --git a/libs/jpegrecoverymap/recoverymap.cpp b/libs/jpegrecoverymap/recoverymap.cpp
index 4a209ec..f7f3622 100644
--- a/libs/jpegrecoverymap/recoverymap.cpp
+++ b/libs/jpegrecoverymap/recoverymap.cpp
@@ -390,12 +390,15 @@
map_data.reset(reinterpret_cast<uint8_t*>(dest->data));
ColorTransformFn hdrInvOetf = nullptr;
+ float hdr_white_nits = 0.0f;
switch (metadata->transferFunction) {
case JPEGR_TF_HLG:
hdrInvOetf = hlgInvOetf;
+ hdr_white_nits = kHlgMaxNits;
break;
case JPEGR_TF_PQ:
hdrInvOetf = pqInvOetf;
+ hdr_white_nits = kPqMaxNits;
break;
}
@@ -426,7 +429,7 @@
Color hdr_rgb_gamma = bt2100YuvToRgb(hdr_yuv_gamma);
Color hdr_rgb = hdrInvOetf(hdr_rgb_gamma);
hdr_rgb = hdrGamutConversionFn(hdr_rgb);
- float hdr_y_nits = luminanceFn(hdr_rgb);
+ float hdr_y_nits = luminanceFn(hdr_rgb) * hdr_white_nits;
hdr_y_nits_avg += hdr_y_nits;
if (hdr_y_nits > hdr_y_nits_max) {
@@ -448,13 +451,13 @@
kMapDimensionScaleFactor, x, y);
Color sdr_rgb_gamma = srgbYuvToRgb(sdr_yuv_gamma);
Color sdr_rgb = srgbInvOetf(sdr_rgb_gamma);
- float sdr_y_nits = luminanceFn(sdr_rgb);
+ float sdr_y_nits = luminanceFn(sdr_rgb) * kSdrWhiteNits;
Color hdr_yuv_gamma = sampleP010(uncompressed_p010_image, kMapDimensionScaleFactor, x, y);
Color hdr_rgb_gamma = bt2100YuvToRgb(hdr_yuv_gamma);
Color hdr_rgb = hdrInvOetf(hdr_rgb_gamma);
hdr_rgb = hdrGamutConversionFn(hdr_rgb);
- float hdr_y_nits = luminanceFn(hdr_rgb);
+ float hdr_y_nits = luminanceFn(hdr_rgb) * hdr_white_nits;
size_t pixel_idx = x + y * map_width;
reinterpret_cast<uint8_t*>(dest->data)[pixel_idx] =