diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index ade4bc019..0bf07381b 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -81,6 +81,9 @@ html_expands.append({u'desc':u'Italics', u'start tag':u'{it}', u'start html':u'', u'end tag':u'{/it}', u'end html':u'', u'protected':True}) +# Image cache to stop regualar image resizing +cache = {} + def translate(context, text, comment=None): """ A special shortcut method to wrap around the Qt4 translation functions. @@ -220,7 +223,7 @@ def image_to_byte(image): ``image`` The image to converted. """ - log.debug(u'image_to_byte') + log.debug(u'image_to_byte') byte_array = QtCore.QByteArray() # use buffer to store pixmap into byteArray buffie = QtCore.QBuffer(byte_array) @@ -250,7 +253,7 @@ def resize_image(image, width, height, background=QtCore.Qt.black): The background colour defaults to black. """ - log.debug(u'resize_image') + log.debug(u'resize_image') preview = QtGui.QImage(image) if not preview.isNull(): # Only resize if different size @@ -258,6 +261,9 @@ def resize_image(image, width, height, background=QtCore.Qt.black): return preview preview = preview.scaled(width, height, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation) + cache_key = u'%s%s%s' % (image, unicode(width), unicode(height)) + if cache_key in cache: + return cache[cache_key] realw = preview.width() realh = preview.height() # and move it to the centre of the preview space @@ -266,6 +272,8 @@ def resize_image(image, width, height, background=QtCore.Qt.black): new_image.fill(background) painter = QtGui.QPainter(new_image) painter.drawImage((width - realw) / 2, (height - realh) / 2, preview) + cache[cache_key] = new_image + print cache return new_image def check_item_selected(list_widget, message): diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 93271a604..147e2fffc 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -188,7 +188,7 @@ class ImageMediaItem(MediaManagerItem): bitem = self.listView.item(item.row()) filename = unicode(bitem.data(QtCore.Qt.UserRole).toString()) frame = QtGui.QImage(unicode(filename)) - self.parent.liveController.display.image(frame) + self.parent.liveController.display.image(filename) self.resetButton.setVisible(True) def onPreviewClick(self):