Skip to content

Commit a3ebb88

Browse files
committed
Merge pull request #6 from cchampet/dev_add_support_pixelFormats
Supported chroma subsampling : * 4:4:4 * 4:4:0 * 4:2:2 * 4:2:0 * 4:1:1 * 4:1:0
2 parents 0e5eb7c + 6e5f044 commit a3ebb88

File tree

2 files changed

+44
-20
lines changed

2 files changed

+44
-20
lines changed

src/AvTranscoder/frame/Pixel.cpp

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,12 @@ Pixel::Pixel( const std::string& avPixelFormat )
1818
}
1919

2020
Pixel::Pixel( const AVPixelFormat avPixelFormat )
21-
: _pixelSize ( 24 )
22-
, _components ( 3 )
23-
, _componentType ( eComponentYuv )
24-
, _subsamplingType ( eSubsamplingNone )
25-
, _endianess ( false )
26-
, _withAlpha ( false )
27-
, _planar ( true )
2821
{
2922
init( avPixelFormat );
3023
}
3124

3225
AVPixelFormat Pixel::findPixel() const
3326
{
34-
//av_register_all();
3527
#if LIBAVUTIL_VERSION_MAJOR > 51
3628
const AVPixFmtDescriptor *pix_desc = NULL;
3729
while( ( pix_desc = av_pix_fmt_desc_next( pix_desc ) ) )
@@ -87,16 +79,31 @@ void Pixel::init( const AVPixelFormat avPixelFormat )
8779

8880
setSubsampling( eSubsamplingNone );
8981

90-
if( ( pix_desc->log2_chroma_w == true ) &&
91-
( pix_desc->log2_chroma_h == false ) )
82+
if( ( pix_desc->log2_chroma_w == 0 ) &&
83+
( pix_desc->log2_chroma_h == 1 ) )
84+
{
85+
setSubsampling( eSubsampling440 );
86+
}
87+
else if( ( pix_desc->log2_chroma_w == 1 ) &&
88+
( pix_desc->log2_chroma_h == 0 ) )
9289
{
9390
setSubsampling( eSubsampling422 );
9491
}
95-
if( ( pix_desc->log2_chroma_w == true ) &&
96-
( pix_desc->log2_chroma_h == true ) )
92+
else if( ( pix_desc->log2_chroma_w == 1 ) &&
93+
( pix_desc->log2_chroma_h == 1 ) )
9794
{
9895
setSubsampling( eSubsampling420 );
9996
}
97+
else if( ( pix_desc->log2_chroma_w == 3 ) &&
98+
( pix_desc->log2_chroma_h == 0 ) )
99+
{
100+
setSubsampling( eSubsampling411 );
101+
}
102+
else if( ( pix_desc->log2_chroma_w == 2 ) &&
103+
( pix_desc->log2_chroma_h == 2 ) )
104+
{
105+
setSubsampling( eSubsampling410 );
106+
}
100107
}
101108

102109
bool Pixel::asCorrectColorComponents( const AVPixFmtDescriptor* pix_desc, const EComponentType componentType ) const
@@ -114,18 +121,33 @@ bool Pixel::asCorrectSubsampling( const AVPixFmtDescriptor* pix_desc, const ESub
114121
{
115122
case eSubsamplingNone :
116123
{
117-
return ( pix_desc->log2_chroma_w == false ) &&
118-
( pix_desc->log2_chroma_h == false );
124+
return ( pix_desc->log2_chroma_w == 0 ) &&
125+
( pix_desc->log2_chroma_h == 0 );
126+
}
127+
case eSubsampling440 :
128+
{
129+
return ( pix_desc->log2_chroma_w == 0 ) &&
130+
( pix_desc->log2_chroma_h == 1 );
119131
}
120132
case eSubsampling422 :
121133
{
122-
return ( pix_desc->log2_chroma_w == true ) &&
123-
( pix_desc->log2_chroma_h == false );
134+
return ( pix_desc->log2_chroma_w == 1 ) &&
135+
( pix_desc->log2_chroma_h == 0 );
124136
}
125137
case eSubsampling420 :
126138
{
127-
return ( pix_desc->log2_chroma_w == true ) &&
128-
( pix_desc->log2_chroma_h == true );
139+
return ( pix_desc->log2_chroma_w == 1 ) &&
140+
( pix_desc->log2_chroma_h == 1 );
141+
}
142+
case eSubsampling411:
143+
{
144+
return ( pix_desc->log2_chroma_w == 3 ) &&
145+
( pix_desc->log2_chroma_h == 0 );
146+
}
147+
case eSubsampling410 :
148+
{
149+
return ( pix_desc->log2_chroma_w == 2 ) &&
150+
( pix_desc->log2_chroma_h == 2 );
129151
}
130152
}
131153
return false;

src/AvTranscoder/frame/Pixel.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ enum EComponentType
2323
enum ESubsamplingType
2424
{
2525
eSubsamplingNone = 0, // 4:4:4
26+
eSubsampling440, // 4:4:0
2627
eSubsampling422, // 4:2:2
27-
eSubsampling420 // 4:2:0
28+
eSubsampling420, // 4:2:0
29+
eSubsampling411, // 4:1:1
30+
eSubsampling410 // 4:1:0
2831
};
2932

3033
class AvExport Pixel
@@ -41,7 +44,6 @@ class AvExport Pixel
4144
{ }
4245

4346
Pixel( const std::string& avPixelFormat );
44-
4547
Pixel( const AVPixelFormat avPixelFormat );
4648

4749
void setBitsPerPixel ( const size_t pixelSize ) { _pixelSize = pixelSize; }

0 commit comments

Comments
 (0)