Replaced pickled RAW data by BytesIO of JPEG-files to reduce memory footprint
This commit is contained in:
@@ -182,12 +182,12 @@ class CameraEvent(Event):
|
||||
def __init__(self, name, picture=None):
|
||||
|
||||
super().__init__(name)
|
||||
self._picture = util.pickle_image(picture)
|
||||
self._picture = picture
|
||||
|
||||
@property
|
||||
def picture(self):
|
||||
|
||||
return util.unpickle_image(self._picture)
|
||||
return self._picture
|
||||
|
||||
|
||||
class WorkerEvent(Event):
|
||||
@@ -441,12 +441,12 @@ class ReviewState(State):
|
||||
def __init__(self, picture):
|
||||
|
||||
super().__init__()
|
||||
self._picture = util.pickle_image(picture)
|
||||
self._picture = picture
|
||||
|
||||
@property
|
||||
def picture(self):
|
||||
|
||||
return util.unpickle_image(self._picture)
|
||||
return self._picture
|
||||
|
||||
def handleEvent(self, event, context):
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
import logging
|
||||
|
||||
from PIL import Image, ImageOps
|
||||
from io import BytesIO
|
||||
|
||||
from .PictureDimensions import PictureDimensions
|
||||
from .. import StateMachine
|
||||
@@ -132,8 +133,10 @@ class Camera:
|
||||
picture = picture.transpose(self._rotation)
|
||||
picture = picture.resize(self._pic_dims.previewSize)
|
||||
picture = ImageOps.mirror(picture)
|
||||
byte_data = BytesIO()
|
||||
picture.save(byte_data, format='jpeg')
|
||||
self._comm.send(Workers.GUI,
|
||||
StateMachine.CameraEvent('preview', picture))
|
||||
StateMachine.CameraEvent('preview', byte_data))
|
||||
|
||||
def capturePicture(self, state):
|
||||
|
||||
@@ -141,12 +144,14 @@ class Camera:
|
||||
picture = self._cap.getPicture()
|
||||
if self._rotation is not None:
|
||||
picture = picture.transpose(self._rotation)
|
||||
self._pictures.append(picture)
|
||||
byte_data = BytesIO()
|
||||
picture.save(byte_data, format='jpeg')
|
||||
self._pictures.append(byte_data)
|
||||
self.setActive()
|
||||
|
||||
if self._is_keep_pictures:
|
||||
self._comm.send(Workers.WORKER,
|
||||
StateMachine.CameraEvent('capture', picture))
|
||||
StateMachine.CameraEvent('capture', byte_data))
|
||||
|
||||
if state.num_picture < self._pic_dims.totalNumPictures:
|
||||
self._comm.send(Workers.MASTER,
|
||||
@@ -161,9 +166,12 @@ class Camera:
|
||||
|
||||
picture = self._template.copy()
|
||||
for i in range(self._pic_dims.totalNumPictures):
|
||||
resized = self._pictures[i].resize(self._pic_dims.thumbnailSize)
|
||||
shot = Image.open(self._pictures[i])
|
||||
resized = shot.resize(self._pic_dims.thumbnailSize)
|
||||
picture.paste(resized, self._pic_dims.thumbnailOffset[i])
|
||||
|
||||
byte_data = BytesIO()
|
||||
picture.save(byte_data, format='jpeg')
|
||||
self._comm.send(Workers.MASTER,
|
||||
StateMachine.CameraEvent('review', picture))
|
||||
StateMachine.CameraEvent('review', byte_data))
|
||||
self._pictures = []
|
||||
|
||||
@@ -24,7 +24,7 @@ from PyQt5 import QtCore
|
||||
from PyQt5 import QtGui
|
||||
from PyQt5 import QtWidgets
|
||||
|
||||
from PIL import ImageQt
|
||||
from PIL import Image, ImageQt
|
||||
|
||||
from ...StateMachine import GuiEvent, TeardownEvent
|
||||
from ...Threading import Workers
|
||||
@@ -198,7 +198,8 @@ class PyQt5Gui(GuiSkeleton):
|
||||
|
||||
def updateCountdown(self, event):
|
||||
|
||||
self._gui.centralWidget().picture = ImageQt.ImageQt(event.picture)
|
||||
picture = Image.open(event.picture)
|
||||
self._gui.centralWidget().picture = ImageQt.ImageQt(picture)
|
||||
self._gui.centralWidget().update()
|
||||
|
||||
def showCapture(self, state):
|
||||
@@ -215,7 +216,8 @@ class PyQt5Gui(GuiSkeleton):
|
||||
|
||||
def showReview(self, state):
|
||||
|
||||
self._picture = ImageQt.ImageQt(state.picture)
|
||||
picture = Image.open(state.picture)
|
||||
self._picture = ImageQt.ImageQt(picture)
|
||||
review_time = self._cfg.getInt('Photobooth', 'display_time') * 1000
|
||||
self._setWidget(Frames.PictureMessage(self._picture))
|
||||
QtCore.QTimer.singleShot(
|
||||
|
||||
@@ -50,7 +50,8 @@ class PictureSaver(WorkerTask):
|
||||
|
||||
filename = self._pic_list.getNext()
|
||||
logging.info('Saving picture as %s', filename)
|
||||
picture.save(filename, 'JPEG')
|
||||
with open(filename, 'wb') as f:
|
||||
f.write(picture.getbuffer())
|
||||
|
||||
|
||||
class Worker:
|
||||
|
||||
Reference in New Issue
Block a user