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)); })
57 using GuardType = HandleGuard<Image>;
100 template <
class RANGE>
104 auto rangeAdapter = MakeRangeAdapter<ImagePtr>(images);
106 handles.reserve(rangeAdapter.Size());
107 for (
const auto &image : images)
108 handles.emplace_back(image->Handle());
109 return FromImageHandles(mapping, handles);
119 template <
class... IMAGES>
120 static typename VarArgRange<std::unique_ptr<Image>,
const Image &, IMAGES...>::type
123 std::array<
void *,
sizeof...(IMAGES)> handles = {images.Handle()...};
124 return FromImageHandles(mapping, handles);
134 template <
class RANGE>
136 const RANGE &planes);
148 template <
class... PLANES>
149 static typename VarArgRange<std::unique_ptr<Image>,
ImagePlane &&, PLANES...>::type
179 template <
class T,
class... ARGS>
211 :
Image(std::move(*
Create(width, height, numPlanes, dataType)))
226 Image &operator=(
const Image &other) =
delete;
228 virtual ~Image() =
default;
239 return handle_.Handle();
249 return static_cast<int>(CExports::ImageDimension(
Handle()));
265 static_cast<int>(CExports::ImageDatatype(
Handle(),
static_cast<CExports::cvbdim_t
>(i))))
301 return static_cast<int>(CExports::ImageHeight(
Handle()));
311 return static_cast<int>(CExports::ImageWidth(
Handle()));
342 void Save(
const String &fileName,
double quality)
const;
405 sourceRect.
Right(), sourceRect.
Bottom(), targetPosition.
X(),
406 targetPosition.
Y())))
407 Utilities::SystemInfo::ThrowLastError();
461 pixelContentChangedCarrierContainer_.Call<void(
const Image &,
Rect<int>)>(*
this, rect);
473 return pixelContentChangedCarrierContainer_.Register(carrier);
483 pixelContentChangedCarrierContainer_.Unregister(eventCookie);
496 CExports::ImageToPixel(
Handle(), point.X(), point.Y(), x, y);
509 CExports::ImageAreaToPixel(
Handle(), *
reinterpret_cast<CExports::TArea *
>(&area),
510 reinterpret_cast<CExports::TArea &
>(retval));
524 CExports::PixelToImage(
Handle(), point.X(), point.Y(), x, y);
537 CExports::PixelAreaToImage(
Handle(), *
reinterpret_cast<CExports::TArea *
>(&area),
538 reinterpret_cast<CExports::TArea &
>(retval));
586 return Internal::DoResCallObjectOut<Image>([&](
void *&image) {
587 return CVB_CALL_CAPI(
588 CVPFCreateImageFromPFNCValue(
static_cast<Cvb::CExports::cvbuint32_t
>(format), width, height, image));
593 explicit Image(HandleGuard<Image> &&guard) noexcept
598 void Detach() noexcept
603 void ResetHandle(
void *newHandle)
noexcept
605 handle_.Reset(newHandle);
610 : handle_(std::move(other.handle_))
611 , pixelContentChangedCarrierContainer_(std::move(other.pixelContentChangedCarrierContainer_))
615 Image &operator=(
Image &&other)
noexcept =
delete;
617 void IncreaseRefCount() const noexcept
622 template <
class RANGE>
623 static typename TypedRange<std::unique_ptr<Image>,
void *, RANGE>::type FromImageHandles(
MappingOption mapping,
626 return Internal::DoBoolCallObjectOut<Image>([&](
void *&handle) {
627 auto rangeAdapter = MakeRangeAdapter<void *>(range);
633 HandleGuard<Image> handle_;
635 mutable std::mutex handlerMutex_;
637 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:78
Cookie used to unregister event handlers.
Definition global.hpp:591
The Common Vision Blox image.
Definition decl_image.hpp:50
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:584
Point2D< double > ImageToPixelCoordinates(Point2D< double > point) const noexcept
Convert a point from image to pixel coordinates.
Definition decl_image.hpp:492
EventCookie RegisterEventPixelContentChanged(std::function< void(const Image &, Rect< int >)> handler)
Register a listener to the pixel content changed event.
Definition decl_image.hpp:470
void RaisePixelContentChanged() const
Inform clients listening to the pixel content changed event, that the image data has been completely ...
Definition decl_image.hpp:448
Area2D PixelToImageCoordinates(Area2D area) const noexcept
Convert an Area2D from pixel to image coordinates.
Definition decl_image.hpp:534
int Width() const noexcept
Width of the image in pixels.
Definition decl_image.hpp:309
Image(Size2D< int > size, int numPlanes=1, DataType dataType=DataType::Int8BppUnsigned())
Constructs an uninitialized image with the given parameters.
Definition decl_image.hpp:197
void Copy(Image &targetImage) const
Copies the image data from this image to the target image.
Definition decl_image.hpp:417
int Height() const noexcept
Height of the image in pixels.
Definition decl_image.hpp:299
AffineMatrix2D CoordinateSystem() const noexcept
Get the coordinate system of the image.
Definition decl_image.hpp:547
Image(const String &fileName)
Loads an image with the given file name.
Definition decl_image.hpp:220
std::unique_ptr< Image > Map(Rect< int > rect) const
Creates a mapped image of the region of this image.
Definition decl_image.hpp:352
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:459
int PlanesCount() const noexcept
Get the number of planes for this image.
Definition decl_image.hpp:247
Image(int width, int height, int numPlanes=1, DataType dataType=DataType::Int8BppUnsigned())
Constructs an uninitialized image with the given parameters.
Definition decl_image.hpp:210
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:402
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:481
Rect< int > Bounds() const noexcept
Bounding rectangle of the image in pixels.
Definition decl_image.hpp:438
static std::unique_ptr< Image > FromHandle(HandleGuard< Image > &&guard)
Creates an image from a classic API handle.
Definition decl_image.hpp:160
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:428
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:101
void SetCoordinateSystem(AffineMatrix2D affineMatrix) noexcept
Set the coordinate system of the image.
Definition decl_image.hpp:559
Area2D ImageToPixelCoordinates(Area2D area) const noexcept
Convert an Area2D from image to pixel coordinates.
Definition decl_image.hpp:506
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:571
static std::unique_ptr< T > FromHandle(HandleGuard< Image > &&guard, ARGS &&...args)
Creates an image from a classic API handle (typed).
Definition decl_image.hpp:180
Cvb::ColorModel ColorModel() const noexcept
Color model realized by this image.
Definition decl_image.hpp:319
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:257
void * Handle() const noexcept
Classic API image handle.
Definition decl_image.hpp:237
Point2D< double > PixelToImageCoordinates(Point2D< double > point) const noexcept
Convert a point from pixel to image coordinates.
Definition decl_image.hpp:520
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:121
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:75
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:34
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