summaryrefslogtreecommitdiffstats
path: root/firmware/drivers/lcd-2bit-vi.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/lcd-2bit-vi.c')
-rw-r--r--firmware/drivers/lcd-2bit-vi.c145
1 files changed, 17 insertions, 128 deletions
diff --git a/firmware/drivers/lcd-2bit-vi.c b/firmware/drivers/lcd-2bit-vi.c
index 0580705a05..b19fdba266 100644
--- a/firmware/drivers/lcd-2bit-vi.c
+++ b/firmware/drivers/lcd-2bit-vi.c
@@ -103,6 +103,8 @@ static void *LCDFN(frameaddress_default)(int x, int y)
return fb->FBFN(ptr) + element;/*(element % fb->elems);*/
}
+#include "lcd-bitmap-common.c"
+
/* LCD init */
void LCDFN(init)(void)
{
@@ -453,10 +455,8 @@ void LCDFN(clear_viewport)(void)
/* Set a single pixel */
void LCDFN(drawpixel)(int x, int y)
{
- if ( ((unsigned)x < (unsigned)CURRENT_VP->width)
- && ((unsigned)y < (unsigned)CURRENT_VP->height)
- )
- LCDFN(pixelfuncs)[CURRENT_VP->drawmode](CURRENT_VP->x+x, CURRENT_VP->y+y);
+ if (LCDFN(clip_viewport_pixel)(&x, &y))
+ LCDFN(pixelfuncs)[CURRENT_VP->drawmode](x, y);
}
/* Draw a line */
@@ -468,6 +468,7 @@ void LCDFN(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;
LCDFN(pixelfunc_type) *pfunc = LCDFN(pixelfuncs)[CURRENT_VP->drawmode];
deltax = abs(x2 - x1);
@@ -522,12 +523,15 @@ void LCDFN(drawline)(int x1, int y1, int x2, int y2)
x = x1;
y = y1;
+ x_vp = CURRENT_VP->x;
+ y_vp = CURRENT_VP->y;
+ w_vp = CURRENT_VP->width;
+ h_vp = CURRENT_VP->height;
+
for (i = 0; i < numpixels; i++)
{
- if ( ((unsigned)x < (unsigned)CURRENT_VP->width)
- && ((unsigned)y < (unsigned)CURRENT_VP->height)
- )
- pfunc(CURRENT_VP->x + x, CURRENT_VP->y + y);
+ if (x >= 0 && y >= 0 && x < w_vp && y < h_vp)
+ pfunc(x + x_vp, y + y_vp);
if (d < 0)
{
@@ -547,36 +551,14 @@ void LCDFN(drawline)(int x1, int y1, int x2, int y2)
/* Draw a horizontal line (optimised) */
void LCDFN(hline)(int x1, int x2, int y)
{
- int x;
int width;
FBFN(data) *dst, *dst_end;
unsigned mask;
LCDFN(blockfunc_type) *bfunc;
- /* direction flip */
- if (x2 < x1)
- {
- x = x1;
- x1 = x2;
- x2 = x;
- }
-
- /******************** In viewport clipping **********************/
- /* nothing to draw? */
- if (((unsigned)y >= (unsigned)CURRENT_VP->height) || (x1 >= CURRENT_VP->width)
- || (x2 < 0))
+ if (!LCDFN(clip_viewport_hline)(&x1, &x2, &y))
return;
- if (x1 < 0)
- x1 = 0;
- if (x2 >= CURRENT_VP->width)
- x2 = CURRENT_VP->width-1;
-
- /* adjust x1 and y to viewport */
- x1 += CURRENT_VP->x;
- x2 += CURRENT_VP->x;
- y += CURRENT_VP->y;
-
width = x2 - x1 + 1;
bfunc = LCDFN(blockfuncs)[CURRENT_VP->drawmode];
@@ -598,30 +580,9 @@ void LCDFN(vline)(int x, int y1, int y2)
unsigned mask, mask_bottom;
LCDFN(blockfunc_type) *bfunc;
- /* direction flip */
- if (y2 < y1)
- {
- ny = y1;
- y1 = y2;
- y2 = ny;
- }
-
- /******************** In viewport clipping **********************/
- /* nothing to draw? */
- if (((unsigned)x >= (unsigned)CURRENT_VP->width) || (y1 >= CURRENT_VP->height)
- || (y2 < 0))
+ if (!LCDFN(clip_viewport_vline)(&x, &y1, &y2))
return;
- if (y1 < 0)
- y1 = 0;
- if (y2 >= CURRENT_VP->height)
- y2 = CURRENT_VP->height-1;
-
- /* adjust for viewport */
- y1 += CURRENT_VP->y;
- y2 += CURRENT_VP->y;
- x += CURRENT_VP->x;
-
bfunc = LCDFN(blockfuncs)[CURRENT_VP->drawmode];
dst = LCDFB(x,y1>>3);
stride_dst = CURRENT_VP->buffer->stride;
@@ -667,31 +628,9 @@ void LCDFN(fillrect)(int x, int y, int width, int height)
LCDFN(blockfunc_type) *bfunc;
bool fillopt = false;
- /******************** In viewport clipping **********************/
- /* nothing to draw? */
- if ((width <= 0) || (height <= 0) || (x >= CURRENT_VP->width)
- || (y >= CURRENT_VP->height) || (x + width <= 0) || (y + height <= 0))
+ if (!LCDFN(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 > CURRENT_VP->width)
- width = CURRENT_VP->width - x;
- if (y + height > CURRENT_VP->height)
- height = CURRENT_VP->height - y;
-
- /* adjust for viewport */
- x += CURRENT_VP->x;
- y += CURRENT_VP->y;
-
if (CURRENT_VP->drawmode & DRMODE_INVERSEVID)
{
if ((CURRENT_VP->drawmode & DRMODE_BG) && !backdrop)
@@ -769,33 +708,9 @@ void ICODE_ATTR LCDFN(mono_bitmap_part)(const unsigned char *src, int src_x,
unsigned data, mask, mask_bottom;
LCDFN(blockfunc_type) *bfunc;
- /******************** Image in viewport clipping **********************/
- /* nothing to draw? */
- if ((width <= 0) || (height <= 0) || (x >= CURRENT_VP->width) ||
- (y >= CURRENT_VP->height) || (x + width <= 0) || (y + height <= 0))
+ if (!LCDFN(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 > CURRENT_VP->width)
- width = CURRENT_VP->width - x;
- if (y + height > CURRENT_VP->height)
- height = CURRENT_VP->height - y;
-
- /* adjust for viewport */
- x += CURRENT_VP->x;
- y += CURRENT_VP->y;
-
src += stride * (src_y >> 3) + src_x; /* move starting point */
src_y &= 7;
y -= src_y;
@@ -913,33 +828,9 @@ void ICODE_ATTR LCDFN(bitmap_part)(const FBFN(data) *src, int src_x,
int stride_dst;
unsigned mask, mask_bottom;
- /******************** Image in viewport clipping **********************/
- /* nothing to draw? */
- if ((width <= 0) || (height <= 0) || (x >= CURRENT_VP->width)
- || (y >= CURRENT_VP->height) || (x + width <= 0) || (y + height <= 0))
+ if (!LCDFN(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 > CURRENT_VP->width)
- width = CURRENT_VP->width - x;
- if (y + height > CURRENT_VP->height)
- height = CURRENT_VP->height - y;
-
- /* adjust for viewport */
- x += CURRENT_VP->x;
- y += CURRENT_VP->y;
-
src += stride * (src_y >> 3) + src_x; /* move starting point */
src_y &= 7;
y -= src_y;
@@ -1036,5 +927,3 @@ void LCDFN(bitmap)(const FBFN(data) *src, int x, int y, int width, int height)
{
LCDFN(bitmap_part)(src, 0, 0, width, x, y, width, height);
}
-
-#include "lcd-bitmap-common.c"