Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting binary flag to return raw qrcode #35

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/zbarlight/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class UnknownSymbologieError(Exception):
pass


def scan_codes(code_types, image):
def scan_codes(code_types, image, is_binary=False):
"""
Get *code_type* codes from a PIL Image.

Expand Down Expand Up @@ -71,7 +71,8 @@ def scan_codes(code_types, image):
raw = converted_image.tobytes() # Get image data.
width, height = converted_image.size # Get image size.

return zbar_code_scanner(symbologies, raw, width, height)
is_binary_int = 1 if is_binary else 0
return zbar_code_scanner(symbologies, raw, width, height, is_binary_int )


def copy_image_on_background(image, color=WHITE):
Expand Down
11 changes: 8 additions & 3 deletions src/zbarlight/_zbarlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ static char** _zbar_code_scanner(
const void *raw_image_data,
unsigned long raw_image_data_length,
unsigned int width,
unsigned int height
unsigned int height,
unsigned int is_binary
) {
int decoded = -2;
int format = *(int *) "Y800";
char **data = NULL;

zbar_image_scanner_t *scanner = zbar_image_scanner_create();
zbar_image_scanner_set_config(scanner, 0, ZBAR_CFG_ENABLE, 0); /* disable all symbologies */
if (is_binary){
zbar_image_scanner_set_config(scanner, 0, ZBAR_CFG_BINARY, 1);
}
for (int i=0; i < symbologies->number; i++) {
zbar_image_scanner_set_config(scanner, symbologies->symbologie[i], ZBAR_CFG_ENABLE, 1);
}
Expand Down Expand Up @@ -61,11 +65,12 @@ static PyObject* zbar_code_scanner(PyObject *self, PyObject *args) {
Py_ssize_t raw_image_data_length = 0;
unsigned int width = 0;
unsigned int height = 0;
unsigned int is_binary = 0;
struct Symbologies symbologies;
char **result = NULL;
PyObject *data = NULL;

if (!PyArg_ParseTuple(args, "O!SII", &PyList_Type, &python_symbologies, &python_image, &width, &height)) {
if (!PyArg_ParseTuple(args, "O!SIII", &PyList_Type, &python_symbologies, &python_image, &width, &height, &is_binary)) {
return NULL;
}
PyBytes_AsStringAndSize(python_image, &raw_image_data, &raw_image_data_length);
Expand All @@ -76,7 +81,7 @@ static PyObject* zbar_code_scanner(PyObject *self, PyObject *args) {
symbologies.symbologie[i] = PyLong_AsLong(obj);
}

result = _zbar_code_scanner(&symbologies, raw_image_data, raw_image_data_length, width, height);
result = _zbar_code_scanner(&symbologies, raw_image_data, raw_image_data_length, width, height, is_binary);
if (result == NULL) {
Py_RETURN_NONE;
}
Expand Down