vate static var cpp_dosomething = Lib.load ("cpp_myextension", "cpp_dosomething", 1);
cpp_dosomething(buffer);
And on the cpp side this:
static void cpp_dosomething (cost char * pixelbuffer)
{
// set pixel data in some way
for(int i = 0; i < width * height; i++) {
memset(pixelbuffer + i * 4, 0xff000000, sizeof(int));
}
}
DEFINE_PRIM (cpp_dosomething, 1);
You can use bitmapData.image.buffer.data directly (but you have to be careful about premultiplied alpha and color order) or use the ByteArray APIs to have it handled for you
Either Float32Array or openfl.utils.ByteArray will be a derivative (in current version) of haxe.io.Bytes, this has a b field that has the real bytes and a length field that tells you the length.
Haxe objects passed to C++ come through as an opaque value type, which needs to be cast to the proper C++ types. For example:
static void cpp_dosomething (value pixelbuffer) {
value b = val_field (pixelbuffer, val_id ("b"));
int length = val_int (val_field (pixelbuffer, val_id ("length")));
}
That gives you a reference to the “b” field, and the length value. The tricky part on “b” is that it will be a raw string on Neko, and a buffer object on C++.
static void cpp_dosomething (value pixelbuffer) {
value b = val_field (pixelbuffer, val_id ("b"));
if (val_is_null (b)) return;
unsigned char* data = (unsigned char*)buffer_data (val_to_buffer (b));
if (!data) data = (unsigned char*)val_string (b);
int length = val_int (val_field (pixelbuffer, val_id ("length")));
// do something with data pointer and length int value
}
Thanks a lot, passing a openfl.utils.ByteArray into singmajesty’s cpp_dosomething method worked just fine! But I didn’t manage to access and maniuplate bitmapData.image.buffer.data directly, which is the way I would want to do it ideally to reduce the overhead of having an extra buffer. As far as I understand the Type of bitmapData.image.buffer.data is lime/utils/UInt8Array. But I can’t just directly manipulate that, because it is not a uint8 array, but a hxpp object that has a little bit of extra information?