How to write to Uint8ClampedArray?

2019-08-01 09:59发布

I'm writing a node addon which accepts HTML canvas Image data, that's of type Uint8ClampedArray. I want to modify the the contents of this array without any extra copy.

The best candidate I've found is the v8::Object::Set method (v8::Object being a class in Uint8ClampedArray's inheritance hierarchy)

However that method requires a handle to v8::Context object as first argument. I don't know how to get that.

I've searched through github repos and found code inside Webkit that directly casts Uint8ClampedArray pointers to raw array pointers, however that doesn't seem to be possible through the public v8 API.

1条回答
霸刀☆藐视天下
2楼-- · 2019-08-01 10:39

Ok, figured it out.

v8::Local<v8::Uint8ClampedArray> arr;
unsigned char *data = (unsigned char *)arr->Buffer()->GetContents().Data();
查看更多
登录 后发表回答