Question

I am looking for sample GLSL fragment shader code that can convert RGB frame (say pixel format as ARGB) to YUV (say YUV420).

Imagine an RGB frame of size 1920x1080. I like to use fragment shader to convert it to YUV frame.

Can you point me to code that can be compiled and run on UBuntu box?

Was it helpful?

Solution

For future reference, a bunch of colorspace conversions in GLSL shaders can be found in Gstreamer gst-plugins-gl codebase :)

OTHER TIPS

First, you should know that your question is poorly phrased. Nobody is going to write you sample code. You can use a search engine (or even search this site) for code to convert from RGB to YUV.

I have written an answer similar to what you're looking for here. It converts from RGB to YIQ, does some shifting of the hue and converts back. You can use the Y'CbCr matrix for the color conversion instead of YIQ, if that's what you need.

It doesn't down-convert to 4:2:0, though. That should be easy enough to do, though. Once it's in Y'CbCr format, you can downsample the appropriate channels as you see fit. I recommend doing a low-pass filter on those channel first to avoid aliasing artifacts.

I don't work with Linux, so haven't tested on Ubuntu. Good luck.

This link has a YUV 4:2:2 v210 to RGB implementation using a compute shader GLSL. YUV 4:2:2 v210 --> RGB GLSL source code

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top