Hello mmd,
I'm still not quite sure what you intend to do. Are you developing a camera application with a function to store and playback the video/images on an SD card? If yes, I would handle all the camera and SD card operations in C code, outside of Embedded Wizard. Only the images you want to present to the user would be passed to Embedded Wizard by using e.g. the extern bitmap interface.
2. Images read in from Native code need to be store in SD card as .bmp
This could be handled directly in the Native code. Just in the moment when the image is processed you could also store it in a BMP file.
3. Stored images from SD card need to be read back in to EW
This could be implemented using the Extern Bitmap Interface you already explored.
4. Imaged in EW need to be passed on to Native code for processing.
This is problematic although not impossible. Finally it depends on what you mean with 'processing'. Generally, to solve this task more detailed understanding of how bitmaps are managed in Embedded Wizard is needed. I will try to explain it:
1. Within Embedded Wizard, bitmaps are represented by objects of a Resources::Bitmap class. Such object encapsulates the bitmap. It is, however, not the bitmap itself.
2. The real bitmap is managed by the Graphics Engine. This is a native code library existing in the target system. Within the Graphics Engine, bitmaps are represented by XBitmap structures. You learned this already when adapting the EwLoadExternBitmap() function.
3. The Resources::Bitmap object refers an XBitmap structure existing within the Graphics Engine. This connection is established by the internal variable bitmap of Resources::Bitmap class.
Following Chora code snippet shows how you access the internal variable bitmap and then invoke an external C function and pass the bitmap to it for processing:
var Resources::Bitmap choraBitmapObject = ...
var handle theRealBitmap = choraBitmapObject.bitmap;
native ( theRealBitmap )
{
extern void ProcessBitmap( XBitmap* aBitmap );
ProcessBitmap((XBitmap*)theRealBitmap );
}
Now, you implement a C module with a C function ProcessBitmap(). There you lock the bitmap and so access its pixel, similarly to how you created the bitmap in EwLoadExternBitmap():
void ProcessBitmap( XBitmap* aBitmap )
{
XRect lockArea;
XBitmapLock* lock;
int width;
int height;
unsigned short* dest;
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( bitmap, 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 ( x = 0; x < width; x++, dest++ )
{
... use 'dest' to read/write pixel data
}
/* Don't forget to unlock the bitmap when you are done! */
EwUnlockBitmap( lock );
}
When processing bitmaps, be careful:
A. If the bitmap is a resource (e.g. some icon used in the GUI) you should not modify the bitmap. Don't write to such bitmap. Resources are managed in a bitmap cache. Your modification may have an impact on the GUI or it may be lost when the bitmap is discarded from the cache.
B. The reading bitmaps may not work for some target systems. For example, OpenGL manages the bitmaps in its internal texture memory. Once the bitmap is stored there, it is not possible to access its pixel data and read it retrospectively. You can only write to the bitmap. In such case, you have to manage the bitmap by yourself within 'your' memory.
5. Read back processed images back into EW. (This is similar to item 1. Done)
This could be implemented using the Extern Bitmap Interface you already explored.
Does it help you further?
Best regards
Paul Banach