Пример #1
0
def main():
    colors = {
        'red'   : '#f00',
        'white' : '#fff',
    }

    float_colors = { }

    for key, value in colors.items():
        color = parse_color(value)
        colors[key] = np.array([ color ], dtype=Pixel)
        float_colors[key] = np.array(tuple(c / 255. for c in color), dtype=FloatPixel)

    image = Tile((0, 0), (512, 512), sample_rate=4, dtype=FloatPixel)
    image.buffer[:,:] = float_colors['white']

    tile_width, tile_height = image.buffer.shape

    mesh = MicropolygonMesh((1,1))
    mesh_width, mesh_height = mesh.buffer.shape

    margin = 16
    width = 128
    right  = image.shape[0]
    top    = image.shape[1]


    buffer = np.array([
            [
                (right - margin - width, top - margin, 1, 1, 1.5, 0, 0, 1),
                (right - margin        , top - margin, 1, 1, 0  , 0, 0, 1)
            ],
            [
                (margin        , margin, 1, 1, .5, 0, 0, 1),
                (margin + width, margin, 1, 1, 0 , 0, 0, 1)
            ],
        ],
        dtype=np.float32
    )

    mesh.buffer.view(dtype=(np.float32, 8))[:] = buffer

    fill_micropolygon_mesh(
        mesh_width, mesh_height,
        generate_numpy_begin(mesh.buffer),
        tile_width, tile_height,
        generate_numpy_begin(image.coordinate_image),
        generate_numpy_begin(image.buffer)
    )

    buffer = array_view(image.downsample(1))
    buffer = np.clip(buffer, 0., 1.)
    buffer = (255. * buffer).astype(dtype=np.uint8)

    save_array_as_image(pixel_view(buffer), 'render/002_micropolygon.tiff', 'RGBA')
Пример #2
0
def test_downsample():
    tile = Tile((0, 0), (2, 2), dtype=FloatPixel, sample_rate=2)

    tile.buffer[:, :]["R"] = tile.coordinate_image["x"]
    tile.buffer[:, :]["G"] = tile.coordinate_image["y"]

    expected = np.array(
        [[(0.25, 1.25, 0, 0.0), (1.25, 1.25, 0.0, 0.0)], [(0.25, 0.25, 0, 0.0), (1.25, 0.25, 0.0, 0.0)]],
        dtype=np.float32,
    ).transpose((1, 0, 2))

    actual = tile.downsample(1)
    np.testing.assert_array_equal(expected, array_view(actual))
Пример #3
0
def main():
    from handsome.opencl_api import fill_micropolygon_mesh
    from handsome.util import save_array_as_image, parse_color

    mesh = generate_mesh()
    tile = Tile((0, 0), (512, 512), 4, dtype=FloatPixel)

    fill_micropolygon_mesh(mesh, tile)

    buffer = array_view(tile.downsample(1))
    # buffer = array_view(tile.buffer)
    buffer = np.clip(buffer, 0., 1.)
    buffer = (255 * buffer).astype(np.uint8)

    save_array_as_image(pixel_view(buffer), 'render/009_opencl.tiff', 'RGBA')
Пример #4
0
def render_frame(frame_no):
    print('rendering frame {}'.format(frame_no))

    image = Tile((0, 0), (512,512), 4, dtype=FloatPixel)
    image.buffer[:,:] = palette['white'].view(dtype=FloatPixel)

    center = (256, 256)
    radius = 192

    mesh = star(center, radius)

    cache = render_mesh(mesh)
    cache.composite_into(image)

    buffer = array_view(image.downsample(1))
    buffer = np.clip(buffer, 0., 1.)
    buffer = (255. * buffer).astype(dtype=np.uint8)

    path = 'render/004/frame_{:03}.tiff'.format(frame_no)
    save_array_as_image(pixel_view(buffer), path, 'RGBA')
Пример #5
0
def render_frame(frame_no):
    print('rendering frame {}'.format(frame_no))

    from math import sin, pi
    tau = 2. * pi

    image = Tile((0, 0), (512,512), 4, dtype=FloatPixel)
    image.buffer[:,:] = palette['white'].view(dtype=FloatPixel)

    center = (256, 256)
    radius = 100

    surface = circle(center, radius)

    global transform

    transform = np.array(
        [
            [ 1., .0 ],
            [ .5 * sin(tau * frame_no / 60.), 1. ]
        ],
        dtype=np.float32
    )

    meshes = generate_meshes(surface)

    for mesh in meshes:
        cache = render_mesh(mesh)
        cache.composite_into(image)

    buffer = array_view(image.downsample(1))
    buffer = np.clip(buffer, 0., 1.)
    buffer = (255. * buffer).astype(dtype=np.uint8)

    path = 'render/003/frame_{:03}.tiff'.format(frame_no)
    save_array_as_image(pixel_view(buffer), path, 'RGBA')