diff options
Diffstat (limited to 'firmware/drivers/lcd-2bit-vert.c')
-rw-r--r-- | firmware/drivers/lcd-2bit-vert.c | 145 |
1 files changed, 17 insertions, 128 deletions
diff --git a/firmware/drivers/lcd-2bit-vert.c b/firmware/drivers/lcd-2bit-vert.c index b206a2d816..5fd86c409a 100644 --- a/firmware/drivers/lcd-2bit-vert.c +++ b/firmware/drivers/lcd-2bit-vert.c | |||
@@ -91,6 +91,8 @@ static void *lcd_frameaddress_default(int x, int y) | |||
91 | return fb->fb_ptr + element; /*(element % fb->elems);*/ | 91 | return fb->fb_ptr + element; /*(element % fb->elems);*/ |
92 | } | 92 | } |
93 | 93 | ||
94 | #include "lcd-bitmap-common.c" | ||
95 | |||
94 | /* LCD init */ | 96 | /* LCD init */ |
95 | void lcd_init(void) | 97 | void lcd_init(void) |
96 | { | 98 | { |
@@ -420,10 +422,8 @@ void lcd_clear_viewport(void) | |||
420 | /* Set a single pixel */ | 422 | /* Set a single pixel */ |
421 | void lcd_drawpixel(int x, int y) | 423 | void lcd_drawpixel(int x, int y) |
422 | { | 424 | { |
423 | if ( ((unsigned)x < (unsigned)lcd_current_viewport->width) | 425 | if (lcd_clip_viewport_pixel(&x, &y)) |
424 | && ((unsigned)y < (unsigned)lcd_current_viewport->height) | 426 | lcd_pixelfuncs[lcd_current_viewport->drawmode](x, y); |
425 | ) | ||
426 | lcd_pixelfuncs[lcd_current_viewport->drawmode](lcd_current_viewport->x + x, lcd_current_viewport->y + y); | ||
427 | } | 427 | } |
428 | 428 | ||
429 | /* Draw a line */ | 429 | /* Draw a line */ |
@@ -435,6 +435,7 @@ void lcd_drawline(int x1, int y1, int x2, int y2) | |||
435 | int d, dinc1, dinc2; | 435 | int d, dinc1, dinc2; |
436 | int x, xinc1, xinc2; | 436 | int x, xinc1, xinc2; |
437 | int y, yinc1, yinc2; | 437 | int y, yinc1, yinc2; |
438 | int x_vp, y_vp, w_vp, h_vp; | ||
438 | lcd_pixelfunc_type *pfunc = lcd_pixelfuncs[lcd_current_viewport->drawmode]; | 439 | lcd_pixelfunc_type *pfunc = lcd_pixelfuncs[lcd_current_viewport->drawmode]; |
439 | 440 | ||
440 | deltax = abs(x2 - x1); | 441 | deltax = abs(x2 - x1); |
@@ -489,12 +490,15 @@ void lcd_drawline(int x1, int y1, int x2, int y2) | |||
489 | x = x1; | 490 | x = x1; |
490 | y = y1; | 491 | y = y1; |
491 | 492 | ||
493 | x_vp = lcd_current_viewport->x; | ||
494 | y_vp = lcd_current_viewport->y; | ||
495 | w_vp = lcd_current_viewport->width; | ||
496 | h_vp = lcd_current_viewport->height; | ||
497 | |||
492 | for (i = 0; i < numpixels; i++) | 498 | for (i = 0; i < numpixels; i++) |
493 | { | 499 | { |
494 | if ( ((unsigned)x < (unsigned)lcd_current_viewport->width) | 500 | if (x >= 0 && y >= 0 && x < w_vp && y < h_vp) |
495 | && ((unsigned)y < (unsigned)lcd_current_viewport->height) | 501 | pfunc(x + x_vp, y + y_vp); |
496 | ) | ||
497 | pfunc(lcd_current_viewport->x + x, lcd_current_viewport->y + y); | ||
498 | 502 | ||
499 | if (d < 0) | 503 | if (d < 0) |
500 | { | 504 | { |
@@ -514,36 +518,14 @@ void lcd_drawline(int x1, int y1, int x2, int y2) | |||
514 | /* Draw a horizontal line (optimised) */ | 518 | /* Draw a horizontal line (optimised) */ |
515 | void lcd_hline(int x1, int x2, int y) | 519 | void lcd_hline(int x1, int x2, int y) |
516 | { | 520 | { |
517 | int x; | ||
518 | int width; | 521 | int width; |
519 | fb_data *dst, *dst_end; | 522 | fb_data *dst, *dst_end; |
520 | unsigned mask; | 523 | unsigned mask; |
521 | lcd_blockfunc_type *bfunc; | 524 | lcd_blockfunc_type *bfunc; |
522 | 525 | ||
523 | /* direction flip */ | 526 | if (!lcd_clip_viewport_hline(&x1, &x2, &y)) |
524 | if (x2 < x1) | ||
525 | { | ||
526 | x = x1; | ||
527 | x1 = x2; | ||
528 | x2 = x; | ||
529 | } | ||
530 | |||
531 | /******************** In viewport clipping **********************/ | ||
532 | /* nothing to draw? */ | ||
533 | if (((unsigned)y >= (unsigned)lcd_current_viewport->height) || (x1 >= lcd_current_viewport->width) | ||
534 | || (x2 < 0)) | ||
535 | return; | 527 | return; |
536 | 528 | ||
537 | if (x1 < 0) | ||
538 | x1 = 0; | ||
539 | if (x2 >= lcd_current_viewport->width) | ||
540 | x2 = lcd_current_viewport->width-1; | ||
541 | |||
542 | /* adjust x1 and y to viewport */ | ||
543 | x1 += lcd_current_viewport->x; | ||
544 | x2 += lcd_current_viewport->x; | ||
545 | y += lcd_current_viewport->y; | ||
546 | |||
547 | width = x2 - x1 + 1; | 529 | width = x2 - x1 + 1; |
548 | 530 | ||
549 | bfunc = lcd_blockfuncs[lcd_current_viewport->drawmode]; | 531 | bfunc = lcd_blockfuncs[lcd_current_viewport->drawmode]; |
@@ -565,30 +547,9 @@ void lcd_vline(int x, int y1, int y2) | |||
565 | unsigned mask, mask_bottom; | 547 | unsigned mask, mask_bottom; |
566 | lcd_blockfunc_type *bfunc; | 548 | lcd_blockfunc_type *bfunc; |
567 | 549 | ||
568 | /* direction flip */ | 550 | if (!lcd_clip_viewport_vline(&x, &y1, &y2)) |
569 | if (y2 < y1) | ||
570 | { | ||
571 | ny = y1; | ||
572 | y1 = y2; | ||
573 | y2 = ny; | ||
574 | } | ||
575 | |||
576 | /******************** In viewport clipping **********************/ | ||
577 | /* nothing to draw? */ | ||
578 | if (((unsigned)x >= (unsigned)lcd_current_viewport->width) || (y1 >= lcd_current_viewport->height) | ||
579 | || (y2 < 0)) | ||
580 | return; | 551 | return; |
581 | 552 | ||
582 | if (y1 < 0) | ||
583 | y1 = 0; | ||
584 | if (y2 >= lcd_current_viewport->height) | ||
585 | y2 = lcd_current_viewport->height-1; | ||
586 | |||
587 | /* adjust for viewport */ | ||
588 | y1 += lcd_current_viewport->y; | ||
589 | y2 += lcd_current_viewport->y; | ||
590 | x += lcd_current_viewport->x; | ||
591 | |||
592 | bfunc = lcd_blockfuncs[lcd_current_viewport->drawmode]; | 553 | bfunc = lcd_blockfuncs[lcd_current_viewport->drawmode]; |
593 | dst = FBADDR(x,y1>>2); | 554 | dst = FBADDR(x,y1>>2); |
594 | stride_dst = lcd_current_viewport->buffer->stride; | 555 | stride_dst = lcd_current_viewport->buffer->stride; |
@@ -632,31 +593,9 @@ void lcd_fillrect(int x, int y, int width, int height) | |||
632 | lcd_blockfunc_type *bfunc; | 593 | lcd_blockfunc_type *bfunc; |
633 | bool fillopt = false; | 594 | bool fillopt = false; |
634 | 595 | ||
635 | /******************** In viewport clipping **********************/ | 596 | if (!lcd_clip_viewport_rect(&x, &y, &width, &height, NULL, NULL)) |
636 | /* nothing to draw? */ | ||
637 | if ((width <= 0) || (height <= 0) || (x >= lcd_current_viewport->width) | ||
638 | || (y >= lcd_current_viewport->height) || (x + width <= 0) || (y + height <= 0)) | ||
639 | return; | 597 | return; |
640 | 598 | ||
641 | if (x < 0) | ||
642 | { | ||
643 | width += x; | ||
644 | x = 0; | ||
645 | } | ||
646 | if (y < 0) | ||
647 | { | ||
648 | height += y; | ||
649 | y = 0; | ||
650 | } | ||
651 | if (x + width > lcd_current_viewport->width) | ||
652 | width = lcd_current_viewport->width - x; | ||
653 | if (y + height > lcd_current_viewport->height) | ||
654 | height = lcd_current_viewport->height - y; | ||
655 | |||
656 | /* adjust for viewport */ | ||
657 | x += lcd_current_viewport->x; | ||
658 | y += lcd_current_viewport->y; | ||
659 | |||
660 | if (lcd_current_viewport->drawmode & DRMODE_INVERSEVID) | 599 | if (lcd_current_viewport->drawmode & DRMODE_INVERSEVID) |
661 | { | 600 | { |
662 | if ((lcd_current_viewport->drawmode & DRMODE_BG) && !lcd_backdrop) | 601 | if ((lcd_current_viewport->drawmode & DRMODE_BG) && !lcd_backdrop) |
@@ -732,33 +671,9 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x, | |||
732 | unsigned mask, mask_bottom; | 671 | unsigned mask, mask_bottom; |
733 | lcd_blockfunc_type *bfunc; | 672 | lcd_blockfunc_type *bfunc; |
734 | 673 | ||
735 | /******************** Image in viewport clipping **********************/ | 674 | if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y)) |
736 | /* nothing to draw? */ | ||
737 | if ((width <= 0) || (height <= 0) || (x >= lcd_current_viewport->width) || | ||
738 | (y >= lcd_current_viewport->height) || (x + width <= 0) || (y + height <= 0)) | ||
739 | return; | 675 | return; |
740 | 676 | ||
741 | if (x < 0) | ||
742 | { | ||
743 | width += x; | ||
744 | src_x -= x; | ||
745 | x = 0; | ||
746 | } | ||
747 | if (y < 0) | ||
748 | { | ||
749 | height += y; | ||
750 | src_y -= y; | ||
751 | y = 0; | ||
752 | } | ||
753 | if (x + width > lcd_current_viewport->width) | ||
754 | width = lcd_current_viewport->width - x; | ||
755 | if (y + height > lcd_current_viewport->height) | ||
756 | height = lcd_current_viewport->height - y; | ||
757 | |||
758 | /* adjust for viewport */ | ||
759 | x += lcd_current_viewport->x; | ||
760 | y += lcd_current_viewport->y; | ||
761 | |||
762 | src += stride * (src_y >> 3) + src_x; /* move starting point */ | 677 | src += stride * (src_y >> 3) + src_x; /* move starting point */ |
763 | src_y &= 7; | 678 | src_y &= 7; |
764 | y -= src_y; | 679 | y -= src_y; |
@@ -905,33 +820,9 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y, | |||
905 | int stride_dst; | 820 | int stride_dst; |
906 | unsigned mask, mask_bottom; | 821 | unsigned mask, mask_bottom; |
907 | 822 | ||
908 | /******************** Image in viewport clipping **********************/ | 823 | if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y)) |
909 | /* nothing to draw? */ | ||
910 | if ((width <= 0) || (height <= 0) || (x >= lcd_current_viewport->width) | ||
911 | || (y >= lcd_current_viewport->height) || (x + width <= 0) || (y + height <= 0)) | ||
912 | return; | 824 | return; |
913 | 825 | ||
914 | if (x < 0) | ||
915 | { | ||
916 | width += x; | ||
917 | src_x -= x; | ||
918 | x = 0; | ||
919 | } | ||
920 | if (y < 0) | ||
921 | { | ||
922 | height += y; | ||
923 | src_y -= y; | ||
924 | y = 0; | ||
925 | } | ||
926 | if (x + width > lcd_current_viewport->width) | ||
927 | width = lcd_current_viewport->width - x; | ||
928 | if (y + height > lcd_current_viewport->height) | ||
929 | height = lcd_current_viewport->height - y; | ||
930 | |||
931 | /* adjust for viewport */ | ||
932 | x += lcd_current_viewport->x; | ||
933 | y += lcd_current_viewport->y; | ||
934 | |||
935 | src += stride * (src_y >> 2) + src_x; /* move starting point */ | 826 | src += stride * (src_y >> 2) + src_x; /* move starting point */ |
936 | src_y &= 3; | 827 | src_y &= 3; |
937 | y -= src_y; | 828 | y -= src_y; |
@@ -1014,5 +905,3 @@ void lcd_bitmap(const fb_data *src, int x, int y, int width, int height) | |||
1014 | { | 905 | { |
1015 | lcd_bitmap_part(src, 0, 0, width, x, y, width, height); | 906 | lcd_bitmap_part(src, 0, 0, width, x, y, width, height); |
1016 | } | 907 | } |
1017 | |||
1018 | #include "lcd-bitmap-common.c" | ||