diff --git a/lib/PlaYUVerFrame.cpp b/lib/PlaYUVerFrame.cpp index 32dfad3..37be54f 100644 --- a/lib/PlaYUVerFrame.cpp +++ b/lib/PlaYUVerFrame.cpp @@ -197,14 +197,13 @@ 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_uiWidthBytes, 1, 1 ); + getMem3ImageComponents( &m_pppcInputPel, m_uiHeight, m_uiWidth, 1, 1 ); } else { - getMem3ImageComponents( &m_pppcInputPel, m_uiHeight, m_uiWidthBytes, m_pcPelFormat->log2ChromaHeight, m_pcPelFormat->log2ChromaWidth ); + getMem3ImageComponents( &m_pppcInputPel, m_uiHeight, m_uiWidth, m_pcPelFormat->log2ChromaHeight, m_pcPelFormat->log2ChromaWidth ); } getMem1D( &m_pcARGB32, m_uiHeight * m_uiWidth * 4 ); @@ -265,14 +264,14 @@ Void PlaYUVerFrame::frameFromBuffer( Byte *Buff, UInt64 uiBuffSize ) Pel* pTmpPel; UInt bytesPixel = ( m_iBitsPel - 1 ) / 8 + 1; Int ratioH, ratioW, step; - UInt i, ch; + UInt i, ch, b; ppBuff[0] = Buff; - for( Int i = 1; i < MAX_NUMBER_PLANES; i++ ) + for( i = 1; i < MAX_NUMBER_PLANES; i++ ) { ratioW = i > 1 ? m_pcPelFormat->log2ChromaWidth : 0; ratioH = i > 1 ? m_pcPelFormat->log2ChromaHeight : 0; - ppBuff[i] = ppBuff[i - 1] + CHROMASHIFT( m_uiHeight, ratioH ) * CHROMASHIFT( m_uiWidth, ratioW ); + ppBuff[i] = ppBuff[i - 1] + CHROMASHIFT( m_uiHeight, ratioH ) * CHROMASHIFT( m_uiWidth, ratioW ) * bytesPixel; } for( ch = 0; ch < m_pcPelFormat->numberChannels; ch++ ) @@ -286,7 +285,14 @@ Void PlaYUVerFrame::frameFromBuffer( Byte *Buff, UInt64 uiBuffSize ) for( i = 0; i < CHROMASHIFT( m_uiHeight, ratioH ) * CHROMASHIFT( m_uiWidth, ratioW ); i++ ) { - *pTmpPel++ = *pTmpBuff; + *pTmpPel = 0; + for( b = 0; b < bytesPixel; b++ ) + { + *pTmpPel = ( *pTmpPel << ( m_iBitsPel - 8 * b ) ); + *pTmpPel += *pTmpBuff++; + } + pTmpBuff--; + pTmpPel++; pTmpBuff += step; } } @@ -362,9 +368,47 @@ Void PlaYUVerFrame::fillRGBBuffer() *pARGB++ = PEL_RGB( iR, iG, iB ); } } - else + else if( m_pcPelFormat->colorSpace == COLOR_YUV ) { - m_pcPelFormat->fillARGB32buffer( m_pppcInputPel, m_pcARGB32, m_uiWidth, m_uiHeight, bytesPixel ); + Int shiftBits = m_iBitsPel - 8; + Pel* pLineY = m_pppcInputPel[LUMA][0]; + Pel* pLineU = m_pppcInputPel[CHROMA_U][0]; + Pel* pLineV = m_pppcInputPel[CHROMA_V][0]; + UInt uiChromaStride = CHROMASHIFT( m_uiWidth, m_pcPelFormat->log2ChromaWidth ); + Pel* pY; + Pel* pU; + Pel* pV; + Int iY, iU, iV, iR, iG, iB; + UInt* pARGBLine = pARGB; + UInt* pARGB; + + UInt y, x; + Int i, j; + for( y = 0; y < m_uiHeight >> m_pcPelFormat->log2ChromaHeight; y++ ) + { + for( i = 0; i < 1 << m_pcPelFormat->log2ChromaHeight; i++ ) + { + pY = pLineY; + pU = pLineU; + pV = pLineV; + pARGB = pARGBLine; + for( x = 0; x < m_uiWidth >> m_pcPelFormat->log2ChromaWidth; x++ ) + { + iU = ( *pU++ ) >> shiftBits; + iV = ( *pV++ ) >> shiftBits; + for( j = 0; j < ( 1 << m_pcPelFormat->log2ChromaWidth ); j++ ) + { + iY = *pY++ >> shiftBits; + YUV2RGB( iY, iU, iV, iR, iG, iB ); + *pARGB++ = PEL_RGB( iR, iG, iB ); + } + } + pLineY += m_uiWidth; + pARGBLine += m_uiWidth; + } + pLineU += uiChromaStride; + pLineV += uiChromaStride; + } } m_bHasRGBPel = true; } diff --git a/lib/PlaYUVerFramePixelFormats.cpp b/lib/PlaYUVerFramePixelFormats.cpp index ae8a8bc..a916622 100644 --- a/lib/PlaYUVerFramePixelFormats.cpp +++ b/lib/PlaYUVerFramePixelFormats.cpp @@ -52,46 +52,7 @@ namespace plaYUVer #define ADD_FFMPEG_PEL_FMT( fmt ) 0 #endif -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]; - Pel* pLineV = in[CHROMA_V][0]; - UInt uiChromaStride = CHROMASHIFT( width, ratioChromaHor ); - Pel* pY; - Pel* pU; - Pel* pV; - Int iY, iU, iV, iR, iG, iB; - UInt* pARGBLine = ( UInt* )out; - UInt* pARGB; - - for( UInt y = 0; y < height >> ratioChromaVer; y++ ) - { - for( Int i = 0; i < 1 << ratioChromaVer; i++ ) - { - pY = pLineY; - pU = pLineU; - pV = pLineV; - pARGB = pARGBLine; - for( UInt x = 0; x < width >> ratioChromaHor; x++ ) - { - iU = *pU++; - iV = *pV++; - for( Int j = 0; j < ( 1 << ratioChromaHor ) * depth; j++ ) - { - iY = *pY++; - YUV2RGB( iY, iU, iV, iR, iG, iB ); - *pARGB++ = PEL_RGB( iR, iG, iB ); - } - } - pLineY += width; - pARGBLine += width; - } - pLineU += uiChromaStride; - pLineV += uiChromaStride; - } -} - +#if 0 Void fillARGB32bufferYUV420p( Pel*** in, UChar* out, UInt width, UInt height, UInt depth ) { #ifdef USE_SSE @@ -238,16 +199,7 @@ Void fillARGB32bufferYUV420p( Pel*** in, UChar* out, UInt width, UInt height, UI fillARGB32bufferYUV( in, out, width, height, depth, 1, 1 ); } } - -Void fillARGB32bufferYUV444p( Pel*** in, UChar* out, UInt width, UInt height, UInt depth ) -{ - fillARGB32bufferYUV( in, out, width, height, depth, 0, 0 ); -} - -Void fillARGB32bufferYUV422( Pel*** in, UChar* out, UInt width, UInt height, UInt depth ) -{ - fillARGB32bufferYUV( in, out, width, height, depth, 1, 0 ); -} +#endif PlaYUVerPixFmtDescriptor yuv420p = { @@ -259,26 +211,11 @@ 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, }; +}; PlaYUVerPixFmtDescriptor yuv422p = { @@ -290,26 +227,11 @@ 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, }; +}; PlaYUVerPixFmtDescriptor yuv444p = { @@ -321,26 +243,11 @@ 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, }; +}; PlaYUVerPixFmtDescriptor yuyv422 = { @@ -352,26 +259,11 @@ 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, }; +}; PlaYUVerPixFmtDescriptor gray = { @@ -382,14 +274,8 @@ PlaYUVerPixFmtDescriptor gray = 0, 0, ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_GRAY8 ), - { - { - 0, - 0, - 1, - 0, - 7 } }, /* Y */ - NULL, }; + { { 0, 0, 1, 0, 7 } }, /* Y */ +}; PlaYUVerPixFmtDescriptor RGB24 = { @@ -401,26 +287,11 @@ 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 */ }, - NULL, }; +}; PlaYUVerPixFmtDescriptor BGR24 = { @@ -432,26 +303,11 @@ 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 */ }, - NULL, }; +}; PlaYUVerPixFmtDescriptor g_PlaYUVerPixFmtDescriptorsList[PLAYUVER_NUMBER_FORMATS] = { @@ -461,6 +317,6 @@ PlaYUVerPixFmtDescriptor g_PlaYUVerPixFmtDescriptorsList[PLAYUVER_NUMBER_FORMATS yuyv422, gray, RGB24, - BGR24, }; - + BGR24, +}; } // NAMESPACE diff --git a/lib/PlaYUVerFramePixelFormats.h b/lib/PlaYUVerFramePixelFormats.h index c84c71e..deede8b 100644 --- a/lib/PlaYUVerFramePixelFormats.h +++ b/lib/PlaYUVerFramePixelFormats.h @@ -156,8 +156,6 @@ typedef struct PlaYUVerPixFmtDescriptor */ PlaYUVerComponentDescriptor comp[4]; - Void (*fillARGB32buffer)( Pel*** in, UChar* out, UInt width, UInt height, UInt depth ); - } PlaYUVerPixFmtDescriptor; #define MAX_NUMBER_PLANES 3