0

I use OpenGL shaders to do color conversion from YUV to RGB. For example, on YUV420P, I create 3 textures (one for Y, one for U, one for V) and use the texture GLSL call to get each texture. Then I use matrix multiplication to get the RGB value. Each of thes textures have the format GL_RED, because they store only 1 component.

This all works on C++. Now I'm using the safe OpenGL Rust library glium. I'm creating a texture like this:

let mipmap = glium::texture::MipmapsOption::NoMipmap;
let format = glium::texture::UncompressedFloatFormat::U8;

let y_texture = glium::texture::texture2d::Texture2d::empty_with_format(&display, format, mipmap, width as u32, height as u32).unwrap();

let u_texture = glium::texture::texture2d::Texture2d::empty_with_format(&display, format, mipmap, (width as u32)/2, (height as u32)/2).unwrap();

let v_texture = glium::texture::texture2d::Texture2d::empty_with_format(&display, format, mipmap, (width as u32)/2, (height as u32)/2).unwrap();

See that the sizes of the U and V textures are 1/4 of the Y texture, as expected for YUV420P.

as you see, for YUV420P I've chosen glium::texture::UncompressedFloatFormat::U8, which I think is the same as GL_RED.

The problem is that I don't know how to fill this texture with data. Its write method expect something that can be converted into a RawImage2D. However, all the filling for methods for RawImage2D expect an RGB image.

I need a method to fill only Y to the first texture, then only U to the second, and only V to the third.

pretzelhammer
  • 13,874
  • 15
  • 47
  • 98
PPP
  • 1,279
  • 1
  • 28
  • 71
  • You can write directly in the [`data`](https://docs.rs/glium/0.13.3/glium/texture/struct.RawImage2d.html#structfield.data) field of a `RawImage2D` since it is public. And you can set its format to [`ClientFormat::U8`](https://docs.rs/glium/0.13.3/glium/texture/enum.ClientFormat.html) – Jmb Oct 05 '20 at 06:53
  • @Jmb you're rigth. It worked! Thanks :) – PPP Oct 05 '20 at 07:11

0 Answers0