示例#1
0
    def test_img_rect(self):
        img = ImageRGBA(40, 40)
        x, y = 5, 5
        width, height = 10, 10
        r, g, b = 125, 175, 210
        draw_rect(img, x, y, width, height, r, g, b)
        for j in range(y, y + height):
            for i in range(x, x + width):
                r1, g1, b1, a1 = img.get_pixel(i, j)

                self.assertEqual(r, r1)
                self.assertEqual(g, g1)
                self.assertEqual(b, b1)
示例#2
0
    def test_get_rgba(self):
        code = """
v1 = get_rgba(image1, 10, 10)
        """
        image = ImageRGBA(200, 200)
        image.set_pixel(10, 10, 25, 77, 142, 185)
        p1 = StructArg('image1', image)
        p2 = Vec4Arg('v1', Vector4(0.0, 0.0, 0.0, 0.0))

        shader = Shader(code=code, args=[p1, p2])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        val = shader.get_value('v1')
        self.assertAlmostEqual(val.x, 25 * 0.0039, places=6)
        self.assertAlmostEqual(val.y, 77 * 0.0039)
        self.assertAlmostEqual(val.z, 142 * 0.0039)
        self.assertAlmostEqual(val.w, 185 * 0.0039)
示例#3
0
    def test_get_rgba(self):
        code = """
v1 = get_rgba(image1, 10, 10)
        """
        image = ImageRGBA(200, 200)
        image.set_pixel(10, 10, 25, 77, 142, 185)
        p1 = StructArg('image1', image)
        p2 = Vec4Arg('v1', Vector4(0.0, 0.0, 0.0, 0.0))

        shader = Shader(code=code, args=[p1, p2])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        val = shader.get_value('v1')
        self.assertAlmostEqual(val.x, 25 * 0.0039, places=6)
        self.assertAlmostEqual(val.y, 77 * 0.0039)
        self.assertAlmostEqual(val.z, 142 * 0.0039)
        self.assertAlmostEqual(val.w, 185 * 0.0039)
示例#4
0
    def test_blt(self):
        source = ImageRGBA(300, 200)
        dest = ImageRGBA(300, 200)
        sa, spitch = source.address_info()
        da, dpitch = dest.address_info()

        draw_rect(source, 120, 130, 10, 8, 130, 120, 150, 180)
        blt_rect(sa, 120, 130, 10, 8, spitch, da, 180, 190, dpitch, fliped=False)
        self._check_values(dest, 180, 190, 10, 8, 130, 120, 150, 180)

        blt_rect(sa, 120, 130, 10, 8, spitch, da, 50, 60, dpitch, fliped=False)
        self._check_values(dest, 50, 60, 10, 8, 130, 120, 150, 180)
示例#5
0
from renlight.image import ImageRGBA
from renlight.win import show_image_in_window


def draw_rect(img, x, y, width, height, r, g, b, a):
    for j in range(y, y + height):
        for i in range(x, x + width):
            img.set_pixel(i, j, r, g, b, a)


img = ImageRGBA(300, 200)
draw_rect(img, 0, 0, 50, 50, 255, 0, 0, 255)
draw_rect(img, 100, 100, 50, 50, 0, 255, 0, 255)
draw_rect(img, 200, 75, 50, 50, 0, 0, 255, 255)
show_image_in_window(img, fliped=False)
示例#6
0
 def test_blt_image(self):
     source = ImageRGBA(50, 20)
     dest = ImageRGBA(50, 20)
     draw_rect(source, 0, 0, 50, 20, 130, 120, 150, 180)
     blt_image(source, dest)
     self._check_values(dest, 0, 0, 50, 20, 130, 120, 150, 180)
示例#7
0
    sphere = Sphere(Vector3(0.0, 0.0, 0.0), 2.0, 0)
    mgr.add('sph1', sphere)

    isector = LinearIsect(mgr)
    isector.compile()
    isector.prepare(runtimes)

    ###################

    integrator = Integrator()
    integrator.load('isect_shader')

    sampler.compile()
    camera.compile()
    sampler.prepare(runtimes)
    camera.prepare(runtimes)

    integrator.compile([sampler.shader, camera.shader, isector.shader])
    integrator.prepare(runtimes)
    img = ImagePRGBA(1024, 768)
    integrator.shader.set_value('image', img)

    start = time.clock()
    integrator.execute()
    end = time.clock()
    print("Rendering time:", end-start)

    img2 = ImageRGBA(1024, 768)
    blt_prgba_to_rgba(img, img2)
    show_image_in_window(img2, fliped=False)
示例#8
0
from .loader import Loader
from .shader import Shader
from .builtins import *
from .args import register_struct, Vec3Arg, StructArgPtr,\
    StructArg, PointerArg, parse_args

from renlight.ray import Ray
from renlight.vector import Vector3
from renlight.image import ImageRGBA, ImagePRGBA

register_struct(
    Ray,
    'Ray',
    fields=[('origin', Vec3Arg), ('direction', Vec3Arg)],
    factory=lambda: Ray(Vector3(0.0, 0.0, 0.0), Vector3(0.0, 0.0, 0.0)))

register_struct(ImageRGBA,
                'ImageRGBA',
                fields=[('width', IntArg), ('height', IntArg),
                        ('pitch', IntArg), ('pixels', PointerArg)],
                factory=lambda: ImageRGBA(1, 1))

register_struct(ImagePRGBA,
                'ImagePRGBA',
                fields=[('width', IntArg), ('height', IntArg),
                        ('pitch', IntArg), ('pixels', PointerArg)],
                factory=lambda: ImagePRGBA(1, 1))