AvTranscoder  0.9.4
C++APIforLibav/FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PixelProperties.hpp
Go to the documentation of this file.
1 #ifndef _AV_TRANSCODER_FRAME_PIXEL_PROPERTIES_HPP_
2 #define _AV_TRANSCODER_FRAME_PIXEL_PROPERTIES_HPP_
3 
6 
7 extern "C" {
8 #include <libavutil/pixfmt.h>
9 #include <libavutil/pixdesc.h>
10 }
11 
12 #include <string>
13 #include <vector>
14 
15 struct AVPixFmtDescriptor;
16 
17 namespace avtranscoder
18 {
19 
21 {
22  eComponentGray = 0, ///< Gray color space
23  eComponentRgb, ///< RGB color space
24  eComponentYuv, ///< YUV color space. 16 <= Y <= 235, 16 <= U, V <= 240
25  eComponentYuvJPEG, ///< YUV color space. 0 <= Y <= 255, 0 <= U, V <= 255
26  eComponentYuvA ///< YUV color space with transparency
27 };
28 
30 {
31  eSubsamplingNone = 0, // 4:4:4
32  eSubsampling440, // 4:4:0
33  eSubsampling422, // 4:2:2
34  eSubsampling420, // 4:2:0
35  eSubsampling411, // 4:1:1
36  eSubsampling410 // 4:1:0
37 };
38 
39 struct AvExport Channel
40 {
41  size_t id;
42  size_t chromaHeight;
43  size_t bitStep;
44 };
45 
46 class AvExport PixelProperties
47 {
48 public:
49  /**
50  * If parameter is an unknown pixel, its format is AV_PIX_FMT_NONE with no access to pixel description.
51  */
52  PixelProperties(const std::string& avPixelFormat = "");
53  PixelProperties(const AVPixelFormat avPixelFormat);
54 
55  std::string getPixelName() const;
56  std::string getPixelFormatName() const;
57 
58  size_t getBitsPerPixel() const; ///< padding bits are not counted
59  size_t getMaxNbBitsInChannels() const;
60  size_t getNbComponents() const;
61  size_t getChromaWidth() const;
62  size_t getChromaHeight() const;
63 
64  EComponentType getColorComponents() const;
65  ESubsamplingType getSubsampling() const;
66 
67  bool isBigEndian() const;
68  bool hasAlpha() const;
69  bool isPlanar() const;
70  bool isIndexedColors() const;
71  bool isBitWisePacked() const;
72  bool isHardwareAccelerated() const;
73  bool isRgbPixelData() const;
74  bool isPseudoPaletted() const;
75 
76  std::vector<Channel> getChannels() const;
77 
78 #ifndef SWIG
79  AVPixelFormat getAVPixelFormat() const { return _pixelFormat; }
80  const AVPixFmtDescriptor* getAVPixFmtDescriptor() const { return _pixelDesc; }
81 #endif
82 
83  PropertyVector asVector() const; ///< Return all pixel properties as a vector (name of property: value)
84  PropertyVector& fillVector(PropertyVector& data) const; ///< To avoid copy of the vector
85 
86 private:
87  void init(const AVPixelFormat avPixelFormat);
88 
89 #ifndef SWIG
90  template <typename T>
91  void addProperty(PropertyVector& data, const std::string& key, T (PixelProperties::*getter)(void) const) const
92  {
93  try
94  {
95  detail::add(data, key, (this->*getter)());
96  }
97  catch(const std::exception& e)
98  {
100  }
101  }
102 #endif
103 
104 private:
106  const AVPixFmtDescriptor* _pixelDesc; ///< Has link (no ownership)
107 };
108 }
109 
110 #endif
std::vector< std::pair< std::string, std::string > > PropertyVector
PropertyVector is a vector of pair, because the order of properties matters to us.
Definition: util.hpp:23
void add(PropertyVector &propertyVector, const std::string &key, const size_t &value)
Definition: util.cpp:16
YUV color space. 16 <= Y <= 235, 16 <= U, V <= 240.
YUV color space with transparency.
YUV color space. 0 <= Y <= 255, 0 <= U, V <= 255.
std::string getPixelFormatName(const AVPixelFormat pixelFormat)
Definition: util.cpp:100
const AVPixFmtDescriptor * _pixelDesc
Has link (no ownership)
void addProperty(PropertyVector &data, const std::string &key, T(PixelProperties::*getter)(void) const) const
const AVPixFmtDescriptor * getAVPixFmtDescriptor() const
#define AVPixelFormat
Definition: common.hpp:43
AVPixelFormat getAVPixelFormat() const
const std::string propertyValueIfError
Definition: util.hpp:38