1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import gtk
24
26 '''
27 Cache pixbuf use to cache pixbuf to avoid new pixbuf generate by scale_simple.
28
29 gtk.gdk.pixbuf.scale_simple is function will make application very slow,
30
31 We use CachePixbuf increase the call times of gtk.gdk.pixbuf.scale_simple.
32 '''
33
35 '''
36 Init cache pixbuf.
37 '''
38 self.pixbuf = None
39 self.cache_pixbuf = None
40 self.scale_width = None
41 self.scale_height = None
42 self.vertical_mirror = False
43 self.horizontal_mirror = False
44
45 - def scale(self, pixbuf, scale_width, scale_height, vertical_mirror=False, horizontal_mirror=False):
46 '''
47 Scale with given sizce and return new pixbuf.
48
49 @param pixbuf: Original pixbuf.
50 @param scale_width: Scale width of pixbuf.
51 @param scale_height: Scale height of pixbuf.
52 @param vertical_mirror: Whether pixbuf mirror vertically.
53 @param horizontal_mirror: Whether pixbuf mirror horizontally.
54 '''
55 if self.pixbuf != pixbuf or self.scale_width != scale_width or self.scale_height != scale_height:
56
57 self.pixbuf = pixbuf
58 self.scale_width = scale_width
59 self.scale_height = scale_height
60
61
62 self.cache_pixbuf = pixbuf.scale_simple(scale_width, scale_height, gtk.gdk.INTERP_BILINEAR)
63
64
65 if self.vertical_mirror:
66 self.cache_pixbuf = self.cache_pixbuf.flip(True)
67
68
69 if self.horizontal_mirror:
70 self.cache_pixbuf = self.cache_pixbuf.flip(False)
71
72
73 if self.vertical_mirror != vertical_mirror:
74 self.vertical_mirror = vertical_mirror
75 self.cache_pixbuf = self.cache_pixbuf.flip(True)
76
77
78 if self.horizontal_mirror != horizontal_mirror:
79 self.horizontal_mirror = horizontal_mirror
80 self.cache_pixbuf = self.cache_pixbuf.flip(False)
81
83 '''
84 Get pixbuf cache.
85
86 @return: Return cache pixbuf.
87 '''
88 return self.cache_pixbuf
89