File tree 3 files changed +9
-20
lines changed 3 files changed +9
-20
lines changed Original file line number Diff line number Diff line change 29
29
"test-server" : " node test/server.js"
30
30
},
31
31
"dependencies" : {
32
- "nan" : " ^2.0.9 "
32
+ "nan" : " ^2.1.0 "
33
33
},
34
34
"devDependencies" : {
35
35
"body-parser" : " ^1.13.3" ,
Original file line number Diff line number Diff line change @@ -736,22 +736,15 @@ NAN_METHOD(Context2d::GetImageData) {
736
736
Local<Object> global = Context::GetCurrent ()->Global ();
737
737
738
738
Local<Int32> sizeHandle = Nan::New (size);
739
- Local<Value> bufargv[] = { sizeHandle };
740
- Local<Object> buffer = global->Get (Nan::New (" ArrayBuffer" ).ToLocalChecked ()).As <Function>()->NewInstance (1 , bufargv);
741
-
742
- Local<Int32> zeroHandle = Nan::New (0 );
743
- Local<Value> caargv[] = { buffer, zeroHandle, sizeHandle };
739
+ Local<Value> caargv[] = { sizeHandle };
744
740
Local<Object> clampedArray = global->Get (Nan::New (" Uint8ClampedArray" ).ToLocalChecked ()).As <Function>()->NewInstance (3 , caargv);
745
- uint8_t *dst = (uint8_t *) clampedArray->GetIndexedPropertiesExternalArrayData ();
746
741
#else
747
742
Local<ArrayBuffer> buffer = ArrayBuffer::New (Isolate::GetCurrent (), size);
748
743
Local<Uint8ClampedArray> clampedArray = Uint8ClampedArray::New (buffer, 0 , size);
749
- #if NODE_MAJOR_VERSION < 3
750
- uint8_t *dst = (uint8_t *)clampedArray->GetIndexedPropertiesExternalArrayData ();
751
- #else
752
- uint8_t *dst = (uint8_t *)buffer->GetContents ().Data ();
753
- #endif
754
744
#endif
745
+
746
+ Nan::TypedArrayContents<uint8_t > typedArrayContents (clampedArray);
747
+ uint8_t * dst = *typedArrayContents;
755
748
756
749
// Normalize data (argb -> rgba)
757
750
for (int y = 0 ; y < sh; ++y) {
Original file line number Diff line number Diff line change @@ -42,8 +42,8 @@ NAN_METHOD(ImageData::New) {
42
42
Local<Uint8ClampedArray> clampedArray;
43
43
#endif
44
44
45
- int width;
46
- int height;
45
+ uint32_t width;
46
+ uint32_t height;
47
47
int length;
48
48
49
49
if (info[0 ]->IsUint32 () && info[1 ]->IsUint32 ()) {
@@ -104,13 +104,9 @@ NAN_METHOD(ImageData::New) {
104
104
return ;
105
105
}
106
106
107
- #if NODE_MAJOR_VERSION < 3
108
- void *dataPtr = clampedArray->GetIndexedPropertiesExternalArrayData ();
109
- #else
110
- void *dataPtr = clampedArray->Buffer ()->GetContents ().Data ();
111
- #endif
107
+ Nan::TypedArrayContents<uint8_t > dataPtr (clampedArray);
112
108
113
- ImageData *imageData = new ImageData (reinterpret_cast <uint8_t *>(dataPtr), width, height);
109
+ ImageData *imageData = new ImageData (reinterpret_cast <uint8_t *>(* dataPtr), width, height);
114
110
imageData->Wrap (info.This ());
115
111
info.This ()->Set (Nan::New (" data" ).ToLocalChecked (), clampedArray);
116
112
info.GetReturnValue ().Set (info.This ());
You can’t perform that action at this time.
0 commit comments