19#include <peak_common/types/peak_common_iimageview.hpp>
20#include <peak_common/types/peak_common_metadata.hpp>
29class ImageBackendAccessor;
90 const peak::ipl::PixelFormat& pixelFormat, uint8_t* buffer,
size_t bufferSize,
size_t width,
size_t height);
127 Image(
const peak::ipl::PixelFormat& pixelFormat, uint8_t* buffer,
size_t bufferSize,
size_t width,
size_t height, uint64_t timestamp_ns);
141 explicit Image(peak::common::IImageView& imageView);
265 template<typename T, typename = std::enable_if_t<std::is_arithmetic<T>::value>>
321 template<typename T, typename = std::enable_if_t<std::is_arithmetic<T>::value>>
324 return reinterpret_cast<T*
>(
Data());
366 size_t outputImageBufferSize,
421 uint8_t* outputImageBuffer,
size_t outputImageBufferSize,
double factor,
double offset = 0.0,
487 template <
typename Integer1,
typename Integer2,
488 typename std::enable_if_t<std::is_integral<Integer1>::value,
int> = 0,
489 typename std::enable_if_t<std::is_integral<Integer2>::value,
int> = 0>
492 return Scale(
peak::ipl::Size2D{
static_cast<std::size_t
>(width),
static_cast<std::size_t
>(height)}, algorithm);
540 template<
typename FloatingPoint1,
typename FloatingPoint2,
541 typename std::enable_if_t<std::is_floating_point<FloatingPoint1>::value,
int> = 0,
542 typename std::enable_if_t<std::is_floating_point<FloatingPoint2>::value,
int> = 0>
634 friend ImageBackendAccessor;
648class ImageBackendAccessor
660 return image.m_backendHandle;
674 return peak::ipl::Image(imageHandle,
false);
688 return peak::ipl::Image(imageHandle,
true);
714 const peak::ipl::PixelFormat& pixelFormat, uint8_t* buffer,
size_t bufferSize,
size_t width,
size_t height)
732 const peak::ipl::PixelFormat& pixelFormat, uint8_t* buffer,
size_t bufferSize,
size_t width,
size_t height, uint64_t timestamp_ns) :
733 Image::
Image(pixelFormat, buffer, bufferSize, width, height)
742 imageView.GetSizeInBytes(), imageView.GetWidth(), imageView.GetHeight())
744 const auto metadata = imageView.GetMetadata();
745 if(metadata->HasEntryByKey<peak::common::MetadataKey::DeviceTimestamp>())
747 const auto timestamp_ns = metadata->GetValueByKey<peak::common::MetadataKey::DeviceTimestamp>();
748 ExecuteAndMapReturnCodes(
749 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Image_SetTimestamp(m_backendHandle, timestamp_ns); });
754 : m_backendHandle(imageHandle)
756 if (acquireReference && m_backendHandle)
772 if (other.m_backendHandle)
777 m_backendHandle = other.m_backendHandle;
789 if (other.m_backendHandle)
795 m_backendHandle = other.m_backendHandle;
802 *
this = std::move(other);
809 if (m_backendHandle !=
nullptr)
813 m_backendHandle = other.m_backendHandle;
814 other.m_backendHandle =
nullptr;
845 uint8_t* pixelPosition =
nullptr;
851 return pixelPosition;
856 size_t byteCount = 0;
878 uint8_t* data =
nullptr;
895 return ImageBackendAccessor::CreateImage(outputImageHandle);
908 return ImageBackendAccessor::CreateImage(outputImageHandle);
921 return ImageBackendAccessor::CreateImage(outputImageHandle);
925 const peak::ipl::PixelFormat& outputPixelFormat, uint8_t* outputImageBuffer,
size_t outputImageBufferSize,
935 return ImageBackendAccessor::CreateImage(outputImageHandle);
948 return ImageBackendAccessor::CreateImage(outputImageHandle);
962 return ImageBackendAccessor::CreateImage(outputImageHandle);
974 return ImageBackendAccessor::CreateImage(outputImageHandle);
979 return Scale(
Size2D{
static_cast<size_t>(
static_cast<double>(
Width()) * factor.
x),
static_cast<size_t>(
static_cast<double>(
Height()) * factor.
y)}, algorithm);
1002 return ImageBackendAccessor::CreateImage(outputImageHandle);
1007 return Crop({0,0}, size);
1016 return ImageBackendAccessor::CreateImage(outputImageHandle);
1026 uint64_t timestamp_ns;
1031 return timestamp_ns;
1036 if (img.
ByteCount() != this->ByteCount())
1040 if (img.
Width() != this->Width())
1044 if (img.
Height() != this->Height())
1052 if (img.
Timestamp() != this->Timestamp())
1057 return memcmp(img.
Data(), this->Data(), img.
ByteCount()) == 0;
1062 return !(*
this == img);
Stores the pixel format, width and height of an image and the pointer to the image buffer.
Definition peak_ipl_image.hpp:46
T * PixelPointer(size_t xPos, size_t yPos) const
Returns the pixel pointer to the given pixel position in relation to the size of the pixel format.
Definition peak_ipl_image.hpp:266
bool operator!=(const Image &img) const
Checks whether the image is data-wise different.
Definition peak_ipl_image.hpp:1060
Image & operator=(const Image &other)
Copy assigment for Image instance.
Definition peak_ipl_image.hpp:780
size_t Width() const
Returns the width.
Definition peak_ipl_image.hpp:820
bool Empty() const
Checks whether the image is empty.
Definition peak_ipl_image.hpp:1019
peak::ipl::Size2D Size() const
Returns the Size.
Definition peak_ipl_image.hpp:838
Image ConvertToWithFactor(const peak::ipl::PixelFormat &outputPixelFormat, double factor, double offset=0.0, peak::ipl::ConversionMode conversionMode=peak::ipl::ConversionMode::Fast) const
Converts the image to the specified outputPixelFormat and scales the pixel values by the factor.
Definition peak_ipl_image.hpp:911
peak::ipl::PixelFormat PixelFormat() const
Returns the pixel format.
Definition peak_ipl_image.hpp:864
uint8_t * PixelPointer(size_t xPos, size_t yPos) const
Returns the pixel pointer to the given pixel position in relation to the size of the pixel format.
Definition peak_ipl_image.hpp:843
size_t ByteCount() const
Returns the size of the given image in number of bytes.
Definition peak_ipl_image.hpp:854
bool operator==(const Image &img) const
Checks whether the image is data-wise the same.
Definition peak_ipl_image.hpp:1034
uint8_t * Data() const
Returns the pointer to the first pixel position in dependency on the size of the pixel format.
Definition peak_ipl_image.hpp:876
void ScaleInto(const peak::ipl::Size2D &size, uint8_t *buffer, std::size_t bufferSize, peak::ipl::InterpolationAlgorithm algorithm=InterpolationAlgorithm::linear) const
Scale the image to the supplied width and height using the supplied algorithm and save it into the su...
Definition peak_ipl_image.hpp:982
Image ConvertToFromInterval(const peak::ipl::PixelFormat &outputPixelFormat, const peak::ipl::Interval< double > &interval, peak::ipl::ConversionMode conversionMode=peak::ipl::ConversionMode::Fast) const
Converts the image to the specified outputPixelFormat. The pixel values are mapped from interval to t...
Definition peak_ipl_image.hpp:938
size_t Height() const
Returns the height.
Definition peak_ipl_image.hpp:829
Image Crop(const peak::ipl::Point2D &pos, const peak::ipl::Size2D &size) const
Crop the image to the size starting at pos.
Definition peak_ipl_image.hpp:992
Image Clone() const
Returns a new created image containing the data of the current image as deep copy.
Definition peak_ipl_image.hpp:1010
~Image()
Destructor for the Image instance.
Definition peak_ipl_image.hpp:762
Image()
Creates an empty image. In other words, size is 0x0 and an invalid pixel format.
Definition peak_ipl_image.hpp:698
Image ConvertTo(const peak::ipl::PixelFormat &outputPixelFormat, peak::ipl::ConversionMode conversionMode=peak::ipl::ConversionMode::Fast) const
Converts the image to the specified outputPixelFormat.
Definition peak_ipl_image.hpp:885
uint64_t Timestamp() const
The timestamp in nanoseconds.
Definition peak_ipl_image.hpp:1024
Image Scale(Integer1 width, Integer2 height, peak::ipl::InterpolationAlgorithm algorithm=InterpolationAlgorithm::linear) const
Scale the image to the supplied width and height using the supplied algorithm.
Definition peak_ipl_image.hpp:490
Image Scale(FloatingPoint1 scaleFactorX, FloatingPoint2 scaleFactorY, peak::ipl::InterpolationAlgorithm algorithm=InterpolationAlgorithm::linear) const
Scale the image to the supplied scale factors scaleFactorX and scaleFactorY using the supplied algori...
Definition peak_ipl_image.hpp:543
T * Data() const
Returns the pointer to the first pixel position in dependency on the size of the pixel format.
Definition peak_ipl_image.hpp:322
Interval support and convenience class.
Definition peak_ipl_interval.hpp:37
constexpr T End() const
Get the end value (inclusive) for the interval.
Definition peak_ipl_interval.hpp:80
constexpr T Start() const
Get the start value (inclusive) for the interval.
Definition peak_ipl_interval.hpp:68
The "peak::ipl" namespace contains the whole image processing library.
InterpolationAlgorithm
Enum holding the possible interpolation algorithm.
Definition peak_ipl_simple_types.hpp:204
@ linear
bilinear interpolation
Definition peak_ipl_simple_types.hpp:206
PixelFormatName
Enum holding the possible pixel format names.
Definition peak_ipl_simple_types.hpp:41
@ Invalid
Invalid Pixel Format.
Definition peak_ipl_simple_types.hpp:42
ConversionMode
Enum holding the possible conversion modes.
Definition peak_ipl_simple_types.hpp:31
@ Fast
Fast conversion mode.
Definition peak_ipl_simple_types.hpp:32
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:271
#define PEAK_IPL_NO_DISCARD
Definition peak_ipl_attribute_defines.h:25
PEAK_IPL_C_API PEAK_IPL_Image_Destruct(PEAK_IPL_IMAGE_HANDLE imageHandle)
Destroys the image associated with the given handle.
PEAK_IPL_C_API PEAK_IPL_Image_ConstructFromBuffer(PEAK_IPL_PIXEL_FORMAT pixelFormat, uint8_t *buffer, uint64_t bufferSize, size_t width, size_t height, PEAK_IPL_IMAGE_HANDLE *imageHandle)
Creates an image from a given buffer.
PEAK_IPL_C_API PEAK_IPL_Image_Construct(PEAK_IPL_PIXEL_FORMAT pixelFormat, size_t width, size_t height, PEAK_IPL_IMAGE_HANDLE *imageHandle)
Creates an image.
PEAK_IPL_C_API PEAK_IPL_Image_ConvertToFromInterval(PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_PIXEL_FORMAT outputPixelFormat, double start, double end, PEAK_IPL_CONVERSION_MODE conversionMode, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Converts the given imageHandle to the specified outputPixelFormat. The pixel values are mapped from t...
PEAK_IPL_C_API PEAK_IPL_Image_ConvertToBufferWithFactorAndOffset(PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_PIXEL_FORMAT outputPixelFormat, double factor, double offset, uint8_t *outputImageBuffer, size_t outputImageBufferSize, PEAK_IPL_CONVERSION_MODE conversionMode, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Converts the given imageHandle to the specified outputPixelFormat into an existing outputImageBuffer ...
PEAK_IPL_C_API PEAK_IPL_Image_Acquire(PEAK_IPL_IMAGE_HANDLE imageHandle)
Increase the reference count of an image object.
PEAK_IPL_C_API PEAK_IPL_Image_GetWidth(PEAK_IPL_IMAGE_HANDLE imageHandle, size_t *width)
Queries the width of the given image.
int32_t PEAK_IPL_CONVERSION_MODE
Definition peak_ipl_backend.h:55
PEAK_IPL_C_API PEAK_IPL_Image_ConvertToBufferFromInterval(PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_PIXEL_FORMAT outputPixelFormat, double start, double end, uint8_t *outputImageBuffer, size_t outputImageBufferSize, PEAK_IPL_CONVERSION_MODE conversionMode, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Converts the given imageHandle to the specified outputPixelFormat into an existing outputImageBuffer....
PEAK_IPL_C_API PEAK_IPL_Image_GetTimestamp(PEAK_IPL_IMAGE_HANDLE imageHandle, uint64_t *timestamp_ns)
Get the timestamp for an image in nanoseconds.
PEAK_IPL_C_API PEAK_IPL_Image_ConvertTo(PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_PIXEL_FORMAT outputPixelFormat, PEAK_IPL_CONVERSION_MODE conversionMode, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Creates a new image containing the data of the current image converted to the given pixel format.
PEAK_IPL_C_API PEAK_IPL_Image_Clone(PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Returns a new created image containing the data of the current image as deep copy.
PEAK_IPL_C_API PEAK_IPL_Image_GetByteCount(PEAK_IPL_IMAGE_HANDLE imageHandle, size_t *byteCount)
Queries the size of the given image in number of bytes.
PEAK_IPL_C_API PEAK_IPL_Image_GetPixelFormat(PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_PIXEL_FORMAT *pixelFormat)
Queries the pixel format of the given image.
struct PEAK_IPL_IMAGE * PEAK_IPL_IMAGE_HANDLE
Definition peak_ipl_backend.h:405
PEAK_IPL_C_API PEAK_IPL_Image_ScaleInto(PEAK_IPL_IMAGE_HANDLE imageHandle, const struct PEAK_IPL_SIZE_2D *size, uint8_t *buffer, size_t bufferSize, PEAK_IPL_INTERPOLATION_ALGORITHM algorithm)
Creates a new image scaled to size using algorithm into the supplied buffer.
PEAK_IPL_C_API PEAK_IPL_Image_Crop(PEAK_IPL_IMAGE_HANDLE imageHandle, const struct PEAK_IPL_POINT_2D *pos, const struct PEAK_IPL_SIZE_2D *size, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Creates a new image cropped to size starting at position.
@ PEAK_IPL_PIXEL_FORMAT_INVALID
Definition peak_ipl_backend.h:60
PEAK_IPL_C_API PEAK_IPL_Image_Scale(PEAK_IPL_IMAGE_HANDLE imageHandle, const struct PEAK_IPL_SIZE_2D *size, PEAK_IPL_INTERPOLATION_ALGORITHM algorithm, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Creates a new image scaled to size using algorithm.
PEAK_IPL_C_API PEAK_IPL_Image_GetData(PEAK_IPL_IMAGE_HANDLE imageHandle, uint8_t **data)
Queries the data pointer of the given image.
int32_t PEAK_IPL_INTERPOLATION_ALGORITHM
Definition peak_ipl_backend.h:303
PEAK_IPL_C_API PEAK_IPL_Image_GetHeight(PEAK_IPL_IMAGE_HANDLE imageHandle, size_t *height)
Queries the height of the given image.
int32_t PEAK_IPL_PIXEL_FORMAT
Definition peak_ipl_backend.h:173
PEAK_IPL_C_API PEAK_IPL_Image_GetPixelPointer(PEAK_IPL_IMAGE_HANDLE imageHandle, size_t xPos, size_t yPos, uint8_t **pixelPointer)
Queries the pointer to the given pixel position.
PEAK_IPL_C_API PEAK_IPL_Image_SetTimestamp(PEAK_IPL_IMAGE_HANDLE imageHandle, uint64_t timestamp_ns)
Set the timestamp for an image in nanoseconds.
PEAK_IPL_C_API PEAK_IPL_Image_ConvertToWithFactorAndOffset(PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_PIXEL_FORMAT outputPixelFormat, double factor, double offset, PEAK_IPL_CONVERSION_MODE conversionMode, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Creates a new image containing the data of the current image converted to the given pixel format mult...
PEAK_IPL_C_API PEAK_IPL_Image_ConvertToBuffer(PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_PIXEL_FORMAT outputPixelFormat, uint8_t *outputImageBuffer, size_t outputImageBufferSize, PEAK_IPL_CONVERSION_MODE conversionMode, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Stores the data of the current image converted to the given pixel format into a destination buffer an...
#define PEAK_IPL_C_ABI_PREFIX
Definition peak_ipl_dll_defines.h:16
Definition peak_ipl_backend.h:259
Definition peak_ipl_backend.h:265
2D position in an image.
Definition peak_ipl_simple_types.hpp:242
size_t x
X position.
Definition peak_ipl_simple_types.hpp:243
size_t y
Y position.
Definition peak_ipl_simple_types.hpp:244
Scale Factors of an image.
Definition peak_ipl_simple_types.hpp:267
double y
Y factor.
Definition peak_ipl_simple_types.hpp:269
double x
X factor.
Definition peak_ipl_simple_types.hpp:268
2D size of an image.
Definition peak_ipl_simple_types.hpp:218
size_t height
Height of size.
Definition peak_ipl_simple_types.hpp:220
size_t width
Width of size.
Definition peak_ipl_simple_types.hpp:219