8 #ifndef META_OCEAN_CV_FRAME_ENLARGER_H
9 #define META_OCEAN_CV_FRAME_ENLARGER_H
52 static bool addBorder(
const Frame& source,
Frame& target,
const unsigned int borderSizeLeft,
const unsigned int borderSizeTop,
const unsigned int borderSizeRight,
const unsigned int borderSizeBottom,
const void* color);
64 static inline bool addBorder(
Frame& frame,
const unsigned int borderSizeLeft,
const unsigned int borderSizeTop,
const unsigned int borderSizeRight,
const unsigned int borderSizeBottom,
const void* color);
77 static bool addBorderNearestPixel(
const Frame& source,
Frame& target,
const unsigned int borderSizeLeft,
const unsigned int borderSizeTop,
const unsigned int borderSizeRight,
const unsigned int borderSizeBottom);
89 static inline bool addBorderNearestPixel(
Frame& frame,
const unsigned int borderSizeLeft,
const unsigned int borderSizeTop,
const unsigned int borderSizeRight,
const unsigned int borderSizeBottom);
101 static bool addBorderMirrored(
const Frame& source,
Frame& target,
const unsigned int borderSizeLeft,
const unsigned int borderSizeTop,
const unsigned int borderSizeRight,
const unsigned int borderSizeBottom);
112 static inline bool addBorderMirrored(
Frame& frame,
const unsigned int borderSizeLeft,
const unsigned int borderSizeTop,
const unsigned int borderSizeRight,
const unsigned int borderSizeBottom);
135 template <
bool tTransparentIs0xFF>
136 static bool addTransparentBorder(
const Frame& source,
Frame& target,
const unsigned int leftBorder,
const unsigned int topBorder,
const unsigned int rightBorder,
const unsigned int bottomBorder);
149 template <
bool tTransparentIs0xFF>
150 static bool addTransparentBorder(
Frame& frame,
const unsigned int leftBorder,
const unsigned int topBorder,
const unsigned int rightBorder,
const unsigned int bottomBorder);
171 template <
unsigned int tChannelsWithAlpha,
bool tAlphaAtFront,
bool tSourceHasAlpha,
bool tTransparentIs0xFF>
172 static void addTransparentBorder8BitPerChannel(
const unsigned char* source,
unsigned char* target,
const unsigned int width,
const unsigned int height,
const unsigned int leftBorder,
const unsigned int topBorder,
const unsigned int rightBorder,
const unsigned int bottomBorder,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements);
190 template <
typename T,
unsigned int tChannels>
191 static void addBorder(
const T* source, T* target,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int borderSizeLeft,
const unsigned int borderSizeTop,
const unsigned int borderSizeRight,
const unsigned int borderSizeBottom,
const T* color,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements);
208 template <
typename T,
unsigned int tChannels>
209 static void addBorderNearestPixel(
const T* source, T* target,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int borderSizeLeft,
const unsigned int borderSizeTop,
const unsigned int borderSizeRight,
const unsigned int borderSizeBottom,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements);
226 template <
typename T,
unsigned int tChannels>
227 static void addBorderMirrored(
const T* source, T* target,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int borderSizeLeft,
const unsigned int borderSizeTop,
const unsigned int borderSizeRight,
const unsigned int borderSizeBottom,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements);
241 template <
typename T,
unsigned int tChannels>
242 static void multiplyByTwo(
const T* source, T* target,
const unsigned int targetWidth,
const unsigned int targetHeight,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
259 template <
typename T,
unsigned int tChannels>
260 static void multiplyByTwoSubset(
const T* source, T* target,
const unsigned int targetWidth,
const unsigned int targetHeight,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
const unsigned int firstTargetRow,
const unsigned int numberTargetRows);
263 inline bool FrameEnlarger::Comfort::addBorder(
Frame& frame,
const unsigned int borderSizeLeft,
const unsigned int borderSizeTop,
const unsigned int borderSizeRight,
const unsigned int borderSizeBottom,
const void* color)
266 ocean_assert(color !=
nullptr);
269 if (!
addBorder(frame, tmpFrame, borderSizeLeft, borderSizeTop, borderSizeRight, borderSizeBottom, color))
277 frame = std::move(tmpFrame);
286 if (!
addBorderNearestPixel(frame, tmpFrame, borderSizeLeft, borderSizeTop, borderSizeRight, borderSizeBottom))
294 frame = std::move(tmpFrame);
303 if (!
addBorderMirrored(frame, tmpFrame, borderSizeLeft, borderSizeTop, borderSizeRight, borderSizeBottom))
311 frame = std::move(tmpFrame);
316 template <
typename T,
unsigned int tChannels>
317 void FrameEnlarger::addBorder(
const T* source, T* target,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int borderSizeLeft,
const unsigned int borderSizeTop,
const unsigned int borderSizeRight,
const unsigned int borderSizeBottom,
const T* color,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements)
319 static_assert(tChannels >= 1u,
"Invalid channel number!");
321 ocean_assert(source !=
nullptr && target !=
nullptr);
322 ocean_assert(sourceWidth != 0u && sourceHeight != 0u);
325 static_assert(
sizeof(PixelType) ==
sizeof(T) * tChannels,
"Invalid pixel type!");
327 const unsigned int targetWidth = sourceWidth + borderSizeLeft + borderSizeRight;
329 const unsigned int sourceStrideElements = sourceWidth * tChannels + sourcePaddingElements;
330 const unsigned int targetStrideElements = targetWidth * tChannels + targetPaddingElements;
332 const PixelType borderColorPixel = *((
const PixelType*)color);
334 if (borderSizeTop != 0u)
339 for (
unsigned int n = 0u; n < targetWidth; ++n)
341 ((PixelType*)target)[n] = borderColorPixel;
345 for (
unsigned int y = 1u; y < borderSizeTop; ++y)
347 memcpy(target + y * targetStrideElements, target, targetWidth *
sizeof(PixelType));
351 for (
unsigned int y = 0u; y < sourceHeight; ++y)
353 const PixelType* sourcePixel = (
const PixelType*)(source + y * sourceStrideElements);
354 PixelType* targetPixel = (PixelType*)(target + (borderSizeTop + y) * targetStrideElements);
356 if (borderSizeTop == 0u)
358 for (
unsigned int n = 0u; n < borderSizeLeft; ++n)
360 targetPixel[n] = borderColorPixel;
366 memcpy(targetPixel, target, borderSizeLeft *
sizeof(PixelType));
369 targetPixel += borderSizeLeft;
372 memcpy(targetPixel, sourcePixel, sourceWidth *
sizeof(PixelType));
374 targetPixel += sourceWidth;
375 sourcePixel += sourceWidth;
377 if (borderSizeTop == 0u)
379 for (
unsigned int n = 0u; n < borderSizeRight; ++n)
381 targetPixel[n] = borderColorPixel;
387 memcpy(targetPixel, target, borderSizeRight *
sizeof(PixelType));
391 if (borderSizeBottom != 0u)
393 PixelType* targetPixel = (PixelType*)(target + (borderSizeTop + sourceHeight) * targetStrideElements);
396 for (
unsigned int n = 0u; n < targetWidth; ++n)
398 targetPixel[n] = borderColorPixel;
402 for (
unsigned int y = 1u; y < borderSizeBottom; ++y)
404 memcpy(target + (borderSizeTop + sourceHeight + y) * targetStrideElements, targetPixel, targetWidth *
sizeof(PixelType));
409 template <
typename T,
unsigned int tChannels>
410 void FrameEnlarger::addBorderNearestPixel(
const T* source, T* target,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int borderSizeLeft,
const unsigned int borderSizeTop,
const unsigned int borderSizeRight,
const unsigned int borderSizeBottom,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements)
412 static_assert(tChannels >= 1u,
"Invalid channel number!");
414 ocean_assert(source !=
nullptr && target !=
nullptr);
415 ocean_assert(sourceWidth != 0u && sourceHeight != 0u);
418 static_assert(
sizeof(PixelType) ==
sizeof(T) * tChannels,
"Invalid pixel type!");
420 const unsigned int targetWidth = sourceWidth + borderSizeLeft + borderSizeRight;
422 const unsigned int sourceStrideElements = sourceWidth * tChannels + sourcePaddingElements;
423 const unsigned int targetStrideElements = targetWidth * tChannels + targetPaddingElements;
425 const PixelType* sourcePixel = (
const PixelType*)source;
426 PixelType* targetPixel = (PixelType*)target;
428 if (borderSizeTop != 0u)
431 for (
unsigned int x = 0u; x < borderSizeLeft; ++x)
433 targetPixel[x] = *sourcePixel;
436 targetPixel += borderSizeLeft;
438 memcpy(targetPixel, sourcePixel, sourceWidth *
sizeof(PixelType));
439 targetPixel += sourceWidth;
441 for (
unsigned int x = 0u; x < borderSizeRight; ++x)
443 targetPixel[x] = sourcePixel[sourceWidth - 1u];
446 targetPixel += borderSizeRight;
449 for (
unsigned int y = 1u; y < borderSizeTop; ++y)
451 memcpy(target + y * targetStrideElements, target, targetWidth *
sizeof(PixelType));
456 for (
unsigned int y = 0u; y < sourceHeight; ++y)
458 sourcePixel = (
const PixelType*)(source + y * sourceStrideElements);
459 targetPixel = (PixelType*)(target + (borderSizeTop + y) * targetStrideElements);
462 for (
unsigned int x = 0u; x < borderSizeLeft; ++x)
464 targetPixel[x] = *sourcePixel;
467 targetPixel += borderSizeLeft;
469 memcpy(targetPixel, sourcePixel, sourceWidth *
sizeof(PixelType));
471 targetPixel += sourceWidth;
472 sourcePixel += sourceWidth - 1u;
475 for (
unsigned int x = 0u; x < borderSizeRight; ++x)
477 targetPixel[x] = *sourcePixel;
481 if (borderSizeBottom != 0u)
483 sourcePixel = (
const PixelType*)(source + (sourceHeight - 1u) * sourceStrideElements);
484 targetPixel = (PixelType*)(target + (borderSizeTop + sourceHeight) * targetStrideElements);
487 for (
unsigned int x = 0u; x < borderSizeLeft; ++x)
489 targetPixel[x] = *sourcePixel;
492 targetPixel += borderSizeLeft;
494 memcpy(targetPixel, sourcePixel, sourceWidth *
sizeof(PixelType));
495 targetPixel += sourceWidth;
497 for (
unsigned int x = 0u; x < borderSizeRight; ++x)
499 targetPixel[x] = sourcePixel[sourceWidth - 1u];
503 const unsigned int targetHeight = sourceHeight + borderSizeTop + borderSizeBottom;
505 targetPixel = (PixelType*)(target + (targetHeight - borderSizeBottom) * targetStrideElements);
507 for (
unsigned int y = targetHeight - borderSizeBottom + 1u; y < targetHeight; ++y)
509 memcpy(target + y * targetStrideElements,targetPixel, targetWidth *
sizeof(PixelType));
514 template <
typename T,
unsigned int tChannels>
515 void FrameEnlarger::addBorderMirrored(
const T* source, T* target,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int borderSizeLeft,
const unsigned int borderSizeTop,
const unsigned int borderSizeRight,
const unsigned int borderSizeBottom,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements)
517 static_assert(tChannels >= 1u,
"Invalid channel number!");
519 ocean_assert(source !=
nullptr && target !=
nullptr);
520 ocean_assert(sourceWidth != 0u && sourceHeight != 0u);
521 ocean_assert(borderSizeLeft <= sourceWidth && borderSizeRight <= sourceWidth);
522 ocean_assert(borderSizeTop <= sourceHeight && borderSizeBottom <= sourceHeight);
525 static_assert(
sizeof(PixelType) ==
sizeof(T) * tChannels,
"Invalid pixel type!");
527 const unsigned int targetWidth = sourceWidth + borderSizeLeft + borderSizeRight;
529 const unsigned int sourceStrideElements = sourceWidth * tChannels + sourcePaddingElements;
530 const unsigned int targetStrideElements = targetWidth * tChannels + targetPaddingElements;
534 for (
unsigned int y = 0u; y < borderSizeTop; ++y)
536 const PixelType* sourcePixel = (
const PixelType*)(source + (borderSizeTop - y - 1u) * sourceStrideElements);
537 PixelType* targetPixel = (PixelType*)(target + y * targetStrideElements);
540 for (
unsigned int n = 0u; n < borderSizeLeft; ++n)
542 targetPixel[n] = *(sourcePixel + borderSizeLeft - n - 1u);
545 targetPixel += borderSizeLeft;
548 memcpy(targetPixel, sourcePixel, sourceWidth *
sizeof(PixelType));
550 targetPixel += sourceWidth;
551 sourcePixel += sourceWidth;
554 for (
unsigned int n = 0u; n < borderSizeRight; ++n)
556 targetPixel[n] = *(sourcePixel - n - 1u);
562 for (
unsigned int y = 0u; y < sourceHeight; ++y)
564 const PixelType* sourcePixel = (
const PixelType*)(source + y * sourceStrideElements);
565 PixelType* targetPixel = (PixelType*)(target + (borderSizeTop + y) * targetStrideElements);
568 for (
unsigned int n = 0u; n < borderSizeLeft; ++n)
570 targetPixel[n] = *(sourcePixel + borderSizeLeft - n - 1u);
573 targetPixel += borderSizeLeft;
576 memcpy(targetPixel, sourcePixel, sourceWidth *
sizeof(PixelType));
578 targetPixel += sourceWidth;
579 sourcePixel += sourceWidth;
582 for (
unsigned int n = 0u; n < borderSizeRight; ++n)
584 targetPixel[n] = *(sourcePixel - n - 1u);
588 for (
unsigned int y = 0u; y < borderSizeBottom; ++y)
590 const PixelType* sourcePixel = (
const PixelType*)(source + (sourceHeight - y - 1u) * sourceStrideElements);
591 PixelType* targetPixel = (PixelType*)(target + (borderSizeTop + sourceHeight + y) * targetStrideElements);
594 for (
unsigned int n = 0u; n < borderSizeLeft; ++n)
596 targetPixel[n] = *(sourcePixel + borderSizeLeft - n - 1u);
599 targetPixel += borderSizeLeft;
602 memcpy(targetPixel, sourcePixel, sourceWidth *
sizeof(PixelType));
604 targetPixel += sourceWidth;
605 sourcePixel += sourceWidth;
608 for (
unsigned int n = 0u; n < borderSizeRight; ++n)
610 targetPixel[n] = *(sourcePixel - n - 1u);
615 template <
bool tTransparentIs0xFF>
618 ocean_assert(source);
620 if (leftBorder == 0u && topBorder == 0u && rightBorder == 0u && bottomBorder == 0u)
645 if (!target.
set(
FrameType(source.
width() + leftBorder + rightBorder, source.
height() + topBorder + bottomBorder, targetPixelFormat, source.
pixelOrigin()),
false ,
true ))
647 ocean_assert(
false &&
"This should never happen!");
658 bool alphaAtBack =
false;
660 ocean_assert_and_suppress_unused(tmpResult, tmpResult);
670 addTransparentBorder8BitPerChannel<2u, false, true, tTransparentIs0xFF>(source.
constdata<uint8_t>(), target.
data<uint8_t>(), source.
width(), source.
height(), leftBorder, topBorder, rightBorder, bottomBorder, source.
paddingElements(), target.
paddingElements());
674 addTransparentBorder8BitPerChannel<2u, false, false, tTransparentIs0xFF>(source.
constdata<uint8_t>(), target.
data<uint8_t>(), source.
width(), source.
height(), leftBorder, topBorder, rightBorder, bottomBorder, source.
paddingElements(), target.
paddingElements());
681 addTransparentBorder8BitPerChannel<2u, true, true, tTransparentIs0xFF>(source.
constdata<uint8_t>(), target.
data<uint8_t>(), source.
width(), source.
height(), leftBorder, topBorder, rightBorder, bottomBorder, source.
paddingElements(), target.
paddingElements());
685 addTransparentBorder8BitPerChannel<2u, true, false, tTransparentIs0xFF>(source.
constdata<uint8_t>(), target.
data<uint8_t>(), source.
width(), source.
height(), leftBorder, topBorder, rightBorder, bottomBorder, source.
paddingElements(), target.
paddingElements());
698 addTransparentBorder8BitPerChannel<3u, false, true, tTransparentIs0xFF>(source.
constdata<uint8_t>(), target.
data<uint8_t>(), source.
width(), source.
height(), leftBorder, topBorder, rightBorder, bottomBorder, source.
paddingElements(), target.
paddingElements());
702 addTransparentBorder8BitPerChannel<3u, false, false, tTransparentIs0xFF>(source.
constdata<uint8_t>(), target.
data<uint8_t>(), source.
width(), source.
height(), leftBorder, topBorder, rightBorder, bottomBorder, source.
paddingElements(), target.
paddingElements());
709 addTransparentBorder8BitPerChannel<3u, true, true, tTransparentIs0xFF>(source.
constdata<uint8_t>(), target.
data<uint8_t>(), source.
width(), source.
height(), leftBorder, topBorder, rightBorder, bottomBorder, source.
paddingElements(), target.
paddingElements());
713 addTransparentBorder8BitPerChannel<3u, true, false, tTransparentIs0xFF>(source.
constdata<uint8_t>(), target.
data<uint8_t>(), source.
width(), source.
height(), leftBorder, topBorder, rightBorder, bottomBorder, source.
paddingElements(), target.
paddingElements());
726 addTransparentBorder8BitPerChannel<4u, false, true, tTransparentIs0xFF>(source.
constdata<uint8_t>(), target.
data<uint8_t>(), source.
width(), source.
height(), leftBorder, topBorder, rightBorder, bottomBorder, source.
paddingElements(), target.
paddingElements());
730 addTransparentBorder8BitPerChannel<4u, false, false, tTransparentIs0xFF>(source.
constdata<uint8_t>(), target.
data<uint8_t>(), source.
width(), source.
height(), leftBorder, topBorder, rightBorder, bottomBorder, source.
paddingElements(), target.
paddingElements());
737 addTransparentBorder8BitPerChannel<4u, true, true, tTransparentIs0xFF>(source.
constdata<uint8_t>(), target.
data<uint8_t>(), source.
width(), source.
height(), leftBorder, topBorder, rightBorder, bottomBorder, source.
paddingElements(), target.
paddingElements());
741 addTransparentBorder8BitPerChannel<4u, true, false, tTransparentIs0xFF>(source.
constdata<uint8_t>(), target.
data<uint8_t>(), source.
width(), source.
height(), leftBorder, topBorder, rightBorder, bottomBorder, source.
paddingElements(), target.
paddingElements());
749 ocean_assert(
false &&
"Missing implementation");
757 template <
bool tTransparentIs0xFF>
763 if (!addTransparentBorder<tTransparentIs0xFF>(frame, tmpFrame, leftBorder, topBorder, rightBorder, bottomBorder))
771 frame = std::move(tmpFrame);
775 template <
unsigned int tChannelsWithAlpha,
bool tAlphaAtFront,
bool tSourceHasAlpha,
bool tTransparentIs0xFF>
776 void FrameEnlarger::addTransparentBorder8BitPerChannel(
const unsigned char* source,
unsigned char* target,
const unsigned int width,
const unsigned int height,
const unsigned int leftBorder,
const unsigned int topBorder,
const unsigned int rightBorder,
const unsigned int bottomBorder,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements)
778 ocean_assert(source && target);
780 typedef typename DataType<uint8_t, tChannelsWithAlpha - 1u>::Type TypeWithoutAlpha;
785 for (
unsigned int x = 0u; x < leftBorder; ++x)
794 for (
unsigned int x = 0u; x < width; ++x)
803 for (
unsigned int x = 0u; x < rightBorder; ++x)
812 for (
unsigned int y = 1u; y < topBorder; ++y)
814 memcpy(target + y * (width + leftBorder + rightBorder) * tChannelsWithAlpha + targetPaddingElements, target, (width + leftBorder + rightBorder) * tChannelsWithAlpha);
818 target += topBorder * (tChannelsWithAlpha * (width + leftBorder + rightBorder) + targetPaddingElements);
822 for (
unsigned int y = 0u; y < height; ++y)
825 for (
unsigned int x = 0u; x < leftBorder; ++x)
834 if constexpr (tSourceHasAlpha)
836 memcpy(target + leftBorder * tChannelsWithAlpha, source, width * tChannelsWithAlpha);
840 for (
unsigned int x = 0u; x < width; ++x)
850 for (
unsigned int x = 0u; x < rightBorder; ++x)
860 target += tChannelsWithAlpha * (width + leftBorder + rightBorder) + targetPaddingElements;
863 if (bottomBorder != 0u)
869 for (
unsigned int x = 0u; x < leftBorder; ++x)
878 for (
unsigned int x = 0u; x < width; ++x)
887 for (
unsigned int x = 0u; x < rightBorder; ++x)
896 for (
unsigned int y = 1u; y < bottomBorder; ++y)
898 memcpy(target + y * (width + leftBorder + rightBorder) * tChannelsWithAlpha + targetPaddingElements, target, (width + leftBorder + rightBorder) * tChannelsWithAlpha);
903 template <
typename T,
unsigned int tChannels>
904 void FrameEnlarger::multiplyByTwo(
const T* source, T* target,
const unsigned int targetWidth,
const unsigned int targetHeight,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker)
906 ocean_assert(targetWidth >= 2u && targetHeight >= 2u);
910 worker->
executeFunction(
Worker::Function::createStatic(&FrameEnlarger::multiplyByTwoSubset<T, tChannels>, source, target, targetWidth, targetHeight, sourcePaddingElements, targetPaddingElements, 0u, 0u), 0u, targetHeight);
914 multiplyByTwoSubset<T, tChannels>(source, target, targetWidth, targetHeight, sourcePaddingElements, targetPaddingElements, 0u, targetHeight);
918 template <
typename T,
unsigned int tChannels>
919 void FrameEnlarger::multiplyByTwoSubset(
const T* source, T* target,
const unsigned int targetWidth,
const unsigned int targetHeight,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
const unsigned int firstTargetRow,
const unsigned int numberTargetRows)
921 ocean_assert(targetWidth >= 2u && targetHeight >= 2u);
923 ocean_assert(source && target);
924 ocean_assert(firstTargetRow + numberTargetRows <= targetHeight);
926 const unsigned int sourceWidth = targetWidth / 2u;
927 const unsigned int sourceHeight = targetHeight / 2u;
928 ocean_assert(sourceWidth >= 1u && sourceHeight >= 1u);
930 const unsigned int sourceStrideElements = sourceWidth * tChannels + sourcePaddingElements;
931 const unsigned int targetStrideElements = targetWidth * tChannels + targetPaddingElements;
936 if (targetWidth % 2u == 0u)
938 for (
unsigned int targetRowIndex = firstTargetRow; targetRowIndex < (firstTargetRow + numberTargetRows); ++targetRowIndex)
940 const PixelType* sourcePixel = (
const PixelType*)(source + min(targetRowIndex / 2u, sourceHeight - 1u) * sourceStrideElements);
942 PixelType* targetPixel = (PixelType*)(target + targetRowIndex * targetStrideElements);
944 const PixelType*
const targetRowEnd = targetPixel + targetWidth;
946 while (targetPixel != targetRowEnd)
948 ocean_assert(targetPixel < targetRowEnd);
950 *targetPixel++ = *sourcePixel;
952 ocean_assert(targetPixel < targetRowEnd);
954 *targetPixel++ = *sourcePixel++;
960 ocean_assert((targetWidth - 1u) % 2u == 0u);
962 for (
unsigned int targetRowIndex = firstTargetRow; targetRowIndex < (firstTargetRow + numberTargetRows); ++targetRowIndex)
964 const PixelType* sourcePixel = (
const PixelType*)(source + min(targetRowIndex / 2u, sourceHeight - 1u) * sourcePaddingElements);
967 PixelType* targetPixel = (PixelType*)(target + targetRowIndex * targetStrideElements);
969 const PixelType*
const targetRowEnd = targetPixel + targetWidth - 1u;
971 while (targetPixel != targetRowEnd)
973 ocean_assert(targetPixel < targetRowEnd);
975 *targetPixel++ = *++sourcePixel;
977 ocean_assert(targetPixel < targetRowEnd);
979 *targetPixel++ = *sourcePixel;
983 *targetPixel++ = *sourcePixel;
Helper class allowing to determine the number of channels of a frame.
Definition: FrameBlender.h:117
Helper class allowing to determine the offset that is necessary to access the alpha channel.
Definition: FrameBlender.h:60
static constexpr unsigned int data()
Returns the offset that is applied to access the first data channel.
Definition: FrameBlender.h:1160
The following comfort class provides comfortable functions simplifying prototyping applications but a...
Definition: FrameEnlarger.h:38
static bool addBorder(const Frame &source, Frame &target, const unsigned int borderSizeLeft, const unsigned int borderSizeTop, const unsigned int borderSizeRight, const unsigned int borderSizeBottom, const void *color)
Adds a border to the given frame while all new pixels will receive a specified border color.
static bool addTransparentBorder(const Frame &source, Frame &target, const unsigned int leftBorder, const unsigned int topBorder, const unsigned int rightBorder, const unsigned int bottomBorder)
Adds a transparent border to a given frame.
Definition: FrameEnlarger.h:616
static bool multiplyByTwo(const Frame &source, Frame &target, Worker *worker=nullptr)
Doubles the size of a given frame by a pixel repeating upsampling.
static bool addBorderMirrored(const Frame &source, Frame &target, const unsigned int borderSizeLeft, const unsigned int borderSizeTop, const unsigned int borderSizeRight, const unsigned int borderSizeBottom)
Adds a border to the given frame by mirroring the frame border (and border neighbor) pixels.
static bool addBorderNearestPixel(const Frame &source, Frame &target, const unsigned int borderSizeLeft, const unsigned int borderSizeTop, const unsigned int borderSizeRight, const unsigned int borderSizeBottom)
Adds a border to the given frame.
This class implements functions to enlarge/up-sample frames.
Definition: FrameEnlarger.h:29
static void multiplyByTwoSubset(const T *source, T *target, const unsigned int targetWidth, const unsigned int targetHeight, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, const unsigned int firstTargetRow, const unsigned int numberTargetRows)
Doubles a subset of a given frame by a pixel repeating upsampling.
Definition: FrameEnlarger.h:919
static void addTransparentBorder8BitPerChannel(const unsigned char *source, unsigned char *target, const unsigned int width, const unsigned int height, const unsigned int leftBorder, const unsigned int topBorder, const unsigned int rightBorder, const unsigned int bottomBorder, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements)
Adds a transparent border to a given frame.
Definition: FrameEnlarger.h:776
static void addBorderMirrored(const T *source, T *target, const unsigned int sourceWidth, const unsigned int sourceHeight, const unsigned int borderSizeLeft, const unsigned int borderSizeTop, const unsigned int borderSizeRight, const unsigned int borderSizeBottom, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements)
Adds a border to a given frame by mirroring the frame's content.
Definition: FrameEnlarger.h:515
static void addBorder(const T *source, T *target, const unsigned int sourceWidth, const unsigned int sourceHeight, const unsigned int borderSizeLeft, const unsigned int borderSizeTop, const unsigned int borderSizeRight, const unsigned int borderSizeBottom, const T *color, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements)
Adds a border to a given frame while all new pixels will receive a specified border color/value.
Definition: FrameEnlarger.h:317
static void addBorderNearestPixel(const T *source, T *target, const unsigned int sourceWidth, const unsigned int sourceHeight, const unsigned int borderSizeLeft, const unsigned int borderSizeTop, const unsigned int borderSizeRight, const unsigned int borderSizeBottom, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements)
Adds a border to a given frame while the color of the border pixels are defined by the nearest pixels...
Definition: FrameEnlarger.h:410
static void multiplyByTwo(const T *source, T *target, const unsigned int targetWidth, const unsigned int targetHeight, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Doubles the size of a given frame by a pixel repeating upsampling.
Definition: FrameEnlarger.h:904
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
Template class allowing to define an array of data types.
Definition: DataType.h:27
This class implements Ocean's image class.
Definition: Frame.h:1792
const T * constdata(const unsigned int planeIndex=0u) const
Returns a pointer to the read-only pixel data of a specific plane.
Definition: Frame.h:4168
void setRelativeTimestamp(const Timestamp &relative)
Sets the relative timestamp of this frame.
Definition: Frame.h:4153
T * data(const unsigned int planeIndex=0u)
Returns a pointer to the pixel data of a specific plane.
Definition: Frame.h:4159
bool isValid() const
Returns whether this frame is valid.
Definition: Frame.h:4448
void setTimestamp(const Timestamp ×tamp)
Sets the timestamp of this frame.
Definition: Frame.h:4148
bool set(const FrameType &frameType, const bool forceOwner, const bool forceWritable=false, const Indices32 &planePaddingElements=Indices32(), const Timestamp ×tamp=Timestamp(false), bool *reallocated=nullptr)
Sets a new frame type for this frame.
const Timestamp & timestamp() const
Returns the timestamp of this frame.
Definition: Frame.h:4138
const Timestamp & relativeTimestamp() const
Returns the relative timestamp of this frame.
Definition: Frame.h:4143
unsigned int paddingElements(const unsigned int planeIndex=0u) const
Returns the optional number of padding elements at the end of each row for a specific plane.
Definition: Frame.h:4042
Definition of a frame type composed by the frame dimension, pixel format and pixel origin.
Definition: Frame.h:30
PixelFormat
Definition of all pixel formats available in the Ocean framework.
Definition: Frame.h:183
@ FORMAT_UNDEFINED
Undefined pixel format.
Definition: Frame.h:187
unsigned int width() const
Returns the width of the frame format in pixel.
Definition: Frame.h:3143
PixelOrigin pixelOrigin() const
Returns the pixel origin of the frame.
Definition: Frame.h:3188
uint32_t numberPlanes() const
Returns the number of planes of the pixel format of this frame.
Definition: Frame.h:3183
static PixelFormat formatRemoveAlphaChannel(const PixelFormat pixelFormat)
Removes an alpha channel from a given pixel format.
static bool formatHasAlphaChannel(const PixelFormat pixelFormat, bool *isLastChannel=nullptr)
Returns whether a given pixel format holds an alpha channel.
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition: Frame.h:3153
unsigned int height() const
Returns the height of the frame in pixel.
Definition: Frame.h:3148
unsigned int channels() const
Returns the number of individual channels the frame has.
Definition: Frame.h:3173
static PixelFormat formatAddAlphaChannel(const PixelFormat pixelFormat, const bool lastChannel=true)
Adds an alpha channel to a given pixel format.
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
Default definition of a type with tBytes bytes.
Definition: DataType.h:32