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
25 {
26 public:
28
38 PixelFormatConverter(PfncFormat sourceFormat, PfncFormat destinationFormat)
39 : handleGuard_(CreateHandle(sourceFormat, destinationFormat))
40 , sourceFormat_(sourceFormat)
41 , destinationFormat_(destinationFormat)
42 {
43 }
44
45 PixelFormatConverter() = delete;
47 PixelFormatConverter &operator=(PixelFormatConverter &&rhs) = default;
49 PixelFormatConverter &operator=(const PixelFormatConverter &) = delete;
50 ~PixelFormatConverter() = default;
51
53
59 static std::unique_ptr<PixelFormatConverter> Create(PfncFormat sourceFormat, PfncFormat destinationFormat)
60 {
61 return std::make_unique<PixelFormatConverter>(sourceFormat, destinationFormat);
62 }
63
65
71 void *Handle() const noexcept
72 {
73 return handleGuard_.Handle();
74 }
75
77
82 {
83 return sourceFormat_;
84 }
85
87
92 {
93 return destinationFormat_;
94 }
95
97
108 template <class T>
109 void Execute(const T &sourceObject, Image &destinationObject)
110 {
111 CVB_CALL_CAPI_CHECKED(
112 CVPFConverterExecute(handleGuard_.Handle(), sourceObject.Handle(), destinationObject.Handle()));
113 }
114
115 private:
116 void *CreateHandle(PfncFormat sourceFormat, PfncFormat destinationFormat)
117 {
118 void *handle = nullptr;
119 CVB_CALL_CAPI_CHECKED(CVPFCreateConverter(static_cast<Cvb::CExports::cvbuint32_t>(sourceFormat),
120 static_cast<Cvb::CExports::cvbuint32_t>(destinationFormat), handle));
121 if (!handle)
122 throw std::runtime_error("handle must not be null");
123
124 return handle;
125 }
126
127 HandleGuard<PixelFormatConverter> handleGuard_;
128 Cvb::PfncFormat sourceFormat_;
129 Cvb::PfncFormat destinationFormat_;
130 };
131
132 CVB_END_INLINE_NS
133
134} // namespace Cvb
The Common Vision Blox image.
Definition: decl_image.hpp:45
void * Handle() const noexcept
Classic API image handle.
Definition: decl_image.hpp:226
Helper class that takes care of pixel format conversion.
Definition: pixel_format_converter.hpp:25
static std::unique_ptr< PixelFormatConverter > Create(PfncFormat sourceFormat, PfncFormat destinationFormat)
Creates a pixel format converter.
Definition: pixel_format_converter.hpp:59
Cvb::PfncFormat SourceFormat() const noexcept
Gets the source pixel format.
Definition: pixel_format_converter.hpp:81
void Execute(const T &sourceObject, Image &destinationObject)
Converts a PFNC compliant object to another.
Definition: pixel_format_converter.hpp:109
PixelFormatConverter(PfncFormat sourceFormat, PfncFormat destinationFormat)
Constructor.
Definition: pixel_format_converter.hpp:38
Cvb::PfncFormat DestinationFormat() const noexcept
Gets the destination pixel format.
Definition: pixel_format_converter.hpp:91
void * Handle() const noexcept
Classic API handle.
Definition: pixel_format_converter.hpp:71
PfncFormat
GenICam Pixel Format Naming Convention (PFNC) format values.
Definition: pfnc_format.hpp:21
Root namespace for the Image Manager interface.
Definition: c_barcode.h:15