Lines Matching +full:mid +full:- +full:scale
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
37 * ALL pixel data is assumed to be 32-bit BGRA (byte order Blue, Green, Red,
43 * 32-bit to/from 32-bit is trivial case.
44 * 32-bit to/from 24-bit is also simple - we just drop the alpha channel.
45 * 32-bit to/from 16-bit is more complicated, because we nee to handle
46 * data loss from 32-bit to 16-bit. While reading/writing from/to video, we
47 * need to apply masks of 16-bit color components. This will preserve
48 * colors for terminal text. For 32-bit truecolor PMG images, we need to
49 * translate 32-bit colors to 15/16 bit colors and this means data loss.
54 * 32-bit to/from 8-bit is the most troublesome because 8-bit colors are
61 * used indexed colors for 8-bit colors (0-255) and for this mode we do
64 * - paletteentry RGB <-> index -
65 * BGRA BUFFER <----/ \ - VIDEO
67 * - RGB (16/24/32) -
70 * from when we set up 8-bit mode video. We cannot read palette data from
76 * Note: In 8-bit mode, We do store first 16 colors to palette registers
80 * loader is used. However, the palette map for 8-bit colors is using
81 * console color ordering - this does allow us to skip translation
151 * - blue and red are swapped (1 <-> 4)
152 * - yellow and cyan are swapped (3 <-> 6)
166 * in order to exclude buggy gop->Blt(), we want option
167 * to use direct draw to framebuffer and avoid gop->Blt.
224 *depth = -1; /* auto select */ in gfx_parse_mode_str()
271 /* colors 232-255 are a grayscale ramp */ in rgb_color_map()
286 * or we will lose color information from 32-bit to 15/16 bit translation.
294 roff = ffs(gfx_state.tg_fb.fb_mask_red) - 1; in gfx_fb_color_map()
295 goff = ffs(gfx_state.tg_fb.fb_mask_green) - 1; in gfx_fb_color_map()
296 boff = ffs(gfx_state.tg_fb.fb_mask_blue) - 1; in gfx_fb_color_map()
320 * Since UEFI does only support 32-bit colors, we do not implement it for
334 diff = r - pe8[k].Red; in rgb_to_color_index()
336 diff = g - pe8[k].Green; in rgb_to_color_index()
338 diff = b - pe8[k].Blue; in rgb_to_color_index()
442 roff = ffs(gfx_state.tg_fb.fb_mask_red) - 1; in gfxfb_blt_fill()
443 goff = ffs(gfx_state.tg_fb.fb_mask_green) - 1; in gfxfb_blt_fill()
444 boff = ffs(gfx_state.tg_fb.fb_mask_blue) - 1; in gfxfb_blt_fill()
447 data = rgb_to_color_index(p->Red, p->Green, p->Blue); in gfxfb_blt_fill()
449 data = (p->Red & in gfxfb_blt_fill()
451 data |= (p->Green & in gfxfb_blt_fill()
453 data |= (p->Blue & in gfxfb_blt_fill()
533 rp = ffs(gfx_state.tg_fb.fb_mask_red) - 1; in gfxfb_blt_video_to_buffer()
534 gp = ffs(gfx_state.tg_fb.fb_mask_green) - 1; in gfxfb_blt_video_to_buffer()
535 bp = ffs(gfx_state.tg_fb.fb_mask_blue) - 1; in gfxfb_blt_video_to_buffer()
542 ffs(rm) - 1 == 8 && rp == 16 && in gfxfb_blt_video_to_buffer()
543 ffs(gm) - 1 == 8 && gp == 8 && in gfxfb_blt_video_to_buffer()
544 ffs(bm) - 1 == 8 && bp == 0; in gfxfb_blt_video_to_buffer()
583 p->Red = (c >> rp) & rm; in gfxfb_blt_video_to_buffer()
584 p->Green = (c >> gp) & gm; in gfxfb_blt_video_to_buffer()
585 p->Blue = (c >> bp) & bm; in gfxfb_blt_video_to_buffer()
586 p->Reserved = 0; in gfxfb_blt_video_to_buffer()
633 rp = ffs(gfx_state.tg_fb.fb_mask_red) - 1; in gfxfb_blt_buffer_to_video()
634 gp = ffs(gfx_state.tg_fb.fb_mask_green) - 1; in gfxfb_blt_buffer_to_video()
635 bp = ffs(gfx_state.tg_fb.fb_mask_blue) - 1; in gfxfb_blt_buffer_to_video()
642 ffs(rm) - 1 == 8 && rp == 16 && in gfxfb_blt_buffer_to_video()
643 ffs(gm) - 1 == 8 && gp == 8 && in gfxfb_blt_buffer_to_video()
644 ffs(bm) - 1 == 8 && bp == 0; in gfxfb_blt_buffer_to_video()
663 c = rgb_to_color_index(p->Red, in gfxfb_blt_buffer_to_video()
664 p->Green, p->Blue); in gfxfb_blt_buffer_to_video()
666 c = (p->Red & rm) << rp | in gfxfb_blt_buffer_to_video()
667 (p->Green & gm) << gp | in gfxfb_blt_buffer_to_video()
668 (p->Blue & bm) << bp; in gfxfb_blt_buffer_to_video()
743 pitch = -pitch; in gfxfb_blt_video_to_video()
746 while (Height-- > 0) { in gfxfb_blt_video_to_video()
772 Width = fbX - DestinationX; in gfxfb_shadow_fill()
775 Height = fbY - DestinationY; in gfxfb_shadow_fill()
807 tpl = BS->RaiseTPL(TPL_NOTIFY); in gfxfb_blt()
812 status = gop->Blt(gop, BltBuffer, EfiBltVideoFill, in gfxfb_blt()
818 status = gop->Blt(gop, BltBuffer, in gfxfb_blt()
825 status = gop->Blt(gop, BltBuffer, EfiBltBufferToVideo, in gfxfb_blt()
831 status = gop->Blt(gop, BltBuffer, EfiBltVideoToVideo, in gfxfb_blt()
856 BS->RestoreTPL(tpl); in gfxfb_blt()
901 width = state->tg_font.vf_width; in gfx_bitblt_bitmap()
902 height = state->tg_font.vf_height; in gfx_bitblt_bitmap()
905 fgc = a->ta_fgcolor; in gfx_bitblt_bitmap()
906 bgc = a->ta_bgcolor; in gfx_bitblt_bitmap()
907 if (a->ta_format & TF_BOLD) in gfx_bitblt_bitmap()
909 if (a->ta_format & TF_BLINK) in gfx_bitblt_bitmap()
915 if (a->ta_format & TF_REVERSE) in gfx_bitblt_bitmap()
938 gfx_mem_wr4(state->tg_glyph, in gfx_bitblt_bitmap()
939 state->tg_glyph_size, o, cc); in gfx_bitblt_bitmap()
952 width = state->tg_font.vf_width; in gfx_fb_printchar()
953 height = state->tg_font.vf_height; in gfx_fb_printchar()
954 x = state->tg_origin.tp_col + p->tp_col * width; in gfx_fb_printchar()
955 y = state->tg_origin.tp_row + p->tp_row * height; in gfx_fb_printchar()
957 gfx_fb_cons_display(x, y, width, height, state->tg_glyph); in gfx_fb_printchar()
971 idx = p->tp_col + p->tp_row * state->tg_tp.tp_col; in gfx_fb_putchar()
972 if (idx >= state->tg_tp.tp_col * state->tg_tp.tp_row) in gfx_fb_putchar()
976 if (state->tg_cursor_visible) in gfx_fb_putchar()
977 gfx_fb_cursor_draw(state, &state->tg_cursor, false); in gfx_fb_putchar()
982 glyph = font_lookup(&state->tg_font, c, a); in gfx_fb_putchar()
987 if (state->tg_cursor_visible) { in gfx_fb_putchar()
990 c = teken_get_cursor(&state->tg_teken); in gfx_fb_putchar()
1005 if (state->tg_cursor_visible) in gfx_fb_fill()
1006 gfx_fb_cursor_draw(state, &state->tg_cursor, false); in gfx_fb_fill()
1008 glyph = font_lookup(&state->tg_font, c, a); in gfx_fb_fill()
1011 for (p.tp_row = r->tr_begin.tp_row; p.tp_row < r->tr_end.tp_row; in gfx_fb_fill()
1013 row = &screen_buffer[p.tp_row * state->tg_tp.tp_col]; in gfx_fb_fill()
1014 for (p.tp_col = r->tr_begin.tp_col; in gfx_fb_fill()
1015 p.tp_col < r->tr_end.tp_col; p.tp_col++) { in gfx_fb_fill()
1023 if (state->tg_cursor_visible) { in gfx_fb_fill()
1026 c = teken_get_cursor(&state->tg_teken); in gfx_fb_fill()
1039 if (p.tp_col >= state->tg_tp.tp_col) in gfx_fb_cursor_draw()
1040 p.tp_col = state->tg_tp.tp_col - 1; in gfx_fb_cursor_draw()
1041 if (p.tp_row >= state->tg_tp.tp_row) in gfx_fb_cursor_draw()
1042 p.tp_row = state->tg_tp.tp_row - 1; in gfx_fb_cursor_draw()
1043 idx = p.tp_col + p.tp_row * state->tg_tp.tp_col; in gfx_fb_cursor_draw()
1044 if (idx >= state->tg_tp.tp_col * state->tg_tp.tp_row) in gfx_fb_cursor_draw()
1047 glyph = font_lookup(&state->tg_font, screen_buffer[idx].c, in gfx_fb_cursor_draw()
1052 state->tg_cursor = p; in gfx_fb_cursor_draw()
1061 if (state->tg_cursor_visible) { in gfx_fb_cursor()
1062 gfx_fb_cursor_draw(state, &state->tg_cursor, false); in gfx_fb_cursor()
1084 c = teken_get_cursor(&state->tg_teken); in gfx_fb_param()
1087 state->tg_cursor_visible = true; in gfx_fb_param()
1089 state->tg_cursor_visible = false; in gfx_fb_param()
1100 if (px1->c != px2->c) in is_same_pixel()
1104 if ((px1->a.ta_format & TF_IMAGE) || in is_same_pixel()
1105 (px2->a.ta_format & TF_IMAGE)) in is_same_pixel()
1108 if (px1->a.ta_format != px2->a.ta_format) in is_same_pixel()
1110 if (px1->a.ta_fgcolor != px2->a.ta_fgcolor) in is_same_pixel()
1112 if (px1->a.ta_bgcolor != px2->a.ta_bgcolor) in is_same_pixel()
1126 width = state->tg_font.vf_width; in gfx_fb_copy_area()
1127 height = state->tg_font.vf_height; in gfx_fb_copy_area()
1129 sx = s->tr_begin.tp_col * width; in gfx_fb_copy_area()
1130 sy = s->tr_begin.tp_row * height; in gfx_fb_copy_area()
1131 dx = d->tp_col * width; in gfx_fb_copy_area()
1132 dy = d->tp_row * height; in gfx_fb_copy_area()
1134 width *= (s->tr_end.tp_col - s->tr_begin.tp_col + 1); in gfx_fb_copy_area()
1139 if (state->tg_shadow_fb == NULL) { in gfx_fb_copy_area()
1141 sx + state->tg_origin.tp_col, in gfx_fb_copy_area()
1142 sy + state->tg_origin.tp_row, in gfx_fb_copy_area()
1143 dx + state->tg_origin.tp_col, in gfx_fb_copy_area()
1144 dy + state->tg_origin.tp_row, in gfx_fb_copy_area()
1155 pitch = state->tg_fb.fb_width; in gfx_fb_copy_area()
1156 bytes = width * sizeof (*state->tg_shadow_fb); in gfx_fb_copy_area()
1164 step = -step; in gfx_fb_copy_area()
1167 while (height-- > 0) { in gfx_fb_copy_area()
1168 uint32_t *source = &state->tg_shadow_fb[sy * pitch + sx]; in gfx_fb_copy_area()
1169 uint32_t *destination = &state->tg_shadow_fb[dy * pitch + dx]; in gfx_fb_copy_area()
1173 0, 0, dx + state->tg_origin.tp_col, in gfx_fb_copy_area()
1174 dy + state->tg_origin.tp_row, width, 1, 0); in gfx_fb_copy_area()
1190 soffset = s->tp_col + s->tp_row * state->tg_tp.tp_col; in gfx_fb_copy_line()
1191 doffset = d->tp_col + d->tp_row * state->tg_tp.tp_col; in gfx_fb_copy_line()
1204 sr.tr_end.tp_col = s->tp_col + x; in gfx_fb_copy_line()
1208 sr.tr_begin.tp_col = s->tp_col + x; in gfx_fb_copy_line()
1209 sr.tr_begin.tp_row = s->tp_row; in gfx_fb_copy_line()
1210 sr.tr_end.tp_col = s->tp_col + x; in gfx_fb_copy_line()
1211 sr.tr_end.tp_row = s->tp_row; in gfx_fb_copy_line()
1212 dp.tp_col = d->tp_col + x; in gfx_fb_copy_line()
1213 dp.tp_row = d->tp_row; in gfx_fb_copy_line()
1228 int nrow, ncol, y; /* Has to be signed - >= 0 comparison */ in gfx_fb_copy()
1235 nrow = r->tr_end.tp_row - r->tr_begin.tp_row; in gfx_fb_copy()
1236 ncol = r->tr_end.tp_col - r->tr_begin.tp_col; in gfx_fb_copy()
1238 if (p->tp_row + nrow > state->tg_tp.tp_row || in gfx_fb_copy()
1239 p->tp_col + ncol > state->tg_tp.tp_col) in gfx_fb_copy()
1242 soffset = r->tr_begin.tp_col + r->tr_begin.tp_row * state->tg_tp.tp_col; in gfx_fb_copy()
1243 doffset = p->tp_col + p->tp_row * state->tg_tp.tp_col; in gfx_fb_copy()
1246 if (state->tg_cursor_visible) in gfx_fb_copy()
1247 gfx_fb_cursor_draw(state, &state->tg_cursor, false); in gfx_fb_copy()
1253 s = r->tr_begin; in gfx_fb_copy()
1256 s.tp_row = r->tr_begin.tp_row + y; in gfx_fb_copy()
1257 d.tp_row = p->tp_row + y; in gfx_fb_copy()
1262 for (y = nrow - 1; y >= 0; y--) { in gfx_fb_copy()
1263 s.tp_row = r->tr_begin.tp_row + y; in gfx_fb_copy()
1264 d.tp_row = p->tp_row + y; in gfx_fb_copy()
1271 if (state->tg_cursor_visible) { in gfx_fb_copy()
1274 c = teken_get_cursor(&state->tg_teken); in gfx_fb_copy()
1283 * blend = alpha * fg + (1.0 - alpha) * bg.
1284 * Since our alpha is not from range [0..1], we scale appropriately.
1296 blend = (alpha * fg + (0xFF - alpha) * bg); in alpha_blend()
1309 * blend = alpha * fg + (1.0 - alpha) * bg.
1310 * Since our alpha is not from range [0..1], we scale appropriately.
1376 (y - gfx_state.tg_origin.tp_row) * pitch + in gfx_fb_cons_display()
1377 x - gfx_state.tg_origin.tp_col); in gfx_fb_cons_display()
1427 num -= res + bit; in isqrt()
1444 if (ap->ta_format & TF_REVERSE) { in gfx_fb_getcolor()
1445 c = ap->ta_bgcolor; in gfx_fb_getcolor()
1446 if (ap->ta_format & TF_BLINK) in gfx_fb_getcolor()
1449 c = ap->ta_fgcolor; in gfx_fb_getcolor()
1450 if (ap->ta_format & TF_BOLD) in gfx_fb_getcolor()
1490 gfxfb_blt(&c, GfxFbBltVideoFill, 0, 0, x1, y1, x2 - x1, in gfx_fb_drawrect()
1491 y2 - y1, 0); in gfx_fb_drawrect()
1493 gfxfb_blt(&c, GfxFbBltVideoFill, 0, 0, x1, y1, x2 - x1, 1, 0); in gfx_fb_drawrect()
1494 gfxfb_blt(&c, GfxFbBltVideoFill, 0, 0, x1, y2, x2 - x1, 1, 0); in gfx_fb_drawrect()
1495 gfxfb_blt(&c, GfxFbBltVideoFill, 0, 0, x1, y1, 1, y2 - y1, 0); in gfx_fb_drawrect()
1496 gfxfb_blt(&c, GfxFbBltVideoFill, 0, 0, x2, y1, 1, y2 - y1, 0); in gfx_fb_drawrect()
1510 sx = x0 < x1? 1 : -1; in gfx_fb_line()
1511 sy = y0 < y1? 1 : -1; in gfx_fb_line()
1512 dx = x1 > x0? x1 - x0 : x0 - x1; in gfx_fb_line()
1513 dy = y1 > y0? y1 - y0 : y0 - y1; in gfx_fb_line()
1521 if ((e2 << 1) >= -dx) { /* x step */ in gfx_fb_line()
1533 err -= dy; in gfx_fb_line()
1537 e2 = dx-e2; in gfx_fb_line()
1567 sx = x2 - x1; in gfx_fb_bezier()
1568 sy = y2 - y1; in gfx_fb_bezier()
1569 xx = x0 - x1; in gfx_fb_bezier()
1570 yy = y0 - y1; in gfx_fb_bezier()
1571 curvature = xx*sy - yy*sx; in gfx_fb_bezier()
1578 curvature = -curvature; in gfx_fb_bezier()
1582 sx = x0 < x2? 1 : -1; in gfx_fb_bezier()
1585 sy = y0 < y2? 1 : -1; in gfx_fb_bezier()
1591 xx = -xx; in gfx_fb_bezier()
1592 yy = -yy; in gfx_fb_bezier()
1593 xy = -xy; in gfx_fb_bezier()
1594 curvature = -curvature; in gfx_fb_bezier()
1596 dx = 4 * sy * curvature * (x1 - x0) + xx - xy; in gfx_fb_bezier()
1597 dy = 4 * sx * curvature * (y0 - y1) + yy - xy; in gfx_fb_bezier()
1605 return; /* last pixel -> curve finished */ in gfx_fb_bezier()
1609 dx -= xy; in gfx_fb_bezier()
1615 dy -= xy; in gfx_fb_bezier()
1619 } while (dy < dx); /* gradient negates -> algorithm fails */ in gfx_fb_bezier()
1642 xshift = (vf_width - width) / 2; in gfx_term_drawrect()
1643 yshift = (vf_height - width) / 2; in gfx_term_drawrect()
1647 ux1--; in gfx_term_drawrect()
1649 uy1--; in gfx_term_drawrect()
1650 ux2--; in gfx_term_drawrect()
1651 uy2--; in gfx_term_drawrect()
1669 y2 += vf_height - yshift - width; in gfx_term_drawrect()
1681 x1 += vf_width - xshift - width; in gfx_term_drawrect()
1693 gfx_fb_bezier(x1 + i, y1, x1 + i, y2 + i, x2, y2 + i, width-i); in gfx_term_drawrect()
1699 y1 += vf_height - yshift; in gfx_term_drawrect()
1703 gfx_fb_bezier(x1, y1 - i, x2 + i, y1 - i, x2 + i, y2, width-i); in gfx_term_drawrect()
1709 x2 += vf_width - xshift - width; in gfx_term_drawrect()
1713 gfx_fb_bezier(x1, y1 + i, x2 + i, y1 + i, x2 + i, y2, width-i); in gfx_term_drawrect()
1718 y1 += vf_height - yshift; in gfx_term_drawrect()
1720 x2 += vf_width - xshift - width; in gfx_term_drawrect()
1723 gfx_fb_bezier(x1, y1 - i, x2 + i, y1 - i, x2 + i, y2, width-i); in gfx_term_drawrect()
1739 bool scale = false; in gfx_fb_putimage() local
1751 if (png->color_type != PNG_TRUECOLOR_ALPHA) { in gfx_fb_putimage()
1764 if (png->width > UINT16_MAX || png->height > UINT16_MAX) { in gfx_fb_putimage()
1770 if (png->width < 1 || png->height < 1) { in gfx_fb_putimage()
1780 scale = true; in gfx_fb_putimage()
1783 ux2 = ux1 + png->width; in gfx_fb_putimage()
1784 uy2 = uy1 + png->height; in gfx_fb_putimage()
1785 scale = false; in gfx_fb_putimage()
1788 ux2 = ux1 + (png->width * (uy2 - uy1)) / png->height; in gfx_fb_putimage()
1791 uy2 = uy1 + (png->height * (ux2 - ux1)) / png->width; in gfx_fb_putimage()
1801 fwidth = ux2 - ux1; in gfx_fb_putimage()
1802 fheight = uy2 - uy1; in gfx_fb_putimage()
1808 if (fwidth == png->width && fheight == png->height) in gfx_fb_putimage()
1809 scale = false; in gfx_fb_putimage()
1813 * No top left X co-ordinate (real coordinates start at 1), in gfx_fb_putimage()
1816 ux2 = gfx_state.tg_fb.fb_width - gfx_state.tg_origin.tp_col; in gfx_fb_putimage()
1817 ux1 = ux2 - fwidth; in gfx_fb_putimage()
1822 * No top left Y co-ordinate (real coordinates start at 1), in gfx_fb_putimage()
1825 uy2 = gfx_state.tg_fb.fb_height - gfx_state.tg_origin.tp_row; in gfx_fb_putimage()
1826 uy1 = uy2 - fheight; in gfx_fb_putimage()
1842 printf("Image %ux%u -> %ux%u @%ux%u\n", in gfx_fb_putimage()
1843 png->width, png->height, fwidth, fheight, ux1, uy1); in gfx_fb_putimage()
1872 #define GETPIXEL(xx, yy) (((yy) * png->width + (xx)) * png->bpp) in gfx_fb_putimage()
1877 * Use fixed-point arithmetic with 16-bits for each of the integer and in gfx_fb_putimage()
1880 const uint32_t wcstep = ((png->width - 1) << 16) / (fwidth - 1); in gfx_fb_putimage()
1881 const uint32_t hcstep = ((png->height - 1) << 16) / (fheight - 1); in gfx_fb_putimage()
1883 rs = 8 - (fls(gfx_state.tg_fb.fb_mask_red) - in gfx_fb_putimage()
1885 gs = 8 - (fls(gfx_state.tg_fb.fb_mask_green) - in gfx_fb_putimage()
1887 bs = 8 - (fls(gfx_state.tg_fb.fb_mask_blue) - in gfx_fb_putimage()
1893 uint32_t hc1 = 0x80 - hc2; in gfx_fb_putimage()
1901 uint32_t wc1 = 0x80 - wc2; in gfx_fb_putimage()
1909 if (!scale) { in gfx_fb_putimage()
1911 r = png->image[i]; in gfx_fb_putimage()
1912 g = png->image[i + 1]; in gfx_fb_putimage()
1913 b = png->image[i + 2]; in gfx_fb_putimage()
1914 a = png->image[i + 3]; in gfx_fb_putimage()
1945 (png->image[p00 + i] * hc1 + in gfx_fb_putimage()
1946 png->image[p01 + i] * hc2) * wc1 + in gfx_fb_putimage()
1947 (png->image[p10 + i] * hc1 + in gfx_fb_putimage()
1948 png->image[p11 + i] * hc2) * wc2) in gfx_fb_putimage()
1986 fl->font_flags = FONT_AUTO; in reset_font_flags()
1999 w = edid_info->display.max_horizontal_image_size; in edid_diagonal_squared()
2000 h = edid_info->display.max_vertical_image_size; in edid_diagonal_squared()
2014 * translate cm to inch, note we scale by 100 here. in edid_diagonal_squared()
2069 * We are using scale up by 10 for roundup. in gfx_get_font()
2082 if (next == NULL || next->font_data->vfbd_height < size) { in gfx_get_font()
2083 font = fl->font_data; in gfx_get_font()
2084 if (font->vfbd_font == NULL || in gfx_get_font()
2085 fl->font_flags == FONT_RELOAD) { in gfx_get_font()
2086 if (fl->font_load != NULL && in gfx_get_font()
2087 fl->font_name != NULL) in gfx_get_font()
2088 font = fl->font_load(fl->font_name); in gfx_get_font()
2109 if (fl->font_flags == FONT_MANUAL) { in set_font()
2110 font = fl->font_data; in set_font()
2111 if (font->vfbd_font == NULL && fl->font_load != NULL && in set_font()
2112 fl->font_name != NULL) { in set_font()
2113 font = fl->font_load(fl->font_name); in set_font()
2115 if (font == NULL || font->vfbd_font == NULL) in set_font()
2125 *rows = height / font->vfbd_height; in set_font()
2126 *cols = width / font->vfbd_width; in set_font()
2136 font = fl->font_data; in set_font()
2137 if ((*rows * font->vfbd_height <= height && in set_font()
2138 *cols * font->vfbd_width <= width) || in set_font()
2141 font->vfbd_height == DEFAULT_FONT_DATA.vfbd_height && in set_font()
2142 font->vfbd_width == DEFAULT_FONT_DATA.vfbd_width)) { in set_font()
2143 if (font->vfbd_font == NULL || in set_font()
2144 fl->font_flags == FONT_RELOAD) { in set_font()
2145 if (fl->font_load != NULL && in set_font()
2146 fl->font_name != NULL) { in set_font()
2147 font = fl->font_load(fl->font_name); in set_font()
2152 *rows = height / font->vfbd_height; in set_font()
2153 *cols = width / font->vfbd_width; in set_font()
2165 if (fl != NULL && fl->font_load != NULL && in set_font()
2166 fl->font_name != NULL) { in set_font()
2167 font = fl->font_load(fl->font_name); in set_font()
2172 *rows = height / font->vfbd_height; in set_font()
2173 *cols = width / font->vfbd_width; in set_font()
2186 gfx_state.tg_functions->tf_param(&gfx_state, TP_SHOWCURSOR, 0); in cons_clear()
2193 teken_pos_t *tp = &state->tg_tp; in setup_font()
2204 font_data = set_font(&tp->tp_row, &tp->tp_col, height, width); in setup_font()
2210 state->tg_font.vf_map[i] = in setup_font()
2211 font_data->vfbd_font->vf_map[i]; in setup_font()
2212 state->tg_font.vf_map_count[i] = in setup_font()
2213 font_data->vfbd_font->vf_map_count[i]; in setup_font()
2216 state->tg_font.vf_bytes = font_data->vfbd_font->vf_bytes; in setup_font()
2217 state->tg_font.vf_height = font_data->vfbd_font->vf_height; in setup_font()
2218 state->tg_font.vf_width = font_data->vfbd_font->vf_width; in setup_font()
2221 state->tg_font.vf_width, state->tg_font.vf_height); in setup_font()
2230 unsigned min, mid, max; in font_bisearch() local
2233 max = len - 1; in font_bisearch()
2243 return (src - map[0].vfm_src + map[0].vfm_dst); in font_bisearch()
2250 mid = (min + max) / 2; in font_bisearch()
2251 if (src < map[mid].vfm_src) in font_bisearch()
2252 max = mid - 1; in font_bisearch()
2253 else if (src > map[mid].vfm_src + map[mid].vfm_len) in font_bisearch()
2254 min = mid + 1; in font_bisearch()
2256 return (src - map[mid].vfm_src + map[mid].vfm_dst); in font_bisearch()
2273 if (a->ta_format & TF_BOLD) { in font_lookup()
2274 dst = font_bisearch(vf->vf_map[VFNT_MAP_BOLD], in font_lookup()
2275 vf->vf_map_count[VFNT_MAP_BOLD], c); in font_lookup()
2279 dst = font_bisearch(vf->vf_map[VFNT_MAP_NORMAL], in font_lookup()
2280 vf->vf_map_count[VFNT_MAP_NORMAL], c); in font_lookup()
2283 stride = howmany(vf->vf_width, 8) * vf->vf_height; in font_lookup()
2284 return (&vf->vf_bytes[dst * stride]); in font_lookup()
2294 if (fp->vf_map_count[n] == 0) in load_mapping()
2297 size = fp->vf_map_count[n] * sizeof(*mp); in load_mapping()
2301 fp->vf_map[n] = mp; in load_mapping()
2305 free(fp->vf_map[n]); in load_mapping()
2306 fp->vf_map[n] = NULL; in load_mapping()
2310 for (i = 0; i < fp->vf_map_count[n]; i++) { in load_mapping()
2327 if (fp->vf_map_count[n] == 0) in builtin_mapping()
2330 size = fp->vf_map_count[n] * sizeof(*mp); in builtin_mapping()
2334 fp->vf_map[n] = mp; in builtin_mapping()
2336 memcpy(mp, DEFAULT_FONT_DATA.vfbd_font->vf_map[n], size); in builtin_mapping()
2361 if (strcmp(fl->font_name, path) == 0) in load_font()
2367 bp = fl->font_data; in load_font()
2368 if (bp->vfbd_font != NULL && fl->font_flags != FONT_RELOAD) in load_font()
2371 fd = -1; in load_font()
2377 if (fl->font_flags == FONT_BUILTIN) { in load_font()
2381 fp->vf_width = DEFAULT_FONT_DATA.vfbd_width; in load_font()
2382 fp->vf_height = DEFAULT_FONT_DATA.vfbd_height; in load_font()
2384 fp->vf_bytes = malloc(DEFAULT_FONT_DATA.vfbd_uncompressed_size); in load_font()
2385 if (fp->vf_bytes == NULL) { in load_font()
2390 bp->vfbd_uncompressed_size = in load_font()
2392 bp->vfbd_compressed_size = in load_font()
2396 fp->vf_bytes, in load_font()
2399 free(fp->vf_bytes); in load_font()
2405 fp->vf_map_count[i] = in load_font()
2406 DEFAULT_FONT_DATA.vfbd_font->vf_map_count[i]; in load_font()
2411 bp->vfbd_font = fp; in load_font()
2434 fp->vf_map_count[i] = be32toh(fh.fh_map_count[i]); in load_font()
2437 fp->vf_width = fh.fh_width; in load_font()
2438 fp->vf_height = fh.fh_height; in load_font()
2440 size = howmany(fp->vf_width, 8) * fp->vf_height * glyphs; in load_font()
2441 bp->vfbd_uncompressed_size = size; in load_font()
2442 if ((fp->vf_bytes = malloc(size)) == NULL) in load_font()
2445 rv = read(fd, fp->vf_bytes, size); in load_font()
2456 if (fl->font_flags == FONT_BUILTIN) in load_font()
2457 fl->font_flags = FONT_AUTO; in load_font()
2463 * We do need to keep fl->font_data for glyph dimensions. in load_font()
2466 if (fl->font_data->vfbd_font == NULL) in load_font()
2470 free(fl->font_data->vfbd_font->vf_map[i]); in load_font()
2471 free(fl->font_data->vfbd_font->vf_bytes); in load_font()
2472 free(fl->font_data->vfbd_font); in load_font()
2473 fl->font_data->vfbd_font = NULL; in load_font()
2476 bp->vfbd_font = fp; in load_font()
2477 bp->vfbd_compressed_size = 0; in load_font()
2480 if (fd != -1) in load_font()
2486 free(fp->vf_map[i]); in load_font()
2487 free(fp->vf_bytes); in load_font()
2551 if (asprintf(&np->n_name, "%s/%s", dir, buf) < 0) { in read_list()
2620 if (fh.fh_width == entry->font_data->vfbd_width && in insert_font()
2621 fh.fh_height == entry->font_data->vfbd_height) { in insert_font()
2622 free(entry->font_name); in insert_font()
2623 entry->font_name = font_name; in insert_font()
2624 entry->font_flags = FONT_RELOAD; in insert_font()
2635 fp->font_data = calloc(sizeof(*fp->font_data), 1); in insert_font()
2636 if (fp->font_data == NULL) { in insert_font()
2641 fp->font_name = font_name; in insert_font()
2642 fp->font_flags = flags; in insert_font()
2643 fp->font_load = load_font; in insert_font()
2644 fp->font_data->vfbd_width = fh.fh_width; in insert_font()
2645 fp->font_data->vfbd_height = fh.fh_height; in insert_font()
2654 size = fp->font_data->vfbd_width * fp->font_data->vfbd_height; in insert_font()
2659 bd = entry->font_data; in insert_font()
2661 if (size > bd->vfbd_width * bd->vfbd_height) { in insert_font()
2673 size > next->font_data->vfbd_width * in insert_font()
2674 next->font_data->vfbd_height) { in insert_font()
2703 if (fl->font_data->vfbd_width == x && in font_set()
2704 fl->font_data->vfbd_height == y) in font_set()
2712 fl->font_flags = FONT_MANUAL; in font_set()
2719 printf(" %dx%d\n", fl->font_data->vfbd_width, in font_set()
2720 fl->font_data->vfbd_height); in font_set()
2749 if (insert_font(np->n_name, FONT_AUTO) == false) in autoload_font()
2750 printf("failed to add font: %s\n", np->n_name); in autoload_font()
2751 free(np->n_name); in autoload_font()
2782 while ((c = getopt(argc, argv, "l")) != -1) { in command_font()
2793 argc -= optind; in command_font()
2797 printf("Usage: loadfont [-l] | [file.fnt]\n"); in command_font()
2803 printf("font %s: %dx%d%s\n", fl->font_name, in command_font()
2804 fl->font_data->vfbd_width, in command_font()
2805 fl->font_data->vfbd_height, in command_font()
2806 fl->font_data->vfbd_font == NULL? "" : " loaded"); in command_font()
2833 if (fl->font_data->vfbd_font != NULL) { in command_font()
2835 bd = fl->font_data; in command_font()
2841 free(bd->vfbd_font->vf_map[i]); in command_font()
2842 free(fl->font_data->vfbd_font); in command_font()
2843 fl->font_data->vfbd_font = NULL; in command_font()
2844 fl->font_data->vfbd_uncompressed_size = 0; in command_font()
2845 fl->font_flags = FONT_AUTO; in command_font()
2861 if ((edid->display.supported_features in gfx_get_edid_resolution()
2868 if (edid->detailed_timings[i].pixel_clock == 0) in gfx_get_edid_resolution()
2872 rp->width = GET_EDID_INFO_WIDTH(edid, i); in gfx_get_edid_resolution()
2873 rp->height = GET_EDID_INFO_HEIGHT(edid, i); in gfx_get_edid_resolution()
2874 if (rp->width > 0 && rp->width <= EDID_MAX_PIXELS && in gfx_get_edid_resolution()
2875 rp->height > 0 && rp->height <= EDID_MAX_LINES) in gfx_get_edid_resolution()
2887 if (edid->standard_timings[i] == 0x0101) in gfx_get_edid_resolution()
2893 rp->width = HSIZE(edid->standard_timings[i]); in gfx_get_edid_resolution()
2894 switch (RATIO(edid->standard_timings[i])) { in gfx_get_edid_resolution()
2896 rp->height = HSIZE(edid->standard_timings[i]); in gfx_get_edid_resolution()
2897 if (edid->header.version > 1 || in gfx_get_edid_resolution()
2898 edid->header.revision > 2) { in gfx_get_edid_resolution()
2899 rp->height = rp->height * 10 / 16; in gfx_get_edid_resolution()
2903 rp->height = HSIZE(edid->standard_timings[i]) * 3 / 4; in gfx_get_edid_resolution()
2906 rp->height = HSIZE(edid->standard_timings[i]) * 4 / 5; in gfx_get_edid_resolution()
2909 rp->height = HSIZE(edid->standard_timings[i]) * 9 / 16; in gfx_get_edid_resolution()
2918 if (p->width * p->height < rp->width * rp->height) { in gfx_get_edid_resolution()
2961 if (gfx_state.tg_font.vf_width == fl->font_data->vfbd_width && in build_font_module()
2962 gfx_state.tg_font.vf_height == fl->font_data->vfbd_height) { in build_font_module()
2966 if (fl->font_flags == FONT_BUILTIN) in build_font_module()
2969 bd = fl->font_data; in build_font_module()
2975 fd = bd->vfbd_font; in build_font_module()
2977 fi.fi_width = fd->vf_width; in build_font_module()
2979 fi.fi_height = fd->vf_height; in build_font_module()
2981 fi.fi_bitmap_size = bd->vfbd_uncompressed_size; in build_font_module()
2986 fi.fi_map_count[i] = fd->vf_map_count[i]; in build_font_module()
2988 size += fd->vf_map_count[i] * sizeof (struct vfnt_map); in build_font_module()
2991 size += bd->vfbd_uncompressed_size; in build_font_module()
2993 fi.fi_checksum = -checksum; in build_font_module()
3005 if (fd->vf_map_count[i] != 0) { in build_font_module()
3006 addr += archsw.arch_copyin(fd->vf_map[i], addr, in build_font_module()
3007 fd->vf_map_count[i] * sizeof (struct vfnt_map)); in build_font_module()
3013 addr += archsw.arch_copyin(fd->vf_bytes, addr, fi.fi_bitmap_size); in build_font_module()