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;
189 for (
unsigned int n = 0u; n < tChannels; ++n)
191 target[n] = uint8_t((sourceFirst[n] + sourceFirst[tChannels + n] + sourceSecond[n] + sourceSecond[tChannels + n] + 2u) / 4u);
196 sourceFirst += tChannels * 2u;
197 sourceSecond += tChannels * 2u;
214 if (denominator != 0u)
216 const unsigned int denominator_2 = denominator / 2u;
240 for (
unsigned int n = 0u; n < tChannels; ++n)
242 target[n] = uint8_t((sourceFirst[n] + sourceFirst[tChannels + n] * 2u + sourceFirst[tChannels * 2u + n]
243 + sourceSecond[n] + sourceSecond[tChannels + n] * 2u + sourceSecond[tChannels * 2u + n] + 4u) / 8u);
248 sourceFirst += tChannels * 3u;
249 sourceSecond += tChannels * 3u;
252 target += targetPaddingElements;
253 sourceFirst += sourcePaddingElements + sourceStrideElements;
254 sourceSecond += sourcePaddingElements + sourceStrideElements;
259 const uint8_t* sourceThird = sourceSecond + sourceStrideElements;
261 for (
unsigned int x = 0u; x < numberTwoTargetColumns; ++x)
274 if (denominator != 0u)
276 const unsigned int denominator_2 = denominator / 2u;
300 for (
unsigned int n = 0u; n < tChannels; ++n)
302 target[n] = uint8_t((sourceFirst[n] + sourceFirst[tChannels + n]
303 + sourceSecond[n] * 2u + sourceSecond[tChannels + n] * 2u
304 + sourceThird[n] + sourceThird[tChannels + n] + 4u) / 8u);
309 sourceFirst += tChannels * 2u;
310 sourceSecond += tChannels * 2u;
311 sourceThird += tChannels * 2u;
333 if (denominator != 0u)
335 const unsigned int denominator_2 = denominator / 2u;
365 for (
unsigned int n = 0u; n < tChannels; ++n)
367 target[n] = uint8_t((sourceFirst[n] + sourceFirst[tChannels + n] * 2u + sourceFirst[tChannels * 2u + n]
368 + sourceSecond[n] * 2u + sourceSecond[tChannels + n] * 4u + sourceSecond[tChannels * 2u + n] * 2u
369 + sourceThird[n] + sourceThird[tChannels + n] * 2u + sourceThird[tChannels * 2u + n] + 4u) / 8u);