1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef MOZILLA_GFX_CONVOLUTION_FILTER_H_
8 #define MOZILLA_GFX_CONVOLUTION_FILTER_H_
9 
10 #include "mozilla/UniquePtr.h"
11 
12 class SkConvolutionFilter1D;
13 
14 namespace mozilla {
15 namespace gfx {
16 
17 class ConvolutionFilter final {
18  public:
19   ConvolutionFilter();
20   ~ConvolutionFilter();
21 
22   int32_t MaxFilter() const;
23   int32_t NumValues() const;
24 
25   bool GetFilterOffsetAndLength(int32_t aRowIndex, int32_t* aResultOffset,
26                                 int32_t* aResultLength);
27 
28   void ConvolveHorizontally(const uint8_t* aSrc, uint8_t* aDst, bool aHasAlpha);
29   void ConvolveVertically(uint8_t* const* aSrc, uint8_t* aDst,
30                           int32_t aRowIndex, int32_t aRowSize, bool aHasAlpha);
31 
32   enum class ResizeMethod { BOX, TRIANGLE, LANCZOS3, HAMMING, MITCHELL };
33 
34   bool ComputeResizeFilter(ResizeMethod aResizeMethod, int32_t aSrcSize,
35                            int32_t aDstSize);
36 
PadBytesForSIMD(size_t aBytes)37   static inline size_t PadBytesForSIMD(size_t aBytes) {
38     return (aBytes + 31) & ~31;
39   }
40 
41  private:
42   UniquePtr<SkConvolutionFilter1D> mFilter;
43 };
44 
45 }  // namespace gfx
46 }  // namespace mozilla
47 
48 #endif /* MOZILLA_GFX_CONVOLUTION_FILTER_H_ */
49