8 #ifndef META_OCEAN_CV_FRAME_FILTER_PREWITT_H
9 #define META_OCEAN_CV_FRAME_FILTER_PREWITT_H
61 template <
typename TTarget,
unsigned int tSourceChannels>
62 static inline void filterHorizontalVertical8BitPerChannel(
const uint8_t* source, TTarget* target,
const unsigned int width,
const unsigned int height,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
80 template <
typename TSource,
typename TTarget,
unsigned int tSourceChannels,
unsigned int tTargetChannels>
81 static void filterHorizontalVerticalRow(
const TSource* sourceRow, TTarget* targetRow,
const unsigned int width,
const unsigned int height,
unsigned int rowIndex,
const unsigned int sourceStrideElements,
const unsigned int targetStrideElements);
84 template <
typename TTarget,
unsigned int tSourceChannels>
87 static_assert(std::is_same<TTarget, int8_t>::value || std::is_same<TTarget, int16_t>::value,
"Invalid target data type!");
88 static_assert(tSourceChannels >= 1u,
"Invalid channel number!");
90 ocean_assert(source !=
nullptr && target !=
nullptr);
91 ocean_assert(width >= 3u && height >= 3u);
94 constexpr
unsigned int tTargetChannels = tSourceChannels * 2u;
96 FrameChannels::applyRowOperator<uint8_t, TTarget, tSourceChannels, tTargetChannels>(source, target, width, height, sourcePaddingElements, targetPaddingElements, &filterHorizontalVerticalRow<uint8_t, TTarget, tSourceChannels, tTargetChannels>, worker);
99 template <
typename TSource,
typename TTarget,
unsigned int tSourceChannels,
unsigned int tTargetChannels>
102 static_assert(std::is_same<TSource, uint8_t>::value,
"Invalid source data type!");
103 static_assert(std::is_same<TTarget, int8_t>::value || std::is_same<TTarget, int16_t>::value,
"Invalid target data type!");
105 static_assert(tSourceChannels >= 1u,
"Invalid source channel number!");
106 static_assert(tTargetChannels == tSourceChannels * 2u,
"Invalid target channel number!");
108 ocean_assert(width >= 3u && height >= 3u);
110 if (rowIndex == 0u || rowIndex == height - 1u)
114 memset(targetRow, 0, width * tTargetChannels *
sizeof(TTarget));
120 for (
unsigned int n = 0u; n < tTargetChannels; ++n)
122 targetRow[n] = TTarget(0);
125 targetRow += tTargetChannels;
127 const uint8_t* source0 = sourceRow - sourceStrideElements;
128 const uint8_t* source1 = sourceRow;
129 const uint8_t* source2 = sourceRow + sourceStrideElements;
131 for (
unsigned int x = 1u; x < width - 1u; ++x)
133 if constexpr (std::is_same<TTarget, int8_t>::value)
135 for (
unsigned int n = 0u; n < tSourceChannels; ++n)
140 *targetRow++ = TTarget((*(source0 + tSourceChannels * 2u) - *(source0) + (*(source1 + tSourceChannels * 2u) - *(source1)) + *(source2 + tSourceChannels * 2u) - *(source2)) / 8);
145 *targetRow++ = TTarget((*(source2) + (*(source2 + tSourceChannels) - *(source0 + tSourceChannels)) + *(source2 + tSourceChannels * 2u) - *(source0) - *(source0 + tSourceChannels * 2u)) / 8);
154 ocean_assert((std::is_same<TTarget, int16_t>::value));
156 for (
unsigned int n = 0u; n < tSourceChannels; ++n)
161 *targetRow++ = TTarget(*(source0 + tSourceChannels * 2u) - *(source0) + (*(source1 + tSourceChannels * 2u) - *(source1)) + *(source2 + tSourceChannels * 2u) - *(source2));
166 *targetRow++ = TTarget(*(source2) + (*(source2 + tSourceChannels) - *(source0 + tSourceChannels)) + *(source2 + tSourceChannels * 2u) - *(source0) - *(source0 + tSourceChannels * 2u));
176 for (
unsigned int n = 0u; n < tTargetChannels; ++n)
178 targetRow[n] = TTarget(0);
This class implements the base class for all filter.
Definition: FrameFilter.h:29
This class implements a Prewitt frame filter.
Definition: FrameFilterPrewitt.h:43
static void filterHorizontalVertical8BitPerChannel(const uint8_t *source, TTarget *target, const unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Horizontal and vertical Prewitt filter for images.
Definition: FrameFilterPrewitt.h:85
static void filterHorizontalVerticalRow(const TSource *sourceRow, TTarget *targetRow, const unsigned int width, const unsigned int height, unsigned int rowIndex, const unsigned int sourceStrideElements, const unsigned int targetStrideElements)
Applies the horizontal and vertical Prewitt filter to one row of a source frame.
Definition: FrameFilterPrewitt.h:100
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15