- Updated texture resizes to use pixbuf resizes. Greatly improved performance inn GridViewer
This commit is contained in:
parent
2331c612b0
commit
41279d04b5
|
@ -18,6 +18,8 @@ class Module:
|
|||
imageDuration = 7 # In seconds
|
||||
effect_FPS = 50
|
||||
|
||||
max_percent_of_stage = 0.75 # The maximum percentage of the stage size that images can be
|
||||
|
||||
def __init__(self, glossMgr, dbMgr):
|
||||
self.glossMgr = glossMgr
|
||||
self.setup_ui()
|
||||
|
@ -106,6 +108,10 @@ class Module:
|
|||
self.stage = self.glossMgr.get_stage()
|
||||
self.currentTexture = clutter.Texture()
|
||||
|
||||
#Set the maximum sizes of the images
|
||||
self.max_height = int(self.stage.get_height() * self.max_percent_of_stage)
|
||||
self.max_width = int(self.stage.get_width() * self.max_percent_of_stage)
|
||||
|
||||
#Check for an empty baseDir, this means there are no slideshows or no db connection. We simply tell the menuMgr to go back a menu level when this occurs
|
||||
if self.baseDir is None:
|
||||
MenuMgr.go_up_x_levels(1)
|
||||
|
@ -155,10 +161,8 @@ class Module:
|
|||
|
||||
#print "No of children: " + str(self.image_texture_group.get_n_children())
|
||||
#Get a random texture
|
||||
self.rand1 = random.randint(0, len(self.textures)-1)
|
||||
self.currentFilename = self.textures[self.rand1]
|
||||
pixbuf = gtk.gdk.pixbuf_new_from_file(self.currentFilename)
|
||||
self.currentTexture.set_pixbuf(pixbuf)
|
||||
self.currentFilename = ""
|
||||
self.currentTexture = self.get_rand_texture()
|
||||
|
||||
(x_pos, y_pos) = self.get_random_coords(self.currentTexture)
|
||||
self.currentTexture.set_position(x_pos, y_pos)
|
||||
|
@ -191,17 +195,8 @@ class Module:
|
|||
self.alpha = clutter.Alpha(self.timeline_main, clutter.ramp_inc_func)
|
||||
|
||||
#Decide on the next texture to use
|
||||
self.nextTexture = None
|
||||
while (self.nextTexture == None):
|
||||
self.rand1 = random.randint(0, len(self.textures)-1 )
|
||||
self.nextTexture = clutter.Texture()
|
||||
self.newFilename = self.textures[self.rand1]
|
||||
pixbuf = gtk.gdk.pixbuf_new_from_file(self.newFilename)
|
||||
self.nextTexture.set_pixbuf(pixbuf)
|
||||
#self.nextTexture.set_anchor_point_from_gravity(clutter.GRAVITY_CENTER)
|
||||
#Make sure we don't show the same photo twice
|
||||
if (self.newFilename == self.currentFilename) and (len(self.textures) > 1):
|
||||
self.nextTexture = None
|
||||
self.nextTexture = self.get_rand_texture()
|
||||
|
||||
|
||||
#Make sure its not visible initially (Prevents a nasty flicker the first time a photo is shown)
|
||||
self.nextTexture.set_opacity(0)
|
||||
|
@ -228,6 +223,36 @@ class Module:
|
|||
self.behaviour2.apply(self.currentTexture)
|
||||
self.timeline_main.start()
|
||||
|
||||
#Just gets a random texture
|
||||
def get_rand_texture(self):
|
||||
self.nextTexture = None
|
||||
while (self.nextTexture == None):
|
||||
self.rand1 = random.randint(0, len(self.textures)-1 )
|
||||
self.newFilename = self.textures[self.rand1]
|
||||
#Make sure we don't show the same photo twice
|
||||
if (self.newFilename == self.currentFilename) and (len(self.textures) > 1):
|
||||
self.nextTexture = None
|
||||
else:
|
||||
self.nextTexture = clutter.Texture()
|
||||
pixbuf = gtk.gdk.pixbuf_new_from_file(self.newFilename)
|
||||
self.currentFilename = self.newFilename
|
||||
|
||||
#Do a check on the size of the image
|
||||
if (pixbuf.get_width() > self.max_width) or (pixbuf.get_height() > self.max_height):
|
||||
#Resize as necesary
|
||||
xy_ratio = float(pixbuf.get_width()) / pixbuf.get_height()
|
||||
if pixbuf.get_width() > pixbuf.get_height():
|
||||
width = self.max_width
|
||||
height = int(width / xy_ratio)
|
||||
else:
|
||||
height = self.max_height
|
||||
width = int(xy_ratio * height)
|
||||
|
||||
pixbuf = pixbuf.scale_simple(width, height, gtk.gdk.INTERP_BILINEAR)
|
||||
|
||||
self.nextTexture.set_pixbuf(pixbuf)
|
||||
|
||||
return self.nextTexture
|
||||
|
||||
def image_timeline_end_event(self, data):
|
||||
#Add the timeline for the dissolve at the end
|
||||
|
@ -261,8 +286,8 @@ class Module:
|
|||
self.nextImage(self.currentTexture)
|
||||
|
||||
def get_random_coords(self, texture):
|
||||
x_pos = random.randint(texture.get_width()/2, (self.stage.get_width() - texture.get_width()) ) #Somewhere between 0 and (stage_width-image_width)
|
||||
y_pos = random.randint(texture.get_height()/2, (self.stage.get_height() - texture.get_height()) )
|
||||
x_pos = random.randint(texture.get_width()/2, (self.stage.get_width() - texture.get_width()/2) ) #Somewhere between 0 and (stage_width-image_width)
|
||||
y_pos = random.randint(texture.get_height()/2, (self.stage.get_height() - texture.get_height()/2) )
|
||||
|
||||
return (x_pos, y_pos)
|
||||
|
||||
|
|
|
@ -34,26 +34,25 @@ class cover_item(clutter.Group):
|
|||
self.video = video
|
||||
|
||||
self.main_pic = clutter.Texture()
|
||||
self.main_pic.set_pixbuf(pixbuf)
|
||||
|
||||
|
||||
self.main_pic.show()
|
||||
#New method of resizing changes size of pixbuf rather than texture.... MUCH better performance :)
|
||||
(x, y) = (0, 0)
|
||||
if self.main_pic.get_height() > self.main_pic.get_width():
|
||||
xy_ratio = float(self.main_pic.get_width()) / self.main_pic.get_height()
|
||||
self.main_pic.set_height(cover_size)
|
||||
if pixbuf.get_height() > pixbuf.get_width():
|
||||
xy_ratio = float(pixbuf.get_width()) / pixbuf.get_height()
|
||||
height = cover_size
|
||||
width = int(cover_size * xy_ratio)
|
||||
self.main_pic.set_width(width)
|
||||
x = (cover_size - width)/2
|
||||
#x = int(cover_size / 2)
|
||||
#x = x + (cover_size - width)
|
||||
else:
|
||||
xy_ratio = float(self.main_pic.get_height()) / float(self.main_pic.get_width())
|
||||
self.main_pic.set_width(cover_size)
|
||||
xy_ratio = float(pixbuf.get_height()) / float(pixbuf.get_width())
|
||||
width = cover_size
|
||||
height = int(cover_size * xy_ratio)
|
||||
self.main_pic.set_height(height)
|
||||
y = (cover_size - height)/2
|
||||
#y = y + (cover_size - height)
|
||||
pixbuf = pixbuf.scale_simple(width, height, gtk.gdk.INTERP_BILINEAR)
|
||||
self.main_pic.set_pixbuf(pixbuf)
|
||||
self.main_pic.show()
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -152,19 +152,20 @@ class image_previewer(clutter.Group):
|
|||
|
||||
texture = clutter.Texture()
|
||||
pixbuf = gtk.gdk.pixbuf_new_from_file(self.textures[rand])
|
||||
texture.set_pixbuf(pixbuf)
|
||||
|
||||
|
||||
#Set the image size based on the max bounds
|
||||
xy_ratio = float(texture.get_width()) / texture.get_height()
|
||||
if texture.get_width() > texture.get_height():
|
||||
texture.set_width(self.max_img_width)
|
||||
xy_ratio = float(pixbuf.get_width()) / pixbuf.get_height()
|
||||
if pixbuf.get_width() > pixbuf.get_height():
|
||||
width = self.max_img_width
|
||||
height = int(self.max_img_width / xy_ratio)
|
||||
texture.set_height(height)
|
||||
else:
|
||||
texture.set_height(self.max_img_height)
|
||||
height = self.max_img_height
|
||||
width = int(xy_ratio * self.max_img_height)
|
||||
texture.set_width(width)
|
||||
|
||||
pixbuf = pixbuf.scale_simple(width, height, gtk.gdk.INTERP_BILINEAR)
|
||||
|
||||
texture.set_pixbuf(pixbuf)
|
||||
reflectionTexture = Texture_Reflection(texture)
|
||||
|
||||
textureGroup = clutter.Group()
|
||||
|
@ -172,7 +173,6 @@ class image_previewer(clutter.Group):
|
|||
textureGroup.add(reflectionTexture)
|
||||
texture.show()
|
||||
reflectionTexture.show()
|
||||
#texture.set_width(width)
|
||||
return textureGroup
|
||||
|
||||
def next_image(self, data):
|
||||
|
|
Loading…
Reference in New Issue