tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

opsin_inverse_test.cc (2592B)


      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 #include <jxl/memory_manager.h>
      8 
      9 #include <utility>
     10 
     11 #include "lib/jxl/base/data_parallel.h"
     12 #include "lib/jxl/base/rect.h"
     13 #include "lib/jxl/codec_in_out.h"
     14 #include "lib/jxl/color_encoding_internal.h"
     15 #include "lib/jxl/dec_xyb.h"
     16 #include "lib/jxl/enc_xyb.h"
     17 #include "lib/jxl/image.h"
     18 #include "lib/jxl/image_ops.h"
     19 #include "lib/jxl/image_test_utils.h"
     20 #include "lib/jxl/test_memory_manager.h"
     21 #include "lib/jxl/test_utils.h"
     22 #include "lib/jxl/testing.h"
     23 
     24 namespace jxl {
     25 namespace {
     26 
     27 TEST(OpsinInverseTest, LinearInverseInverts) {
     28  JxlMemoryManager* memory_manager = jxl::test::MemoryManager();
     29  JXL_TEST_ASSIGN_OR_DIE(Image3F linear,
     30                         Image3F::Create(memory_manager, 128, 128));
     31  RandomFillImage(&linear, 0.0f, 1.0f);
     32 
     33  CodecInOut io{memory_manager};
     34  io.metadata.m.SetFloat32Samples();
     35  io.metadata.m.color_encoding = ColorEncoding::LinearSRGB();
     36  JXL_TEST_ASSIGN_OR_DIE(Image3F linear2,
     37                         Image3F::Create(memory_manager, 128, 128));
     38  ASSERT_TRUE(CopyImageTo(linear, &linear2));
     39  ASSERT_TRUE(
     40      io.SetFromImage(std::move(linear2), io.metadata.m.color_encoding));
     41  ThreadPool* null_pool = nullptr;
     42  JXL_TEST_ASSIGN_OR_DIE(
     43      Image3F opsin, Image3F::Create(memory_manager, io.xsize(), io.ysize()));
     44  (void)ToXYB(io.Main(), null_pool, &opsin, *JxlGetDefaultCms());
     45 
     46  OpsinParams opsin_params;
     47  opsin_params.Init(/*intensity_target=*/255.0f);
     48  ASSERT_TRUE(OpsinToLinearInplace(&opsin, /*pool=*/nullptr, opsin_params));
     49 
     50  JXL_TEST_ASSERT_OK(VerifyRelativeError(linear, opsin, 3E-3, 2E-4, _));
     51 }
     52 
     53 TEST(OpsinInverseTest, YcbCrInverts) {
     54  JxlMemoryManager* memory_manager = jxl::test::MemoryManager();
     55  JXL_TEST_ASSIGN_OR_DIE(Image3F rgb,
     56                         Image3F::Create(memory_manager, 128, 128));
     57  RandomFillImage(&rgb, 0.0f, 1.0f);
     58 
     59  ThreadPool* null_pool = nullptr;
     60  JXL_TEST_ASSIGN_OR_DIE(
     61      Image3F ycbcr, Image3F::Create(memory_manager, rgb.xsize(), rgb.ysize()));
     62  EXPECT_TRUE(RgbToYcbcr(rgb.Plane(0), rgb.Plane(1), rgb.Plane(2),
     63                         &ycbcr.Plane(1), &ycbcr.Plane(0), &ycbcr.Plane(2),
     64                         null_pool));
     65 
     66  JXL_TEST_ASSIGN_OR_DIE(
     67      Image3F rgb2, Image3F::Create(memory_manager, rgb.xsize(), rgb.ysize()));
     68  YcbcrToRgb(ycbcr, &rgb2, Rect(rgb));
     69 
     70  JXL_TEST_ASSERT_OK(VerifyRelativeError(rgb, rgb2, 4E-5, 4E-7, _));
     71 }
     72 
     73 }  // namespace
     74 }  // namespace jxl