示例#1
0
def lut3d(cfg, xsplit=.3, trilinear=True):
    '''Lookup Table 3D using a Texture3D'''
    level = 6
    level2 = level**2

    # Generated with `ffmpeg -f lavfi -i haldclutsrc=6,curves=vintage -f
    # rawvideo -frames:v 1 lut3d.raw`
    lut3d_filename = op.join(op.dirname(__file__), 'data', 'lut3d.raw')
    cfg.files.append(lut3d_filename)
    lut3d_buf = ngl.BufferUBVec3(filename=lut3d_filename)
    lut3d_tex = ngl.Texture3D(data_src=lut3d_buf,
                              width=level2, height=level2, depth=level2)
    if trilinear:
        lut3d_tex.set_min_filter('linear')
        lut3d_tex.set_mag_filter('linear')

    m0 = cfg.medias[0]
    cfg.duration = m0.duration
    cfg.aspect_ratio = (m0.width, m0.height)
    video = ngl.Media(m0.filename)
    video_tex = ngl.Texture2D(data_src=video)

    shader_version = '300 es' if cfg.backend == 'gles' else '330'
    shader_header = '#version %s\n' % shader_version
    prog = ngl.Program(fragment=shader_header + cfg.get_frag('lut3d'),
                       vertex=shader_header + cfg.get_vert('lut3d'))

    quad = ngl.Quad((-1, -1, 0), (2, 0, 0), (0, 2, 0))
    render = ngl.Render(quad, prog)
    render.update_textures(tex0=video_tex)
    render.update_textures(lut3d=lut3d_tex)
    render.update_uniforms(xsplit=ngl.UniformFloat(value=xsplit))

    return render
def lut3d(cfg, xsplit=0.3, trilinear=True):
    """Lookup Table 3D using a Texture3D"""
    level = 6
    level2 = level**2

    # Generated with `ffmpeg -f lavfi -i haldclutsrc=6,curves=vintage,format=rgba
    # -f rawvideo -frames:v 1 lut3d.raw`
    lut3d_filename = op.join(op.dirname(__file__), "data", "lut3d.raw")
    cfg.files.append(lut3d_filename)
    lut3d_buf = ngl.BufferUBVec4(filename=lut3d_filename)
    lut3d_tex = ngl.Texture3D(data_src=lut3d_buf,
                              width=level2,
                              height=level2,
                              depth=level2)
    if trilinear:
        lut3d_tex.set_min_filter("linear")
        lut3d_tex.set_mag_filter("linear")

    m0 = cfg.medias[0]
    cfg.duration = m0.duration
    cfg.aspect_ratio = (m0.width, m0.height)
    video = ngl.Media(m0.filename)
    video_tex = ngl.Texture2D(data_src=video)

    scene_tex = ngl.RenderTexture(video_tex)

    quad = ngl.Quad((-1, -1, 0), (2, 0, 0), (0, 2, 0))
    prog_lut = ngl.Program(fragment=cfg.get_frag("lut3d"),
                           vertex=cfg.get_vert("lut3d"))
    prog_lut.update_vert_out_vars(var_uvcoord=ngl.IOVec2(),
                                  var_tex0_coord=ngl.IOVec2())
    scene_lut = ngl.Render(quad, prog_lut)
    scene_lut.update_frag_resources(tex0=video_tex, lut3d=lut3d_tex)

    return compare(cfg, scene_tex, scene_lut, xsplit)
示例#3
0
def lut3d(cfg, xsplit=.3, trilinear=True):
    '''Lookup Table 3D using a Texture3D'''
    level = 6
    level2 = level**2

    # Generated with `ffmpeg -f lavfi -i haldclutsrc=6,curves=vintage,format=rgba
    # -f rawvideo -frames:v 1 lut3d.raw`
    lut3d_filename = op.join(op.dirname(__file__), 'data', 'lut3d.raw')
    cfg.files.append(lut3d_filename)
    lut3d_buf = ngl.BufferUBVec4(filename=lut3d_filename)
    lut3d_tex = ngl.Texture3D(data_src=lut3d_buf,
                              width=level2,
                              height=level2,
                              depth=level2)
    if trilinear:
        lut3d_tex.set_min_filter('linear')
        lut3d_tex.set_mag_filter('linear')

    m0 = cfg.medias[0]
    cfg.duration = m0.duration
    cfg.aspect_ratio = (m0.width, m0.height)
    video = ngl.Media(m0.filename)
    video_tex = ngl.Texture2D(data_src=video)

    prog = ngl.Program(fragment=cfg.get_frag('lut3d'),
                       vertex=cfg.get_vert('lut3d'))
    prog.update_vert_out_vars(var_uvcoord=ngl.IOVec2(),
                              var_tex0_coord=ngl.IOVec2())

    quad = ngl.Quad((-1, -1, 0), (2, 0, 0), (0, 2, 0))
    render = ngl.Render(quad, prog)
    render.update_frag_resources(tex0=video_tex, lut3d=lut3d_tex)
    render.update_frag_resources(xsplit=ngl.UniformFloat(value=xsplit))

    return render
示例#4
0
def texture_3d(cfg):
    random.seed(0)
    width, height, depth = 9, 9, 3
    n = width * height
    data = array.array('B')
    for i in random.sample(range(n), n):
        data.extend([i * 255 // n, 0, 0, 255])
    for i in random.sample(range(n), n):
        data.extend([0, i * 255 // n, 0, 255])
    for i in random.sample(range(n), n):
        data.extend([0, 0, i * 255 // n, 255])
    texture_buffer = ngl.BufferUBVec4(data=data)
    texture = ngl.Texture3D(width=width,
                            height=height,
                            depth=depth,
                            data_src=texture_buffer)

    glsl_version = '300 es' if cfg.backend == 'gles' else '330'
    glsl_header = '#version %s\n' % glsl_version
    render_cubemap_vert = glsl_header + _TEXTURE3D_VERT
    render_cubemap_frag = glsl_header + _TEXTURE3D_FRAG

    quad = ngl.Quad((-1, -1, 0), (2, 0, 0), (0, 2, 0))
    program = ngl.Program(vertex=render_cubemap_vert,
                          fragment=render_cubemap_frag)
    render = ngl.Render(quad, program)
    render.update_textures(tex0=texture)
    return render
def texture_3d(cfg):
    width, height, depth = 9, 9, 3
    n = width * height
    data = array.array("B")
    for i in cfg.rng.sample(range(n), n):
        data.extend([i * 255 // n, 0, 0, 255])
    for i in cfg.rng.sample(range(n), n):
        data.extend([0, i * 255 // n, 0, 255])
    for i in cfg.rng.sample(range(n), n):
        data.extend([0, 0, i * 255 // n, 255])
    texture_buffer = ngl.BufferUBVec4(data=data)
    texture = ngl.Texture3D(width=width,
                            height=height,
                            depth=depth,
                            data_src=texture_buffer)

    quad = ngl.Quad((-1, -1, 0), (2, 0, 0), (0, 2, 0))
    program = ngl.Program(vertex=_TEXTURE3D_VERT, fragment=_TEXTURE3D_FRAG)
    program.update_vert_out_vars(var_uvcoord=ngl.IOVec2())
    render = ngl.Render(quad, program)
    render.update_frag_resources(tex0=texture)
    return render