summaryrefslogtreecommitdiffstats
path: root/firmware/drivers/lcd-2bit-vert.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/lcd-2bit-vert.c')
-rw-r--r--firmware/drivers/lcd-2bit-vert.c145
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)
return fb->fb_ptr + element; /*(element % fb->elems);*/
}
+#include "lcd-bitmap-common.c"
+
/* LCD init */
void lcd_init(void)
{
@@ -420,10 +422,8 @@ void lcd_clear_viewport(void)
/* Set a single pixel */
void lcd_drawpixel(int x, int y)
{
- if ( ((unsigned)x < (unsigned)lcd_current_viewport->width)
- && ((unsigned)y < (unsigned)lcd_current_viewport->height)
- )
- lcd_pixelfuncs[lcd_current_viewport->drawmode](lcd_current_viewport->x + x, lcd_current_viewport->y + y);
+ if (lcd_clip_viewport_pixel(&x, &y))
+ lcd_pixelfuncs[lcd_current_viewport->drawmode](x, y);
}
/* Draw a line */
@@ -435,6 +435,7 @@ void lcd_drawline(int x1, int y1, int x2, int y2)
int d, dinc1, dinc2;
int x, xinc1, xinc2;
int y, yinc1, yinc2;
+ int x_vp, y_vp, w_vp, h_vp;
lcd_pixelfunc_type *pfunc = lcd_pixelfuncs[lcd_current_viewport->drawmode];
deltax = abs(x2 - x1);
@@ -489,12 +490,15 @@ void lcd_drawline(int x1, int y1, int x2, int y2)
x = x1;
y = y1;
+ x_vp = lcd_current_viewport->x;
+ y_vp = lcd_current_viewport->y;
+ w_vp = lcd_current_viewport->width;
+ h_vp = lcd_current_viewport->height;
+
for (i = 0; i < numpixels; i++)
{
- if ( ((unsigned)x < (unsigned)lcd_current_viewport->width)
- && ((unsigned)y < (unsigned)lcd_current_viewport->height)
- )
- pfunc(lcd_current_viewport->x + x, lcd_current_viewport->y + y);
+ if (x >= 0 && y >= 0 && x < w_vp && y < h_vp)
+ pfunc(x + x_vp, y + y_vp);
if (d < 0)
{
@@ -514,36 +518,14 @@ void lcd_drawline(int x1, int y1, int x2, int y2)
/* Draw a horizontal line (optimised) */
void lcd_hline(int x1, int x2, int y)
{
- int x;
int width;
fb_data *dst, *dst_end;
unsigned mask;
lcd_blockfunc_type *bfunc;
- /* direction flip */
- if (x2 < x1)
- {
- x = x1;
- x1 = x2;
- x2 = x;
- }
-
- /******************** In viewport clipping **********************/
- /* nothing to draw? */
- if (((unsigned)y >= (unsigned)lcd_current_viewport->height) || (x1 >= lcd_current_viewport->width)
- || (x2 < 0))
+ if (!lcd_clip_viewport_hline(&x1, &x2, &y))
return;
- if (x1 < 0)
- x1 = 0;
- if (x2 >= lcd_current_viewport->width)
- x2 = lcd_current_viewport->width-1;
-
- /* adjust x1 and y to viewport */
- x1 += lcd_current_viewport->x;
- x2 += lcd_current_viewport->x;
- y += lcd_current_viewport->y;
-
width = x2 - x1 + 1;
bfunc = lcd_blockfuncs[lcd_current_viewport->drawmode];
@@ -565,30 +547,9 @@ void lcd_vline(int x, int y1, int y2)
unsigned mask, mask_bottom;
lcd_blockfunc_type *bfunc;
- /* direction flip */
- if (y2 < y1)
- {
- ny = y1;
- y1 = y2;
- y2 = ny;
- }
-
- /******************** In viewport clipping **********************/
- /* nothing to draw? */
- if (((unsigned)x >= (unsigned)lcd_current_viewport->width) || (y1 >= lcd_current_viewport->height)
- || (y2 < 0))
+ if (!lcd_clip_viewport_vline(&x, &y1, &y2))
return;
- if (y1 < 0)
- y1 = 0;
- if (y2 >= lcd_current_viewport->height)
- y2 = lcd_current_viewport->height-1;
-
- /* adjust for viewport */
- y1 += lcd_current_viewport->y;
- y2 += lcd_current_viewport->y;
- x += lcd_current_viewport->x;
-
bfunc = lcd_blockfuncs[lcd_current_viewport->drawmode];
dst = FBADDR(x,y1>>2);
stride_dst = lcd_current_viewport->buffer->stride;
@@ -632,31 +593,9 @@ void lcd_fillrect(int x, int y, int width, int height)
lcd_blockfunc_type *bfunc;
bool fillopt = false;
- /******************** In viewport clipping **********************/
- /* nothing to draw? */
- if ((width <= 0) || (height <= 0) || (x >= lcd_current_viewport->width)
- || (y >= lcd_current_viewport->height) || (x + width <= 0) || (y + height <= 0))
+ if (!lcd_clip_viewport_rect(&x, &y, &width, &height, NULL, NULL))
return;
- if (x < 0)
- {
- width += x;
- x = 0;
- }
- if (y < 0)
- {
- height += y;
- y = 0;
- }
- if (x + width > lcd_current_viewport->width)
- width = lcd_current_viewport->width - x;
- if (y + height > lcd_current_viewport->height)
- height = lcd_current_viewport->height - y;
-
- /* adjust for viewport */
- x += lcd_current_viewport->x;
- y += lcd_current_viewport->y;
-
if (lcd_current_viewport->drawmode & DRMODE_INVERSEVID)
{
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,
unsigned mask, mask_bottom;
lcd_blockfunc_type *bfunc;
- /******************** Image in viewport clipping **********************/
- /* nothing to draw? */
- if ((width <= 0) || (height <= 0) || (x >= lcd_current_viewport->width) ||
- (y >= lcd_current_viewport->height) || (x + width <= 0) || (y + height <= 0))
+ if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
return;
- if (x < 0)
- {
- width += x;
- src_x -= x;
- x = 0;
- }
- if (y < 0)
- {
- height += y;
- src_y -= y;
- y = 0;
- }
- if (x + width > lcd_current_viewport->width)
- width = lcd_current_viewport->width - x;
- if (y + height > lcd_current_viewport->height)
- height = lcd_current_viewport->height - y;
-
- /* adjust for viewport */
- x += lcd_current_viewport->x;
- y += lcd_current_viewport->y;
-
src += stride * (src_y >> 3) + src_x; /* move starting point */
src_y &= 7;
y -= src_y;
@@ -905,33 +820,9 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
int stride_dst;
unsigned mask, mask_bottom;
- /******************** Image in viewport clipping **********************/
- /* nothing to draw? */
- if ((width <= 0) || (height <= 0) || (x >= lcd_current_viewport->width)
- || (y >= lcd_current_viewport->height) || (x + width <= 0) || (y + height <= 0))
+ if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
return;
- if (x < 0)
- {
- width += x;
- src_x -= x;
- x = 0;
- }
- if (y < 0)
- {
- height += y;
- src_y -= y;
- y = 0;
- }
- if (x + width > lcd_current_viewport->width)
- width = lcd_current_viewport->width - x;
- if (y + height > lcd_current_viewport->height)
- height = lcd_current_viewport->height - y;
-
- /* adjust for viewport */
- x += lcd_current_viewport->x;
- y += lcd_current_viewport->y;
-
src += stride * (src_y >> 2) + src_x; /* move starting point */
src_y &= 3;
y -= src_y;
@@ -1014,5 +905,3 @@ void lcd_bitmap(const fb_data *src, int x, int y, int width, int height)
{
lcd_bitmap_part(src, 0, 0, width, x, y, width, height);
}
-
-#include "lcd-bitmap-common.c"