From ec1ae7d9513746a11375d0a6863d0dc5b0b0d05f Mon Sep 17 00:00:00 2001 From: Florian Larysch Date: Wed, 11 Nov 2015 23:54:23 +0100 Subject: [PATCH] add frame caching --- renderlib.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/renderlib.py b/renderlib.py index 96231a8..213a78e 100644 --- a/renderlib.py +++ b/renderlib.py @@ -7,6 +7,7 @@ import glob import math import shutil import errno +import shutil from lxml import etree from xml.sax.saxutils import escape as xmlescape import cssutils @@ -87,11 +88,24 @@ def rendertask(task): # iterate through the animation seqence frame by frame # frame is a ... tbd + cache = {} for frame in task.sequence(task.parameters): # print a line for each and every frame generated if debug: 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) 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