From b9b5548dc8546b22ea33b948b55ec1ca23a743c5 Mon Sep 17 00:00:00 2001 From: Christian Dittrich Date: Fri, 10 Aug 2018 21:58:16 +0200 Subject: [PATCH] buffers somehow not working correctly and crashing findCode, removed --- src/image.cc | 1 + src/zxing.cc | 17 ++++------------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/image.cc b/src/image.cc index c58f907..1189f7d 100644 --- a/src/image.cc +++ b/src/image.cc @@ -197,6 +197,7 @@ NAN_MODULE_INIT(Image::Init) Nan::SetAccessor(ctorInst, Nan::New("width").ToLocalChecked(), GetWidth); Nan::SetAccessor(ctorInst, Nan::New("height").ToLocalChecked(), GetHeight); Nan::SetAccessor(ctorInst, Nan::New("depth").ToLocalChecked(), GetDepth); + Nan::SetAccessor(ctorInst, Nan::New("resolution").ToLocalChecked(), GetResolution, SetResolution); Nan::SetPrototypeMethod(ctor, "invert", Invert); Nan::SetPrototypeMethod(ctor, "or", Or); diff --git a/src/zxing.cc b/src/zxing.cc index 8f65d58..097c696 100644 --- a/src/zxing.cc +++ b/src/zxing.cc @@ -44,7 +44,7 @@ class PixSource : public zxing::LuminanceSource }; PixSource::PixSource(Pix* pix, bool take) - : LuminanceSource(pix ? pix->w : 0, pix ? pix->h : 0) + : LuminanceSource(pix != NULL ? pix->w : 0, pix != NULL ? pix->h : 0) { if (take) { assert(pix->d == 8); @@ -187,11 +187,10 @@ NAN_SETTER(ZXing::SetImage) { ZXing* obj = Nan::ObjectWrap::Unwrap(info.This()); if (Image::HasInstance(value) || value->IsNull()) { - if (!obj->image_.IsEmpty()) { - obj->image_.Reset(); - } if (!value->IsNull()) { obj->image_.Reset(value->ToObject()); + } else if (!obj->image_.IsEmpty()) { + obj->image_.Reset(); } } else { Nan::ThrowTypeError("value must be of type Image"); @@ -261,15 +260,7 @@ NAN_METHOD(ZXing::FindCode) object->Set(Nan::New("type").ToLocalChecked(), Nan::New(zxing::BarcodeFormat::barcodeFormatNames[result->getBarcodeFormat()]).ToLocalChecked()); object->Set(Nan::New("data").ToLocalChecked(), - Nan::New(resultStr.c_str()).ToLocalChecked()); - if (result->getRawBytes() != NULL) { - std::vector resultRawBytes = (*(result->getRawBytes())).values(); - object->Set(Nan::New("buffer").ToLocalChecked(), - Nan::NewBuffer((char*)resultRawBytes.data(), resultRawBytes.size()).ToLocalChecked()); - } else { - object->Set(Nan::New("buffer").ToLocalChecked(), - Nan::NewBuffer(0).ToLocalChecked()); - } + Nan::New(resultStr).ToLocalChecked()); Local points = Nan::New(); auto strX = Nan::New("x").ToLocalChecked(); auto strY = Nan::New("y").ToLocalChecked();