mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Avoid using roundf
While this shouldn't happen the method seems to sometimes round up past limits. For example, 1 * 2.0 could be 3 because the 2.0 might be like 2.0000000000001. So, avoid using roundf. There are other methods this needs to be switched out on. But, will do these ones for now. Note that not all roundf values must be removed... just areas where there's a clear limit on the max value returned from roundf.
This commit is contained in:
parent
954431ef52
commit
ca94ffec42
@ -280,17 +280,17 @@ void imlib_draw_string(image_t *img, int x_off, int y_off, const char *str, int
|
||||
|
||||
if ((ch == '\n') || (ch == '\r')) { // handle '\n' or '\r' strings
|
||||
x_off = anchor;
|
||||
y_off += fast_roundf(font[0].h * scale) + y_spacing; // newline height == space height
|
||||
y_off += fast_floorf(font[0].h * scale) + y_spacing; // newline height == space height
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((ch < ' ') || (ch > '~')) { // handle unknown characters
|
||||
imlib_draw_rectangle(img,
|
||||
x_off + (fast_roundf(scale * 3) / 2),
|
||||
y_off + (fast_roundf(scale * 3) / 2),
|
||||
fast_roundf(font[0].w * scale) - ((fast_roundf(scale * 3) / 2) * 2),
|
||||
fast_roundf(font[0].h * scale) - ((fast_roundf(scale * 3) / 2) * 2),
|
||||
c, fast_roundf(scale), false);
|
||||
x_off + (fast_floorf(scale * 3) / 2),
|
||||
y_off + (fast_floorf(scale * 3) / 2),
|
||||
fast_floorf(font[0].w * scale) - ((fast_floorf(scale * 3) / 2) * 2),
|
||||
fast_floorf(font[0].h * scale) - ((fast_floorf(scale * 3) / 2) * 2),
|
||||
c, fast_floorf(scale), false);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -303,7 +303,7 @@ void imlib_draw_string(image_t *img, int x_off, int y_off, const char *str, int
|
||||
for (int x = 0, xx = g->w; x < xx; x++) {
|
||||
for (int y = 0, yy = g->h; y < yy; y++) {
|
||||
if (g->data[y] & (1 << (g->w - 1 - x))) {
|
||||
x_off -= fast_roundf(x * scale);
|
||||
x_off -= fast_floorf(x * scale);
|
||||
exit = true;
|
||||
break;
|
||||
}
|
||||
@ -313,16 +313,16 @@ void imlib_draw_string(image_t *img, int x_off, int y_off, const char *str, int
|
||||
}
|
||||
}
|
||||
|
||||
for (int y = 0, yy = fast_roundf(g->h * scale); y < yy; y++) {
|
||||
for (int x = 0, xx = fast_roundf(g->w * scale); x < xx; x++) {
|
||||
if (g->data[fast_roundf(y / scale)] & (1 << (g->w - 1 - fast_roundf(x / scale)))) {
|
||||
for (int y = 0, yy = fast_floorf(g->h * scale); y < yy; y++) {
|
||||
for (int x = 0, xx = fast_floorf(g->w * scale); x < xx; x++) {
|
||||
if (g->data[fast_floorf(y / scale)] & (1 << (g->w - 1 - fast_floorf(x / scale)))) {
|
||||
imlib_set_pixel(img, (x_off + x), (y_off + y), c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mono_space) {
|
||||
x_off += fast_roundf(g->w * scale) + x_spacing;
|
||||
x_off += fast_floorf(g->w * scale) + x_spacing;
|
||||
} else {
|
||||
// Find the last pixel set and offset to that.
|
||||
bool exit = false;
|
||||
@ -330,7 +330,7 @@ void imlib_draw_string(image_t *img, int x_off, int y_off, const char *str, int
|
||||
for (int x = g->w - 1; x >= 0; x--) {
|
||||
for (int y = g->h - 1; y >= 0; y--) {
|
||||
if (g->data[y] & (1 << (g->w - 1 - x))) {
|
||||
x_off += fast_roundf((x + 2) * scale) + x_spacing;
|
||||
x_off += fast_floorf((x + 2) * scale) + x_spacing;
|
||||
exit = true;
|
||||
break;
|
||||
}
|
||||
@ -339,7 +339,7 @@ void imlib_draw_string(image_t *img, int x_off, int y_off, const char *str, int
|
||||
if (exit) break;
|
||||
}
|
||||
|
||||
if (!exit) x_off += fast_roundf(scale * 3); // space char
|
||||
if (!exit) x_off += fast_floorf(scale * 3); // space char
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -405,11 +405,11 @@ void imlib_draw_image(image_t *img, image_t *other, int x_off, int y_off, float
|
||||
{
|
||||
float over_xscale = IM_DIV(1.0, x_scale), over_yscale = IM_DIV(1.0f, y_scale), beta = 1 - alpha;
|
||||
|
||||
for (int y = 0, yy = fast_roundf(other->h * y_scale); y < yy; y++) {
|
||||
int other_y = fast_roundf(y * over_yscale);
|
||||
for (int y = 0, yy = fast_floorf(other->h * y_scale); y < yy; y++) {
|
||||
int other_y = fast_floorf(y * over_yscale);
|
||||
|
||||
for (int x = 0, xx = fast_roundf(other->w * x_scale); x < xx; x++) {
|
||||
int other_x = fast_roundf(x * over_xscale);
|
||||
for (int x = 0, xx = fast_floorf(other->w * x_scale); x < xx; x++) {
|
||||
int other_x = fast_floorf(x * over_xscale);
|
||||
|
||||
if ((!mask) || image_get_mask_pixel(mask, other_x, other_y)) {
|
||||
int pixel = safe_map_pixel(img, other, imlib_get_pixel(other, other_x, other_y));
|
||||
@ -446,22 +446,22 @@ void imlib_flood_fill(image_t *img, int x, int y,
|
||||
|
||||
switch(img->bpp) {
|
||||
case IMAGE_BPP_BINARY: {
|
||||
color_seed_threshold = fast_roundf(seed_threshold * COLOR_BINARY_MAX);
|
||||
color_floating_threshold = fast_roundf(floating_threshold * COLOR_BINARY_MAX);
|
||||
color_seed_threshold = fast_floorf(seed_threshold * COLOR_BINARY_MAX);
|
||||
color_floating_threshold = fast_floorf(floating_threshold * COLOR_BINARY_MAX);
|
||||
break;
|
||||
}
|
||||
case IMAGE_BPP_GRAYSCALE: {
|
||||
color_seed_threshold = fast_roundf(seed_threshold * COLOR_GRAYSCALE_MAX);
|
||||
color_floating_threshold = fast_roundf(floating_threshold * COLOR_GRAYSCALE_MAX);
|
||||
color_seed_threshold = fast_floorf(seed_threshold * COLOR_GRAYSCALE_MAX);
|
||||
color_floating_threshold = fast_floorf(floating_threshold * COLOR_GRAYSCALE_MAX);
|
||||
break;
|
||||
}
|
||||
case IMAGE_BPP_RGB565: {
|
||||
color_seed_threshold = COLOR_R5_G6_B5_TO_RGB565(fast_roundf(seed_threshold * COLOR_R5_MAX),
|
||||
fast_roundf(seed_threshold * COLOR_G6_MAX),
|
||||
fast_roundf(seed_threshold * COLOR_B5_MAX));
|
||||
color_floating_threshold = COLOR_R5_G6_B5_TO_RGB565(fast_roundf(floating_threshold * COLOR_R5_MAX),
|
||||
fast_roundf(floating_threshold * COLOR_G6_MAX),
|
||||
fast_roundf(floating_threshold * COLOR_B5_MAX));
|
||||
color_seed_threshold = COLOR_R5_G6_B5_TO_RGB565(fast_floorf(seed_threshold * COLOR_R5_MAX),
|
||||
fast_floorf(seed_threshold * COLOR_G6_MAX),
|
||||
fast_floorf(seed_threshold * COLOR_B5_MAX));
|
||||
color_floating_threshold = COLOR_R5_G6_B5_TO_RGB565(fast_floorf(floating_threshold * COLOR_R5_MAX),
|
||||
fast_floorf(floating_threshold * COLOR_G6_MAX),
|
||||
fast_floorf(floating_threshold * COLOR_B5_MAX));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
||||
@ -32,7 +32,7 @@ void imlib_histeq(image_t *img, image_t *mask)
|
||||
if (mask && (!image_get_mask_pixel(mask, x, y))) continue;
|
||||
int pixel = IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, x);
|
||||
IMAGE_PUT_BINARY_PIXEL_FAST(row_ptr, x,
|
||||
fast_roundf((s * hist[pixel - COLOR_BINARY_MIN]) + COLOR_BINARY_MIN));
|
||||
fast_floorf((s * hist[pixel - COLOR_BINARY_MIN]) + COLOR_BINARY_MIN));
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ void imlib_histeq(image_t *img, image_t *mask)
|
||||
if (mask && (!image_get_mask_pixel(mask, x, y))) continue;
|
||||
int pixel = IMAGE_GET_GRAYSCALE_PIXEL_FAST(row_ptr, x);
|
||||
IMAGE_PUT_GRAYSCALE_PIXEL_FAST(row_ptr, x,
|
||||
fast_roundf((s * hist[pixel - COLOR_GRAYSCALE_MIN]) + COLOR_GRAYSCALE_MIN));
|
||||
fast_floorf((s * hist[pixel - COLOR_GRAYSCALE_MIN]) + COLOR_GRAYSCALE_MIN));
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ void imlib_histeq(image_t *img, image_t *mask)
|
||||
if (mask && (!image_get_mask_pixel(mask, x, y))) continue;
|
||||
int pixel = IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, x);
|
||||
IMAGE_PUT_RGB565_PIXEL_FAST(row_ptr, x,
|
||||
imlib_yuv_to_rgb(fast_roundf(s * hist[COLOR_RGB565_TO_Y(pixel) - COLOR_Y_MIN]),
|
||||
imlib_yuv_to_rgb(fast_floorf(s * hist[COLOR_RGB565_TO_Y(pixel) - COLOR_Y_MIN]),
|
||||
COLOR_RGB565_TO_U(pixel),
|
||||
COLOR_RGB565_TO_V(pixel)));
|
||||
}
|
||||
@ -149,7 +149,7 @@ void imlib_mean_filter(image_t *img, const int ksize, bool threshold, int offset
|
||||
}
|
||||
}
|
||||
|
||||
int pixel = fast_roundf(acc * over_n);
|
||||
int pixel = fast_floorf(acc * over_n);
|
||||
|
||||
if (threshold) {
|
||||
if (((pixel - offset) < IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, x)) ^ invert) {
|
||||
@ -204,7 +204,7 @@ void imlib_mean_filter(image_t *img, const int ksize, bool threshold, int offset
|
||||
}
|
||||
}
|
||||
|
||||
int pixel = fast_roundf(acc * over_n);
|
||||
int pixel = fast_floorf(acc * over_n);
|
||||
|
||||
if (threshold) {
|
||||
if (((pixel - offset) < IMAGE_GET_GRAYSCALE_PIXEL_FAST(row_ptr, x)) ^ invert) {
|
||||
@ -262,9 +262,9 @@ void imlib_mean_filter(image_t *img, const int ksize, bool threshold, int offset
|
||||
}
|
||||
}
|
||||
|
||||
int pixel = COLOR_R5_G6_B5_TO_RGB565(fast_roundf(r_acc * over_n),
|
||||
fast_roundf(g_acc * over_n),
|
||||
fast_roundf(b_acc * over_n));
|
||||
int pixel = COLOR_R5_G6_B5_TO_RGB565(fast_floorf(r_acc * over_n),
|
||||
fast_floorf(g_acc * over_n),
|
||||
fast_floorf(b_acc * over_n));
|
||||
|
||||
if (threshold) {
|
||||
if (((COLOR_RGB565_TO_Y(pixel) - offset) < COLOR_RGB565_TO_Y(IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, x))) ^ invert) {
|
||||
@ -310,7 +310,7 @@ void imlib_median_filter(image_t *img, const int ksize, float percentile, bool t
|
||||
buf.h = brows;
|
||||
buf.bpp = img->bpp;
|
||||
|
||||
int n = ((ksize*2)+1)*((ksize*2)+1), int_percentile = fast_roundf(percentile * (n - 1));
|
||||
int n = ((ksize*2)+1)*((ksize*2)+1), int_percentile = fast_floorf(percentile * (n - 1));
|
||||
|
||||
switch(img->bpp) {
|
||||
case IMAGE_BPP_BINARY: {
|
||||
@ -782,7 +782,7 @@ void imlib_midpoint_filter(image_t *img, const int ksize, float bias, bool thres
|
||||
}
|
||||
}
|
||||
|
||||
int pixel = fast_roundf((min*min_bias)+(max*max_bias));
|
||||
int pixel = fast_floorf((min*min_bias)+(max*max_bias));
|
||||
|
||||
if (threshold) {
|
||||
if (((pixel - offset) < IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, x)) ^ invert) {
|
||||
@ -839,7 +839,7 @@ void imlib_midpoint_filter(image_t *img, const int ksize, float bias, bool thres
|
||||
}
|
||||
}
|
||||
|
||||
int pixel = fast_roundf((min*min_bias)+(max*max_bias));
|
||||
int pixel = fast_floorf((min*min_bias)+(max*max_bias));
|
||||
|
||||
if (threshold) {
|
||||
if (((pixel - offset) < IMAGE_GET_GRAYSCALE_PIXEL_FAST(row_ptr, x)) ^ invert) {
|
||||
@ -905,9 +905,9 @@ void imlib_midpoint_filter(image_t *img, const int ksize, float bias, bool thres
|
||||
}
|
||||
}
|
||||
|
||||
int pixel = COLOR_R5_G6_B5_TO_RGB565(fast_roundf((r_min*min_bias)+(r_max*max_bias)),
|
||||
fast_roundf((g_min*min_bias)+(g_max*max_bias)),
|
||||
fast_roundf((b_min*min_bias)+(b_max*max_bias)));
|
||||
int pixel = COLOR_R5_G6_B5_TO_RGB565(fast_floorf((r_min*min_bias)+(r_max*max_bias)),
|
||||
fast_floorf((g_min*min_bias)+(g_max*max_bias)),
|
||||
fast_floorf((b_min*min_bias)+(b_max*max_bias)));
|
||||
|
||||
if (threshold) {
|
||||
if (((COLOR_RGB565_TO_Y(pixel) - offset) < COLOR_RGB565_TO_Y(IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, x))) ^ invert) {
|
||||
@ -980,7 +980,7 @@ void imlib_morph(image_t *img, const int ksize, const int *krn, const float m, c
|
||||
}
|
||||
}
|
||||
|
||||
int pixel = IM_MAX(IM_MIN(fast_roundf(acc * m) + b, COLOR_BINARY_MAX), COLOR_BINARY_MIN);
|
||||
int pixel = IM_MAX(IM_MIN(fast_floorf(acc * m) + b, COLOR_BINARY_MAX), COLOR_BINARY_MIN);
|
||||
|
||||
if (threshold) {
|
||||
if (((pixel - offset) < IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, x)) ^ invert) {
|
||||
@ -1035,7 +1035,7 @@ void imlib_morph(image_t *img, const int ksize, const int *krn, const float m, c
|
||||
}
|
||||
}
|
||||
|
||||
int pixel = IM_MAX(IM_MIN(fast_roundf(acc * m) + b, COLOR_GRAYSCALE_MAX), COLOR_GRAYSCALE_MIN);
|
||||
int pixel = IM_MAX(IM_MIN(fast_floorf(acc * m) + b, COLOR_GRAYSCALE_MAX), COLOR_GRAYSCALE_MIN);
|
||||
|
||||
if (threshold) {
|
||||
if (((pixel - offset) < IMAGE_GET_GRAYSCALE_PIXEL_FAST(row_ptr, x)) ^ invert) {
|
||||
@ -1093,9 +1093,9 @@ void imlib_morph(image_t *img, const int ksize, const int *krn, const float m, c
|
||||
}
|
||||
}
|
||||
|
||||
int pixel = COLOR_R5_G6_B5_TO_RGB565(IM_MAX(IM_MIN(fast_roundf(r_acc * m) + b, COLOR_R5_MAX), COLOR_R5_MIN),
|
||||
IM_MAX(IM_MIN(fast_roundf(g_acc * m) + b, COLOR_G6_MAX), COLOR_G6_MIN),
|
||||
IM_MAX(IM_MIN(fast_roundf(b_acc * m) + b, COLOR_B5_MAX), COLOR_B5_MIN));
|
||||
int pixel = COLOR_R5_G6_B5_TO_RGB565(IM_MAX(IM_MIN(fast_floorf(r_acc * m) + b, COLOR_R5_MAX), COLOR_R5_MIN),
|
||||
IM_MAX(IM_MIN(fast_floorf(g_acc * m) + b, COLOR_G6_MAX), COLOR_G6_MIN),
|
||||
IM_MAX(IM_MIN(fast_floorf(b_acc * m) + b, COLOR_B5_MAX), COLOR_B5_MIN));
|
||||
|
||||
if (threshold) {
|
||||
if (((COLOR_RGB565_TO_Y(pixel) - offset) < COLOR_RGB565_TO_Y(IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, x))) ^ invert) {
|
||||
@ -1196,7 +1196,7 @@ void imlib_bilateral_filter(image_t *img, const int ksize, float color_sigma, fl
|
||||
}
|
||||
}
|
||||
|
||||
int pixel = fast_roundf(IM_MIN(IM_DIV(i_acc, w_acc), COLOR_BINARY_MAX));
|
||||
int pixel = fast_floorf(IM_MIN(IM_DIV(i_acc, w_acc), COLOR_BINARY_MAX));
|
||||
|
||||
if (threshold) {
|
||||
if (((pixel - offset) < IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, x)) ^ invert) {
|
||||
@ -1273,7 +1273,7 @@ void imlib_bilateral_filter(image_t *img, const int ksize, float color_sigma, fl
|
||||
}
|
||||
}
|
||||
|
||||
int pixel = fast_roundf(IM_MIN(IM_DIV(i_acc, w_acc), COLOR_GRAYSCALE_MAX));
|
||||
int pixel = fast_floorf(IM_MIN(IM_DIV(i_acc, w_acc), COLOR_GRAYSCALE_MAX));
|
||||
|
||||
if (threshold) {
|
||||
if (((pixel - offset) < IMAGE_GET_GRAYSCALE_PIXEL_FAST(row_ptr, x)) ^ invert) {
|
||||
@ -1377,9 +1377,9 @@ void imlib_bilateral_filter(image_t *img, const int ksize, float color_sigma, fl
|
||||
}
|
||||
}
|
||||
|
||||
int pixel = COLOR_R5_G6_B5_TO_RGB565(fast_roundf(IM_MIN(IM_DIV(r_i_acc, r_w_acc), COLOR_R5_MAX)),
|
||||
fast_roundf(IM_MIN(IM_DIV(g_i_acc, g_w_acc), COLOR_G6_MAX)),
|
||||
fast_roundf(IM_MIN(IM_DIV(b_i_acc, b_w_acc), COLOR_B5_MAX)));
|
||||
int pixel = COLOR_R5_G6_B5_TO_RGB565(fast_floorf(IM_MIN(IM_DIV(r_i_acc, r_w_acc), COLOR_R5_MAX)),
|
||||
fast_floorf(IM_MIN(IM_DIV(g_i_acc, g_w_acc), COLOR_G6_MAX)),
|
||||
fast_floorf(IM_MIN(IM_DIV(b_i_acc, b_w_acc), COLOR_B5_MAX)));
|
||||
|
||||
if (threshold) {
|
||||
if (((COLOR_RGB565_TO_Y(pixel) - offset) < COLOR_RGB565_TO_Y(IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, x))) ^ invert) {
|
||||
@ -1527,22 +1527,22 @@ void imlib_cartoon_filter(image_t *img, float seed_threshold, float floating_thr
|
||||
|
||||
switch(img->bpp) {
|
||||
case IMAGE_BPP_BINARY: {
|
||||
color_seed_threshold = fast_roundf(seed_threshold * COLOR_BINARY_MAX);
|
||||
color_floating_threshold = fast_roundf(floating_threshold * COLOR_BINARY_MAX);
|
||||
color_seed_threshold = fast_floorf(seed_threshold * COLOR_BINARY_MAX);
|
||||
color_floating_threshold = fast_floorf(floating_threshold * COLOR_BINARY_MAX);
|
||||
break;
|
||||
}
|
||||
case IMAGE_BPP_GRAYSCALE: {
|
||||
color_seed_threshold = fast_roundf(seed_threshold * COLOR_GRAYSCALE_MAX);
|
||||
color_floating_threshold = fast_roundf(floating_threshold * COLOR_GRAYSCALE_MAX);
|
||||
color_seed_threshold = fast_floorf(seed_threshold * COLOR_GRAYSCALE_MAX);
|
||||
color_floating_threshold = fast_floorf(floating_threshold * COLOR_GRAYSCALE_MAX);
|
||||
break;
|
||||
}
|
||||
case IMAGE_BPP_RGB565: {
|
||||
color_seed_threshold = COLOR_R5_G6_B5_TO_RGB565(fast_roundf(seed_threshold * COLOR_R5_MAX),
|
||||
fast_roundf(seed_threshold * COLOR_G6_MAX),
|
||||
fast_roundf(seed_threshold * COLOR_B5_MAX));
|
||||
color_floating_threshold = COLOR_R5_G6_B5_TO_RGB565(fast_roundf(floating_threshold * COLOR_R5_MAX),
|
||||
fast_roundf(floating_threshold * COLOR_G6_MAX),
|
||||
fast_roundf(floating_threshold * COLOR_B5_MAX));
|
||||
color_seed_threshold = COLOR_R5_G6_B5_TO_RGB565(fast_floorf(seed_threshold * COLOR_R5_MAX),
|
||||
fast_floorf(seed_threshold * COLOR_G6_MAX),
|
||||
fast_floorf(seed_threshold * COLOR_B5_MAX));
|
||||
color_floating_threshold = COLOR_R5_G6_B5_TO_RGB565(fast_floorf(floating_threshold * COLOR_R5_MAX),
|
||||
fast_floorf(floating_threshold * COLOR_G6_MAX),
|
||||
fast_floorf(floating_threshold * COLOR_B5_MAX));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
||||
@ -314,7 +314,7 @@ int8_t imlib_rgb565_to_l(uint16_t pixel)
|
||||
|
||||
y = (y>0.008856f) ? fast_cbrtf(y) : ((y * 7.787037f) + 0.137931f);
|
||||
|
||||
return fast_roundf(116 * y) - 16;
|
||||
return fast_floorf(116 * y) - 16;
|
||||
}
|
||||
|
||||
int8_t imlib_rgb565_to_a(uint16_t pixel)
|
||||
@ -329,7 +329,7 @@ int8_t imlib_rgb565_to_a(uint16_t pixel)
|
||||
x = (x>0.008856f) ? fast_cbrtf(x) : ((x * 7.787037f) + 0.137931f);
|
||||
y = (y>0.008856f) ? fast_cbrtf(y) : ((y * 7.787037f) + 0.137931f);
|
||||
|
||||
return fast_roundf(500 * (x-y));
|
||||
return fast_floorf(500 * (x-y));
|
||||
}
|
||||
|
||||
int8_t imlib_rgb565_to_b(uint16_t pixel)
|
||||
@ -344,7 +344,7 @@ int8_t imlib_rgb565_to_b(uint16_t pixel)
|
||||
y = (y>0.008856f) ? fast_cbrtf(y) : ((y * 7.787037f) + 0.137931f);
|
||||
z = (z>0.008856f) ? fast_cbrtf(z) : ((z * 7.787037f) + 0.137931f);
|
||||
|
||||
return fast_roundf(200 * (y-z));
|
||||
return fast_floorf(200 * (y-z));
|
||||
}
|
||||
|
||||
int8_t imlib_rgb565_to_y(uint16_t pixel)
|
||||
@ -394,9 +394,9 @@ uint16_t imlib_lab_to_rgb(uint8_t l, int8_t a, int8_t b)
|
||||
g_lin = (g_lin>0.0031308f) ? ((1.055f*powf(g_lin, 0.416666f))-0.055f) : (g_lin*12.92f);
|
||||
b_lin = (b_lin>0.0031308f) ? ((1.055f*powf(b_lin, 0.416666f))-0.055f) : (b_lin*12.92f);
|
||||
|
||||
uint32_t red = IM_MAX(IM_MIN(fast_roundf(r_lin * COLOR_R8_MAX), COLOR_R8_MAX), COLOR_R8_MIN);
|
||||
uint32_t green = IM_MAX(IM_MIN(fast_roundf(g_lin * COLOR_G8_MAX), COLOR_G8_MAX), COLOR_G8_MIN);
|
||||
uint32_t blue = IM_MAX(IM_MIN(fast_roundf(b_lin * COLOR_B8_MAX), COLOR_B8_MAX), COLOR_B8_MIN);
|
||||
uint32_t red = IM_MAX(IM_MIN(fast_floorf(r_lin * COLOR_R8_MAX), COLOR_R8_MAX), COLOR_R8_MIN);
|
||||
uint32_t green = IM_MAX(IM_MIN(fast_floorf(g_lin * COLOR_G8_MAX), COLOR_G8_MAX), COLOR_G8_MIN);
|
||||
uint32_t blue = IM_MAX(IM_MIN(fast_floorf(b_lin * COLOR_B8_MAX), COLOR_B8_MAX), COLOR_B8_MIN);
|
||||
|
||||
return COLOR_R8_G8_B8_TO_RGB565(red, green, blue);
|
||||
}
|
||||
@ -826,8 +826,8 @@ void imlib_lens_corr(image_t *img, float strength, float zoom)
|
||||
|
||||
float r = lens_corr_radius * fast_sqrtf(newX2 + newY2);
|
||||
float theta = (r < 0.0000001f) ? 1.0f : (fast_atanf(r) / r);
|
||||
int sourceX = halfWidth + fast_roundf(theta * zoomedX);
|
||||
int sourceY = halfHeight + fast_roundf(theta * zoomedY);
|
||||
int sourceX = halfWidth + fast_floorf(theta * zoomedX);
|
||||
int sourceY = halfHeight + fast_floorf(theta * zoomedY);
|
||||
|
||||
if ((0 <= sourceX) && (sourceX < img->w) && (0 <= sourceY) && (sourceY < img->h)) {
|
||||
uint32_t *ptr = tmp + (((img->w + UINT32_T_MASK) >> UINT32_T_SHIFT) * sourceY);
|
||||
@ -859,8 +859,8 @@ void imlib_lens_corr(image_t *img, float strength, float zoom)
|
||||
|
||||
float r = lens_corr_radius * fast_sqrtf(newX2 + newY2);
|
||||
float theta = (r < 0.0000001f) ? 1.0f : (fast_atanf(r) / r);
|
||||
int sourceX = halfWidth + fast_roundf(theta * zoomedX);
|
||||
int sourceY = halfHeight + fast_roundf(theta * zoomedY);
|
||||
int sourceX = halfWidth + fast_floorf(theta * zoomedX);
|
||||
int sourceY = halfHeight + fast_floorf(theta * zoomedY);
|
||||
|
||||
if ((0 <= sourceX) && (sourceX < img->w) && (0 <= sourceY) && (sourceY < img->h)) {
|
||||
uint8_t *ptr = tmp + (img->w * sourceY);
|
||||
@ -892,8 +892,8 @@ void imlib_lens_corr(image_t *img, float strength, float zoom)
|
||||
|
||||
float r = lens_corr_radius * fast_sqrtf(newX2 + newY2);
|
||||
float theta = (r < 0.0000001f) ? 1.0f : (fast_atanf(r) / r);
|
||||
int sourceX = halfWidth + fast_roundf(theta * zoomedX);
|
||||
int sourceY = halfHeight + fast_roundf(theta * zoomedY);
|
||||
int sourceX = halfWidth + fast_floorf(theta * zoomedX);
|
||||
int sourceY = halfHeight + fast_floorf(theta * zoomedY);
|
||||
|
||||
if ((0 <= sourceX) && (sourceX < img->w) && (0 <= sourceY) && (sourceY < img->h)) {
|
||||
uint16_t *ptr = tmp + (img->w * sourceY);
|
||||
|
||||
@ -1430,9 +1430,9 @@ static mp_obj_t py_image_copy_int(uint n_args, const mp_obj_t *args, mp_map_t *k
|
||||
}
|
||||
|
||||
image_t image;
|
||||
image.w = fast_roundf(roi.w * arg_x_scale);
|
||||
image.w = fast_floorf(roi.w * arg_x_scale);
|
||||
PY_ASSERT_TRUE_MSG(image.w >= 1, "Output image width is 0!");
|
||||
image.h = fast_roundf(roi.h * arg_y_scale);
|
||||
image.h = fast_floorf(roi.h * arg_y_scale);
|
||||
PY_ASSERT_TRUE_MSG(image.h >= 1, "Output image height is 0!");
|
||||
image.bpp = arg_img->bpp;
|
||||
image.data = NULL;
|
||||
@ -1478,33 +1478,33 @@ static mp_obj_t py_image_copy_int(uint n_args, const mp_obj_t *args, mp_map_t *k
|
||||
switch(arg_img->bpp) {
|
||||
case IMAGE_BPP_BINARY: {
|
||||
for (int y = 0, yy = image.h; y < yy; y++) {
|
||||
uint32_t *row_ptr = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(arg_img, fast_roundf(y * over_yscale) + roi.y);
|
||||
uint32_t *row_ptr = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(arg_img, fast_floorf(y * over_yscale) + roi.y);
|
||||
uint32_t *row_ptr_2 = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(&image, y);
|
||||
for (int x = 0, xx = image.w; x < xx; x++) {
|
||||
IMAGE_PUT_BINARY_PIXEL_FAST(row_ptr_2, x,
|
||||
IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, fast_roundf(x * over_xscale) + roi.x));
|
||||
IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, fast_floorf(x * over_xscale) + roi.x));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IMAGE_BPP_GRAYSCALE: {
|
||||
for (int y = 0, yy = image.h; y < yy; y++) {
|
||||
uint8_t *row_ptr = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(arg_img, fast_roundf(y * over_yscale) + roi.y);
|
||||
uint8_t *row_ptr = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(arg_img, fast_floorf(y * over_yscale) + roi.y);
|
||||
uint8_t *row_ptr_2 = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(&image, y);
|
||||
for (int x = 0, xx = image.w; x < xx; x++) {
|
||||
IMAGE_PUT_GRAYSCALE_PIXEL_FAST(row_ptr_2, x,
|
||||
IMAGE_GET_GRAYSCALE_PIXEL_FAST(row_ptr, fast_roundf(x * over_xscale) + roi.x));
|
||||
IMAGE_GET_GRAYSCALE_PIXEL_FAST(row_ptr, fast_floorf(x * over_xscale) + roi.x));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IMAGE_BPP_RGB565: {
|
||||
for (int y = 0, yy = image.h; y < yy; y++) {
|
||||
uint16_t *row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(arg_img, fast_roundf(y * over_yscale) + roi.y);
|
||||
uint16_t *row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(arg_img, fast_floorf(y * over_yscale) + roi.y);
|
||||
uint16_t *row_ptr_2 = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(&image, y);
|
||||
for (int x = 0, xx = image.w; x < xx; x++) {
|
||||
IMAGE_PUT_RGB565_PIXEL_FAST(row_ptr_2, x,
|
||||
IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, fast_roundf(x * over_xscale) + roi.x));
|
||||
IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, fast_floorf(x * over_xscale) + roi.x));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user