text and visualization colour can be changed using commandline

This commit is contained in:
tassaron 2017-05-22 19:42:32 -04:00
parent 77eed58a87
commit 07644f0348
4 changed files with 62 additions and 21 deletions

13
core.py
View File

@ -42,7 +42,8 @@ class Core():
else:
return self.getVideoFrames(backgroundImage, preview)
def drawBaseImage(self, backgroundFile, titleText, titleFont, fontSize, alignment, xOffset, yOffset):
def drawBaseImage(self, backgroundFile, titleText, titleFont, fontSize, alignment,\
xOffset, yOffset, textColor, visColor):
if backgroundFile == '':
im = Image.new("RGB", (1280, 720), "black")
else:
@ -62,7 +63,7 @@ class Core():
font = titleFont
font.setPointSizeF(fontSize)
painter.setFont(font)
painter.setPen(QColor(255, 255, 255))
painter.setPen(QColor(*textColor))
yPosition = yOffset
@ -86,13 +87,15 @@ class Core():
strio.seek(0)
return Image.open(strio)
def drawBars(self, spectrum, image):
def drawBars(self, spectrum, image, color):
imTop = Image.new("RGBA", (1280, 360))
draw = ImageDraw.Draw(imTop)
r, g, b = color
color2 = (r, g, b, 50)
for j in range(0, 63):
draw.rectangle((10 + j * 20, 325, 10 + j * 20 + 20, 325 - spectrum[j * 4] * 1 - 10), fill=(255, 255, 255, 50))
draw.rectangle((15 + j * 20, 320, 15 + j * 20 + 10, 320 - spectrum[j * 4] * 1), fill="white")
draw.rectangle((10 + j * 20, 325, 10 + j * 20 + 20, 325 - spectrum[j * 4] * 1 - 10), fill=color2)
draw.rectangle((15 + j * 20, 320, 15 + j * 20 + 10, 320 - spectrum[j * 4] * 1), fill=color)
imBottom = imTop.transpose(Image.FLIP_TOP_BOTTOM)

41
main.py
View File

@ -15,7 +15,7 @@ import preview_thread, core, video_thread
class Command(QtCore.QObject):
videoTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int, str, str)
videoTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int, tuple, tuple, str, str)
def __init__(self):
QtCore.QObject.__init__(self)
@ -28,12 +28,36 @@ class Command(QtCore.QObject):
self.parser.add_argument('-t', '--text', dest='text', help='title text', required=True)
self.parser.add_argument('-f', '--font', dest='font', help='title font', required=False)
self.parser.add_argument('-s', '--fontsize', dest='fontsize', help='title font size', required=False)
self.parser.add_argument('-c', '--textcolor', dest='textcolor', help='title text color', required=False)
self.parser.add_argument('-C', '--viscolor', dest='viscolor', help='visualization color', required=False)
self.parser.add_argument('-x', '--xposition', dest='xposition', help='x position', required=False)
self.parser.add_argument('-y', '--yposition', dest='yposition', help='y position', required=False)
self.parser.add_argument('-a', '--alignment', dest='alignment', help='title alignment', required=False, type=int, choices=[0, 1, 2])
self.args = self.parser.parse_args()
self.settings = QSettings('settings.ini', QSettings.IniFormat)
# colour settings
RGBError = 'Bad RGB input (use two commas)'
self.textcolor = (255, 255, 255)
self.viscolor = (255, 255, 255)
if self.args.textcolor:
try:
r, g, b = self.args.textcolor.split(',')
except:
print(RGBError)
else:
self.textcolor = (int(r), int(g), int(b))
if self.args.viscolor:
try:
r, g, b = self.args.viscolor.split(',')
except:
print(RGBError)
else:
self.viscolor = (int(r), int(g), int(b))
# font settings
if self.args.font:
self.font = QFont(self.args.font)
else:
@ -43,7 +67,6 @@ class Command(QtCore.QObject):
self.fontsize = int(self.args.fontsize)
else:
self.fontsize = int(self.settings.value("fontSize", 35))
if self.args.alignment:
self.alignment = int(self.args.alignment)
else:
@ -75,6 +98,8 @@ class Command(QtCore.QObject):
self.alignment,
self.textX,
self.textY,
self.textcolor,
self.viscolor,
self.args.input,
self.args.output)
@ -93,9 +118,9 @@ class Command(QtCore.QObject):
class Main(QtCore.QObject):
newTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int)
newTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int, tuple, tuple)
processTask = QtCore.pyqtSignal()
videoTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int, str, str)
videoTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int, tuple, tuple, str, str)
def __init__(self, window):
@ -106,6 +131,8 @@ class Main(QtCore.QObject):
self.core = core.Core()
self.settings = QSettings('settings.ini', QSettings.IniFormat)
self.textcolor = (255, 255, 255)
self.viscolor = (255, 255, 255)
self.previewQueue = Queue()
@ -236,6 +263,8 @@ class Main(QtCore.QObject):
self.window.alignmentComboBox.currentIndex(),
self.window.textXSpinBox.value(),
self.window.textYSpinBox.value(),
self.textcolor,
self.viscolor,
self.window.label_input.text(),
self.window.label_output.text())
@ -257,7 +286,9 @@ class Main(QtCore.QObject):
self.window.fontsizeSpinBox.value(),
self.window.alignmentComboBox.currentIndex(),
self.window.textXSpinBox.value(),
self.window.textYSpinBox.value())
self.window.textYSpinBox.value(),
self.textcolor,
self.viscolor)
# self.processTask.emit()
def showPreviewImage(self, image):

View File

@ -19,8 +19,9 @@ class Worker(QtCore.QObject):
self.queue = queue
@pyqtSlot(str, str, QtGui.QFont, int, int, int, int)
def createPreviewImage(self, backgroundImage, titleText, titleFont, fontSize, alignment, xOffset, yOffset):
@pyqtSlot(str, str, QtGui.QFont, int, int, int, int, tuple, tuple)
def createPreviewImage(self, backgroundImage, titleText, titleFont, fontSize,\
alignment, xOffset, yOffset, textColor, visColor):
# print('worker thread id: {}'.format(QtCore.QThread.currentThreadId()))
dic = {
"backgroundImage": backgroundImage,
@ -29,7 +30,9 @@ class Worker(QtCore.QObject):
"fontSize": fontSize,
"alignment": alignment,
"xoffset": xOffset,
"yoffset": yOffset
"yoffset": yOffset,
"textColor" : textColor,
"visColor" : visColor
}
self.queue.put(dic)
@ -59,11 +62,12 @@ class Worker(QtCore.QObject):
nextPreviewInformation["fontSize"],
nextPreviewInformation["alignment"],
nextPreviewInformation["xoffset"],
nextPreviewInformation["yoffset"])
nextPreviewInformation["yoffset"],
nextPreviewInformation["textColor"],
nextPreviewInformation["visColor"])
spectrum = numpy.fromfunction(lambda x: 0.008*(x-128)**2, (255,), dtype="int16")
im = self.core.drawBars(spectrum, im)
im = self.core.drawBars(spectrum, im, nextPreviewInformation["visColor"])
self._image = ImageQt(im)
self._previewImage = QtGui.QImage(self._image)

View File

@ -19,8 +19,9 @@ class Worker(QtCore.QObject):
self.core = core.Core()
@pyqtSlot(str, str, QtGui.QFont, int, int, int, int, str, str)
def createVideo(self, backgroundImage, titleText, titleFont, fontSize, alignment, xOffset, yOffset, inputFile, outputFile):
@pyqtSlot(str, str, QtGui.QFont, int, int, int, int, tuple, tuple, str, str)
def createVideo(self, backgroundImage, titleText, titleFont, fontSize, alignment,\
xOffset, yOffset, textColor, visColor, inputFile, outputFile):
# print('worker thread id: {}'.format(QtCore.QThread.currentThreadId()))
def getBackgroundAtIndex(i):
return self.core.drawBaseImage(
@ -30,7 +31,9 @@ class Worker(QtCore.QObject):
fontSize,
alignment,
xOffset,
yOffset)
yOffset,
textColor,
visColor)
progressBarValue = 0
self.progressBarUpdate.emit(progressBarValue)
@ -97,9 +100,9 @@ class Worker(QtCore.QObject):
smoothConstantUp,
lastSpectrum)
if imBackground != None:
im = self.core.drawBars(lastSpectrum, imBackground)
im = self.core.drawBars(lastSpectrum, imBackground, visColor)
else:
im = self.core.drawBars(lastSpectrum, getBackgroundAtIndex(bgI))
im = self.core.drawBars(lastSpectrum, getBackgroundAtIndex(bgI), visColor)
if bgI < len(backgroundFrames)-1:
bgI += 1