Performance boost for static backgrounds. moved drawBars() inside class.
This commit is contained in:
parent
43073cbd42
commit
fcbe211bf1
|
@ -44,7 +44,7 @@ class Component(__base__.Component):
|
||||||
spectrum = numpy.fromfunction(lambda x: 0.008*(x-128)**2, (255,), dtype="int16")
|
spectrum = numpy.fromfunction(lambda x: 0.008*(x-128)**2, (255,), dtype="int16")
|
||||||
width = int(previewWorker.core.settings.value('outputWidth'))
|
width = int(previewWorker.core.settings.value('outputWidth'))
|
||||||
height = int(previewWorker.core.settings.value('outputHeight'))
|
height = int(previewWorker.core.settings.value('outputHeight'))
|
||||||
return drawBars(width, height, spectrum, self.visColor, self.layout)
|
return self.drawBars(width, height, spectrum, self.visColor, self.layout)
|
||||||
|
|
||||||
def preFrameRender(self, **kwargs):
|
def preFrameRender(self, **kwargs):
|
||||||
super().preFrameRender(**kwargs)
|
super().preFrameRender(**kwargs)
|
||||||
|
@ -61,7 +61,7 @@ class Component(__base__.Component):
|
||||||
def frameRender(self, moduleNo, frameNo):
|
def frameRender(self, moduleNo, frameNo):
|
||||||
width = int(self.worker.core.settings.value('outputWidth'))
|
width = int(self.worker.core.settings.value('outputWidth'))
|
||||||
height = int(self.worker.core.settings.value('outputHeight'))
|
height = int(self.worker.core.settings.value('outputHeight'))
|
||||||
return drawBars(width, height, self.spectrumArray[frameNo], self.visColor, self.layout)
|
return self.drawBars(width, height, self.spectrumArray[frameNo], self.visColor, self.layout)
|
||||||
|
|
||||||
def pickColor(self):
|
def pickColor(self):
|
||||||
RGBstring, btnStyle = super().pickColor()
|
RGBstring, btnStyle = super().pickColor()
|
||||||
|
@ -97,42 +97,41 @@ class Component(__base__.Component):
|
||||||
x = frequencies[0:int(paddedSampleSize/2) - 1]
|
x = frequencies[0:int(paddedSampleSize/2) - 1]
|
||||||
|
|
||||||
return lastSpectrum
|
return lastSpectrum
|
||||||
|
|
||||||
def drawBars(width, height, spectrum, color, layout):
|
|
||||||
vH = height-height/8
|
|
||||||
bF = width / 64
|
|
||||||
bH = bF / 2
|
|
||||||
bQ = bF / 4
|
|
||||||
imTop = Image.new("RGBA", (width, height),(0,0,0,0))
|
|
||||||
draw = ImageDraw.Draw(imTop)
|
|
||||||
r, g, b = color
|
|
||||||
color2 = (r, g, b, 125)
|
|
||||||
|
|
||||||
bP = height / 1200
|
def drawBars(self, width, height, spectrum, color, layout):
|
||||||
|
vH = height-height/8
|
||||||
|
bF = width / 64
|
||||||
|
bH = bF / 2
|
||||||
|
bQ = bF / 4
|
||||||
|
imTop = Image.new("RGBA", (width, height),(0,0,0,0))
|
||||||
|
draw = ImageDraw.Draw(imTop)
|
||||||
|
r, g, b = color
|
||||||
|
color2 = (r, g, b, 125)
|
||||||
|
|
||||||
for j in range(0, 63):
|
bP = height / 1200
|
||||||
draw.rectangle((bH + j * bF, vH+bQ, bH + j * bF + bF, vH + bQ - spectrum[j * 4] * bP - bH), fill=color2)
|
|
||||||
draw.rectangle((bH + bQ + j * bF, vH , bH + bQ + j * bF + bH, vH - spectrum[j * 4] * bP), fill=color)
|
|
||||||
|
|
||||||
|
for j in range(0, 63):
|
||||||
|
draw.rectangle((bH + j * bF, vH+bQ, bH + j * bF + bF, vH + bQ - spectrum[j * 4] * bP - bH), fill=color2)
|
||||||
|
draw.rectangle((bH + bQ + j * bF, vH , bH + bQ + j * bF + bH, vH - spectrum[j * 4] * bP), fill=color)
|
||||||
|
|
||||||
imBottom = imTop.transpose(Image.FLIP_TOP_BOTTOM)
|
imBottom = imTop.transpose(Image.FLIP_TOP_BOTTOM)
|
||||||
|
|
||||||
im = Image.new("RGBA", (width, height),(0,0,0,0))
|
im = Image.new("RGBA", (width, height),(0,0,0,0))
|
||||||
|
|
||||||
if layout == 0:
|
if layout == 0:
|
||||||
y = 0 - int(height/100*43)
|
y = 0 - int(height/100*43)
|
||||||
im.paste(imTop, (0, y), mask=imTop)
|
im.paste(imTop, (0, y), mask=imTop)
|
||||||
y = 0 + int(height/100*43)
|
y = 0 + int(height/100*43)
|
||||||
im.paste(imBottom, (0, y), mask=imBottom)
|
im.paste(imBottom, (0, y), mask=imBottom)
|
||||||
|
|
||||||
if layout == 1:
|
if layout == 1:
|
||||||
y = 0 + int(height/100*10)
|
y = 0 + int(height/100*10)
|
||||||
im.paste(imTop, (0, y), mask=imTop)
|
im.paste(imTop, (0, y), mask=imTop)
|
||||||
y = 0 - int(height/100*10)
|
y = 0 - int(height/100*10)
|
||||||
im.paste(imBottom, (0, y), mask=imBottom)
|
im.paste(imBottom, (0, y), mask=imBottom)
|
||||||
|
|
||||||
if layout == 2:
|
if layout == 2:
|
||||||
y = 0 + int(height/100*10)
|
y = 0 + int(height/100*10)
|
||||||
im.paste(imTop, (0, y), mask=imTop)
|
im.paste(imTop, (0, y), mask=imTop)
|
||||||
|
|
||||||
return im
|
return im
|
||||||
|
|
|
@ -32,16 +32,10 @@ class Worker(QtCore.QObject):
|
||||||
while True:
|
while True:
|
||||||
i = self.compositeQueue.get()
|
i = self.compositeQueue.get()
|
||||||
|
|
||||||
frame = Image.new(
|
|
||||||
"RGBA",
|
|
||||||
(self.width, self.height),
|
|
||||||
(0, 0, 0, 255)
|
|
||||||
)
|
|
||||||
|
|
||||||
if self.imBackground is not None:
|
if self.imBackground is not None:
|
||||||
frame.paste(self.imBackground)
|
frame = self.imBackground
|
||||||
else:
|
else:
|
||||||
frame.paste(self.getBackgroundAtIndex(i[1]))
|
frame = self.getBackgroundAtIndex(i[1])
|
||||||
|
|
||||||
for compNo, comp in enumerate(self.components):
|
for compNo, comp in enumerate(self.components):
|
||||||
if compNo in self.staticComponents and self.staticComponents[compNo] != None:
|
if compNo in self.staticComponents and self.staticComponents[compNo] != None:
|
||||||
|
@ -75,10 +69,16 @@ class Worker(QtCore.QObject):
|
||||||
self.lastPreview = time.time()
|
self.lastPreview = time.time()
|
||||||
|
|
||||||
self.previewQueue.task_done()
|
self.previewQueue.task_done()
|
||||||
|
|
||||||
|
|
||||||
def getBackgroundAtIndex(self, i):
|
def getBackgroundAtIndex(self, i):
|
||||||
return self.core.drawBaseImage(self.backgroundFrames[i])
|
background = Image.new(
|
||||||
|
"RGBA",
|
||||||
|
(self.width, self.height),
|
||||||
|
(0, 0, 0, 255)
|
||||||
|
)
|
||||||
|
layer = self.core.drawBaseImage(self.backgroundFrames[i])
|
||||||
|
background.paste(layer)
|
||||||
|
return background
|
||||||
|
|
||||||
@pyqtSlot(str, str, str, list)
|
@pyqtSlot(str, str, str, list)
|
||||||
def createVideo(self, backgroundImage, inputFile, outputFile, components):
|
def createVideo(self, backgroundImage, inputFile, outputFile, components):
|
||||||
|
@ -154,7 +154,6 @@ class Worker(QtCore.QObject):
|
||||||
|
|
||||||
if properties and 'static' in properties:
|
if properties and 'static' in properties:
|
||||||
self.staticComponents[compNo] = copy(comp.frameRender(compNo, 0))
|
self.staticComponents[compNo] = copy(comp.frameRender(compNo, 0))
|
||||||
print('done')
|
|
||||||
|
|
||||||
self.compositeQueue = Queue()
|
self.compositeQueue = Queue()
|
||||||
self.compositeQueue.maxsize = 20
|
self.compositeQueue.maxsize = 20
|
||||||
|
@ -163,7 +162,7 @@ class Worker(QtCore.QObject):
|
||||||
self.previewQueue = PriorityQueue()
|
self.previewQueue = PriorityQueue()
|
||||||
|
|
||||||
# create threads to render frames and send them back here for piping out
|
# create threads to render frames and send them back here for piping out
|
||||||
for i in range(2):
|
for i in range(3):
|
||||||
t = Thread(target=self.renderNode, name="Render Thread")
|
t = Thread(target=self.renderNode, name="Render Thread")
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
|
|
Reference in New Issue