CVB++ 15.0
decl_wrapped_image.hpp
1#pragma once
2
3#include <array>
4
5#include "../global.hpp"
6
7#include "decl_image.hpp"
8
9namespace Cvb
10{
11
12 CVB_BEGIN_INLINE_NS
13
14 template <>
15 inline HandleGuard<WrappedImage>::HandleGuard(void *handle) noexcept
16 : HandleGuard<WrappedImage>(handle, [](void *handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
17 {
18 }
19
21
27 class WrappedImage : public Image
28 {
29 friend class Image;
30
31 public:
33
46 static std::unique_ptr<WrappedImage> FromGreyPixels(void *buffer, int bufferSize, int width, int height,
47 DataType dataType, int pixelStride, int lineStride)
48 {
49 std::array<int, 1> planeOrder = {0};
50 return Create(buffer, bufferSize, width, height, dataType, pixelStride, lineStride, 0, planeOrder);
51 }
52
54
61 static std::unique_ptr<WrappedImage> FromGrey8Pixels(void *buffer, int width, int height)
62 {
63 return FromGreyPixels(buffer, width * height, width, height, DataType::FromNativeType<std::uint8_t>(), 1, width);
64 }
65
67
81 static std::unique_ptr<WrappedImage> FromRgbPixels(void *buffer, int bufferSize, int width, int height,
82 DataType dataType, int pixelStride, int lineStride,
83 int planeStride)
84 {
85 std::array<int, 3> planeOrder = {0, 1, 2};
86 return Create(buffer, bufferSize, width, height, dataType, pixelStride, lineStride, planeStride, planeOrder);
87 }
88
90
104 static std::unique_ptr<WrappedImage> FromBgrPixels(void *buffer, int bufferSize, int width, int height,
105 DataType dataType, int pixelStride, int lineStride,
106 int planeStride)
107 {
108 std::array<int, 3> planeOrder = {2, 1, 0};
109 return Create(buffer, bufferSize, width, height, dataType, pixelStride, lineStride, planeStride, planeOrder);
110 }
111
112 static std::unique_ptr<WrappedImage> FromArray(const IArray &array);
113
114 WrappedImage(const WrappedImage &other) = delete;
115 WrappedImage &operator=(const WrappedImage &other) = delete;
116 WrappedImage(WrappedImage &&other) = delete;
117 WrappedImage &operator=(WrappedImage &&other) = delete;
118 virtual ~WrappedImage() = default;
119
121
128 static std::unique_ptr<WrappedImage> FromHandle(HandleGuard<WrappedImage> &&guard)
129 {
130 return Image::FromHandle<WrappedImage>(HandleGuard<Image>(guard.Release()));
131 }
132
133 private:
134 explicit WrappedImage(HandleGuard<Image> &&guard) noexcept
135 : Image(std::move(guard))
136 {
137 }
138
139 template <std::size_t N>
140 static std::unique_ptr<WrappedImage> Create(void *buffer, int bufferSize, int width, int height, DataType dataType,
141 int pixelStride, int lineStride, int planeStride,
142 const std::array<int, N> &planeOrder)
143 {
144 return Internal::DoResCallObjectOut<WrappedImage>([=](void *&handle) {
145 std::vector<CExports::cvbval_t> repackedOrder(planeOrder.begin(), planeOrder.end());
146 return CVB_CALL_CAPI(CreateImageFromPointer(
147 buffer, static_cast<std::size_t>(bufferSize), static_cast<CExports::cvbdim_t>(width),
148 static_cast<CExports::cvbdim_t>(height), static_cast<CExports::cvbdim_t>(N),
149 static_cast<CExports::cvbdatatype_t>(dataType.NativeDescriptor()), static_cast<std::intptr_t>(pixelStride),
150 static_cast<std::intptr_t>(lineStride), static_cast<std::intptr_t>(planeStride), repackedOrder.data(),
151 [](void *, void *) {}, nullptr, handle));
152 });
153 }
154 };
155
156 CVB_END_INLINE_NS
157
158} // namespace Cvb
Data type description for an image plane.
Definition data_type.hpp:23
static DataType FromNativeType() noexcept
Construct a data type descriptor from one of the native data type value equivalents.
Definition data_type.hpp:173
Array interface.
Definition iarray.hpp:16
The Common Vision Blox image.
Definition decl_image.hpp:50
static std::unique_ptr< Image > FromHandle(HandleGuard< Image > &&guard)
Creates an image from a classic API handle.
Definition decl_image.hpp:160
A wrapped image wraps another pixel buffer without owning it.
Definition decl_wrapped_image.hpp:28
static std::unique_ptr< WrappedImage > FromRgbPixels(void *buffer, int bufferSize, int width, int height, DataType dataType, int pixelStride, int lineStride, int planeStride)
Wraps, without copying, the given RGB pixel buffer in a CvbImage.
Definition decl_wrapped_image.hpp:81
static std::unique_ptr< WrappedImage > FromHandle(HandleGuard< WrappedImage > &&guard)
Creates a wrapped image from a classic API handle.
Definition decl_wrapped_image.hpp:128
static std::unique_ptr< WrappedImage > FromGrey8Pixels(void *buffer, int width, int height)
Wraps, without copying, the given Mono8 pixel buffer in a CvbImage.
Definition decl_wrapped_image.hpp:61
static std::unique_ptr< WrappedImage > FromBgrPixels(void *buffer, int bufferSize, int width, int height, DataType dataType, int pixelStride, int lineStride, int planeStride)
Wraps, without copying, the given BGR pixel buffer in a CvbImage.
Definition decl_wrapped_image.hpp:104
static std::unique_ptr< WrappedImage > FromGreyPixels(void *buffer, int bufferSize, int width, int height, DataType dataType, int pixelStride, int lineStride)
Wraps, without copying, the given monochrome pixel buffer in an image.
Definition decl_wrapped_image.hpp:46
cvbres_t CreateImageFromPointer(void *pImageMemory, size_t MemorySize, cvbdim_t Width, cvbdim_t Height, cvbdim_t NumPlanes, cvbdatatype_t DataType, intptr_t PitchX, intptr_t PitchY, intptr_t PitchPlane, const cvbval_t PlaneOrder[], PFFINALRELEASE ReleaseCallback, void *pPrivate, IMG &ImageOut)
cvbbool_t ReleaseObject(OBJ &Object)
T move(T... args)
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17