×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    95

    Convert from RGB888 to YUV420

    Hi all,
    i have seen yesterday post about it, but it don't solve my problem.

    So I have searched information to transform a bitmap in a yuv and i wrote this code, but i can see only the luminance (so my video is b/w) and colors is wrong

    The source bitmap is 176x144.

    CFbsBitmap *iBitmap;
    iBitmap = new (ELeave) CFbsBitmap();
    iBitmap->Load(_L("\\resource\\apps\\DevVideoEx.mbm"),1);

    static TUint8 yuvTable[38016]; // 176*144*3/2

    // Prepara la yuvTable
    // Luminanza
    TRgb rgb;
    float *arrY; arrY = new float[176*144];
    float *arrU; arrU = new float[176*144];
    float *arrV; arrV= new float[176*144];
    float u1, v1;
    int contuv = 0;
    for (int j=0;j<144;j++)
    {
    for(int k=0;k<176;k++)
    {
    // Fill array of Y, U, V
    iBitmap->GetPixel(rgb,TPoint(k,j));
    arrY[k+176*j]= 0.257 *rgb.Red()+0.504 *rgb.Green()+0.098 *rgb.Blue()+16 ;
    arrU[k+176*j]=-0.148*rgb.Red()-0.291*rgb.Green()+0.439 *rgb.Blue()+128;
    arrV[k+176*j]= 0.439 *rgb.Red()-0.368*rgb.Green()-0.071*rgb.Blue()+128;
    }
    }
    u1 = v1 = 0;
    for (int j=0;j<144;j++)
    {
    for(int k=0;k<176;k++)
    {
    yuvTable[k+176*j] = arrY[k+176*j];
    u1 = arrU[k+176*j];
    v1 = arrV[k+176*j];

    // Every four sample of luminance, i write at the end of memory [176*144] a sample of chrominance cb and a sample of chrominance cr
    if ((k+1)%4==0)
    {
    yuvTable[176*144+contuv] = v1;
    contuv++;
    yuvTable[176*144+contuv] = u1;
    contuv++;
    u1 = v1 = 0;
    }
    }
    }

    I have used this documentation for memory block: http://msdn.microsoft.com/en-us/library/ms867704.aspx (figure 13)

    Where is the problem in chrominance?

    Thanks

  2. #2
    Registered User
    Join Date
    Dec 2006
    Posts
    2,280

    Re: Convert from RGB888 to YUV420

    Hi,

    Are you sure that the format (NV12?) you are trying to use is compatible with the codec you're using for your video?

    Sorcery

  3. #3
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    95

    Re: Convert from RGB888 to YUV420

    Quote Originally Posted by Sorcery-ltd View Post
    Hi,

    Are you sure that the format (NV12?) you are trying to use is compatible with the codec you're using for your video?

    Sorcery
    I'm using these values:

    fmt.iDataFormat = EYuvRawData;
    fmt.iYuvFormat.iCoefficients = EYuvBt601Range1; // BT.601 coeffs, full range
    fmt.iYuvFormat.iPattern = EYuv420Chroma2;
    fmt.iYuvFormat.iDataLayout = EYuvDataPlanar;
    fmt.iYuvFormat.iYuv2RgbMatrix = NULL;
    fmt.iYuvFormat.iRgb2YuvMatrix = NULL;
    fmt.iYuvFormat.iAspectRatioNum = 1;
    fmt.iYuvFormat.iAspectRatioDenom = 1;
    iDvr->SetInputFormatL(iEnc, fmt, iSize);

    I must use NV12 of the many YUV standard?


    Thanks for reply.

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,684

    Re: Convert from RGB888 to YUV420

    This part
    Quote Originally Posted by negus View Post
    Code:
                       if ((k+1)%4==0)
                           {
                               yuvTable[176*144+contuv] = v1;
                               contuv++;
                               yuvTable[176*144+contuv] = u1;
                               contuv++;
                               u1 = v1 = 0;
                           }
                                     }
           }
    seems to be EYuvDataSemiPlanar to me.
    EYuvDataPlanar would be
    Code:
                               yuvTable[176*144+contuv] = v1;
                               yuvTable[176*144+88*72+contuv] = u1;
                               contuv++;
                               u1 = v1 = 0;
    Also note the effect of [CODE ] and [/CODE ] tags.

Similar Threads

  1. how to convert ARGB8888 to YUV420
    By sunyiii in forum Symbian Media (Closed)
    Replies: 5
    Last Post: 2008-11-26, 10:23

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×