Skip to content

Commit

Permalink
png generation: crop generated images to actual painting(scribing) ar…
Browse files Browse the repository at this point in the history
…ea (Instead of generating 8000x8000 pixel blocks)
  • Loading branch information
krisjans committed May 9, 2012
1 parent b84e3f4 commit 63fd7a0
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions stf.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,40 @@ def handle_point(self, x, y, force, time):
assert False


surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 8000, 8000)
class PreParser(STFParser):
def __init__(self, *args):
super(PreParser, self).__init__(*args)
self.minx=8000
self.miny=8000
self.maxx=0
self.maxy=0

def handle_point(self, x, y, f, time):
if f:
if x > self.maxx:
self.maxx=x
if x < self.minx:
self.minx=x
if y > self.maxy:
self.maxy=y
if y < self.miny:
self.miny=y

try:
stf_file
except NameError:
stf_file = sys.argv[1]

pref = file(stf_file)
prep = PreParser(pref)
prep.parse()

if prep.maxx > 8000:
prep.maxx = 8000
if prep.maxy > 8000:
prep.maxy = 8000

surface = cairo.ImageSurface(cairo.FORMAT_RGB24, prep.maxx-prep.minx, prep.maxy-prep.miny)
ctx = cairo.Context(surface)

print float(fgRed)
Expand Down Expand Up @@ -320,9 +353,9 @@ def handle_stroke_end(self, time):
def handle_point(self, x, y, f, time):
if f:
if self.last_force:
ctx.line_to(x, y)
ctx.line_to(x-prep.minx, y-prep.miny)
else:
ctx.move_to(x, y)
ctx.move_to(x-prep.minx, y-prep.miny)
self.last_force = 1

try:
Expand Down

0 comments on commit 63fd7a0

Please sign in to comment.