Major improvements and generalization of the frame from/to buffer based on ffmpeg enfort

This commit is contained in:
jfmcarreira committed 2015-03-05 22:47:36 +00:00
1 parent 2b749e3da0
commit 379d13a8ed
6 files changed
+275 -256

No files matched your search

+101 -201
View File
@@ -51,26 +51,6 @@ namespace plaYUVer
#define ADD_FFMPEG_PEL_FMT( fmt ) 0
#endif
/**
* YUV Formats
* Progressive and interlaces
*/
Void frameFromBufferYUVProgressive( Pel* in, Pel ***out, UInt width, UInt height, UInt ratioChromaWidth, UInt ratioChromaHeight )
{
UInt64 chromaSize = CHROMASHIFT( width, ratioChromaWidth ) * CHROMASHIFT( height, ratioChromaHeight );
memcpy( &out[LUMA][0][0], in, width * height * sizeof(Pel) );
memcpy( &out[CHROMA_U][0][0], in + width * height, chromaSize * sizeof(Pel) );
memcpy( &out[CHROMA_V][0][0], in + width * height + chromaSize, chromaSize * sizeof(Pel) );
}
Void bufferFromFrameYUVProgressive( Pel*** in, Pel *out, UInt width, UInt height, UInt ratioChromaWidth, UInt ratioChromaHeight )
{
UInt64 chromaSize = CHROMASHIFT( width, ratioChromaWidth ) * CHROMASHIFT( height, ratioChromaHeight );
memcpy( out, &in[LUMA][0][0], width * height * sizeof(Pel) );
memcpy( out + width * height, &in[CHROMA_U][0][0], chromaSize * sizeof(Pel) );
memcpy( out + width * height + chromaSize, &in[CHROMA_V][0][0], chromaSize * sizeof(Pel) );
}
Void fillARGB32bufferYUV( Pel*** in, UChar* out, UInt width, UInt height, UInt ratioChromaHor, UInt ratioChromaVer )
{
@@ -112,18 +92,6 @@ Void fillARGB32bufferYUV( Pel*** in, UChar* out, UInt width, UInt height, UInt r
}
}
/**
* YUV420p 12 bits per pixel
*/
Void frameFromBufferYUV420p( Pel *in, Pel*** out, UInt width, UInt height )
{
frameFromBufferYUVProgressive( in, out, width, height, 1, 1 );
}
Void bufferFromFrameYUV420p( Pel ***in, Pel* out, UInt width, UInt height )
{
bufferFromFrameYUVProgressive( in, out, width, height, 1, 1 );
}
Void fillARGB32bufferYUV420p( Pel*** in, UChar* out, UInt width, UInt height )
{
#ifdef USE_SSE
@@ -271,128 +239,23 @@ Void fillARGB32bufferYUV420p( Pel*** in, UChar* out, UInt width, UInt height )
}
}
PlaYUVerFramePelFormat yuv420p =
{
"YUV420p",
PlaYUVerFrame::COLOR_YUV,
3,
2,
2,
frameFromBufferYUV420p,
bufferFromFrameYUV420p,
fillARGB32bufferYUV420p,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_YUV420P ), };
/**
* YUV444p 24 bits per pixel
*/
Void frameFromBufferYUV444p( Pel *in, Pel*** out, UInt width, UInt height )
{
frameFromBufferYUVProgressive( in, out, width, height, 0, 0 );
}
Void bufferFromFrameYUV444p( Pel ***in, Pel* out, UInt width, UInt height )
{
bufferFromFrameYUVProgressive( in, out, width, height, 0, 0 );
}
Void fillARGB32bufferYUV444p( Pel*** in, UChar* out, UInt width, UInt height )
{
fillARGB32bufferYUV( in, out, width, height, 0, 0 );
}
PlaYUVerFramePelFormat yuv444p =
{
"YUV444p",
PlaYUVerFrame::COLOR_YUV,
3,
1,
1,
frameFromBufferYUV444p,
bufferFromFrameYUV444p,
fillARGB32bufferYUV444p,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_YUV444P ), };
/**
* YUV422p 16 bits per pixel
*/
Void frameFromBufferYUV422p( Pel *in, Pel*** out, UInt width, UInt height )
{
frameFromBufferYUVProgressive( in, out, width, height, 1, 0 );
}
Void bufferFromFrameYUV422p( Pel ***in, Pel* out, UInt width, UInt height )
{
bufferFromFrameYUVProgressive( in, out, width, height, 1, 0 );
}
Void fillARGB32bufferYUV422( Pel*** in, UChar* out, UInt width, UInt height )
{
fillARGB32bufferYUV( in, out, width, height, 1, 0 );
}
PlaYUVerFramePelFormat yuv422p =
{
"YUV422p",
PlaYUVerFrame::COLOR_YUV,
3,
2,
1,
frameFromBufferYUV422p,
bufferFromFrameYUV422p,
fillARGB32bufferYUV422,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_YUV422P ), };
/**
* YUYV422 16 bits per pixel
*/
Void frameFromBufferYUYV422( Pel *in, Pel*** out, UInt width, UInt height )
{
Pel* pY = out[LUMA][0];
Pel* pU = out[CHROMA_U][0];
Pel* pV = out[CHROMA_V][0];
for( UInt i = 0; i < width * height / 2; i++ )
{
*pY++ = *in++;
*pU++ = *in++;
*pY++ = *in++;
*pV++ = *in++;
}
}
Void bufferFromFrameYUYV422( Pel ***in, Pel* out, UInt width, UInt height )
{
Pel* pY = in[LUMA][0];
Pel* pU = in[CHROMA_U][0];
Pel* pV = in[CHROMA_V][0];
for( UInt i = 0; i < height * width / 2; i++ )
{
*out++ = *pY++;
*out++ = *pU++;
*out++ = *pY++;
*out++ = *pV++;
}
}
PlaYUVerFramePelFormat yuyv422 =
{
"YUYV422",
PlaYUVerFrame::COLOR_YUV,
3,
2,
1,
frameFromBufferYUYV422,
bufferFromFrameYUYV422,
fillARGB32bufferYUV422,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_YUYV422 ), };
/**
* Gray Format
*/
Void frameFromBufferGray( Pel *in, Pel*** out, UInt width, UInt height )
{
memcpy( &out[LUMA][0][0], in, width * height * sizeof(Pel) );
}
Void bufferFromFrameGray( Pel ***in, Pel* out, UInt width, UInt height )
{
memcpy( out, &in[LUMA][0][0], width * height * sizeof(Pel) );
}
Void fillARGB32bufferGray( Pel*** in, UChar* out, UInt width, UInt height )
{
Pel *inPel = in[0][0];
@@ -405,41 +268,7 @@ Void fillARGB32bufferGray( Pel*** in, UChar* out, UInt width, UInt height )
inPel++;
}
}
PlaYUVerFramePelFormat gray =
{
"GRAY",
PlaYUVerFrame::COLOR_GRAY,
1,
0,
0,
frameFromBufferGray,
bufferFromFrameGray,
fillARGB32bufferGray,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_GRAY8 ), };
/**
* RGB formats
* Interlaced
*/
Void frameFromBufferRGB( Pel *in, Pel*** out, UInt64 size, Pel* pFirst, Pel* pSecond, Pel* pthird )
{
for( UInt i = 0; i < size; i++ )
{
*pFirst++ = *in++;
*pSecond++ = *in++;
*pthird++ = *in++;
}
}
Void bufferFromFrameRGB( Pel ***in, Pel* out, UInt64 size, Pel* pFirst, Pel* pSecond, Pel* pthird )
{
for( UInt i = 0; i < size; i++ )
{
*out++ = *pFirst++;
*out++ = *pSecond++;
*out++ = *pthird++;
}
}
Void fillARGB32bufferRGB( Pel*** in, UChar* out, UInt width, UInt height )
{
Pel* pR = in[COLOR_R][0];
@@ -456,51 +285,122 @@ Void fillARGB32bufferRGB( Pel*** in, UChar* out, UInt width, UInt height )
}
}
/** RGB 8 bits per pixel / 3 channels */
Void frameFromBufferRGB24( Pel *in, Pel*** out, UInt width, UInt height )
PlaYUVerPixFmtDescriptor yuv420p =
{
frameFromBufferRGB( in, out, width * height, out[COLOR_R][0], out[COLOR_G][0], out[COLOR_B][0] );
}
Void bufferFromFrameRGB24( Pel ***in, Pel* out, UInt width, UInt height )
{
bufferFromFrameRGB( in, out, width * height, in[COLOR_R][0], in[COLOR_G][0], in[COLOR_B][0] );
}
"YUV420p",
PlaYUVerFrame::COLOR_YUV,
3,
3,
1,
1,
fillARGB32bufferYUV420p,
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 */
},
};
PlaYUVerFramePelFormat RGB24 =
PlaYUVerPixFmtDescriptor yuv422p =
{
"YUV422p",
PlaYUVerFrame::COLOR_YUV,
3,
3,
1,
0,
fillARGB32bufferYUV422,
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 */
},
};
PlaYUVerPixFmtDescriptor yuv444p =
{
"YUV444p",
PlaYUVerFrame::COLOR_YUV,
3,
3,
0,
0,
fillARGB32bufferYUV444p,
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 */
},
};
PlaYUVerPixFmtDescriptor yuyv422 =
{
"YUYV422",
PlaYUVerFrame::COLOR_YUV,
3,
1,
1,
0,
fillARGB32bufferYUV422,
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 */
},
};
PlaYUVerPixFmtDescriptor gray =
{
"GRAY",
PlaYUVerFrame::COLOR_GRAY,
1,
1,
0,
0,
fillARGB32bufferGray,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_GRAY8 ),
{ { 0, 0, 1, 0, 7 } }, /* Y */
};
PlaYUVerPixFmtDescriptor RGB24 =
{
"RGB24",
PlaYUVerFrame::COLOR_RGB,
3,
1,
1,
frameFromBufferRGB24,
bufferFromFrameRGB24,
0,
0,
fillARGB32bufferRGB,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_RGB24 ), };
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 */
},
};
/** BGR 8 bits per pixel / 3 channels */
Void frameFromBufferBGR24( Pel *in, Pel*** out, UInt width, UInt height )
{
frameFromBufferRGB( in, out, width * height, out[COLOR_B][0], out[COLOR_G][0], out[COLOR_R][0] );
}
Void bufferFromFrameBGR24( Pel ***in, Pel* out, UInt width, UInt height )
{
bufferFromFrameRGB( in, out, width * height, in[COLOR_B][0], in[COLOR_G][0], in[COLOR_R][0] );
}
PlaYUVerFramePelFormat BGR24 =
PlaYUVerPixFmtDescriptor BGR24 =
{
"BRG24",
PlaYUVerFrame::COLOR_RGB,
3,
1,
1,
frameFromBufferBGR24,
bufferFromFrameBGR24,
0,
0,
fillARGB32bufferRGB,
ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_BGR24 ), };
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 */
},
};
PlaYUVerFramePelFormat g_PlaYUVerFramePelFormatsList[PLAYUVER_NUMBER_FORMATS] =
PlaYUVerPixFmtDescriptor g_PlaYUVerPixFmtDescriptorsList[PLAYUVER_NUMBER_FORMATS] =
{
yuv420p,
yuv444p,