×

Discussion Board

Results 1 to 15 of 15
  1. #1
    Regular Contributor
    Join Date
    Mar 2009
    Location
    Strasbourg - France
    Posts
    110

    Convert pixel to YUV image

    Hi everybody,

    I have an array of pixel in memory, that I obtain like that :

    Code:
    #define PIXEL TDesC8
    CWsScreenDevice* screenDev = CCoeEnv::Static()->ScreenDevice();
    scr = (PIXEL*) (info().iScreenAddress);
    and I wish have this image in an YUV format.

    (I already think about : pixel -> bitmap -> YUV but my implementation crachs and I wish have something more optimal.)

    Thanks for you help.
    Regards and Peace.

    Cartouche67.

  2. #2
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: Convert pixel to YUV image

    If you have the RAW RGB and you want to convert them to yuv then there are no inbuilt APIs in SDK that can do that. But you can use the same Function that you use in Desktop from RGB to YUV in Symbian.C++.

  3. #3
    Regular Contributor
    Join Date
    Mar 2009
    Location
    Strasbourg - France
    Posts
    110

    Re: Convert pixel to YUV image

    Sorry I don't understand, what you mean "Function that you use in Desktop" ?
    Regards and Peace.

    Cartouche67.

  4. #4
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: Convert pixel to YUV image


  5. #5
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: Convert pixel to YUV image

    (I already think about : pixel -> bitmap -> YUV but my implementation crachs and I wish have something more optimal.)
    Sorry i over looked this part. It seems you already have a function can you let us know what error you are getting and if you still not able to solve the problem can you show us your function

  6. #6
    Regular Contributor
    Join Date
    Mar 2009
    Location
    Strasbourg - France
    Posts
    110

    Re: Convert pixel to YUV image

    Thank you for your reply, this is my code :

    (
    For the RGB to YUV conversion I found the code here : http://wiki.forum.nokia.com/index.ph...YUV_conversion

    and for the MDFDevVideo Record I found the code here http://wiki.forum.nokia.com/index.ph...deo_Record_API

    )



    Code:
                  #define PIXEL TDesC8
    
                  // 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;
    
    
    [...]
    
           CWsScreenDevice* screenDev = CCoeEnv::Static()->ScreenDevice();
    	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
    	User::LeaveIfError(bitmap->Create( TSize(176,144),EColor256 ) ); //TSize(360,640)
    	//copy de la capture dans le bitmap
    	User::LeaveIfError(screenDev->CopyScreenToBitmap(bitmap));
    	
    	LFPRINT((_L("avant la conversion")));
    	
    	/*Debut : code permettant la conversion de bitmap a yuv*/
    	
    	// Lock source bitmap (CFbsBitmap)
    	  bitmap->LockHeap(EFalse);
    	  TUint8* s = (TUint8*)bitmap->DataAddress();
    	     
    	  TInt i = 0;
    	  TInt ui = KImageNumPixels;
    	  TInt vi = KImageNumPixels + KImageNumPixels/4;
    	  
    	  // iYuv is an array of TUint8 values, length (KImageNumPixels*3/2)
    	  LFPRINT((_L("avant la boucle")));
    	    
    	  for(TInt j=0; j < KImageHeigth; j++)
    	    for(TInt k=0; k < KImageWidth; k++)
    	      {
    	      //LFPRINT((_L("dans la boucle")));
    	      // Y value is generated for each pixel
    	      iYuv[i] = (TUint8)( (  66*sR + 129*sG +  25*sB + 128) >> 8 ) + 16;
    	      //Mem::Fill(iYuv+i,1,( (  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;
    	        //Mem::Fill(iYuv+ui,1,( (-38*sR - 74*sG + 112*sB + 128) >> 8 ) + 128);
    	        //ui++;
    	        iYuv[vi++] = (TUint8)( (112*sR - 94*sG - 18*sB + 128) >> 8 ) + 128;
    	        //Mem::Fill(iYuv+vi,1,( (112*sR - 94*sG - 18*sB + 128) >> 8 ) + 128);
    	        //vi++;
    	        }
    	      i++; 
    	      s+=EColor256; // Number of bytes representing one pixel in source
    	                         // bitmap e.g. if bitmap display mode == EColor16M 
    	                         // (24bits/pixel), then iBytesPerPixel == 3
    	      }
    	  
    	  bitmap->UnlockHeap(EFalse);
    	  // iYuv now contains the source frame converted to YUV420p format
    	  
    	  LFPRINT((_L("apres la conversion")));
    	
    	// Write picture
            LFPRINT((_L("WritePictureL")));
            iPic.iData.iDataFormat = EYuvRawData;
            iPic.iData.iDataSize = TSize(176,144);
            iPicDataPtr.Set(iYuv, 176*144*3/2, 176*144*3/2);
            iPic.iData.iRawData = &iPicDataPtr;
            iPic.iOptions = TVideoPicture::ETimestamp;
            iPic.iTimestamp = (1000000 * iPicNum) / 99;
            TRAPD(err, iDvr->WritePictureL(&iPic));
            if ( err != KErrNone ) {
                LFPRINT((_L("WritePictureL failed with %d"), err));
                TestComplete(err);
            }
            iPicNum++;

    I tried to replace iYuv[x]=... with Mem::Fill(iYuv+x... without result.
    Regards and Peace.

    Cartouche67.

  7. #7
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: Convert pixel to YUV image

    Can you point out on which line you are crashing.

    Note: You can use RFileLogger or Carbide.C++ ODD to debug .

  8. #8
    Regular Contributor
    Join Date
    Mar 2009
    Location
    Strasbourg - France
    Posts
    110

    Re: Convert pixel to YUV image

    Ok you can find the complete code here http://fr.sourcepod.com/ktdirm14-204

    the log file give me this :
    Code:
    -- 14:03:07.380625 - DoTestL...
    -- 14:03:07.395625 - NewL()
    -- 14:03:07.400625 - FindEncodersL()
    -- 14:03:07.520625 - Got 1 encoders
    -- 14:03:07.525625 - Get info for encoder 0x10282cfd
    -- 14:03:07.705625 - Not accelerated, but haven't seen one so far -- using this
    -- 14:03:07.710625 - Selecting encoder 0x10282cfd
    -- 14:03:07.750625 - Setting input format
    -- 14:03:07.760625 - Setting output format
    -- 14:03:07.765625 - Setting buffer options
    -- 14:03:07.775625 - SetSourceMemoryL
    -- 14:03:07.781250 - Initialize
    -- 14:03:07.841250 - MdvroInitializeComplete(0)
    -- 14:03:07.846250 - Start
    -- 14:03:07.856250 - apres Start
    -- 14:03:07.861250 - avant la conversion
    -- 14:03:07.871250 - avant la boucle
    so there are no logs after the line 304.

    And in Carbide.c++ debuger, the last lines are :
    Code:
     108.830	CVEARMMPEG4EncodeHwDevice::Initialize(), iEncoder [0x4762b648]
       108.830	CVEARMMPEG4EncodeHwDevice::Initialize(), iMaxOutputBufferSize increased to [20480]
       108.830	CVEARMH263EncodeHwDevice::AllocateStructsL(), In
       108.830	CVEARMH263EncodeHwDevice::AllocateStructsL(), iDataArray: [0x4762b908] 
       108.830	CVEARMH263EncodeHwDevice::AllocateStructsL(), [0]: [0x47648814] 
       108.830	CVEARMH263EncodeHwDevice::AllocateStructsL(), [1]: [0x4764d820] 
       108.835	CVEARMH263EncodeHwDevice::AllocateStructsL(), [2]: [0x4765282c] 
       108.835	CVEARMH263EncodeHwDevice::AllocateStructsL(), [3]: [0x47657838] 
       108.835	CVEARMH263EncodeHwDevice::AllocateStructsL(), iOutBufferArray: [0x4762c7b0] 
       108.835	CVEARMH263EncodeHwDevice::AllocateStructsL(), iDataArrayUnc: [0x4762c954] 
       108.835	CVEARMH263EncodeHwDevice::AllocateStructsL(), iOutBuffSize: [0x4762c11c] 
       108.835	CVEARMH263EncodeHwDevice::AllocateStructsL(), iVOPCodingTypePtr: [0x4762c1c4] 
       108.840	CVEARMH263EncodeHwDevice::AllocateStructsL(), iKey[0x47648814] 
       108.840	CVEARMH263EncodeHwDevice::AllocateStructsL(), iKey[0x4764d820] 
       108.840	CVEARMH263EncodeHwDevice::AllocateStructsL(), iKey[0x4765282c] 
       108.840	CVEARMH263EncodeHwDevice::AllocateStructsL(), iKey[0x47657838] 
       108.840	CVEARMH263EncodeHwDevice::AllocateStructsL(), Out
       108.840	CVEARMMPEG4EncodeHwDevice::Initialize(), Initialize status [0]
       108.855	CVEARMMPEG4EncodeHwDevice::Start(), In
       108.855	CVEARMMPEG4EncodeHwDevice::Start(), status[0]
       108.855	CVEARMMPEG4EncodeHwDevice::Start(), Out
       108.880	Thread DevvideoEx::DevvideoEx Panic KERN-EXEC 3
    that seems show us that it crashs after the call of Start() line 410, but logs contain the line "apres Start" (that means "after Start" in french), so I don't undertsand where is really the problem.
    Regards and Peace.

    Cartouche67.

  9. #9
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: Convert pixel to YUV image

    i suggest you put some more logs to get the exact error Line.

  10. #10
    Regular Contributor
    Join Date
    Mar 2009
    Location
    Strasbourg - France
    Posts
    110

    Re: Convert pixel to YUV image

    When I added two logs in my program, it crash any more but it doesn't produce a video


    I add
    LFPRINT((_L("Line 340"))); and LFPRINT((_L("Line 352")));
    it appears a lot of time in my log, I'm looking for how put the values of j and k.
    Regards and Peace.

    Cartouche67.

  11. #11
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: Convert pixel to YUV image

    I Donot know how you implemented LFPRINT but you can use RFileLogger for easier Logging .

  12. #12
    Regular Contributor
    Join Date
    Mar 2009
    Location
    Strasbourg - France
    Posts
    110

    Re: Convert pixel to YUV image

    Ok, I managed to write the value of j and k of the loop line 319.

    The logs stopped when k=80 and j=6 after the instruction line 324 ...

    edit : sorry, I opened the logfile too early, the application had not yet finished.
    The values are k=52 and j=54 in the end of the loop.
    And the emulator crash when we obtain these values.
    Last edited by Cartouche67; 2009-04-19 at 15:10.
    Regards and Peace.

    Cartouche67.

  13. #13
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,751

    Re: Convert pixel to YUV image

    It is always a good idea knowing what kind of data you are working with.
    Personally I have absolutely no idea what happens when CopyScreenToBitmap is combined with EColor256 (which is a 256-color => palettized format), but it certainly uses 1 byte per pixel, so accessing "components" (which are actually not there, due to the palettized image) with [0]-[2] does not make any sense.
    The
    s+=EColor256; // Number of bytes representing one pixel in source
    is a "bit" suspicious too. EXy-s are enumerations, the value of EColor256 is actually 4, while it uses 1 byte for representing 1 pixel.
    If you are expecting [0]-[2] to mean something, experiment with EColor16MU (perhaps EColor16M).

  14. #14
    Regular Contributor
    Join Date
    Mar 2009
    Location
    Strasbourg - France
    Posts
    110

    Re: Convert pixel to YUV image

    thank you for your remark wizard, I put EColor16M when I create my bitmap, that mean 1 pixel is coded in 3 bytes, so I put
    Code:
    s+=3;// Number of bytes representing one pixel in source
    It crashs any more, and it produce a video in a QCIF format (176*144). Now the problem is that if I change the resolution of capture (I have to register a video in 360*640), it crashs again.
    The logs indicates that the call of Start() go wrong, do you have any idee of what can I do ?

    edit: I tried with 176*143 (instead 176*144) and it crashs too !
    Last edited by Cartouche67; 2009-04-19 at 21:58.
    Regards and Peace.

    Cartouche67.

  15. #15
    Regular Contributor
    Join Date
    Mar 2009
    Location
    Strasbourg - France
    Posts
    110

    Re: Convert pixel to YUV image

    I think it's another specific problem and I'm going to open an second topic.
    Thanks for your help !
    Regards and Peace.

    Cartouche67.

Similar Threads

  1. How to convert a JPEG image to a PNG image using J2ME Code
    By hussain_afs in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2007-12-31, 16:48
  2. How to convert 3gp bytearray into image in J2ME?
    By Adeesh in forum Streaming and Video
    Replies: 0
    Last Post: 2006-10-25, 07:02
  3. image pixel operation possible?
    By huiben in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2003-08-29, 21:32
  4. Loading Image data from 'raw' bytes
    By LongSteve in forum Mobile Java General
    Replies: 2
    Last Post: 2002-11-20, 17:38

Posting Permissions

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