From 53e955daff3f1566a84e6e9e93a69017c24f1ca5 Mon Sep 17 00:00:00 2001 From: xy Date: Sun, 15 Jul 2012 19:09:11 +0800 Subject: [PATCH] More aggressive blur detection. --- src/subtitles/RTS.cpp | 2 +- src/subtitles/Rasterizer.cpp | 19 ++++++++++++++++--- src/subtitles/Rasterizer.h | 7 ++++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/subtitles/RTS.cpp b/src/subtitles/RTS.cpp index 97e5f98..a113e2b 100644 --- a/src/subtitles/RTS.cpp +++ b/src/subtitles/RTS.cpp @@ -183,7 +183,7 @@ void CWord::PaintFromOverlay(const CPoint& p, const CPoint& trans_org2, OverlayK void CWord::PaintFromNoneBluredOverlay(SharedPtrOverlay raterize_result, const OverlayKey& overlay_key, SharedPtrOverlay* overlay) { - if( m_style.get().fBlur>0 || m_style.get().fGaussianBlur>0.000001 ) + if( Rasterizer::IsItReallyBlur(m_style.get().fBlur, m_style.get().fGaussianBlur) ) { overlay->reset(new Overlay()); if(!Rasterizer::Blur(*raterize_result, m_style.get().fBlur, m_style.get().fGaussianBlur, *overlay)) diff --git a/src/subtitles/Rasterizer.cpp b/src/subtitles/Rasterizer.cpp index 635e36b..1457f47 100644 --- a/src/subtitles/Rasterizer.cpp +++ b/src/subtitles/Rasterizer.cpp @@ -718,13 +718,25 @@ bool Rasterizer::Rasterize(const ScanLineData2& scan_line_data2, int xsub, int y return true; } + +const float Rasterizer::GAUSSIAN_BLUR_THREHOLD = 0.333333f; + +bool Rasterizer::IsItReallyBlur( int fBlur, double fGaussianBlur ) +{ + if (fBlur<=0 && fGaussianBlur<=GAUSSIAN_BLUR_THREHOLD) + { + return false; + } + return true; +} // @return: true if actually a blur operation has done, or else false and output is leave unset. bool Rasterizer::Blur(const Overlay& input_overlay, int fBlur, double fGaussianBlur, SharedPtrOverlay output_overlay) { using namespace ::boost::flyweights; - + + ASSERT(IsItReallyBlur(fBlur, fGaussianBlur)); if(!output_overlay) { return false; @@ -740,7 +752,7 @@ bool Rasterizer::Blur(const Overlay& input_overlay, int fBlur, double fGaussianB output_overlay->mfWideOutlineEmpty = input_overlay.mfWideOutlineEmpty; int bluradjust = 0; - if(fBlur || fGaussianBlur > 0.1) + if ( IsItReallyBlur(fBlur, fGaussianBlur) ) { if (fGaussianBlur > 0) bluradjust += (int)(fGaussianBlur*3*8 + 0.5) | 1; @@ -803,7 +815,7 @@ bool Rasterizer::Blur(const Overlay& input_overlay, int fBlur, double fGaussianB ass_tmp_buf tmp_buf( max((output_overlay->mOverlayPitch+1)*(output_overlay->mOverlayHeight+1),0) ); //flyweight, no_locking> tmp_buf((overlay->mOverlayWidth+1)*(overlay->mOverlayPitch+1)); // Do some gaussian blur magic - if (fGaussianBlur > 0.1)//(fGaussianBlur > 0) return true even if fGaussianBlur very small + if ( fGaussianBlur > GAUSSIAN_BLUR_THREHOLD ) { byte* plan_selected= output_overlay->mfWideOutlineEmpty ? body : border; flyweight, no_locking> fw_priv_blur(fGaussianBlur); @@ -1544,6 +1556,7 @@ void Rasterizer::FillSolidRect(SubPicDesc& spd, int x, int y, int nWidth, int nH _mm_empty(); } + /////////////////////////////////////////////////////////////// // Overlay diff --git a/src/subtitles/Rasterizer.h b/src/subtitles/Rasterizer.h index b522bd2..0150806 100644 --- a/src/subtitles/Rasterizer.h +++ b/src/subtitles/Rasterizer.h @@ -214,8 +214,13 @@ private: AYUV_PLANAR = 1<<4 }; }; -public: +public: + static const float GAUSSIAN_BLUR_THREHOLD; +public: + static bool Rasterize(const ScanLineData2& scan_line_data2, int xsub, int ysub, SharedPtrOverlay overlay); + + static bool IsItReallyBlur(int fBlur, double fGaussianBlur); static bool Blur(const Overlay& input_overlay, int fBlur, double fGaussianBlur, SharedPtrOverlay output_overlay); static SharedPtrByte CompositeAlphaMask(const SharedPtrOverlay& overlay, const CRect& clipRect, -- 2.11.4.GIT