mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-08-04 14:46:03 +00:00
Add test for quarter blocks
This commit is contained in:
parent
b96da25380
commit
073d5c7340
2 changed files with 45 additions and 9 deletions
|
|
@ -809,7 +809,7 @@ extract_scaled_cell_from_canvas(
|
|||
unsigned src_row_size = scaled_cell_width * num_cells;
|
||||
if (xoff >= src_row_size) return ans; // nothing to copy
|
||||
unsigned width = MIN(src_row_size - xoff, unscaled_cell_width);
|
||||
/*printf("\n");*/
|
||||
/*printf("extracting width: %u ------------------------\n", width);*/
|
||||
for (unsigned src_y=src.top, dest_y=dest.top; src_y < src.bottom && src_y < scaled_cell_height && dest_y < dest.bottom && dest_y < unscaled_cell_height; src_y++, dest_y++) {
|
||||
pixel *srcp = canvas->buf + src_row_size * src_y;
|
||||
pixel *destp = ans + unscaled_cell_width * dest_y;
|
||||
|
|
@ -869,21 +869,22 @@ render_box_cell(FontGroup *fg, RunFont rf, CPUCell *cpu_cell, GPUCell *gpu_cell,
|
|||
}
|
||||
if (all_rendered) return;
|
||||
unsigned width = fg->fcm.cell_width, height = fg->fcm.cell_height;
|
||||
scaled_cell_dimensions(rf, &width, &height);
|
||||
float scale = scaled_cell_dimensions(rf, &width, &height);
|
||||
RAII_PyObject(ret, PyObject_CallFunction(box_drawing_function, "IIId", (unsigned int)ch, width, height, (fg->logical_dpi_x + fg->logical_dpi_y) / 2.0));
|
||||
if (ret == NULL) { PyErr_Print(); return; }
|
||||
uint8_t *alpha_mask = PyLong_AsVoidPtr(PyTuple_GET_ITEM(ret, 0));
|
||||
ensure_canvas_can_fit(fg, 2, rf.scale);
|
||||
Region src = { .right = width, .bottom = height }, dest = src;
|
||||
render_alpha_mask(alpha_mask, fg->canvas.buf, &src, &dest, width, width, 0xffffff);
|
||||
/*for (unsigned y = 0; y < height; y++) { for (unsigned x = 0; x < width; x++) { printf("%d ", (fg->canvas.buf + width * y)[0] != 0); } printf("\n"); }*/
|
||||
if (rf.scale == 1) {
|
||||
/*printf("Rendered char sz: (%u, %u)\n", width, height); for (unsigned y = 0; y < height; y++) { for (unsigned x = 0; x < width; x++) { printf("%d ", (fg->canvas.buf + width * y)[x] != 0); } printf("\n"); }*/
|
||||
if (scale == 1.f && rf.scale == 1 && !rf.subscale_n) {
|
||||
current_send_sprite_to_gpu((FONTS_DATA_HANDLE)fg, sp[0]->x, sp[0]->y, sp[0]->z, fg->canvas.buf);
|
||||
} else {
|
||||
calculate_regions_for_line(rf, fg->fcm.cell_height, &src, &dest);
|
||||
/*printf("width: %u height: %u src.top: %u src.bottom: %u\n", width, height, src.top, src.bottom);*/
|
||||
/*printf("width: %u height: %u unscaled_cell_width: %u unscaled_cell_height: %u src.top: %u src.bottom: %u rf.scale: %u\n", width, height, fg->fcm.cell_width, fg->fcm.cell_height, src.top, src.bottom, rf.scale);*/
|
||||
for (unsigned i = 0; i < rf.scale; i++) {
|
||||
pixel *b = extract_scaled_cell_from_canvas(&fg->canvas, i, 1, src, dest, fg->fcm.cell_width, fg->fcm.cell_height, width, height);
|
||||
/*printf("Sprite %u: pos: (%u, %u, %u) sz: (%u, %u)\n", i, sp[i]->x, sp[i]->y, sp[i]->z, fg->fcm.cell_width, fg->fcm.cell_height); for (unsigned y = 0; y < fg->fcm.cell_height; y++) { for (unsigned x = 0; x < fg->fcm.cell_width; x++) { printf("%d ", (b + fg->fcm.cell_width * y)[x] != 0); } printf("\n"); }*/
|
||||
current_send_sprite_to_gpu((FONTS_DATA_HANDLE)fg, sp[i]->x, sp[i]->y, sp[i]->z, b);
|
||||
}
|
||||
}
|
||||
|
|
@ -948,13 +949,15 @@ render_group(
|
|||
render_glyphs_in_cells(font->face, font->bold, font->italic, info, positions, num_glyphs, fg->canvas.buf, fg->fcm.cell_width, fg->fcm.cell_height, num_cells, fg->fcm.baseline, &was_colored, (FONTS_DATA_HANDLE)fg, center_glyph);
|
||||
if (PyErr_Occurred()) PyErr_Print();
|
||||
|
||||
#define sendtogpu { FontCellMetrics scaled = fg->fcm; current_send_sprite_to_gpu((FONTS_DATA_HANDLE)fg, sp[i]->x, sp[i]->y, sp[i]->z, b); fg->fcm = scaled; }
|
||||
|
||||
if (scale == 1.f) {
|
||||
for (unsigned i = 0; i < num_cells; i++) {
|
||||
if (!sp[i]->rendered) {
|
||||
sp[i]->rendered = true;
|
||||
sp[i]->colored = was_colored;
|
||||
pixel *buf = num_cells == 1 ? fg->canvas.buf : extract_cell_from_canvas(fg, i, num_cells);
|
||||
current_send_sprite_to_gpu((FONTS_DATA_HANDLE)fg, sp[i]->x, sp[i]->y, sp[i]->z, buf);
|
||||
pixel *b = num_cells == 1 ? fg->canvas.buf : extract_cell_from_canvas(fg, i, num_cells);
|
||||
sendtogpu;
|
||||
}
|
||||
set_cell_sprite(gpu_cells + i, sp[i]);
|
||||
}
|
||||
|
|
@ -964,7 +967,7 @@ render_group(
|
|||
for (unsigned i = 0; i < num_cells; i++) {
|
||||
if (!sp[i]->rendered) {
|
||||
pixel *b = extract_scaled_cell_from_canvas(&fg->canvas, i, num_cells, src, dest, unscaled_metrics.cell_width, unscaled_metrics.cell_height, fg->fcm.cell_width, fg->fcm.cell_height);
|
||||
current_send_sprite_to_gpu((FONTS_DATA_HANDLE)fg, sp[i]->x, sp[i]->y, sp[i]->z, b);
|
||||
sendtogpu;
|
||||
}
|
||||
set_cell_sprite(gpu_cells + i, sp[i]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
# License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
import array
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
|
|
@ -223,14 +224,46 @@ class Rendering(BaseTest):
|
|||
rest = self.cell_height - height
|
||||
return (first * (rest * self.cell_width * 4)) + (second * height * self.cell_width * 4)
|
||||
|
||||
def quarter_block():
|
||||
frac = 0.5
|
||||
height = ceil(frac * self.cell_height)
|
||||
width = ceil(frac * self.cell_width)
|
||||
ans = array.array('I', b'\0' * block_size)
|
||||
self.ae(len(ans), self.cell_width * self.cell_height)
|
||||
for y in range(height):
|
||||
pos = self.cell_width * y
|
||||
for x in range(width):
|
||||
ans[pos + x] = 0xffffffff
|
||||
return ans.tobytes()
|
||||
|
||||
def upper_half_block():
|
||||
return half_block()
|
||||
|
||||
def lower_half_block():
|
||||
return half_block(b'\0', b'\xff')
|
||||
|
||||
def block_as_str(a):
|
||||
pixels = array.array('I', a)
|
||||
def row(y):
|
||||
pos = y * self.cell_width
|
||||
return ' '.join(f'{int(pixels[pos + x] != 0)}' for x in range(self.cell_width))
|
||||
return '\n'.join(row(y) for y in range(self.cell_height))
|
||||
|
||||
def assert_blocks(a, b, msg=''):
|
||||
if a != b:
|
||||
assert_blocks.__msg = (msg or 'block not equal') + '\n' + block_as_str(a) + '\n\n' + block_as_str(b)
|
||||
del a, b
|
||||
raise AssertionError(assert_blocks.__msg)
|
||||
|
||||
s = self.create_screen(cols=8, lines=8, scrollback=0)
|
||||
|
||||
s.reset()
|
||||
before = len(self.sprites)
|
||||
draw_multicell(s, '█', scale=1, subscale_n=1, subscale_d=2, vertical_align=0)
|
||||
test_render_line(s.line(0))
|
||||
self.ae(len(self.sprites), before + 1)
|
||||
assert_blocks(quarter_block(), self.sprites[tuple(self.sprites)[before]])
|
||||
|
||||
def block_test(a=empty_block, b=empty_block, c=empty_block, d=empty_block, scale=2, half_block=True, vertical_align=0):
|
||||
s.reset()
|
||||
before = len(self.sprites)
|
||||
|
|
@ -244,7 +277,7 @@ class Rendering(BaseTest):
|
|||
self.ae(len(self.sprites), before + 4)
|
||||
blocks = tuple(self.sprites)[before:]
|
||||
for i, (expected, actual) in enumerate(zip((a(), b(), c(), d()), blocks)):
|
||||
self.ae(self.sprites[actual], expected, f'The {i} block differs')
|
||||
assert_blocks(expected, self.sprites[actual], f'The {i} block differs')
|
||||
|
||||
block_test(full_block, full_block, full_block, full_block, half_block=False)
|
||||
block_test(a=full_block)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue