~pygame/pygame/trunk

« back to all changes in this revision

Viewing changes to test/blit_test.py

  • Committer: pygame
  • Date: 2017-01-10 00:31:42 UTC
  • Revision ID: git-v1:2eea4f299a2e791f884608d7ed601558634af73c
commit 1639c41a8cb3433046882ede92c80ce69d59016b
Author: Thomas Kluyver <takowl@gmail.com>
Date:   Sun Jan 8 18:46:46 2017 +0000

    Build newer versions of libogg and libvorbis into Linux base images

    Closes #317
    Closes #323

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
if __name__ == '__main__':
 
2
    import sys
 
3
    import os
 
4
    pkg_dir = os.path.split(os.path.abspath(__file__))[0]
 
5
    parent_dir, pkg_name = os.path.split(pkg_dir)
 
6
    is_pygame_pkg = (pkg_name == 'tests' and
 
7
                     os.path.split(parent_dir)[1] == 'pygame')
 
8
    if not is_pygame_pkg:
 
9
        sys.path.insert(0, parent_dir)
 
10
else:
 
11
    is_pygame_pkg = __name__.startswith('pygame.tests.')
 
12
 
 
13
import unittest
 
14
 
 
15
import pygame
 
16
from pygame.locals import *
 
17
 
 
18
class BlitTest( unittest.TestCase ):
 
19
    def test_SRCALPHA( self ):
 
20
        """ SRCALPHA tests.
 
21
        """
 
22
        #blend(s, 0, d) = d
 
23
        s = pygame.Surface((1,1), SRCALPHA, 32)
 
24
        s.fill((255, 255,255, 0))
 
25
 
 
26
        d = pygame.Surface((1,1), SRCALPHA, 32)
 
27
        d.fill((0, 0,255, 255))
 
28
 
 
29
        s.blit(d, (0,0))
 
30
        self.assertEqual(s.get_at((0,0)), d.get_at((0,0)) )
 
31
 
 
32
        #blend(s, 255, d) = s
 
33
        s = pygame.Surface((1,1), SRCALPHA, 32)
 
34
        s.fill((123, 0, 0, 255))
 
35
        s1 = pygame.Surface((1,1), SRCALPHA, 32)
 
36
        s1.fill((123, 0, 0, 255))
 
37
        d = pygame.Surface((1,1), SRCALPHA, 32)
 
38
        d.fill((10, 0,0, 0))
 
39
        s.blit(d, (0,0))
 
40
        self.assertEqual(s.get_at((0,0)), s1.get_at((0,0)) )
 
41
 
 
42
        #TODO: these should be true too.
 
43
        #blend(0, sA, 0) = 0
 
44
        #blend(255, sA, 255) = 255
 
45
        #blend(s, sA, d) <= 255
 
46
 
 
47
    def test_BLEND( self ):
 
48
        """ BLEND_ tests.
 
49
        """
 
50
 
 
51
        #test that it doesn't overflow, and that it is saturated.
 
52
        s = pygame.Surface((1,1), SRCALPHA, 32)
 
53
        s.fill((255, 255,255, 0))
 
54
 
 
55
        d = pygame.Surface((1,1), SRCALPHA, 32)
 
56
        d.fill((0, 0,255, 255))
 
57
 
 
58
        s.blit(d, (0,0), None, BLEND_ADD)
 
59
 
 
60
        #print "d %s" % (d.get_at((0,0)),)
 
61
        #print s.get_at((0,0))
 
62
        #self.assertEqual(s.get_at((0,0))[2], 255 )
 
63
        #self.assertEqual(s.get_at((0,0))[3], 0 )
 
64
 
 
65
 
 
66
 
 
67
        s.blit(d, (0,0), None, BLEND_RGBA_ADD)
 
68
        #print s.get_at((0,0))
 
69
        self.assertEqual(s.get_at((0,0))[3], 255 )
 
70
 
 
71
 
 
72
        # test adding works.
 
73
        s.fill((20, 255,255, 0))
 
74
        d.fill((10, 0,255, 255))
 
75
        s.blit(d, (0,0), None, BLEND_ADD)
 
76
        self.assertEqual(s.get_at((0,0))[2], 255 )
 
77
 
 
78
        # test subbing works.
 
79
        s.fill((20, 255,255, 0))
 
80
        d.fill((10, 0,255, 255))
 
81
        s.blit(d, (0,0), None, BLEND_SUB)
 
82
        self.assertEqual(s.get_at((0,0))[0], 10 )
 
83
 
 
84
        # no overflow in sub blend.
 
85
        s.fill((20, 255,255, 0))
 
86
        d.fill((30, 0,255, 255))
 
87
        s.blit(d, (0,0), None, BLEND_SUB)
 
88
        self.assertEqual(s.get_at((0,0))[0], 0 )
 
89
 
 
90
 
 
91
 
 
92
if __name__ == '__main__':
 
93
    unittest.main()