Removed new_image_t, replaced with current image_t.

This commit is contained in:
Kwabena W. Agyeman 2017-01-10 18:25:33 -05:00
parent 5f7b40489b
commit cf4cb787f5
6 changed files with 102 additions and 139 deletions

View File

@ -11,7 +11,7 @@ typedef struct xylf
}
xylf_t;
void imlib_find_blobs(list_t *out, new_image_t *ptr, rectangle_t *roi,
void imlib_find_blobs(list_t *out, image_t *ptr, rectangle_t *roi,
list_t *thresholds, bool invert, unsigned int area_threshold, unsigned int pixels_threshold,
bool merge, int margin)
{
@ -29,8 +29,8 @@ void imlib_find_blobs(list_t *out, new_image_t *ptr, rectangle_t *roi,
color_thresholds_list_lnk_data_t lnk_data;
iterator_get(thresholds, it, &lnk_data);
switch(ptr->type) {
case IMAGE_TYPE_BINARY: {
switch(ptr->bpp) {
case IMAGE_BPP_BINARY: {
for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) {
uint32_t *row_ptr = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(ptr, y);
size_t row_index = BITMAP_COMPUTE_ROW_INDEX(ptr, y);
@ -200,7 +200,7 @@ void imlib_find_blobs(list_t *out, new_image_t *ptr, rectangle_t *roi,
}
break;
}
case IMAGE_TYPE_GRAYSCALE: {
case IMAGE_BPP_GRAYSCALE: {
for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) {
uint8_t *row_ptr = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(ptr, y);
size_t row_index = BITMAP_COMPUTE_ROW_INDEX(ptr, y);
@ -370,7 +370,7 @@ void imlib_find_blobs(list_t *out, new_image_t *ptr, rectangle_t *roi,
}
break;
}
case IMAGE_TYPE_RGB565: {
case IMAGE_BPP_RGB565: {
for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) {
uint16_t *row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(ptr, y);
size_t row_index = BITMAP_COMPUTE_ROW_INDEX(ptr, y);

View File

@ -104,18 +104,17 @@ void rectangle_united(rectangle_t *dst, rectangle_t *src)
// Image Stuff //
/////////////////
void image_init(new_image_t *ptr, new_image_type_t type, int w, int h)
void image_init(image_t *ptr, int w, int h, int bpp, void *data)
{
ptr->type = type;
ptr->w = w;
ptr->h = h;
ptr->size = 0;
ptr->data = NULL;
ptr->bpp = bpp;
ptr->data = data;
}
void image_copy(new_image_t *dst, new_image_t *src)
void image_copy(image_t *dst, image_t *src)
{
memcpy(dst, src, sizeof(new_image_t));
memcpy(dst, src, sizeof(image_t));
}
// Gamma uncompress

View File

@ -99,7 +99,7 @@ typedef struct rectangle {
void rectangle_init(rectangle_t *ptr, int x, int y, int w, int h);
void rectangle_copy(rectangle_t *dst, rectangle_t *src);
bool rectangle_equal(rectangle_t *ptr0, rectangle_t *ptr1);
bool rectangle_equal_fast(rectangle_t *ptr0, rectangle_t *ptr1);
bool rectangle_overlap(rectangle_t *ptr0, rectangle_t *ptr1);
void rectangle_intersected(rectangle_t *dst, rectangle_t *src);
void rectangle_united(rectangle_t *dst, rectangle_t *src);
@ -268,27 +268,27 @@ extern const int8_t yuv_table[196608];
// Image Stuff //
/////////////////
typedef enum new_image_type
typedef enum image_bpp
{
IMAGE_TYPE_BINARY,
IMAGE_TYPE_GRAYSCALE,
IMAGE_TYPE_RGB565,
IMAGE_TYPE_JPG
IMAGE_BPP_BINARY, // bpp = 0
IMAGE_BPP_GRAYSCALE, // bpp = 1
IMAGE_BPP_RGB565, // bpp = 2
IMAGE_BPP_JPEG // bpp != 0 && bpp != 1 && bpp != 2
}
new_image_type_t;
image_bpp_t;
typedef struct new_image
{
new_image_type_t type;
int16_t w;
int16_t h;
size_t size;
void *data;
}
new_image_t;
typedef struct image {
int w;
int h;
int bpp;
union {
uint8_t *pixels;
uint8_t *data;
};
} image_t;
void image_init(new_image_t *ptr, new_image_type_t type, int w, int h);
void image_copy(new_image_t *dst, new_image_t *src);
void image_init(image_t *ptr, int w, int h, int bpp, void *data);
void image_copy(image_t *dst, image_t *src);
#define IMAGE_GET_BINARY_PIXEL(image, x, y) \
({ \
@ -722,16 +722,6 @@ typedef struct simple_color {
}
simple_color_t;
typedef struct image {
int w;
int h;
int bpp;
union {
uint8_t *pixels;
uint8_t *data;
};
} image_t;
typedef struct integral_image {
int w;
int h;
@ -1069,15 +1059,15 @@ void imlib_find_hog(image_t *src, rectangle_t *roi, int cell_size);
// Lens correction
void imlib_lens_corr(image_t *src, float strength);
// Stats
void imlib_get_histogram(histogram_t *out, new_image_t *ptr, rectangle_t *roi);
void imlib_get_percentile(percentile_t *out, new_image_type_t type, histogram_t *ptr, float percentile);
void imlib_get_statistics(statistics_t *out, new_image_type_t type, histogram_t *ptr);
// Statistics
void imlib_get_histogram(histogram_t *out, image_t *ptr, rectangle_t *roi);
void imlib_get_percentile(percentile_t *out, image_bpp_t bpp, histogram_t *ptr, float percentile);
void imlib_get_statistics(statistics_t *out, image_bpp_t bpp, histogram_t *ptr);
// Color Tracking
void imlib_find_blobs(list_t *out, new_image_t *ptr, rectangle_t *roi,
void imlib_find_blobs(list_t *out, image_t *ptr, rectangle_t *roi,
list_t *thresholds, bool invert, unsigned int area_threshold, unsigned int pixels_threshold,
bool merge, int margin);
// Codes
void imlib_find_qrcodes(list_t *out, new_image_t *ptr, rectangle_t *roi);
// 1/2D Bar Codes
void imlib_find_qrcodes(list_t *out, image_t *ptr, rectangle_t *roi);
#endif //__IMLIB_H__

View File

@ -2913,44 +2913,42 @@ const char *quirc_strerror(quirc_decode_error_t err)
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
void imlib_find_qrcodes(list_t *out, new_image_t *ptr, rectangle_t *roi)
void imlib_find_qrcodes(list_t *out, image_t *ptr, rectangle_t *roi)
{
struct quirc *controller = quirc_new();
quirc_resize(controller, roi->w, roi->h);
uint8_t *grayscale_image = quirc_begin(controller, NULL, NULL);
int w, h;
uint8_t *grayscale_image = quirc_begin(controller, &w, &h);
switch(ptr->type) {
case IMAGE_TYPE_BINARY: {
for (int y = roi->y, yy = roi->y + h; y < yy; y++) {
switch(ptr->bpp) {
case IMAGE_BPP_BINARY: {
for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) {
uint32_t *row_ptr = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(ptr, y);
for (int x = roi->x, xx = roi->x + w; x < xx; x++) {
for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) {
*(grayscale_image++) = COLOR_BINARY_TO_GRAYSCALE(IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, x));
}
}
break;
}
case IMAGE_TYPE_GRAYSCALE: {
for (int y = roi->y, yy = roi->y + h; y < yy; y++) {
case IMAGE_BPP_GRAYSCALE: {
for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) {
uint8_t *row_ptr = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(ptr, y);
for (int x = roi->x, xx = roi->x + w; x < xx; x++) {
for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) {
*(grayscale_image++) = IMAGE_GET_GRAYSCALE_PIXEL_FAST(row_ptr, x);
}
}
break;
}
case IMAGE_TYPE_RGB565: {
for (int y = roi->y, yy = roi->y + h; y < yy; y++) {
case IMAGE_BPP_RGB565: {
for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) {
uint16_t *row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(ptr, y);
for (int x = roi->x, xx = roi->x + w; x < xx; x++) {
for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) {
*(grayscale_image++) = COLOR_RGB565_TO_GRAYSCALE(IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, x));
}
}
break;
}
default: {
memset(grayscale_image, 0, w * h);
memset(grayscale_image, 0, roi->w * roi->h);
break;
}
}
@ -2967,7 +2965,7 @@ void imlib_find_qrcodes(list_t *out, new_image_t *ptr, rectangle_t *roi)
find_qrcodes_list_lnk_data_t lnk_data;
rectangle_init(&(lnk_data.rect), code->corners[0].x, code->corners[0].y, 0, 0);
for (size_t k = 1; k < (sizeof(code->corners) / sizeof(code->corners[0])); k++) {
for (size_t k = 1, l = (sizeof(code->corners) / sizeof(code->corners[0])); k < l; k++) {
rectangle_t temp;
rectangle_init(&temp, code->corners[k].x, code->corners[k].y, 0, 0);
rectangle_united(&(lnk_data.rect), &temp);

View File

@ -5,10 +5,10 @@
#include "imlib.h"
void imlib_get_histogram(histogram_t *out, new_image_t *ptr, rectangle_t *roi)
void imlib_get_histogram(histogram_t *out, image_t *ptr, rectangle_t *roi)
{
switch(ptr->type) {
case IMAGE_TYPE_BINARY: {
switch(ptr->bpp) {
case IMAGE_BPP_BINARY: {
memset(out->LBins, 0, out->LBinCount * sizeof(uint32_t));
float mult = (out->LBinCount - 1) / ((float) (COLOR_BINARY_MAX - COLOR_BINARY_MIN));
@ -29,7 +29,7 @@ void imlib_get_histogram(histogram_t *out, new_image_t *ptr, rectangle_t *roi)
break;
}
case IMAGE_TYPE_GRAYSCALE: {
case IMAGE_BPP_GRAYSCALE: {
memset(out->LBins, 0, out->LBinCount * sizeof(uint32_t));
float mult = (out->LBinCount - 1) / ((float) (COLOR_GRAYSCALE_MAX - COLOR_GRAYSCALE_MIN));
@ -50,7 +50,7 @@ void imlib_get_histogram(histogram_t *out, new_image_t *ptr, rectangle_t *roi)
break;
}
case IMAGE_TYPE_RGB565: {
case IMAGE_BPP_RGB565: {
memset(out->LBins, 0, out->LBinCount * sizeof(uint32_t));
memset(out->ABins, 0, out->ABinCount * sizeof(uint32_t));
memset(out->BBins, 0, out->BBinCount * sizeof(uint32_t));
@ -91,11 +91,11 @@ void imlib_get_histogram(histogram_t *out, new_image_t *ptr, rectangle_t *roi)
}
}
void imlib_get_percentile(percentile_t *out, new_image_type_t type, histogram_t *ptr, float percentile)
void imlib_get_percentile(percentile_t *out, image_bpp_t bpp, histogram_t *ptr, float percentile)
{
memset(out, 0, sizeof(percentile_t));
switch(type) {
case IMAGE_TYPE_BINARY: {
switch(bpp) {
case IMAGE_BPP_BINARY: {
float mult = (COLOR_BINARY_MAX - COLOR_BINARY_MIN) / ((float) (ptr->LBinCount - 1));
float median_count = 0;
@ -109,7 +109,7 @@ void imlib_get_percentile(percentile_t *out, new_image_type_t type, histogram_t
}
break;
}
case IMAGE_TYPE_GRAYSCALE: {
case IMAGE_BPP_GRAYSCALE: {
float mult = (COLOR_GRAYSCALE_MAX - COLOR_GRAYSCALE_MIN) / ((float) (ptr->LBinCount - 1));
float median_count = 0;
@ -123,7 +123,7 @@ void imlib_get_percentile(percentile_t *out, new_image_type_t type, histogram_t
}
break;
}
case IMAGE_TYPE_RGB565: {
case IMAGE_BPP_RGB565: {
{
float mult = (COLOR_L_MAX - COLOR_L_MIN) / ((float) (ptr->LBinCount - 1));
float median_count = 0;
@ -171,11 +171,11 @@ void imlib_get_percentile(percentile_t *out, new_image_type_t type, histogram_t
}
}
void imlib_get_statistics(statistics_t *out, new_image_type_t type, histogram_t *ptr)
void imlib_get_statistics(statistics_t *out, image_bpp_t bpp, histogram_t *ptr)
{
memset(out, 0, sizeof(statistics_t));
switch(type) {
case IMAGE_TYPE_BINARY: {
switch(bpp) {
case IMAGE_BPP_BINARY: {
float mult = (COLOR_BINARY_MAX - COLOR_BINARY_MIN) / ((float) (ptr->LBinCount - 1));
float avg = 0;
@ -224,7 +224,7 @@ void imlib_get_statistics(statistics_t *out, new_image_type_t type, histogram_t
out->LSTDev = fast_roundf(fast_sqrtf(stdev - (avg * avg)));
break;
}
case IMAGE_TYPE_GRAYSCALE: {
case IMAGE_BPP_GRAYSCALE: {
float mult = (COLOR_GRAYSCALE_MAX - COLOR_GRAYSCALE_MIN) / ((float) (ptr->LBinCount - 1));
float avg = 0;
@ -273,7 +273,7 @@ void imlib_get_statistics(statistics_t *out, new_image_type_t type, histogram_t
out->LSTDev = fast_roundf(fast_sqrtf(stdev - (avg * avg)));
break;
}
case IMAGE_TYPE_RGB565: {
case IMAGE_BPP_RGB565: {
{
float mult = (COLOR_L_MAX - COLOR_L_MIN) / ((float) (ptr->LBinCount - 1));

View File

@ -868,7 +868,7 @@ static mp_obj_t py_image_mask_ellipse(mp_obj_t img_obj)
#define py_histogram_obj_size 6
typedef struct py_histogram_obj {
mp_obj_base_t base;
new_image_type_t type;
image_bpp_t bpp;
mp_obj_t LBinCount, LBins, ABinCount, ABins, BBinCount, BBins;
} py_histogram_obj_t;
@ -876,7 +876,7 @@ typedef struct py_histogram_obj {
#define py_percentile_obj_size 3
typedef struct py_percentile_obj {
mp_obj_base_t base;
new_image_type_t type;
image_bpp_t bpp;
mp_obj_t LValue, AValue, BValue;
} py_percentile_obj_t;
@ -884,27 +884,27 @@ typedef struct py_percentile_obj {
#define py_statistics_obj_size 24
typedef struct py_statistics_obj {
mp_obj_base_t base;
new_image_type_t type;
image_bpp_t bpp;
mp_obj_t LMean, LMedian, LMode, LSTDev, LMin, LMax, LLQ, LUQ, AMean, AMedian, AMode, ASTDev, AMin, AMax, ALQ, AUQ, BMean, BMedian, BMode, BSTDev, BMin, BMax, BLQ, BUQ;
} py_statistics_obj_t;
static void py_histogram_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind)
{
py_histogram_obj_t *self = self_in;
switch(self->type) {
case IMAGE_TYPE_BINARY: {
switch(self->bpp) {
case IMAGE_BPP_BINARY: {
mp_printf(print, "{bin_count:%d, bins:", mp_obj_get_int(self->LBinCount));
mp_obj_print_helper(print, self->LBins, kind);
mp_printf(print, "}");
break;
}
case IMAGE_TYPE_GRAYSCALE: {
case IMAGE_BPP_GRAYSCALE: {
mp_printf(print, "{bin_count:%d, bins:", mp_obj_get_int(self->LBinCount));
mp_obj_print_helper(print, self->LBins, kind);
mp_printf(print, "}");
break;
}
case IMAGE_TYPE_RGB565: {
case IMAGE_BPP_RGB565: {
mp_printf(print, "{l_bin_count:%d, l_bins:", mp_obj_get_int(self->LBinCount));
mp_obj_print_helper(print, self->LBins, kind);
mp_printf(print, ", a_bin_count:%d, a_bins:", mp_obj_get_int(self->ABinCount));
@ -978,13 +978,13 @@ mp_obj_t py_histogram_get_percentile(mp_obj_t self_in, mp_obj_t percentile)
}
percentile_t p;
imlib_get_percentile(&p, ((py_histogram_obj_t *) self_in)->type, &hist, mp_obj_get_float(percentile));
imlib_get_percentile(&p, ((py_histogram_obj_t *) self_in)->bpp, &hist, mp_obj_get_float(percentile));
if (hist.BBinCount) fb_free();
if (hist.ABinCount) fb_free();
if (hist.LBinCount) fb_free();
py_percentile_obj_t *o = m_new_obj(py_percentile_obj_t);
o->type = ((py_histogram_obj_t *) self_in)->type;
o->bpp = ((py_histogram_obj_t *) self_in)->bpp;
o->LValue = mp_obj_new_int(p.LValue);
o->AValue = mp_obj_new_int(p.AValue);
@ -1016,13 +1016,13 @@ mp_obj_t py_histogram_get_statistics(mp_obj_t self_in)
}
statistics_t stats;
imlib_get_statistics(&stats, ((py_histogram_obj_t *) self_in)->type, &hist);
imlib_get_statistics(&stats, ((py_histogram_obj_t *) self_in)->bpp, &hist);
if (hist.BBinCount) fb_free();
if (hist.ABinCount) fb_free();
if (hist.LBinCount) fb_free();
py_statistics_obj_t *o = m_new_obj(py_statistics_obj_t);
o->type = ((py_histogram_obj_t *) self_in)->type;
o->bpp = ((py_histogram_obj_t *) self_in)->bpp;
o->LMean = mp_obj_new_int(stats.LMean);
o->LMedian = mp_obj_new_int(stats.LMedian);
@ -1091,16 +1091,16 @@ static const mp_obj_type_t py_histogram_type = {
static void py_percentile_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind)
{
py_percentile_obj_t *self = self_in;
switch(self->type) {
case IMAGE_TYPE_BINARY: {
switch(self->bpp) {
case IMAGE_BPP_BINARY: {
mp_printf(print, "{value:%d}", mp_obj_get_int(self->LValue));
break;
}
case IMAGE_TYPE_GRAYSCALE: {
case IMAGE_BPP_GRAYSCALE: {
mp_printf(print, "{value:%d}", mp_obj_get_int(self->LValue));
break;
}
case IMAGE_TYPE_RGB565: {
case IMAGE_BPP_RGB565: {
mp_printf(print, "{l_value:%d, a_value:%d, b_value:%d}", mp_obj_get_int(self->LValue), mp_obj_get_int(self->AValue), mp_obj_get_int(self->BValue));
break;
}
@ -1163,8 +1163,8 @@ static const mp_obj_type_t py_percentile_type = {
static void py_statistics_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind)
{
py_statistics_obj_t *self = self_in;
switch(self->type) {
case IMAGE_TYPE_BINARY: {
switch(self->bpp) {
case IMAGE_BPP_BINARY: {
mp_printf(print, "{mean:%d, median:%d, mode:%d, stdev:%d, min:%d, max:%d, lq:%d, uq:%d}",
mp_obj_get_int(self->LMean),
mp_obj_get_int(self->LMedian),
@ -1176,7 +1176,7 @@ static void py_statistics_print(const mp_print_t *print, mp_obj_t self_in, mp_pr
mp_obj_get_int(self->LUQ));
break;
}
case IMAGE_TYPE_GRAYSCALE: {
case IMAGE_BPP_GRAYSCALE: {
mp_printf(print, "{mean:%d, median:%d, mode:%d, stdev:%d, min:%d, max:%d, lq:%d, uq:%d}",
mp_obj_get_int(self->LMean),
mp_obj_get_int(self->LMedian),
@ -1188,7 +1188,7 @@ static void py_statistics_print(const mp_print_t *print, mp_obj_t self_in, mp_pr
mp_obj_get_int(self->LUQ));
break;
}
case IMAGE_TYPE_RGB565: {
case IMAGE_BPP_RGB565: {
mp_printf(print, "{l_mean:%d, l_median:%d, l_mode:%d, l_stdev:%d, l_min:%d, l_max:%d, l_lq:%d, l_uq:%d,"
" a_mean:%d, a_median:%d, a_mode:%d, a_stdev:%d, a_min:%d, a_max:%d, a_lq:%d, a_uq:%d,"
" b_mean:%d, b_median:%d, b_mode:%d, b_stdev:%d, b_min:%d, b_max:%d, b_lq:%d, b_uq:%d}",
@ -1385,19 +1385,13 @@ static mp_obj_t py_image_get_histogram(uint n_args, const mp_obj_t *args, mp_map
PY_ASSERT_FALSE_MSG(IM_IS_JPEG(arg_img),
"Operation not supported on JPEG");
// Transfer to new image type.
new_image_t image;
image_init(&image, (arg_img->bpp == 2) ? IMAGE_TYPE_RGB565 : IMAGE_TYPE_GRAYSCALE, arg_img->w, arg_img->h);
image.size = arg_img->bpp * arg_img->w * arg_img->h;
image.data = arg_img->pixels;
rectangle_t roi;
py_helper_lookup_rectangle(kw_args, arg_img, &roi);
// TODO: Need to set fb_alloc trap here to recover from any exception...
histogram_t hist;
switch(image.type) {
case IMAGE_TYPE_BINARY: {
switch(arg_img->bpp) {
case IMAGE_BPP_BINARY: {
int bin_count = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_bin_count), (COLOR_BINARY_MAX-COLOR_BINARY_MIN+1));
PY_ASSERT_TRUE_MSG(bin_count >= 2, "bin_count must be >= 2");
hist.LBinCount = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_l_bin_count), bin_count);
@ -1407,10 +1401,10 @@ static mp_obj_t py_image_get_histogram(uint n_args, const mp_obj_t *args, mp_map
hist.LBins = fb_alloc(hist.LBinCount * sizeof(float));
hist.ABins = NULL;
hist.BBins = NULL;
imlib_get_histogram(&hist, &image, &roi);
imlib_get_histogram(&hist, arg_img, &roi);
break;
}
case IMAGE_TYPE_GRAYSCALE: {
case IMAGE_BPP_GRAYSCALE: {
int bin_count = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_bin_count), (COLOR_GRAYSCALE_MAX-COLOR_GRAYSCALE_MIN+1));
PY_ASSERT_TRUE_MSG(bin_count >= 2, "bin_count must be >= 2");
hist.LBinCount = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_l_bin_count), bin_count);
@ -1420,10 +1414,10 @@ static mp_obj_t py_image_get_histogram(uint n_args, const mp_obj_t *args, mp_map
hist.LBins = fb_alloc(hist.LBinCount * sizeof(float));
hist.ABins = NULL;
hist.BBins = NULL;
imlib_get_histogram(&hist, &image, &roi);
imlib_get_histogram(&hist, arg_img, &roi);
break;
}
case IMAGE_TYPE_RGB565: {
case IMAGE_BPP_RGB565: {
int l_bin_count = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_bin_count), (COLOR_L_MAX-COLOR_L_MIN+1));
PY_ASSERT_TRUE_MSG(l_bin_count >= 2, "bin_count must be >= 2");
hist.LBinCount = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_l_bin_count), l_bin_count);
@ -1439,7 +1433,7 @@ static mp_obj_t py_image_get_histogram(uint n_args, const mp_obj_t *args, mp_map
hist.LBins = fb_alloc(hist.LBinCount * sizeof(float));
hist.ABins = fb_alloc(hist.ABinCount * sizeof(float));
hist.BBins = fb_alloc(hist.BBinCount * sizeof(float));
imlib_get_histogram(&hist, &image, &roi);
imlib_get_histogram(&hist, arg_img, &roi);
break;
}
default: {
@ -1448,7 +1442,7 @@ static mp_obj_t py_image_get_histogram(uint n_args, const mp_obj_t *args, mp_map
}
py_histogram_obj_t *o = m_new_obj(py_histogram_obj_t);
o->type = image.type;
o->bpp = arg_img->bpp;
o->LBinCount = mp_obj_new_int(hist.LBinCount);
o->LBins = hist.LBinCount ? mp_obj_new_list(hist.LBinCount, NULL) : MP_OBJ_NULL;
@ -1480,19 +1474,13 @@ static mp_obj_t py_image_get_statistics(uint n_args, const mp_obj_t *args, mp_ma
PY_ASSERT_FALSE_MSG(IM_IS_JPEG(arg_img),
"Operation not supported on JPEG");
// Transfer to new image type.
new_image_t image;
image_init(&image, (arg_img->bpp == 2) ? IMAGE_TYPE_RGB565 : IMAGE_TYPE_GRAYSCALE, arg_img->w, arg_img->h);
image.size = arg_img->bpp * arg_img->w * arg_img->h;
image.data = arg_img->pixels;
rectangle_t roi;
py_helper_lookup_rectangle(kw_args, arg_img, &roi);
// TODO: Need to set fb_alloc trap here to recover from any exception...
histogram_t hist;
switch(image.type) {
case IMAGE_TYPE_BINARY: {
switch(arg_img->bpp) {
case IMAGE_BPP_BINARY: {
int bin_count = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_bin_count), (COLOR_BINARY_MAX-COLOR_BINARY_MIN+1));
PY_ASSERT_TRUE_MSG(bin_count >= 2, "bin_count must be >= 2");
hist.LBinCount = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_l_bin_count), bin_count);
@ -1502,10 +1490,10 @@ static mp_obj_t py_image_get_statistics(uint n_args, const mp_obj_t *args, mp_ma
hist.LBins = fb_alloc(hist.LBinCount * sizeof(float));
hist.ABins = NULL;
hist.BBins = NULL;
imlib_get_histogram(&hist, &image, &roi);
imlib_get_histogram(&hist, arg_img, &roi);
break;
}
case IMAGE_TYPE_GRAYSCALE: {
case IMAGE_BPP_GRAYSCALE: {
int bin_count = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_bin_count), (COLOR_GRAYSCALE_MAX-COLOR_GRAYSCALE_MIN+1));
PY_ASSERT_TRUE_MSG(bin_count >= 2, "bin_count must be >= 2");
hist.LBinCount = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_l_bin_count), bin_count);
@ -1515,10 +1503,10 @@ static mp_obj_t py_image_get_statistics(uint n_args, const mp_obj_t *args, mp_ma
hist.LBins = fb_alloc(hist.LBinCount * sizeof(float));
hist.ABins = NULL;
hist.BBins = NULL;
imlib_get_histogram(&hist, &image, &roi);
imlib_get_histogram(&hist, arg_img, &roi);
break;
}
case IMAGE_TYPE_RGB565: {
case IMAGE_BPP_RGB565: {
int l_bin_count = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_bin_count), (COLOR_L_MAX-COLOR_L_MIN+1));
PY_ASSERT_TRUE_MSG(l_bin_count >= 2, "bin_count must be >= 2");
hist.LBinCount = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_l_bin_count), l_bin_count);
@ -1534,7 +1522,7 @@ static mp_obj_t py_image_get_statistics(uint n_args, const mp_obj_t *args, mp_ma
hist.LBins = fb_alloc(hist.LBinCount * sizeof(float));
hist.ABins = fb_alloc(hist.ABinCount * sizeof(float));
hist.BBins = fb_alloc(hist.BBinCount * sizeof(float));
imlib_get_histogram(&hist, &image, &roi);
imlib_get_histogram(&hist, arg_img, &roi);
break;
}
default: {
@ -1543,13 +1531,13 @@ static mp_obj_t py_image_get_statistics(uint n_args, const mp_obj_t *args, mp_ma
}
statistics_t stats;
imlib_get_statistics(&stats, image.type, &hist);
imlib_get_statistics(&stats, arg_img->bpp, &hist);
if (hist.BBinCount) fb_free();
if (hist.ABinCount) fb_free();
if (hist.LBinCount) fb_free();
py_statistics_obj_t *o = m_new_obj(py_statistics_obj_t);
o->type = image.type;
o->bpp = arg_img->bpp;
o->LMean = mp_obj_new_int(stats.LMean);
o->LMedian = mp_obj_new_int(stats.LMedian);
@ -1705,12 +1693,6 @@ static mp_obj_t py_image_find_blobs(uint n_args, const mp_obj_t *args, mp_map_t
PY_ASSERT_FALSE_MSG(IM_IS_JPEG(arg_img),
"Operation not supported on JPEG");
// Transfer to new image type.
new_image_t image;
image_init(&image, (arg_img->bpp == 2) ? IMAGE_TYPE_RGB565 : IMAGE_TYPE_GRAYSCALE, arg_img->w, arg_img->h);
image.size = arg_img->bpp * arg_img->w * arg_img->h;
image.data = arg_img->pixels;
rectangle_t roi;
py_helper_lookup_rectangle(kw_args, arg_img, &roi);
@ -1756,7 +1738,7 @@ static mp_obj_t py_image_find_blobs(uint n_args, const mp_obj_t *args, mp_map_t
// TODO: Need to set fb_alloc trap here to recover from any exception...
list_t out;
imlib_find_blobs(&out, &image, &roi, &thresholds, invert, area_threshold, pixels_threshold, merge, margin);
imlib_find_blobs(&out, arg_img, &roi, &thresholds, invert, area_threshold, pixels_threshold, merge, margin);
list_free(&thresholds);
mp_obj_list_t *objects_list = mp_obj_new_list(list_size(&out), NULL);
@ -1909,18 +1891,12 @@ static mp_obj_t py_image_find_qrcodes(uint n_args, const mp_obj_t *args, mp_map_
PY_ASSERT_FALSE_MSG(IM_IS_JPEG(arg_img),
"Operation not supported on JPEG");
// Transfer to new image type.
new_image_t image;
image_init(&image, (arg_img->bpp == 2) ? IMAGE_TYPE_RGB565 : IMAGE_TYPE_GRAYSCALE, arg_img->w, arg_img->h);
image.size = arg_img->bpp * arg_img->w * arg_img->h;
image.data = arg_img->pixels;
rectangle_t roi;
py_helper_lookup_rectangle(kw_args, arg_img, &roi);
// TODO: Need to set fb_alloc trap here to recover from any exception...
list_t out;
imlib_find_qrcodes(&out, &image, &roi);
imlib_find_qrcodes(&out, arg_img, &roi);
mp_obj_list_t *objects_list = mp_obj_new_list(list_size(&out), NULL);
for (size_t i = 0; list_size(&out); i++) {