Ocean
SumSquareDifferencesNoCenterSSE.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_CV_ADVANCED_SUM_SQUARE_DIFFERENCES_NO_CENTER_SSE_H
9 #define META_OCEAN_CV_ADVANCED_SUM_SQUARE_DIFFERENCES_NO_CENTER_SSE_H
10 
12 
13 #if defined(OCEAN_HARDWARE_SSE_VERSION) && OCEAN_HARDWARE_SSE_VERSION >= 41
14 
16 
17 namespace Ocean
18 {
19 
20 namespace CV
21 {
22 
23 namespace Advanced
24 {
25 
26 /**
27  * This class implements functions calculating the sum of square differences and omits center pixel using SSE instructions.
28  * @ingroup cvadvanced
29  */
31 {
32  protected:
33 
34  /**
35  * Internal helper class providing access to CV::SumSquareDifferencesSSE
36  */
38  {
39  // nothing to do here
40  };
41 
42  public:
43 
44  /**
45  * Returns the sum of square differences between two square patches while skipping the center pixel.
46  * @param image0 The image in which the first patch is located, must be valid
47  * @param image1 The image in which the second patch is located, must be valid
48  * @param width0 The width of the first image, in pixels, with range [tPatchSize, infinity)
49  * @param width1 The width of the second image, in pixels, with range [tPatchSize, infinity)
50  * @param centerX0 Horizontal center position of the (tPatchSize x tPatchSize) block in the first frame, with range [tPatchSize/2, width - tPatchSize/2 - 1]
51  * @param centerY0 Vertical center position of the (tPatchSize x tPatchSize) block in the first frame, with range [tPatchSize/2, height - tPatchSize/2 - 1]
52  * @param centerX1 Horizontal center position of the (tPatchSize x tPatchSize) block in the second frame, with range [tPatchSize/2, width - tPatchSize/2 - 1]
53  * @param centerY1 Vertical center position of the (tPatchSize x tPatchSize) block in the second frame, with range [tPatchSize/2, height - tPatchSize/2 - 1]
54  * @param image0PaddingElements The number of padding elements at the end of each row of the first image, in elements, with range [0, infinity)
55  * @param image1PaddingElements The number of padding elements at the end of each row of the second image, in elements, with range [0, infinity)
56  * @return The resulting sum of square differences, with range [0, infinity)
57  * @tparam tChannels The number of frame channels, with range [1, infinity)
58  * @tparam tPatchSize The size of the square patch (the edge length) in pixel, with range [1, infinity), must be odd
59  */
60  template <unsigned int tChannels, unsigned int tPatchSize>
61  static inline uint32_t patch8BitPerChannel(const uint8_t* const image0, const uint8_t* const image1, const unsigned int width0, const unsigned int width1, const unsigned int centerX0, const unsigned int centerY0, const unsigned int centerX1, const unsigned int centerY1, const unsigned int image0PaddingElements, const unsigned int image1PaddingElements);
62 };
63 
64 template <unsigned int tChannels, unsigned int tPatchSize>
65 inline uint32_t SumSquareDifferencesNoCenterSSE::patch8BitPerChannel(const uint8_t* const image0, const uint8_t* const image1, const unsigned int width0, const unsigned int width1, const unsigned int centerX0, const unsigned int centerY0, const unsigned int centerX1, const unsigned int centerY1, const unsigned int image0PaddingElements, const unsigned int image1PaddingElements)
66 {
67  static_assert(tChannels >= 1u, "Invalid channel number!");
68  static_assert(tPatchSize >= 1u, "Invalid patch size!");
69 
70  ocean_assert(image0 != nullptr && image1 != nullptr);
71 
72  ocean_assert(width0 >= tPatchSize);
73  ocean_assert(width1 >= tPatchSize);
74 
75  constexpr unsigned int tPatchSize_2 = tPatchSize / 2u;
76 
77  ocean_assert(centerX0 >= tPatchSize_2 && centerY0 >= tPatchSize_2);
78  ocean_assert(centerX1 >= tPatchSize_2 && centerY1 >= tPatchSize_2);
79 
80  ocean_assert(centerX0 < width0 - tPatchSize_2);
81  ocean_assert(centerX1 < width1 - tPatchSize_2);
82 
83  const unsigned int image0StrideElements = width0 * tChannels + image0PaddingElements;
84  const unsigned int image1StrideElements = width1 * tChannels + image1PaddingElements;
85 
86  const uint8_t* const patch0 = image0 + (centerY0 - tPatchSize_2) * image0StrideElements + (centerX0 - tPatchSize_2) * tChannels;
87  const uint8_t* const patch1 = image1 + (centerY1 - tPatchSize_2) * image1StrideElements + (centerX1 - tPatchSize_2) * tChannels;
88 
89  return SumSquareDifferencesSSE::patch8BitPerChannel<tChannels, tPatchSize>(patch0, patch1, image0StrideElements, image1StrideElements)
90  - SumSquareDifferences::buffer8BitPerChannel<tChannels, 1u>(patch0 + tPatchSize_2 * image0StrideElements + tPatchSize_2 * tChannels, patch1 + tPatchSize_2 * image1StrideElements + tPatchSize_2 * tChannels);
91 }
92 
93 }
94 
95 }
96 
97 }
98 
99 #endif // OCEAN_HARDWARE_SSE_VERSION >= 41
100 
101 #endif // META_OCEAN_CV_ADVANCED_SUM_SQUARE_DIFFERENCES_NO_CENTER_SSE_H
Internal helper class providing access to CV::SumSquareDifferencesSSE.
Definition: SumSquareDifferencesNoCenterSSE.h:38
This class implements functions calculating the sum of square differences and omits center pixel usin...
Definition: SumSquareDifferencesNoCenterSSE.h:31
static uint32_t patch8BitPerChannel(const uint8_t *const image0, const uint8_t *const image1, const unsigned int width0, const unsigned int width1, const unsigned int centerX0, const unsigned int centerY0, const unsigned int centerX1, const unsigned int centerY1, const unsigned int image0PaddingElements, const unsigned int image1PaddingElements)
Returns the sum of square differences between two square patches while skipping the center pixel.
Definition: SumSquareDifferencesNoCenterSSE.h:65
This class implements function to calculate sum square differences using SSE instructions.
Definition: SumSquareDifferencesSSE.h:30
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15