1 """ Image transformations for use with the image loader. """
5 import pygame.locals as pgl
8 class Transform(object):
12 def __init__(self, **kw):
14 setattr(self, k, kw.pop(k))
16 self._repr = "%s: <%s>" % (
17 self.__class__.__name__,
18 ", ".join("%s=%s" % (k, getattr(self, k)) for k in self.ARGS))
25 return hash(self._repr)
27 def __eq__(self, other):
28 if not isinstance(other, Transform):
30 return self._repr == other._repr
32 def apply(self, surface):
33 raise NotImplementedError("Transforms should implement .apply")
36 class NullTransform(Transform):
39 def apply(self, surface):
43 class Overlay(Transform):
44 """ Apply a colour overlay. """
48 def apply(self, surface):
49 over = pygame.surface.Surface(surface.get_size())
50 over = over.convert_alpha()
51 over.fill(self.colour)
52 surface.blit(over, (0, 0), None)
56 class Multiply(Transform):
57 """ Apply a colour by multiplying. """
61 def apply(self, surface):
62 mult = pygame.surface.Surface(surface.get_size())
63 mult = mult.convert_alpha()
64 mult.fill(self.colour)
65 surface.blit(mult, (0, 0), None, pgl.BLEND_RGBA_MULT)
69 class Alpha(Transform):
70 """ Make translucent. """
74 def apply(self, surface):
75 surface.fill((255, 255, 255, self.alpha), None, pgl.BLEND_RGBA_MULT)