649 views
in System Integration by

I am trying to decode a png, I have gotten to the poin where I have my raw png bytes. I have pretty much copied the example that was given.

I have created my bitmap

EwCreateBitmap( EW_PIXEL_FORMAT_NATIVE, frameSize, 0, 1 );

I then lock the area

lock              = EwLockBitmap( bitmap, 0, lockArea, 0, 1 );

Obtain the pointer to the first pixel within the locked bitmap:

dest   = (unsigned int*)lock->Pixel1;

After this is done, I begin to traverse the rows and colums of my png. I can printf the RGBA colors and see that they are correct as I am plugging them into the red, blue, green and alpha ints, I also the merge the values into a single 32 bit integer just as the example shows:

unsigned int red   = ptr[0];
unsigned int green = ptr[1];
unsigned int blue  = ptr[2];
unsigned int alpha = ptr[3];

*dest = red | green | blue | alpha;

My problem is that no matter what image I use, the image produced by my extern bitmap is always some kind of greyscale. I also noticed that blacks do not show.

I have tried numerous variations before merging the colors into a 32 bit int, these variations might produce a red tinted image or something like it, but the image never comes out exactly the way it should:

#ifdef EW_PREMULTIPLY_COLOR_CHANNELS
 red   = (( red   * ( alpha + 1 )) >> 8 );
 green = (( green * ( alpha + 1 )) >> 8 );
 blue  = (( blue  * ( alpha + 1 )) >> 8 );
#endif

red   <<= EW_COLOR_CHANNEL_BIT_OFFSET_RED;
green <<= EW_COLOR_CHANNEL_BIT_OFFSET_GREEN;
blue  <<= EW_COLOR_CHANNEL_BIT_OFFSET_BLUE;
alpha <<= EW_COLOR_CHANNEL_BIT_OFFSET_ALPHA;

Do you have any guidance?

1 Answer

0 votes
by

Hello,

maybe there is something going wrong within the color calculation.

When you read the colors from your decoder, by the following code

unsigned int red   = ptr[0];
unsigned int green = ptr[1];
unsigned int blue  = ptr[2];
unsigned int alpha = ptr[3];

then every color component is already shifted to the bits 7...0. Now, if you make the following composition

*dest = red | green | blue | alpha;

then all color components are ored to bits 7...0. This will not work.

Maybe you can do the following: First try to ensure that writing into the destination is working properly. For this purpose, you can just ignore the read value from the decoder and make the following setting:

red = 0xFF;
green = 0x00;
blue = 0x00;
alpha = 0xFF;

#ifdef EW_PREMULTIPLY_COLOR_CHANNELS
  red   = (( red   * ( alpha + 1 )) >> 8 );
  green = (( green * ( alpha + 1 )) >> 8 );
  blue  = (( blue  * ( alpha + 1 )) >> 8 );
#endif

red   <<= EW_COLOR_CHANNEL_BIT_OFFSET_RED;
green <<= EW_COLOR_CHANNEL_BIT_OFFSET_GREEN;
blue  <<= EW_COLOR_CHANNEL_BIT_OFFSET_BLUE;
alpha <<= EW_COLOR_CHANNEL_BIT_OFFSET_ALPHA;
     
/* Now compose the color components to a single 32-bit value and store
   the result in the bitmap memory ... */
*dest = red | green | blue | alpha;

As a result you should get a completely red bitmap. If this works (also for the other color components), then there must be something wrong with the decoder. Otherwise, let me know the result.

Btw: What target are you using?

Best regards,

Manfred.

by
Thanks for the response Manfred.

Yes I am able to create the correct red, green, and blue solid colors. I had a feeling it was a problem with my png decoding capabilities.

I am using libpng on a raspberry pi, the learning curve with this library is rather big. I was able to get the example you have of libjpg working very quickly. Do you have the same sample code but for libpng? I am getting very close to this working.

Thanks for your help,

Jimjamurcode
by
Hi Jimjamurcode,

great to hear that the libjpeg is running within your ExternBitmap loader. So, the reamining problem it is a question of the PNG decoder.

Unfortunatley, for libpng I do not have a ready-to-use example. But I think there should be many examples about converting PNG to BMP in the internet, which could help to make the integration.

Maybe the libpng library is already reporting some error messages that could help.

Best regards,

Manfred.

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...