Jeroen Vreeken wrote: > > Hi, > > I am looking for a piece of code (or just documentation) to convert an > bgr24 image to yuv240p. > I have found some stuff but the result is terrible, overflows and black and > white images... > > Jeroen > > _______________________________________________ > Video4linux-list mailing list > Video4linux-list@xxxxxxxxxx > https://listman.redhat.com/mailman/listinfo/video4linux-list Try this one (from Rene Muller): void rgb_yuv(int w, int h, unsigned char *rgb, unsigned char *buf) { register int i,j; char *off = buf+w*h, *off2 = buf+w*h+w*h/4; for(j=0; j<h; j++) { for(i=0; i<w; i++) { int b = *rgb++; int g = *rgb++; int r = *rgb++; int y,cb,cr; y = (0.257 * r) + (0.504 * g) + (0.098 * b) + 16; cr = (0.439 * r) - (0.368 * g) - (0.071 * b) + 128; cb = -(0.148 * r) - (0.291 * g) + (0.439 * b) + 128; if(y<0) y = 0; if(y>255) y = 255; if(cb<0) cb = 0; if(cb>255) cb = 255; if(cr<0) cr = 0; if(cr>255) cr = 255; *buf++ = y; if(j&1&&i&1) *off++ = cr; if(j&1&&i&1) *off2++ = cb; } } }