Add new YUV formats

This commit is contained in:
jfmcarreira committed 2014-03-23 19:47:14 +00:00
1 parent a1ba419d2c
commit 83df007fad
6 files changed
+146 -83

No files matched your search

+1 -2
View File
@@ -246,7 +246,6 @@ Void InputStream::readFrame()
return; return;
} }
m_cCurrFrame->FrameFromBuffer( m_pInputBuffer, m_iPixelFormat ); m_cCurrFrame->FrameFromBuffer( m_pInputBuffer, m_iPixelFormat );
return; return;
} }
@@ -289,7 +288,7 @@ Void InputStream::seekInput( Int new_frame_num )
else else
#endif #endif
{ {
UInt64 frame_bytes_input = m_uiWidth * m_uiHeight * 1.5; UInt64 frame_bytes_input = m_cCurrFrame->getBytesPerFrame();
UInt64 nbytes_seek = frame_bytes_input * new_frame_num; UInt64 nbytes_seek = frame_bytes_input * new_frame_num;
fseek( m_pFile, nbytes_seek, SEEK_SET ); fseek( m_pFile, nbytes_seek, SEEK_SET );
m_iCurrFrameNum = new_frame_num - 1; m_iCurrFrameNum = new_frame_num - 1;
+133 -76
View File
@@ -33,7 +33,13 @@ namespace plaYUVer
QStringList PlaYUVerFrame::supportedPixelFormatList() QStringList PlaYUVerFrame::supportedPixelFormatList()
{ {
QStringList formats; QStringList formats;
formats << "yuv420" << "yuv400"; formats << "yuv420p"
<< "yuv444p";
/* << "yuv422p"
<< "yuv410p"
<< "yuv411p"
<< "gray"
<< "rgb8"; */
return formats; return formats;
} }
@@ -50,24 +56,35 @@ PlaYUVerFrame::PlaYUVerFrame( UInt width, UInt height, Int pel_format )
switch( m_iPixelFormat ) switch( m_iPixelFormat )
{ {
case YUV420: case YUV420p:
get_mem2Dpel( &( m_pppcInputPel[0] ), m_uiHeight, m_uiWidth ); get_mem2Dpel( &( m_pppcInputPel[0] ), m_uiHeight, m_uiWidth );
get_mem2Dpel( &( m_pppcInputPel[1] ), m_uiHeight / 2, m_uiWidth / 2 ); get_mem2Dpel( &( m_pppcInputPel[1] ), m_uiHeight / 2, m_uiWidth / 2 );
get_mem2Dpel( &( m_pppcInputPel[2] ), m_uiHeight / 2, m_uiWidth / 2 ); get_mem2Dpel( &( m_pppcInputPel[2] ), m_uiHeight / 2, m_uiWidth / 2 );
break; break;
case YUV422: case YUV444p:
get_mem2Dpel( &( m_pppcInputPel[0] ), m_uiHeight, m_uiWidth );
get_mem2Dpel( &( m_pppcInputPel[1] ), m_uiHeight, m_uiWidth );
get_mem2Dpel( &( m_pppcInputPel[2] ), m_uiHeight, m_uiWidth );
break;
case YUV422p:
get_mem2Dpel( &( m_pppcInputPel[0] ), m_uiHeight, m_uiWidth ); get_mem2Dpel( &( m_pppcInputPel[0] ), m_uiHeight, m_uiWidth );
get_mem2Dpel( &( m_pppcInputPel[1] ), m_uiHeight / 2, m_uiWidth ); get_mem2Dpel( &( m_pppcInputPel[1] ), m_uiHeight / 2, m_uiWidth );
get_mem2Dpel( &( m_pppcInputPel[2] ), m_uiHeight / 2, m_uiWidth ); get_mem2Dpel( &( m_pppcInputPel[2] ), m_uiHeight / 2, m_uiWidth );
break; break;
case YUV400: case YUV410p:
case YUV411p:
get_mem2Dpel( &( m_pppcInputPel[0] ), m_uiHeight, m_uiWidth );
get_mem2Dpel( &( m_pppcInputPel[1] ), m_uiHeight, m_uiWidth );
get_mem2Dpel( &( m_pppcInputPel[2] ), m_uiHeight, m_uiWidth );
break;
case GRAY:
get_mem2Dpel( &( m_pppcInputPel[0] ), m_uiHeight, m_uiWidth ); get_mem2Dpel( &( m_pppcInputPel[0] ), m_uiHeight, m_uiWidth );
break; break;
case RGB: case RGB8:
get_mem3Dpel( &m_pppcRGBPel, 3, m_uiHeight, m_uiWidth ); get_mem3Dpel( &m_pppcRGBPel, 3, m_uiHeight, m_uiWidth );
break; break;
} }
if( m_iPixelFormat != RGB ) if( m_iPixelFormat != RGB8 )
get_mem3Dpel( &m_pppcRGBPel, 3, m_uiHeight, m_uiWidth ); get_mem3Dpel( &m_pppcRGBPel, 3, m_uiHeight, m_uiWidth );
} }
@@ -116,58 +133,77 @@ Void rgbToyuv( T iR, T iG, T iB, T &iY, T &iU, T &iV )
iV = 0; iV = 0;
} }
Void PlaYUVerFrame::YUV420toRGB() Void PlaYUVerFrame::FrametoRGB8()
{ {
Int iY, iU, iV, iR, iG, iB; Int iY, iU, iV, iR, iG, iB;
for( UInt y = 0; y < m_uiHeight; y += 2 )
Pel** ppInputPelY = m_pppcInputPel[0];
Pel* pInputPelY = &(m_pppcInputPel[0][0][0]);
Pel* pInputPelU = &(m_pppcInputPel[1][0][0]);
Pel* pInputPelV = &(m_pppcInputPel[2][0][0]);
Pel* pRGBPelR = &(m_pppcRGBPel[0][0][0]);
Pel* pRGBPelG = &(m_pppcRGBPel[1][0][0]);
Pel* pRGBPelB = &(m_pppcRGBPel[2][0][0]);
switch( m_iPixelFormat )
{ {
for( UInt x = 0; x < m_uiWidth; x += 2 ) case YUV420p:
{ for( UInt y = 0; y < m_uiHeight; y += 2 )
// Pixel (x, y). for( UInt x = 0; x < m_uiWidth; x += 2 )
{
iY = m_pppcInputPel[0][y][x]; // Pixel (x, y).
iU = m_pppcInputPel[1][y >> 1][x >> 1]; iY = ppInputPelY[y][x];
iV = m_pppcInputPel[2][y >> 1][x >> 1]; iU = *pInputPelU++;
iU -= 128; iV = *pInputPelV++;
iV -= 128; iU -= 128;
iV -= 128;
yuvToRgb( iY, iU, iV, iR, iG, iB ); yuvToRgb( iY, iU, iV, iR, iG, iB );
m_pppcRGBPel[0][y][x] = iR;
m_pppcRGBPel[0][y][x] = iR; m_pppcRGBPel[1][y][x] = iG;
m_pppcRGBPel[1][y][x] = iG; m_pppcRGBPel[2][y][x] = iB;
m_pppcRGBPel[2][y][x] = iB; // Pixel (x+1, y)
iY = ppInputPelY[y][x+1];
// Pixel (x+1, y) yuvToRgb( iY, iU, iV, iR, iG, iB );
m_pppcRGBPel[0][y][x + 1] = iR;
iY = m_pppcInputPel[0][y][x + 1]; m_pppcRGBPel[1][y][x + 1] = iG;
m_pppcRGBPel[2][y][x + 1] = iB;
yuvToRgb( iY, iU, iV, iR, iG, iB ); // Pixel (x, y+1)
iY = ppInputPelY[y+1][x];
m_pppcRGBPel[0][y][x + 1] = iR; yuvToRgb( iY, iU, iV, iR, iG, iB );
m_pppcRGBPel[1][y][x + 1] = iG; m_pppcRGBPel[0][y + 1][x] = iR;
m_pppcRGBPel[2][y][x + 1] = iB; m_pppcRGBPel[1][y + 1][x] = iG;
m_pppcRGBPel[2][y + 1][x] = iB;
// Pixel (x, y+1) // Pixel (x+1, y+1)
iY = ppInputPelY[y+1][x+1];
iY = m_pppcInputPel[0][y + 1][x]; yuvToRgb( iY, iU, iV, iR, iG, iB );
m_pppcRGBPel[0][y + 1][x + 1] = iR;
yuvToRgb( iY, iU, iV, iR, iG, iB ); m_pppcRGBPel[1][y + 1][x + 1] = iG;
m_pppcRGBPel[2][y + 1][x + 1] = iB;
m_pppcRGBPel[0][y + 1][x] = iR; }
m_pppcRGBPel[1][y + 1][x] = iG; break;
m_pppcRGBPel[2][y + 1][x] = iB; case YUV444p:
for( UInt y = 0; y < m_uiHeight; y++ )
// Pixel (x+1, y+1) for( UInt x = 0; x < m_uiWidth; x++ )
{
iY = m_pppcInputPel[0][y + 1][x + 1]; iY = *pInputPelY++;
iU = *pInputPelU++;
yuvToRgb( iY, iU, iV, iR, iG, iB ); iV = *pInputPelV++;
iU -= 128;
m_pppcRGBPel[0][y + 1][x + 1] = iR; iV -= 128;
m_pppcRGBPel[1][y + 1][x + 1] = iG; yuvToRgb( iY, iU, iV, iR, iG, iB );
m_pppcRGBPel[2][y + 1][x + 1] = iB; *pRGBPelR++ = iR;
*pRGBPelG++ = iG;
} *pRGBPelB++ = iB;
}
break;
case YUV422p:
case YUV410p:
case YUV411p:
case GRAY:
case RGB8:
default:
// No action.
break;
} }
} }
@@ -180,16 +216,21 @@ Void PlaYUVerFrame::FrameFromBuffer( Pel *input_buffer, Int pel_format )
UInt64 frame_bytes_input = m_uiWidth * m_uiHeight; UInt64 frame_bytes_input = m_uiWidth * m_uiHeight;
switch( m_iPixelFormat ) switch( m_iPixelFormat )
{ {
case YUV420: case YUV420p:
memcpy( &m_pppcInputPel[0][0][0], input_buffer, frame_bytes_input * sizeof(Pel) ); memcpy( &m_pppcInputPel[0][0][0], input_buffer + frame_bytes_input * 0, frame_bytes_input * sizeof(Pel) );
memcpy( &m_pppcInputPel[1][0][0], input_buffer + frame_bytes_input, frame_bytes_input / 4 * sizeof(Pel) ); memcpy( &m_pppcInputPel[1][0][0], input_buffer + frame_bytes_input * 1, frame_bytes_input / 4 * sizeof(Pel) );
memcpy( &m_pppcInputPel[2][0][0], input_buffer + frame_bytes_input * 5 / 4, frame_bytes_input / 4 * sizeof(Pel) ); memcpy( &m_pppcInputPel[2][0][0], input_buffer + frame_bytes_input * 5 / 4, frame_bytes_input / 4 * sizeof(Pel) );
break; break;
case YUV422: case YUV444p:
memcpy( &m_pppcInputPel[0][0][0], input_buffer + frame_bytes_input * 0, frame_bytes_input * sizeof(Pel) );
memcpy( &m_pppcInputPel[1][0][0], input_buffer + frame_bytes_input * 1, frame_bytes_input * sizeof(Pel) );
memcpy( &m_pppcInputPel[2][0][0], input_buffer + frame_bytes_input * 2, frame_bytes_input * sizeof(Pel) );
break; break;
case YUV400: case YUV422p:
break; case YUV410p:
case RGB: case YUV411p:
case GRAY:
case RGB8:
break; break;
} }
} }
@@ -203,17 +244,21 @@ Void PlaYUVerFrame::CopyFrom( PlaYUVerFrame* input_frame )
UInt64 num_bytes = m_uiWidth * m_uiHeight; UInt64 num_bytes = m_uiWidth * m_uiHeight;
switch( m_iPixelFormat ) switch( m_iPixelFormat )
{ {
case YUV420: case YUV420p:
memcpy( &m_pppcInputPel[0][0][0], &( input_frame->getPelBufferYUV()[0][0][0] ), num_bytes * sizeof(Pel) ); memcpy( &m_pppcInputPel[0][0][0], &( input_frame->getPelBufferYUV()[0][0][0] ), num_bytes * sizeof(Pel) );
memcpy( &m_pppcInputPel[1][0][0], &( input_frame->getPelBufferYUV()[1][0][0] ), num_bytes / 4 * sizeof(Pel) ); memcpy( &m_pppcInputPel[1][0][0], &( input_frame->getPelBufferYUV()[1][0][0] ), num_bytes / 4 * sizeof(Pel) );
memcpy( &m_pppcInputPel[2][0][0], &( input_frame->getPelBufferYUV()[2][0][0] ), num_bytes / 4 * sizeof(Pel) ); memcpy( &m_pppcInputPel[2][0][0], &( input_frame->getPelBufferYUV()[2][0][0] ), num_bytes / 4 * sizeof(Pel) );
//YUV420toRGB();
break; break;
case YUV422: case YUV444p:
memcpy( &m_pppcInputPel[0][0][0], &( input_frame->getPelBufferYUV()[0][0][0] ), num_bytes * sizeof(Pel) );
memcpy( &m_pppcInputPel[1][0][0], &( input_frame->getPelBufferYUV()[1][0][0] ), num_bytes * sizeof(Pel) );
memcpy( &m_pppcInputPel[2][0][0], &( input_frame->getPelBufferYUV()[2][0][0] ), num_bytes * sizeof(Pel) );
break; break;
case YUV400: case YUV422p:
break; case YUV410p:
case RGB: case YUV411p:
case GRAY:
case RGB8:
break; break;
} }
} }
@@ -244,16 +289,23 @@ UInt64 PlaYUVerFrame::getBytesPerFrame()
{ {
switch( m_iPixelFormat ) switch( m_iPixelFormat )
{ {
case YUV420: case YUV420p:
return m_uiWidth * m_uiHeight * 1.5; return m_uiWidth * m_uiHeight * 1.5;
break; break;
case YUV422: case YUV444p:
return m_uiWidth * m_uiHeight * 3;
break;
case YUV422p:
return m_uiWidth * m_uiHeight * 2; return m_uiWidth * m_uiHeight * 2;
break; break;
case YUV400: case YUV410p:
case YUV411p:
return 0;
break;
case GRAY:
return m_uiWidth * m_uiHeight; return m_uiWidth * m_uiHeight;
break; break;
case RGB: case RGB8:
return m_uiWidth * m_uiHeight * 3; return m_uiWidth * m_uiHeight * 3;
break; break;
default: default:
@@ -288,25 +340,30 @@ Pixel PlaYUVerFrame::getPixelValue(const QPoint &pos, ColorSpace space)
Pixel pixel_value; Pixel pixel_value;
switch( m_iPixelFormat ) switch( m_iPixelFormat )
{ {
case YUV420: case YUV420p:
pixel_value.color_space = COLOR_YUV; pixel_value.color_space = COLOR_YUV;
pixel_value.Luma = m_pppcInputPel[LUMA][pos.y()][pos.x()]; pixel_value.Luma = m_pppcInputPel[LUMA][pos.y()][pos.x()];
pixel_value.ChromaU = m_pppcInputPel[CHROMA_U][pos.y()>>1][pos.x()>>1]; pixel_value.ChromaU = m_pppcInputPel[CHROMA_U][pos.y()>>1][pos.x()>>1];
pixel_value.ChromaV = m_pppcInputPel[CHROMA_V][pos.y()>>1][pos.x()>>1]; pixel_value.ChromaV = m_pppcInputPel[CHROMA_V][pos.y()>>1][pos.x()>>1];
break; break;
case YUV422: case YUV444p:
pixel_value.Luma = m_pppcInputPel[LUMA][pos.y()][pos.x()];
pixel_value.ChromaU = m_pppcInputPel[CHROMA_U][pos.y()][pos.x()];
pixel_value.ChromaV = m_pppcInputPel[CHROMA_V][pos.y()][pos.x()];
break;
case YUV422p:
pixel_value.color_space = COLOR_YUV; pixel_value.color_space = COLOR_YUV;
pixel_value.Luma = m_pppcInputPel[LUMA][pos.y()][pos.x()]; pixel_value.Luma = m_pppcInputPel[LUMA][pos.y()][pos.x()];
pixel_value.ChromaU = m_pppcInputPel[CHROMA_U][pos.y()][pos.x()>>1]; pixel_value.ChromaU = m_pppcInputPel[CHROMA_U][pos.y()][pos.x()>>1];
pixel_value.ChromaV = m_pppcInputPel[CHROMA_V][pos.y()][pos.x()>>1]; pixel_value.ChromaV = m_pppcInputPel[CHROMA_V][pos.y()][pos.x()>>1];
break; break;
case YUV400: case GRAY:
pixel_value.color_space = COLOR_YUV; pixel_value.color_space = COLOR_YUV;
pixel_value.Luma = m_pppcInputPel[LUMA][pos.y()][pos.x()]; pixel_value.Luma = m_pppcInputPel[LUMA][pos.y()][pos.x()];
pixel_value.ChromaU = 0; pixel_value.ChromaU = 0;
pixel_value.ChromaV = 0; pixel_value.ChromaV = 0;
break; break;
case RGB: case RGB8:
pixel_value.color_space = COLOR_RGB; pixel_value.color_space = COLOR_RGB;
pixel_value.ColorR = m_pppcInputPel[COLOR_R][pos.y()][pos.x()]; pixel_value.ColorR = m_pppcInputPel[COLOR_R][pos.y()][pos.x()];
pixel_value.ColorG = m_pppcInputPel[COLOR_G][pos.y()][pos.x()]; pixel_value.ColorG = m_pppcInputPel[COLOR_G][pos.y()][pos.x()];
+1 -1
View File
@@ -46,7 +46,7 @@ public:
static QStringList supportedPixelFormatList(); static QStringList supportedPixelFormatList();
Void YUV420toRGB(); Void FrametoRGB8();
Void FrameFromBuffer( Pel *input_buffer, Int pel_format ); Void FrameFromBuffer( Pel *input_buffer, Int pel_format );
Void CopyFrom( PlaYUVerFrame* ); Void CopyFrom( PlaYUVerFrame* );
+1 -1
View File
@@ -152,7 +152,7 @@ QImage* SubWindowHandle::FrameToQImage( PlaYUVerFrame* curr_frame )
{ {
Pel*** bufferRGB = curr_frame->getPelBufferRGB(); Pel*** bufferRGB = curr_frame->getPelBufferRGB();
curr_frame->YUV420toRGB(); curr_frame->FrametoRGB8();
for( UInt y = 0; y < curr_frame->getHeight(); y++ ) for( UInt y = 0; y < curr_frame->getHeight(); y++ )
{ {
+8 -1
View File
@@ -112,7 +112,14 @@ typedef UChar Pel; ///< 8-bit pixel type
enum InputStreamColorSpace enum InputStreamColorSpace
{ {
NO_FMT = -1, YUV420, YUV400, YUV422, RGB, NO_FMT = -1,
YUV420p,
YUV444p,
YUV422p,
YUV410p,
YUV411p,
GRAY,
RGB8,
}; };
enum ColorSpace enum ColorSpace
+2 -2
View File
@@ -110,7 +110,7 @@ Bool LibAvContextHandle::initAvFormat( char* filename, UInt& width, UInt& height
{ {
case NO_FMT: case NO_FMT:
break; break;
case YUV420: case YUV420p:
av_dict_set( &format_opts, "pixel_format", av_get_pix_fmt_name( AV_PIX_FMT_YUV420P ), 0 ); av_dict_set( &format_opts, "pixel_format", av_get_pix_fmt_name( AV_PIX_FMT_YUV420P ), 0 );
break; break;
case YUV400: case YUV400:
@@ -174,7 +174,7 @@ Bool LibAvContextHandle::initAvFormat( char* filename, UInt& width, UInt& height
switch( video_dec_ctx->pix_fmt ) switch( video_dec_ctx->pix_fmt )
{ {
case AV_PIX_FMT_YUV420P: case AV_PIX_FMT_YUV420P:
pixel_format = YUV420; pixel_format = YUV420p;
break; break;
case AV_PIX_FMT_GRAY8: case AV_PIX_FMT_GRAY8:
pixel_format = YUV400; pixel_format = YUV400;