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