image_drawing_alpha_blending_test.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 图像绘制Alpha混合测试
#
# 这个脚本测试draw_image()的性能和质量。
# 方法,它可以执行最近邻、双线性、双三次和
# 区域缩放,以及颜色通道提取、透明度混合、
# 颜色调色板应用和alpha调色板应用的方法。

import csi
import image
import time

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.QVGA)

hint = image.BICUBIC  # image.BILINEAR image.BICUBIC

small_img = image.Image(4, 4, csi.RGB565)
small_img.set_pixel((0, 0), (0, 0, 127))
small_img.set_pixel((1, 0), (47, 255, 199))
small_img.set_pixel((2, 0), (0, 188, 255))
small_img.set_pixel((3, 0), (0, 0, 127))
small_img.set_pixel((0, 1), (0, 176, 255))
small_img.set_pixel((1, 1), (222, 0, 0))
small_img.set_pixel((2, 1), (50, 255, 195))
small_img.set_pixel((3, 1), (86, 255, 160))
small_img.set_pixel((0, 2), (255, 211, 0))
small_img.set_pixel((1, 2), (83, 255, 163))
small_img.set_pixel((2, 2), (255, 211, 0))
small_img.set_pixel((3, 2), (0, 80, 255))
small_img.set_pixel((0, 3), (255, 118, 0))
small_img.set_pixel((1, 3), (127, 0, 0))
small_img.set_pixel((2, 3), (0, 144, 255))
small_img.set_pixel((3, 3), (50, 255, 195))
# small_img.to_grayscale()
# small_img.to_bitmap()

big_img = image.Image(128, 128, csi.RGB565)
big_img.draw_image(small_img, 0, 0, x_scale=32, y_scale=32, hint=hint)
# big_img.to_grayscale()
# big_img.to_bitmap()

alpha_div = 1
alpha_value = 0
alpha_step = 3

x_bounce = csi0.width() // 2
x_bounce_toggle = 1

y_bounce = csi0.height() // 2
y_bounce_toggle = 1

clock = time.clock()
while True:
    clock.tick()

    img = csi0.snapshot()
    # img.to_grayscale()
    # img.to_bitmap()
    img.draw_image(
        big_img,
        x_bounce,
        y_bounce,
        rgb_channel=-1,
        alpha=alpha_value // alpha_div,
        hint=hint
    )

    x_bounce += x_bounce_toggle
    if abs(x_bounce - (img.width() // 2)) >= (img.width() // 2):
        x_bounce_toggle = -x_bounce_toggle

    y_bounce += y_bounce_toggle
    if abs(y_bounce - (img.height() // 2)) >= (img.height() // 2):
        y_bounce_toggle = -y_bounce_toggle

    alpha_value += alpha_step
    if not alpha_value or alpha_value // alpha_div >= 255:
        alpha_step = -alpha_step

    print(clock.fps())

results matching ""

    No results matching ""