Return raw image buffer instead of an object

This commit is contained in:
bsudekum
2015-09-04 12:01:34 -07:00
parent 15a66b8989
commit 3db1421eb1
3 changed files with 5 additions and 13 deletions

View File

@@ -258,10 +258,6 @@ void NodeMap::renderFinished() {
cb->Call(1, argv);
} else if (img) {
auto result = NanNew<v8::Object>();
result->Set(NanNew("width"), NanNew(img->width));
result->Set(NanNew("height"), NanNew(img->height));
v8::Local<v8::Object> pixels = NanNewBufferHandle(
reinterpret_cast<char *>(img->pixels.get()),
size_t(img->width) * size_t(img->height) * sizeof(mbgl::StillImage::Pixel),
@@ -274,11 +270,9 @@ void NodeMap::renderFinished() {
);
img.release();
result->Set(NanNew("pixels"), pixels);
v8::Local<v8::Value> argv[] = {
NanNull(),
result,
pixels,
};
cb->Call(2, argv);
} else {

View File

@@ -231,14 +231,12 @@ test('Map', function(t) {
t.test('returns an image', function(t) {
var map = new mbgl.Map(options);
map.load(style);
map.render({}, function(err, data) {
map.render({}, function(err, pixels) {
t.error(err);
map.release();
t.ok(data.pixels);
t.equal(data.width, 512);
t.equal(data.height, 512);
t.ok(pixels);
t.end();
});
});

View File

@@ -21,8 +21,8 @@ suite.run('native', {tests: tests}, function (style, options, callback) {
});
map.load(style);
map.render(options, function (err, result) {
map.render(options, function (err, pixels) {
map.release();
callback(err, result && result.pixels);
callback(err, pixels);
});
});