]> git.sesse.net Git - vlc/commitdiff
skins2(win32): improve boundaries check
authorErwan Tulou <erwan10@videolan.org>
Thu, 4 Apr 2013 11:29:21 +0000 (13:29 +0200)
committerErwan Tulou <erwan10@videolan.org>
Thu, 4 Apr 2013 15:57:24 +0000 (17:57 +0200)
modules/gui/skins2/win32/win32_graphics.cpp
modules/gui/skins2/win32/win32_graphics.hpp

index 8b856bfc04ed9f16563917c1cebd00d6531d428c..71b49719ca714b9ec8c36b3134bb6fd2410d3008 100644 (file)
@@ -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
index b3cbd95430a036203912426564340dd6feed6ff7..83f575a40a8333804ae54e5e92fa2fce2b7efcc2 100644 (file)
@@ -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 );
 };