|
|
|
@ -39,9 +39,8 @@ void quirc_destroy(struct quirc *q) |
|
|
|
|
free(q->image); |
|
|
|
|
/* q->pixels may alias q->image when their type representation is of the
|
|
|
|
|
same size, so we need to be careful here to avoid a double free */ |
|
|
|
|
if (sizeof(*q->image) != sizeof(*q->pixels)) |
|
|
|
|
if (!QUIRC_PIXEL_ALIAS_IMAGE) |
|
|
|
|
free(q->pixels); |
|
|
|
|
free(q->row_average); |
|
|
|
|
free(q); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -49,7 +48,6 @@ int quirc_resize(struct quirc *q, int w, int h) |
|
|
|
|
{ |
|
|
|
|
uint8_t *image = NULL; |
|
|
|
|
quirc_pixel_t *pixels = NULL; |
|
|
|
|
int *row_average = NULL; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* XXX: w and h should be size_t (or at least unsigned) as negatives |
|
|
|
@ -82,35 +80,27 @@ int quirc_resize(struct quirc *q, int w, int h) |
|
|
|
|
(void)memcpy(image, q->image, min); |
|
|
|
|
|
|
|
|
|
/* alloc a new buffer for q->pixels if needed */ |
|
|
|
|
if (sizeof(*q->image) != sizeof(*q->pixels)) { |
|
|
|
|
if (!QUIRC_PIXEL_ALIAS_IMAGE) { |
|
|
|
|
pixels = calloc(newdim, sizeof(quirc_pixel_t)); |
|
|
|
|
if (!pixels) |
|
|
|
|
goto fail; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* alloc a new buffer for q->row_average */ |
|
|
|
|
row_average = calloc(w, sizeof(int)); |
|
|
|
|
if (!row_average) |
|
|
|
|
goto fail; |
|
|
|
|
|
|
|
|
|
/* alloc succeeded, update `q` with the new size and buffers */ |
|
|
|
|
q->w = w; |
|
|
|
|
q->h = h; |
|
|
|
|
free(q->image); |
|
|
|
|
q->image = image; |
|
|
|
|
if (sizeof(*q->image) != sizeof(*q->pixels)) { |
|
|
|
|
if (!QUIRC_PIXEL_ALIAS_IMAGE) { |
|
|
|
|
free(q->pixels); |
|
|
|
|
q->pixels = pixels; |
|
|
|
|
} |
|
|
|
|
free(q->row_average); |
|
|
|
|
q->row_average = row_average; |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
/* NOTREACHED */ |
|
|
|
|
fail: |
|
|
|
|
free(image); |
|
|
|
|
free(pixels); |
|
|
|
|
free(row_average); |
|
|
|
|
|
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
@ -133,6 +123,8 @@ static const char *const error_table[] = { |
|
|
|
|
|
|
|
|
|
const char *quirc_strerror(quirc_decode_error_t err) |
|
|
|
|
{ |
|
|
|
|
if ((int)err < 8) { return error_table[err]; } |
|
|
|
|
else { return "Unknown error"; } |
|
|
|
|
if ((int)err >= 0 && (int)err < sizeof(error_table) / sizeof(error_table[0])) |
|
|
|
|
return error_table[err]; |
|
|
|
|
|
|
|
|
|
return "Unknown error"; |
|
|
|
|
} |
|
|
|
|