IDSpeakIPL  v1.8.0
peak_ipl_image_converter.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
17 
18 #include <cstdint>
19 #include <utility>
20 #include <vector>
21 
25 namespace peak
26 {
27 namespace ipl
28 {
29 
30 class Image;
31 
46 class ImageConverter final
47 {
48 public:
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 
192  PEAK_IPL_NO_DISCARD Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat) const;
193 
209  Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
210  uint8_t* outputImageBuffer, size_t outputImageBufferSize) const;
211 
212 private:
213  PEAK_IPL_IMAGE_CONVERTER_HANDLE m_backendHandle{};
214 };
215 
216 } /* namespace ipl */
217 } /* namespace peak */
218 
220 
221 namespace peak
222 {
223 namespace ipl
224 {
225 
227 {
229 }
230 
232  const peak::ipl::PixelFormat& outputPixelFormat, const size_t width, const size_t height, const size_t imageCount)
233 {
235  PreAllocateConversion(inputPixelFormat, outputPixelFormat, width, height, imageCount);
236 }
237 
239 {
240  if (m_backendHandle)
241  {
243  }
244 }
245 
247 {
248  if (other.m_backendHandle)
249  {
251  }
252 
253  m_backendHandle = other.m_backendHandle;
254 }
255 
257 {
258  if (this != &other)
259  {
260  if (m_backendHandle)
261  {
263  }
264 
265  if (other.m_backendHandle)
266  {
268  [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_ImageConverter_Acquire(other.m_backendHandle); });
269  }
270  }
271 
272  m_backendHandle = other.m_backendHandle;
273 
274  return *this;
275 }
276 
278 {
279  *this = std::move(other);
280 }
281 
283 {
284  if (this != &other)
285  {
287  m_backendHandle = other.m_backendHandle;
288  other.m_backendHandle = nullptr;
289  }
290 
291  return *this;
292 }
293 
295  const peak::ipl::PixelFormat& outputPixelFormat, const size_t width, const size_t height,
296  const size_t imageCount)
297 {
300  static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()),
301  static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), width, height, imageCount);
302  });
303 }
304 
306 {
308 
311  m_backendHandle, reinterpret_cast<PEAK_IPL_CONVERSION_MODE*>(&conversionMode));
312  });
313 
314  return conversionMode;
315 }
316 
318 {
321  m_backendHandle, static_cast<PEAK_IPL_CONVERSION_MODE>(conversionMode));
322  });
323 }
324 
325 inline std::vector<PixelFormatName> ImageConverter::SupportedOutputPixelFormatNames(
326  const PixelFormat& inputPixelFormat) const
327 {
328  size_t size = 0;
331  m_backendHandle, static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()), nullptr, &size);
332  });
333  std::vector<PixelFormatName> supportedOutputPixelFormats(size);
336  static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()),
337  reinterpret_cast<PEAK_IPL_PIXEL_FORMAT*>(supportedOutputPixelFormats.data()), &size);
338  });
339 
340  return supportedOutputPixelFormats;
341 }
342 
343 inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat) const
344 {
345  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
348  ImageBackendAccessor::BackendHandle(inputImage),
349  static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), &outputImageHandle);
350  });
351 
352  return ImageBackendAccessor::CreateImage(outputImageHandle);
353 }
354 
355 inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat,
356  uint8_t* outputImageBuffer, size_t outputImageBufferSize) const
357 {
358  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
361  ImageBackendAccessor::BackendHandle(inputImage),
362  static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), outputImageBuffer,
363  outputImageBufferSize, &outputImageHandle);
364  });
365 
366  return ImageBackendAccessor::CreateImage(outputImageHandle);
367 }
368 
369 } /* namespace ipl */
370 } /* namespace peak */
#define PEAK_IPL_NO_DISCARD
Definition: peak_ipl_backend.h:26
#define PEAK_IPL_C_ABI_PREFIX
Definition: peak_ipl_dll_defines.h:16
ImageConverter()
Constructor for a new ImageConverter instance.
Definition: peak_ipl_image_converter.hpp:226
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_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...
The "peak::ipl" namespace contains the whole image processing library.
Definition: peak_ipl_binning.hpp:22
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition: peak_ipl_exception.hpp:182
Stores the pixel format, width and height of an image and the pointer to the image buffer...
Definition: peak_ipl_image.hpp:39
void SetConversionMode(peak::ipl::ConversionMode conversionMode)
Set conversion mode.
Definition: peak_ipl_image_converter.hpp:317
ConversionMode
Enum holding the possible conversion modes.
Definition: peak_ipl_simple_types.hpp:28
struct PEAK_IPL_IMAGE_CONVERTER * PEAK_IPL_IMAGE_CONVERTER_HANDLE
Definition: peak_ipl_backend.h:322
PEAK_IPL_NO_DISCARD peak::ipl::PixelFormatName PixelFormatName() const
Returns the name of the pixel format as enum value.
Definition: peak_ipl_pixel_format.hpp:122
struct PEAK_IPL_IMAGE * PEAK_IPL_IMAGE_HANDLE
Definition: peak_ipl_backend.h:354
PEAK_IPL_NO_DISCARD Image Convert(const Image &inputImage, const peak::ipl::PixelFormat &outputPixelFormat) const
Converts the input image converted to the given pixel format.
Definition: peak_ipl_image_converter.hpp:343
PEAK_IPL_C_API PEAK_IPL_ImageConverter_Construct(PEAK_IPL_IMAGE_CONVERTER_HANDLE *imageConverterHandle)
Creates an image converter.
Fast conversion mode.
PEAK_IPL_C_API PEAK_IPL_ImageConverter_GetConversionMode(PEAK_IPL_IMAGE_CONVERTER_HANDLE imageConverterHandle, PEAK_IPL_CONVERSION_MODE *conversionMode)
Queries the given image converter&#39;s current conversion mode.
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:294
PEAK_IPL_NO_DISCARD peak::ipl::ConversionMode ConversionMode() const
Returns the current conversion mode.
Definition: peak_ipl_image_converter.hpp:305
PEAK_IPL_C_API PEAK_IPL_ImageConverter_Destruct(PEAK_IPL_IMAGE_CONVERTER_HANDLE imageConverterHandle)
Destroys the image converter associated with the given handle.
PEAK_IPL_C_API PEAK_IPL_ImageConverter_Acquire(PEAK_IPL_IMAGE_CONVERTER_HANDLE imageConverterHandle)
Increase the reference count of an image converter.
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.
ImageConverter & operator=(const ImageConverter &other)
Copy assigment for ImageConverter instance.
Definition: peak_ipl_image_converter.hpp:256
Converts images from one PixelFormat to another.
Definition: peak_ipl_image_converter.hpp:46
PEAK_IPL_C_API PEAK_IPL_ImageConverter_SetConversionMode(PEAK_IPL_IMAGE_CONVERTER_HANDLE imageConverterHandle, PEAK_IPL_CONVERSION_MODE conversionMode)
Sets the given image converter&#39;s conversion mode.
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.
Represents a pixel format and its specific properties.
Definition: peak_ipl_pixel_format.hpp:31
PEAK_IPL_NO_DISCARD 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:325
~ImageConverter()
Destructor for the ImageConverter instance.
Definition: peak_ipl_image_converter.hpp:238