Fix FrameMask and minor bug fixes in PlaYUVerFrame

This commit is contained in:
2016-03-10 02:38:35 +00:00
parent 7ddf3c0a6d
commit e38ba03f65
8 changed files with 71 additions and 17 deletions
+6 -3
View File
@@ -173,7 +173,8 @@ Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format, Int bitsPixel
m_iPixelFormat = pel_format; m_iPixelFormat = pel_format;
m_iNumberChannels = 3; m_iNumberChannels = 3;
m_uiBitsPel = bitsPixel > 8 ? bitsPixel : 8; m_uiBitsPel = bitsPixel > 8 ? bitsPixel : 8;
m_uiHalfPelValue = 1 << ( m_uiBitsPel - 1 );
if( m_uiWidth == 0 || m_uiHeight == 0 || m_iPixelFormat == -1 || bitsPixel > 16 ) if( m_uiWidth == 0 || m_uiHeight == 0 || m_iPixelFormat == -1 || bitsPixel > 16 )
{ {
throw "Cannot create a PlYUVerFrame of this type"; throw "Cannot create a PlYUVerFrame of this type";
@@ -238,6 +239,8 @@ Bool PlaYUVerFrame::haveSameFmt( PlaYUVerFrame* other, UInt match ) const
bRet &= ( getPelFormat() == other->getPelFormat() ); bRet &= ( getPelFormat() == other->getPelFormat() );
if( match & MATCH_BITS ) if( match & MATCH_BITS )
bRet &= ( getBitsPel() == other->getBitsPel() ); bRet &= ( getBitsPel() == other->getBitsPel() );
if( match & MATCH_COLOR_SPACE_IGNORE_GRAY )
bRet &= ( getColorSpace() == PlaYUVerPixel::COLOR_GRAY || getColorSpace() == other->getColorSpace() );
} }
else else
{ {
@@ -320,7 +323,7 @@ UInt PlaYUVerFrame::getChromaSize() const
PlaYUVerPixel PlaYUVerFrame::getPixelValue( Int xPos, Int yPos ) PlaYUVerPixel PlaYUVerFrame::getPixelValue( Int xPos, Int yPos )
{ {
PlaYUVerPixel PixelValue( m_pcPelFormat->colorSpace, 0, 0, 0 ); PlaYUVerPixel PixelValue( m_pcPelFormat->colorSpace, m_uiHalfPelValue, m_uiHalfPelValue, m_uiHalfPelValue );
for( UInt ch = 0; ch < m_pcPelFormat->numberChannels; ch++ ) for( UInt ch = 0; ch < m_pcPelFormat->numberChannels; ch++ )
{ {
Int ratioH = ch > 0 ? m_pcPelFormat->log2ChromaWidth : 0; Int ratioH = ch > 0 ? m_pcPelFormat->log2ChromaWidth : 0;
@@ -332,7 +335,7 @@ PlaYUVerPixel PlaYUVerFrame::getPixelValue( Int xPos, Int yPos )
PlaYUVerPixel PlaYUVerFrame::getPixelValue( Int xPos, Int yPos, PlaYUVerPixel::ColorSpace eColorSpace ) PlaYUVerPixel PlaYUVerFrame::getPixelValue( Int xPos, Int yPos, PlaYUVerPixel::ColorSpace eColorSpace )
{ {
PlaYUVerPixel PixelValue( m_pcPelFormat->colorSpace, 0, 0, 0 ); PlaYUVerPixel PixelValue( m_pcPelFormat->colorSpace );
for( UInt ch = 0; ch < m_pcPelFormat->numberChannels; ch++ ) for( UInt ch = 0; ch < m_pcPelFormat->numberChannels; ch++ )
{ {
Int ratioH = ch > 0 ? m_pcPelFormat->log2ChromaWidth : 0; Int ratioH = ch > 0 ? m_pcPelFormat->log2ChromaWidth : 0;
+5 -3
View File
@@ -56,16 +56,16 @@ class PlaYUVerFrame
{ {
public: public:
/** ColorSpace Enum /** ColorSpace Enum (deprecated)
* List of supported pixel formats (deprecated) * List of supported pixel formats - do not change order
*/ */
enum PixelFormats enum PixelFormats
{ {
NO_FMT = -1, NO_FMT = -1,
YUV420p = 0, YUV420p = 0,
YUV444p,
YUV422p, YUV422p,
YUYV422, YUYV422,
YUV444p,
GRAY, GRAY,
RGB24, RGB24,
BRG24, BRG24,
@@ -80,6 +80,7 @@ public:
MATCH_RESOLUTION = 2, MATCH_RESOLUTION = 2,
MATCH_PEL_FMT = 4, MATCH_PEL_FMT = 4,
MATCH_BITS = 8, MATCH_BITS = 8,
MATCH_COLOR_SPACE_IGNORE_GRAY = 16,
MATCH_ALL = 0xFFFF, MATCH_ALL = 0xFFFF,
}; };
@@ -296,6 +297,7 @@ private:
Int m_iPixelFormat; //!< Pixel format number (it follows the list of supported pixel formats) Int m_iPixelFormat; //!< Pixel format number (it follows the list of supported pixel formats)
Int m_iNumberChannels; //!< Number of channels Int m_iNumberChannels; //!< Number of channels
UInt m_uiBitsPel; //!< Bits per pixel/channel UInt m_uiBitsPel; //!< Bits per pixel/channel
UInt m_uiHalfPelValue; //!< Bits per pixel/channel
Pel*** m_pppcInputPel; Pel*** m_pppcInputPel;
+9
View File
@@ -40,6 +40,15 @@ PlaYUVerPixel::PlaYUVerPixel()
PixelComponents[3] = 0; PixelComponents[3] = 0;
} }
PlaYUVerPixel::PlaYUVerPixel( Int ColorSpace )
{
m_iColorSpace = ColorSpace == COLOR_GRAY ? COLOR_YUV : ColorSpace;
PixelComponents[0] = 0;
PixelComponents[1] = 0;
PixelComponents[2] = 0;
PixelComponents[3] = 0;
}
PlaYUVerPixel::PlaYUVerPixel( Int ColorSpace, Pel c0, Pel c1, Pel c2 ) PlaYUVerPixel::PlaYUVerPixel( Int ColorSpace, Pel c0, Pel c1, Pel c2 )
{ {
m_iColorSpace = ColorSpace == COLOR_GRAY ? COLOR_YUV : ColorSpace; m_iColorSpace = ColorSpace == COLOR_GRAY ? COLOR_YUV : ColorSpace;
+1
View File
@@ -74,6 +74,7 @@ public:
}; };
PlaYUVerPixel(); PlaYUVerPixel();
PlaYUVerPixel( Int ColorSpace );
PlaYUVerPixel( Int ColorSpace, Pel c0, Pel c1, Pel c2 ); PlaYUVerPixel( Int ColorSpace, Pel c0, Pel c1, Pel c2 );
Int ColorSpaceType() Int ColorSpaceType()
+2 -2
View File
@@ -49,8 +49,8 @@ Bool AbsoluteFrameDifference::create( std::vector<PlaYUVerFrame*> apcFrameList )
{ {
_BASIC_MODULE_API_2_CHECK_ _BASIC_MODULE_API_2_CHECK_
for( UInt i = 0; i < apcFrameList.size(); i++ ) for( UInt i = 1; i < apcFrameList.size(); i++ )
if( !apcFrameList[i]->haveSameFmt( apcFrameList[i], PlaYUVerFrame::MATCH_COLOR_SPACE | PlaYUVerFrame::MATCH_RESOLUTION | PlaYUVerFrame::MATCH_BITS) ) if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], PlaYUVerFrame::MATCH_COLOR_SPACE | PlaYUVerFrame::MATCH_RESOLUTION | PlaYUVerFrame::MATCH_BITS) )
return false; return false;
m_pcFrameDifference = new PlaYUVerFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), PlaYUVerFrame::GRAY ); m_pcFrameDifference = new PlaYUVerFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), PlaYUVerFrame::GRAY );
+1 -1
View File
@@ -54,7 +54,7 @@ Bool FrameDifference::create( std::vector<PlaYUVerFrame*> apcFrameList )
UInt uiMaxBitsPixel = 0; UInt uiMaxBitsPixel = 0;
for( UInt i = 0; i < apcFrameList.size(); i++ ) for( UInt i = 0; i < apcFrameList.size(); i++ )
{ {
if( !apcFrameList[i]->haveSameFmt( apcFrameList[i], PlaYUVerFrame::MATCH_COLOR_SPACE | PlaYUVerFrame::MATCH_RESOLUTION ) ) if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], PlaYUVerFrame::MATCH_COLOR_SPACE | PlaYUVerFrame::MATCH_RESOLUTION ) )
return false; return false;
if( apcFrameList[i]->getBitsPel() > uiMaxBitsPixel ) if( apcFrameList[i]->getBitsPel() > uiMaxBitsPixel )
{ {
+46 -7
View File
@@ -24,6 +24,7 @@
#include "FrameMask.h" #include "FrameMask.h"
#include <algorithm> #include <algorithm>
class be;
namespace plaYUVer namespace plaYUVer
{ {
@@ -36,10 +37,13 @@ FrameMask::FrameMask()
m_pchModuleCategory = "Utilities"; m_pchModuleCategory = "Utilities";
m_pchModuleName = "FrameMask"; m_pchModuleName = "FrameMask";
m_pchModuleTooltip = "Applies a mask to the selected image (first image)"; m_pchModuleTooltip = "Applies a mask to the selected image (first image)";
m_uiModuleRequirements = MODULE_REQUIRES_NEW_WINDOW;
m_uiNumberOfFrames = MODULE_REQUIRES_TWO_FRAMES; m_uiNumberOfFrames = MODULE_REQUIRES_TWO_FRAMES;
m_uiModuleRequirements = MODULE_REQUIRES_NEW_WINDOW | MODULE_REQUIRES_OPTIONS | MODULE_USES_KEYS;
m_dWeigth = 0.3; m_cModuleOptions.addOptions()/**/
( "MaskWeigth", m_uiWeight, "Influence of the mask [60%]" );
m_uiWeight = 6;
m_pcFrameProcessed = NULL; m_pcFrameProcessed = NULL;
} }
@@ -48,16 +52,34 @@ Bool FrameMask::create( std::vector<PlaYUVerFrame*> apcFrameList )
{ {
_BASIC_MODULE_API_2_CHECK_ _BASIC_MODULE_API_2_CHECK_
for( UInt i = 0; i < apcFrameList.size(); i++ ) for( UInt i = 1; i < apcFrameList.size(); i++ )
{ {
if( !apcFrameList[i]->haveSameFmt( apcFrameList[i], PlaYUVerFrame::MATCH_COLOR_SPACE | if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], PlaYUVerFrame::MATCH_COLOR_SPACE_IGNORE_GRAY |
PlaYUVerFrame::MATCH_RESOLUTION | PlaYUVerFrame::MATCH_BITS ) ) PlaYUVerFrame::MATCH_RESOLUTION | PlaYUVerFrame::MATCH_BITS ) )
{ {
return false; return false;
} }
} }
Int iPelFmt = apcFrameList[0]->getPelFormat();
iPelFmt = apcFrameList[1]->getPelFormat() > iPelFmt ? apcFrameList[1]->getPelFormat() : iPelFmt; Int iPelFmt = 0;
Int iColorSpace = apcFrameList[0]->getColorSpace();
if( iColorSpace == PlaYUVerPixel::COLOR_GRAY )
{
iColorSpace = apcFrameList[1]->getPelFormat();
}
switch( iColorSpace )
{
case PlaYUVerPixel::COLOR_GRAY:
iPelFmt = PlaYUVerFrame::GRAY;
break;
case PlaYUVerPixel::COLOR_YUV:
iPelFmt = PlaYUVerFrame::YUV444p;
break;
case PlaYUVerPixel::COLOR_RGB:
iPelFmt = PlaYUVerFrame::RGB24;
break;
}
m_pcFrameProcessed = new PlaYUVerFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), iPelFmt, apcFrameList[0]->getBitsPel() ); m_pcFrameProcessed = new PlaYUVerFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), iPelFmt, apcFrameList[0]->getBitsPel() );
return true; return true;
} }
@@ -76,13 +98,30 @@ PlaYUVerFrame* FrameMask::process( std::vector<PlaYUVerFrame*> apcFrameList )
{ {
pixelImg = InputFrame->getPixelValue( x, y ); pixelImg = InputFrame->getPixelValue( x, y );
pixelMask = MaskFrame->getPixelValue( x, y ); pixelMask = MaskFrame->getPixelValue( x, y );
pixelOut = pixelImg * ( 1 - m_dWeigth ) + pixelMask * m_dWeigth; pixelOut = pixelImg * ( 10 - m_uiWeight ) + pixelMask * m_uiWeight;
pixelOut = pixelOut * 0.1;
m_pcFrameProcessed->setPixelValue( x, y, pixelOut ); m_pcFrameProcessed->setPixelValue( x, y, pixelOut );
} }
} }
return m_pcFrameProcessed; return m_pcFrameProcessed;
} }
Bool FrameMask::keyPressed( enum Module_Key_Supported value )
{
if( value == MODULE_KEY_UP )
{
m_uiWeight -= 1;
return true;
}
if( value == MODULE_KEY_DOWN )
{
m_uiWeight += 1;
return true;
}
return false;
}
Void FrameMask::destroy() Void FrameMask::destroy()
{ {
if( m_pcFrameProcessed ) if( m_pcFrameProcessed )
+1 -1
View File
@@ -37,7 +37,7 @@ class FrameMask: public PlaYUVerModuleIf
REGISTER_CLASS_FACTORY( FrameMask ) REGISTER_CLASS_FACTORY( FrameMask )
private: private:
Double m_dWeigth; UInt m_uiWeight;
PlaYUVerFrame* m_pcFrameProcessed; PlaYUVerFrame* m_pcFrameProcessed;
public: public: