Commits

illume committed 77c972e

[BUG] Fixes #93. Where oversized input rect would not work
with surf.fill special flags like BLEND_ADD

Comments (0)

Files changed (2)

         rect = &temp;
     }
 
-    if (rect->w < 0 || rect->h < 0) {
+    if (rect->w < 0 || rect->h < 0 || rect->x > surf->w || rect->y > surf->h) {
         sdlrect.x = sdlrect.y = 0;
         sdlrect.w = sdlrect.h = 0;
     }
         sdlrect.w = rect->w;
         sdlrect.h = rect->h;
         
+        // clip the rect to be within the surface.
+        if(sdlrect.x + sdlrect.w > surf->w) {
+            sdlrect.w = sdlrect.w + (surf->w - (sdlrect.x + sdlrect.w));
+        }
+        if(sdlrect.y + sdlrect.h > surf->h) {
+            sdlrect.h = sdlrect.h + (surf->h - (sdlrect.y + sdlrect.h));
+        }
+
+
         if (blendargs != 0) {
             
             /* 

test/surface_test.py

                                      (dst.get_at((x, y)), tst.get_at((x, y)),
                                       x, y))
 
+
+
+
+    def test_blit_blend_big_rect(self):
+        """ test that an oversized rect works ok.
+        """
+        color = (1, 2, 3, 255)
+        area = (1, 1, 30, 30)
+        s1 = pygame.Surface((4, 4), 0, 32)
+        r = s1.fill(special_flags=pygame.BLEND_ADD, color=color, rect=area)
+        self.assertEquals(pygame.Rect((1, 1, 3, 3)), r)
+        self.assert_(s1.get_at((0, 0)) == (0, 0, 0, 255))
+        self.assert_(s1.get_at((1, 1)) == color)
+
+
+
+
+
     def test_GET_PIXELVALS(self):
         # surface.h GET_PIXELVALS bug regarding whether of not
         # a surface has per-pixel alpha. Looking at the Amask