IDS peak IPL v1.15.0
Loading...
Searching...
No Matches
peak_ipl_image_converter.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
17
20#include <cstdint>
21#include <utility>
22#include <vector>
23
27namespace peak
28{
29namespace ipl
30{
31
32class Image;
33
48class ImageConverter final
49{
50public:
58
66
78 ImageConverter(const ImageConverter& other);
79
92
101 ImageConverter(ImageConverter&& other) noexcept;
102
111 ImageConverter& operator=(ImageConverter&& other) noexcept;
112
127 ImageConverter(const peak::ipl::PixelFormat& inputPixelFormat,
128 const peak::ipl::PixelFormat& outputPixelFormat, size_t width, size_t height, size_t imageCount = 5);
129
143 void PreAllocateConversion(const peak::ipl::PixelFormat& inputPixelFormat,
144 const peak::ipl::PixelFormat& outputPixelFormat, size_t width, size_t height, size_t imageCount = 5);
145
156
166 void SetConversionMode(peak::ipl::ConversionMode conversionMode);
167
179 PEAK_IPL_NO_DISCARD std::vector<peak::ipl::PixelFormatName> SupportedOutputPixelFormatNames(
180 const peak::ipl::PixelFormat& inputPixelFormat) const;
181
195 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat) const;
196
215 Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
216 uint8_t* outputImageBuffer, size_t outputImageBufferSize) const;
217
238 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
239 double factor, double offset = 0.0) const;
240
264 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
265 uint8_t* outputImageBuffer, size_t outputImageBufferSize, double factor, double offset = 0.0) const;
266
286 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
287 peak::ipl::Interval<double> interval) const;
288
313 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
314 uint8_t* outputImageBuffer, size_t outputImageBufferSize, peak::ipl::Interval<double> interval) const;
315
316private:
317 PEAK_IPL_IMAGE_CONVERTER_HANDLE m_backendHandle{};
318};
319
320} /* namespace ipl */
321} /* namespace peak */
322
324
325namespace peak
326{
327namespace ipl
328{
329
334
336 const peak::ipl::PixelFormat& outputPixelFormat, const size_t width, const size_t height, const size_t imageCount)
337{
339 PreAllocateConversion(inputPixelFormat, outputPixelFormat, width, height, imageCount);
340}
341
343{
344 if (m_backendHandle)
345 {
347 }
348}
349
351{
352 if (other.m_backendHandle)
353 {
355 }
356
357 m_backendHandle = other.m_backendHandle;
358}
359
361{
362 if (this != &other)
363 {
364 if (m_backendHandle)
365 {
367 }
368
369 if (other.m_backendHandle)
370 {
372 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_ImageConverter_Acquire(other.m_backendHandle); });
373 }
374 }
375
376 m_backendHandle = other.m_backendHandle;
377
378 return *this;
379}
380
382{
383 *this = std::move(other);
384}
385
387{
388 if (this != &other)
389 {
390 if (m_backendHandle != nullptr)
391 {
393 }
394
395 m_backendHandle = other.m_backendHandle;
396 other.m_backendHandle = nullptr;
397 }
398
399 return *this;
400}
401
403 const peak::ipl::PixelFormat& outputPixelFormat, const size_t width, const size_t height,
404 const size_t imageCount)
405{
408 static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()),
409 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), width, height, imageCount);
410 });
411}
412
414{
416
419 m_backendHandle, reinterpret_cast<PEAK_IPL_CONVERSION_MODE*>(&conversionMode));
420 });
421
422 return conversionMode;
423}
424
426{
429 m_backendHandle, static_cast<PEAK_IPL_CONVERSION_MODE>(conversionMode));
430 });
431}
432
433inline std::vector<PixelFormatName> ImageConverter::SupportedOutputPixelFormatNames(
434 const PixelFormat& inputPixelFormat) const
435{
436 size_t size = 0;
439 m_backendHandle, static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()), nullptr, &size);
440 });
441 std::vector<PixelFormatName> supportedOutputPixelFormats(size);
444 static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()),
445 reinterpret_cast<PEAK_IPL_PIXEL_FORMAT*>(supportedOutputPixelFormats.data()), &size);
446 });
447
448 return supportedOutputPixelFormats;
449}
450
451inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat) const
452{
453 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
456 ImageBackendAccessor::BackendHandle(inputImage),
457 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), &outputImageHandle);
458 });
459
460 return ImageBackendAccessor::CreateImage(outputImageHandle);
461}
462
463inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat,
464 uint8_t* outputImageBuffer, size_t outputImageBufferSize) const
465{
466 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
469 ImageBackendAccessor::BackendHandle(inputImage),
470 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), outputImageBuffer,
471 outputImageBufferSize, &outputImageHandle);
472 });
473
474 return ImageBackendAccessor::CreateImage(outputImageHandle);
475}
476
477inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat, peak::ipl::Interval<double> interval) const
478{
479 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
482 ImageBackendAccessor::BackendHandle(inputImage),
483 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), interval.Start(),
484 interval.End(), &outputImageHandle);
485 });
486
487 return ImageBackendAccessor::CreateImage(outputImageHandle);
488}
489
490inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat,
491 uint8_t* outputImageBuffer, size_t outputImageBufferSize, peak::ipl::Interval<double> interval) const
492{
493 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
496 ImageBackendAccessor::BackendHandle(inputImage), interval.Start(), interval.End(),
497 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), outputImageBuffer,
498 outputImageBufferSize, &outputImageHandle);
499 });
500
501 return ImageBackendAccessor::CreateImage(outputImageHandle);
502}
503
505 const Image& inputImage, const PixelFormat& outputPixelFormat, double factor, double offset) const
506{
507 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
510 ImageBackendAccessor::BackendHandle(inputImage),
511 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), factor, offset, &outputImageHandle);
512 });
513
514 return ImageBackendAccessor::CreateImage(outputImageHandle);
515}
516
517inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat,
518 uint8_t* outputImageBuffer, size_t outputImageBufferSize, double factor, double offset) const
519{
520 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
523 ImageBackendAccessor::BackendHandle(inputImage), factor, offset,
524 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), outputImageBuffer,
525 outputImageBufferSize, &outputImageHandle);
526 });
527
528 return ImageBackendAccessor::CreateImage(outputImageHandle);
529}
530
531} /* namespace ipl */
532} /* namespace peak */
peak::ipl::ConversionMode ConversionMode() const
Returns the current conversion mode.
Definition peak_ipl_image_converter.hpp:413
~ImageConverter()
Destructor for the ImageConverter instance.
Definition peak_ipl_image_converter.hpp:342
ImageConverter & operator=(const ImageConverter &other)
Copy assigment for ImageConverter instance.
Definition peak_ipl_image_converter.hpp:360
Image Convert(const Image &inputImage, const peak::ipl::PixelFormat &outputPixelFormat) const
Converts the given inputImage to the specified outputPixelFormat.
Definition peak_ipl_image_converter.hpp:451
ImageConverter()
Constructor for a new ImageConverter instance.
Definition peak_ipl_image_converter.hpp:330
void PreAllocateConversion(const peak::ipl::PixelFormat &inputPixelFormat, const peak::ipl::PixelFormat &outputPixelFormat, size_t width, size_t height, size_t imageCount=5)
Pre-allocate buffer pools needed for the specified conversion.
Definition peak_ipl_image_converter.hpp:402
void SetConversionMode(peak::ipl::ConversionMode conversionMode)
Set conversion mode.
Definition peak_ipl_image_converter.hpp:425
std::vector< peak::ipl::PixelFormatName > SupportedOutputPixelFormatNames(const peak::ipl::PixelFormat &inputPixelFormat) const
Returns the supported output pixel formats for a given input pixel format.
Definition peak_ipl_image_converter.hpp:433
Stores the pixel format, width and height of an image and the pointer to the image buffer.
Definition peak_ipl_image.hpp:41
Interval support and convenience class.
Definition peak_ipl_interval.hpp:35
constexpr T End() const
Get the end value (inclusive) for the interval.
Definition peak_ipl_interval.hpp:78
constexpr T Start() const
Get the start value (inclusive) for the interval.
Definition peak_ipl_interval.hpp:66
Represents a pixel format and its specific properties.
Definition peak_ipl_pixel_format.hpp:32
peak::ipl::PixelFormatName PixelFormatName() const
Returns the name of the pixel format as enum value.
Definition peak_ipl_pixel_format.hpp:122
Definition peak_ipl_binning.hpp:25
ConversionMode
Enum holding the possible conversion modes.
Definition peak_ipl_simple_types.hpp:29
@ Fast
Fast conversion mode.
Definition peak_ipl_simple_types.hpp:30
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:182
The "peak::ipl" namespace contains the whole image processing library.
Definition peak_ipl_binning.hpp:23
#define PEAK_IPL_NO_DISCARD
Definition peak_ipl_attribute_defines.h:25
PEAK_IPL_C_API PEAK_IPL_ImageConverter_GetSupportedOutputPixelFormats(PEAK_IPL_IMAGE_CONVERTER_HANDLE imageConverterHandle, PEAK_IPL_PIXEL_FORMAT inputPixelFormat, PEAK_IPL_PIXEL_FORMAT *outputPixelFormats, size_t *outputPixelFormatsSize)
Queries the supported output pixel formats for a given input pixel format.
PEAK_IPL_C_API PEAK_IPL_ImageConverter_ConvertWithFactorAndOffset(PEAK_IPL_IMAGE_CONVERTER_HANDLE imageConverterHandle, PEAK_IPL_IMAGE_HANDLE inputImageHandle, PEAK_IPL_PIXEL_FORMAT outputPixelFormat, double factor, double offset, 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_ImageConverter_Convert(PEAK_IPL_IMAGE_CONVERTER_HANDLE imageConverterHandle, PEAK_IPL_IMAGE_HANDLE inputImageHandle, PEAK_IPL_PIXEL_FORMAT outputPixelFormat, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Creates a new image containing the data of the input image converted to the given pixel format.
PEAK_IPL_C_API PEAK_IPL_ImageConverter_Construct(PEAK_IPL_IMAGE_CONVERTER_HANDLE *imageConverterHandle)
Creates an image converter.
PEAK_IPL_C_API PEAK_IPL_ImageConverter_Acquire(PEAK_IPL_IMAGE_CONVERTER_HANDLE imageConverterHandle)
Increase the reference count of an image converter.
int32_t PEAK_IPL_CONVERSION_MODE
Definition peak_ipl_backend.h:55
PEAK_IPL_C_API PEAK_IPL_ImageConverter_ConvertToBuffer(PEAK_IPL_IMAGE_CONVERTER_HANDLE imageConverterHandle, PEAK_IPL_IMAGE_HANDLE inputImageHandle, PEAK_IPL_PIXEL_FORMAT outputPixelFormat, uint8_t *outputImageBuffer, size_t outputImageBufferSize, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Creates a new image containing the data of the input image converted to the given pixel format.
PEAK_IPL_C_API PEAK_IPL_ImageConverter_PreAllocateConversion(PEAK_IPL_IMAGE_CONVERTER_HANDLE imageConverterHandle, PEAK_IPL_PIXEL_FORMAT inputPixelFormat, PEAK_IPL_PIXEL_FORMAT outputPixelFormat, size_t width, size_t height, size_t imageCount)
Pre-allocates internal buffer pools for the specified conversion.
PEAK_IPL_C_API PEAK_IPL_ImageConverter_SetConversionMode(PEAK_IPL_IMAGE_CONVERTER_HANDLE imageConverterHandle, PEAK_IPL_CONVERSION_MODE conversionMode)
Sets the given image converter's conversion mode.
struct PEAK_IPL_IMAGE * PEAK_IPL_IMAGE_HANDLE
Definition peak_ipl_backend.h:388
PEAK_IPL_C_API PEAK_IPL_ImageConverter_Destruct(PEAK_IPL_IMAGE_CONVERTER_HANDLE imageConverterHandle)
Destroys the image converter associated with the given handle.
int32_t PEAK_IPL_PIXEL_FORMAT
Definition peak_ipl_backend.h:173
PEAK_IPL_C_API PEAK_IPL_ImageConverter_ConvertFromInterval(PEAK_IPL_IMAGE_CONVERTER_HANDLE imageConverterHandle, PEAK_IPL_IMAGE_HANDLE inputImageHandle, PEAK_IPL_PIXEL_FORMAT outputPixelFormat, double start, double end, 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_ImageConverter_ConvertToBufferFromInterval(PEAK_IPL_IMAGE_CONVERTER_HANDLE imageConverterHandle, PEAK_IPL_IMAGE_HANDLE inputImageHandle, double start, double end, PEAK_IPL_PIXEL_FORMAT outputPixelFormat, uint8_t *outputImageBuffer, size_t outputImageBufferSize, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Converts the given imageHandle to the specified outputPixelFormat into an existing outputImageBuffer....
PEAK_IPL_C_API PEAK_IPL_ImageConverter_ConvertToBufferWithFactorAndOffset(PEAK_IPL_IMAGE_CONVERTER_HANDLE imageConverterHandle, PEAK_IPL_IMAGE_HANDLE inputImageHandle, double factor, double offset, PEAK_IPL_PIXEL_FORMAT outputPixelFormat, uint8_t *outputImageBuffer, size_t outputImageBufferSize, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Converts the given imageHandle to the specified outputPixelFormat into an existing outputImageBuffer ...
struct PEAK_IPL_IMAGE_CONVERTER * PEAK_IPL_IMAGE_CONVERTER_HANDLE
Definition peak_ipl_backend.h:356
PEAK_IPL_C_API PEAK_IPL_ImageConverter_GetConversionMode(PEAK_IPL_IMAGE_CONVERTER_HANDLE imageConverterHandle, PEAK_IPL_CONVERSION_MODE *conversionMode)
Queries the given image converter's current conversion mode.
#define PEAK_IPL_C_ABI_PREFIX
Definition peak_ipl_dll_defines.h:16