diff --git a/lib/PlaYUVerFrame.cpp b/lib/PlaYUVerFrame.cpp index 48057bf..d03248f 100644 --- a/lib/PlaYUVerFrame.cpp +++ b/lib/PlaYUVerFrame.cpp @@ -173,7 +173,8 @@ Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format, Int bitsPixel m_iPixelFormat = pel_format; m_iNumberChannels = 3; m_uiBitsPel = bitsPixel > 8 ? bitsPixel : 8; - + m_uiHalfPelValue = 1 << ( m_uiBitsPel - 1 ); + if( m_uiWidth == 0 || m_uiHeight == 0 || m_iPixelFormat == -1 || bitsPixel > 16 ) { throw "Cannot create a PlYUVerFrame of this type"; @@ -238,6 +239,8 @@ Bool PlaYUVerFrame::haveSameFmt( PlaYUVerFrame* other, UInt match ) const bRet &= ( getPelFormat() == other->getPelFormat() ); if( match & MATCH_BITS ) bRet &= ( getBitsPel() == other->getBitsPel() ); + if( match & MATCH_COLOR_SPACE_IGNORE_GRAY ) + bRet &= ( getColorSpace() == PlaYUVerPixel::COLOR_GRAY || getColorSpace() == other->getColorSpace() ); } else { @@ -320,7 +323,7 @@ UInt PlaYUVerFrame::getChromaSize() const 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++ ) { 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 PixelValue( m_pcPelFormat->colorSpace, 0, 0, 0 ); + PlaYUVerPixel PixelValue( m_pcPelFormat->colorSpace ); for( UInt ch = 0; ch < m_pcPelFormat->numberChannels; ch++ ) { Int ratioH = ch > 0 ? m_pcPelFormat->log2ChromaWidth : 0; diff --git a/lib/PlaYUVerFrame.h b/lib/PlaYUVerFrame.h index d775d88..33ea961 100644 --- a/lib/PlaYUVerFrame.h +++ b/lib/PlaYUVerFrame.h @@ -56,16 +56,16 @@ class PlaYUVerFrame { public: - /** ColorSpace Enum - * List of supported pixel formats (deprecated) + /** ColorSpace Enum (deprecated) + * List of supported pixel formats - do not change order */ enum PixelFormats { NO_FMT = -1, YUV420p = 0, + YUV444p, YUV422p, YUYV422, - YUV444p, GRAY, RGB24, BRG24, @@ -80,6 +80,7 @@ public: MATCH_RESOLUTION = 2, MATCH_PEL_FMT = 4, MATCH_BITS = 8, + MATCH_COLOR_SPACE_IGNORE_GRAY = 16, MATCH_ALL = 0xFFFF, }; @@ -296,6 +297,7 @@ private: Int m_iPixelFormat; //!< Pixel format number (it follows the list of supported pixel formats) Int m_iNumberChannels; //!< Number of channels UInt m_uiBitsPel; //!< Bits per pixel/channel + UInt m_uiHalfPelValue; //!< Bits per pixel/channel Pel*** m_pppcInputPel; diff --git a/lib/PlaYUVerPixel.cpp b/lib/PlaYUVerPixel.cpp index 2dc3bee..6c2bdfc 100644 --- a/lib/PlaYUVerPixel.cpp +++ b/lib/PlaYUVerPixel.cpp @@ -40,6 +40,15 @@ PlaYUVerPixel::PlaYUVerPixel() 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 ) { m_iColorSpace = ColorSpace == COLOR_GRAY ? COLOR_YUV : ColorSpace; diff --git a/lib/PlaYUVerPixel.h b/lib/PlaYUVerPixel.h index 343add9..2ca1787 100644 --- a/lib/PlaYUVerPixel.h +++ b/lib/PlaYUVerPixel.h @@ -74,6 +74,7 @@ public: }; PlaYUVerPixel(); + PlaYUVerPixel( Int ColorSpace ); PlaYUVerPixel( Int ColorSpace, Pel c0, Pel c1, Pel c2 ); Int ColorSpaceType() diff --git a/modules/AbsoluteFrameDifference.cpp b/modules/AbsoluteFrameDifference.cpp index 21a6021..63d5dba 100644 --- a/modules/AbsoluteFrameDifference.cpp +++ b/modules/AbsoluteFrameDifference.cpp @@ -49,8 +49,8 @@ Bool AbsoluteFrameDifference::create( std::vector apcFrameList ) { _BASIC_MODULE_API_2_CHECK_ - for( UInt i = 0; i < apcFrameList.size(); i++ ) - if( !apcFrameList[i]->haveSameFmt( apcFrameList[i], PlaYUVerFrame::MATCH_COLOR_SPACE | PlaYUVerFrame::MATCH_RESOLUTION | PlaYUVerFrame::MATCH_BITS) ) + for( UInt i = 1; i < apcFrameList.size(); i++ ) + if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], PlaYUVerFrame::MATCH_COLOR_SPACE | PlaYUVerFrame::MATCH_RESOLUTION | PlaYUVerFrame::MATCH_BITS) ) return false; m_pcFrameDifference = new PlaYUVerFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), PlaYUVerFrame::GRAY ); diff --git a/modules/FrameDifference.cpp b/modules/FrameDifference.cpp index 3120929..f757f97 100644 --- a/modules/FrameDifference.cpp +++ b/modules/FrameDifference.cpp @@ -54,7 +54,7 @@ Bool FrameDifference::create( std::vector apcFrameList ) UInt uiMaxBitsPixel = 0; 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; if( apcFrameList[i]->getBitsPel() > uiMaxBitsPixel ) { diff --git a/modules/FrameMask.cpp b/modules/FrameMask.cpp index aa85a77..12b5c39 100644 --- a/modules/FrameMask.cpp +++ b/modules/FrameMask.cpp @@ -24,6 +24,7 @@ #include "FrameMask.h" #include +class be; namespace plaYUVer { @@ -36,10 +37,13 @@ FrameMask::FrameMask() m_pchModuleCategory = "Utilities"; m_pchModuleName = "FrameMask"; m_pchModuleTooltip = "Applies a mask to the selected image (first image)"; - m_uiModuleRequirements = MODULE_REQUIRES_NEW_WINDOW; 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; } @@ -48,16 +52,34 @@ Bool FrameMask::create( std::vector apcFrameList ) { _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 ) ) { 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() ); return true; } @@ -76,13 +98,30 @@ PlaYUVerFrame* FrameMask::process( std::vector apcFrameList ) { pixelImg = InputFrame->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 ); } } 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() { if( m_pcFrameProcessed ) diff --git a/modules/FrameMask.h b/modules/FrameMask.h index 4d74455..4a75e54 100644 --- a/modules/FrameMask.h +++ b/modules/FrameMask.h @@ -37,7 +37,7 @@ class FrameMask: public PlaYUVerModuleIf REGISTER_CLASS_FACTORY( FrameMask ) private: - Double m_dWeigth; + UInt m_uiWeight; PlaYUVerFrame* m_pcFrameProcessed; public: