diff options
author | Bobby Sudekum <bobby@mapbox.com> | 2017-04-07 10:23:31 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-07 10:23:31 -0700 |
commit | 0e72fc4ec3a903bf6a91c3074e6a27275cd87cdd (patch) | |
tree | 525f5789d86623a245b4327e585abcf7b3167d2a /platform | |
parent | 62355bc860ce7e1eb12e07b8c98ec5fb79740aa0 (diff) | |
download | qtlocation-mapboxgl-0e72fc4ec3a903bf6a91c3074e6a27275cd87cdd.tar.gz |
[node] Calculate image buffer and length once (#8673)
Diffstat (limited to 'platform')
-rw-r--r-- | platform/node/src/node_map.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index 674aae7451..1890529393 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -635,13 +635,16 @@ void NodeMap::AddImage(const Nan::FunctionCallbackInfo<v8::Value>& info) { uint32_t pixelRatio = Nan::Get(optionObject, Nan::New("pixelRatio").ToLocalChecked()).ToLocalChecked()->Uint32Value(); auto imageBuffer = Nan::To<v8::Object>(info[1]).ToLocalChecked()->ToObject(); + + char * imageDataBuffer = node::Buffer::Data(imageBuffer); + size_t imageLength = node::Buffer::Length(imageBuffer); - if (node::Buffer::Length(imageBuffer) != imageHeight * imageWidth * 4) { + if (imageLength != imageHeight * imageWidth * 4) { return Nan::ThrowTypeError("Image size does not match buffer size"); } - std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(node::Buffer::Length(imageBuffer)); - std::copy(node::Buffer::Data(imageBuffer), node::Buffer::Data(imageBuffer) + node::Buffer::Length(imageBuffer), data.get()); + std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(imageLength); + std::copy(imageDataBuffer, imageDataBuffer + imageLength, data.get()); mbgl::PremultipliedImage cPremultipliedImage({ imageWidth, imageHeight}, std::move(data)); nodeMap->map->addImage(*Nan::Utf8String(info[0]), std::make_unique<mbgl::SpriteImage>(std::move(cPremultipliedImage), pixelRatio)); |