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_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 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))
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): img1.set_pixel(x, y, 0.5, 0.5, 0.5) end = time.clock() print("Execution time of python = ", end - start)
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): img1.set_pixel(x, y, 0.5, 0.5, 0.5) end = time.clock() print("Execution time of python = ", end-start)
#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')) print(shader.get_value('slika.pixels'))