From 96ec2feaed19f974dac9ce45e1123469590348c4 Mon Sep 17 00:00:00 2001 From: Georges Berenger Date: Tue, 5 Dec 2023 10:37:09 -0800 Subject: [PATCH] Fix jxl grey8 compression Summary: This diff fixes the quality issues we noticed with grey8 when using MS-SSIM testing. It's unclear how we got to the non-sense grey8 code, but the MS-SSIM validation doesn't lie: grey8 works now. Reviewed By: kiminoue7 Differential Revision: D51841807 fbshipit-source-id: a8b26e4ee8d25263cf7d659c5e5fea1dfa430673 --- vrs/utils/PixelFrameJxl.cpp | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/vrs/utils/PixelFrameJxl.cpp b/vrs/utils/PixelFrameJxl.cpp index 21b545d1..6c405e34 100644 --- a/vrs/utils/PixelFrameJxl.cpp +++ b/vrs/utils/PixelFrameJxl.cpp @@ -170,16 +170,8 @@ bool PixelFrame::readJxlFrame(const vector& jxlBuf, bool decodePixels) case JXL_DEC_COLOR_ENCODING: { JxlColorEncoding colorEncoding; - if (JxlDecoderGetColorAsEncodedProfile( - dec, &format, JXL_COLOR_PROFILE_TARGET_ORIGINAL, &colorEncoding) == - JXL_DEC_SUCCESS && - colorEncoding.color_space == JXL_COLOR_SPACE_GRAY) { - colorEncoding.gamma = 0.5; - colorEncoding.transfer_function = JXL_TRANSFER_FUNCTION_GAMMA; - } else { - DEC_CHECK(JxlDecoderGetColorAsEncodedProfile( - dec, &format, JXL_COLOR_PROFILE_TARGET_ORIGINAL, &colorEncoding)); - } + DEC_CHECK(JxlDecoderGetColorAsEncodedProfile( + dec, &format, JXL_COLOR_PROFILE_TARGET_ORIGINAL, &colorEncoding)); DEC_CHECK(JxlDecoderSetPreferredColorProfile(dec, &colorEncoding)); } break; @@ -334,15 +326,7 @@ bool PixelFrame::jxlCompress( ENC_CHECK(JxlEncoderSetBasicInfo(enc, &basic_info)); JxlColorEncoding color_encoding = {}; - if (basic_info.num_color_channels > 1) { - JxlColorEncodingSetToLinearSRGB( - &color_encoding, - /*is_gray=*/pixel_format.num_channels < 3); - } else { - JxlColorEncodingSetToSRGB( - &color_encoding, - /*is_gray=*/pixel_format.num_channels < 3); - } + JxlColorEncodingSetToLinearSRGB(&color_encoding, basic_info.num_color_channels < 2); ENC_CHECK(JxlEncoderSetColorEncoding(enc, &color_encoding)); JxlEncoderFrameSettings* settings = JxlEncoderFrameSettingsCreate(enc, nullptr);