IDS peak IPL  v1.4.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 {
186 }
187 
189 {
190  *this = std::move(other);
191 }
192 
194 {
195  if (this != &other)
196  {
198  m_backendHandle = other.m_backendHandle;
199  other.m_backendHandle = nullptr;
200  }
201 
202  return *this;
203 }
204 
206  const peak::ipl::PixelFormat& outputPixelFormat, const size_t width, const size_t height,
207  const size_t imageCount)
208 {
211  static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()),
212  static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), width, height, imageCount);
213  });
214 }
215 
217 {
219 
222  m_backendHandle, reinterpret_cast<PEAK_IPL_CONVERSION_MODE*>(&conversionMode));
223  });
224 
225  return conversionMode;
226 }
227 
229 {
232  m_backendHandle, static_cast<PEAK_IPL_CONVERSION_MODE>(conversionMode));
233  });
234 }
235 
236 inline std::vector<PixelFormatName> ImageConverter::SupportedOutputPixelFormatNames(
237  const PixelFormat& inputPixelFormat) const
238 {
239  size_t size = 0;
242  m_backendHandle, static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()), nullptr, &size);
243  });
244  std::vector<PixelFormatName> supportedOutputPixelFormats(size);
247  static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()),
248  reinterpret_cast<PEAK_IPL_PIXEL_FORMAT*>(supportedOutputPixelFormats.data()), &size);
249  });
250 
251  return supportedOutputPixelFormats;
252 }
253 
254 inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat) const
255 {
256  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
259  ImageBackendAccessor::BackendHandle(inputImage),
260  static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), &outputImageHandle);
261  });
262 
263  return ImageBackendAccessor::CreateImage(outputImageHandle);
264 }
265 
266 inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat,
267  uint8_t* outputImageBuffer, size_t outputImageBufferSize) const
268 {
269  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
272  ImageBackendAccessor::BackendHandle(inputImage),
273  static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), outputImageBuffer,
274  outputImageBufferSize, &outputImageHandle);
275  });
276 
277  return ImageBackendAccessor::CreateImage(outputImageHandle);
278 }
279 
280 } /* namespace ipl */
281 } /* 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:16
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition: peak_ipl_exception.hpp:128
Stores the pixel format, width and height of an image and the pointer to the image buffer...
Definition: peak_ipl_image.hpp:37
void SetConversionMode(peak::ipl::ConversionMode conversionMode)
Set conversion mode.
Definition: peak_ipl_image_converter.hpp:228
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:210
struct PEAK_IPL_IMAGE * PEAK_IPL_IMAGE_HANDLE
Definition: peak_ipl_backend.h:238
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:254
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:205
peak::ipl::ConversionMode ConversionMode() const
Returns the current conversion mode.
Definition: peak_ipl_image_converter.hpp:216
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:236
~ImageConverter()
Definition: peak_ipl_image_converter.hpp:183