Hi Paul, bitmap resource passed from EW to native code looks like RGB888. I had to look at the pixel RGB data stored in a 32 bit integer using 24 bits of it in the native C code.
See code below where I modified the bitmap to gray scale (actually the gray scale was not done to the proper formula where it should have been using: grayValue = (BYTE)(0.299*redValue + 0.587*greenValue + 0.114*blueValue)). I just changed the "dest" pointer to : unsigned int* dest; and took the width = 2* aBitmap->FrameSize.X back to its original width = aBitmap->FrameSize.X
Also I had to modify the for loop. Did not use the "ofs"
//for ( y = 0 ; y < height; y++, dest += ofs )
for ( y = 0 ; y < height; y++, dest++ )
for ( x = 0; x < width; x++, dest++ )
{ ..
This way I could see the modified image in its entirety
Here is the "Inline" code below:
#include <stdio.h>
#include <stdlib.h>
#include "ewrte.h"
#include "ewgfxdriver.h"
#include "ewextgfx.h"
#include "ewgfxdefs.h"
#include "ewextpxl_RGB565.h"
void ProcessBitmap( XBitmap* aBitmap )
{
XRect lockArea;
XBitmapLock* lock;
int width;
int height;
//unsigned short* dest;
unsigned int* dest;
unsigned short red, green, blue;
unsigned int sum_color;
int ofs;
int x, y;
width = aBitmap->FrameSize.X;
height = aBitmap->FrameSize.Y;
/* Lock the entire bitmap for write/read operation */
lockArea.Point1.X = 0;
lockArea.Point1.Y = 0;
lockArea.Point2.X = width;
lockArea.Point2.Y = height;
lock = EwLockBitmap( aBitmap, 0, lockArea, 1, 1 );
dest = (unsigned short*)lock->Pixel1;
ofs = ( lock->Pitch1Y / 2 ) - width;
/* Iterate through the pixel within the locked area. Do this
row-by-row and column-by-column. */
//for ( y = 0 ; y < height; y++, dest += ofs )
for ( y = 0 ; y < height; y++, dest++ )
for ( x = 0; x < width; x++, dest++ )
{
red = (*dest & 0xff0000) >> 16;
green = (*dest & 0x00ff00) >> 8;
blue = (*dest & 0x0000ff) ;
sum_color = red + green + blue;
sum_color = sum_color/3;
// Actually this values should be calculated as
// grayValue = (BYTE)(0.299*redValue + 0.587*greenValue + 0.114*blueValue);
if (sum_color > 0xff)
sum_color = 0xff; //cieling sqrt(pow(Gx,2.0)
*dest = (sum_color << 16 ) | (sum_color << 8) | sum_color;
}
/* Don't forget to unlock the bitmap when you are done! */
EwUnlockBitmap( lock );
}
The Platform STM32F746 is set for RGB565.
