forked from openlp/openlp
Initial version of Image performance improvements
This commit is contained in:
parent
63b3be4767
commit
6dbb80ee94
@ -314,6 +314,7 @@ def expand_tags(text):
|
||||
|
||||
from spelltextedit import SpellTextEdit
|
||||
from eventreceiver import Receiver
|
||||
from imagemanager import ImageManager
|
||||
from settingsmanager import SettingsManager
|
||||
from plugin import PluginStatus, StringContent, Plugin
|
||||
from pluginmanager import PluginManager
|
||||
|
@ -73,7 +73,7 @@ class Renderer(object):
|
||||
self.theme_name = theme.theme_name
|
||||
if theme.background_type == u'image':
|
||||
if theme.background_filename:
|
||||
self._bg_image_filename = unicode(theme.background_filename)
|
||||
self._bg_image_filename =theme.background_filename
|
||||
|
||||
def set_text_rectangle(self, rect_main, rect_footer):
|
||||
"""
|
||||
@ -118,25 +118,16 @@ class Renderer(object):
|
||||
"""
|
||||
log.debug(u'set frame dest (frame) w %d h %d', frame_width,
|
||||
frame_height)
|
||||
self.frame = QtGui.QImage(frame_width, frame_height,
|
||||
QtGui.QImage.Format_ARGB32_Premultiplied)
|
||||
if self._bg_image_filename and not self.bg_image:
|
||||
self.bg_image = resize_image(self._bg_image_filename,
|
||||
self.frame.width(), self.frame.height())
|
||||
if self._theme.background_type == u'image':
|
||||
self.bg_frame = QtGui.QImage(self.frame.width(),
|
||||
self.frame.height(),
|
||||
frame = QtGui.QImage(frame_width, frame_height,
|
||||
QtGui.QImage.Format_ARGB32_Premultiplied)
|
||||
painter = QtGui.QPainter()
|
||||
painter.begin(self.bg_frame)
|
||||
painter.fillRect(self.frame.rect(), QtCore.Qt.black)
|
||||
if self.bg_image:
|
||||
painter.drawImage(0, 0, self.bg_image)
|
||||
painter.end()
|
||||
self.bg_image_bytes = image_to_byte(self.bg_frame)
|
||||
self.bg_image = resize_image(self._bg_image_filename,
|
||||
frame.width(), frame.height())
|
||||
self.bg_image_bytes = image_to_byte(self.bg_image)
|
||||
else:
|
||||
self.bg_frame = None
|
||||
self.bg_image_bytes = None
|
||||
log.debug(u'end frame dest (frame)')
|
||||
|
||||
def format_slide(self, words, line_break):
|
||||
"""
|
||||
|
@ -28,7 +28,7 @@ import logging
|
||||
|
||||
from PyQt4 import QtCore
|
||||
|
||||
from openlp.core.lib import Renderer, ThemeLevel, ServiceItem
|
||||
from openlp.core.lib import Renderer, ThemeLevel, ServiceItem, ImageManager
|
||||
from openlp.core.ui import MainDisplay
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@ -56,6 +56,7 @@ class RenderManager(object):
|
||||
"""
|
||||
log.debug(u'Initilisation started')
|
||||
self.screens = screens
|
||||
self.image_manager = ImageManager()
|
||||
self.display = MainDisplay(self, screens, False)
|
||||
self.display.setup()
|
||||
self.theme_manager = theme_manager
|
||||
@ -78,6 +79,7 @@ class RenderManager(object):
|
||||
self.display.setup()
|
||||
self.renderer.bg_frame = None
|
||||
self.themedata = None
|
||||
self.image_manager.update_display(self.width, self.height)
|
||||
|
||||
def set_global_theme(self, global_theme, theme_level=ThemeLevel.Global):
|
||||
"""
|
||||
@ -153,6 +155,8 @@ class RenderManager(object):
|
||||
self.calculate_default(self.screens.current[u'size'])
|
||||
self.renderer.set_theme(self.themedata)
|
||||
self.build_text_rectangle(self.themedata)
|
||||
self.image_manager.add_image(self.themedata.theme_name,
|
||||
self.themedata.background_filename)
|
||||
self.renderer.set_frame_dest(self.width, self.height)
|
||||
return self.renderer._rect, self.renderer._rect_footer
|
||||
|
||||
|
@ -208,6 +208,7 @@ class ServiceItem(object):
|
||||
self.service_item_type = ServiceItemType.Image
|
||||
self._raw_frames.append(
|
||||
{u'title': title, u'image': image, u'path': path})
|
||||
self.render_manager.image_manager.add_image(title, path)
|
||||
self._new_item()
|
||||
|
||||
def add_from_text(self, title, raw_slide, verse_tag=None):
|
||||
@ -389,7 +390,7 @@ class ServiceItem(object):
|
||||
if self.service_item_type == ServiceItemType.Text:
|
||||
return None, self._display_frames[row][u'html'].split(u'\n')[0]
|
||||
else:
|
||||
return self._raw_frames[row][u'image'], u''
|
||||
return self._raw_frames[row][u'title'], u''
|
||||
|
||||
def get_frame_title(self, row=0):
|
||||
"""
|
||||
|
@ -222,7 +222,7 @@ class MainDisplay(DisplayWidget):
|
||||
shrinkItem.resize(self.screen[u'size'].width(),
|
||||
self.screen[u'size'].height())
|
||||
|
||||
def image(self, image):
|
||||
def image(self, name):
|
||||
"""
|
||||
Add an image as the background. The image is converted to a
|
||||
bytestream on route.
|
||||
@ -231,9 +231,8 @@ class MainDisplay(DisplayWidget):
|
||||
The Image to be displayed can be QImage or QPixmap
|
||||
"""
|
||||
log.debug(u'image to display')
|
||||
if not isinstance(image, QtGui.QImage):
|
||||
image = resize_image(image, self.screen[u'size'].width(),
|
||||
self.screen[u'size'].height())
|
||||
image = self.parent.parent.RenderManager.image_manager. \
|
||||
get_image(name)
|
||||
self.resetVideo()
|
||||
self.displayImage(image)
|
||||
# show screen
|
||||
|
@ -37,24 +37,6 @@ from openlp.core.lib import OpenLPToolbar, Receiver, resize_image, \
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class SlideThread(QtCore.QThread):
|
||||
"""
|
||||
A special Qt thread class to speed up the display of text based frames.
|
||||
This is threaded so it loads the frames in background
|
||||
"""
|
||||
def __init__(self, parent, prefix, count):
|
||||
QtCore.QThread.__init__(self, parent)
|
||||
self.prefix = prefix
|
||||
self.count = count
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
Run the thread.
|
||||
"""
|
||||
time.sleep(1)
|
||||
for i in range(0, self.count):
|
||||
Receiver.send_message(u'%s_slide_cache' % self.prefix, i)
|
||||
|
||||
class SlideList(QtGui.QTableWidget):
|
||||
"""
|
||||
Customised version of QTableWidget which can respond to keyboard
|
||||
@ -410,8 +392,6 @@ class SlideController(QtGui.QWidget):
|
||||
if self.isLive:
|
||||
QtCore.QObject.connect(self.volumeSlider,
|
||||
QtCore.SIGNAL(u'sliderReleased()'), self.mediaVolume)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'%s_slide_cache' % self.typePrefix), self.slideCache)
|
||||
|
||||
def screenSizeChanged(self):
|
||||
"""
|
||||
@ -606,13 +586,9 @@ class SlideController(QtGui.QWidget):
|
||||
label = QtGui.QLabel()
|
||||
label.setMargin(4)
|
||||
label.setScaledContents(True)
|
||||
if isinstance(frame[u'image'], QtGui.QImage):
|
||||
label.setPixmap(QtGui.QPixmap.fromImage(frame[u'image']))
|
||||
else:
|
||||
pixmap = resize_image(frame[u'image'],
|
||||
self.parent.RenderManager.width,
|
||||
self.parent.RenderManager.height)
|
||||
label.setPixmap(QtGui.QPixmap.fromImage(pixmap))
|
||||
image = self.parent.RenderManager.image_manager. \
|
||||
get_image(frame[u'title'])
|
||||
label.setPixmap(QtGui.QPixmap.fromImage(image))
|
||||
self.PreviewListWidget.setCellWidget(framenumber, 0, label)
|
||||
slideHeight = width * self.parent.RenderManager.screen_ratio
|
||||
row += 1
|
||||
@ -638,10 +614,6 @@ class SlideController(QtGui.QWidget):
|
||||
self.PreviewListWidget.setFocus()
|
||||
Receiver.send_message(u'slidecontroller_%s_started' % self.typePrefix,
|
||||
[serviceItem])
|
||||
if self.serviceItem.is_image():
|
||||
st = SlideThread(
|
||||
self, self.typePrefix, len(self.serviceItem.get_frames()))
|
||||
st.start()
|
||||
|
||||
def onTextRequest(self):
|
||||
"""
|
||||
@ -794,13 +766,6 @@ class SlideController(QtGui.QWidget):
|
||||
% self.serviceItem.name.lower(),
|
||||
[self.serviceItem, self.isLive])
|
||||
|
||||
def slideCache(self, slide):
|
||||
"""
|
||||
Generate a slide cache item rendered and ready for use
|
||||
in the background.
|
||||
"""
|
||||
self.serviceItem.get_rendered_frame(int(slide))
|
||||
|
||||
def onSlideSelected(self):
|
||||
"""
|
||||
Generate the preview when you click on a slide.
|
||||
|
@ -166,9 +166,9 @@ class ImageMediaItem(MediaManagerItem):
|
||||
for item in items:
|
||||
bitem = self.listView.item(item.row())
|
||||
filename = unicode(bitem.data(QtCore.Qt.UserRole).toString())
|
||||
frame = QtGui.QImage(unicode(filename))
|
||||
#frame = QtGui.QImage(unicode(filename))
|
||||
(path, name) = os.path.split(filename)
|
||||
service_item.add_from_image(path, name, frame)
|
||||
service_item.add_from_image(path, name, None)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
Loading…
Reference in New Issue
Block a user