gauss_blur.h (2147B)
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_GAUSS_BLUR_H_ 7 #define LIB_JXL_GAUSS_BLUR_H_ 8 9 #include <cstddef> 10 #include <functional> 11 #include <hwy/aligned_allocator.h> 12 13 #include "lib/jxl/base/data_parallel.h" 14 15 namespace jxl { 16 17 // Only for use by CreateRecursiveGaussian and FastGaussian*. 18 #pragma pack(push, 1) 19 struct RecursiveGaussian { 20 // For k={1,3,5} in that order, each broadcasted 4x for LoadDup128. Used only 21 // for vertical passes. 22 float n2[3 * 4]; 23 float d1[3 * 4]; 24 25 // We unroll horizontal passes 4x - one output per lane. These are each lane's 26 // multiplier for the previous output (relative to the first of the four 27 // outputs). Indexing: 4 * 0..2 (for {1,3,5}) + 0..3 for the lane index. 28 float mul_prev[3 * 4]; 29 // Ditto for the second to last output. 30 float mul_prev2[3 * 4]; 31 32 // We multiply a vector of inputs 0..3 by a vector shifted from this array. 33 // in=0 uses all 4 (nonzero) terms; for in=3, the lower three lanes are 0. 34 float mul_in[3 * 4]; 35 36 size_t radius; 37 }; 38 #pragma pack(pop) 39 40 // Precomputation for FastGaussian*; users may use the same pointer/storage in 41 // subsequent calls to FastGaussian* with the same sigma. 42 hwy::AlignedUniquePtr<RecursiveGaussian> CreateRecursiveGaussian(double sigma); 43 44 // 1D Gaussian with zero-pad boundary handling and runtime independent of sigma. 45 void FastGaussian1D(const hwy::AlignedUniquePtr<RecursiveGaussian>& rg, 46 size_t xsize, const float* JXL_RESTRICT in, 47 float* JXL_RESTRICT out); 48 49 typedef std::function<const float*(size_t /*y*/)> GetConstRow; 50 typedef std::function<float*(size_t /*y*/)> GetRow; 51 52 // 2D Gaussian with zero-pad boundary handling and runtime independent of sigma. 53 void FastGaussian(const hwy::AlignedUniquePtr<RecursiveGaussian>& rg, 54 size_t xsize, size_t ysize, const GetConstRow& in, 55 const GetRow& temp, const GetRow& out, 56 ThreadPool* pool = nullptr); 57 58 } // namespace jxl 59 60 #endif // LIB_JXL_GAUSS_BLUR_H_