IDS peak IPL v1.17.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
28
29namespace peak
30{
31namespace ipl
32{
33
34class Image;
35
50class ImageConverter final
51{
52public:
60
68
80 ImageConverter(const ImageConverter& other);
81
94
103 ImageConverter(ImageConverter&& other) noexcept;
104
113 ImageConverter& operator=(ImageConverter&& other) noexcept;
114
129 ImageConverter(const peak::ipl::PixelFormat& inputPixelFormat,
130 const peak::ipl::PixelFormat& outputPixelFormat, size_t width, size_t height, size_t imageCount = 5);
131
145 void PreAllocateConversion(const peak::ipl::PixelFormat& inputPixelFormat,
146 const peak::ipl::PixelFormat& outputPixelFormat, size_t width, size_t height, size_t imageCount = 5);
147
158
168 void SetConversionMode(peak::ipl::ConversionMode conversionMode);
169
181 PEAK_IPL_NO_DISCARD std::vector<peak::ipl::PixelFormatName> SupportedOutputPixelFormatNames(
182 const peak::ipl::PixelFormat& inputPixelFormat) const;
183
197 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat) const;
198
217 Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
218 uint8_t* outputImageBuffer, size_t outputImageBufferSize) const;
219
240 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
241 double factor, double offset = 0.0) const;
242
266 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
267 uint8_t* outputImageBuffer, size_t outputImageBufferSize, double factor, double offset = 0.0) const;
268
288 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
289 peak::ipl::Interval<double> interval) const;
290
315 PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
316 uint8_t* outputImageBuffer, size_t outputImageBufferSize, peak::ipl::Interval<double> interval) const;
317
318private:
319 PEAK_IPL_IMAGE_CONVERTER_HANDLE m_backendHandle{};
320};
321
322} /* namespace ipl */
323} /* namespace peak */
324
326
327namespace peak
328{
329namespace ipl
330{
331
336
338 const peak::ipl::PixelFormat& outputPixelFormat, const size_t width, const size_t height, const size_t imageCount)
339{
341 PreAllocateConversion(inputPixelFormat, outputPixelFormat, width, height, imageCount);
342}
343
345{
346 if (m_backendHandle)
347 {
349 }
350}
351
353{
354 if (other.m_backendHandle)
355 {
357 }
358
359 m_backendHandle = other.m_backendHandle;
360}
361
363{
364 if (this != &other)
365 {
366 if (m_backendHandle)
367 {
369 }
370
371 if (other.m_backendHandle)
372 {
374 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_ImageConverter_Acquire(other.m_backendHandle); });
375 }
376 }
377
378 m_backendHandle = other.m_backendHandle;
379
380 return *this;
381}
382
384{
385 *this = std::move(other);
386}
387
389{
390 if (this != &other)
391 {
392 if (m_backendHandle != nullptr)
393 {
395 }
396
397 m_backendHandle = other.m_backendHandle;
398 other.m_backendHandle = nullptr;
399 }
400
401 return *this;
402}
403
405 const peak::ipl::PixelFormat& outputPixelFormat, const size_t width, const size_t height,
406 const size_t imageCount)
407{
410 static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()),
411 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), width, height, imageCount);
412 });
413}
414
416{
418
421 m_backendHandle, reinterpret_cast<PEAK_IPL_CONVERSION_MODE*>(&conversionMode));
422 });
423
424 return conversionMode;
425}
426
428{
431 m_backendHandle, static_cast<PEAK_IPL_CONVERSION_MODE>(conversionMode));
432 });
433}
434
435inline std::vector<PixelFormatName> ImageConverter::SupportedOutputPixelFormatNames(
436 const PixelFormat& inputPixelFormat) const
437{
438 size_t size = 0;
441 m_backendHandle, static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()), nullptr, &size);
442 });
443 std::vector<PixelFormatName> supportedOutputPixelFormats(size);
446 static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()),
447 reinterpret_cast<PEAK_IPL_PIXEL_FORMAT*>(supportedOutputPixelFormats.data()), &size);
448 });
449
450 return supportedOutputPixelFormats;
451}
452
453inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat) const
454{
455 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
458 ImageBackendAccessor::BackendHandle(inputImage),
459 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), &outputImageHandle);
460 });
461
462 return ImageBackendAccessor::CreateImage(outputImageHandle);
463}
464
465inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat,
466 uint8_t* outputImageBuffer, size_t outputImageBufferSize) const
467{
468 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
471 ImageBackendAccessor::BackendHandle(inputImage),
472 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), outputImageBuffer,
473 outputImageBufferSize, &outputImageHandle);
474 });
475
476 return ImageBackendAccessor::CreateImage(outputImageHandle);
477}
478
479inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat, peak::ipl::Interval<double> interval) const
480{
481 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
484 ImageBackendAccessor::BackendHandle(inputImage),
485 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), interval.Start(),
486 interval.End(), &outputImageHandle);
487 });
488
489 return ImageBackendAccessor::CreateImage(outputImageHandle);
490}
491
492inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat,
493 uint8_t* outputImageBuffer, size_t outputImageBufferSize, peak::ipl::Interval<double> interval) const
494{
495 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
498 ImageBackendAccessor::BackendHandle(inputImage), interval.Start(), interval.End(),
499 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), outputImageBuffer,
500 outputImageBufferSize, &outputImageHandle);
501 });
502
503 return ImageBackendAccessor::CreateImage(outputImageHandle);
504}
505
507 const Image& inputImage, const PixelFormat& outputPixelFormat, double factor, double offset) const
508{
509 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
512 ImageBackendAccessor::BackendHandle(inputImage),
513 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), factor, offset, &outputImageHandle);
514 });
515
516 return ImageBackendAccessor::CreateImage(outputImageHandle);
517}
518
519inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat,
520 uint8_t* outputImageBuffer, size_t outputImageBufferSize, double factor, double offset) const
521{
522 PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
525 ImageBackendAccessor::BackendHandle(inputImage), factor, offset,
526 static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), outputImageBuffer,
527 outputImageBufferSize, &outputImageHandle);
528 });
529
530 return ImageBackendAccessor::CreateImage(outputImageHandle);
531}
532
533} /* namespace ipl */
534} /* namespace peak */
peak::ipl::ConversionMode ConversionMode() const
Returns the current conversion mode.
Definition peak_ipl_image_converter.hpp:415
~ImageConverter()
Destructor for the ImageConverter instance.
Definition peak_ipl_image_converter.hpp:344
ImageConverter & operator=(const ImageConverter &other)
Copy assigment for ImageConverter instance.
Definition peak_ipl_image_converter.hpp:362
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:453
ImageConverter()
Constructor for a new ImageConverter instance.
Definition peak_ipl_image_converter.hpp:332
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:404
void SetConversionMode(peak::ipl::ConversionMode conversionMode)
Set conversion mode.
Definition peak_ipl_image_converter.hpp:427
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:435
Stores the pixel format, width and height of an image and the pointer to the image buffer.
Definition peak_ipl_image.hpp:46
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
Represents a pixel format and its specific properties.
Definition peak_ipl_pixel_format.hpp:34
peak::ipl::PixelFormatName PixelFormatName() const
Returns the name of the pixel format as enum value.
Definition peak_ipl_pixel_format.hpp:124
The "peak::ipl" namespace contains the whole image processing library.
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_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