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;
188 for (
unsigned int n = 0u; n < tChannels; ++n)
190 target[n] = uint8_t((sourceFirst[n] + sourceFirst[tChannels + n] + sourceSecond[n] + sourceSecond[tChannels + n] + 2u) / 4u);
195 sourceFirst += tChannels * 2u;
196 sourceSecond += tChannels * 2u;
213 if (denominator != 0u)
215 const unsigned int denominator_2 = denominator / 2u;
238 for (
unsigned int n = 0u; n < tChannels; ++n)
240 target[n] = uint8_t((sourceFirst[n] + sourceFirst[tChannels + n] * 2u + sourceFirst[tChannels * 2u + n]
241 + sourceSecond[n] + sourceSecond[tChannels + n] * 2u + sourceSecond[tChannels * 2u + n] + 4u) / 8u);
246 sourceFirst += tChannels * 3u;
247 sourceSecond += tChannels * 3u;
250 target += targetPaddingElements;
251 sourceFirst += sourcePaddingElements + sourceStrideElements;
252 sourceSecond += sourcePaddingElements + sourceStrideElements;
257 const uint8_t* sourceThird = sourceSecond + sourceStrideElements;
259 for (
unsigned int x = 0u; x < numberTwoTargetColumns; ++x)
272 if (denominator != 0u)
274 const unsigned int denominator_2 = denominator / 2u;
297 for (
unsigned int n = 0u; n < tChannels; ++n)
299 target[n] = uint8_t((sourceFirst[n] + sourceFirst[tChannels + n]
300 + sourceSecond[n] * 2u + sourceSecond[tChannels + n] * 2u
301 + sourceThird[n] + sourceThird[tChannels + n] + 4u) / 8u);
306 sourceFirst += tChannels * 2u;
307 sourceSecond += tChannels * 2u;
308 sourceThird += tChannels * 2u;
330 if (denominator != 0u)
332 const unsigned int denominator_2 = denominator / 2u;
361 for (
unsigned int n = 0u; n < tChannels; ++n) {
362 target[n] = uint8_t((sourceFirst[n] + sourceFirst[tChannels + n] * 2u + sourceFirst[tChannels * 2u + n]
363 + sourceSecond[n] * 2u + sourceSecond[tChannels + n] * 4u + sourceSecond[tChannels * 2u + n] * 2u
364 + sourceThird[n] + sourceThird[tChannels + n] * 2u + sourceThird[tChannels * 2u + n] + 4u) / 8u);