130void 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);