IDS peak IPL  v1.7.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:
51  ImageConverter(const ImageConverter& other) = delete;
52  ImageConverter& operator=(const ImageConverter& other) = delete;
53  ImageConverter(ImageConverter&& other) noexcept;
54  ImageConverter& operator=(ImageConverter&& other) noexcept;
55 
70  ImageConverter(const peak::ipl::PixelFormat& inputPixelFormat,
71  const peak::ipl::PixelFormat& outputPixelFormat, size_t width, size_t height, size_t imageCount = 5);
72 
86  void PreAllocateConversion(const peak::ipl::PixelFormat& inputPixelFormat,
87  const peak::ipl::PixelFormat& outputPixelFormat, size_t width, size_t height, size_t imageCount = 5);
88 
99 
109  void SetConversionMode(peak::ipl::ConversionMode conversionMode);
110 
122  std::vector<peak::ipl::PixelFormatName> SupportedOutputPixelFormatNames(
123  const peak::ipl::PixelFormat& inputPixelFormat) const;
124 
137  Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat) const;
138 
154  Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
155  uint8_t* outputImageBuffer, size_t outputImageBufferSize) const;
156 
157 private:
158  PEAK_IPL_IMAGE_CONVERTER_HANDLE m_backendHandle{};
159 };
160 
161 } /* namespace ipl */
162 } /* namespace peak */
163 
165 
166 namespace peak
167 {
168 namespace ipl
169 {
170 
172 {
174 }
175 
177  const peak::ipl::PixelFormat& outputPixelFormat, const size_t width, const size_t height, const size_t imageCount)
178 {
180  PreAllocateConversion(inputPixelFormat, outputPixelFormat, width, height, imageCount);
181 }
182 
184 {
185  if (m_backendHandle)
186  {
188  }
189 }
190 
192 {
193  *this = std::move(other);
194 }
195 
197 {
198  if (this != &other)
199  {
201  m_backendHandle = other.m_backendHandle;
202  other.m_backendHandle = nullptr;
203  }
204 
205  return *this;
206 }
207 
209  const peak::ipl::PixelFormat& outputPixelFormat, const size_t width, const size_t height,
210  const size_t imageCount)
211 {
214  static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()),
215  static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), width, height, imageCount);
216  });
217 }
218 
220 {
222 
225  m_backendHandle, reinterpret_cast<PEAK_IPL_CONVERSION_MODE*>(&conversionMode));
226  });
227 
228  return conversionMode;
229 }
230 
232 {
235  m_backendHandle, static_cast<PEAK_IPL_CONVERSION_MODE>(conversionMode));
236  });
237 }
238 
239 inline std::vector<PixelFormatName> ImageConverter::SupportedOutputPixelFormatNames(
240  const PixelFormat& inputPixelFormat) const
241 {
242  size_t size = 0;
245  m_backendHandle, static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()), nullptr, &size);
246  });
247  std::vector<PixelFormatName> supportedOutputPixelFormats(size);
250  static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()),
251  reinterpret_cast<PEAK_IPL_PIXEL_FORMAT*>(supportedOutputPixelFormats.data()), &size);
252  });
253 
254  return supportedOutputPixelFormats;
255 }
256 
257 inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat) const
258 {
259  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
262  ImageBackendAccessor::BackendHandle(inputImage),
263  static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), &outputImageHandle);
264  });
265 
266  return ImageBackendAccessor::CreateImage(outputImageHandle);
267 }
268 
269 inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat,
270  uint8_t* outputImageBuffer, size_t outputImageBufferSize) const
271 {
272  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
275  ImageBackendAccessor::BackendHandle(inputImage),
276  static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), outputImageBuffer,
277  outputImageBufferSize, &outputImageHandle);
278  });
279 
280  return ImageBackendAccessor::CreateImage(outputImageHandle);
281 }
282 
283 } /* namespace ipl */
284 } /* namespace peak */
#define PEAK_IPL_C_ABI_PREFIX
Definition: peak_ipl_dll_defines.h:16
ImageConverter()
Definition: peak_ipl_image_converter.hpp:171
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:231
ConversionMode
Enum holding the possible conversion modes.
Definition: peak_ipl_simple_types.hpp:28
ImageConverter & operator=(const ImageConverter &other)=delete
struct PEAK_IPL_IMAGE_CONVERTER * PEAK_IPL_IMAGE_CONVERTER_HANDLE
Definition: peak_ipl_backend.h:294
struct PEAK_IPL_IMAGE * PEAK_IPL_IMAGE_HANDLE
Definition: peak_ipl_backend.h:326
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:257
PEAK_IPL_C_API PEAK_IPL_ImageConverter_Construct(PEAK_IPL_IMAGE_CONVERTER_HANDLE *imageConverterHandle)
Creates an image converter.
peak::ipl::PixelFormatName PixelFormatName() const
Returns the name of the pixel format as enum value.
Definition: peak_ipl_pixel_format.hpp:67
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:208
peak::ipl::ConversionMode ConversionMode() const
Returns the current conversion mode.
Definition: peak_ipl_image_converter.hpp:219
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_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.
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
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:239
~ImageConverter()
Definition: peak_ipl_image_converter.hpp:183