CVB++ 15.0
format_converter.hpp
1#pragma once
2
3#include "codec_bridge.hpp"
4#include "../global.hpp"
5#include "../utilities/system_info.hpp"
6
7#include "frame.hpp"
8
9namespace Cvb
10{
11
12 CVB_BEGIN_INLINE_NS
13
14 template <>
15 inline HandleGuard<CodecBridge::FormatConverter>::HandleGuard(void *handle) noexcept
16 : HandleGuard<CodecBridge::FormatConverter>(handle, [](void *handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
17 {
18 }
19
20 namespace CodecBridge
21 {
22
28 class FormatConverter final
29 {
30
31 public:
33
43 PixelFormat dstFormat, Interpolation method)
44 {
45 return Internal::DoResCallObjectOut<FormatConverter>([&](void *&handle) {
46 return CVB_CALL_CAPI(CVCBCreateFormatConverter(
47 srcSize.Width(), srcSize.Height(), static_cast<CExports::CVCBPixelFormat>(srcFormat), dstSize.Width(),
48 dstSize.Height(), static_cast<CExports::CVCBPixelFormat>(dstFormat),
49 static_cast<CExports::CVCBInterpolation>(method), handle));
50 });
51 }
52
53 static std::unique_ptr<FormatConverter> FromHandle(HandleGuard<FormatConverter> &&guard)
54 {
55 if (!guard.Handle())
56 throw std::runtime_error("handle must not be null");
57
58 return std::make_unique<FormatConverter>(std::move(guard));
59 }
60
61 explicit FormatConverter(HandleGuard<FormatConverter> &&guard) noexcept
62 : handle_(std::move(guard))
63 {
64 }
65
66 FormatConverter(const FormatConverter &other) = delete;
67 FormatConverter &operator=(const FormatConverter &other) = delete;
68 FormatConverter(FormatConverter &&other) = delete;
69 FormatConverter &operator=(FormatConverter &&other) = delete;
70
71 ~FormatConverter() = default;
72
73 void *Handle() const noexcept
74 {
75 return handle_.Handle();
76 }
77
79
86 void Execute(const Frame &srcFrame, const Frame &dstFrame)
87 {
88 CVB_CALL_CAPI(CVCBFormatConverterExecute(Handle(), srcFrame.Handle(), dstFrame.Handle()));
89 }
90
91 private:
92 HandleGuard<FormatConverter> handle_;
93 };
94
95 } // namespace CodecBridge
96
97 CVB_END_INLINE_NS
98} // namespace Cvb
void Execute(const Frame &srcFrame, const Frame &dstFrame)
Convert an from one frame to another.
Definition format_converter.hpp:86
static std::unique_ptr< FormatConverter > Create(Size2D< int > srcSize, PixelFormat srcFormat, Size2D< int > dstSize, PixelFormat dstFormat, Interpolation method)
Creates a format converter.
Definition format_converter.hpp:42
A video frame for encoding and decoding.
Definition frame.hpp:30
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 ReleaseObject(OBJ &Object)
T move(T... args)
Namespace for encoding and decoding videos.
Definition codec_bridge.hpp:24
PixelFormat
Subset of FFmpeg pixel formats.
Definition codec_bridge.hpp:91
Interpolation
Interpolation method when scaling frames.
Definition codec_bridge.hpp:175
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17