libjxl

FORK: libjxl patches used on blog
git clone https://git.neptards.moe/blog/libjxl.git
Log | Files | Refs | Submodules | README | LICENSE

gamma_correct_test.cc (1124B)


      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 <stdlib.h>
      7 
      8 #include <algorithm>
      9 
     10 #include "lib/jxl/enc_gamma_correct.h"
     11 #include "lib/jxl/testing.h"
     12 
     13 namespace jxl {
     14 namespace {
     15 
     16 TEST(GammaCorrectTest, TestLinearToSrgbEdgeCases) {
     17   EXPECT_EQ(0, LinearToSrgb8Direct(0.0));
     18   EXPECT_NEAR(0, LinearToSrgb8Direct(1E-6f), 2E-5);
     19   EXPECT_EQ(0, LinearToSrgb8Direct(-1E-6f));
     20   EXPECT_EQ(0, LinearToSrgb8Direct(-1E6));
     21   EXPECT_NEAR(1, LinearToSrgb8Direct(1 - 1E-6f), 1E-5);
     22   EXPECT_EQ(1, LinearToSrgb8Direct(1 + 1E-6f));
     23   EXPECT_EQ(1, LinearToSrgb8Direct(1E6));
     24 }
     25 
     26 TEST(GammaCorrectTest, TestRoundTrip) {
     27   // NOLINTNEXTLINE(clang-analyzer-security.FloatLoopCounter)
     28   for (double linear = 0.0; linear <= 1.0; linear += 1E-7) {
     29     const double srgb = LinearToSrgb8Direct(linear);
     30     const double linear2 = Srgb8ToLinearDirect(srgb);
     31     ASSERT_LT(std::abs(linear - linear2), 2E-13)
     32         << "linear = " << linear << ", linear2 = " << linear2;
     33   }
     34 }
     35 
     36 }  // namespace
     37 }  // namespace jxl