opsin_inverse_test.cc (2032B)
1 // Copyright (c) the JPEG XL Project Authors. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 #include <jxl/cms.h> 7 8 #include <utility> 9 10 #include "lib/jxl/base/data_parallel.h" 11 #include "lib/jxl/codec_in_out.h" 12 #include "lib/jxl/color_encoding_internal.h" 13 #include "lib/jxl/dec_xyb.h" 14 #include "lib/jxl/enc_xyb.h" 15 #include "lib/jxl/image.h" 16 #include "lib/jxl/image_ops.h" 17 #include "lib/jxl/image_test_utils.h" 18 #include "lib/jxl/testing.h" 19 20 namespace jxl { 21 namespace { 22 23 TEST(OpsinInverseTest, LinearInverseInverts) { 24 JXL_ASSIGN_OR_DIE(Image3F linear, Image3F::Create(128, 128)); 25 RandomFillImage(&linear, 0.0f, 1.0f); 26 27 CodecInOut io; 28 io.metadata.m.SetFloat32Samples(); 29 io.metadata.m.color_encoding = ColorEncoding::LinearSRGB(); 30 JXL_ASSIGN_OR_DIE(Image3F linear2, Image3F::Create(128, 128)); 31 CopyImageTo(linear, &linear2); 32 io.SetFromImage(std::move(linear2), io.metadata.m.color_encoding); 33 ThreadPool* null_pool = nullptr; 34 JXL_ASSIGN_OR_DIE(Image3F opsin, Image3F::Create(io.xsize(), io.ysize())); 35 (void)ToXYB(io.Main(), null_pool, &opsin, *JxlGetDefaultCms()); 36 37 OpsinParams opsin_params; 38 opsin_params.Init(/*intensity_target=*/255.0f); 39 OpsinToLinearInplace(&opsin, /*pool=*/nullptr, opsin_params); 40 41 JXL_ASSERT_OK(VerifyRelativeError(linear, opsin, 3E-3, 2E-4, _)); 42 } 43 44 TEST(OpsinInverseTest, YcbCrInverts) { 45 JXL_ASSIGN_OR_DIE(Image3F rgb, Image3F::Create(128, 128)); 46 RandomFillImage(&rgb, 0.0f, 1.0f); 47 48 ThreadPool* null_pool = nullptr; 49 JXL_ASSIGN_OR_DIE(Image3F ycbcr, Image3F::Create(rgb.xsize(), rgb.ysize())); 50 EXPECT_TRUE(RgbToYcbcr(rgb.Plane(0), rgb.Plane(1), rgb.Plane(2), 51 &ycbcr.Plane(1), &ycbcr.Plane(0), &ycbcr.Plane(2), 52 null_pool)); 53 54 JXL_ASSIGN_OR_DIE(Image3F rgb2, Image3F::Create(rgb.xsize(), rgb.ysize())); 55 YcbcrToRgb(ycbcr, &rgb2, Rect(rgb)); 56 57 JXL_ASSERT_OK(VerifyRelativeError(rgb, rgb2, 4E-5, 4E-7, _)); 58 } 59 60 } // namespace 61 } // namespace jxl