Lines Matching +full:start +full:- +full:from +full:- +full:bottom

4  * SPDX-License-Identifier: Apache-2.0
20 #define MSB_BIT_MASK(x) (BIT_MASK(x) << (8 - x))
72 return (uint8_t *)fptr->data + in get_glyph_ptr()
73 (c - fptr->first_char) * in get_glyph_ptr()
74 (fptr->width * fptr->height / 8U); in get_glyph_ptr()
80 if (fptr->caps & CFB_FONT_MONO_VPACKED) { in get_glyph_byte()
81 return glyph_ptr[x * (fptr->height / 8U) + y]; in get_glyph_byte()
82 } else if (fptr->caps & CFB_FONT_MONO_HPACKED) { in get_glyph_byte()
83 return glyph_ptr[y * (fptr->width) + x]; in get_glyph_byte()
98 const struct cfb_font *fptr = &(fb->fonts[fb->font_idx]); in draw_char_vtmono()
99 const bool font_is_msbfirst = ((fptr->caps & CFB_FONT_MSB_FIRST) != 0); in draw_char_vtmono()
101 (((fb->screen_info & SCREEN_INFO_MONO_MSB_FIRST) != 0) != font_is_msbfirst); in draw_char_vtmono()
104 if (c < fptr->first_char || c > fptr->last_char) { in draw_char_vtmono()
113 for (size_t g_x = 0; g_x < fptr->width; g_x++) { in draw_char_vtmono()
116 for (size_t g_y = 0; g_y < fptr->height;) { in draw_char_vtmono()
119 * by separating per 8-line boundaries. in draw_char_vtmono()
123 const size_t fb_index = (fb_y / 8U) * fb->x_res + fb_x; in draw_char_vtmono()
125 const uint8_t bottom_lines = ((offset + fptr->height) % 8); in draw_char_vtmono()
130 if (fb_x < 0 || fb->x_res <= fb_x || fb_y < 0 || fb->y_res <= fb_y) { in draw_char_vtmono()
138 * starting to draw with a tile-aligned position case. in draw_char_vtmono()
151 * Extract the necessary 8 bits from the combined 2 tiles of glyphs. in draw_char_vtmono()
159 bg_mask = BIT_MASK(8 - offset); in draw_char_vtmono()
168 byte = ((next_byte << 8) | byte) >> (8 - offset); in draw_char_vtmono()
170 bg_mask = BIT_MASK(8 - offset) << offset; in draw_char_vtmono()
177 * Clip the bottom margin to protect existing draw contents. in draw_char_vtmono()
179 if (((fptr->height - g_y) < 8) && (bottom_lines != 0)) { in draw_char_vtmono()
191 fb->buf[fb_index] &= ~bg_mask; in draw_char_vtmono()
197 fb->buf[fb_index] |= byte; in draw_char_vtmono()
200 g_y += (8 - offset); in draw_char_vtmono()
201 } else if ((fptr->height - g_y) >= 8) { in draw_char_vtmono()
209 return fptr->width; in draw_char_vtmono()
214 const bool need_reverse = ((fb->screen_info & SCREEN_INFO_MONO_MSB_FIRST) != 0); in draw_point()
215 const size_t index = ((y / 8) * fb->x_res); in draw_point()
218 if (x < 0 || x >= fb->x_res) { in draw_point()
222 if (y < 0 || y >= fb->y_res) { in draw_point()
230 fb->buf[index + x] |= m; in draw_point()
235 int16_t sx = (x0 < x1) ? 1 : -1; in draw_line()
236 int16_t sy = (y0 < y1) ? 1 : -1; in draw_line()
237 int16_t dx = (sx > 0) ? (x1 - x0) : (x0 - x1); in draw_line()
238 int16_t dy = (sy > 0) ? (y0 - y1) : (y1 - y0); in draw_line()
269 if (!fb->fonts || !fb->buf) { in draw_text()
270 return -ENODEV; in draw_text()
273 fptr = &(fb->fonts[fb->font_idx]); in draw_text()
275 if (fptr->height % 8) { in draw_text()
277 return -EINVAL; in draw_text()
280 if ((fb->screen_info & SCREEN_INFO_MONO_VTILED)) { in draw_text()
284 if ((x + fptr->width > fb->x_res) && wrap) { in draw_text()
286 y += fptr->height; in draw_text()
288 x += fb->kerning + draw_char_vtmono(fb, str[i], x, y, wrap); in draw_text()
294 return -EINVAL; in draw_text()
301 draw_point(fb, pos->x, pos->y); in cfb_draw_point()
306 int cfb_draw_line(const struct device *dev, const struct cfb_position *start, in cfb_draw_line() argument
311 draw_line(fb, start->x, start->y, end->x, end->y); in cfb_draw_line()
316 int cfb_draw_rect(const struct device *dev, const struct cfb_position *start, in cfb_draw_rect() argument
321 draw_line(fb, start->x, start->y, end->x, start->y); in cfb_draw_rect()
322 draw_line(fb, end->x, start->y, end->x, end->y); in cfb_draw_rect()
323 draw_line(fb, end->x, end->y, start->x, end->y); in cfb_draw_rect()
324 draw_line(fb, start->x, end->y, start->x, start->y); in cfb_draw_rect()
343 const bool need_reverse = ((fb->screen_info & SCREEN_INFO_MONO_MSB_FIRST) != 0); in cfb_invert_area()
345 if (x >= fb->x_res || y >= fb->y_res) { in cfb_invert_area()
348 return -EINVAL; in cfb_invert_area()
351 if ((fb->screen_info & SCREEN_INFO_MONO_VTILED)) { in cfb_invert_area()
352 if (x > fb->x_res) { in cfb_invert_area()
353 x = fb->x_res; in cfb_invert_area()
356 if (y > fb->y_res) { in cfb_invert_area()
357 y = fb->y_res; in cfb_invert_area()
360 if (x + width > fb->x_res) { in cfb_invert_area()
361 width = fb->x_res - x; in cfb_invert_area()
364 if (y + height > fb->y_res) { in cfb_invert_area()
365 height = fb->y_res - y; in cfb_invert_area()
372 * by separating per 8-line boundaries. in cfb_invert_area()
375 const size_t index = ((j / 8) * fb->x_res) + i; in cfb_invert_area()
376 const uint8_t remains = y + height - j; in cfb_invert_area()
380 * between the start line or end line and the 8-line boundary. in cfb_invert_area()
384 uint8_t b = fb->buf[index]; in cfb_invert_area()
388 * drawing within 8 lines from the start line in cfb_invert_area()
391 m |= BIT_MASK((8 - (j % 8) + remains)) in cfb_invert_area()
399 fb->buf[index] = (b ^ (~m)); in cfb_invert_area()
400 j += 7 - (j % 8); in cfb_invert_area()
402 /* No mask required if no start or end line is included */ in cfb_invert_area()
403 fb->buf[index] = ~fb->buf[index]; in cfb_invert_area()
406 uint8_t m = BIT_MASK(8 - remains) << (remains); in cfb_invert_area()
407 uint8_t b = fb->buf[index]; in cfb_invert_area()
413 fb->buf[index] = (b ^ (~m)); in cfb_invert_area()
414 j += (remains - 1); in cfb_invert_area()
423 return -EINVAL; in cfb_invert_area()
428 for (size_t i = 0; i < fb->x_res * fb->y_res / 8U; i++) { in cfb_invert()
429 fb->buf[i] = ~fb->buf[i]; in cfb_invert()
439 if (!fb->buf) { in cfb_framebuffer_clear()
440 return -ENODEV; in cfb_framebuffer_clear()
443 memset(fb->buf, 0, fb->size); in cfb_framebuffer_clear()
456 fb->inverted = !fb->inverted; in cfb_framebuffer_invert()
463 const struct display_driver_api *api = dev->api; in cfb_framebuffer_finalize()
469 if (!fb->buf) { in cfb_framebuffer_finalize()
470 return -ENODEV; in cfb_framebuffer_finalize()
474 .buf_size = fb->size, in cfb_framebuffer_finalize()
475 .width = fb->x_res, in cfb_framebuffer_finalize()
476 .height = fb->y_res, in cfb_framebuffer_finalize()
477 .pitch = fb->x_res, in cfb_framebuffer_finalize()
480 if (!(fb->pixel_format & PIXEL_FORMAT_MONO10) != !(fb->inverted)) { in cfb_framebuffer_finalize()
482 err = api->write(dev, 0, 0, &desc, fb->buf); in cfb_framebuffer_finalize()
487 return api->write(dev, 0, 0, &desc, fb->buf); in cfb_framebuffer_finalize()
497 return fb->y_res; in cfb_get_display_parameter()
499 return fb->x_res; in cfb_get_display_parameter()
501 return fb->ppt; in cfb_get_display_parameter()
503 if (fb->screen_info & SCREEN_INFO_MONO_VTILED) { in cfb_get_display_parameter()
504 return fb->y_res / fb->ppt; in cfb_get_display_parameter()
506 return fb->y_res; in cfb_get_display_parameter()
508 if (fb->screen_info & SCREEN_INFO_MONO_VTILED) { in cfb_get_display_parameter()
509 return fb->x_res; in cfb_get_display_parameter()
511 return fb->x_res / fb->ppt; in cfb_get_display_parameter()
520 if (idx >= fb->numof_fonts) { in cfb_framebuffer_set_font()
521 return -EINVAL; in cfb_framebuffer_set_font()
524 fb->font_idx = idx; in cfb_framebuffer_set_font()
534 if (idx >= fb->numof_fonts) { in cfb_get_font_size()
535 return -EINVAL; in cfb_get_font_size()
560 return fb->numof_fonts; in cfb_get_numof_fonts()
565 const struct display_driver_api *api = dev->api; in cfb_framebuffer_init()
571 api->get_capabilities(dev, &cfg); in cfb_framebuffer_init()
573 STRUCT_SECTION_COUNT(cfb_font, &fb->numof_fonts); in cfb_framebuffer_init()
575 LOG_DBG("number of fonts %d", fb->numof_fonts); in cfb_framebuffer_init()
577 fb->x_res = cfg.x_resolution; in cfb_framebuffer_init()
578 fb->y_res = cfg.y_resolution; in cfb_framebuffer_init()
579 fb->ppt = 8U; in cfb_framebuffer_init()
580 fb->pixel_format = cfg.current_pixel_format; in cfb_framebuffer_init()
581 fb->screen_info = cfg.screen_info; in cfb_framebuffer_init()
582 fb->kerning = 0; in cfb_framebuffer_init()
583 fb->inverted = false; in cfb_framebuffer_init()
585 fb->fonts = TYPE_SECTION_START(cfb_font); in cfb_framebuffer_init()
586 fb->font_idx = 0U; in cfb_framebuffer_init()
588 fb->size = fb->x_res * fb->y_res / fb->ppt; in cfb_framebuffer_init()
589 fb->buf = k_malloc(fb->size); in cfb_framebuffer_init()
590 if (!fb->buf) { in cfb_framebuffer_init()
591 return -ENOMEM; in cfb_framebuffer_init()
594 memset(fb->buf, 0, fb->size); in cfb_framebuffer_init()
603 if (fb->buf) { in cfb_framebuffer_deinit()
604 k_free(fb->buf); in cfb_framebuffer_deinit()
605 fb->buf = NULL; in cfb_framebuffer_deinit()