Image Drawing Alpha Blending Test

# This work is licensed under the MIT license.
# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Image Drawing Alpha Blending Test
#
# This script tests the performance and quality of the draw_image()
# method which can perform nearest neighbor, bilinear, bicubic, and
# area scaling along with color channel extraction, alpha blending,
# color palette application, and alpha palette application.

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 ""