×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    21

    Bitmap to DesC --plz help

    Hey Everyone,

    I was trying to convert the bitmap frames obtained from viewfinder into DesC format and then back to Bitmap again.The code is:

    void CVideoRecorder::ViewFinderFrameReady(CFbsBitmap& aFrame)

    {


    delete iBuffer;

    iBuffer=NULL;



    delete iEncoder;

    iEncoder=NULL;



    delete iDecoder;

    iDecoder=NULL;



    iBuffer=HBufC8::NewL(500);


    iEncoder=CImageEncoder:ataNewL(iBuffer,CImageEncoder::EOptionNone,imageType,imageSubType);

    iEncoder->Convert(aStatus,aFrame);



    delete iBitmap;

    iBitmap=NULL;



    iBitmap=new(ELeave)CFbsBitmap();


    iDecoder=CImageDecoder:ataNewL(iFs,*iBuffer,CImageDecoder::EOptionNone,imageType,imageSubType,aDecoderUid);

    iDecoder->Convert(aStatus,*iBitmap);



    iAppView->DrawImage(iBitmap);

    }

    When I run the application,it fails. It shows "Programname closed". Please tell me what changes am supposed to make in this code.

    Thanks in Advance

  2. #2
    Super Contributor
    Join Date
    May 2003
    Location
    Vancouver, Canada
    Posts
    985
    I haven't tried the code, but be careful using CImageEncoder::Convert() and CImageDecoder::Convert() because they are asynchronous.

    It means you cannot encode and then decode in the same function. You have to wait the signal from aStatus before decoding the buffer.

    Antony

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    21

    Bitmap to DesC

    Thanks for the suggestion antony. I'll always remember that.

    But that's not the only problem here. Even after commenting the decode part the error is still there.

    Plz help me. I need to finish my project by next week.

  4. #4
    Super Contributor
    Join Date
    May 2003
    Location
    Vancouver, Canada
    Posts
    985
    Do you know where the program crashes? Also make sure that your buffer is large enough (is 500 bytes large enough to hold your image).

    I recommend you to create the buffer depending on the size of the image (using the information from CFbsBitmap).

    Antony

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    21

    bitmap to desc

    Hey antony,

    This is my new code below:
    void CVideoRecorder::ViewFinderFrameReady(CFbsBitmap& aFrame)

    {
    if(IsActive())

    {
    User::Leave(KErrInUse);
    }

    delete iBuffer;
    iBuffer=NULL;

    delete iEncoder;
    iEncoder=NULL;

    CFbsBitmap *iBitmap=&aFrame;

    TSize iSize=iBitmap->SizeInPixels();
    TInt intSize=((iSize.iHeight * iSize.iWidth)*3)+1024;

    iBuffer=HBufC8::NewMaxL(intSize);

    iEncoder=CImageEncoder:ataNewL(iBuffer,CImageEncoder::EOptionNone,imageType,imageSubType);
    iState=EEncoding;

    iEncoder->Convert(iStatus,aFrame);

    SetActive();
    }

    void CVideoRecorder::RunL()

    {
    if(iStatus == KErrNone)
    {
    switch(iState)
    {
    case EEncoding:

    {

    delete iBitmap;
    iBitmap=NULL;

    iBitmap=new(ELeave)CFbsBitmap();

    delete iDecoder;
    iDecoder=NULL;

    iDecoder=CImageDecoder:ataNewL(iFs,*iBuffer,CImageDecoder::EOptionNone,imageType,imageSubType,aDecoderUid);
    iState = EDecoding;

    iDecoder->Convert(iStatus,*iBitmap);

    SetActive();

    break;
    }
    case EDecoding:
    {
    iAppView->DrawImage(iBitmap);
    break;
    }
    }
    }
    else
    { InfoNotifyL(_L("Encode error: "));

    }
    }



    When I run this code I get Panic 17 i.e "The descriptor that is passed is not NULL".



    When I comment this part and run leaving the ibuffer Null



    /* CFbsBitmap *iBitmap=&aFrame;



    TSize iSize=iBitmap->SizeInPixels();
    TInt intSize=((iSize.iHeight * iSize.iWidth)*3)+1024;

    iBuffer=HBufC8::NewMaxL(intSize);

    */



    Then I get Panic 20 i.e "Illegal image type".



    How do I solve this problem.
    Plz help me.
    Last edited by ihjaz; 2005-05-17 at 11:30.

  6. #6
    Super Contributor
    Join Date
    May 2003
    Location
    Vancouver, Canada
    Posts
    985
    Yeap, I think I know what's wrong....

    You have aFrame which declared as a parameter (it means it is local to this function). After you go out from this function, aFrame will no longer be valid. So MMF will convert something that it doesn't recognize. You have to make aFrame somehow global, so that it can be accessed by MMF.

    Antony

  7. #7
    Registered User
    Join Date
    Dec 2004
    Posts
    21

    Bitmap to Desc

    Hey Antony,

    Thanks for replying.

    But I did'nt use aFrame outside the function.

    I have used it only within the ViewFinderFrameReady() function.

  8. #8
    Super Contributor
    Join Date
    May 2003
    Location
    Vancouver, Canada
    Posts
    985
    As I said Convert() is an asynchronous function, so aFrame will be accessed outside ViewFinderFrameReady() by MMF.

    Antony

  9. #9
    Registered User
    Join Date
    Dec 2004
    Posts
    21

    Got it!!

    Hey Antony,
    Its working now. Thanks a lot of your help.

    But still there are some problems. The application is running , its encodeing, decoding & displaying the viewfinder also but a "stop" error keeps coming in between. It says: "Requsted object is used by another application -14".

    And when I exit the application I get an "Alloc" Panic which as the documentation says is due to memory leak, but I can't figure out where memory is leaking.

    This is the new working code:

    void CleanupRArray( TAny* object )
    {
    ((RImageTypeDescriptionArray*)object)->ResetAndDestroy();
    }

    void CVideoRecorder::ViewFinderFrameReady(CFbsBitmap& aFrame)
    {
    aBitmap=&aFrame;
    StartEncodeL();
    }

    void CVideoRecorder::StartEncodeL()
    {
    if(IsActive())
    {
    User::Leave(KErrInUse);
    }

    CImageEncoder::GetImageTypesL(aImageTypeArray);

    CleanupStack::PushL( TCleanupItem(CleanupRArray, &aImageTypeArray) );

    delete iBuffer;
    iBuffer=NULL;

    delete iEncoder;
    iEncoder=NULL;

    iEncoder=CImageEncoder:ataNewL(iBuffer,CImageEncoder::EOptionNone,aImageTypeArray[imageId]->ImageType(),aImageTypeArray[imageId]->SubType());
    iState=EEncoding;

    iEncoder->Convert(&iStatus,*aBitmap);
    SetActive();

    CleanupStack::PopAndDestroy();
    }

    void CVideoRecorder::RunL()
    {
    if(iStatus == KErrNone)
    {
    switch(iState)
    {
    case EEncoding:
    {
    delete iBitmap;
    iBitmap=NULL;

    delete iDecoder;
    iDecoder=NULL;

    iBitmap=new(ELeave)CFbsBitmap();

    iBitmap->Create( aBitmap->SizeInPixels(),

    aBitmap->DisplayMode());

    iDecoder=CImageDecoder:ataNewL(iFs,*iBuffer,CImageDecoder::EOptionNone);

    iState = EDecoding;

    iDecoder->Convert(&iStatus,*iBitmap);
    SetActive();
    break;
    }
    case EDecoding:
    {
    iAppView->DrawImage(aBitmap);
    break;
    }
    }
    }
    else
    {
    InfoNotifyL(_L("Encode error: "));
    }
    }

    I think the memory leak is bcoz the imageTypeArray is not deallocated properly. This is how I found them doing it in an "ImageConverter" application I got from forum.nokia.com

    void CleanupRArray( TAny* object )
    { ((RImageTypeDescriptionArray*)object)->ResetAndDestroy();
    }

    The above is a non-member funtion.
    CImageEncoder::GetImageTypesL(aImageTypeArray);

    CleanupStack::PushL( TCleanupItem(CleanupRArray, &aImageTypeArray) );

    Using TCleanupItem() imageTypeArray is added to the CleanupStack.

    It is popped at the end of the StartEncode() after calling setActive().
    CleanUpStack::PopAndDestroy();

    I feel there is something wrong in this.

    Plz help me out with this .

    Thanks

  10. #10
    Registered User
    Join Date
    Dec 2004
    Posts
    21
    I 've cleared all those errors. Thnaks for your help.

    The bitmap displayed after decoding is not of the same
    quality
    . I used aDisplayMode=EColor16M. Is there anythng I need to do while encoding to retain the quality of image.

    // Decoding Descriptor to bitmap

    delete iDecoder;
    iDecoder=NULL;

    delete iBitmap;
    iBitmap=NULL;

    TSize imageSize(KDefaultImageWidth,KDefaultImageHeight);

    iBitmap=new(ELeave)CFbsBitmap();

    iDecoder=CImageDecoder:ataNewL(iFs,*iBuffer,CImageDecoder::EOptionNone);

    iFrameInfo=&iDecoder->FrameInfo(0);
    iBitmap->Create(iFrameInfo->iOverallSizeInPixels,aDisplayMode);

    iState = EDecoding; iDecoder->Convert(&iStatus,*iBitmap);
    SetActive();

Posting Permissions

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