2010-08-27 12:28:02 -04:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# flam3cuda, one of a surprisingly large number of ports of the fractal flame
|
|
|
|
# algorithm to NVIDIA GPUs.
|
|
|
|
#
|
|
|
|
# This one is copyright 2010 Steven Robertson <steven@strobe.cc>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2 or later
|
|
|
|
# as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2011-06-13 23:20:18 -04:00
|
|
|
from subprocess import Popen
|
2011-05-03 17:12:12 -04:00
|
|
|
|
2010-09-11 13:15:36 -04:00
|
|
|
from pprint import pprint
|
2010-08-30 14:45:44 -04:00
|
|
|
from ctypes import *
|
2010-08-27 12:28:02 -04:00
|
|
|
|
|
|
|
import numpy as np
|
2010-10-01 01:20:20 -04:00
|
|
|
np.set_printoptions(precision=5, edgeitems=20)
|
2011-05-02 15:30:14 -04:00
|
|
|
import scipy
|
2010-10-01 01:20:20 -04:00
|
|
|
|
2011-05-03 17:12:12 -04:00
|
|
|
import pyglet
|
|
|
|
import pycuda.autoinit
|
|
|
|
|
|
|
|
import cuburn._pyflam3_hacks
|
2011-06-11 15:59:10 -04:00
|
|
|
from fr0stlib import pyflam3
|
2011-04-29 11:00:18 -04:00
|
|
|
from cuburn.render import *
|
2011-04-30 16:40:16 -04:00
|
|
|
from cuburn.code.mwc import MWCTest
|
2011-05-03 13:02:15 -04:00
|
|
|
|
2011-05-03 17:12:12 -04:00
|
|
|
# Required on my system; CUDA doesn't yet work with GCC 4.5
|
|
|
|
os.environ['PATH'] = ('/usr/x86_64-pc-linux-gnu/gcc-bin/4.4.5:'
|
|
|
|
+ os.environ['PATH'])
|
2010-10-07 11:21:43 -04:00
|
|
|
|
2010-10-09 11:18:58 -04:00
|
|
|
def main(args):
|
2011-05-03 17:12:12 -04:00
|
|
|
if '-t' in args:
|
|
|
|
MWCTest.test_mwc()
|
|
|
|
|
|
|
|
with open(args[1]) as fp:
|
2011-06-11 15:59:10 -04:00
|
|
|
genome_ptr, ngenomes = pyflam3.Genome.from_string(fp.read())
|
|
|
|
genomes = cast(genome_ptr, POINTER(pyflam3.Genome*ngenomes)).contents
|
2011-04-29 17:25:51 -04:00
|
|
|
anim = Animation(genomes)
|
2011-06-11 15:59:10 -04:00
|
|
|
anim.compile()
|
|
|
|
anim.load()
|
|
|
|
for n, out in enumerate(anim.render_frames()):
|
|
|
|
noalpha = np.delete(out, 3, axis=2)
|
2011-06-13 23:20:18 -04:00
|
|
|
name = 'rendered_%03d' % n
|
|
|
|
scipy.misc.imsave(name+'.png', noalpha)
|
|
|
|
# Convert using imagemagick, to set custom quality
|
|
|
|
Popen(['convert', name+'.png', '-quality', '90', name+'.jpg'])
|
2011-06-11 15:59:10 -04:00
|
|
|
return
|
|
|
|
|
|
|
|
#if '-g' not in args:
|
|
|
|
# return
|
2011-05-03 14:36:20 -04:00
|
|
|
|
2011-05-04 01:30:22 -04:00
|
|
|
window = pyglet.window.Window(anim.features.width, anim.features.height)
|
2011-05-02 12:19:55 -04:00
|
|
|
imgbuf = (np.minimum(accum * 255, 255)).astype(np.uint8)
|
2011-05-04 01:30:22 -04:00
|
|
|
image = pyglet.image.ImageData(anim.features.width, anim.features.height,
|
|
|
|
'RGBA', imgbuf.tostring(),
|
|
|
|
-anim.features.width * 4)
|
2010-09-09 11:36:14 -04:00
|
|
|
tex = image.texture
|
2010-08-27 12:28:02 -04:00
|
|
|
|
2011-04-29 17:25:51 -04:00
|
|
|
#pal = (anim.ctx.ptx.instances[PaletteLookup].pal * 255.).astype(np.uint8)
|
|
|
|
#image2 = pyglet.image.ImageData(256, 16, 'RGBA', pal.tostring())
|
2010-09-12 18:42:52 -04:00
|
|
|
|
2010-09-09 11:36:14 -04:00
|
|
|
@window.event
|
|
|
|
def on_draw():
|
|
|
|
window.clear()
|
|
|
|
tex.blit(0, 0)
|
2011-04-29 17:25:51 -04:00
|
|
|
#image2.blit(0, 0)
|
2010-08-27 12:28:02 -04:00
|
|
|
|
2010-09-09 11:36:14 -04:00
|
|
|
@window.event
|
|
|
|
def on_key_press(sym, mod):
|
|
|
|
if sym == pyglet.window.key.Q:
|
|
|
|
pyglet.app.exit()
|
2010-08-27 12:28:02 -04:00
|
|
|
|
2010-09-09 11:36:14 -04:00
|
|
|
pyglet.app.run()
|
2010-08-27 12:28:02 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2011-05-03 17:12:12 -04:00
|
|
|
if len(sys.argv) < 2 or not os.path.isfile(sys.argv[1]):
|
2010-09-02 16:12:22 -04:00
|
|
|
print "Last argument must be a path to a genome file"
|
2010-08-27 12:28:02 -04:00
|
|
|
sys.exit(1)
|
2010-09-02 16:12:22 -04:00
|
|
|
main(sys.argv)
|
2010-08-27 12:28:02 -04:00
|
|
|
|