Add new class PlaYUVerPixel

This commit is contained in:
2016-03-10 00:13:44 +00:00
parent 6841e57135
commit 201a2ebdd6
10 changed files with 258 additions and 162 deletions
+5 -5
View File
@@ -290,7 +290,7 @@ Void FramePropertiesDock::setFrame( PlaYUVerFrame* pcFrame )
if( m_iLastFrameType != colorSpace )
{
m_iLastFrameType = colorSpace;
if( colorSpace == PlaYUVerFrame::COLOR_RGB || colorSpace == PlaYUVerFrame::COLOR_ARGB )
if( colorSpace == PlaYUVerPixel::COLOR_RGB || colorSpace == PlaYUVerPixel::COLOR_ARGB )
{
channelCB->clear();
channelCB->clear();
@@ -298,7 +298,7 @@ Void FramePropertiesDock::setFrame( PlaYUVerFrame* pcFrame )
channelCB->insertItem( FirstChannel, QIcon( ":/images/channel-red.png" ), "Red" );
channelCB->insertItem( SecondChannel, QIcon( ":/images/channel-green.png" ), "Green" );
channelCB->insertItem( ThirdChannel, QIcon( ":/images/channel-blue.png" ), "Blue" );
if( colorSpace == PlaYUVerFrame::COLOR_ARGB )
if( colorSpace == PlaYUVerPixel::COLOR_ARGB )
{
channelCB->insertItem( AlphaChannel, QIcon( ":/images/channel-alpha.png" ), "Alpha" );
}
@@ -316,7 +316,7 @@ Void FramePropertiesDock::setFrame( PlaYUVerFrame* pcFrame )
colorsCB->show();
colorsLabel->show();
}
else if( colorSpace == PlaYUVerFrame::COLOR_YUV )
else if( colorSpace == PlaYUVerPixel::COLOR_YUV )
{
channelCB->clear();
channelCB->insertItem( FirstChannel, QIcon( ":/images/channel-luma.png" ), "Luminance" );
@@ -500,9 +500,9 @@ Void FramePropertiesDock::slotHistogramComputationFailed()
Void FramePropertiesDock::slotChannelChanged( Int channel )
{
if( m_pcFrame->getColorSpace() == PlaYUVerFrame::COLOR_YUV )
if( m_pcFrame->getColorSpace() == PlaYUVerPixel::COLOR_YUV )
channel += 1;
if( channel == AlphaChannel && m_pcFrame->getColorSpace() != PlaYUVerFrame::COLOR_ARGB )
if( channel == AlphaChannel && m_pcFrame->getColorSpace() != PlaYUVerPixel::COLOR_ARGB )
channel = ColorChannels;
switch( channel )
+4 -4
View File
@@ -903,7 +903,7 @@ Void VideoSubWindow::updatePixelValueStatusBar( const QPoint& pos )
{
if( m_pcCurrFrame )
{
PlaYUVerFrame::Pixel sPixelValue;
PlaYUVerPixel sPixelValue;
Int iWidth, iHeight;
Int posX = pos.x();
Int posY = pos.y();
@@ -917,18 +917,18 @@ Void VideoSubWindow::updatePixelValueStatusBar( const QPoint& pos )
strStatus = QString( "(%1,%2) " ).arg( posX ).arg( posY );
Int ColorSpace = m_pcCurrFrame->getColorSpace();
if( ColorSpace == PlaYUVerFrame::COLOR_GRAY )
if( ColorSpace == PlaYUVerPixel::COLOR_GRAY )
{
sPixelValue = m_pcCurrFrame->getPixelValue( pos.x(), pos.y() );
strStatus.append( QString( "Y: %1" ).arg( sPixelValue.Y() ) );
}
if( ColorSpace == PlaYUVerFrame::COLOR_YUV )
if( ColorSpace == PlaYUVerPixel::COLOR_YUV )
{
sPixelValue = m_pcCurrFrame->getPixelValue( pos.x(), pos.y() );
strStatus.append( QString( "Y: %1 U: %2 V: %3" ).arg( sPixelValue.Y() ).arg( sPixelValue.Cb() ).arg( sPixelValue.Cr() ) );
}
if( ( ColorSpace == PlaYUVerFrame::COLOR_RGB ) )
if( ( ColorSpace == PlaYUVerPixel::COLOR_RGB ) )
{
sPixelValue = m_pcCurrFrame->getPixelValue( pos.x(), pos.y() );
strStatus.append( QString( "R: %1 G: %2 B: %3" ).arg( sPixelValue.R() ).arg( sPixelValue.G() ).arg( sPixelValue.B() ) );
+4 -4
View File
@@ -482,7 +482,7 @@ Void ViewArea::paintEvent( QPaintEvent *event )
{
Int imageWidth = m_pixmap.width();
Int imageHeight = m_pixmap.height();
PlaYUVerFrame::Pixel sPixelValue;
PlaYUVerPixel sPixelValue;
QFont font( "Helvetica" );
font.setPixelSize( 12 );
@@ -501,7 +501,7 @@ Void ViewArea::paintEvent( QPaintEvent *event )
Int frFormat = m_pcCurrFrame->getColorSpace();
if( frFormat == PlaYUVerFrame::COLOR_YUV )
if( frFormat == PlaYUVerPixel::COLOR_YUV )
{
sPixelValue = m_pcCurrFrame->getPixelValue( pixelTopLeft.x(), pixelTopLeft.y() );
@@ -514,7 +514,7 @@ Void ViewArea::paintEvent( QPaintEvent *event )
"Y: " + QString::number( sPixelValue.Y() ) + "\n" + "U: " + QString::number( sPixelValue.Cb() ) + "\n" + "V: "
+ QString::number( sPixelValue.Cr() ) );
}
if( frFormat == PlaYUVerFrame::COLOR_GRAY )
if( frFormat == PlaYUVerPixel::COLOR_GRAY )
{
sPixelValue = m_pcCurrFrame->getPixelValue( pixelTopLeft.x(), pixelTopLeft.y() );
@@ -526,7 +526,7 @@ Void ViewArea::paintEvent( QPaintEvent *event )
paInter.drawText( pixelRect, Qt::AlignCenter, "Y: " + QString::number( sPixelValue.Y() ) );
}
if( ( frFormat == PlaYUVerFrame::COLOR_RGB ) )
if( ( frFormat == PlaYUVerPixel::COLOR_RGB ) )
{
sPixelValue = m_pcCurrFrame->getPixelValue( pixelTopLeft.x(), pixelTopLeft.y() );
+1
View File
@@ -7,6 +7,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} )
set(PlaYUVer_Lib_SRCS
# Frame
PlaYUVerFrame.cpp
PlaYUVerPixel.cpp
PlaYUVerFramePixelFormats.cpp
# PlaYUVerFrameStats.cpp
# Stream
+29 -45
View File
@@ -74,31 +74,6 @@ std::vector<std::string> PlaYUVerFrame::supportedPixelFormatListNames( Int color
return formatsList;
}
PlaYUVerFrame::Pixel PlaYUVerFrame::ConvertPixel( Pixel inputPixel, ColorSpace eOutputSpace )
{
Int outA, outB, outC;
PlaYUVerFrame::Pixel outPixel( COLOR_INVALID, 0, 0, 0 );
if( inputPixel.ColorSpace() == eOutputSpace || eOutputSpace == COLOR_ARGB || eOutputSpace == COLOR_GRAY )
return inputPixel;
if( eOutputSpace == COLOR_RGB )
{
YUV2RGB( inputPixel.Y(), inputPixel.Cb(), inputPixel.Cr(), outA, outB, outC );
outPixel.R() = outA;
outPixel.G() = outB;
outPixel.B() = outC;
}
if( eOutputSpace == COLOR_YUV )
{
rgbToYuv( inputPixel.R(), inputPixel.G(), inputPixel.B(), outA, outB, outC );
outPixel.Y() = outA;
outPixel.Cb() = outB;
outPixel.Cr() = outC;
}
return outPixel;
}
PlaYUVerFrame::PlaYUVerFrame( UInt width, UInt height, Int pelFormat, Int bitsPixel )
{
init( width, height, pelFormat, bitsPixel );
@@ -207,7 +182,7 @@ Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format, Int bitsPixel
m_pcPelFormat = &( g_PlaYUVerPixFmtDescriptorsList[pel_format] );
m_bHasRGBPel = false;
if( m_pcPelFormat->colorSpace == COLOR_GRAY )
if( m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_GRAY )
{
getMem3ImageComponents( &m_pppcInputPel, m_uiHeight, m_uiWidth, 1, 1 );
}
@@ -222,7 +197,7 @@ Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format, Int bitsPixel
m_uiHistoSegments = 1 << m_uiBitsPel;
if( m_pcPelFormat->colorSpace == PlaYUVerFrame::COLOR_RGB || m_pcPelFormat->colorSpace == PlaYUVerFrame::COLOR_ARGB )
if( m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_RGB || m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_ARGB )
m_uiHistoChannels = m_pcPelFormat->numberChannels + 1;
else
m_uiHistoChannels = m_pcPelFormat->numberChannels;
@@ -343,19 +318,28 @@ UInt PlaYUVerFrame::getChromaSize() const
return getChromaWidth() * getChromaHeight();
}
PlaYUVerFrame::Pixel PlaYUVerFrame::getPixelValue( Int xPos, Int yPos, ColorSpace eColorSpace )
PlaYUVerPixel PlaYUVerFrame::getPixelValue( Int xPos, Int yPos )
{
PlaYUVerFrame::Pixel PixelValue( m_pcPelFormat->colorSpace, 0, 0, 0 );
PlaYUVerPixel PixelValue( m_pcPelFormat->colorSpace, 0, 0, 0 );
for( UInt ch = 0; ch < m_pcPelFormat->numberChannels; ch++ )
{
Int ratioH = ch > 0 ? m_pcPelFormat->log2ChromaWidth : 0;
Int ratioW = ch > 0 ? m_pcPelFormat->log2ChromaHeight : 0;
PixelValue.Components()[ch] = m_pppcInputPel[ch][( yPos >> ratioH )][( xPos >> ratioW )];
}
if( eColorSpace != COLOR_INVALID )
return PixelValue;
}
PlaYUVerPixel PlaYUVerFrame::getPixelValue( Int xPos, Int yPos, PlaYUVerPixel::ColorSpace eColorSpace )
{
PlaYUVerPixel PixelValue( m_pcPelFormat->colorSpace, 0, 0, 0 );
for( UInt ch = 0; ch < m_pcPelFormat->numberChannels; ch++ )
{
PixelValue = ConvertPixel( PixelValue, eColorSpace );
Int ratioH = ch > 0 ? m_pcPelFormat->log2ChromaWidth : 0;
Int ratioW = ch > 0 ? m_pcPelFormat->log2ChromaHeight : 0;
PixelValue.Components()[ch] = m_pppcInputPel[ch][( yPos >> ratioH )][( xPos >> ratioW )];
}
PixelValue = PixelValue.ConvertPixel( eColorSpace );
return PixelValue;
}
@@ -478,7 +462,7 @@ Void PlaYUVerFrame::fillRGBBuffer()
Int iR, iG, iB;
Int shiftBits = m_uiBitsPel - 8;
UInt* pARGB = ( UInt* )m_pcARGB32;
if( m_pcPelFormat->colorSpace == COLOR_GRAY )
if( m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_GRAY )
{
Pel* pY = m_pppcInputPel[LUMA][0];
Int iY;
@@ -492,7 +476,7 @@ Void PlaYUVerFrame::fillRGBBuffer()
*pARGB++ = PEL_RGB( iR, iG, iB );
}
}
else if( m_pcPelFormat->colorSpace == COLOR_RGB )
else if( m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_RGB )
{
Pel* pR = m_pppcInputPel[COLOR_R][0];
Pel* pG = m_pppcInputPel[COLOR_G][0];
@@ -506,7 +490,7 @@ Void PlaYUVerFrame::fillRGBBuffer()
*pARGB++ = PEL_RGB( ( iR >> shiftBits ), ( iG >> shiftBits ), ( iB >> shiftBits ) );
}
}
else if( m_pcPelFormat->colorSpace == COLOR_YUV )
else if( m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_YUV )
{
Pel* pLineY = m_pppcInputPel[LUMA][0];
Pel* pLineU = m_pppcInputPel[CHROMA_U][0];
@@ -578,7 +562,7 @@ Void PlaYUVerFrame::calcHistogram()
UInt i, j;
UInt numberChannels = m_pcPelFormat->numberChannels;
Int colorSpace = m_pcPelFormat->colorSpace;
if( colorSpace == PlaYUVerFrame::COLOR_YUV )
if( colorSpace == PlaYUVerPixel::COLOR_YUV )
{
const Pel *data[3];
data[LUMA] = m_pppcInputPel[LUMA][0];
@@ -612,10 +596,10 @@ Void PlaYUVerFrame::calcHistogram()
{
m_puiHistogram[*( data[j] ) + j * m_uiHistoSegments]++;
}
if( ( colorSpace == PlaYUVerFrame::COLOR_RGB || colorSpace == PlaYUVerFrame::COLOR_ARGB ) )
if( ( colorSpace == PlaYUVerPixel::COLOR_RGB || colorSpace == PlaYUVerPixel::COLOR_ARGB ) )
{
PlaYUVerFrame::Pixel currPixel( colorSpace, *( data[COLOR_R] ), *( data[COLOR_G] ), *( data[COLOR_B] ) );
luma = PlaYUVerFrame::ConvertPixel( currPixel, PlaYUVerFrame::COLOR_YUV ).Y();
PlaYUVerPixel currPixel( colorSpace, *( data[COLOR_R] ), *( data[COLOR_G] ), *( data[COLOR_B] ) );
luma = currPixel.ConvertPixel( PlaYUVerPixel::COLOR_YUV ).Y();
m_puiHistogram[luma + j * m_uiHistoSegments]++;
}
for( j = 0; j < numberChannels; j++ )
@@ -637,14 +621,14 @@ Int PlaYUVerFrame::getRealHistoChannel( Int channel )
switch( getColorSpace() )
{
case PlaYUVerFrame::COLOR_GRAY:
case PlaYUVerPixel::COLOR_GRAY:
if( channel != LUMA )
{
return -1;
}
histoChannel = 0;
break;
case PlaYUVerFrame::COLOR_RGB:
case PlaYUVerPixel::COLOR_RGB:
if( channel != COLOR_R && channel != COLOR_G && channel != COLOR_B && channel != LUMA )
{
return -1;
@@ -661,7 +645,7 @@ Int PlaYUVerFrame::getRealHistoChannel( Int channel )
}
}
break;
case PlaYUVerFrame::COLOR_ARGB:
case PlaYUVerPixel::COLOR_ARGB:
if( channel != COLOR_R && channel != COLOR_G && channel != COLOR_B && channel != COLOR_A && channel != LUMA )
{
return -1;
@@ -678,7 +662,7 @@ Int PlaYUVerFrame::getRealHistoChannel( Int channel )
}
}
break;
case PlaYUVerFrame::COLOR_YUV:
case PlaYUVerPixel::COLOR_YUV:
if( channel != LUMA && channel != CHROMA_U && channel != CHROMA_V )
{
return -1;
@@ -950,14 +934,14 @@ Void PlaYUVerFrame::FrametoRGB8Pixfc()
cv::Mat* PlaYUVerFrame::getCvMat( Bool convertToGray )
{
#ifdef USE_OPENCV
if( convertToGray && !( m_pcPelFormat->colorSpace == PlaYUVerFrame::COLOR_YUV || m_pcPelFormat->colorSpace == PlaYUVerFrame::COLOR_GRAY ) )
if( convertToGray && !( m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_YUV || m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_GRAY ) )
{
return NULL;
}
Int cvType = CV_MAKETYPE( CV_8U, convertToGray ? 1 : m_pcPelFormat->numberChannels );
cv::Mat *pcCvFrame = new cv::Mat( m_uiHeight, m_uiWidth, cvType );
UChar* pCvPel = pcCvFrame->data;
if( !convertToGray && ( m_pcPelFormat->colorSpace == PlaYUVerFrame::COLOR_YUV || m_pcPelFormat->colorSpace == PlaYUVerFrame::COLOR_RGB ) )
if( !convertToGray && ( m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_YUV || m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_RGB ) )
{
fillRGBBuffer();
UChar* pARGB = m_pcARGB32;
@@ -969,7 +953,7 @@ cv::Mat* PlaYUVerFrame::getCvMat( Bool convertToGray )
pARGB++;
}
}
else if( convertToGray || m_pcPelFormat->colorSpace == PlaYUVerFrame::COLOR_GRAY )
else if( convertToGray || m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_GRAY )
{
Pel* pPel = m_pppcInputPel[LUMA][0];
for( UInt i = 0; i < m_uiWidth * m_uiHeight; i++ )
+3 -82
View File
@@ -31,6 +31,7 @@
#include <cassert>
#include <vector>
#include "PlaYUVerDefs.h"
#include "PlaYUVerPixel.h"
class PixFcSSE;
namespace cv
@@ -43,8 +44,6 @@ namespace plaYUVer
struct PlaYUVerPixFmtDescriptor;
#define MAX_NUMBER_COMPONENTS 4
#define CHROMASHIFT( SIZE, SHIFT ) UInt( -( ( - ( Int( SIZE ) ) ) >> SHIFT ) )
/**
@@ -57,77 +56,6 @@ class PlaYUVerFrame
{
public:
/**
* \class Pixel
* \ingroup PlaYUVerLib PlaYUVerLib_Frame
* \brief Pel handling class
*/
class Pixel
{
private:
Int m_iColorSpace;
Pel PixelComponents[3];
public:
Pixel()
{
m_iColorSpace = PlaYUVerFrame::COLOR_INVALID;
PixelComponents[0] = 0;
PixelComponents[1] = 0;
PixelComponents[2] = 0;
}
Pixel( Int ColorSpace, Pel c0, Pel c1, Pel c2 )
{
m_iColorSpace = ColorSpace == PlaYUVerFrame::COLOR_GRAY ? PlaYUVerFrame::COLOR_YUV : ColorSpace;
PixelComponents[0] = c0;
PixelComponents[1] = c1;
PixelComponents[2] = c2;
}
Int ColorSpace()
{
return m_iColorSpace;
}
Pel* Components()
{
return PixelComponents;
}
Pel& Y()
{
return PixelComponents[0];
}
Pel& Cb()
{
return PixelComponents[1];
}
Pel& Cr()
{
return PixelComponents[2];
}
Pel& R()
{
return PixelComponents[0];
}
Pel& G()
{
return PixelComponents[1];
}
Pel& B()
{
return PixelComponents[2];
}
};
/** ColorSpace Enum
* List of supported color spaces
*/
enum ColorSpace
{
COLOR_INVALID = -1, //!< Invalid
COLOR_YUV = 0, //!< YUV
COLOR_RGB = 1, //!< RGB
COLOR_ARGB = 3, //!< RGB + Alpha
COLOR_GRAY = 2, //!< Grayscale
};
/** ColorSpace Enum
* List of supported pixel formats (deprecated)
*/
@@ -177,14 +105,6 @@ public:
*/
static UInt64 getBytesPerFrame( UInt uiWidth, UInt uiHeight, Int iPixelFormat, UInt bitsPixel );
/**
* Convert a Pixel to a new color space
* @param inputPixel input pixel (PlaYUVerFrame::Pixel)
* @param eOutputSpace output color space
* @return converted pixel
*/
static PlaYUVerFrame::Pixel ConvertPixel( Pixel inputPixel, ColorSpace eOutputSpace );
/**
* Creates a new frame using the following configuration
*
@@ -283,7 +203,8 @@ public:
UInt getChromaLength() const;
UInt getChromaSize() const;
PlaYUVerFrame::Pixel getPixelValue( Int xPos, Int yPos, ColorSpace eColorSpace = COLOR_INVALID );
PlaYUVerPixel getPixelValue( Int xPos, Int yPos );
PlaYUVerPixel getPixelValue( Int xPos, Int yPos, PlaYUVerPixel::ColorSpace eColorSpace );
Void copyFrom( PlaYUVerFrame* );
Void copyFrom( PlaYUVerFrame*, UInt, UInt );
+7 -7
View File
@@ -204,7 +204,7 @@ Void fillARGB32bufferYUV420p( Pel*** in, UChar* out, UInt width, UInt height, UI
PlaYUVerPixFmtDescriptor yuv420p =
{
"YUV420p",
PlaYUVerFrame::COLOR_YUV,
PlaYUVerPixel::COLOR_YUV,
3,
3,
1,
@@ -220,7 +220,7 @@ PlaYUVerPixFmtDescriptor yuv420p =
PlaYUVerPixFmtDescriptor yuv422p =
{
"YUV422p",
PlaYUVerFrame::COLOR_YUV,
PlaYUVerPixel::COLOR_YUV,
3,
3,
1,
@@ -236,7 +236,7 @@ PlaYUVerPixFmtDescriptor yuv422p =
PlaYUVerPixFmtDescriptor yuv444p =
{
"YUV444p",
PlaYUVerFrame::COLOR_YUV,
PlaYUVerPixel::COLOR_YUV,
3,
3,
0,
@@ -252,7 +252,7 @@ PlaYUVerPixFmtDescriptor yuv444p =
PlaYUVerPixFmtDescriptor yuyv422 =
{
"YUYV422",
PlaYUVerFrame::COLOR_YUV,
PlaYUVerPixel::COLOR_YUV,
3,
1,
1,
@@ -268,7 +268,7 @@ PlaYUVerPixFmtDescriptor yuyv422 =
PlaYUVerPixFmtDescriptor gray =
{
"GRAY",
PlaYUVerFrame::COLOR_GRAY,
PlaYUVerPixel::COLOR_GRAY,
1,
1,
0,
@@ -280,7 +280,7 @@ PlaYUVerPixFmtDescriptor gray =
PlaYUVerPixFmtDescriptor RGB24 =
{
"RGB24",
PlaYUVerFrame::COLOR_RGB,
PlaYUVerPixel::COLOR_RGB,
3,
1,
0,
@@ -296,7 +296,7 @@ PlaYUVerPixFmtDescriptor RGB24 =
PlaYUVerPixFmtDescriptor BGR24 =
{
"BRG24",
PlaYUVerFrame::COLOR_RGB,
PlaYUVerPixel::COLOR_RGB,
3,
1,
0,
+1 -15
View File
@@ -28,6 +28,7 @@
#include "PlaYUVerDefs.h"
#include "PlaYUVerFrame.h"
#include "PlaYUVerPixel.h"
namespace plaYUVer
{
@@ -36,21 +37,6 @@ namespace plaYUVer
#define CHROMARATIO( SIZE, RATIO ) ( RATIO > 1 ? ( ( SIZE + 1 ) / RATIO ) : SIZE )
#define CLAMP(X) X = X < 0 ? 0 : X > 255 ? 255 : X;
#define YUV2RGB( iY, iU, iV, iR, iG, iB ) \
iR = iY + ( ( 1436 * ( iV - 128) ) >> 10 ); \
iG = iY - ( ( 352 * ( iU - 128 ) + 731 * ( iV - 128 ) ) >> 10 ); \
iB = iY + ( ( 1812 * ( iU - 128 ) ) >> 10 ); \
CLAMP(iR) CLAMP(iG) CLAMP(iB)
static inline Void rgbToYuv( Int iR, Int iG, Int iB, Int &iY, Int &iU, Int &iV )
{
iY = ( 299 * iR + 587 * iG + 114 * iB + 500 ) / 1000;
iU = ( 1000 * ( iB - iY ) + 226816 ) / 1772;
iV = ( 1000 * ( iR - iY ) + 179456 ) / 1402;
}
inline Int pelRed( UInt rgb ) // get red part of RGB
{
return ( ( rgb >> 16 ) & 0xff );
+59
View File
@@ -0,0 +1,59 @@
/* This file is a part of plaYUVer project
* Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com)
* Joao Carreira (jfmcarreira@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file PlaYUVerPixel.cpp
* \ingroup PlaYUVerLib
* \brief Pixel handling
*/
#include <cstdio>
#include <cmath>
#include "PlaYUVerFrame.h"
#include "PlaYUVerPixel.h"
namespace plaYUVer
{
PlaYUVerPixel PlaYUVerPixel::ConvertPixel( ColorSpace eOutputSpace )
{
Int outA, outB, outC;
PlaYUVerPixel outPixel( COLOR_INVALID, 0, 0, 0 );
if( ColorSpace() == eOutputSpace || eOutputSpace == COLOR_ARGB || eOutputSpace == COLOR_GRAY )
return *this;
if( eOutputSpace == COLOR_RGB )
{
YUV2RGB( Y(), Cb(), Cr(), outA, outB, outC );
outPixel.R() = outA;
outPixel.G() = outB;
outPixel.B() = outC;
}
if( eOutputSpace == COLOR_YUV )
{
rgbToYuv( R(), G(), B(), outA, outB, outC );
outPixel.Y() = outA;
outPixel.Cb() = outB;
outPixel.Cr() = outC;
}
return outPixel;
}
} // NAMESPACE
+145
View File
@@ -0,0 +1,145 @@
/* This file is a part of plaYUVer project
* Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com)
* Joao Carreira (jfmcarreira@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file PlaYUVerPixel.h
* \ingroup PlaYUVerLib
* \brief Pixel handling
*/
#ifndef __PLAYUVERPIXEL_H__
#define __PLAYUVERPIXEL_H__
#include <iostream>
#include <cstdio>
#include <cassert>
#include <vector>
#include "PlaYUVerDefs.h"
namespace plaYUVer
{
#define CLAMP(X) X = X < 0 ? 0 : X > 255 ? 255 : X;
#define YUV2RGB( iY, iU, iV, iR, iG, iB ) \
iR = iY + ( ( 1436 * ( iV - 128) ) >> 10 ); \
iG = iY - ( ( 352 * ( iU - 128 ) + 731 * ( iV - 128 ) ) >> 10 ); \
iB = iY + ( ( 1812 * ( iU - 128 ) ) >> 10 ); \
CLAMP(iR) CLAMP(iG) CLAMP(iB)
static inline Void rgbToYuv( Int iR, Int iG, Int iB, Int &iY, Int &iU, Int &iV )
{
iY = ( 299 * iR + 587 * iG + 114 * iB + 500 ) / 1000;
iU = ( 1000 * ( iB - iY ) + 226816 ) / 1772;
iV = ( 1000 * ( iR - iY ) + 179456 ) / 1402;
}
#define MAX_NUMBER_COMPONENTS 4
/**
* \class PlaYUVerPixel
* \ingroup PlaYUVerLib PlaYUVerLib_Frame
* \brief Pel handling class
*/
class PlaYUVerPixel
{
public:
/** ColorSpace Enum
* List of supported color spaces
*/
enum ColorSpace
{
COLOR_INVALID = -1, //!< Invalid
COLOR_YUV = 0, //!< YUV
COLOR_RGB = 1, //!< RGB
COLOR_GRAY = 2, //!< Grayscale
COLOR_ARGB = 3, //!< RGB + Alpha
};
PlaYUVerPixel()
{
m_iColorSpace = COLOR_INVALID;
PixelComponents[0] = 0;
PixelComponents[1] = 0;
PixelComponents[2] = 0;
PixelComponents[3] = 0;
}
PlaYUVerPixel( Int ColorSpace, Pel c0, Pel c1, Pel c2 )
{
m_iColorSpace = ColorSpace == COLOR_GRAY ? COLOR_YUV : ColorSpace;
PixelComponents[0] = c0;
PixelComponents[1] = c1;
PixelComponents[2] = c2;
PixelComponents[3] = 0;
}
Int ColorSpaceType()
{
return m_iColorSpace;
}
Pel* Components()
{
return PixelComponents;
}
Pel& Y()
{
return PixelComponents[0];
}
Pel& Cb()
{
return PixelComponents[1];
}
Pel& Cr()
{
return PixelComponents[2];
}
Pel& R()
{
return PixelComponents[0];
}
Pel& G()
{
return PixelComponents[1];
}
Pel& B()
{
return PixelComponents[2];
}
Pel& A()
{
return PixelComponents[3];
}
/**
* Convert a Pixel to a new color space
* @param inputPixel input pixel (PlaYUVerPixel)
* @param eOutputSpace output color space
* @return converted pixel
*/
PlaYUVerPixel ConvertPixel( ColorSpace eOutputSpace );
private:
Int m_iColorSpace;
Pel PixelComponents[MAX_NUMBER_COMPONENTS];
};
} // NAMESPACE
#endif // __PLAYUVERPIXEL_H__