IDS peak IPL  v1.3.2
peak_ipl_image.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
16 
17 #include <cstddef>
18 #include <cstdint>
19 #include <utility>
20 
21 namespace
22 {
23 class ImageBackendAccessor;
24 }
25 
29 namespace peak
30 {
31 namespace ipl
32 {
33 
37 class Image
38 {
39 public:
47  Image();
60  Image(const peak::ipl::PixelFormat& pixelFormat, size_t width, size_t height);
79  Image(
80  const peak::ipl::PixelFormat& pixelFormat, uint8_t* buffer, size_t bufferSize, size_t width, size_t height);
81  ~Image();
82  Image(const Image& other) = delete;
83  Image& operator=(const Image& other) = delete;
84  Image(Image&& other) noexcept;
85  Image& operator=(Image&& other) noexcept;
86 
96  size_t Width() const;
97 
107  size_t Height() const;
108 
122  uint8_t* PixelPointer(size_t xPos, size_t yPos) const;
123 
133  size_t ByteCount() const;
134 
145 
155  uint8_t* Data() const;
156 
169  Image ConvertTo(const peak::ipl::PixelFormat& outputPixelFormat,
171 
188  Image ConvertTo(const peak::ipl::PixelFormat& outputPixelFormat, uint8_t* outputImageBuffer,
189  size_t outputImageBufferSize,
191 
201  Image Clone() const;
202 
212  bool Empty() const;
213 
214 private:
215  friend ImageBackendAccessor;
216  explicit Image(PEAK_IPL_IMAGE_HANDLE imageHandle) noexcept;
217  PEAK_IPL_IMAGE_HANDLE m_backendHandle{};
218 };
219 
220 } /* namespace ipl */
221 } /* namespace peak */
222 
223 namespace
224 {
225 
226 // helper class to access the C-backend of the Image, which are hidden from the public interface
227 class ImageBackendAccessor
228 {
229 public:
230  static PEAK_IPL_IMAGE_HANDLE BackendHandle(const peak::ipl::Image& image)
231  {
232  return image.m_backendHandle;
233  }
234  static peak::ipl::Image CreateImage(PEAK_IPL_IMAGE_HANDLE imageHandle)
235  {
236  return peak::ipl::Image(imageHandle);
237  }
238 };
239 
240 } /* namespace */
241 
243 
244 namespace peak
245 {
246 namespace ipl
247 {
248 
249 inline Image::Image()
250 {
253  });
254 }
255 
256 inline Image::Image(const peak::ipl::PixelFormat& pixelFormat, size_t width, size_t height)
257 {
260  static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormat.PixelFormatName()), width, height, &m_backendHandle);
261  });
262 }
263 
265  const peak::ipl::PixelFormat& pixelFormat, uint8_t* buffer, size_t bufferSize, size_t width, size_t height)
266 {
269  static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormat.PixelFormatName()), buffer, bufferSize, width, height,
270  &m_backendHandle);
271  });
272 }
273 
274 inline Image::Image(PEAK_IPL_IMAGE_HANDLE imageHandle) noexcept
275  : m_backendHandle(imageHandle)
276 {}
277 
279 {
280  (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Image_Destruct(m_backendHandle);
281 }
282 
283 inline Image::Image(Image&& other) noexcept
284 {
285  *this = std::move(other);
286 }
287 
288 inline Image& Image::operator=(Image&& other) noexcept
289 {
290  if (this != &other)
291  {
292  (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Image_Destruct(m_backendHandle);
293  m_backendHandle = other.m_backendHandle;
294  other.m_backendHandle = nullptr;
295  }
296 
297  return *this;
298 }
299 
300 inline size_t Image::Width() const
301 {
302  size_t width = 0;
303 
304  ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Image_GetWidth(m_backendHandle, &width); });
305 
306  return width;
307 }
308 
309 inline size_t Image::Height() const
310 {
311  size_t height = 0;
312 
313  ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Image_GetHeight(m_backendHandle, &height); });
314 
315  return height;
316 }
317 
318 inline uint8_t* Image::PixelPointer(size_t xPos, size_t yPos) const
319 {
320  uint8_t* pixelPosition = nullptr;
321 
323  return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Image_GetPixelPointer(m_backendHandle, xPos, yPos, &pixelPosition);
324  });
325 
326  return pixelPosition;
327 }
328 
329 inline size_t Image::ByteCount() const
330 {
331  size_t byteCount = 0;
332 
334  [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Image_GetByteCount(m_backendHandle, &byteCount); });
335 
336  return byteCount;
337 }
338 
340 {
342 
345  m_backendHandle, reinterpret_cast<PEAK_IPL_PIXEL_FORMAT*>(&pixelFormatName));
346  });
347 
348  return peak::ipl::PixelFormat{ pixelFormatName };
349 }
350 
351 inline uint8_t* Image::Data() const
352 {
353  uint8_t* data = nullptr;
354 
355  ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Image_GetData(m_backendHandle, &data); });
356 
357  return data;
358 }
359 
361  const peak::ipl::PixelFormat& outputPixelFormat, peak::ipl::ConversionMode conversionMode) const
362 {
363  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
365  return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Image_ConvertTo(m_backendHandle,
366  static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()),
367  static_cast<PEAK_IPL_CONVERSION_MODE>(conversionMode), &outputImageHandle);
368  });
369 
370  return ImageBackendAccessor::CreateImage(outputImageHandle);
371 }
372 
373 inline Image Image::ConvertTo(const peak::ipl::PixelFormat& outputPixelFormat, uint8_t* outputImageBuffer,
374  size_t outputImageBufferSize, peak::ipl::ConversionMode conversionMode) const
375 {
376  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
379  static_cast<PEAK_IPL_PIXEL_FORMAT>(outputPixelFormat.PixelFormatName()), outputImageBuffer,
380  outputImageBufferSize, static_cast<PEAK_IPL_CONVERSION_MODE>(conversionMode), &outputImageHandle);
381  });
382 
383  return ImageBackendAccessor::CreateImage(outputImageHandle);
384 }
385 
386 inline Image Image::Clone() const
387 {
388  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
390  [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Image_Clone(m_backendHandle, &outputImageHandle); });
391 
392  return ImageBackendAccessor::CreateImage(outputImageHandle);
393 }
394 
395 inline bool Image::Empty() const
396 {
397  return (m_backendHandle == nullptr) || (PixelFormat().PixelFormatName() == PixelFormatName::Invalid);
398 }
399 
400 } /* namespace ipl */
401 } /* namespace peak */
PEAK_IPL_C_API PEAK_IPL_Image_GetData(PEAK_IPL_IMAGE_HANDLE imageHandle, uint8_t **data)
Queries the data pointer of the given image.
PEAK_IPL_C_API PEAK_IPL_Image_GetPixelFormat(PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_PIXEL_FORMAT *pixelFormat)
Queries the pixel format of the given image.
PEAK_IPL_C_API PEAK_IPL_Image_ConvertToBuffer(PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_PIXEL_FORMAT outputPixelFormat, uint8_t *outputImageBuffer, size_t outputImageBufferSize, PEAK_IPL_CONVERSION_MODE conversionMode, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Stores the data of the current image converted to the given pixel format into a destination buffer an...
#define PEAK_IPL_C_ABI_PREFIX
Definition: peak_ipl_dll_defines.h:16
Image()
Creates an empty image, i.e. with size 0x0 and invalid pixel format.
Definition: peak_ipl_image.hpp:249
Image ConvertTo(const peak::ipl::PixelFormat &outputPixelFormat, peak::ipl::ConversionMode conversionMode=peak::ipl::ConversionMode::Fast) const
Returns a new created image containing the data of the current image converted to the given pixel for...
Definition: peak_ipl_image.hpp:360
PixelFormatName
Enum holding the possible pixel format names.
Definition: peak_ipl_simple_types.hpp:38
size_t ByteCount() const
Returns the size of the given image in number of bytes.
Definition: peak_ipl_image.hpp:329
PEAK_IPL_C_API PEAK_IPL_Image_Clone(PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Returns a new created image containing the data of the current image as deep copy.
The "peak::ipl" namespace contains the whole image processing library.
Definition: peak_ipl_color_corrector.hpp:30
Definition: peak_ipl_backend.h:55
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
PEAK_IPL_C_API PEAK_IPL_Image_GetHeight(PEAK_IPL_IMAGE_HANDLE imageHandle, size_t *height)
Queries the height of the given image.
ConversionMode
Enum holding the possible conversion modes.
Definition: peak_ipl_simple_types.hpp:28
size_t Height() const
Returns the height.
Definition: peak_ipl_image.hpp:309
PEAK_IPL_C_API PEAK_IPL_Image_GetPixelPointer(PEAK_IPL_IMAGE_HANDLE imageHandle, size_t xPos, size_t yPos, uint8_t **pixelPointer)
Queries the pointer to the given pixel position.
struct PEAK_IPL_IMAGE * PEAK_IPL_IMAGE_HANDLE
Definition: peak_ipl_backend.h:227
PEAK_IPL_C_API PEAK_IPL_Image_ConvertTo(PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_PIXEL_FORMAT outputPixelFormat, PEAK_IPL_CONVERSION_MODE conversionMode, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Creates a new image containing the data of the current image converted to the given pixel format...
~Image()
Definition: peak_ipl_image.hpp:278
Image Clone() const
Returns a new created image containing the data of the current image as deep copy.
Definition: peak_ipl_image.hpp:386
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_Image_ConstructFromBuffer(PEAK_IPL_PIXEL_FORMAT pixelFormat, uint8_t *buffer, uint64_t bufferSize, size_t width, size_t height, PEAK_IPL_IMAGE_HANDLE *imageHandle)
Creates an image from a given buffer.
PEAK_IPL_C_API PEAK_IPL_Image_GetWidth(PEAK_IPL_IMAGE_HANDLE imageHandle, size_t *width)
Queries the width of the given image.
uint8_t * Data() const
Returns the pointer to the first pixel position in dependency on the size of the pixel format...
Definition: peak_ipl_image.hpp:351
PEAK_IPL_C_API PEAK_IPL_Image_GetByteCount(PEAK_IPL_IMAGE_HANDLE imageHandle, size_t *byteCount)
Queries the size of the given image in number of bytes.
size_t Width() const
Returns the width.
Definition: peak_ipl_image.hpp:300
uint8_t * PixelPointer(size_t xPos, size_t yPos) const
Returns the pixel pointer to the given pixel position in dependency of the size of the pixel format...
Definition: peak_ipl_image.hpp:318
bool Empty() const
Checks whether the image is empty.
Definition: peak_ipl_image.hpp:395
Represents a pixel format and its specific properties.
Definition: peak_ipl_pixel_format.hpp:31
PEAK_IPL_C_API PEAK_IPL_Image_Construct(PEAK_IPL_PIXEL_FORMAT pixelFormat, size_t width, size_t height, PEAK_IPL_IMAGE_HANDLE *imageHandle)
Creates an image.
peak::ipl::PixelFormat PixelFormat() const
Returns the pixel format.
Definition: peak_ipl_image.hpp:339
PEAK_IPL_C_API PEAK_IPL_Image_Destruct(PEAK_IPL_IMAGE_HANDLE imageHandle)
Destroys the image associated with the given handle.
Image & operator=(const Image &other)=delete