8 #ifndef META_OCEAN_CV_FRAME_INTERPOLATOR_TRILINEAR_H
9 #define META_OCEAN_CV_FRAME_INTERPOLATOR_TRILINEAR_H
43 static bool resize(
const FramePyramid& source, uint8_t* target,
const unsigned int targetWidth,
const unsigned int targetHeight,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
73 static bool resize(
Frame& frame,
const unsigned int newWidth,
const unsigned int newHeight,
Worker* worker =
nullptr);
87 template <
unsigned int tChannels>
88 static inline void homography8BitPerChannel(
const FramePyramid& sourcePyramid,
const unsigned int width,
const unsigned int height,
const SquareMatrix3& homography,
const uint8_t* borderColor, uint8_t* target,
Worker* worker =
nullptr);
102 static inline Vector3 interpolatePosition(
const unsigned int layerCount,
const Vector2& centerPosition,
const Vector2& cornerPosition1,
const Vector2& cornerPosition2,
const Vector2& cornerPosition3,
const Vector2& cornerPosition4);
113 template <
unsigned int tChannels>
114 static inline void interpolateFullBorder8BitPerChannel(
const FramePyramid& framePyramid,
const Vector3& position, uint8_t* result);
127 template <
unsigned int tChannels,
bool tAlphaAtFront,
bool tTransparentIs0xFF>
128 static inline void interpolateInfiniteBorder8BitPerChannelAlpha(
const FramePyramid& framePyramid,
const Vector3& position, uint8_t* result);
140 template <
unsigned int tChannels>
141 static inline void resize8BitPerChannel(
const FramePyramid& source, uint8_t* target,
const unsigned int targetWidth,
const unsigned int targetHeight,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
157 template <
unsigned int tChannels,
void tBilinearInterpolationFunction(const u
int8_t*, const
unsigned int, const
unsigned int, const
unsigned int, const Vector2&, u
int8_t*),
void tLinearInterpolationFunction(const u
int8_t*, const
unsigned int, const u
int8_t*, u
int8_t*)>
158 static inline void interpolate8BitPerChannel(
const FramePyramid& framePyramid,
const Vector3& position, uint8_t* result);
168 template <
unsigned int tChannels>
169 static inline void interpolateTwoPixels8BitPerChannel(
const uint8_t* first,
const unsigned int firstFactor,
const uint8_t* second, uint8_t* result);
181 template <
unsigned int tChannels,
bool tAlphaAtFront,
bool tTransparentIs0xFF>
182 static inline void interpolateTwoPixels8BitPerChannelAlpha(
const uint8_t* first,
const unsigned int firstFactor,
const uint8_t* second, uint8_t* result);
195 template <
unsigned int tChannels>
196 static void resize8BitPerChannelSubset(
const FramePyramid* source, uint8_t* target,
const unsigned int targetWidth,
const unsigned int targetHeight,
const unsigned int targetPaddingElements,
const unsigned int firstTargetRow,
const unsigned int numberTargetRows);
210 template <
unsigned int tChannels>
211 static void homography8BitPerChannelSubset(
const FramePyramid* sourcePyramid,
const unsigned int width,
const unsigned int height,
const SquareMatrix3* homography,
const uint8_t* borderColor, uint8_t* target,
const unsigned int firstRow,
const unsigned int numberRows);
216 const Scalar distance2 = ((cornerPosition3 - cornerPosition1).length() + (cornerPosition4 - cornerPosition2).length()) *
Scalar(0.5);
222 template <
unsigned int tChannels>
225 ocean_assert(framePyramid.
isValid() && result !=
nullptr);
229 interpolate8BitPerChannel<tChannels, &FrameInterpolatorBilinear::interpolatePixel8BitPerChannel<tChannels, PC_CENTER, Scalar>, &FrameInterpolatorTrilinear::interpolateTwoPixels8BitPerChannel<tChannels> >(framePyramid, position, result);
232 template <
unsigned int tChannels,
bool tAlphaAtFront,
bool tTransparentIs0xFF>
235 ocean_assert(framePyramid.
isValid() && result !=
nullptr);
239 interpolate8BitPerChannel<tChannels, &FrameInterpolatorBilinearAlpha<tAlphaAtFront, tTransparentIs0xFF>::template interpolateInfiniteBorder8BitPerChannel<tChannels>, &FrameInterpolatorTrilinear::interpolateTwoPixels8BitPerChannelAlpha<tChannels, tAlphaAtFront, tTransparentIs0xFF> >(framePyramid, position, result);
242 template <
unsigned int tChannels,
void tBilinearInterpolationFunction(const u
int8_t*, const
unsigned int, const
unsigned int, const
unsigned int, const Vector2&, u
int8_t*),
void tLinearInterpolationFunction(const u
int8_t*, const
unsigned int, const u
int8_t*, u
int8_t*)>
245 static_assert(tChannels != 0u,
"Invalid channel number!");
247 ocean_assert(result !=
nullptr);
248 ocean_assert(framePyramid.
layers() > 0u);
250 ocean_assert(position.
z() >= 0);
251 ocean_assert(position.
z() <=
Scalar(framePyramid.
layers() - 1u));
253 const unsigned int indexFine = (
unsigned int)position.
z();
254 const unsigned int indexCoarse = indexFine + (indexFine + 1u < framePyramid.
layers() ? 1u : 0u);
256 const Frame& frameFine = framePyramid.
layer(indexFine);
257 const unsigned int widthFine = frameFine.
width();
258 const unsigned int heightFine = frameFine.height();
260 const Frame& frameCoarse = framePyramid.
layer(indexCoarse);
261 const unsigned int widthCoarse = frameCoarse.
width();
262 const unsigned int heightCoarse = frameCoarse.
height();
272 uint8_t valueFine[tChannels];
273 uint8_t valueCoarse[tChannels];
275 tBilinearInterpolationFunction(frameFine.constdata<uint8_t>(), widthFine, heightFine, frameFine.paddingElements(), positionFine, valueFine);
276 tBilinearInterpolationFunction(frameCoarse.
constdata<uint8_t>(), widthCoarse, heightCoarse, frameCoarse.
paddingElements(), positionCoarse, valueCoarse);
280 ocean_assert(tz >= 0 && tz <= 1);
282 const unsigned int tzi = (
unsigned int)(tz *
Scalar(128) +
Scalar(0.5));
283 ocean_assert(tzi >= 0u && tzi <= 128u);
285 tLinearInterpolationFunction(valueCoarse, tzi, valueFine, result);
288 template <
unsigned int tChannels>
291 ocean_assert(first && second && result);
292 ocean_assert(firstFactor <= 128u);
294 const unsigned int secondFactor = 128u - firstFactor;
296 for (
unsigned int n = 0u; n < tChannels; ++n)
298 result[n] = (
unsigned char)((first[n] * firstFactor + second[n] * secondFactor + 64u) >> 7u);
302 template <
unsigned int tChannels,
bool tAlphaAtFront,
bool tTransparentIs0xFF>
305 ocean_assert(first && second && result);
306 ocean_assert(firstFactor <= 128u);
311 const unsigned int secondFactor = 128u - firstFactor;
312 const unsigned int denominator = firstFactor * FrameBlender::alpha8BitToOpaqueIs0xFF<tTransparentIs0xFF>(firstAlpha)
313 + secondFactor * FrameBlender::alpha8BitToOpaqueIs0xFF<tTransparentIs0xFF>(secondAlpha);
315 if (denominator != 0u)
317 const unsigned int denominator_2 = denominator / 2u;
321 result[n] = (
unsigned char)((first[n] * firstFactor * FrameBlender::alpha8BitToOpaqueIs0xFF<tTransparentIs0xFF>(firstAlpha)
322 + second[n] * secondFactor * FrameBlender::alpha8BitToOpaqueIs0xFF<tTransparentIs0xFF>(secondAlpha) + denominator_2) / denominator);
329 for (
unsigned int n = 0u; n < tChannels; ++n)
331 result[n] = uint8_t((first[n] * firstFactor + second[n] * secondFactor + 64u) >> 7u);
336 template <
unsigned int tChannels>
345 resize8BitPerChannelSubset<tChannels>(&source, target, targetWidth, targetHeight, targetPaddingElements, 0u, targetHeight);
349 template <
unsigned int tChannels>
352 static_assert(tChannels != 0u,
"Invalid channel number!");
354 ocean_assert(source !=
nullptr && target !=
nullptr);
355 ocean_assert(source->
isValid());
356 ocean_assert(source->
layers() != 0u);
361 const unsigned int sourceWidth = source->
finestWidth();
362 const unsigned int sourceHeight = source->
finestHeight();
364 ocean_assert(sourceWidth > 0);
365 ocean_assert(sourceHeight > 0);
376 const unsigned int targetStrideElements = targetWidth * tChannels + targetPaddingElements;
380 for (
unsigned int ty = firstTargetRow; ty < firstTargetRow + numberTargetRows; ++ty)
382 uint8_t* targetRow = target + ty * targetStrideElements;
386 for (
unsigned int tx = 0; tx < targetWidth; ++tx)
390 interpolateFullBorder8BitPerChannel<tChannels>(*source, position, targetRow);
391 targetRow += tChannels;
396 template <
unsigned int tChannels>
401 worker->
executeFunction(
Worker::Function::createStatic(&FrameInterpolatorTrilinear::homography8BitPerChannelSubset<tChannels>, &sourcePyramid, width, height, &homography, borderColor, target, 0u, 0u), 0, height, 6u, 7u, 20u);
405 homography8BitPerChannelSubset<tChannels>(&sourcePyramid, width, height, &homography, borderColor, target, 0u, height);
409 template <
unsigned int tChannels>
412 static_assert(tChannels >= 1u,
"Invalid channel number!");
414 ocean_assert(sourcePyramid && target);
415 ocean_assert(width > 0u && height > 0u);
416 ocean_assert(homography);
418 ocean_assert(firstRow + numberRows <= height);
426 memset(&zeroColor, 0x00,
sizeof(PixelType));
427 const PixelType*
const bColor = borderColor ? (PixelType*)borderColor : &zeroColor;
429 PixelType* targetData = (PixelType*)target + firstRow * width;
431 for (
unsigned int y = firstRow; y < firstRow + numberRows; ++y)
433 for (
unsigned int x = 0; x < width; ++x)
436 const Vector2 cornerPosition1 = centerPosition +
Vector2(-0.5, -0.5);
437 const Vector2 cornerPosition2 = centerPosition +
Vector2(0.5, -0.5);
438 const Vector2 cornerPosition3 = centerPosition +
Vector2(-0.5, 0.5);
439 const Vector2 cornerPosition4 = centerPosition +
Vector2(0.5, 0.5);
441 const Vector2 centerPositionHomography(*homography * centerPosition);
442 const Vector2 cornerPosition1Homography(*homography * cornerPosition1);
443 const Vector2 cornerPosition2Homography(*homography * cornerPosition2);
444 const Vector2 cornerPosition3Homography(*homography * cornerPosition3);
445 const Vector2 cornerPosition4Homography(*homography * cornerPosition4);
447 const Vector3 pyramidPosition =
interpolatePosition(sourcePyramid->
layers(), centerPositionHomography, cornerPosition1Homography, cornerPosition2Homography, cornerPosition3Homography, cornerPosition4Homography);
449 if (centerPositionHomography.
x() <
Scalar(0) || centerPositionHomography.
x() > scalarWidth_1 || centerPositionHomography.
y() <
Scalar(0) || centerPositionHomography.
y() > scalarHeight_1)
451 *targetData = *bColor;
455 interpolateFullBorder8BitPerChannel<tChannels>(*sourcePyramid, pyramidPosition, (uint8_t*)targetData);
Helper class allowing to determine the offset that is necessary to access the alpha channel.
Definition: FrameBlender.h:60
This class implements tri-linear frame interpolator functions.
Definition: FrameInterpolatorTrilinear.h:29
static Vector3 interpolatePosition(const unsigned int layerCount, const Vector2 ¢erPosition, const Vector2 &cornerPosition1, const Vector2 &cornerPosition2, const Vector2 &cornerPosition3, const Vector2 &cornerPosition4)
Calculates a 3D position usable for tri-linear interpolation.
Definition: FrameInterpolatorTrilinear.h:214
static void interpolateInfiniteBorder8BitPerChannelAlpha(const FramePyramid &framePyramid, const Vector3 &position, uint8_t *result)
Performs a pixel lookup in the frame pyramid using tri-linear interpolation with infinite transparent...
Definition: FrameInterpolatorTrilinear.h:233
static void homography8BitPerChannel(const FramePyramid &sourcePyramid, const unsigned int width, const unsigned int height, const SquareMatrix3 &homography, const uint8_t *borderColor, uint8_t *target, Worker *worker=nullptr)
Transforms a given 8 bit per channel input frame into an output frame by application of a homography.
Definition: FrameInterpolatorTrilinear.h:397
static bool resize(Frame &frame, const unsigned int newWidth, const unsigned int newHeight, Worker *worker=nullptr)
Resizes a given frame by a tri-linear interpolation and optionally uses a worker object to distribute...
static void interpolate8BitPerChannel(const FramePyramid &framePyramid, const Vector3 &position, uint8_t *result)
Performs a pixel lookup in the frame pyramid using tri-linear interpolation.
Definition: FrameInterpolatorTrilinear.h:243
static bool resize(const FramePyramid &source, uint8_t *target, const unsigned int targetWidth, const unsigned int targetHeight, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Resizes the finest layer of a given frame pyramid by a tri-linear interpolation and optionally uses a...
static void homography8BitPerChannelSubset(const FramePyramid *sourcePyramid, const unsigned int width, const unsigned int height, const SquareMatrix3 *homography, const uint8_t *borderColor, uint8_t *target, const unsigned int firstRow, const unsigned int numberRows)
Transforms an 8 bit per channel frame using the given homography.
Definition: FrameInterpolatorTrilinear.h:410
static void interpolateTwoPixels8BitPerChannelAlpha(const uint8_t *first, const unsigned int firstFactor, const uint8_t *second, uint8_t *result)
This function determines the linear interpolation result for to given layer pixels while the interpol...
Definition: FrameInterpolatorTrilinear.h:303
static void resize8BitPerChannel(const FramePyramid &source, uint8_t *target, const unsigned int targetWidth, const unsigned int targetHeight, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Renders the passed source frame pyramid into the target frame using tri-linear interpolation.
Definition: FrameInterpolatorTrilinear.h:337
static bool resize(const FramePyramid &source, Frame &target, Worker *worker=nullptr)
Resizes the finest layer of a given frame pyramid by a tri-linear interpolation and optionally uses a...
static void resize8BitPerChannelSubset(const FramePyramid *source, uint8_t *target, const unsigned int targetWidth, const unsigned int targetHeight, const unsigned int targetPaddingElements, const unsigned int firstTargetRow, const unsigned int numberTargetRows)
Renders the passed source frame pyramid into the target frame using tri-linear interpolation.
Definition: FrameInterpolatorTrilinear.h:350
static void interpolateFullBorder8BitPerChannel(const FramePyramid &framePyramid, const Vector3 &position, uint8_t *result)
Performs a pixel lookup in the frame pyramid using tri-linear interpolation.
Definition: FrameInterpolatorTrilinear.h:223
static void interpolateTwoPixels8BitPerChannel(const uint8_t *first, const unsigned int firstFactor, const uint8_t *second, uint8_t *result)
This function determines the linear interpolation result for to given layer pixels.
Definition: FrameInterpolatorTrilinear.h:289
static bool resize(const Frame &source, Frame &target, Worker *worker=nullptr)
Resizes a given frame by a tri-linear interpolation and optionally uses a worker object to distribute...
This class implements a frame pyramid.
Definition: FramePyramid.h:37
const Frame & finestLayer() const
Returns the finest layer frame of this pyramid.
Definition: FramePyramid.h:735
unsigned int finestWidth() const
Returns the width of the finest (first) layer.
Definition: FramePyramid.h:778
bool isValid() const
Returns whether this pyramid holds at least one frame layer.
Definition: FramePyramid.h:863
unsigned int layers() const
Returns the number of layers this pyramid holds.
Definition: FramePyramid.h:761
const FrameType & frameType() const
Returns the frame type of the finest layer.
Definition: FramePyramid.h:811
unsigned int finestHeight() const
Returns the height of the finest (first) layer.
Definition: FramePyramid.h:784
const Frame & layer(const unsigned int layer) const
Returns the frame of a specified layer.
Definition: FramePyramid.h:723
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
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
unsigned int width() const
Returns the width of the frame format in pixel.
Definition: Frame.h:3143
uint32_t numberPlanes() const
Returns the number of planes of the pixel format of this frame.
Definition: Frame.h:3183
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition: Frame.h:3153
@ DT_UNSIGNED_INTEGER_8
Unsigned 8 bit integer data type (uint8_t).
Definition: Frame.h:41
unsigned int height() const
Returns the height of the frame in pixel.
Definition: Frame.h:3148
static bool formatIsGeneric(const PixelFormat pixelFormat, const DataType dataType, const uint32_t channels, const uint32_t planes=1u, const uint32_t widthMultiple=1u, const uint32_t heightMultiple=1u)
Checks whether a given pixel format is a specific layout regarding data channels and data type.
Definition: Frame.h:3406
static T log(const T value)
Returns the natural logarithm of a given value (the logarithm to the base e).
Definition: Numeric.h:1655
static T ceil(const T value)
Returns the smallest integer value that is not less than the given value.
Definition: Numeric.h:1988
static constexpr T sqr(const T value)
Returns the square of a given value.
Definition: Numeric.h:1495
const T & x() const noexcept
Returns the x value.
Definition: Vector2.h:698
const T & y() const noexcept
Returns the y value.
Definition: Vector2.h:710
const T & y() const noexcept
Returns the y value.
Definition: Vector3.h:812
const T & x() const noexcept
Returns the x value.
Definition: Vector3.h:800
const T & z() const noexcept
Returns the z value.
Definition: Vector3.h:824
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.
T minmax(const T &lowerBoundary, const T &value, const T &upperBoundary)
This function fits a given parameter into a specified value range.
Definition: base/Utilities.h:903
float Scalar
Definition of a scalar type.
Definition: Math.h:128
VectorT3< Scalar > Vector3
Definition of a 3D vector.
Definition: Vector3.h:22
VectorT2< Scalar > Vector2
Definition of a 2D vector.
Definition: Vector2.h:21
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15