add frame caching

This commit is contained in:
Florian Larysch 2015-11-11 23:54:23 +01:00
parent 38d3c80483
commit ec1ae7d951

View file

@ -7,6 +7,7 @@ import glob
import math import math
import shutil import shutil
import errno import errno
import shutil
from lxml import etree from lxml import etree
from xml.sax.saxutils import escape as xmlescape from xml.sax.saxutils import escape as xmlescape
import cssutils import cssutils
@ -87,11 +88,24 @@ def rendertask(task):
# iterate through the animation seqence frame by frame # iterate through the animation seqence frame by frame
# frame is a ... tbd # frame is a ... tbd
cache = {}
for frame in task.sequence(task.parameters): for frame in task.sequence(task.parameters):
# print a line for each and every frame generated # print a line for each and every frame generated
if debug: if debug:
print("frameNr {0:3d} => {1}".format(frameNr, frame)) print("frameNr {0:3d} => {1}".format(frameNr, frame))
frame = tuple(frame)
if frame in cache:
print("cache hit, reusing frame {0}".format(cache[frame]))
framedir = task.workdir + "/.frames/"
shutil.copyfile("{0}/{1:04d}.png".format(framedir, cache[frame]), "{0}/{1:04d}.png".format(framedir, frameNr))
frameNr += 1
continue
else:
cache[frame] = frameNr
# open the output-file (named ".gen.svg" in the workdir) # open the output-file (named ".gen.svg" in the workdir)
with open(os.path.join(task.workdir, '.gen.svg'), 'w') as fp: with open(os.path.join(task.workdir, '.gen.svg'), 'w') as fp:
# apply the replace-pairs to the input text, by finding the specified xml-elements by thier id and modify thier css-parameter the correct value # apply the replace-pairs to the input text, by finding the specified xml-elements by thier id and modify thier css-parameter the correct value