forked from h4tr3d/avcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpixelformat.cpp
66 lines (56 loc) · 1.41 KB
/
pixelformat.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "pixelformat.h"
namespace av {
PixelFormat::PixelFormat(const char *name) noexcept
: Parent(av_get_pix_fmt(name))
{
}
PixelFormat::PixelFormat(const std::string &name) noexcept
: PixelFormat(name.c_str())
{
}
const char *PixelFormat::name(OptionalErrorCode ec) const
{
if (auto nm = av_get_pix_fmt_name(m_fmt))
{
clear_if(ec);
return nm;
}
throws_if(ec, std::errc::invalid_argument);
return nullptr;
}
const AVPixFmtDescriptor *PixelFormat::descriptor(OptionalErrorCode ec) const
{
if (auto desc = av_pix_fmt_desc_get(m_fmt))
{
clear_if(ec);
return desc;
}
throws_if(ec, std::errc::invalid_argument);
return nullptr;
}
int PixelFormat::bitsPerPixel(OptionalErrorCode ec) const
{
if (auto desc = descriptor(ec))
return av_get_bits_per_pixel(desc);
return 0;
}
size_t PixelFormat::planesCount(OptionalErrorCode ec) const
{
auto count = av_pix_fmt_count_planes(m_fmt);
if (count < 0)
{
throws_if(ec, count, ffmpeg_category());
return 0;
}
clear_if(ec);
return static_cast<size_t>(count);
}
PixelFormat PixelFormat::swapEndianness() const noexcept
{
return av_pix_fmt_swap_endianness(m_fmt);
}
size_t PixelFormat::convertionLoss(PixelFormat dstFmt, bool srcHasAlpha) const noexcept
{
return static_cast<size_t>(av_get_pix_fmt_loss(dstFmt, m_fmt, srcHasAlpha));
}
} // namespace av