CVB++ 15.1
Loading...
Searching...
No Matches
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 "image.hpp"
9#include "global.hpp"
10#include "pfnc_format.hpp"
11
12namespace Cvb
13{
14
15 CVB_BEGIN_INLINE_NS
16
17 template <>
18 inline HandleGuard<PixelFormatConverter>::HandleGuard(void *handle) noexcept
19 : HandleGuard<PixelFormatConverter>(handle, [](void *handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
20 {
21 }
22
24
38 {
39 public:
41
51 PixelFormatConverter(PfncFormat sourceFormat, PfncFormat destinationFormat)
52 : handleGuard_(CreateHandle(sourceFormat, destinationFormat))
53 , sourceFormat_(sourceFormat)
54 , destinationFormat_(destinationFormat)
55 {
56 }
57
58 PixelFormatConverter() = delete;
60 PixelFormatConverter &operator=(PixelFormatConverter &&rhs) = default;
62 PixelFormatConverter &operator=(const PixelFormatConverter &) = delete;
63 ~PixelFormatConverter() = default;
64
66
72 static std::unique_ptr<PixelFormatConverter> Create(PfncFormat sourceFormat, PfncFormat destinationFormat)
73 {
74 return std::make_unique<PixelFormatConverter>(sourceFormat, destinationFormat);
75 }
76
78
84 void *Handle() const noexcept
85 {
86 return handleGuard_.Handle();
87 }
88
90
95 {
96 return sourceFormat_;
97 }
98
100
105 {
106 return destinationFormat_;
107 }
108
110
121 template <class T>
122 void Execute(const T &sourceObject, Image &destinationObject)
123 {
124 CVB_CALL_CAPI_CHECKED(
125 CVPFConverterExecute(handleGuard_.Handle(), sourceObject.Handle(), destinationObject.Handle()));
126 }
127
128 private:
129 void *CreateHandle(PfncFormat sourceFormat, PfncFormat destinationFormat)
130 {
131 void *handle = nullptr;
132 CVB_CALL_CAPI_CHECKED(CVPFCreateConverter(static_cast<Cvb::CExports::cvbuint32_t>(sourceFormat),
133 static_cast<Cvb::CExports::cvbuint32_t>(destinationFormat), handle));
134 if (!handle)
135 throw std::runtime_error("handle must not be null");
136
137 return handle;
138 }
139
140 HandleGuard<PixelFormatConverter> handleGuard_;
141 Cvb::PfncFormat sourceFormat_;
142 Cvb::PfncFormat destinationFormat_;
143 };
144
145 CVB_END_INLINE_NS
146
147} // 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:38
static std::unique_ptr< PixelFormatConverter > Create(PfncFormat sourceFormat, PfncFormat destinationFormat)
Creates a pixel format converter.
Definition pixel_format_converter.hpp:72
Cvb::PfncFormat SourceFormat() const noexcept
Gets the source pixel format.
Definition pixel_format_converter.hpp:94
void Execute(const T &sourceObject, Image &destinationObject)
Converts a PFNC compliant object to another.
Definition pixel_format_converter.hpp:122
PixelFormatConverter(PfncFormat sourceFormat, PfncFormat destinationFormat)
Constructor.
Definition pixel_format_converter.hpp:51
Cvb::PfncFormat DestinationFormat() const noexcept
Gets the destination pixel format.
Definition pixel_format_converter.hpp:104
void * Handle() const noexcept
Classic API handle.
Definition pixel_format_converter.hpp:84
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 version.hpp:11