12#include <system_error>
15#include "../_cexports/c_img.h"
16#include "../_cexports/c_pixfmtcnv.h"
18#include "../global.hpp"
20#include "../affine_matrix_2d.hpp"
21#include "../area_2d.hpp"
22#include "../data_type.hpp"
23#include "../pfnc_format.hpp"
25#include "../string.hpp"
27#include "../utilities/system_info.hpp"
37 inline HandleGuard<Image>::HandleGuard(
void *handle) noexcept
38 : HandleGuard<Image>(handle, [](
void *handle) { CVB_CALL_CAPI(
ReleaseObject(handle)); })
52 using GuardType = HandleGuard<Image>;
95 template <
class RANGE>
99 auto rangeAdapter = MakeRangeAdapter<ImagePtr>(images);
101 handles.reserve(rangeAdapter.Size());
102 for (
const auto &image : images)
103 handles.emplace_back(image->Handle());
104 return FromImageHandles(mapping, handles);
114 template <
class... IMAGES>
115 static typename VarArgRange<std::unique_ptr<Image>,
const Image &, IMAGES...>::type
118 std::array<
void *,
sizeof...(IMAGES)> handles = {images.Handle()...};
119 return FromImageHandles(mapping, handles);
129 template <
class RANGE>
131 const RANGE &planes);
143 template <
class... PLANES>
144 static typename VarArgRange<std::unique_ptr<Image>,
ImagePlane &&, PLANES...>::type
174 template <
class T,
class... ARGS>
206 :
Image(std::move(*
Create(width, height, numPlanes, dataType)))
221 Image &operator=(
const Image &other) =
delete;
223 virtual ~Image() =
default;
234 return handle_.Handle();
244 return static_cast<int>(CExports::ImageDimension(
Handle()));
260 static_cast<int>(CExports::ImageDatatype(
Handle(),
static_cast<CExports::cvbdim_t
>(i))))
296 return static_cast<int>(CExports::ImageHeight(
Handle()));
306 return static_cast<int>(CExports::ImageWidth(
Handle()));
337 void Save(
const String &fileName,
double quality)
const;
400 sourceRect.
Right(), sourceRect.
Bottom(), targetPosition.
X(),
401 targetPosition.
Y())))
402 Utilities::SystemInfo::ThrowLastError();
456 pixelContentChangedCarrierContainer_.Call<void(
const Image &,
Rect<int>)>(*
this, rect);
468 return pixelContentChangedCarrierContainer_.Register(carrier);
478 pixelContentChangedCarrierContainer_.Unregister(eventCookie);
491 CExports::ImageToPixel(
Handle(), point.X(), point.Y(), x, y);
504 CExports::ImageAreaToPixel(
Handle(), *
reinterpret_cast<CExports::TArea *
>(&area),
505 reinterpret_cast<CExports::TArea &
>(retval));
519 CExports::PixelToImage(
Handle(), point.X(), point.Y(), x, y);
532 CExports::PixelAreaToImage(
Handle(), *
reinterpret_cast<CExports::TArea *
>(&area),
533 reinterpret_cast<CExports::TArea &
>(retval));
581 return Internal::DoResCallObjectOut<Image>([&](
void *&image) {
582 return CVB_CALL_CAPI(
583 CVPFCreateImageFromPFNCValue(
static_cast<Cvb::CExports::cvbuint32_t
>(format), width, height, image));
588 explicit Image(HandleGuard<Image> &&guard) noexcept
593 void Detach() noexcept
598 void ResetHandle(
void *newHandle)
noexcept
600 handle_.Reset(newHandle);
605 : handle_(std::move(other.handle_))
606 , pixelContentChangedCarrierContainer_(std::move(other.pixelContentChangedCarrierContainer_))
610 Image &operator=(
Image &&other)
noexcept =
delete;
612 void IncreaseRefCount() const noexcept
617 template <
class RANGE>
618 static typename TypedRange<std::unique_ptr<Image>,
void *, RANGE>::type FromImageHandles(
MappingOption mapping,
621 return Internal::DoBoolCallObjectOut<Image>([&](
void *&handle) {
622 auto rangeAdapter = MakeRangeAdapter<void *>(range);
628 HandleGuard<Image> handle_;
630 mutable std::mutex handlerMutex_;
632 Internal::CarrierContainer pixelContentChangedCarrierContainer_;
Compacted affine matrix describing the Common Vision Blox coordinate system.
Definition affine_matrix_2d.hpp:17
Structure that represents an area of interest in the image.
Definition area_2d.hpp:21
Data type description for an image plane.
Definition data_type.hpp:23
static DataType Int8BppUnsigned() noexcept
Represents 8-bit unsigned integer pixels (bytes).
Definition data_type.hpp:41
static DataType FromNativeDescriptor(int dataTypeDescriptor) noexcept
Construct a data type descriptor from one of the native library's descriptor values.
Definition data_type.hpp:31
Generic CVB physical device.
Definition decl_device.hpp:39
Cookie used to unregister event handlers.
Definition global.hpp:591
The Common Vision Blox image.
Definition decl_image.hpp:45
static std::unique_ptr< Image > FromPixelFormat(int width, int height, Cvb::PfncFormat format)
Creates an image from a specified pixel format.
Definition decl_image.hpp:579
Point2D< double > ImageToPixelCoordinates(Point2D< double > point) const noexcept
Convert a point from image to pixel coordinates.
Definition decl_image.hpp:487
EventCookie RegisterEventPixelContentChanged(std::function< void(const Image &, Rect< int >)> handler)
Register a listener to the pixel content changed event.
Definition decl_image.hpp:465
void RaisePixelContentChanged() const
Inform clients listening to the pixel content changed event, that the image data has been completely ...
Definition decl_image.hpp:443
Area2D PixelToImageCoordinates(Area2D area) const noexcept
Convert an Area2D from pixel to image coordinates.
Definition decl_image.hpp:529
int Width() const noexcept
Width of the image in pixels.
Definition decl_image.hpp:304
Image(Size2D< int > size, int numPlanes=1, DataType dataType=DataType::Int8BppUnsigned())
Constructs an uninitialized image with the given parameters.
Definition decl_image.hpp:192
void Copy(Image &targetImage) const
Copies the image data from this image to the target image.
Definition decl_image.hpp:412
int Height() const noexcept
Height of the image in pixels.
Definition decl_image.hpp:294
AffineMatrix2D CoordinateSystem() const noexcept
Get the coordinate system of the image.
Definition decl_image.hpp:542
Image(const String &fileName)
Loads an image with the given file name.
Definition decl_image.hpp:215
std::unique_ptr< Image > Map(Rect< int > rect) const
Creates a mapped image of the region of this image.
Definition decl_image.hpp:347
void RaisePixelContentChanged(Rect< int > rect) const
Inform clients listening to the pixel content changed event, that the image data has been updated in ...
Definition decl_image.hpp:454
int PlanesCount() const noexcept
Get the number of planes for this image.
Definition decl_image.hpp:242
Image(int width, int height, int numPlanes=1, DataType dataType=DataType::Int8BppUnsigned())
Constructs an uninitialized image with the given parameters.
Definition decl_image.hpp:205
void Copy(Image &targetImage, Rect< int > sourceRect, Point2D< int > targetPosition) const
Copies the image data from the source rectangle of this image to the target position inside the targe...
Definition decl_image.hpp:397
static TypedRange< std::unique_ptr< Image >, ImagePlane, RANGE >::type FromPlanes(MappingOption mapping, const RANGE &planes)
Create an image that is the result of concatenating a series of input planes.
Definition detail_image.hpp:40
void UnregisterEventPixelContentChanged(EventCookie eventCookie) noexcept
Manually unregister a listener from the pixel content changed event.
Definition decl_image.hpp:476
Rect< int > Bounds() const noexcept
Bounding rectangle of the image in pixels.
Definition decl_image.hpp:433
static std::unique_ptr< Image > FromHandle(HandleGuard< Image > &&guard)
Creates an image from a classic API handle.
Definition decl_image.hpp:155
ImagePlane Plane(int plane) const
Indexed access to the individual plane information.
Definition detail_image.hpp:58
void Save(const String &fileName) const
Write the current content of the image into a file.
Definition detail_image.hpp:84
std::unique_ptr< Image > Clone() const
Creates a new image object, that is a copy of the current instance.
Definition detail_image.hpp:116
Size2D< int > Size() const noexcept
Size of the image in pixels.
Definition decl_image.hpp:423
static TypedRange< std::unique_ptr< Image >, ImagePtr, RANGE >::type FromImages(MappingOption mapping, const RANGE &images)
Create an image that is the result of concatenating a series of input images.
Definition decl_image.hpp:96
void SetCoordinateSystem(AffineMatrix2D affineMatrix) noexcept
Set the coordinate system of the image.
Definition decl_image.hpp:554
Area2D ImageToPixelCoordinates(Area2D area) const noexcept
Convert an Area2D from image to pixel coordinates.
Definition decl_image.hpp:501
std::vector< ImagePlane > Planes() const noexcept
Access all planes for this image.
Definition detail_image.hpp:65
static std::unique_ptr< Image > FromPixelFormat(const Cvb::Size2D< int > &size, Cvb::PfncFormat format)
Creates an image from a specified pixel format.
Definition decl_image.hpp:566
static std::unique_ptr< T > FromHandle(HandleGuard< Image > &&guard, ARGS &&...args)
Creates an image from a classic API handle (typed).
Definition decl_image.hpp:175
Cvb::ColorModel ColorModel() const noexcept
Color model realized by this image.
Definition decl_image.hpp:314
std::vector< double > GetPixel(Point2D< int > position) const
Gets the pixel values for all planes at a give position.
Definition detail_image.hpp:74
static std::unique_ptr< Image > Load(const String &fileName)
Loads an image with the given file name.
Definition detail_image.hpp:25
bool PlaneDataTypesIdentical() const noexcept
Check if all planes have the same data type.
Definition decl_image.hpp:252
void * Handle() const noexcept
Classic API image handle.
Definition decl_image.hpp:232
Point2D< double > PixelToImageCoordinates(Point2D< double > point) const noexcept
Convert a point from pixel to image coordinates.
Definition decl_image.hpp:515
static VarArgRange< std::unique_ptr< Image >, constImage &, IMAGES... >::type FromImages(MappingOption mapping, const IMAGES &...images)
Create an image that is the result of concatenating a series of input images.
Definition decl_image.hpp:116
static std::unique_ptr< Image > Create(Size2D< int > size, int numPlanes=1, DataType dataType=DataType::Int8BppUnsigned())
Creates an uninitialized image with the given parameters.
Definition decl_image.hpp:70
Image plane information container.
Definition decl_image_plane.hpp:29
Multi-purpose 2D vector class.
Definition point_2d.hpp:20
T X() const noexcept
Gets the x-component of the point.
Definition point_2d.hpp:84
T Y() const noexcept
Gets the y-component of the point.
Definition point_2d.hpp:104
Rectangle object.
Definition rect.hpp:24
T Bottom() const noexcept
Gets bottom row of the rectangle (still inside the rectangle).
Definition rect.hpp:144
Size2D< T > Size() const noexcept
Gets the size of the rectangle.
Definition rect.hpp:204
T Top() const noexcept
Gets first row of the rectangle.
Definition rect.hpp:104
T Right() const noexcept
Gets rightmost column of the rectangle (still inside the rectangle).
Definition rect.hpp:124
T Left() const noexcept
Gets first column of the rectangle.
Definition rect.hpp:84
Stores a pair of numbers that represents the width and the height of a subject, typically a rectangle...
Definition size_2d.hpp:20
T Height() const noexcept
Gets the vertical component of the size.
Definition size_2d.hpp:77
T Width() const noexcept
Gets the horizontal component of the size.
Definition size_2d.hpp:57
cvbbool_t GetImageCoordinates(IMG Image, TCoordinateMap &CS)
cvbbool_t SetImageCoordinates(IMG Image, TCoordinateMap CS)
cvbbool_t CopyImageRectPlanes(IMG ImageIn, IMG ImageOut, cvbdim_t InLeft, cvbdim_t InTop, cvbdim_t InRight, cvbdim_t InBottom, cvbdim_t OutX, cvbdim_t OutY)
cvbbool_t CreateConcatenatedImage(IMG *ImageArray, size_t ArrayLength, cvbbool_t ShareMemory, IMG &ImageOut)
cvbbool_t ShareObject(OBJ Object)
cvbbool_t ReleaseObject(OBJ &Object)
PfncFormat
GenICam Pixel Format Naming Convention (PFNC) format values.
Definition pfnc_format.hpp:21
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
RotationMap
Amount of rotation to apply when mapping an image.
Definition global.hpp:377
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49
MappingOption
Mapping options when creating a (potentially) mapped image.
Definition global.hpp:361
@ LinkPixels
Definition global.hpp:372
std::shared_ptr< Image > ImagePtr
Convenience shared pointer for Image.
Definition global.hpp:86
ColorModel
Color model that this image is using.
Definition global.hpp:176