Cleanup the code of getBitmap
This commit is contained in:
parent
b5c19a9c6d
commit
1be253e1aa
2 changed files with 20 additions and 15 deletions
|
@ -172,6 +172,9 @@ bool ReadImageSkiaFromICO(gfx::ImageSkia* image, HICON icon) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void Noop(char*, void*) {
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
NativeImage::NativeImage(v8::Isolate* isolate, const gfx::Image& image)
|
NativeImage::NativeImage(v8::Isolate* isolate, const gfx::Image& image)
|
||||||
|
@ -228,18 +231,6 @@ v8::Local<v8::Value> NativeImage::ToBitmap(v8::Isolate* isolate) {
|
||||||
bitmap->getSafeSize()).ToLocalChecked();
|
bitmap->getSafeSize()).ToLocalChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
void noop(char*, void*) {}
|
|
||||||
|
|
||||||
v8::Local<v8::Value> NativeImage::GetBitmap(v8::Isolate* isolate) {
|
|
||||||
const SkBitmap* bitmap = image_.ToSkBitmap();
|
|
||||||
SkPixelRef* ref = bitmap->pixelRef();
|
|
||||||
return node::Buffer::New(isolate,
|
|
||||||
reinterpret_cast<char*>(ref->pixels()),
|
|
||||||
bitmap->getSafeSize(),
|
|
||||||
&noop,
|
|
||||||
nullptr).ToLocalChecked();
|
|
||||||
}
|
|
||||||
|
|
||||||
v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
|
v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
|
||||||
std::vector<unsigned char> output;
|
std::vector<unsigned char> output;
|
||||||
gfx::JPEG1xEncodedDataFromImage(image_, quality, &output);
|
gfx::JPEG1xEncodedDataFromImage(image_, quality, &output);
|
||||||
|
@ -258,6 +249,16 @@ std::string NativeImage::ToDataURL() {
|
||||||
return data_url;
|
return data_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v8::Local<v8::Value> NativeImage::GetBitmap(v8::Isolate* isolate) {
|
||||||
|
const SkBitmap* bitmap = image_.ToSkBitmap();
|
||||||
|
SkPixelRef* ref = bitmap->pixelRef();
|
||||||
|
return node::Buffer::New(isolate,
|
||||||
|
reinterpret_cast<char*>(ref->pixels()),
|
||||||
|
bitmap->getSafeSize(),
|
||||||
|
&Noop,
|
||||||
|
nullptr).ToLocalChecked();
|
||||||
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> NativeImage::GetNativeHandle(v8::Isolate* isolate,
|
v8::Local<v8::Value> NativeImage::GetNativeHandle(v8::Isolate* isolate,
|
||||||
mate::Arguments* args) {
|
mate::Arguments* args) {
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
|
|
|
@ -163,7 +163,8 @@ Returns a [Buffer][buffer] that contains the image's `JPEG` encoded data.
|
||||||
|
|
||||||
#### `image.toBitmap()`
|
#### `image.toBitmap()`
|
||||||
|
|
||||||
Returns a [Buffer][buffer] that contains a copy of the image's raw pixel data.
|
Returns a [Buffer][buffer] that contains a copy of the image's raw bitmap pixel
|
||||||
|
data.
|
||||||
|
|
||||||
#### `image.toDataURL()`
|
#### `image.toDataURL()`
|
||||||
|
|
||||||
|
@ -171,8 +172,11 @@ Returns the data URL of the image.
|
||||||
|
|
||||||
#### `image.getBitmap()`
|
#### `image.getBitmap()`
|
||||||
|
|
||||||
Returns a [Buffer][buffer] that contains the image's raw pixel data. The pixel
|
Returns a [Buffer][buffer] that contains the image's raw bitmap pixel data.
|
||||||
data is not owned by the `Buffer` object.
|
|
||||||
|
The difference between `getBitmap()` and `toBitmap()` is, `getBitmap()` does not
|
||||||
|
copy the bitmap data, so you have to use the returned Buffer immediately in
|
||||||
|
current event loop tick, otherwise the data might be changed or destroyed.
|
||||||
|
|
||||||
#### `image.getNativeHandle()` _macOS_
|
#### `image.getNativeHandle()` _macOS_
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue