1

Is there a way to do a color conversion in OpenGL (e.g. from RGB to YUV420p back and forth)? I can either use the contents of the back buffer, a texture or a FBO. I saw this question here, but is restricted to OpenGL 1.1, and I am not constrained to any particular version of OpenGL. OpenGL Colorspace Conversion

I was wondering if there is a newer/faster way to do this with the newer versions. I would prefer not to use anything that is hardware specific, but if it needs to be, I am working with Nvidia GPUs.

Community
  • 1
  • 1
cloudraven
  • 2,484
  • 1
  • 24
  • 49
  • 1
    You can use a glsl shader instead of an ARB_FRAGMENT program. [This answer](http://stackoverflow.com/questions/9234724/how-to-change-hue-of-a-texture-with-glsl/9234854#9234854) gives an example of converting to YIQ. Y'CbCr is similar but with slightly different matrices. – user1118321 Oct 07 '12 at 00:32
  • Thanks! I was hoping for it to be a common task and to have some library to just do it, but this definitely works. That would definitely give me RGB -> YUV444. How would you do the downsampled chroma channels for YUV420p? That is only one sample for each four pixels. From your code I would have to do something different here, I think float I = dot (color, kRGBToI); float Q = dot (color, kRGBToQ); – cloudraven Oct 07 '12 at 05:07
  • 1
    I'm not aware of any library, but you could probably do some sort of resampling to get down to 4:2:0. A box blur on the Cb/Cr channels would be my first attempt, but other resampling filters like a Gaussian or Lanczos would probably be higher quality. – user1118321 Oct 08 '12 at 03:11
  • I guess I will need to go and implement it. I think that should work. If you put all your comments as an answer I would accept it. – cloudraven Oct 08 '12 at 04:19

1 Answers1

1

Since you want newer/faster, yes you can try using CUDA or OpenCL. Whether they will be much faster than a shader... I have no idea, do let us know. If anything, it gives you more control on how resources are allocated to the task.

Both frameworks have ways of sharing memory with OpenGL so you should be able to just write a kernel and pass it your opengl texture/fbo.

I happen to have written a number of such modules for xpra, you can find links for them here: xpra wiki: CSC (code is GPL2+)

totaam
  • 1,306
  • 14
  • 25
  • This is very useful. It will be some time before I get the chance to try this because more pressing issues have to be solved first, but I will be back to post my results. – cloudraven Nov 15 '13 at 19:58