Re: C : how to export raw YUV to a file ?

From: Arthur J. O'Dwyer (ajo_at_nospam.andrew.cmu.edu)
Date: 10/06/04


Date: Tue, 5 Oct 2004 20:32:15 -0400 (EDT)


On Tue, 5 Oct 2004, DEMAINE Benoit-Pierre wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1

   Here's a question for you: Why do PGP signatures always wind up in the
body text of Usenet posts? Hasn't someone written a PGP client that can
put the ugly stuff in headers where I don't have to look at it unless I
want to?

> Using C under Linux, I have an array containing row data about an YUV
> picture; how to store it on the hdd under bmp or better : png file ?

   Okay, so you have two basic questions here: (1) How do I write an image
to disk as a PNG-format file? (2) How do I deal with YUV images, as
opposed to the more "canonical" (in most circles) RGB encoding?

   (1) Use libpng, a free PNG library available on the Web. There's a
bare-bones example C source on my website:
http://www.contrib.andrew.cmu.edu/~ajo/free-software/simple_png.c
but depending on your level of expertise, it may be easier for you to
read the libpng documentation yourself than try to figure out what my C
routines are doing. ;)

   (2) You have three options for dealing with YUV images:

(a) Convert the YUV data to RGB data and write it to the file as RGB.
You can find conversion formulas on the Web. This is a slightly lossy
procedure, which means you won't be able to get back exactly the YUV
values you started with. But that may not be a big deal.

(b) Just pretend YUV is RGB. For example, if you have a YUV triple
(200, 32, 32), just write out the RGB triple (200, 32, 32). Viewing
the resulting image file in a normal application will make that pixel
appear bright red, when really it's supposed to be... I dunno, bright
brown? I don't do YUV. Anyway, it'll make a funny-looking picture,
but you'll be able to read it back in and do processing on it as long
as you remember that R=Y, G=U, and B=V.

(c) Find an image format that supports YUV colorspace directly. AFAIK,
the PNG format does not do YUV. I bet TIFF does, but TIFF is kind of
cumbersome, in my opinion. Of course, you could also just dump the raw
YUV data, if you didn't need to be able to see the pretty pictures outside
of the application you're writing.

HTH,
-Arthur



Relevant Pages

  • Re: about Color Format transformation
    ... it will accept RGB or YUV in and allow RGB out only. ... Having said that your code will not reject YUV output if a downstream ... > Hi Iain ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: Need help in converting YUV to RGB using OV7620
    ... Hope you guys can give me some advise on converting the YUV ... THEN consider doing colour conversion. ... the format is best described spatially as ... You cannot work out true RGB until 2nd Y and V has been acquired, ...
    (comp.arch.embedded)
  • Re: Color balance in YUV/YCbCr domain
    ... Colour balancing is selecting an area in the image that you know is ... If you know what scaling factors are needed to colour-balance the RGB ... So the operation that colour-balances a YUV ... Multiplying three 3x3 matrices together is *not* complicated. ...
    (sci.image.processing)
  • Re: Need help in converting YUV to RGB using OV7620
    ... >THEN consider doing colour conversion. ... >You cannot work out true RGB until 2nd Y and V has been acquired, ... >>The formula given in the data sheet to get YUV was as followed ... I did not do any gamma correction but basically I just convert the ...
    (comp.arch.embedded)
  • Re: C : how to export raw YUV to a file ?
    ... Hasn't someone written a PGP client that can ... | put the ugly stuff in headers where I don't have to look at it unless I ... I thought that some lib could directly export from YUV to png. ... I d just need to understand which format WritePNGexpect RGB data to ...
    (comp.programming)