diff --git a/package.json b/package.json index eb3ab8a..ab8f8dd 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "should": "*" }, "engines": { - "node": ">= 0.12.0" + "node": ">=0.8.0 <3" }, "main": "./lib/canvas.js", "license": "MIT" diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index c3e0b12..e1ad7a2 100755 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -738,9 +738,21 @@ NAN_METHOD(Context2d::GetImageData) { uint8_t *dst = (uint8_t *)calloc(1, size); NanAdjustExternalMemory(size); +#if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION <= 10 + Local global = Context::GetCurrent()->Global(); + + Handle bufargv[] = { NanNew(size) }; + Local buffer = global->Get(NanNew("ArrayBuffer")).As()->NewInstance(1, bufargv); + + Handle caargv[] = { buffer, NanNew(0), NanNew(size) }; + Local clampedArray = global->Get(NanNew("Uint8ClampedArray")).As()->NewInstance(3, caargv); + + clampedArray->SetIndexedPropertiesToExternalArrayData(dst, kExternalPixelArray, size); +#else Local buffer = ArrayBuffer::New(Isolate::GetCurrent(), size); Local clampedArray = Uint8ClampedArray::New(buffer, 0, size); clampedArray->SetIndexedPropertiesToExternalArrayData(dst, kExternalUint8ClampedArray, size); +#endif // Normalize data (argb -> rgba) for (int y = 0; y < sh; ++y) { diff --git a/src/ImageData.cc b/src/ImageData.cc index c94eea6..13ecfaf 100644 --- a/src/ImageData.cc +++ b/src/ImageData.cc @@ -37,22 +37,45 @@ ImageData::Initialize(Handle target) { NAN_METHOD(ImageData::New) { NanScope(); +#if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION <= 10 + Local clampedArray; + Local global = Context::GetCurrent()->Global(); +#else Local clampedArray; +#endif + int width; int height; + if (args[0]->IsUint32() && args[1]->IsUint32()) { width = args[0]->Uint32Value(); height = args[1]->Uint32Value(); int size = width * height; + +#if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION <= 10 + Handle caargv[] = { NanNew(size) }; + Local clampedArray = global->Get(NanNew("Uint8ClampedArray")).As()->NewInstance(1, caargv); +#else clampedArray = Uint8ClampedArray::New(ArrayBuffer::New(Isolate::GetCurrent(), size), 0, size); +#endif + +#if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION <= 10 + } else if (args[0]->ToObject()->GetIndexedPropertiesExternalArrayDataType() == kExternalPixelArray && args[1]->IsUint32()) { + clampedArray = args[0]->ToObject(); +#else } else if (args[0]->IsUint8ClampedArray() && args[1]->IsUint32()) { clampedArray = args[0].As(); +#endif width = args[1]->Uint32Value(); if (args[2]->IsUint32()) { height = args[2]->Uint32Value(); } else { +#if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION <= 10 + height = clampedArray->GetIndexedPropertiesExternalArrayDataLength() / width; +#else height = clampedArray->Length() / width; +#endif } } else { NanThrowTypeError("Expected (Uint8ClampedArray, width[, height]) or (width, height)");