IDS peak ICV v1.0.0
Loading...
Searching...
No Matches
peak_icv_image.hpp
Go to the documentation of this file.
1
11#pragma once
12
13
19#include <memory>
20
21#if WITH_peak_ipl
22# include <peak_ipl/types/peak_ipl_image.hpp>
23#endif
24
26
27struct peak_icv_image_info;
28struct peak_icv_image;
29using peak_icv_image_handle = peak_icv_image*;
30
31namespace peak
32{
33namespace icv
34{
35
36class ImageWriter;
37
45class Image : private detail::IBackendAccessible<Image>
46{
47public:
48#if WITH_peak_ipl
58 Image(const peak::ipl::Image& image); // NOLINT
59#endif
60
69 explicit Image(const peak::common::IImageView& imageView);
70
127 explicit Image(const std::string& path);
128
194 explicit Image(const std::string& path, peak::common::PixelFormat name);
195
206 Image(peak::common::PixelFormat pixelFormat, uint8_t* buffer, size_t bufferSize, const peak::common::Size& imageSize);
207
216 Image(peak::common::PixelFormat pixelFormat, const peak::common::Size& imageSize);
217
223 Image(const Image& other);
224
230 Image(Image&& other) noexcept;
231
237 Image& operator=(const Image& other);
238
244 Image& operator=(Image&& other) noexcept;
245
251 ~Image() override;
252
258 bool operator==(const Image& rhs) const;
259
267 PEAK_ICV_NO_DISCARD Image Copy() const;
268
276 PEAK_ICV_NO_DISCARD peak::common::Size GetSize() const;
277
285 PEAK_ICV_NO_DISCARD uint8_t* GetData() const;
286
294 PEAK_ICV_NO_DISCARD size_t GetSizeInBytes() const;
295
306 PEAK_ICV_NO_DISCARD size_t GetBytesPerLine() const;
307
308
316 PEAK_ICV_NO_DISCARD peak::common::PixelFormat GetPixelFormat() const;
317
325 PEAK_ICV_NO_DISCARD experimental::Region GetRegion() const;
326
338 void SetRegion(const experimental::Region& region) const;
339
345 void ResetRegion() const;
346
357 template <typename DataType>
358 PEAK_ICV_NO_DISCARD DataType* At(size_t x, size_t y) const
359 {
360 return reinterpret_cast<DataType*>(m_buffer + (x + y * m_size.GetWidth()) * m_pixelFormatInfo.GetAllocatedBitsPerPixel() / 8);
361 }
362
383 PEAK_ICV_NO_DISCARD peak::icv::Image ConvertPixelFormat(peak::common::PixelFormat pixelFormat) const;
384
385
393 void SetMetadata(const peak::common::Metadata& metadata);
394
402 PEAK_ICV_NO_DISCARD peak::common::Metadata GetMetadata() const;
403
417 PEAK_ICV_NO_DISCARD Image Subtract(const Image& subtrahend) const;
418
432 PEAK_ICV_NO_DISCARD Image operator-(const Image& subtrahend) const;
433
443 PEAK_ICV_NO_DISCARD Image Crop(const peak::common::Rectangle& rect) const;
444
464 PEAK_ICV_NO_DISCARD Image Scale(
465 const peak::common::Size& targetImageSize, const Interpolation& interpolation = Interpolation::NearestNeighbor) const;
466
467#if WITH_peak_ipl
475 operator peak::ipl::Image() const; // NOLINT
476#endif
477
478protected:
486 PEAK_ICV_NO_DISCARD detail::handle_of_t<Image> GetHandle() const override;
487
488private:
489 friend peak::common::detail::BackendAccessor<Image>;
490 friend ImageWriter;
491
492 explicit Image(peak_icv_image_handle imageHandle);
493 Image(peak_icv_image_handle handle, peak_icv_image_info info);
494
495 static peak::common::Metadata AddCaptureInformationDataToMetadata(
496 peak_icv_capture_information captureInformationC, peak::common::Metadata metadata);
497
498 static peak_icv_image_handle CreateFromFile(const std::string& path);
499 static peak_icv_image_handle CreateFromFile(const std::string& path, peak::common::PixelFormat name);
500 static peak_icv_image_info CreateFromHandle(peak_icv_image_handle handle);
501 static peak_icv_image_handle CreateFromSize(peak::common::PixelFormat pixelFormat, const peak::common::Size& size);
502 static peak_icv_image_handle CreateFromBuffer(
503 peak::common::PixelFormat pixelFormat, const peak::common::Size& size, const uint8_t* buffer, size_t bufferSize);
504
505#if WITH_peak_ipl
506 PEAK_ICV_NO_DISCARD peak::ipl::Image GetIPLImage() const;
507#endif
508
509 peak_icv_image_handle m_imageHandle{};
510 peak::common::Size m_size;
511 uint8_t* m_buffer;
512 peak::common::PixelFormatInfo m_pixelFormatInfo;
513 mutable std::unique_ptr<peak::common::Metadata> m_metaData; // mutable because we cache it in getter function
514
515#if WITH_peak_ipl
516 peak::ipl::Image m_image;
517#endif
518};
519} /* namespace icv */
520} /* namespace peak */
521
Interface for viewing image pixel data from arbitrary sources.
Type-safe container for image acquisition metadata.
Provides information and utility functions for pixel formats.
size_t GetAllocatedBitsPerPixel() const
Returns the number of allocated bits per pixel.
A generic rectangle defined by a point and a size.
Represents a two-dimensional size with non-negative width and height.
constexpr T GetWidth() const
Returns the width.
For detailed information about the use of ids_peak_icv Image refer to the Image Guide.
void SetRegion(const experimental::Region &region) const
Updates the region on the image.
peak::common::Size GetSize() const
Provides the size of the image.
void ResetRegion() const
Resets the region on the image to the complete image.
Image operator-(const Image &subtrahend) const
Subtracts the specified subtrahend image pixelwise from the current image and returns the resulting i...
Image & operator=(const Image &other)
experimental::Region GetRegion() const
Provides the region of the image.
uint8_t * GetData() const
Provides a pointer to the image data buffer.
Image Subtract(const Image &subtrahend) const
Subtracts the specified subtrahend image pixelwise from the current image and returns the resulting i...
Image(const peak::common::IImageView &imageView)
Constructs an Image from an IImageView Instance. This can be a buffer or a possibility to convert oth...
peak::common::PixelFormat GetPixelFormat() const
Provides the pixel format of the image.
Image Crop(const peak::common::Rectangle &rect) const
Crops the image to the given rectangle.
peak::common::Metadata GetMetadata() const
Returns the CaptureInformation of an image which contains information about the image capture setting...
peak::icv::Image ConvertPixelFormat(peak::common::PixelFormat pixelFormat) const
Converts the image to a different pixel format.
void SetMetadata(const peak::common::Metadata &metadata)
Updates the CaptureInformation of an image which is used to store and manage capture settings.
Image Copy() const
Creates a deep copy of the current Image.
Image Scale(const peak::common::Size &targetImageSize, const Interpolation &interpolation=Interpolation::NearestNeighbor) const
Returns an image scaled to the given image size.
size_t GetSizeInBytes() const
Provides the size of the image data in bytes.
bool operator==(const Image &rhs) const
DataType * At(size_t x, size_t y) const
Provides a pointer to the data at the specified coordinates.
size_t GetBytesPerLine() const
Computes the number of bytes required to store one line of pixel data (no padding).
Writes an image to a file.
A region consists of a set of points in the image plane.
PixelFormat
Enum listing all supported pixel formats and their internal IDs.
Interpolation
Interpolation method for image transformations.
peak::common::detail::c_type_of_t< Type > * handle_of_t
Enum holding the possible pixel format names.
peak_icv_image * peak_icv_image_handle