diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /third_party/jpeg-xl/lib/jxl/enc_comparator.cc | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/jpeg-xl/lib/jxl/enc_comparator.cc')
-rw-r--r-- | third_party/jpeg-xl/lib/jxl/enc_comparator.cc | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/third_party/jpeg-xl/lib/jxl/enc_comparator.cc b/third_party/jpeg-xl/lib/jxl/enc_comparator.cc index 268122af06..3ef6a49b8f 100644 --- a/third_party/jpeg-xl/lib/jxl/enc_comparator.cc +++ b/third_party/jpeg-xl/lib/jxl/enc_comparator.cc @@ -66,9 +66,10 @@ float ComputeScoreImpl(const ImageBundle& rgb0, const ImageBundle& rgb1, } // namespace -float ComputeScore(const ImageBundle& rgb0, const ImageBundle& rgb1, - Comparator* comparator, const JxlCmsInterface& cms, - ImageF* diffmap, ThreadPool* pool, bool ignore_alpha) { +Status ComputeScore(const ImageBundle& rgb0, const ImageBundle& rgb1, + Comparator* comparator, const JxlCmsInterface& cms, + float* score, ImageF* diffmap, ThreadPool* pool, + bool ignore_alpha) { // Convert to linear sRGB (unless already in that space) ImageMetadata metadata0 = *rgb0.metadata(); ImageBundle store0(&metadata0); @@ -83,25 +84,28 @@ float ComputeScore(const ImageBundle& rgb0, const ImageBundle& rgb1, // No alpha: skip blending, only need a single call to Butteraugli. if (ignore_alpha || (!rgb0.HasAlpha() && !rgb1.HasAlpha())) { - return ComputeScoreImpl(*linear_srgb0, *linear_srgb1, comparator, diffmap); + *score = + ComputeScoreImpl(*linear_srgb0, *linear_srgb1, comparator, diffmap); + return true; } // Blend on black and white backgrounds const float black = 0.0f; - ImageBundle blended_black0 = linear_srgb0->Copy(); - ImageBundle blended_black1 = linear_srgb1->Copy(); + JXL_ASSIGN_OR_RETURN(ImageBundle blended_black0, linear_srgb0->Copy()); + JXL_ASSIGN_OR_RETURN(ImageBundle blended_black1, linear_srgb1->Copy()); AlphaBlend(black, &blended_black0); AlphaBlend(black, &blended_black1); const float white = 1.0f; - ImageBundle blended_white0 = linear_srgb0->Copy(); - ImageBundle blended_white1 = linear_srgb1->Copy(); + JXL_ASSIGN_OR_RETURN(ImageBundle blended_white0, linear_srgb0->Copy()); + JXL_ASSIGN_OR_RETURN(ImageBundle blended_white1, linear_srgb1->Copy()); AlphaBlend(white, &blended_white0); AlphaBlend(white, &blended_white1); - ImageF diffmap_black, diffmap_white; + ImageF diffmap_black; + ImageF diffmap_white; const float dist_black = ComputeScoreImpl(blended_black0, blended_black1, comparator, &diffmap_black); const float dist_white = ComputeScoreImpl(blended_white0, blended_white1, @@ -111,7 +115,7 @@ float ComputeScore(const ImageBundle& rgb0, const ImageBundle& rgb1, if (diffmap != nullptr) { const size_t xsize = rgb0.xsize(); const size_t ysize = rgb0.ysize(); - *diffmap = ImageF(xsize, ysize); + JXL_ASSIGN_OR_RETURN(*diffmap, ImageF::Create(xsize, ysize)); for (size_t y = 0; y < ysize; ++y) { const float* JXL_RESTRICT row_black = diffmap_black.ConstRow(y); const float* JXL_RESTRICT row_white = diffmap_white.ConstRow(y); @@ -121,7 +125,8 @@ float ComputeScore(const ImageBundle& rgb0, const ImageBundle& rgb1, } } } - return std::max(dist_black, dist_white); + *score = std::max(dist_black, dist_white); + return true; } } // namespace jxl |