Skip to content

Instantly share code, notes, and snippets.

@yushulx
Created November 16, 2020 02:15
Show Gist options
  • Save yushulx/faa7cc3b77ed31b1db870f517249ad6f to your computer and use it in GitHub Desktop.
Save yushulx/faa7cc3b77ed31b1db870f517249ad6f to your computer and use it in GitHub Desktop.
void decode_barcode_buffer(void* barcodeReader, const unsigned char *data, int width, int height, int channel, boolean has_region, int left, int right, int top, int bottom)
{
if (has_region)
{
PublicRuntimeSettings settings;
char errorMessage[256];
int errorCode = DBR_GetRuntimeSettings(barcodeReader, &settings);
settings.region.regionLeft = left;
settings.region.regionRight = right;
settings.region.regionTop = top;
settings.region.regionBottom = bottom;
settings.region.regionMeasuredByPercentage = 0;
settings.barcodeFormatIds = BF_QR_CODE;
settings.expectedBarcodesCount = 1;
settings.localizationModes[2] = LM_SKIP;
settings.localizationModes[3] = LM_SKIP;
DBR_UpdateRuntimeSettings(barcodeReader, &settings, errorMessage, 256);
}
double time = get_time_point();
ImagePixelFormat format = IPF_RGB_888;
if (channel == 1)
{
format = IPF_GRAYSCALED;
}
else if (channel == 4)
{
format = IPF_ARGB_8888;
}
int errorCode = DBR_DecodeBuffer(barcodeReader, data, width, height, width * channel, format, "");
printf(" Barcode buffer decoding in %lf milli-seconds.\n", ((double)get_time_point() - time) / 1000);
TextResultArray *resultArray = NULL;
DBR_GetAllTextResults(barcodeReader, &resultArray);
if (resultArray->resultsCount == 0)
{
printf("No barcode found.\n");
}
else
{
int index = 0;
for (; index < resultArray->resultsCount; index++)
{
printf(" Type: %s, Value: %s \n\n", resultArray->results[index]->barcodeFormatString, resultArray->results[index]->barcodeText);
}
}
DBR_FreeTextResults(&amp;resultArray);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment