Skip to content

Instantly share code, notes, and snippets.

@yushulx
Created July 17, 2020 03:17
Show Gist options
  • Save yushulx/0e96b717c62e8f7074fe17085a2b5e12 to your computer and use it in GitHub Desktop.
Save yushulx/0e96b717c62e8f7074fe17085a2b5e12 to your computer and use it in GitHub Desktop.
void DecodeBufferAsync(const FunctionCallbackInfo<Value>&amp; args) {
if (!createDBR()) {return;}
Isolate* isolate = Isolate::GetCurrent();
Local<Context> context = isolate->GetCurrentContext();
// get arguments
unsigned char* buffer = (unsigned char*) node::Buffer::Data(args[0]); // file stream
int width = args[1]->Int32Value(context).ToChecked(); // image width
int height = args[2]->Int32Value(context).ToChecked(); // image height
int stride = args[3]->Int32Value(context).ToChecked(); // stride
int iFormat = args[4]->Int32Value(context).ToChecked(); // barcode types
Local<Function> cb = Local<Function>::Cast(args[5]); // javascript callback function
String::Utf8Value templateName(isolate, args[6]); // template name
char *pTemplateName = *templateName;
// initialize BarcodeWorker
BarcodeWorker *worker = new BarcodeWorker;
worker->request.data = worker;
worker->callback.Reset(isolate, cb);
worker->iFormat = iFormat;
worker->pResults = NULL;
worker->buffer = buffer;
worker->width = width;
worker->height = height;
worker->bufferType = RGB_BUFFER;
worker->stride = stride;
if (hasTemplate(pTemplateName)) {
// Load the template.
char szErrorMsg[256];
DBR_InitRuntimeSettingsWithString(hBarcode, pTemplateName, CM_OVERWRITE, szErrorMsg, 256);
worker->useTemplate = true;
}
else {
worker->useTemplate = false;
}
uv_queue_work(uv_default_loop(), &amp;worker->request, (uv_work_cb)DetectionWorking, (uv_after_work_cb)DetectionDone);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment