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

From: DEMAINE Benoit-Pierre (nntp_pipex_at_demaine.info)
Date: 10/06/04


Date: Wed, 06 Oct 2004 03:34:17 +0100


-----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?

I use mozilla thunderbird, and it never show PGP headers, exept when
they are commented as you just did :(
It simply notify valid or non valid PGP header somewhere above the
message by a specific icon.

| 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?

I thought that some lib could directly export from YUV to png. Looks
like no.

~From that, I have a book which explains how to convert YUV<=>RGB. But
since I am learning clean coding, instead of doing by hand, I thought it
d be a good idear to use dedicated tools. => which lib can convert YUV
in anything else ?

| (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. ;)

160 lines example is what you call simple ... I dont want you to send me
a 'difficult' example ^^
I have read the man 3 libpng, and found a revealant section, but it
looks so big and complex, i guess I d make so many mistakes i d never be
able to make my code work properly.
let study the content :
what
unsigned char (*data)[3];
exactly mean ? array of pointers ?

I do not really understand how you read the file, or more precisely, how
you read the content of the picture.

oh : (*data) = malloc(*w * *h * sizeof **data);
that is interesting ... but I still do not understand what type is data :/

the part I am focussing on is:
~ for (j=0; j < h; ++j)
~ row_pointers[j] = (png_byte*)data[j*w+0];

so: data look to be an array of something, but I still do not understand
how many dimensions it has : 1 or 2 ?

in the read func, why the hell do you read data ? I thought you would
write it !

and in write, you also always read it ... what is the use of a var you
always read ???

all that remains much fuzzy to me.

***
I d just need to understand which format WritePNG() expect RGB data to
be. If i understand that, it is all done. - for now I dont.
***

| (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.

I dont want to store RGB in file. I need a compessed format.

| (b) Just pretend YUV is RGB. For example, if you have a YUV triple
[...]
| as you remember that R=Y, G=U, and B=V.

my YUV is compleetely different than RGB. I cant assume what you say.
y= light, U = green/red V=blue/red ( IIRC)

| (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.

I could _optionally_ write data to a .yuv file, but I do not find any
documentation about their headers. I already learnt how to read headers
of .wav . But if I have to export YUV to anything, I ll do it to RGB.

- --
DEMAINE Benoît-Pierre http:/www.demaine.info/
\_o< apt-get remove ispell >o_/
There're 10 types of people: those who can count in binary and those who
can't
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBY1moGWSTLbOSw8IRAnQnAKC9G7M4GE4+2WORkU6997oFoYEUUQCfdMuR
ShCpSOSYwkn+BWhlsmoor0k=
=bQOz
-----END PGP SIGNATURE-----



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: 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: 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)