Source

pygame / test / blit_test.py

import unittest
import pygame
from pygame.locals import *

class BlitTest( unittest.TestCase ):
    def test_SRCALPHA( self ):
        """ SRCALPHA tests.
        """

        #blend(s, 0, d) = d
        s = pygame.Surface((1,1), SRCALPHA, 32)
        s.fill((255, 255,255, 0))

        d = pygame.Surface((1,1), SRCALPHA, 32)
        d.fill((0, 0,255, 255))

        s.blit(d, (0,0))
        self.assertEqual(s.get_at((0,0)), d.get_at((0,0)) )



        #blend(s, 255, d) = s
        s = pygame.Surface((1,1), SRCALPHA, 32)
        s.fill((123, 0, 0, 255))
        s1 = pygame.Surface((1,1), SRCALPHA, 32)
        s1.fill((123, 0, 0, 255))
        d = pygame.Surface((1,1), SRCALPHA, 32)
        d.fill((10, 0,0, 0))
        s.blit(d, (0,0))
        self.assertEqual(s.get_at((0,0)), s1.get_at((0,0)) )


        #TODO: these should be true too.
        #blend(0, sA, 0) = 0
        #blend(255, sA, 255) = 255
        #blend(s, sA, d) <= 255


    def test_BLEND( self ):
        """ BLEND_ tests.
        """

        #test that it doesn't overflow, and that it is saturated.
        s = pygame.Surface((1,1))
        s.fill((255, 255,255, 0))

        d = pygame.Surface((1,1))
        d.fill((0, 0,255, 255))

        s.blit(d, (0,0), None, BLEND_ADD)
        self.assertEqual(s.get_at((0,0))[2], 255 )

        # test adding works.
        s.fill((20, 255,255, 0))
        d.fill((10, 0,255, 255))
        s.blit(d, (0,0), None, BLEND_ADD)
        self.assertEqual(s.get_at((0,0))[2], 255 )

        # test subbing works.
        s.fill((20, 255,255, 0))
        d.fill((10, 0,255, 255))
        s.blit(d, (0,0), None, BLEND_SUB)
        self.assertEqual(s.get_at((0,0))[0], 10 )

        # no overflow in sub blend.
        s.fill((20, 255,255, 0))
        d.fill((30, 0,255, 255))
        s.blit(d, (0,0), None, BLEND_SUB)
        self.assertEqual(s.get_at((0,0))[0], 0 )



if __name__ == '__main__':
    unittest.main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.