8 #ifndef META_OCEAN_CV_FRAME_SHRINKER_ALPHA_H
9 #define META_OCEAN_CV_FRAME_SHRINKER_ALPHA_H
52 template <
bool tTransparentIs0xFF>
62 template <
bool tTransparentIs0xFF>
84 template <
unsigned int tChannels,
bool tAlphaAtFront,
bool tTransparentIs0xFF>
85 static void divideByTwo8BitPerChannel(
const uint8_t* source, uint8_t* target,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
104 template <
unsigned int tChannels,
bool tAlphaAtFront,
bool tTransparentIs0xFF>
105 static void divideByTwo8BitPerChannelSubset(
const uint8_t* source, uint8_t* target,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
const unsigned int firstTargetRow,
const unsigned int numberTargetRows);
108 template <
unsigned int tChannels,
bool tAlphaAtFront,
bool tTransparentIs0xFF>
111 static_assert(tChannels >= 1u,
"Invalid channel number!");
113 ocean_assert(source !=
nullptr && target !=
nullptr);
114 ocean_assert(sourceWidth >= 2u && sourceHeight >= 2u);
116 const unsigned int targetHeight = sourceHeight / 2u;
117 ocean_assert(targetHeight > 0u);
121 worker->
executeFunction(
Worker::Function::createStatic(÷ByTwo8BitPerChannelSubset<tChannels, tAlphaAtFront, tTransparentIs0xFF>, source, target, sourceWidth, sourceHeight, sourcePaddingElements, targetPaddingElements, 0u, 0u), 0u, targetHeight, 6u, 7u, 20u);
125 divideByTwo8BitPerChannelSubset<tChannels, tAlphaAtFront, tTransparentIs0xFF>(source, target, sourceWidth, sourceHeight, sourcePaddingElements, targetPaddingElements, 0u, targetHeight);
129 template <
unsigned int tChannels,
bool tAlphaAtFront,
bool tTransparentIs0xFF>
130 void FrameShrinkerAlpha::divideByTwo8BitPerChannelSubset(
const uint8_t* source, uint8_t* target,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
const unsigned int firstTargetRow,
const unsigned int numberTargetRows)
132 static_assert(tChannels >= 1u,
"Invalid channel number!");
134 ocean_assert(source !=
nullptr && target !=
nullptr);
135 ocean_assert(sourceWidth >= 2u && sourceHeight >= 2u);
136 ocean_assert(firstTargetRow + numberTargetRows <= sourceHeight / 2u);
138 const unsigned int targetWidth = sourceWidth / 2u;
140 const unsigned int sourceStrideElements = sourceWidth * tChannels + sourcePaddingElements;
141 const unsigned int targetStrideElements = targetWidth * tChannels + targetPaddingElements;
143 const bool xEven = sourceWidth % 2u == 0u;
144 const bool yEven = sourceHeight % 2u == 0u;
146 const uint8_t* sourceFirst = source + firstTargetRow * 2u * sourceStrideElements;
147 const uint8_t* sourceSecond = sourceFirst + sourceStrideElements;
149 target += firstTargetRow * targetStrideElements;
151 const bool threeBottomRows = !yEven && firstTargetRow + numberTargetRows == sourceHeight / 2u;
153 const unsigned int numberTwoTargetRows = threeBottomRows ? (
unsigned int)(max(
int(numberTargetRows) - 1, 0)) : numberTargetRows;
154 const unsigned int numberTwoTargetColumns = xEven ? targetWidth : (
unsigned int)(max(
int(targetWidth) - 1, 0));
156 for (
unsigned int y = 0u; y < numberTwoTargetRows; ++y)
158 for (
unsigned int x = 0u; x < numberTwoTargetColumns; ++x)
168 if (denominator != 0u)
170 const unsigned int denominator_2 = denominator / 2u;
187 for (
unsigned int n = 0u; n < tChannels; ++n)
189 target[n] = uint8_t((sourceFirst[n] + sourceFirst[tChannels + n] + sourceSecond[n] + sourceSecond[tChannels + n] + 2u) / 4u);
194 sourceFirst += tChannels * 2u;
195 sourceSecond += tChannels * 2u;
212 if (denominator != 0u)
214 const unsigned int denominator_2 = denominator / 2u;
236 for (
unsigned int n = 0u; n < tChannels; ++n)
238 target[n] = uint8_t((sourceFirst[n] + sourceFirst[tChannels + n] * 2u + sourceFirst[tChannels * 2u + n]
239 + sourceSecond[n] + sourceSecond[tChannels + n] * 2u + sourceSecond[tChannels * 2u + n] + 4u) / 8u);
244 sourceFirst += tChannels * 3u;
245 sourceSecond += tChannels * 3u;
248 target += targetPaddingElements;
249 sourceFirst += sourcePaddingElements + sourceStrideElements;
250 sourceSecond += sourcePaddingElements + sourceStrideElements;
255 const uint8_t* sourceThird = sourceSecond + sourceStrideElements;
257 for (
unsigned int x = 0u; x < numberTwoTargetColumns; ++x)
270 if (denominator != 0u)
272 const unsigned int denominator_2 = denominator / 2u;
294 for (
unsigned int n = 0u; n < tChannels; ++n)
296 target[n] = uint8_t((sourceFirst[n] + sourceFirst[tChannels + n]
297 + sourceSecond[n] * 2u + sourceSecond[tChannels + n] * 2u
298 + sourceThird[n] + sourceThird[tChannels + n] + 4u) / 8u);
303 sourceFirst += tChannels * 2u;
304 sourceSecond += tChannels * 2u;
305 sourceThird += tChannels * 2u;
327 if (denominator != 0u)
329 const unsigned int denominator_2 = denominator / 2u;
357 for (
unsigned int n = 0u; n < tChannels; ++n)
358 target[n] = uint8_t((sourceFirst[n] + sourceFirst[tChannels + n] * 2u + sourceFirst[tChannels * 2u + n]
359 + sourceSecond[n] * 2u + sourceSecond[tChannels + n] * 4u + sourceSecond[tChannels * 2u + n] * 2u
360 + sourceThird[n] + sourceThird[tChannels + n] * 2u + sourceThird[tChannels * 2u + n] + 4u) / 8u);
Helper class allowing to determine the offset that is necessary to access the alpha channel.
Definition: FrameBlender.h:60
The following comfort class provides comfortable functions simplifying prototyping applications but a...
Definition: FrameShrinkerAlpha.h:38
static bool divideByTwo(Frame &frame, Worker *worker=nullptr)
Divides a given frame by two, taking four pixel values into account: If the given source image has a...
static bool divideByTwo(const Frame &source, Frame &target, Worker *worker=nullptr)
Divides a given frame by two, taking four pixel values into account: | 1 1 | | 1 1 | If the given ...
This class implements functions downsizing frames that hold alpha channels.
Definition: FrameShrinkerAlpha.h:29
static void divideByTwo8BitPerChannelSubset(const uint8_t *source, uint8_t *target, const unsigned int sourceWidth, const unsigned int sourceHeight, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, const unsigned int firstTargetRow, const unsigned int numberTargetRows)
Divides a subset of a given 8 bit per channel frame by two, taking the average of four pixel values.
Definition: FrameShrinkerAlpha.h:130
static void divideByTwo8BitPerChannel(const uint8_t *source, uint8_t *target, const unsigned int sourceWidth, const unsigned int sourceHeight, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Divides a given 8 bit per channel frame by two, taking four pixel values into account: | 1 1 | | 1 ...
Definition: FrameShrinkerAlpha.h:109
static Caller< void > createStatic(typename StaticFunctionPointerMaker< void, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass >::Type function)
Creates a new caller container for a static function with no function parameter.
Definition: Caller.h:2876
This class implements Ocean's image class.
Definition: Frame.h:1792
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
bool executeFunction(const Function &function, const unsigned int first, const unsigned int size, const unsigned int firstIndex=(unsigned int)(-1), const unsigned int sizeIndex=(unsigned int)(-1), const unsigned int minimalIterations=1u, const unsigned int threadIndex=(unsigned int)(-1))
Executes a callback function separable by two function parameters.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15