IDS peak IPL  v1.3.2
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 
39 class ImageConverter final
40 {
41 public:
44  ImageConverter(const ImageConverter& other) = delete;
45  ImageConverter& operator=(const ImageConverter& other) = delete;
46  ImageConverter(ImageConverter&& other) noexcept;
47  ImageConverter& operator=(ImageConverter&& other) noexcept;
48 
59 
69  void SetConversionMode(peak::ipl::ConversionMode conversionMode);
70 
82  std::vector<peak::ipl::PixelFormatName> SupportedOutputPixelFormatNames(
83  const peak::ipl::PixelFormat& inputPixelFormat) const;
84 
97  Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat) const;
98 
114  Image Convert(const Image& inputImage, const peak::ipl::PixelFormat& outputPixelFormat,
115  uint8_t* outputImageBuffer, size_t outputImageBufferSize) const;
116 
117 private:
118  PEAK_IPL_IMAGE_CONVERTER_HANDLE m_backendHandle{};
119 };
120 
121 } /* namespace ipl */
122 } /* namespace peak */
123 
125 
126 namespace peak
127 {
128 namespace ipl
129 {
130 
132 {
134 }
135 
137 {
139 }
140 
142 {
143  *this = std::move(other);
144 }
145 
147 {
148  if (this != &other)
149  {
151  m_backendHandle = other.m_backendHandle;
152  other.m_backendHandle = nullptr;
153  }
154 
155  return *this;
156 }
157 
159 {
161 
164  m_backendHandle, reinterpret_cast<PEAK_IPL_CONVERSION_MODE*>(&conversionMode));
165  });
166 
167  return conversionMode;
168 }
169 
171 {
174  m_backendHandle, static_cast<PEAK_IPL_CONVERSION_MODE>(conversionMode));
175  });
176 }
177 
178 inline std::vector<PixelFormatName> ImageConverter::SupportedOutputPixelFormatNames(
179  const PixelFormat& inputPixelFormat) const
180 {
181  size_t size = 0;
184  m_backendHandle, static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()), nullptr, &size);
185  });
186  std::vector<PixelFormatName> supportedOutputPixelFormats(size);
189  static_cast<PEAK_IPL_PIXEL_FORMAT>(inputPixelFormat.PixelFormatName()),
190  reinterpret_cast<PEAK_IPL_PIXEL_FORMAT*>(supportedOutputPixelFormats.data()), &size);
191  });
192 
193  return supportedOutputPixelFormats;
194 }
195 
196 inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat) const
197 {
198  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
201  ImageBackendAccessor::BackendHandle(inputImage),
202  static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), &outputImageHandle);
203  });
204 
205  return ImageBackendAccessor::CreateImage(outputImageHandle);
206 }
207 
208 inline Image ImageConverter::Convert(const Image& inputImage, const PixelFormat& outputPixelFormat,
209  uint8_t* outputImageBuffer, size_t outputImageBufferSize) const
210 {
211  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
214  ImageBackendAccessor::BackendHandle(inputImage),
215  static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), outputImageBuffer,
216  outputImageBufferSize, &outputImageHandle);
217  });
218 
219  return ImageBackendAccessor::CreateImage(outputImageHandle);
220 }
221 
222 } /* namespace ipl */
223 } /* namespace peak */
#define PEAK_IPL_C_ABI_PREFIX
Definition: peak_ipl_dll_defines.h:16
ImageConverter()
Definition: peak_ipl_image_converter.hpp:131
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_color_corrector.hpp:30
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:170
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:203
struct PEAK_IPL_IMAGE * PEAK_IPL_IMAGE_HANDLE
Definition: peak_ipl_backend.h:227
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:196
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.
peak::ipl::ConversionMode ConversionMode() const
Returns the current conversion mode.
Definition: peak_ipl_image_converter.hpp:158
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:39
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.
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:178
~ImageConverter()
Definition: peak_ipl_image_converter.hpp:136