diff --git a/utils/kmstest.py b/utils/kmstest.py index b7c976a..2d61d5d 100755 --- a/utils/kmstest.py +++ b/utils/kmstest.py @@ -6,6 +6,7 @@ import numpy as np +from kms.framebuffer import Framebuffer from pixutils.dmaheap import DMAHeap import kms @@ -36,6 +37,141 @@ def draw_test_pattern(fb): d1[0::fb.width+1] = 0xffffff d1[fb.width-1::fb.width-1] = 0xffffff +def draw_pixel_xv15(fmt: kms.PixelFormat, buf_y, buf_uv, x, y, color: tuple): + MASK10 = (1 << 10) - 1 + + color_Y, color_Cb, color_Cr = color + + pos = (x, y) + + Y_pos = (pos[0] // fmt.planes[0].hsub, pos[1] // fmt.planes[0].vsub) + UV_pos = (pos[0] // fmt.planes[1].hsub, pos[1] // fmt.planes[1].vsub) + + Y_offset = Y_pos[0] // 3 + Y_mod = Y_pos[0] % 3 + + UV_offset = UV_pos[0] // 3 + UV_mod = UV_pos[0] % 3 + + Y_pos_unit = (Y_offset, Y_pos[1]) + UV_pos_unit = (UV_offset, UV_pos[1]) + + + #print('pos:', pos, Y_pos, UV_pos) + #print('Y offset ', Y_offset, 'mod', Y_mod) + #print('UV offset ', UV_offset, 'mod', UV_mod) + + + shift_Y = 10 * Y_mod + + v = buf_y[Y_pos_unit[1], Y_pos_unit[0]] + v &= ~(MASK10 << shift_Y) + v |= color_Y << shift_Y + buf_y[Y_pos_unit[1], Y_pos_unit[0]] = v + + + if UV_mod == 0: + shift_Cb = 0 + shift_Cr = 10 + elif UV_mod == 1: + shift_Cb = 20 + shift_Cr = 32 + elif UV_mod == 2: + shift_Cb = 32 + 10 + shift_Cr = 32 + 20 + else: + assert False + + v = buf_uv[UV_pos_unit[1], UV_pos_unit[0]] + v &= ~((np.uint64(MASK10) << np.uint64(shift_Cb)) | (np.uint64(MASK10) << np.uint64(shift_Cr))) + v |= (np.uint64(color_Cb) << np.uint64(shift_Cb)) | (np.uint64(color_Cr) << np.uint64(shift_Cr)) + buf_uv[UV_pos_unit[1], UV_pos_unit[0]] = v + +def draw_test_pattern_xv15(fb: Framebuffer): + fmt = fb.format + + buf_y = np.frombuffer(fb.map(0), dtype=np.dtype('