aboutsummaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
authortassaron2017-07-02 21:38:19 -0400
committertassaron2017-07-02 21:38:19 -0400
commit3a6d7ae421ad2b650cac7f17d43be313787f0e61 (patch)
tree1788ad881bb621d6d3bc2962d3d8b65e9f952522 /src/components
parent0da275bf1b1dd2c956fed9d4a1051dcf3365c382 (diff)
frame-drawing tools for components to share
Diffstat (limited to 'src/components')
-rw-r--r--src/components/color.py27
-rw-r--r--src/components/image.py3
-rw-r--r--src/components/original.py5
-rw-r--r--src/components/text.py23
-rw-r--r--src/components/video.py9
5 files changed, 30 insertions, 37 deletions
diff --git a/src/components/color.py b/src/components/color.py
index bd45951..4a10263 100644
--- a/src/components/color.py
+++ b/src/components/color.py
@@ -5,6 +5,7 @@ from PIL.ImageQt import ImageQt
import os
from component import Component
+from frame import BlankFrame, FloodFrame, FramePainter, PaintColor
class Component(Component):
@@ -128,20 +129,19 @@ class Component(Component):
# in default state, skip all this logic and return a plain fill
if self.fillType == 0 and shapeSize == (width, height) \
and self.x == 0 and self.y == 0:
- return Image.new("RGBA", (width, height), (r, g, b, 255))
-
- frame = self.blankFrame(width, height)
+ return FloodFrame(width, height, (r, g, b, 255))
# Return a solid image at x, y
if self.fillType == 0:
+ frame = BlankFrame(width, height)
image = Image.new("RGBA", shapeSize, (r, g, b, 255))
frame.paste(image, box=(self.x, self.y))
return frame
# Now fills that require using Qt...
elif self.fillType > 0:
- image = ImageQt(frame)
- painter = QtGui.QPainter(image)
+ image = FramePainter(width, height)
+
if self.stretch:
w = width
h = height
@@ -164,21 +164,20 @@ class Component(Component):
self.RG_centre)
brush.setSpread(self.spread)
- brush.setColorAt(0.0, QColor(*self.color1))
+ brush.setColorAt(0.0, PaintColor(*self.color1))
if self.trans:
- brush.setColorAt(1.0, QColor(0, 0, 0, 0))
+ brush.setColorAt(1.0, PaintColor(0, 0, 0, 0))
elif self.fillType == 1 and self.stretch:
- brush.setColorAt(0.2, QColor(*self.color2))
+ brush.setColorAt(0.2, PaintColor(*self.color2))
else:
- brush.setColorAt(1.0, QColor(*self.color2))
- painter.setBrush(brush)
- painter.drawRect(
+ brush.setColorAt(1.0, PaintColor(*self.color2))
+ image.setBrush(brush)
+ image.drawRect(
self.x, self.y,
self.sizeWidth, self.sizeHeight
)
- painter.end()
- imBytes = image.bits().asstring(image.byteCount())
- return Image.frombytes('RGBA', (width, height), imBytes)
+
+ return image.finalize()
def loadPreset(self, pr, presetName=None):
super().loadPreset(pr, presetName)
diff --git a/src/components/image.py b/src/components/image.py
index ba99113..1aae51b 100644
--- a/src/components/image.py
+++ b/src/components/image.py
@@ -3,6 +3,7 @@ from PyQt5 import QtGui, QtCore, QtWidgets
import os
from component import Component
+from frame import BlankFrame
class Component(Component):
@@ -53,7 +54,7 @@ class Component(Component):
return self.drawFrame(width, height)
def drawFrame(self, width, height):
- frame = self.blankFrame(width, height)
+ frame = BlankFrame(width, height)
if self.imagePath and os.path.exists(self.imagePath):
image = Image.open(self.imagePath)
if self.stretched and image.size != (width, height):
diff --git a/src/components/original.py b/src/components/original.py
index 42049f3..82cdc1d 100644
--- a/src/components/original.py
+++ b/src/components/original.py
@@ -7,6 +7,7 @@ import time
from copy import copy
from component import Component
+from frame import BlankFrame
class Component(Component):
@@ -162,7 +163,7 @@ class Component(Component):
bF = width / 64
bH = bF / 2
bQ = bF / 4
- imTop = self.blankFrame(width, height)
+ imTop = BlankFrame(width, height)
draw = ImageDraw.Draw(imTop)
r, g, b = color
color2 = (r, g, b, 125)
@@ -180,7 +181,7 @@ class Component(Component):
imBottom = imTop.transpose(Image.FLIP_TOP_BOTTOM)
- im = self.blankFrame(width, height)
+ im = BlankFrame(width, height)
if layout == 0: # Classic
y = self.y - int(height/100*43)
diff --git a/src/components/text.py b/src/components/text.py
index 6be3120..97d7d07 100644
--- a/src/components/text.py
+++ b/src/components/text.py
@@ -1,11 +1,10 @@
from PIL import Image, ImageDraw
-from PyQt5.QtGui import QPainter, QColor, QFont
+from PyQt5.QtGui import QColor, QFont
from PyQt5 import QtGui, QtCore, QtWidgets
-from PIL.ImageQt import ImageQt
import os
-import sys
from component import Component
+from frame import FramePainter
class Component(Component):
@@ -131,22 +130,14 @@ class Component(Component):
def addText(self, width, height):
x, y = self.getXY()
- im = self.blankFrame(width, height)
- image = ImageQt(im)
+ image = FramePainter(width, height)
- painter = QPainter(image)
self.titleFont.setPixelSize(self.fontSize)
- painter.setFont(self.titleFont)
- if sys.byteorder == 'big':
- painter.setPen(QColor(*self.textColor))
- else:
- painter.setPen(QColor(*self.textColor[::-1]))
- painter.drawText(x, y, self.title)
- painter.end()
+ image.setFont(self.titleFont)
+ image.setPen(self.textColor)
+ image.drawText(x, y, self.title)
- imBytes = image.bits().asstring(image.byteCount())
-
- return Image.frombytes('RGBA', (width, height), imBytes)
+ return image.finalize()
def pickColor(self):
RGBstring, btnStyle = super().pickColor()
diff --git a/src/components/video.py b/src/components/video.py
index c5649c5..175cf29 100644
--- a/src/components/video.py
+++ b/src/components/video.py
@@ -7,6 +7,7 @@ import threading
from queue import PriorityQueue
from component import Component, BadComponentInit
+from frame import BlankFrame
class Video:
@@ -145,7 +146,7 @@ class Component(Component):
self.updateChunksize(width, height)
frame = self.getPreviewFrame(width, height)
if not frame:
- return self.blankFrame(width, height)
+ return BlankFrame(width, height)
else:
return frame
@@ -153,7 +154,7 @@ class Component(Component):
super().preFrameRender(**kwargs)
width = int(self.worker.core.settings.value('outputWidth'))
height = int(self.worker.core.settings.value('outputHeight'))
- self.blankFrame_ = self.blankFrame(width, height)
+ self.blankFrame_ = BlankFrame(width, height)
self.updateChunksize(width, height)
self.video = Video(
ffmpeg=self.parent.core.FFMPEG_BIN, videoPath=self.videoPath,
@@ -279,11 +280,11 @@ def finalizeFrame(self, imageData, width, height):
'### BAD VIDEO SELECTED ###\n'
'Video will not export with these settings'
)
- return self.blankFrame(width, height)
+ return BlankFrame(width, height)
if self.scale != 100 \
or self.xPosition != 0 or self.yPosition != 0:
- frame = self.blankFrame(width, height)
+ frame = BlankFrame(width, height)
frame.paste(image, box=(self.xPosition, self.yPosition))
else:
frame = image