CVB++ 15.0
pixel_format_converter.hpp
1#pragma once
2
3#include <memory>
4
5#include "_cexports/c_img.h"
6#include "_cexports/c_pixfmtcnv.h"
7
8#include "global.hpp"
9#include "pfnc_format.hpp"
10
11namespace Cvb
12{
13
14 CVB_BEGIN_INLINE_NS
15
16 template <>
17 inline HandleGuard<PixelFormatConverter>::HandleGuard(void *handle) noexcept
18 : HandleGuard<PixelFormatConverter>(handle, [](void *handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
19 {
20 }
21
23
37 {
38 public:
40
50 PixelFormatConverter(PfncFormat sourceFormat, PfncFormat destinationFormat)
51 : handleGuard_(CreateHandle(sourceFormat, destinationFormat))
52 , sourceFormat_(sourceFormat)
53 , destinationFormat_(destinationFormat)
54 {
55 }
56
57 PixelFormatConverter() = delete;
59 PixelFormatConverter &operator=(PixelFormatConverter &&rhs) = default;
61 PixelFormatConverter &operator=(const PixelFormatConverter &) = delete;
62 ~PixelFormatConverter() = default;
63
65
71 static std::unique_ptr<PixelFormatConverter> Create(PfncFormat sourceFormat, PfncFormat destinationFormat)
72 {
73 return std::make_unique<PixelFormatConverter>(sourceFormat, destinationFormat);
74 }
75
77
83 void *Handle() const noexcept
84 {
85 return handleGuard_.Handle();
86 }
87
89
94 {
95 return sourceFormat_;
96 }
97
99
104 {
105 return destinationFormat_;
106 }
107
109
120 template <class T>
121 void Execute(const T &sourceObject, Image &destinationObject)
122 {
123 CVB_CALL_CAPI_CHECKED(
124 CVPFConverterExecute(handleGuard_.Handle(), sourceObject.Handle(), destinationObject.Handle()));
125 }
126
127 private:
128 void *CreateHandle(PfncFormat sourceFormat, PfncFormat destinationFormat)
129 {
130 void *handle = nullptr;
131 CVB_CALL_CAPI_CHECKED(CVPFCreateConverter(static_cast<Cvb::CExports::cvbuint32_t>(sourceFormat),
132 static_cast<Cvb::CExports::cvbuint32_t>(destinationFormat), handle));
133 if (!handle)
134 throw std::runtime_error("handle must not be null");
135
136 return handle;
137 }
138
139 HandleGuard<PixelFormatConverter> handleGuard_;
140 Cvb::PfncFormat sourceFormat_;
141 Cvb::PfncFormat destinationFormat_;
142 };
143
144 CVB_END_INLINE_NS
145
146} // namespace Cvb
The Common Vision Blox image.
Definition decl_image.hpp:50
void * Handle() const noexcept
Classic API image handle.
Definition decl_image.hpp:237
Helper class that takes care of pixel format conversion.
Definition pixel_format_converter.hpp:37
static std::unique_ptr< PixelFormatConverter > Create(PfncFormat sourceFormat, PfncFormat destinationFormat)
Creates a pixel format converter.
Definition pixel_format_converter.hpp:71
Cvb::PfncFormat SourceFormat() const noexcept
Gets the source pixel format.
Definition pixel_format_converter.hpp:93
void Execute(const T &sourceObject, Image &destinationObject)
Converts a PFNC compliant object to another.
Definition pixel_format_converter.hpp:121
PixelFormatConverter(PfncFormat sourceFormat, PfncFormat destinationFormat)
Constructor.
Definition pixel_format_converter.hpp:50
Cvb::PfncFormat DestinationFormat() const noexcept
Gets the destination pixel format.
Definition pixel_format_converter.hpp:103
void * Handle() const noexcept
Classic API handle.
Definition pixel_format_converter.hpp:83
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