# RGB与YUV的转换

S60 5th Edition
S60 3rd Edition FP2
S60 3rd Edition FP1
S60 3rd Edition (initial release)

• 详细描述

• 解决方案

`// Definitions that help access each colour component in source bitmap#define sR ((TInt32)(s[2]))#define sG ((TInt32)(s[1]))#define sB ((TInt32)(s[0])) #define KImageWidth 176   // QCIF resolution#define KImageHeigth 144 const TInt KImageNumPixels = KImageWidth * KImageHeigth;`
`// Lock source bitmap (CFbsBitmap)iSourceBitmap->LockHeap(EFalse);TUint8* s = (TUint8*)iSourceBitmap->DataAddress(); TInt i = 0;TInt ui = KImageNumPixels;TInt vi = KImageNumPixels + KImageNumPixels/4; // iYuv is an array of TUint8 values, length (KImageNumPixels*3/2) for(TInt j=0; j < KImageHeigth; j++)for(TInt k=0; k < KImageWidth; k++)   {   // Y value is generated for each pixel   iYuv[i] = (TUint8)( (  66*sR + 129*sG +  25*sB + 128) >> 8 ) + 16;    // U, V values are generated for every other pixel on every other scanline    if(0 == j%2 && 0 == k%2)     {     iYuv[ui++] = (TUint8)( (-38*sR - 74*sG + 112*sB + 128) >> 8 ) + 128;     iYuv[vi++] = (TUint8)( (112*sR - 94*sG - 18*sB + 128) >> 8 ) + 128;     }   i++;    s+=iBytesPerPixel; // Number of bytes representing one pixel in source                      // bitmap e.g. if bitmap display mode == EColor16M                       // (24bits/pixel), then iBytesPerPixel == 3   } iSourceBitmap->UnlockHeap(EFalse);// iYuv now contains the source frame converted to YUV420p format`