-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Conversation
@bsudekum, thanks for your PR! By analyzing this pull request, we identified @tmpsantos, @jfirebaugh and @tmcw to be potential reviewers. |
Can you make the following API adjustments:
So, you'd call it like:
|
return Nan::ThrowTypeError("imageBuffer parameter required"); | ||
} | ||
|
||
double imageHeight = Nan::Get(imageObject, Nan::New("height").ToLocalChecked()).ToLocalChecked()->NumberValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imageHeight
and imageWidth
should be integers -- validate the type using IsUint32
rather than IsNumber
and convert using Uint32Value
rather than NumberValue
, assigning to a uint32_t
rather than a double
.
double imageHeight = Nan::Get(imageObject, Nan::New("height").ToLocalChecked()).ToLocalChecked()->NumberValue(); | ||
double imageWidth = Nan::Get(imageObject, Nan::New("width").ToLocalChecked()).ToLocalChecked()->NumberValue(); | ||
auto imageBuffer = Nan::Get(imageObject, Nan::New("imageBuffer").ToLocalChecked()).ToLocalChecked()->ToObject(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a check here that the expected size is correct:
if (node::Buffer::Length(imageBuffer) != imageHeight * imageWidth * 4) {
return Nan::ThrowTypeError("image size does not match buffer size");
}
One option is to write an unit test like
|
It would be better to write a test-suite render test that can be used to test the implementation of the equivalent GL JS feature. Similar tests of the runtime styling API are in this directory. Take a look at the Since we can't embed literal image data into the style.json, the format I'd propose for the |
@jfirebaugh started to go down the route of adding a custom |
Also, let's require specifying an ID for the |
@jfirebaugh this is ready for review |
pixelRatio: 1 | ||
}); | ||
|
||
map.addLayer({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be test-specific; that is the add-image test should use:
"operations": [
[
"addImage",
"marker",
"./image/marker.png"
],
[
"addLayer",
...
],
[
"wait"
]
]
|
||
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()); | ||
mbgl::PremultipliedImage cPremultipliedImage({ static_cast<uint32_t>(imageWidth), static_cast<uint32_t>(imageHeight) }, std::move(data)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need static_cast
s here.
uint32_t imageHeight = Nan::Get(optionObject, Nan::New("height").ToLocalChecked()).ToLocalChecked()->Uint32Value(); | ||
uint32_t imageWidth = Nan::Get(optionObject, Nan::New("width").ToLocalChecked()).ToLocalChecked()->Uint32Value(); | ||
|
||
if (imageWidth > 1024 && imageHeight > 1024) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be ||
rather than &&
.
}); | ||
|
||
applyOperations(operations.slice(1), callback); | ||
} else if (operation[0] === 'addLayer') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addLayer
is already handled by the subsequent else
block.
Can you open a PR for the mapbox-gl-test-suite additions too? |
uint32_t imageHeight = Nan::Get(optionObject, Nan::New("height").ToLocalChecked()).ToLocalChecked()->Uint32Value(); | ||
uint32_t imageWidth = Nan::Get(optionObject, Nan::New("width").ToLocalChecked()).ToLocalChecked()->Uint32Value(); | ||
|
||
if (imageWidth > 1024 || imageHeight > 1024) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, it’s possible for the image-adding operation to have no effect (and log to stderr) if the size of all the images combined exceeds this 1024-by-1024 square.
This exposes the
addImage
andremoveImage
functions to platform: node. Example usage:The developer then would add a corresponding layer,
myImageName
to style the image.@jfirebaugh I'm not seeing tests for other similar APIs like
addLayer
. How should this be tested?