IDS peak IPL v1.17.2
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
28
29namespace peak
30{
31namespace ipl
32{
33
34class Image;
35
51class ImageConverter final
52{
53public:
61
69
81 ImageConverter(const ImageConverter& other);
82
95
104 ImageConverter(ImageConverter&& other) noexcept;
105
114 ImageConverter& operator=(ImageConverter&& other) noexcept;
115
130 ImageConverter(const peak::ipl::PixelFormat& inputPixelFormat,
131 const peak::ipl::PixelFormat& outputPixelFormat, size_t width, size_t height, size_t imageCount = 5);
132
146 void PreAllocateConversion(const peak::ipl::PixelFormat& inputPixelFormat,
147 const peak::ipl::PixelFormat& outputPixelFormat, size_t width, size_t height, size_t imageCount = 5);
148
159
169 void SetConversionMode(peak::ipl::ConversionMode conversionMode);
170
182 PEAK_IPL_NO_DISCARD std::vector<peak::ipl::PixelFormatName> SupportedOutputPixelFormatNames(
183 const peak::ipl::PixelFormat& inputPixelFormat) const;
184
198 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat) const;
199
218 Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
219 uint8_t* outputImageBuffer, size_t outputImageBufferSize) const;
220
241 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
242 double factor, double offset = 0.0) const;
243
267 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
268 uint8_t* outputImageBuffer, size_t outputImageBufferSize, double factor, double offset = 0.0) const;
269
289 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
290 peak::ipl::Interval<double> interval) const;
291
316 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
317 uint8_t* outputImageBuffer, size_t outputImageBufferSize, peak::ipl::Interval<double> interval) const;
318
319private:
320 PEAK_IPL_IMAGE_CONVERTER_HANDLE m_backendHandle{};
321};
322
323} /* namespace ipl */
324} /* namespace peak */
325
327
328namespace peak
329{
330namespace ipl
331{
332
337
339 const peak::ipl::PixelFormat& outputPixelFormat, const size_t width, const size_t height, const size_t imageCount)
340{
342 PreAllocateConversion(inputPixelFormat, outputPixelFormat, width, height, imageCount);
343}
344
346{
347 if (m_backendHandle)
348 {
350 }
351}
352
354{
355 if (other.m_backendHandle)
356 {
358 }
359
360 m_backendHandle = other.m_backendHandle;
361}
362
364{
365 if (this != &other)
366 {
367 if (m_backendHandle)
368 {
370 }
371
372 if (other.m_backendHandle)
373 {
375 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_ImageConverter_Acquire(other.m_backendHandle); });
376 }
377 }
378
379 m_backendHandle = other.m_backendHandle;
380
381 return *this;
382}
383
385{
386 *this = std::move(other);
387}
388
390{
391 if (this != &other)
392 {
393 if (m_backendHandle != nullptr)
394 {
396 }
397
398 m_backendHandle = other.m_backendHandle;
399 other.m_backendHandle = nullptr;
400 }
401
402 return *this;
403}
404
406 const peak::ipl::PixelFormat& outputPixelFormat, const size_t width, const size_t height,
407 const size_t imageCount)
408{
411 static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()),
412 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), width, height, imageCount);
413 });
414}
415
417{
419
422 m_backendHandle, reinterpret_cast<PEAK_IPL_CONVERSION_MODE*>(&conversionMode));
423 });
424
425 return conversionMode;
426}
427
429{
432 m_backendHandle, static_cast<PEAK_IPL_CONVERSION_MODE>(conversionMode));
433 });
434}
435
436inline std::vector<PixelFormatName> ImageConverter::SupportedOutputPixelFormatNames(
437 const PixelFormat& inputPixelFormat) const
438{
439 size_t size = 0;
442 m_backendHandle, static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()), nullptr, &size);
443 });
444 std::vector<PixelFormatName> supportedOutputPixelFormats(size);
447 static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()),
448 reinterpret_cast<PEAK_IPL_PIXEL_FORMAT*>(supportedOutputPixelFormats.data()), &size);
449 });
450
451 return supportedOutputPixelFormats;
452}
453
454inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat) const
455{
456 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
459 ImageBackendAccessor::BackendHandle(inputImage),
460 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), &outputImageHandle);
461 });
462
463 return ImageBackendAccessor::CreateImage(outputImageHandle);
464}
465
466inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat,
467 uint8_t* outputImageBuffer, size_t outputImageBufferSize) const
468{
469 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
472 ImageBackendAccessor::BackendHandle(inputImage),
473 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), outputImageBuffer,
474 outputImageBufferSize, &outputImageHandle);
475 });
476
477 return ImageBackendAccessor::CreateImage(outputImageHandle);
478}
479
480inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat, peak::ipl::Interval<double> interval) const
481{
482 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
485 ImageBackendAccessor::BackendHandle(inputImage),
486 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), interval.Start(),
487 interval.End(), &outputImageHandle);
488 });
489
490 return ImageBackendAccessor::CreateImage(outputImageHandle);
491}
492
493inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat,
494 uint8_t* outputImageBuffer, size_t outputImageBufferSize, peak::ipl::Interval<double> interval) const
495{
496 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
499 ImageBackendAccessor::BackendHandle(inputImage), interval.Start(), interval.End(),
500 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), outputImageBuffer,
501 outputImageBufferSize, &outputImageHandle);
502 });
503
504 return ImageBackendAccessor::CreateImage(outputImageHandle);
505}
506
508 const Image& inputImage, const PixelFormat& outputPixelFormat, double factor, double offset) const
509{
510 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
513 ImageBackendAccessor::BackendHandle(inputImage),
514 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), factor, offset, &outputImageHandle);
515 });
516
517 return ImageBackendAccessor::CreateImage(outputImageHandle);
518}
519
520inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat,
521 uint8_t* outputImageBuffer, size_t outputImageBufferSize, double factor, double offset) const
522{
523 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
526 ImageBackendAccessor::BackendHandle(inputImage), factor, offset,
527 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), outputImageBuffer,
528 outputImageBufferSize, &outputImageHandle);
529 });
530
531 return ImageBackendAccessor::CreateImage(outputImageHandle);
532}
533
534} /* namespace ipl */
535} /* namespace peak */
peak::ipl::ConversionMode ConversionMode() const
Returns the current conversion mode.
Definition peak_ipl_image_converter.hpp:416
~ImageConverter()
Destructor for the ImageConverter instance.
Definition peak_ipl_image_converter.hpp:345
ImageConverter & operator=(const ImageConverter &other)
Copy assigment for ImageConverter instance.
Definition peak_ipl_image_converter.hpp:363
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:454
ImageConverter()
Constructor for a new ImageConverter instance.
Definition peak_ipl_image_converter.hpp:333
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:405
void SetConversionMode(peak::ipl::ConversionMode conversionMode)
Set conversion mode.
Definition peak_ipl_image_converter.hpp:428
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:436
Stores the pixel format, width and height of an image and the pointer to the image buffer.
Definition peak_ipl_image.hpp:47
Interval support and convenience class.
Definition peak_ipl_interval.hpp:38
constexpr T End() const
Get the end value (inclusive) for the interval.
Definition peak_ipl_interval.hpp:81
constexpr T Start() const
Get the start value (inclusive) for the interval.
Definition peak_ipl_interval.hpp:69
Represents a pixel format and its specific properties.
Definition peak_ipl_pixel_format.hpp:35
peak::ipl::PixelFormatName PixelFormatName() const
Returns the name of the pixel format as enum value.
Definition peak_ipl_pixel_format.hpp:125
ConversionMode
Enum holding the possible conversion modes.
Definition peak_ipl_simple_types.hpp:32
@ Fast
Fast conversion mode.
Definition peak_ipl_simple_types.hpp:33
The "peak::ipl" namespace contains the whole image processing library.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:289
#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:405
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:373
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