Implement n bits per pixel in Frame to buffer and from buffer

This commit is contained in:
jfmcarreira committed 2015-04-02 18:53:26 +01:00
1 parent a38f9c3283
commit c8079e87cb
8 files changed
+181 -111

No files matched your search

+25 -9
View File
@@ -197,13 +197,14 @@ Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format, Int bitsPixel
m_pcPelFormat = &( g_PlaYUVerPixFmtDescriptorsList[pel_format] );
m_bHasRGBPel = false;
UInt m_uiWidthBytes = m_uiWidth * ( ( m_iBitsPel - 1 ) / 8 + 1 );
if( m_pcPelFormat->colorSpace == COLOR_GRAY )
{
getMem3ImageComponents( &m_pppcInputPel, m_uiHeight, m_uiWidth, 1, 1 );
getMem3ImageComponents( &m_pppcInputPel, m_uiHeight, m_uiWidthBytes, 1, 1 );
}
else
{
getMem3ImageComponents( &m_pppcInputPel, m_uiHeight, m_uiWidth, m_pcPelFormat->log2ChromaHeight, m_pcPelFormat->log2ChromaWidth );
getMem3ImageComponents( &m_pppcInputPel, m_uiHeight, m_uiWidthBytes, m_pcPelFormat->log2ChromaHeight, m_pcPelFormat->log2ChromaWidth );
}
getMem1D( &m_pcARGB32, m_uiHeight * m_uiWidth * 4 );
@@ -229,7 +230,7 @@ UInt64 PlaYUVerFrame::getBytesPerFrame()
UInt64 PlaYUVerFrame::getBytesPerFrame( UInt uiWidth, UInt uiHeight, Int iPixelFormat, Int bitsPixel )
{
PlaYUVerPixFmtDescriptor* pcPelFormat = &( g_PlaYUVerPixFmtDescriptorsList[iPixelFormat] );
UInt bytesPerPixel = bitsPixel / 8;
UInt bytesPerPixel = ( bitsPixel - 1 ) / 8 + 1;
UInt64 numberBytes = uiWidth * uiHeight;
if( pcPelFormat->numberChannels > 1 )
{
@@ -261,6 +262,7 @@ Void PlaYUVerFrame::frameFromBuffer( Pel *Buff, UInt64 uiBuffSize )
Pel* ppBuff[MAX_NUMBER_PLANES];
Pel* pTmpPel, *pTmpBuff;
UInt bytesPixel = ( m_iBitsPel - 1 ) / 8 + 1;
Int ratioH, ratioW, step;
UInt i, ch;
@@ -281,7 +283,7 @@ Void PlaYUVerFrame::frameFromBuffer( Pel *Buff, UInt64 uiBuffSize )
pTmpPel = m_pppcInputPel[ch][0];
pTmpBuff = ppBuff[m_pcPelFormat->comp[ch].plane] + ( m_pcPelFormat->comp[ch].offset_plus1 - 1 );
for( i = 0; i < CHROMASHIFT( m_uiHeight, ratioH ) * CHROMASHIFT( m_uiWidth, ratioW ); i++ )
for( i = 0; i < CHROMASHIFT( m_uiHeight, ratioH ) * CHROMASHIFT( m_uiWidth, ratioW ) * bytesPixel; i++ )
{
*pTmpPel++ = *pTmpBuff;
pTmpBuff += step;
@@ -294,6 +296,7 @@ Void PlaYUVerFrame::frameFromBuffer( Pel *Buff, UInt64 uiBuffSize )
Void PlaYUVerFrame::frameToBuffer( Pel *output_buffer )
{
UInt bytesPixel = ( m_iBitsPel - 1 ) / 8 + 1;
Pel* ppBuff[MAX_NUMBER_PLANES];
Pel* pTmpPel, *pTmpBuff;
Int ratioH, ratioW, step;
@@ -316,7 +319,7 @@ Void PlaYUVerFrame::frameToBuffer( Pel *output_buffer )
pTmpPel = m_pppcInputPel[ch][0];
pTmpBuff = ppBuff[m_pcPelFormat->comp[ch].plane];
for( i = 0; i < CHROMASHIFT( m_uiHeight, ratioH ) * CHROMASHIFT( m_uiWidth, ratioW ); i++ )
for( i = 0; i < CHROMASHIFT( m_uiHeight, ratioH ) * CHROMASHIFT( m_uiWidth, ratioW ) * bytesPixel; i++ )
{
*pTmpBuff = *pTmpPel++;
pTmpBuff += step;
@@ -329,13 +332,26 @@ Void PlaYUVerFrame::fillRGBBuffer()
{
if( m_bHasRGBPel )
return;
if( m_pcPelFormat->colorSpace == COLOR_RGB )
UInt bytesPixel = ( m_iBitsPel - 1 ) / 8 + 1;
Int iR, iG, iB;
UInt* pARGB = ( UInt* )m_pcARGB32;
if( m_pcPelFormat->colorSpace == COLOR_GRAY )
{
Pel* pY = m_pppcInputPel[LUMA][0];
for( UInt i = 0; i < m_uiHeight * m_uiWidth; i++ )
{
iR = *pY++;
iG = *pY++;
iB = *pY++;
*pARGB++ = PEL_RGB( iR, iG, iB );
}
}
else if( m_pcPelFormat->colorSpace == COLOR_RGB )
{
Pel* pR = m_pppcInputPel[COLOR_R][0];
Pel* pG = m_pppcInputPel[COLOR_G][0];
Pel* pB = m_pppcInputPel[COLOR_B][0];
Int iR, iG, iB;
UInt* pARGB = ( UInt* )m_pcARGB32;
for( UInt i = 0; i < m_uiHeight * m_uiWidth; i++ )
{
iR = *pR++;
@@ -346,7 +362,7 @@ Void PlaYUVerFrame::fillRGBBuffer()
}
else
{
m_pcPelFormat->fillARGB32buffer( m_pppcInputPel, m_pcARGB32, m_uiWidth, m_uiHeight );
m_pcPelFormat->fillARGB32buffer( m_pppcInputPel, m_pcARGB32, m_uiWidth, m_uiHeight, bytesPixel );
}
m_bHasRGBPel = true;
}
+145 -88
View File
@@ -52,8 +52,7 @@ namespace plaYUVer
#define ADD_FFMPEG_PEL_FMT( fmt ) 0
#endif
Void fillARGB32bufferYUV( Pel*** in, UChar* out, UInt width, UInt height, UInt ratioChromaHor, UInt ratioChromaVer )
Void fillARGB32bufferYUV( Pel*** in, UChar* out, UInt width, UInt height, UInt depth, UInt ratioChromaHor, UInt ratioChromaVer )
{
Pel* pLineY = in[LUMA][0];
Pel* pLineU = in[CHROMA_U][0];
@@ -78,7 +77,7 @@ Void fillARGB32bufferYUV( Pel*** in, UChar* out, UInt width, UInt height, UInt r
{
iU = *pU++;
iV = *pV++;
for( Int j = 0; j < 1 << ratioChromaHor; j++ )
for( Int j = 0; j < ( 1 << ratioChromaHor ) * depth; j++ )
{
iY = *pY++;
YUV2RGB( iY, iU, iV, iR, iG, iB );
@@ -93,7 +92,7 @@ Void fillARGB32bufferYUV( Pel*** in, UChar* out, UInt width, UInt height, UInt r
}
}
Void fillARGB32bufferYUV420p( Pel*** in, UChar* out, UInt width, UInt height )
Void fillARGB32bufferYUV420p( Pel*** in, UChar* out, UInt width, UInt height, UInt depth )
{
#ifdef USE_SSE
if( ( width % 16 ) == 0 )
@@ -184,14 +183,14 @@ Void fillARGB32bufferYUV420p( Pel*** in, UChar* out, UInt width, UInt height )
b00 = _mm_srai_epi16( _mm_add_epi16( y00r0, bu00 ), 6 );
b01 = _mm_srai_epi16( _mm_add_epi16( y01r0, bu01 ), 6 );
r00 = _mm_packus_epi16( r00, r01 ); // rrrr.. saturated
g00 = _mm_packus_epi16( g00, g01 ); // gggg.. saturated
b00 = _mm_packus_epi16( b00, b01 ); // bbbb.. saturated
r00 = _mm_packus_epi16( r00, r01 );// rrrr.. saturated
g00 = _mm_packus_epi16( g00, g01 );// gggg.. saturated
b00 = _mm_packus_epi16( b00, b01 );// bbbb.. saturated
r01 = _mm_unpacklo_epi8( r00, zero ); // 0r0r..
gbgb = _mm_unpacklo_epi8( b00, g00 ); // gbgb..
rgb0123 = _mm_unpacklo_epi16( gbgb, r01 ); // 0rgb0rgb..
rgb4567 = _mm_unpackhi_epi16( gbgb, r01 ); // 0rgb0rgb..
r01 = _mm_unpacklo_epi8( r00, zero );// 0r0r..
gbgb = _mm_unpacklo_epi8( b00, g00 );// gbgb..
rgb0123 = _mm_unpacklo_epi16( gbgb, r01 );// 0rgb0rgb..
rgb4567 = _mm_unpackhi_epi16( gbgb, r01 );// 0rgb0rgb..
r01 = _mm_unpackhi_epi8( r00, zero );
gbgb = _mm_unpackhi_epi8( b00, g00 );
@@ -211,14 +210,14 @@ Void fillARGB32bufferYUV420p( Pel*** in, UChar* out, UInt width, UInt height )
b00 = _mm_srai_epi16( _mm_add_epi16( y00r1, bu00 ), 6 );
b01 = _mm_srai_epi16( _mm_add_epi16( y01r1, bu01 ), 6 );
r00 = _mm_packus_epi16( r00, r01 ); // rrrr.. saturated
g00 = _mm_packus_epi16( g00, g01 ); // gggg.. saturated
b00 = _mm_packus_epi16( b00, b01 ); // bbbb.. saturated
r00 = _mm_packus_epi16( r00, r01 );// rrrr.. saturated
g00 = _mm_packus_epi16( g00, g01 );// gggg.. saturated
b00 = _mm_packus_epi16( b00, b01 );// bbbb.. saturated
r01 = _mm_unpacklo_epi8( r00, zero ); // 0r0r..
gbgb = _mm_unpacklo_epi8( b00, g00 ); // gbgb..
rgb0123 = _mm_unpacklo_epi16( gbgb, r01 ); // 0rgb0rgb..
rgb4567 = _mm_unpackhi_epi16( gbgb, r01 ); // 0rgb0rgb..
r01 = _mm_unpacklo_epi8( r00, zero );// 0r0r..
gbgb = _mm_unpacklo_epi8( b00, g00 );// gbgb..
rgb0123 = _mm_unpacklo_epi16( gbgb, r01 );// 0rgb0rgb..
rgb4567 = _mm_unpackhi_epi16( gbgb, r01 );// 0rgb0rgb..
r01 = _mm_unpackhi_epi8( r00, zero );
gbgb = _mm_unpackhi_epi8( b00, g00 );
@@ -236,50 +235,20 @@ Void fillARGB32bufferYUV420p( Pel*** in, UChar* out, UInt width, UInt height )
else
#endif
{
fillARGB32bufferYUV( in, out, width, height, 1, 1 );
fillARGB32bufferYUV( in, out, width, height, depth, 1, 1 );
}
}
Void fillARGB32bufferYUV444p( Pel*** in, UChar* out, UInt width, UInt height )
Void fillARGB32bufferYUV444p( Pel*** in, UChar* out, UInt width, UInt height, UInt depth )
{
fillARGB32bufferYUV( in, out, width, height, 0, 0 );
fillARGB32bufferYUV( in, out, width, height, depth, 0, 0 );
}
Void fillARGB32bufferYUV422( Pel*** in, UChar* out, UInt width, UInt height )
Void fillARGB32bufferYUV422( Pel*** in, UChar* out, UInt width, UInt height, UInt depth )
{
fillARGB32bufferYUV( in, out, width, height, 1, 0 );
fillARGB32bufferYUV( in, out, width, height, depth, 1, 0 );
}
Void fillARGB32bufferGray( Pel*** in, UChar* out, UInt width, UInt height )
{
Pel *inPel = in[0][0];
Pel iY;
UInt* buff = ( UInt* )out;
for( UInt i = 0; i < height * width; i++ )
{
iY = *inPel;
*buff++ = PEL_RGB( iY, iY, iY );
inPel++;
}
}
Void fillARGB32bufferRGB( Pel*** in, UChar* out, UInt width, UInt height )
{
Pel* pR = in[COLOR_R][0];
Pel* pG = in[COLOR_G][0];
Pel* pB = in[COLOR_B][0];
Int iR, iG, iB;
UInt* buff = ( UInt* )out;
for( UInt i = 0; i < height * width; i++ )
{
iR = *pR++;
iG = *pG++;
iB = *pB++;
*buff++ = PEL_RGB( iR, iG, iB );
}
}
PlaYUVerPixFmtDescriptor yuv420p =
{
"YUV420p",
@@ -290,12 +259,26 @@ PlaYUVerPixFmtDescriptor yuv420p =
1,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_YUV420P ),
{
{ 0, 0, 1, 0, 7 }, /* Y */
{ 1, 0, 1, 0, 7 }, /* U */
{ 2, 0, 1, 0, 7 }, /* V */
{
0,
0,
1,
0,
7 }, /* Y */
{
1,
0,
1,
0,
7 }, /* U */
{
2,
0,
1,
0,
7 }, /* V */
},
fillARGB32bufferYUV420p,
};
fillARGB32bufferYUV420p, };
PlaYUVerPixFmtDescriptor yuv422p =
{
@@ -307,12 +290,26 @@ PlaYUVerPixFmtDescriptor yuv422p =
0,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_YUV422P ),
{
{ 0, 0, 1, 0, 7 }, /* Y */
{ 1, 0, 1, 0, 7 }, /* U */
{ 2, 0, 1, 0, 7 }, /* V */
{
0,
0,
1,
0,
7 }, /* Y */
{
1,
0,
1,
0,
7 }, /* U */
{
2,
0,
1,
0,
7 }, /* V */
},
fillARGB32bufferYUV422,
};
fillARGB32bufferYUV422, };
PlaYUVerPixFmtDescriptor yuv444p =
{
@@ -324,12 +321,26 @@ PlaYUVerPixFmtDescriptor yuv444p =
0,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_YUV444P ),
{
{ 0, 0, 1, 0, 7 }, /* Y */
{ 1, 0, 1, 0, 7 }, /* U */
{ 2, 0, 1, 0, 7 }, /* V */
{
0,
0,
1,
0,
7 }, /* Y */
{
1,
0,
1,
0,
7 }, /* U */
{
2,
0,
1,
0,
7 }, /* V */
},
fillARGB32bufferYUV444p,
};
fillARGB32bufferYUV444p, };
PlaYUVerPixFmtDescriptor yuyv422 =
{
@@ -341,12 +352,26 @@ PlaYUVerPixFmtDescriptor yuyv422 =
0,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_YUYV422 ),
{
{ 0, 1, 1, 0, 7 }, /* Y */
{ 0, 3, 2, 0, 7 }, /* U */
{ 0, 3, 4, 0, 7 }, /* V */
{
0,
1,
1,
0,
7 }, /* Y */
{
0,
3,
2,
0,
7 }, /* U */
{
0,
3,
4,
0,
7 }, /* V */
},
fillARGB32bufferYUV422,
};
fillARGB32bufferYUV422, };
PlaYUVerPixFmtDescriptor gray =
{
@@ -357,9 +382,14 @@ PlaYUVerPixFmtDescriptor gray =
0,
0,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_GRAY8 ),
{ { 0, 0, 1, 0, 7 } }, /* Y */
fillARGB32bufferGray,
};
{
{
0,
0,
1,
0,
7 } }, /* Y */
NULL, };
PlaYUVerPixFmtDescriptor RGB24 =
{
@@ -371,12 +401,26 @@ PlaYUVerPixFmtDescriptor RGB24 =
0,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_RGB24 ),
{
{ 0, 2, 1, 0, 7 }, /* R */
{ 0, 2, 2, 0, 7 }, /* G */
{ 0, 2, 3, 0, 7 }, /* B */
{
0,
2,
1,
0,
7 }, /* R */
{
0,
2,
2,
0,
7 }, /* G */
{
0,
2,
3,
0,
7 }, /* B */
},
fillARGB32bufferRGB,
};
NULL, };
PlaYUVerPixFmtDescriptor BGR24 =
{
@@ -388,12 +432,26 @@ PlaYUVerPixFmtDescriptor BGR24 =
0,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_BGR24 ),
{
{ 0, 2, 3, 0, 7 }, /* R */
{ 0, 2, 2, 0, 7 }, /* G */
{ 0, 2, 1, 0, 7 }, /* B */
{
0,
2,
3,
0,
7 }, /* R */
{
0,
2,
2,
0,
7 }, /* G */
{
0,
2,
1,
0,
7 }, /* B */
},
fillARGB32bufferRGB,
};
NULL, };
PlaYUVerPixFmtDescriptor g_PlaYUVerPixFmtDescriptorsList[PLAYUVER_NUMBER_FORMATS] =
{
@@ -403,7 +461,6 @@ PlaYUVerPixFmtDescriptor g_PlaYUVerPixFmtDescriptorsList[PLAYUVER_NUMBER_FORMATS
yuyv422,
gray,
RGB24,
BGR24,
};
BGR24, };
} // NAMESPACE
+1 -1
View File
@@ -156,7 +156,7 @@ typedef struct PlaYUVerPixFmtDescriptor
*/
PlaYUVerComponentDescriptor comp[4];
Void (*fillARGB32buffer)( Pel*** in, UChar* out, UInt width, UInt height );
Void (*fillARGB32buffer)( Pel*** in, UChar* out, UInt width, UInt height, UInt depth );
} PlaYUVerPixFmtDescriptor;