IDS peak IPL v1.18.0
Loading...
Searching...
No Matches
peak_ipl_image_converter.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
12
15#include <cstdint>
16#include <utility>
17#include <vector>
18
23
24namespace peak
25{
26namespace ipl
27{
28
29class Image;
30
46class ImageConverter final
47{
48public:
56
64
76 ImageConverter(const ImageConverter& other);
77
90
99 ImageConverter(ImageConverter&& other) noexcept;
100
109 ImageConverter& operator=(ImageConverter&& other) noexcept;
110
125 ImageConverter(const peak::ipl::PixelFormat& inputPixelFormat,
126 const peak::ipl::PixelFormat& outputPixelFormat, size_t width, size_t height, size_t imageCount = 5);
127
141 void PreAllocateConversion(const peak::ipl::PixelFormat& inputPixelFormat,
142 const peak::ipl::PixelFormat& outputPixelFormat, size_t width, size_t height, size_t imageCount = 5);
143
154
164 void SetConversionMode(peak::ipl::ConversionMode conversionMode);
165
177 PEAK_IPL_NO_DISCARD std::vector<peak::ipl::PixelFormatName> SupportedOutputPixelFormatNames(
178 const peak::ipl::PixelFormat& inputPixelFormat) const;
179
193 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat) const;
194
213 Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
214 uint8_t* outputImageBuffer, size_t outputImageBufferSize) const;
215
236 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
237 double factor, double offset = 0.0) const;
238
262 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
263 uint8_t* outputImageBuffer, size_t outputImageBufferSize, double factor, double offset = 0.0) const;
264
284 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
285 peak::ipl::Interval<double> interval) const;
286
311 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
312 uint8_t* outputImageBuffer, size_t outputImageBufferSize, peak::ipl::Interval<double> interval) const;
313
314private:
315 PEAK_IPL_IMAGE_CONVERTER_HANDLE m_backendHandle{};
316};
317
318} /* namespace ipl */
319} /* namespace peak */
320
322
323namespace peak
324{
325namespace ipl
326{
327
332
334 const peak::ipl::PixelFormat& outputPixelFormat, const size_t width, const size_t height, const size_t imageCount)
335{
337 PreAllocateConversion(inputPixelFormat, outputPixelFormat, width, height, imageCount);
338}
339
341{
342 if (m_backendHandle)
343 {
345 }
346}
347
349{
350 if (other.m_backendHandle)
351 {
353 }
354
355 m_backendHandle = other.m_backendHandle;
356}
357
359{
360 if (this != &other)
361 {
362 if (m_backendHandle)
363 {
365 }
366
367 if (other.m_backendHandle)
368 {
370 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_ImageConverter_Acquire(other.m_backendHandle); });
371 }
372 }
373
374 m_backendHandle = other.m_backendHandle;
375
376 return *this;
377}
378
380{
381 *this = std::move(other);
382}
383
385{
386 if (this != &other)
387 {
388 if (m_backendHandle != nullptr)
389 {
391 }
392
393 m_backendHandle = other.m_backendHandle;
394 other.m_backendHandle = nullptr;
395 }
396
397 return *this;
398}
399
401 const peak::ipl::PixelFormat& outputPixelFormat, const size_t width, const size_t height,
402 const size_t imageCount)
403{
406 static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()),
407 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), width, height, imageCount);
408 });
409}
410
412{
414
417 m_backendHandle, reinterpret_cast<PEAK_IPL_CONVERSION_MODE*>(&conversionMode));
418 });
419
420 return conversionMode;
421}
422
424{
427 m_backendHandle, static_cast<PEAK_IPL_CONVERSION_MODE>(conversionMode));
428 });
429}
430
431inline std::vector<PixelFormatName> ImageConverter::SupportedOutputPixelFormatNames(
432 const PixelFormat& inputPixelFormat) const
433{
434 size_t size = 0;
437 m_backendHandle, static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()), nullptr, &size);
438 });
439 std::vector<PixelFormatName> supportedOutputPixelFormats(size);
442 static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()),
443 reinterpret_cast<PEAK_IPL_PIXEL_FORMAT*>(supportedOutputPixelFormats.data()), &size);
444 });
445
446 return supportedOutputPixelFormats;
447}
448
449inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat) const
450{
451 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
454 ImageBackendAccessor::BackendHandle(inputImage),
455 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), &outputImageHandle);
456 });
457
458 return ImageBackendAccessor::CreateImage(outputImageHandle);
459}
460
461inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat,
462 uint8_t* outputImageBuffer, size_t outputImageBufferSize) const
463{
464 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
467 ImageBackendAccessor::BackendHandle(inputImage),
468 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), outputImageBuffer,
469 outputImageBufferSize, &outputImageHandle);
470 });
471
472 return ImageBackendAccessor::CreateImage(outputImageHandle);
473}
474
475inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat, peak::ipl::Interval<double> interval) const
476{
477 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
480 ImageBackendAccessor::BackendHandle(inputImage),
481 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), interval.Start(),
482 interval.End(), &outputImageHandle);
483 });
484
485 return ImageBackendAccessor::CreateImage(outputImageHandle);
486}
487
488inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat,
489 uint8_t* outputImageBuffer, size_t outputImageBufferSize, peak::ipl::Interval<double> interval) const
490{
491 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
494 ImageBackendAccessor::BackendHandle(inputImage), interval.Start(), interval.End(),
495 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), outputImageBuffer,
496 outputImageBufferSize, &outputImageHandle);
497 });
498
499 return ImageBackendAccessor::CreateImage(outputImageHandle);
500}
501
503 const Image& inputImage, const PixelFormat& outputPixelFormat, double factor, double offset) const
504{
505 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
508 ImageBackendAccessor::BackendHandle(inputImage),
509 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), factor, offset, &outputImageHandle);
510 });
511
512 return ImageBackendAccessor::CreateImage(outputImageHandle);
513}
514
515inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat,
516 uint8_t* outputImageBuffer, size_t outputImageBufferSize, double factor, double offset) const
517{
518 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
521 ImageBackendAccessor::BackendHandle(inputImage), factor, offset,
522 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), outputImageBuffer,
523 outputImageBufferSize, &outputImageHandle);
524 });
525
526 return ImageBackendAccessor::CreateImage(outputImageHandle);
527}
528
529} /* namespace ipl */
530} /* namespace peak */
peak::ipl::ConversionMode ConversionMode() const
Returns the current conversion mode.
Definition peak_ipl_image_converter.hpp:411
~ImageConverter()
Destructor for the ImageConverter instance.
Definition peak_ipl_image_converter.hpp:340
ImageConverter & operator=(const ImageConverter &other)
Copy assigment for ImageConverter instance.
Definition peak_ipl_image_converter.hpp:358
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:449
ImageConverter()
Constructor for a new ImageConverter instance.
Definition peak_ipl_image_converter.hpp:328
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:400
void SetConversionMode(peak::ipl::ConversionMode conversionMode)
Set conversion mode.
Definition peak_ipl_image_converter.hpp:423
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:431
Stores the pixel format, width and height of an image and the pointer to the image buffer.
Definition peak_ipl_image.hpp:42
Interval support and convenience class.
Definition peak_ipl_interval.hpp:33
constexpr T End() const
Get the end value (inclusive) for the interval.
Definition peak_ipl_interval.hpp:76
constexpr T Start() const
Get the start value (inclusive) for the interval.
Definition peak_ipl_interval.hpp:64
Represents a pixel format and its specific properties.
Definition peak_ipl_pixel_format.hpp:30
peak::ipl::PixelFormatName PixelFormatName() const
Returns the name of the pixel format as enum value.
Definition peak_ipl_pixel_format.hpp:120
ConversionMode
Enum holding the possible conversion modes.
Definition peak_ipl_simple_types.hpp:27
@ Fast
Fast conversion mode.
Definition peak_ipl_simple_types.hpp:28
The "peak::ipl" namespace contains the whole image processing library.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:284
#define PEAK_IPL_NO_DISCARD
Definition peak_ipl_attribute_defines.h:20
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:52
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:402
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:170
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:370
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:11