def conv_angular_to_ll(img): width, height = img.size() new_img = ImagePRGBA(width*2, height) for j in range(height): for i in range(width * 2): x, y, z = _set_lat_long_coords(1 - j / float(height - 1), i / float(width * 2 - 1)) u, v = _get_mirror_ball_pixel_coord(x, y, z) #convert to pixel coordiantes u = (u + 1) * 0.5 * width v = (v + 1) * 0.5 * height r, g, b, a = img.get_pixel(int(u), int(v)) new_img.set_pixel(i, j, r, g, b, a) return new_img
def conv_angular_to_ll(img): width, height = img.size() new_img = ImagePRGBA(width * 2, height) for j in range(height): for i in range(width * 2): x, y, z = _set_lat_long_coords(1 - j / float(height - 1), i / float(width * 2 - 1)) u, v = _get_mirror_ball_pixel_coord(x, y, z) #convert to pixel coordiantes u = (u + 1) * 0.5 * width v = (v + 1) * 0.5 * height r, g, b, a = img.get_pixel(int(u), int(v)) new_img.set_pixel(i, j, r, g, b, a) return new_img
def test_set_rgba(self): img1 = ImagePRGBA(200, 200) code = """ set_rgba(img, 25, 25, (0.1, 0.2, 0.3, 0.4)) """ props = {'img': img1} bs = BasicShader(code, props) runtime = Runtime() bs.prepare([runtime]) #print (bs.shader._code) bs.execute() val = img1.get_pixel(25, 25) self.assertAlmostEqual(val[0], 0.1, places=5) self.assertAlmostEqual(val[1], 0.2, places=5) self.assertAlmostEqual(val[2], 0.3, places=5) self.assertAlmostEqual(val[3], 0.4, places=5)
def test_get_rgba(self): img1 = ImagePRGBA(200, 200) img1.set_pixel(25, 25, 0.2, 0.3, 0.4, 0.5) v1 = Vector4(0, 0, 0, 0) code = """ v1 = get_rgba(img, 25, 25) """ props = {'img': img1, 'v1': v1} bs = BasicShader(code, props) runtime = Runtime() bs.prepare([runtime]) #print (bs.shader._code) bs.execute() val = bs.shader.get_value('v1') self.assertAlmostEqual(val.x, 0.2, places=5) self.assertAlmostEqual(val.y, 0.3, places=5) self.assertAlmostEqual(val.z, 0.4, places=5) self.assertAlmostEqual(val.w, 0.5, places=5)
from renmas3.renderer.renderer import create_props def create_tmo(tmo_shader='exp_tmo'): tmo_loader = FileLoader(["F:/GitRenmas/renmas/renmas3/tmo_shaders"]) contents = tmo_loader.load(tmo_shader, 'props.txt') props = create_props(contents) contents = tmo_loader.load(tmo_shader, 'tmo.py') tmo = Tmo(contents, props) return tmo hdr_image = load_image('Desk_oBA2.hdr') #hdr_image = load_image('AtriumNight_oA9D.hdr') width, height = hdr_image.size() ldr_image = ImagePRGBA(width, height) output_image = ImageBGRA(width, height) reinhard = ReinhardOperator() tmo = create_tmo('log_tmo') start = time.clock() #tmo shader tmo.tone_map(hdr_image, ldr_image) blt_prgba_to_bgra(ldr_image, output_image) #old asm implementation #reinhard.tone_map(hdr_image, output_image) #without tone mapping
from renmas3.base import GraphicsPRGBA, RGBSpectrum, ImagePRGBA, ImageRGBA from renmas3.utils import blt_prgba_to_rgba from renmas3.win32 import show_image_in_window img = ImagePRGBA(400, 400) gr = GraphicsPRGBA() gr.draw_rect(img, 20, 20, 80, 50, RGBSpectrum(0.6, 0.0, 0.0)) width, height = img.size() img2 = ImageRGBA(width, height) blt_prgba_to_rgba(img, img2) show_image_in_window(img2)
from tdasm import Runtime from renmas3.base import ImagePRGBA, arg_map, create_shader, Vec3 arg_map1 = arg_map([('image1', ImagePRGBA), ('value', Vec3)]) img1 = ImagePRGBA(1024, 768) img1.set_pixel(10, 10, 0.4, 0.3, 0.2) code = """ value = get_rgb(image1, 10, 10) color = (0.1, 0.5, 0.6) set_rgb(image1, 20, 20, color) """ shader = create_shader("test", code, arg_map1) runtimes = [Runtime()] shader.prepare(runtimes) shader.set_value('image1', img1) shader.execute() print(shader.get_value('value')) print(img1.get_pixel(20, 20))
import time from tdasm import Runtime from renmas3.base import ImagePRGBA, arg_map, create_shader arg_map1 = arg_map([('image1', ImagePRGBA)]) img1 = ImagePRGBA(1024, 768) code = """ value = (0.5, 0.5, 0.5) y = image1.height - 1 while y >= 0: x = image1.width - 1 while x >= 0: set_rgb(image1, x, y, value) x = x - 1 y = y - 1 """ shader = create_shader("test", code, arg_map1) runtimes = [Runtime()] shader.prepare(runtimes) shader.set_value('image1', img1) start = time.clock() shader.execute() end = time.clock() print("Execution time of shader = ", end - start) start = time.clock() for y in range(img1.height): for x in range(img1.width):
def copy_image(in_img, out_image): width, height = in_img.size() for y in range(height): for x in range(width): r1, g1, b1, a1 = in_img.get_pixel(x, y) out_image.set_pixel(x, y, r1, g1, b1, a1) img = load_image('F:/hdr_images/Desk_oBA2.hdr') print(img) img_props = calc_img_props(img) print(img_props) width, height = img.size() output_image = ImagePRGBA(width, height) def tmo_py(props, in_img, out_img): pass code = """ rgb_col = get_rgb(in_img, 25, 25) key = luminance(rgb_col) rgb_col = normalize(rgb_col) """ props = [Float('key', 0.18), Vec3('rgb_col')] tmo = TmoShader(code=code, py_code=tmo_py, props=props)
import time from tdasm import Runtime from renmas3.base import ImagePRGBA, arg_map, create_shader arg_map1 = arg_map([('image1', ImagePRGBA)]) img1 = ImagePRGBA(1024, 768) code = """ value = (0.5, 0.5, 0.5) y = image1.height - 1 while y >= 0: x = image1.width - 1 while x >= 0: set_rgb(image1, x, y, value) x = x - 1 y = y - 1 """ shader = create_shader("test", code, arg_map1) runtimes = [Runtime()] shader.prepare(runtimes) shader.set_value('image1', img1) start = time.clock() shader.execute() end = time.clock() print("Execution time of shader = ", end-start) start = time.clock() for y in range(img1.height):
code2 = """ #p1 is input argument p2 = p1 return p2 """ arg_lst = arg_list([('p1', 3)]) arg_map2 = arg_map([]) shader2 = create_shader("ret_arg", code2, arg_map2, arg_lst, func=True) runtimes = [Runtime()] shader = create_shader("test", code, arg_map1, shaders=[shader2]) print(shader._code) shader.prepare(runtimes) img = ImagePRGBA(3,3) img.set_pixel(1, 2, 0.2, 0.3, 0.1) shader.set_value('slika', img) shader.execute() print(shader.get_value('p1')) print(shader.get_value('ps.x')) print(shader.get_value('pm.x')) print(shader.get_value('p3')) print(shader.get_value('p4')) print(shader.get_value('rect.w')) print(shader.get_value('rect.h')) print(shader.get_value('rect.k')) print(shader.get_value('slika.width')) print(shader.get_value('slika.height')) print(shader.get_value('slika.pitch'))
from renmas3.base import GraphicsRGBA, RGBSpectrum, ImagePRGBA, ImageRGBA from renmas3.utils import blt_prgba_to_rgba, blt_rgba_to_prgba from renmas3.win32 import show_image_in_window img = ImageRGBA(400, 400) gr = GraphicsRGBA() gr.draw_rect(img, 20, 20, 80, 50, RGBSpectrum(0.6, 0.2, 0.4)) width, height = img.size() img2 = ImagePRGBA(width, height) blt_rgba_to_prgba(img, img2) img3 = ImageRGBA(width, height) blt_prgba_to_rgba(img2, img3) print (img.get_pixel(25,25)) print (img2.get_pixel(25,25)) print (img3.get_pixel(25,25)) show_image_in_window(img3)