tor-browser

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

convolve.h (2841B)


      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 #ifndef LIB_JXL_CONVOLVE_H_
      7 #define LIB_JXL_CONVOLVE_H_
      8 
      9 // 2D convolution.
     10 
     11 #include <cstddef>
     12 
     13 #include "lib/jxl/base/compiler_specific.h"
     14 #include "lib/jxl/base/data_parallel.h"
     15 #include "lib/jxl/base/rect.h"
     16 #include "lib/jxl/base/status.h"
     17 #include "lib/jxl/image.h"
     18 
     19 namespace jxl {
     20 
     21 // No valid values outside [0, xsize), but the strategy may still safely load
     22 // the preceding vector, and/or round xsize up to the vector lane count. This
     23 // avoids needing PadImage.
     24 // Requires xsize >= kConvolveLanes + kConvolveMaxRadius.
     25 static constexpr size_t kConvolveMaxRadius = 3;
     26 
     27 // Weights must already be normalized.
     28 
     29 struct WeightsSymmetric3 {
     30  // d r d (each replicated 4x)
     31  // r c r
     32  // d r d
     33  float c[4];
     34  float r[4];
     35  float d[4];
     36 };
     37 
     38 struct WeightsSymmetric5 {
     39  // The lower-right quadrant is: c r R  (each replicated 4x)
     40  //                              r d L
     41  //                              R L D
     42  float c[4];
     43  float r[4];
     44  float R[4];
     45  float d[4];
     46  float D[4];
     47  float L[4];
     48 };
     49 
     50 // Weights for separable 5x5 filters (typically but not necessarily the same
     51 // values for horizontal and vertical directions). The kernel must already be
     52 // normalized, but note that values for negative offsets are omitted, so the
     53 // given values do not sum to 1.
     54 struct WeightsSeparable5 {
     55  // Horizontal 1D, distances 0..2 (each replicated 4x)
     56  float horz[3 * 4];
     57  float vert[3 * 4];
     58 };
     59 
     60 const WeightsSymmetric3& WeightsSymmetric3Lowpass();
     61 const WeightsSeparable5& WeightsSeparable5Lowpass();
     62 const WeightsSymmetric5& WeightsSymmetric5Lowpass();
     63 
     64 Status SlowSymmetric3(const ImageF& in, const Rect& rect,
     65                      const WeightsSymmetric3& weights, ThreadPool* pool,
     66                      ImageF* JXL_RESTRICT out);
     67 
     68 Status SlowSeparable5(const ImageF& in, const Rect& in_rect,
     69                      const WeightsSeparable5& weights, ThreadPool* pool,
     70                      ImageF* out, const Rect& out_rect);
     71 
     72 Status Symmetric3(const ImageF& in, const Rect& rect,
     73                  const WeightsSymmetric3& weights, ThreadPool* pool,
     74                  ImageF* out);
     75 
     76 Status Symmetric5(const ImageF& in, const Rect& in_rect,
     77                  const WeightsSymmetric5& weights, ThreadPool* pool,
     78                  ImageF* JXL_RESTRICT out, const Rect& out_rect);
     79 
     80 Status Symmetric5(const ImageF& in, const Rect& rect,
     81                  const WeightsSymmetric5& weights, ThreadPool* pool,
     82                  ImageF* JXL_RESTRICT out);
     83 
     84 Status Separable5(const ImageF& in, const Rect& rect,
     85                  const WeightsSeparable5& weights, ThreadPool* pool,
     86                  ImageF* out);
     87 
     88 }  // namespace jxl
     89 
     90 #endif  // LIB_JXL_CONVOLVE_H_