def draw_samples(sampler, spp=None, fname=None, grid=False, resolution=None): if resolution is None: resolution = 10 else: resolution = int(resolution) if spp is None: spp = 16 else: spp = int(spp) if sampler == 'regular': sam = RegularSampler(width=resolution, height=resolution) elif sampler == 'random': sam = RandomSampler(width=resolution, height=resolution, nsamples=spp) elif sampler == 'jittered': sam = JitteredSampler(width=resolution, height=resolution, nsamples=spp) else: raise ValueError("Unknown sampler %s" % sampler) sam_gen = SamplerGenerator(sam) # sam.create_shader() # sam.prepare_standalone() ppx = 32 width = sam._width * ppx height = sam._height * ppx img = ImageRGBA(width, height) draw_white_rect(img) #beacuse of jpeg format if grid: draw_grid(img, ppx) while True: if not sam.has_more_samples(): break while True: sample = sam_gen.generate_sample() if sample is False: break x = sample.ix * ppx + int(sample.px * ppx) y = sample.iy * ppx + int(sample.py * ppx) img.set_pixel(x, y, 255, 0, 0) sam.increment_pass() if not sam.has_more_samples(): break if fname: save_image(fname, img) else: save_image("sampling.png", img)
def draw_samples(sampler, spp=None, fname=None, grid=False, resolution=None): if resolution is None: resolution = 10 else: resolution = int(resolution) if spp is None: spp = 16 else: spp = int(spp) if sampler == "regular": sam = RegularSampler(width=resolution, height=resolution) elif sampler == "random": sam = RandomSampler(width=resolution, height=resolution, nsamples=spp) elif sampler == "jittered": sam = JitteredSampler(width=resolution, height=resolution, nsamples=spp) else: raise ValueError("Unknown sampler %s" % sampler) sam_gen = SamplerGenerator(sam) # sam.create_shader() # sam.prepare_standalone() ppx = 32 width = sam._width * ppx height = sam._height * ppx img = ImageRGBA(width, height) draw_white_rect(img) # beacuse of jpeg format if grid: draw_grid(img, ppx) while True: if not sam.has_more_samples(): break while True: sample = sam_gen.generate_sample() if sample is False: break x = sample.ix * ppx + int(sample.px * ppx) y = sample.iy * ppx + int(sample.py * ppx) img.set_pixel(x, y, 255, 0, 0) sam.increment_pass() if not sam.has_more_samples(): break if fname: save_image(fname, img) else: save_image("sampling.png", img)
def render(filename, output=None, integrator=None, tmo=True): ren = Renderer() if integrator is not None: ren.integrator.load(integrator, ren.sam_mgr, ren.spectral) print("Begin of loading %s" % filename) start = time.clock() ren.load(filename) elapsed = time.clock() - start print("Loading scene took %f seconds" % elapsed) print("Begin preparing scene for rendering") start = time.clock() ren.prepare() elapsed = time.clock() - start print("Preparation of scene took %f seconds" % elapsed) total_time = 0.0 iteration = 0 while True: start = time.clock() ret = ren.render() elapsed = time.clock() - start total_time += elapsed iteration += 1 print("Rendering of iteration %i took %f seconds" % (iteration, elapsed)) if ret: # We finished rendering all samples break; print("Total rendering time took %f seconds." % total_time) if output is None: output = os.path.join(os.path.dirname(filename), 'Unknown.jpeg') name, ext = os.path.splitext(output) hdr_output = os.path.join(os.path.dirname(filename), 'Unknown.exr') save_image(hdr_output, ren._hdr_buffer) if ext in ('.rgbe', '.exr'): save_image(output, ren._hdr_buffer) else: width, height = ren._hdr_buffer.size() new_img = ImageRGBA(width, height) if tmo: print("Tone mapping is in progress!") start = time.clock() ren.tmo() elapsed = time.clock() - start print("Tone mapping took %f seconds!" % elapsed) blt_prgba_to_rgba(ren._hdr_output, new_img) else: blt_prgba_to_rgba(ren._hdr_buffer, new_img) save_image(output, new_img)
def save_image(self, objects, args): fname, id_img = args.split(',') image = objects[id_img] if isinstance(image, ImagePRGBA): width, height = image.size() new_img = ImageRGBA(width, height) blt_prgba_to_rgba(image, new_img) save_image(fname, new_img) elif isinstance(image, ImageRGBA): save_image(fname, image) elif isinstance(image, ImageBGRA): new_img = image.to_rgba() save_image(fname, new_img) return ""
from imldr import load_image, save_image #img = load_image('E:/hdr_images/Desk_oBA2.hdr') # print(img) # # img = load_image('E:/hdr_images/Apartment_float_o15C.hdr') # # print(img) #img = load_image('E:/hdr_images/AtriumNight_oA9D.hdr') # print(img) # img = load_image('C:/Users/Public/Pictures/Sample Pictures/Koala.jpg') # print(img) img = load_image('C:/Users/Public/Pictures/Sample Pictures/Koala.jpg') print(img) save_image('Koala.png', img) #save_image('Koala.exr', img)
from sdl.blt_floatrgba import blt_prgba_to_rgba, ImageRGBA from imldr import save_image from renlgt import Renderer ren = Renderer() # ren.load('sphere1.txt') ren.load("triangle1.txt") ren.prepare() ren.render() ren.tmo() width, height = ren._hdr_buffer.size() new_img = ImageRGBA(width, height) # blt_prgba_to_rgba(ren._hdr_buffer, new_img) blt_prgba_to_rgba(ren._hdr_output, new_img) save_image("render1.jpeg", new_img)
from sdl.blt_floatrgba import blt_prgba_to_rgba, ImageRGBA from imldr import save_image from renlgt import Renderer ren = Renderer() #ren.load('sphere1.txt') ren.load('triangle1.txt') ren.prepare() ren.render() ren.tmo() width, height = ren._hdr_buffer.size() new_img = ImageRGBA(width, height) #blt_prgba_to_rgba(ren._hdr_buffer, new_img) blt_prgba_to_rgba(ren._hdr_output, new_img) save_image("render1.jpeg", new_img)