[vlc-commits] skins2(win32): improve boundaries check
Erwan Tulou
git at videolan.org
Thu Apr 4 18:00:16 CEST 2013
vlc | branch: master | Erwan Tulou <erwan10 at videolan.org> | Thu Apr 4 13:29:21 2013 +0200| [f6ba5119dfbedd245129493fd64a18bc8770701d] | committer: Erwan Tulou
skins2(win32): improve boundaries check
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f6ba5119dfbedd245129493fd64a18bc8770701d
---
modules/gui/skins2/win32/win32_graphics.cpp | 59 +++++++++++++++++++++------
modules/gui/skins2/win32/win32_graphics.hpp | 5 +++
2 files changed, 51 insertions(+), 13 deletions(-)
diff --git a/modules/gui/skins2/win32/win32_graphics.cpp b/modules/gui/skins2/win32/win32_graphics.cpp
index 8b856bf..71b4971 100644
--- a/modules/gui/skins2/win32/win32_graphics.cpp
+++ b/modules/gui/skins2/win32/win32_graphics.cpp
@@ -82,19 +82,20 @@ void Win32Graphics::drawBitmap( const GenericBitmap &rBitmap,
int width, int height, bool blend )
{
(void)blend;
- // Get the bitmap size if necessary
- if( width == -1 )
- {
- width = rBitmap.getWidth();
- }
- if( height == -1 )
+
+ // check and adapt to source if needed
+ if( !checkBoundaries( 0, 0, rBitmap.getWidth(), rBitmap.getHeight(),
+ xSrc, ySrc, width, height ) )
{
- height = rBitmap.getHeight();
+ msg_Err( getIntf(), "empty source! pls, debug your skin" );
+ return;
}
- if( xDest + width > m_width || yDest + height > m_height )
+ // check destination
+ if( !checkBoundaries( 0, 0, m_width, m_height,
+ xDest, yDest, width, height ) )
{
- msg_Err( getIntf(), "Bitmap too large !" );
+ msg_Err( getIntf(), "out of reach destination! pls, debug your skin" );
return;
}
@@ -212,13 +213,20 @@ void Win32Graphics::drawGraphics( const OSGraphics &rGraphics, int xSrc,
int ySrc, int xDest, int yDest, int width,
int height )
{
- if( width == -1 )
+ // check and adapt to source if needed
+ if( !checkBoundaries( 0, 0, rGraphics.getWidth(), rGraphics.getHeight(),
+ xSrc, ySrc, width, height ) )
{
- width = rGraphics.getWidth();
+ msg_Err( getIntf(), "nothing to draw from graphics source" );
+ return;
}
- if( height == -1 )
+
+ // check destination
+ if( !checkBoundaries( 0, 0, m_width, m_height,
+ xDest, yDest, width, height ) )
{
- height = rGraphics.getHeight();
+ msg_Err( getIntf(), "out of reach destination! pls, debug your skin" );
+ return;
}
// Create the mask for transparency
@@ -346,4 +354,29 @@ void Win32Graphics::addSegmentInRegion( HRGN &rMask, int start,
DeleteObject( buffer );
}
+
+bool Win32Graphics::checkBoundaries( int x_src, int y_src,
+ int w_src, int h_src,
+ int& x_target, int& y_target,
+ int& w_target, int& h_target )
+{
+ // set valid width and height
+ w_target = (w_target > 0) ? w_target : w_src;
+ h_target = (h_target > 0) ? h_target : h_src;
+
+ // clip source if needed
+ rect srcRegion( x_src, y_src, w_src, h_src );
+ rect targetRegion( x_target, y_target, w_target, h_target );
+ rect inter;
+ if( rect::intersect( srcRegion, targetRegion, &inter ) )
+ {
+ x_target = inter.x;
+ y_target = inter.y;
+ w_target = inter.width;
+ h_target = inter.height;
+ return true;
+ }
+ return false;
+}
+
#endif
diff --git a/modules/gui/skins2/win32/win32_graphics.hpp b/modules/gui/skins2/win32/win32_graphics.hpp
index b3cbd95..83f575a 100644
--- a/modules/gui/skins2/win32/win32_graphics.hpp
+++ b/modules/gui/skins2/win32/win32_graphics.hpp
@@ -95,6 +95,11 @@ private:
/// Add a segment in a region
void addSegmentInRegion( HRGN &rMask, int start, int end, int line );
+
+ /// check boundaries for graphics and bitmaps
+ bool checkBoundaries( int x_src, int y_src, int w_src, int h_src,
+ int& x_target, int& y_target,
+ int& w_target, int& h_target );
};
More information about the vlc-commits
mailing list