npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

glsl-ntsc-video

v2.0.2

Published

modulate and demodulate an ntsc video signal in a shader

Downloads

259

Readme

glsl-ntsc-video

modulate and demodulate an ntsc video signal in a shader

compile with glslify

ntsc was a broadcast television standard used in north america, the caribbean, parts of south america, and a few places in east asia and the pacific. ntsc was mostly discontinued in 2009 for over-the-air use but lives on in legacy consumer electronics such as game consoles and vhs tapes made for ntsc regions.

this module has not been tested against an actual ntsc signal, but it can decode its own signals with some fidelity.

example

this example modulates and then demodulates a picture from an image file.

check the example directory for a demo that reads from a visual effect written to framebuffer and then modulated and demodulated.

var glsl = require('glslify')
var regl = require('regl')()
var fbopts = [
  { color: regl.texture({ width: 720*2, height: 262 }) },
  { color: regl.texture({ width: 720*2, height: 263 }) }
]
var fbo = [
  regl.framebuffer(fbopts[0]),
  regl.framebuffer(fbopts[1])
]

require('resl')({
  manifest: { picture: { type: 'image', src: 'smpte.png' } },
  onDone: (assets) => {
    var draw = {
      modulate: regl({
        frag: glsl`
          precision highp float;
          #pragma glslify: modulate = require('glsl-ntsc-video/modulate')
          varying vec2 vpos;
          uniform float n_lines;
          uniform sampler2D picture;
          void main () {
            float signal = modulate(vpos*0.5+0.5, n_lines, picture);
            gl_FragColor = vec4(signal,0,0,1);
          }
        `,
        vert: `
          precision highp float;
          attribute vec2 position;
          varying vec2 vpos;
          void main () {
            vpos = position;
            gl_Position = vec4(position,0,1);
          }
        `,
        attributes: { position: [-4,-4,-4,+4,+4,+0] },
        elements: [0,1,2],
        framebuffer: regl.prop('framebuffer'),
        uniforms: {
          n_lines: regl.prop('n_lines'),
          picture: regl.texture({ data: assets.picture, flipY: true })
        }
      }),
      demodulate: regl({
        frag: glsl`
          precision highp float;
          #pragma glslify: demodulate = require('glsl-ntsc-video/demodulate')
          uniform sampler2D signal0, signal1;
          varying vec2 vpos;
          uniform float tick;
          const float PI = ${Math.PI};
          void main () {
            vec2 v = vpos*0.5+0.5;
            vec2 r = vec2(720,485);
            vec3 rgb0 = demodulate(v, vec3(262.0,r), signal0);
            vec3 rgb1 = demodulate(v, vec3(263.0,r), signal1);
            vec3 rgb = mix(rgb0,rgb1,sin(v.y*PI*2.0*242.5)*0.5+0.5);
            gl_FragColor = vec4(rgb,1);
          }
        `,
        vert: `
          precision highp float;
          attribute vec2 position;
          varying vec2 vpos;
          void main () {
            vpos = position;
            gl_Position = vec4(position,0,1);
          }
        `,
        attributes: { position: [-4,-4,-4,+4,+4,+0] },
        elements: [0,1,2],
        uniforms: {
          signal0: regl.prop('signal0'),
          signal1: regl.prop('signal1'),
          tick: regl.context('tick')
        }
      })
    }
    var tick = 0
    frame(); frame()
    window.addEventListener('resize', () => { frame(); frame() })
    function frame () {
      regl.poll()
      fbo[tick%2](fbopts[tick%2])
      draw.modulate({ framebuffer: fbo[tick%2], n_lines: tick%2 ? 263 : 262 })
      regl.clear({ color: [0,0,0,1], depth: true })
      draw.demodulate({ signal0: fbo[0], signal1: fbo[1] })
      tick++
    }
  }
})

api

#pragma glslify: modulate = require('glsl-ntsc-video/modulate')
#pragma glslify: demodulate = require('glsl-ntsc-video/demodulate')

float signal = modulate(vec2 uv, float n_lines, sampler2D picture)

return the modulated floating point signal from 0.0 to +1.0 for uv in unit coordinates (values from 0 to 1, inclusive) where (0,0) is the bottom-left. the picture texture should have its (0,0) at the bottom-left too.

n_lines is the total number of lines (262 or 263).

vec3 rgb = demodulate(uv, vec3(n_lines,width,height), sampler2D signal)

decode a texture signal with its red channel set as modulated ntsc from 0.0 to +1.0 for uv in unit coordinates (values from 0 to 1, inclusive) where (0,0) is the bottom-left.

n_lines is the number of lines (262 or 263).

width and height are the decoded size of the resulting visual image (use 720,485).

For higher precision you can use a floating point texture for signal although in practice it doesn't appear to make much of a difference.

license

bsd

install

npm install glsl-ntsc-video