Show
Ignore:
Timestamp:
02/21/10 23:59:26 (2 years ago)
Author:
Robin Gareus <rgareus@…>
Parents:
66e0a72e52b6c9076ab19cebe52ae0ada6898d4a
Children:
26852f5d3ef287c9672aba17dc5f0bfa3f9a2396
git-committer:
Robin Gareus <rgareus@priroda.local> / 2010-02-22T00:59:26Z+0100
Message:

better RGB -> YUV convertion

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • oggzcap/src/videoout/encoder_example.c

    r66e0a72 r6e49c34  
    8686        cr_base += dst->uv_stride; 
    8787    } 
    88 #else // RGBA -> 420 
     88#else // RGBA -> 420  
     89        // TODO: offset ! & strides 
    8990         
    9091#define _CR ((bptr[(4*i)+2])&0xff) 
     
    9293#define _CB ((bptr[(4*i)+0])&0xff) 
    9394         
     95#define _CRX ( ( ((bptr[(4*i)+2])&0xff) + ((bptr[(4*(i+1))+2])&0xff) + ((bptr[(4*(i+1+width))+2])&0xff) + ((bptr[(4*(i+1+width))+2])&0xff) )>>2) 
     96#define _CGX ( ( ((bptr[(4*i)+1])&0xff) + ((bptr[(4*(i+1))+1])&0xff) + ((bptr[(4*(i+1+width))+1])&0xff) + ((bptr[(4*(i+1+width))+1])&0xff) )>>2) 
     97#define _CBX ( ( ((bptr[(4*i)+0])&0xff) + ((bptr[(4*(i+1))+0])&0xff) + ((bptr[(4*(i+1+width))+0])&0xff) + ((bptr[(4*(i+1+width))+0])&0xff) )>>2) 
     98         
    9499        uint8_t *bptr = (uint8_t*) b_2vuy; 
    95100        int i; int c=0; 
    96101        for (i=0;i<width*height;i++) { 
    97                 double Y  = (0.257 * _CR) + (0.504 * _CG) + (0.098 * _CB) + 16; 
     102                double Y  = (0.299 * _CR) + (0.587 * _CG) + (0.114 * _CB); 
    98103                if (Y<0) dst->y[i]=0; 
    99104                else if (Y>255) dst->y[i]=255; 
    100105                else dst->y[i]=(uint8_t) floor(Y+.5); 
    101106#if 1 
    102                 if (i%2==0 && ((i/width)%2)==0) { // TODO average 4 pixels 
    103             double V =  (0.439 * _CR) - (0.368 * _CG) - (0.071 * _CB) + 128; 
    104             double U = -(0.148 * _CR) - (0.291 * _CG) + (0.439 * _CB) + 128; 
     107                if (i%2==0 && ((i/width)%2)==0) {  
     108            double V =  (0.500 * _CRX) - (0.419 * _CGX) - (0.081 * _CBX) + 128; 
     109            double U = -(0.169 * _CRX) - (0.331 * _CGX) + (0.500 * _CBX) + 128; 
    105110                         
    106111            if (U<0) dst->u[c]=0;