libjxl

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

enc_gaborish_test.cc (2353B)


      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 "lib/jxl/enc_gaborish.h"
      7 
      8 #include <jxl/types.h>
      9 
     10 #include <hwy/base.h>
     11 
     12 #include "lib/jxl/base/compiler_specific.h"
     13 #include "lib/jxl/base/data_parallel.h"
     14 #include "lib/jxl/base/status.h"
     15 #include "lib/jxl/convolve.h"
     16 #include "lib/jxl/image.h"
     17 #include "lib/jxl/image_ops.h"
     18 #include "lib/jxl/image_test_utils.h"
     19 #include "lib/jxl/testing.h"
     20 
     21 namespace jxl {
     22 namespace {
     23 
     24 // weight1,2 need not be normalized.
     25 WeightsSymmetric3 GaborishKernel(float weight1, float weight2) {
     26   constexpr float weight0 = 1.0f;
     27 
     28   // Normalize
     29   const float mul = 1.0f / (weight0 + 4 * (weight1 + weight2));
     30   const float w0 = weight0 * mul;
     31   const float w1 = weight1 * mul;
     32   const float w2 = weight2 * mul;
     33 
     34   const WeightsSymmetric3 w = {{HWY_REP4(w0)}, {HWY_REP4(w1)}, {HWY_REP4(w2)}};
     35   return w;
     36 }
     37 
     38 void ConvolveGaborish(const ImageF& in, float weight1, float weight2,
     39                       ThreadPool* pool, ImageF* JXL_RESTRICT out) {
     40   JXL_CHECK(SameSize(in, *out));
     41   Symmetric3(in, Rect(in), GaborishKernel(weight1, weight2), pool, out);
     42 }
     43 
     44 void TestRoundTrip(const Image3F& in, float max_l1) {
     45   JXL_ASSIGN_OR_DIE(Image3F fwd, Image3F::Create(in.xsize(), in.ysize()));
     46   ThreadPool* null_pool = nullptr;
     47   ConvolveGaborish(in.Plane(0), 0, 0, null_pool, &fwd.Plane(0));
     48   ConvolveGaborish(in.Plane(1), 0, 0, null_pool, &fwd.Plane(1));
     49   ConvolveGaborish(in.Plane(2), 0, 0, null_pool, &fwd.Plane(2));
     50   float w = 0.92718927264540152f;
     51   float weights[3] = {
     52       w,
     53       w,
     54       w,
     55   };
     56   JXL_CHECK(GaborishInverse(&fwd, Rect(fwd), weights, null_pool));
     57   JXL_ASSERT_OK(VerifyRelativeError(in, fwd, max_l1, 1E-4f, _));
     58 }
     59 
     60 TEST(GaborishTest, TestZero) {
     61   JXL_ASSIGN_OR_DIE(Image3F in, Image3F::Create(20, 20));
     62   ZeroFillImage(&in);
     63   TestRoundTrip(in, 0.0f);
     64 }
     65 
     66 // Disabled: large difference.
     67 #if JXL_FALSE
     68 TEST(GaborishTest, TestDirac) {
     69   JXL_ASSIGN_OR_DIE(Image3F in, Image3F::Create(20, 20));
     70   ZeroFillImage(&in);
     71   in.PlaneRow(1, 10)[10] = 10.0f;
     72   TestRoundTrip(in, 0.26f);
     73 }
     74 #endif
     75 
     76 TEST(GaborishTest, TestFlat) {
     77   JXL_ASSIGN_OR_DIE(Image3F in, Image3F::Create(20, 20));
     78   FillImage(1.0f, &in);
     79   TestRoundTrip(in, 1E-5f);
     80 }
     81 
     82 }  // namespace
     83 }  // namespace jxl