Bitmap to DesC--Plz help urgent
Login to reply to this topic.
Thu, 2005-05-12 07:21
Joined: 2005-02-10
Forum posts: 27
Hey Everyone,


               I was trying to convert the Bitmap frames of viewfinder to Desc and then convert it back to Bitmap. The code is below:
Code:

void CVideoRecorder::ViewFinderFrameReady(CFbsBitmap& aFrame)

   {



delete iBuffer;

iBuffer=NULL;



delete iEncoder;

iEncoder=NULL;



delete iDecoder;

iDecoder=NULL;



iBuffer=HBufC8::NewL(500);



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

       iEncoder->Convert(aStatus,aFrame);





delete iBitmap;

iBitmap=NULL;



iBitmap=new(ELeave)CFbsBitmap();



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

iDecoder->Convert(aStatus,*iBitmap);



      iAppView->DrawImage(iBitmap);

   }


When I run the application, it says "Programname Closed".

Can anyone please tell me what changes I need to make in this code.

Thanks in Advance.

Mon, 2005-05-16 08:00
Joined: 2004-01-09
Forum posts: 187
create the file ErrRd (blank, with no extension) in the folder \Epoc32\wins(cw)\c\system\bootdata.

than try to run ur app on emulator,  it will give the panic number.

remember ErrRd file have no extention and no contents(means empty file).

Than try to find out the detail of that panic code in SDK Help.

----
Chetan Kulshrestha

Mon, 2005-05-16 08:30
Joined: 2004-07-28
Forum posts: 1379
What type is "aStatus"?

didster

Mon, 2005-05-16 11:12
Joined: 2005-02-10
Forum posts: 27
Thanks Chetan I was wondering how to get the panic code.

 Hey didster,

          aStatus is of TRequeStatus * type.
 
       Didster , can you show me any sample working code for bitmap to desc encoding using CimageEncoder or any links to documents or tutorials using CImageEncoder class.

     If u have any working code with you plz send it to this address ihjazmohamed@hotmail.com.

Thanks in advance.
Mon, 2005-05-16 11:19
Joined: 2004-07-28
Forum posts: 1379
Well, there is your problem.  Loook in the help:

On completion contains KErrNone if the bitmap was encoded successfully, otherwise one of the other system-wide error codes.


"On Completion" - it doesn't complete immediatly!!  i.e. Convert is a asynchronous function which needs to be wrapped up in an active object.

You're not waiting for it to complete.

didster

Mon, 2005-05-16 11:32
Joined: 2005-02-10
Forum posts: 27
Hey didster

Thanks for replying.

Can you tell me how am supposed to code to wait for the completion of encoding.

Thanks.
Mon, 2005-05-16 11:43
Joined: 2004-07-28
Forum posts: 1379
Assuming your class doesn't derive from anything (apart from CBase), you want something like this.

Note, if you class does derive from another C class, then it's sligtly different (you need to split the two classes up basically)

Code:
class CVideoRecorder : public CActive
{
public:
CVideoRecorder(CMyAppView* aAppView);
~CVideoRecorder();

void ViewFinderFrameReadyL(const CFbsBitmap& aFrame);

protected:
void RunL();
void DoCancel();

private:
CMyAppView* iAppView;

enum TState
{
EUnknown,
EEncoding
EDecoding
};

TState iState;
.
.
.
};

CVideoRecorder::CVideoRecorder(CMyAppView* aAppView) :
iAppView(aAppView),
CActive(EPriorityNormal)
{
CActiveScheduler::Add(this);
}

CVideoRecorder::~CVideoRecorder()
{
Cancel();
}


void CVideoRecorder::ViewFinderFrameReadyL(const CFbsBitmap& aFrame)
{
if(IsActive())
{
User::Leave(KErrInUse);
}

delete iBuffer;
iBuffer=NULL;

     
      delete iEncoder;
      iEncoder=NULL;

      delete iDecoder;
      iDecoder=NULL;
     
      iBuffer=HBufC8::NewL(500);
      iEncoder=CImageEncoder::DataNewL(iBuffer,CImageEncoder::EOptionNone,imageType,imageSubType);

iState = EEncoding;
       iEncoder->Convert(iStatus, aFrame);
       SetActive();
       }
       
void CVideoRecorder::RunL()
{
if(iStatus.Int() == KErrNone)
{
switch(iState)
{
case EEncoding:
{
delete iBitmap;
iBitmap=NULL;

iBitmap=new(ELeave)CFbsBitmap();

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

iState = EDecoding;
      iDecoder->Convert(iStatus,*iBitmap);
      SetActive();
      break;
}
case EDecoding:
{
iAppView->DrawImage(iBitmap);
break;
}
}
}
else
{
// error!
}
}

void CVideoRecorder::DoCancel()
{
switch(iState)
{
case EEncoding:
{
iEncoder->Cancel();
break;
}
case EDecoding:
{
iDecoder->Cancel();
break;
}
}
}


NOTE:  the CFbsBitmap passed to ViewFinderFrameReadyL MUST remain in scope right up until the iAppView->DrawImage callback is made!!!

didster

Tue, 2005-05-17 05:15
Joined: 2005-02-10
Forum posts: 27
Hey didster,

Thanks a lot for the code you have shown.

But am still having problems. This is my code right now:
Code:

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::DataNewL(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::DataNewL(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.
Tue, 2005-05-17 08:11
Joined: 2005-04-17
Forum posts: 12
you first solve that problem blow howardchan's article  
and then you can go ahead your program
good luck! Cheezy
Tue, 2005-05-17 08:45
Joined: 2004-07-28
Forum posts: 1379
You use the variable "imageType" - what is it?  Where do you set it?  And what do you set it to?

didster

Tue, 2005-05-17 11:13
Joined: 2005-02-10
Forum posts: 27
Hey didster,

           I have declared the imageType and imageSubType as follows:

        TUid imageType;
        TUid imageSubType;

     I haven't set any value or initialised it.

Thanks
Tue, 2005-05-17 11:45
Joined: 2004-07-28
Forum posts: 1379
Well thats your problem then Smiley

The image encoder is a generic system for encoding images to any number of supported formats.

If you don't tell the encoder what you want it to encode to, how the hell is it suppose to encode it Smiley

You can get a list of supported encoder plugins (and their UIDs) by calling GetImageTypesL.

Once you have done that, go through the list and select which one you want to use, and pass that to DataNewL

didster

Wed, 2005-05-18 07:22
Joined: 2005-02-10
Forum posts: 27
Hey didster,

          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::DataNewL(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::DataNewL(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 didster.

 Thanks
Wed, 2005-05-18 09:11
Joined: 2004-07-28
Forum posts: 1379
Yes there is.  Good old forum nokia Smiley

Change it to:

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

And the leak should go away.

didster

Wed, 2005-05-18 10:56
Joined: 2005-02-10
Forum posts: 27
Hey didster,

   Thanks a lot for that.

Actually am trying stream the viewfinder via bluetooth.

In my appUi am creating  
                     iClient=CmessageClient::NewL(*iAppView);
                     iServer=CmessageServer::NewL(*iAppView);

then in the HandleCommandL()

case Startstreaming: iVideoRecorder=new(ELeave)CVideoRecorder(iClient);

                                   break;

 In the CVideoRecorder after encoding in the RunL() am calling
                 iClient->SendMessageL(iBitmap);

But here I get an error:"Illegal use of incomplete struct/union/Class".

Thanks
Wed, 2005-05-18 10:57
Joined: 2005-02-10
Forum posts: 27
Hey didster,

   Thanks a lot for that.

Actually am trying stream the viewfinder via bluetooth.

In my appUi am creating  
                     iClient=CmessageClient::NewL(*iAppView);
                     iServer=CmessageServer::NewL(*iAppView);

then in the HandleCommandL()

case Startstreaming: iVideoRecorder=new(ELeave)CVideoRecorder(iClient);

                                   break;

 In the CVideoRecorder after encoding in the RunL() am calling
                 iClient->SendMessageL(iBitmap);

But here I get an error:"Illegal use of incomplete struct/union/Class".

Thanks

copyright 2003-2009 NewLC SARL