Merge pull request #2486 from kwagyeman/kwabena/update_alpha

imlib: Update draw_image alpha to 0-255 from 0-256.
This commit is contained in:
Ibrahim Abdelkader 2024-11-14 10:12:54 +02:00 committed by GitHub
commit b4b3243028
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
25 changed files with 90 additions and 87 deletions

View File

@ -46,7 +46,7 @@ big_img.draw_image(small_img, 0, 0, x_scale=32, y_scale=32, hint=hint)
alpha_div = 1
alpha_value = 0
alpha_step = 2
alpha_step = 3
x_bounce = sensor.width() // 2
x_bounce_toggle = 1
@ -79,7 +79,7 @@ while True:
y_bounce_toggle = -y_bounce_toggle
alpha_value += alpha_step
if not alpha_value or alpha_value // alpha_div == 256:
if not alpha_value or alpha_value // alpha_div >= 255:
alpha_step = -alpha_step
print(clock.fps())

View File

@ -56,7 +56,7 @@ big_img.draw_image(small_img, 0, 0, x_scale=32, y_scale=32, hint=hint)
alpha_div = 1
alpha_value = 0
alpha_step = 2
alpha_step = 3
x_bounce = sensor.width() // 2
x_bounce_toggle = 1
@ -90,7 +90,7 @@ while True:
y_bounce_toggle = -y_bounce_toggle
alpha_value += alpha_step
if not alpha_value or alpha_value // alpha_div == 256:
if not alpha_value or alpha_value // alpha_div >= 255:
alpha_step = -alpha_step
print(clock.fps())

View File

@ -50,7 +50,7 @@ for i in range(256):
alpha_div = 1
alpha_value = 0
alpha_step = 2
alpha_step = 3
x_bounce = sensor.width() // 2
x_bounce_toggle = 1
@ -84,7 +84,7 @@ while True:
y_bounce_toggle = -y_bounce_toggle
alpha_value += alpha_step
if not alpha_value or alpha_value // alpha_div == 256:
if not alpha_value or alpha_value // alpha_div >= 255:
alpha_step = -alpha_step
print(clock.fps())

View File

@ -60,7 +60,7 @@ for i in range(256):
alpha_div = 1
alpha_value = 0
alpha_step = 2
alpha_step = 3
x_bounce = sensor.width() // 2
x_bounce_toggle = 1
@ -95,7 +95,7 @@ while True:
y_bounce_toggle = -y_bounce_toggle
alpha_value += alpha_step
if not alpha_value or alpha_value // alpha_div == 256:
if not alpha_value or alpha_value // alpha_div >= 255:
alpha_step = -alpha_step
print(clock.fps())

View File

@ -14,7 +14,7 @@ import time
TRIGGER_THRESHOLD = 5
BG_UPDATE_FRAMES = 50 # How many frames before blending.
BG_UPDATE_BLEND = 128 # How much to blend by... ([0-256]==[0.0-1.0]).
BG_UPDATE_BLEND = 128 # How much to blend by... ([0-255]==[0.0-1.0]).
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.RGB565
@ -44,15 +44,15 @@ while True:
img = sensor.snapshot() # Take a picture and return the image.
frame_count += 1
if frame_count > BG_UPDATE_FRAMES and not triggered:
if frame_count > BG_UPDATE_FRAMES:
frame_count = 0
# Blend in new frame. We're doing 256-alpha here because we want to
# Blend in new frame. We're doing 255-alpha here because we want to
# blend the new frame into the background. Not the background into the
# new frame which would be just alpha. Blend replaces each pixel by
# ((NEW*(alpha))+(OLD*(256-alpha)))/256. So, a low alpha results in
# ((NEW*(alpha))+(OLD*(255-alpha)))/255. So, a low alpha results in
# low blending of the new image while a high alpha results in high
# blending of the new image. We need to reverse that for this update.
img.blend(extra_fb, alpha=(256 - BG_UPDATE_BLEND))
img.blend(extra_fb, alpha=(255 - BG_UPDATE_BLEND))
extra_fb.replace(img)
# Replace the image with the "abs(NEW-OLD)" frame difference.

View File

@ -17,7 +17,7 @@ import time
TRIGGER_THRESHOLD = 5
BG_UPDATE_FRAMES = 50 # How many frames before blending.
BG_UPDATE_BLEND = 128 # How much to blend by... ([0-256]==[0.0-1.0]).
BG_UPDATE_BLEND = 128 # How much to blend by... ([0-255]==[0.0-1.0]).
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.RGB565
@ -42,15 +42,15 @@ while True:
img = sensor.snapshot() # Take a picture and return the image.
frame_count += 1
if frame_count > BG_UPDATE_FRAMES and not triggered:
if frame_count > BG_UPDATE_FRAMES:
frame_count = 0
# Blend in new frame. We're doing 256-alpha here because we want to
# Blend in new frame. We're doing 255-alpha here because we want to
# blend the new frame into the background. Not the background into the
# new frame which would be just alpha. Blend replaces each pixel by
# ((NEW*(alpha))+(OLD*(256-alpha)))/256. So, a low alpha results in
# ((NEW*(alpha))+(OLD*(255-alpha)))/255. So, a low alpha results in
# low blending of the new image while a high alpha results in high
# blending of the new image. We need to reverse that for this update.
img.blend("temp/bg.bmp", alpha=(256 - BG_UPDATE_BLEND))
img.blend("temp/bg.bmp", alpha=(255 - BG_UPDATE_BLEND))
img.save("temp/bg.bmp")
# Replace the image with the "abs(NEW-OLD)" frame difference.

View File

@ -53,7 +53,7 @@ while True:
else:
# Create a secondary image and then blend into the frame buffer.
extra_fb.clear()
fir.draw_ir(extra_fb, ir, alpha=256, hint=drawing_hint)
fir.draw_ir(extra_fb, ir, hint=drawing_hint)
img.blend(extra_fb, alpha=128)
# Draw ambient, min and max temperatures.

View File

@ -57,7 +57,7 @@ while True:
else:
# Create a secondary image and then blend into the frame buffer.
extra_fb.clear()
fir.draw_ir(extra_fb, ir, alpha=256, hint=drawing_hint)
fir.draw_ir(extra_fb, ir, hint=drawing_hint)
img.blend(extra_fb, alpha=128)
# Draw ambient, min and max temperatures.

View File

@ -32,7 +32,7 @@ void omv_gpu_deinit();
// Draws src_rect from src_img to dst_rect in dst_img.
// If the sizes of src_rect and dst_rect are different then the image must be scaled.
// Alpha is the alpha value (0-256) to use when blending the source image with the destination image.
// Alpha is the alpha value (0-255) to use when blending the source image with the destination image.
// If color_palette is not NULL, it is used to map the source image's 8-bit Y to an 16-bit RGB565 color.
// If alpha_palette is not NULL, it is used to map the source image's 8-bit Y to an 8-bit alpha value.
//

View File

@ -11995,7 +11995,7 @@ void imlib_find_apriltags(list_t *out, image_t *ptr, rectangle_t *roi, apriltag_
img.h = roi->h;
img.pixfmt = PIXFORMAT_GRAYSCALE;
img.data = fb_alloc(image_size(&img), FB_ALLOC_NO_HINT);
imlib_draw_image(&img, ptr, 0, 0, 1.f, 1.f, roi, -1, 256, NULL, NULL, 0, NULL, NULL, NULL);
imlib_draw_image(&img, ptr, 0, 0, 1.f, 1.f, roi, -1, 255, NULL, NULL, 0, NULL, NULL, NULL);
image_u8_t im;
im.width = roi->w;
@ -12111,7 +12111,7 @@ void imlib_find_rects(list_t *out, image_t *ptr, rectangle_t *roi, uint32_t thre
img.h = roi->h;
img.pixfmt = PIXFORMAT_GRAYSCALE;
img.data = fb_alloc(image_size(&img), FB_ALLOC_NO_HINT);
imlib_draw_image(&img, ptr, 0, 0, 1.f, 1.f, roi, -1, 256, NULL, NULL, 0, NULL, NULL, NULL);
imlib_draw_image(&img, ptr, 0, 0, 1.f, 1.f, roi, -1, 255, NULL, NULL, 0, NULL, NULL, NULL);
image_u8_t im;
im.width = roi->w;

View File

@ -200,7 +200,7 @@ void imlib_binary(image_t *out, image_t *img, list_t *thresholds, bool invert, b
dst_row_override = fb_alloc0(image_line_size(out), FB_ALLOC_CACHE_ALIGN);
}
imlib_draw_image(out, &bmp, 0, 0, 1.0f, 1.0f, NULL, -1, 256, NULL, NULL, 0, callback, mask, dst_row_override);
imlib_draw_image(out, &bmp, 0, 0, 1.0f, 1.0f, NULL, -1, 255, NULL, NULL, 0, callback, mask, dst_row_override);
if (dst_row_override) {
fb_free(); // dst_row_override
@ -1255,7 +1255,7 @@ static void imlib_hat(image_t *img, int ksize, int threshold, image_t *mask, bin
memcpy(temp.data, img->data, image_size(img));
op(&temp, ksize, threshold, mask);
void *dst_row_override = fb_alloc0(image_line_size(img), FB_ALLOC_CACHE_ALIGN);
imlib_draw_image(img, &temp, 0, 0, 1.0f, 1.0f, NULL, -1, 256, NULL, NULL, 0,
imlib_draw_image(img, &temp, 0, 0, 1.0f, 1.0f, NULL, -1, 255, NULL, NULL, 0,
imlib_difference_line_op, mask, dst_row_override);
fb_free(); // dst_row_override
fb_free(); // temp.data

View File

@ -6016,7 +6016,7 @@ void imlib_find_datamatrices(list_t *out, image_t *ptr, rectangle_t *roi, int ef
img.h = roi->h;
img.pixfmt = PIXFORMAT_GRAYSCALE;
img.data = grayscale_image;
imlib_draw_image(&img, ptr, 0, 0, 1.f, 1.f, roi, -1, 256, NULL, NULL, 0, NULL, NULL, NULL);
imlib_draw_image(&img, ptr, 0, 0, 1.f, 1.f, roi, -1, 255, NULL, NULL, 0, NULL, NULL, NULL);
}
umm_init_x(fb_avail());

View File

@ -722,6 +722,9 @@ void imlib_draw_row_setup(imlib_draw_row_data_t *data) {
int alpha = data->alpha, max = 256;
// To avoid having to divide by 255 scale alpha to 0-256 so we can right shift by 8.
alpha = fast_roundf((alpha * 256) / 255.0f);
if (data->dst_img->pixfmt == PIXFORMAT_RGB565) {
alpha >>= 3; // 5-bit alpha for RGB565
max = 32;
@ -733,7 +736,7 @@ void imlib_draw_row_setup(imlib_draw_row_data_t *data) {
data->smuad_alpha_palette = fb_alloc(256 * sizeof(uint32_t), FB_ALLOC_NO_HINT);
for (int i = 0, a = alpha; i < 256; i++) {
int new_alpha = fast_roundf((a * data->alpha_palette[i]) / 255.f);
int new_alpha = fast_roundf((a * data->alpha_palette[i]) / 255.0f);
data->smuad_alpha_palette[i] = data->black_background ? new_alpha : ((new_alpha << 16) | (max - new_alpha));
}
} else {
@ -836,7 +839,7 @@ void imlib_draw_row(int x_start, int x_end, int y_row, imlib_draw_row_data_t *da
}
}
}
} else if (data->alpha == 256) {
} else if (data->alpha == 255) {
if (!data->color_palette) {
for (int x = x_start; x < x_end; x++) {
int pixel = IMAGE_GET_BINARY_PIXEL_FAST(src32, x);
@ -1021,7 +1024,7 @@ void imlib_draw_row(int x_start, int x_end, int y_row, imlib_draw_row_data_t *da
}
}
}
} else if (data->alpha == 256) {
} else if (data->alpha == 255) {
if (!data->color_palette) {
for (int x = x_start; x < x_end; x++) {
int pixel = *src8++ > 127;
@ -1139,7 +1142,7 @@ void imlib_draw_row(int x_start, int x_end, int y_row, imlib_draw_row_data_t *da
}
}
}
} else if (data->alpha == 256) {
} else if (data->alpha == 255) {
if (!data->color_palette) {
for (int x = x_start; x < x_end; x++) {
int pixel = *src16++;
@ -1257,7 +1260,7 @@ void imlib_draw_row(int x_start, int x_end, int y_row, imlib_draw_row_data_t *da
}
}
}
} else if (data->alpha == 256) {
} else if (data->alpha == 255) {
if (!data->color_palette) {
for (int x = x_start; x < x_end; x++) {
int pixel = *src16++;
@ -1375,7 +1378,7 @@ void imlib_draw_row(int x_start, int x_end, int y_row, imlib_draw_row_data_t *da
}
}
}
} else if (data->alpha == 256) {
} else if (data->alpha == 255) {
if (!data->color_palette) {
for (int x = x_start; x < x_end; x++) {
int pixel = *src16++;
@ -1493,7 +1496,7 @@ void imlib_draw_row(int x_start, int x_end, int y_row, imlib_draw_row_data_t *da
}
}
}
} else if (data->alpha == 256) {
} else if (data->alpha == 255) {
if (!data->color_palette) {
for (int x = x_start; x < x_end; x++) {
int pixel = *src16++;
@ -1616,7 +1619,7 @@ void imlib_draw_row(int x_start, int x_end, int y_row, imlib_draw_row_data_t *da
}
}
}
} else if (data->alpha == 256) {
} else if (data->alpha == 255) {
if (!data->color_palette) {
for (int x = x_start; x < x_end; x++) {
*dst8++ =
@ -1709,7 +1712,7 @@ void imlib_draw_row(int x_start, int x_end, int y_row, imlib_draw_row_data_t *da
}
}
}
} else if (data->alpha == 256) {
} else if (data->alpha == 255) {
if (!data->color_palette) {
unaligned_memcpy(dst8, src8, (x_end - x_start) * sizeof(uint8_t));
} else {
@ -1793,7 +1796,7 @@ void imlib_draw_row(int x_start, int x_end, int y_row, imlib_draw_row_data_t *da
}
}
}
} else if (data->alpha == 256) {
} else if (data->alpha == 255) {
if (!data->color_palette) {
for (int x = x_start; x < x_end; x++) {
int pixel = *src16++;
@ -1881,7 +1884,7 @@ void imlib_draw_row(int x_start, int x_end, int y_row, imlib_draw_row_data_t *da
}
}
}
} else if (data->alpha == 256) {
} else if (data->alpha == 255) {
if (!data->color_palette) {
for (int x = x_start; x < x_end; x++) {
int pixel = *src16++;
@ -1969,7 +1972,7 @@ void imlib_draw_row(int x_start, int x_end, int y_row, imlib_draw_row_data_t *da
}
}
}
} else if (data->alpha == 256) {
} else if (data->alpha == 255) {
if (!data->color_palette) {
for (int x = x_start; x < x_end; x++) {
int pixel = *src16++;
@ -2057,7 +2060,7 @@ void imlib_draw_row(int x_start, int x_end, int y_row, imlib_draw_row_data_t *da
}
}
}
} else if (data->alpha == 256) {
} else if (data->alpha == 255) {
if (!data->color_palette) {
for (int x = x_start; x < x_end; x++) {
int pixel = *src16++;
@ -2163,7 +2166,7 @@ void imlib_draw_row(int x_start, int x_end, int y_row, imlib_draw_row_data_t *da
}
}
}
} else if (data->alpha == 256) {
} else if (data->alpha == 255) {
if (!data->color_palette) {
for (int x = x_start; x < x_end; x++) {
*dst16++ =
@ -2254,7 +2257,7 @@ void imlib_draw_row(int x_start, int x_end, int y_row, imlib_draw_row_data_t *da
}
}
}
} else if (data->alpha == 256) {
} else if (data->alpha == 255) {
if (!data->color_palette) {
for (int x = x_start; x < x_end; x++) {
int pixel = *src8++;
@ -2342,7 +2345,7 @@ void imlib_draw_row(int x_start, int x_end, int y_row, imlib_draw_row_data_t *da
}
}
}
} else if (data->alpha == 256) {
} else if (data->alpha == 255) {
if (!data->color_palette) {
unaligned_memcpy(dst16, src16, (x_end - x_start) * sizeof(uint16_t));
} else {
@ -2428,7 +2431,7 @@ void imlib_draw_row(int x_start, int x_end, int y_row, imlib_draw_row_data_t *da
}
}
}
} else if (data->alpha == 256) {
} else if (data->alpha == 255) {
if (!data->color_palette) {
for (int x = x_start; x < x_end; x++) {
int pixel = *src16++;
@ -2522,7 +2525,7 @@ void imlib_draw_row(int x_start, int x_end, int y_row, imlib_draw_row_data_t *da
}
}
}
} else if (data->alpha == 256) {
} else if (data->alpha == 255) {
if (!data->color_palette) {
for (int x = x_start; x < x_end; x++) {
int pixel = *src16++;
@ -2616,7 +2619,7 @@ void imlib_draw_row(int x_start, int x_end, int y_row, imlib_draw_row_data_t *da
}
}
}
} else if (data->alpha == 256) {
} else if (data->alpha == 255) {
if (!data->color_palette) {
for (int x = x_start; x < x_end; x++) {
int pixel = *src16++;
@ -3031,7 +3034,7 @@ void imlib_draw_image(image_t *dst_img,
new_src_img.pixfmt = color_palette ? PIXFORMAT_RGB565 : PIXFORMAT_GRAYSCALE;
new_src_img.data = fb_alloc(image_size(&new_src_img), FB_ALLOC_CACHE_ALIGN);
imlib_draw_image(&new_src_img, src_img, 0, 0, 1.f, 1.f, NULL,
rgb_channel, 256, color_palette, NULL, 0, NULL, NULL, NULL);
rgb_channel, 255, color_palette, NULL, 0, NULL, NULL, NULL);
src_img = &new_src_img;
rgb_channel = -1;
color_palette = NULL;
@ -3131,7 +3134,7 @@ void imlib_draw_image(image_t *dst_img,
t_src_img.h = t_roi.h = src_width_scaled; // was transposed
t_src_img.data = fb_alloc(image_size(&t_src_img), FB_ALLOC_CACHE_ALIGN);
imlib_draw_image(&t_src_img, src_img, 0, 0, x_scale, y_scale, roi,
-1, 256, NULL, NULL,
-1, 255, NULL, NULL,
hint & (IMAGE_HINT_AREA | IMAGE_HINT_BILINEAR | IMAGE_HINT_BICUBIC),
NULL, NULL, NULL);
} else {

View File

@ -2699,7 +2699,7 @@ void imlib_lsd_find_line_segments(list_t *out,
img.h = roi->h;
img.pixfmt = PIXFORMAT_GRAYSCALE;
img.data = grayscale_image;
imlib_draw_image(&img, ptr, 0, 0, 1.f, 1.f, roi, -1, 256, NULL, NULL, 0, NULL, NULL, NULL);
imlib_draw_image(&img, ptr, 0, 0, 1.f, 1.f, roi, -1, 255, NULL, NULL, 0, NULL, NULL, NULL);
umm_init_x(fb_avail());

View File

@ -131,7 +131,7 @@ void mjpeg_write(FIL *fp, int width, int height, uint32_t *frames, uint32_t *byt
(roi->w == img->w) &&
(roi->h == img->h) &&
(rgb_channel == -1) &&
(alpha == 256) &&
(alpha == 255) &&
(color_palette == NULL) &&
(alpha_palette == NULL);

View File

@ -2984,7 +2984,7 @@ void imlib_find_qrcodes(list_t *out, image_t *ptr, rectangle_t *roi)
img.h = roi->h;
img.pixfmt = PIXFORMAT_GRAYSCALE;
img.data = grayscale_image;
imlib_draw_image(&img, ptr, 0, 0, 1.f, 1.f, roi, -1, 256, NULL, NULL, 0, NULL, NULL, NULL);
imlib_draw_image(&img, ptr, 0, 0, 1.f, 1.f, roi, -1, 255, NULL, NULL, 0, NULL, NULL, NULL);
quirc_end(controller);
list_init(out, sizeof(find_qrcodes_list_lnk_data_t));

View File

@ -8733,7 +8733,7 @@ void imlib_find_barcodes(list_t *out, image_t *ptr, rectangle_t *roi)
img.h = roi->h;
img.pixfmt = PIXFORMAT_GRAYSCALE;
img.data = grayscale_image;
imlib_draw_image(&img, ptr, 0, 0, 1.f, 1.f, roi, -1, 256, NULL, NULL, 0, NULL, NULL, NULL);
imlib_draw_image(&img, ptr, 0, 0, 1.f, 1.f, roi, -1, 255, NULL, NULL, 0, NULL, NULL, NULL);
}
umm_init_x(fb_avail());

View File

@ -149,7 +149,7 @@ static mp_obj_t py_display_write(uint n_args, const mp_obj_t *pos_args, mp_map_t
{ MP_QSTR_y_scale, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_roi, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_rgb_channel, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 256 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 255 } },
{ MP_QSTR_color_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_alpha_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_hint, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0 } },
@ -168,8 +168,8 @@ static mp_obj_t py_display_write(uint n_args, const mp_obj_t *pos_args, mp_map_t
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("RGB channel can be 0, 1, or 2"));
}
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 256) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Alpha ranges between 0 and 256"));
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 255) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Alpha ranges between 0 and 255"));
}
float x_scale = 1.0f;

View File

@ -899,7 +899,7 @@ mp_obj_t py_fir_draw_ir(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_args
{ MP_QSTR_y_scale, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_roi, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_rgb_channel, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 256 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 255 } },
{ MP_QSTR_color_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_INT(COLOR_PALETTE_RAINBOW)} },
{ MP_QSTR_alpha_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_hint, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0 } },
@ -919,8 +919,8 @@ mp_obj_t py_fir_draw_ir(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_args
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("RGB channel can be 0, 1, or 2"));
}
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 256) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Alpha ranges between 0 and 256"));
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 255) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Alpha ranges between 0 and 255"));
}
image_t src_img = {
@ -975,7 +975,7 @@ mp_obj_t py_fir_snapshot(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg
{ MP_QSTR_y_scale, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_roi, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_rgb_channel, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 256 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 255 } },
{ MP_QSTR_color_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_INT(COLOR_PALETTE_RAINBOW)} },
{ MP_QSTR_alpha_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_hint, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0 } },
@ -994,8 +994,8 @@ mp_obj_t py_fir_snapshot(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("RGB channel can be 0, 1, or 2"));
}
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 256) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Alpha ranges between 0 and 256"));
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 255) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Alpha ranges between 0 and 255"));
}
if ((args[ARG_pixformat].u_int != PIXFORMAT_GRAYSCALE) && (args[ARG_pixformat].u_int != PIXFORMAT_RGB565)) {

View File

@ -1006,7 +1006,7 @@ static mp_obj_t py_image_to(pixformat_t pixfmt, mp_rom_obj_t default_color_palet
{ MP_QSTR_y_scale, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_roi, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_rgb_channel, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 256 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 255 } },
{ MP_QSTR_color_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = default_color_palette} },
{ MP_QSTR_alpha_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_hint, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0 } },
@ -1028,8 +1028,8 @@ static mp_obj_t py_image_to(pixformat_t pixfmt, mp_rom_obj_t default_color_palet
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("RGB channel can be 0, 1, or 2"));
}
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 256) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Alpha ranges between 0 and 256"));
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 255) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Alpha ranges between 0 and 255"));
}
if (args[ARG_quality].u_int < 1 || args[ARG_quality].u_int > 100) {
@ -1074,7 +1074,7 @@ static mp_obj_t py_image_to(pixformat_t pixfmt, mp_rom_obj_t default_color_palet
(((x_scale != 1.0f) && (x_scale != -1.0f)) ||
((y_scale != 1.0f) && (y_scale != -1.0f)) ||
(args[ARG_channel].u_int != -1) ||
(args[ARG_alpha].u_int != 256) ||
(args[ARG_alpha].u_int != 255) ||
(color_palette != NULL) || (alpha_palette != NULL))) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Only copying/cropping is supported for Bayer/YUV!"));
}
@ -1107,7 +1107,7 @@ static mp_obj_t py_image_to(pixformat_t pixfmt, mp_rom_obj_t default_color_palet
(roi.w == src_img->w) &&
(roi.h == src_img->h) &&
(args[ARG_channel].u_int == -1) &&
(args[ARG_alpha].u_int == 256) &&
(args[ARG_alpha].u_int == 255) &&
(color_palette == NULL) &&
(alpha_palette == NULL) &&
(!transposed);
@ -1732,7 +1732,7 @@ static mp_obj_t py_image_line_op(uint n_args, const mp_obj_t *pos_args, mp_map_t
{ MP_QSTR_y_scale, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_roi, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_rgb_channel, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 256 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 255 } },
{ MP_QSTR_color_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_alpha_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_hint, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0 } },
@ -1788,8 +1788,8 @@ static mp_obj_t py_image_line_op(uint n_args, const mp_obj_t *pos_args, mp_map_t
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("RGB channel can be 0, 1, or 2"));
}
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 256) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Alpha ranges between 0 and 256"));
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 255) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Alpha ranges between 0 and 255"));
}
float x_scale = 1.0f;
@ -2692,7 +2692,7 @@ static mp_obj_t py_image_get_similarity(uint n_args, const mp_obj_t *pos_args, m
{ MP_QSTR_y_scale, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_roi, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_rgb_channel, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 256 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 255 } },
{ MP_QSTR_color_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_alpha_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_hint, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0 } },
@ -2712,8 +2712,8 @@ static mp_obj_t py_image_get_similarity(uint n_args, const mp_obj_t *pos_args, m
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("RGB channel can be 0, 1, or 2"));
}
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 256) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Alpha ranges between 0 and 256"));
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 255) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Alpha ranges between 0 and 255"));
}
float x_scale = 1.0f;

View File

@ -98,7 +98,7 @@ static mp_obj_t py_mjpeg_write(uint n_args, const mp_obj_t *pos_args, mp_map_t *
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_roi, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_rgb_channel, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 256 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 255 } },
{ MP_QSTR_color_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_alpha_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_hint, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0 } },
@ -119,8 +119,8 @@ static mp_obj_t py_mjpeg_write(uint n_args, const mp_obj_t *pos_args, mp_map_t *
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("RGB channel can be 0, 1, or 2"));
}
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 256) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Alpha ranges between 0 and 256"));
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 255) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Alpha ranges between 0 and 255"));
}
if (args[ARG_quality].u_int < 0 || args[ARG_quality].u_int > 100) {

View File

@ -403,7 +403,7 @@ mp_obj_t py_tof_draw_depth(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
{ MP_QSTR_y_scale, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_roi, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_rgb_channel, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 256 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 255 } },
{ MP_QSTR_color_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_INT(COLOR_PALETTE_DEPTH)} },
{ MP_QSTR_alpha_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_hint, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0 } },
@ -423,8 +423,8 @@ mp_obj_t py_tof_draw_depth(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("RGB channel can be 0, 1, or 2"));
}
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 256) {
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("Alpha ranges between 0 and 256"));
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 255) {
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("Alpha ranges between 0 and 255"));
}
image_t src_img = {
@ -479,7 +479,7 @@ mp_obj_t py_tof_snapshot(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg
{ MP_QSTR_y_scale, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_roi, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_rgb_channel, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 256 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 255 } },
{ MP_QSTR_color_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_INT(COLOR_PALETTE_DEPTH)} },
{ MP_QSTR_alpha_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_hint, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0 } },
@ -498,8 +498,8 @@ mp_obj_t py_tof_snapshot(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("RGB channel can be 0, 1, or 2"));
}
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 256) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Alpha ranges between 0 and 256"));
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 255) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Alpha ranges between 0 and 255"));
}
if ((args[ARG_pixformat].u_int != PIXFORMAT_GRAYSCALE) && (args[ARG_pixformat].u_int != PIXFORMAT_RGB565)) {

View File

@ -895,7 +895,7 @@ static mp_obj_t py_tv_display(uint n_args, const mp_obj_t *pos_args, mp_map_t *k
{ MP_QSTR_y_scale, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_roi, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_rgb_channel, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 256 } },
{ MP_QSTR_alpha, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 255 } },
{ MP_QSTR_color_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_alpha_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
{ MP_QSTR_hint, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0 } },
@ -912,8 +912,8 @@ static mp_obj_t py_tv_display(uint n_args, const mp_obj_t *pos_args, mp_map_t *k
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("RGB channel can be 0, 1, or 2"));
}
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 256) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Alpha ranges between 0 and 256"));
if (args[ARG_alpha].u_int < 0 || args[ARG_alpha].u_int > 255) {
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Alpha ranges between 0 and 255"));
}
float x_scale = 1.0f;

View File

@ -442,7 +442,7 @@ static void display_write(py_display_obj_t *self, image_t *src_img, int dst_x_st
display.framebuffer_layers[tail].WindowX1 = black ? self->width : p1.x;
display.framebuffer_layers[tail].WindowY0 = black ? 0 : p0.y;
display.framebuffer_layers[tail].WindowY1 = black ? self->height : p1.y;
display.framebuffer_layers[tail].Alpha = black ? 0 : fast_roundf((alpha * 255) / 256.f);
display.framebuffer_layers[tail].Alpha = black ? 0 : alpha;
display.framebuffer_layers[tail].FBStartAdress =
black ? ((uint32_t) dst_img.data) : ((uint32_t) (IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(&dst_img, p0.y) + p0.x));
display.framebuffer_layers[tail].ImageWidth = black ? self->width : dst_img.w;
@ -451,7 +451,7 @@ static void display_write(py_display_obj_t *self, image_t *src_img, int dst_x_st
// Set alpha to 256 here as we will use the layer alpha to blend the image into the background color of black for free.
if (!black) {
imlib_draw_image(&dst_img, src_img, dst_x_start, dst_y_start,
x_scale, y_scale, roi, rgb_channel, 256, color_palette,
x_scale, y_scale, roi, rgb_channel, 255, color_palette,
alpha_palette, hint | IMAGE_HINT_BLACK_BACKGROUND, NULL, NULL, NULL);
}

View File

@ -87,7 +87,7 @@ int omv_gpu_draw_image(image_t *src_img,
dma2d.Init.Mode = DMA2D_M2M_PFC;
}
if ((alpha != 256) || alpha_palette) {
if ((alpha != 255) || alpha_palette) {
dma2d.Init.Mode = DMA2D_M2M_BLEND;
}
@ -159,7 +159,7 @@ int omv_gpu_draw_image(image_t *src_img,
}
dma2d.LayerCfg[1].InputOffset = src_img->w - src_rect->w;
dma2d.LayerCfg[1].InputAlpha = (alpha * 255) / 256;
dma2d.LayerCfg[1].InputAlpha = alpha;
HAL_DMA2D_ConfigLayer(&dma2d, 1);