Decoding jpeg to bmp

Login to reply to this topic.
Wed, 2007-10-03 12:24
Joined: 2007-10-03
Forum posts: 5

Hello,

I am writing a simple piece of code to decode from jpeg to bmp:

_LIT(KJPEGFile, "C:\\planet.jpg");
_LIT(KDecodedBmpFile, "C:\\planet.bmp");
TFileName aJPEGFile(KJPEGFile);
TFileName aDecBmpFile(KDecodedBmpFile);

User::LeaveIfError(RFbsSession::Connect());

RFs aFs;
User::LeaveIfError(aFs.Connect());
CleanupClosePushL(aFs);

CImageDecoder *aImageDecoder = CImageDecoder::FileNewL(aFs, aJPEGFile, CImageDecoder::EOptionAlwaysThread);

CFbsBitmap* aBitmap = new (ELeave) CFbsBitmap();
aBitmap->Create( aImageDecoder->FrameInfo().iOverallSizeInPixels,
aImageDecoder->FrameInfo().iFrameDisplayMode );

TRequestStatus aStatus;
aImageDecoder->Convert(&aStatus, *aBitmap);
User::WaitForRequest(aStatus);

TInt aError = aBitmap->Save(aDecBmpFile);

When I try to open the planet.bmp file, I get a message that it is not valid. However, when I use the following code, the resulting bitmap
file is valid and I am able to open it (the file is also bigger in size)...

_LIT(KJPEGFile, "C:\\planet.jpg");
_LIT(KDecodedBmpFile, "C:\\planet.bmp");
TFileName aJPEGFile(KJPEGFile);
TFileName aDecBmpFile(KDecodedBmpFile);

User::LeaveIfError(RFbsSession::Connect());

RFs aFs;
User::LeaveIfError(aFs.Connect());
CleanupClosePushL(aFs);

CImageDecoder *aImageDecoder = CImageDecoder::FileNewL(aFs, aJPEGFile, CImageDecoder::EOptionAlwaysThread);

CFbsBitmap* aBitmap = new (ELeave) CFbsBitmap();
aBitmap->Create( aImageDecoder->FrameInfo().iOverallSizeInPixels,
aImageDecoder->FrameInfo().iFrameDisplayMode );

TRequestStatus aStatus;
aImageDecoder->Convert(&aStatus, *aBitmap);
User::WaitForRequest(aStatus);


TUid aImageType = TUid::Uid(0x101f45b0);
TUid aImageSubType = TUid::Uid(0x0);

CImageEncoder* aImageEncoder = CImageEncoder::FileNewL( aFs, aDecBmpFile,
CImageEncoder::EOptionAlwaysThread, aImageType, aImageSubType);

aImageEncoder->Convert(&aStatus, *aBitmap);
User::WaitForRequest(aStatus);

It just seems a bit strange that i have to use both the decoder and edncoder API's in order to successfully turn a jpg to a bmp, which is just
a decoding operation. This method would also require me to use both decode and encode API's if I just wanted to encode a bmp to any
other format. Anyone have any thoughts/suggestions on what I am doing wrong?...Thanks


Wed, 2007-10-03 12:36
Joined: 2004-11-29
Forum posts: 1232
Re: Decoding jpeg to bmp

windows "bmp" is not a raw bitmap, it has headers and stuff, and might even be compressed (with a simple non-destructive RLE compression)
So there is nothing strange with that the symbian memory bitmap has to be "encoded" into it. (even though the encoding in this case is very simple)

The reason you can't open it after using "Save" is that this function does not save the bitmap in windows "bmp" format, but its own format.
Might be mbm, but I've heard some say otherwise..

CImageEncoder is the class to use if you need a portable format that should work in other operating systems.

Thu, 2007-10-04 12:16
Joined: 2004-05-21
Forum posts: 286
Re: Decoding jpeg to bmp

Might be mbm, but I've heard some say otherwise

Yes CFbsBitmap::Save wil save in mbm format *only*

Cheers,
Sri

Mon, 2007-10-08 17:10
Joined: 2007-10-03
Forum posts: 5
Re: Decoding jpeg to bmp

Anyone know how I could view an mbm image without having to convert it to some encoded format?

Tue, 2007-10-09 11:43
Joined: 2006-09-18
Forum posts: 68
Re: Decoding jpeg to bmp

If you want to view it on Windows then Nokia supplies a program called mbmviewer which you can use. The phone's default viewer should be able to display an mbm file as well.
"C:\Symbian\9.1\S60_3rd_MR\S60Tools\mbmviewer\mbmviewer.exe"

  • Login to reply to this topic.