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