×

Discussion Board

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

    Wink Convert from RGB888 to YUV420

    Hi all,
    to thanks you of support given to me, i'll post the code to correctly convert from RGB888 to YUV420:

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

    #define _R ((TInt32)(s[2]))
    #define _G ((TInt32)(s[1]))
    #define _B ((TInt32)(s[0]))
    #define _BPP 3 // bytes per pixel, check color depth of source bitmap

    LOCAL_C inline int Clamp255( TInt aVal )
    {
    if (aVal <= 0)
    return 0;
    if (aVal >= 255)
    return 255;
    return aVal;
    }

    void CMediaVideoRecord::PreparaYUVTable()
    {
    TInt index = iArrIndicesImages->operator [](iCurrentArrIndicesImage);
    CFbsBitmap *iBitmap = new (ELeave) CFbsBitmap();
    iBitmap->Load(_L("\\resource\\apps\\AlfaMitoSymbian_video.mbm"),index);

    /**
    * CONVERT FROM CFBSBITMAP TO YUV420
    */
    iBitmap->LockHeap(EFalse);
    TUint8* s = (TUint8*)iBitmap->DataAddress();

    TInt iScanlineLen = CFbsBitmap::ScanLineLength(iBitmap->SizeInPixels().iWidth,
    iBitmap->DisplayMode());
    HBufC8* iScanline = HBufC8::NewL(iScanlineLen);

    iScanline->Des().Copy(s, iScanlineLen);
    Mem::Copy(s, (s+iScanlineLen), iScanlineLen*143);
    Mem::Copy((s+iScanlineLen*143), iScanline->Des().Ptr(), iScanlineLen);

    TInt ui = 176*144;
    TInt vi = 176*144 + (176*144)/4;
    TInt i = 0;
    for(TInt j=0; j < 144; j++)
    for(TInt k=0; k < 176; k++)
    {
    yuvTable[i] = (TUint8)( ( 66*_R + 129*_G + 25*_B + 128) >> 8 ) + 16;

    // U, V values (planar 420), so each U and V covers 2*2 pixels
    if(0 == j%2 && 0 == k%2)
    {
    yuvTable[ui++] = (TUint8)Clamp255(( ( -38*_R - 74*_G + 112*_B + 128) >> 8 ) + 128 );
    yuvTable[vi++] = (TUint8)Clamp255(( ( 112*_R - 94*_G - 18*_B + 128) >> 8 ) + 128 );
    }
    i++; s+=_BPP;
    }
    iBitmap->UnlockHeap(EFalse);
    /**
    * CONVERT FROM CFBSBITMAP TO YUV420
    */

    delete iBitmap;
    }

    ------------------------------------------------------

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4

    Re: Convert from RGB888 to YUV420

    Hi,
    I have tryed same thing but i am not getting the output.

    below is my code...

    _LIT(KImagePath, "z:\\resource\\apps\\MyApp.mbm");

    RPointerArray<CFbsBitmap> bitmapArr;
    CFbsBitmap* iBitmap;

    for(int i=0,j=0; i < 120; i++)
    {
    if(i/5 == 0)
    j++;
    iBitmap = new(ELeave) CFbsBitmap();
    iBitmap->Load(KImagePath, (TMbmDevvideoex)j);
    bitmapArr.AppendL(iBitmap);
    }

    please help..

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,752

    Re: Convert from RGB888 to YUV420

    What have you tried and what kind of result do you expect?

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4

    Re: Convert from RGB888 to YUV420

    Quote Originally Posted by wizard_hu_ View Post
    What have you tried and what kind of result do you expect?
    Hi wizard_hu_,
    Thanks for your quick reply.
    I am trying the below scenario.
    I want to run all the BITMAP file and creat a "c:\\testout.m4v" in the directory so that when i run testout.m4v it will run one image after other.
    I have lets say 20 bit map file.
    In MMP file i have written
    START BITMAP DevVideoEx.mbm to creata mbm file.
    I took the sample code from forum DevvideoEx.zip from nokia forum to create such scenario.

    Please help me.....

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,752

    Re: Convert from RGB888 to YUV420

    Is there a particular thing that does not work? You have DevvideoEx, apparently you already know how to pack and load some images for experimenting. And RGB->YUV conversion code is in #1. _BPP=3 suggests EColor16M display mode for the CFbsBitmap objects, so you should use c24 for the BITMAP statements in the .mmp file.

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4

    Re: Convert from RGB888 to YUV420

    Quote Originally Posted by wizard_hu_ View Post
    Is there a particular thing that does not work? You have DevvideoEx, apparently you already know how to pack and load some images for experimenting. And RGB->YUV conversion code is in #1. _BPP=3 suggests EColor16M display mode for the CFbsBitmap objects, so you should use c24 for the BITMAP statements in the .mmp file.

    Hi

    I have written in my MMP file like below and i got DevVideoEx.mbm file generated.

    START BITMAP DevVideoEx.mbm
    HEADER
    TARGETPATH resource\apps
    SOURCEPATH ..\data
    SOURCE c24 CapturedImage1.bmp
    SOURCE c24 CapturedImage2.bmp
    SOURCE c24 CapturedImage3.bmp
    SOURCE c24 CapturedImage4.bmp
    SOURCE c24 CapturedImage5.bmp
    SOURCE c24 CapturedImage6.bmp
    SOURCE c24 CapturedImage7.bmp
    SOURCE c24 CapturedImage8.bmp
    SOURCE c24 CapturedImage9.bmp
    SOURCE c24 CapturedImage10.bmp
    SOURCE c24 CapturedImage11.bmp
    SOURCE c24 CapturedImage12.bmp
    SOURCE c24 CapturedImage13.bmp
    SOURCE c24 CapturedImage14.bmp
    SOURCE c24 CapturedImage15.bmp
    SOURCE c24 CapturedImage16.bmp
    SOURCE c24 CapturedImage17.bmp
    SOURCE c24 CapturedImage18.bmp
    SOURCE c24 CapturedImage19.bmp
    SOURCE c24 CapturedImage20.bmp
    SOURCE c24 CapturedImage21.bmp
    SOURCE c24 CapturedImage22.bmp
    SOURCE c24 CapturedImage23.bmp
    SOURCE c24 CapturedImage24.bmp
    END

    When i ran the i saw testout.m4v is generated in the path but while running in VLC media player i am not able to run. I have to use some other player or some thing else....

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,752

    Re: Convert from RGB888 to YUV420

    You could check if the device can play it (in that case c:\Data is a better place, or use drive e: ).

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    4

    Re: Convert from RGB888 to YUV420

    Quote Originally Posted by wizard_hu_ View Post
    You could check if the device can play it (in that case c:\Data is a better place, or use drive e: ).
    in the header DevVideoRecord.h
    /**
    Sets pre-processing options for RGB to YUV color space conversion. By default, input RGB data is
    assumed to use the full value range ([0…255]), and the output YUV format is the hardware device
    output format, so typically calling this method is not necessary.

    @param "aHwDevice" "The hardware device to configure. The value is returned from SelectEncoderL()
    or SelectPreProcessorL() when the device is selected."
    @param "aRgbRange" "Input RGB data range"
    @param "aOutputFormat" "Conversion output YUV format."
    @leave "The method will leave if an error occurs. Typical error codes used:
    - KErrNotSupported - The formats specified are not supported"
    @pre "This method can only be called before the API has been initialized with Initialize()."
    */
    IMPORT_C void SetRgbToYuvOptionsL(THwDeviceId aHwDevice, TRgbRange aRgbRange, const TYuvFormat& aOutputFormat);

    Can we use "SetRgbToYuvOptionsL" to convert from RGB to YUV..

    // SetRgbToYuvOptionsL
    LFPRINT((_L("SetRgbToYuvOptionsL")));
    TYuvFormat iYuvFormat;
    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->SetRgbToYuvOptionsL(iEnc,ERgbRangeFull,iYuvFormat);

    Please let me know....
    Last edited by symbianindia; 2010-05-10 at 19:03. Reason: Missing info

Similar Threads

  1. Convert from RGB888 to YUV420
    By negus in forum Symbian Media (Closed)
    Replies: 3
    Last Post: 2008-11-27, 15:41

Posting Permissions

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