summaryrefslogtreecommitdiffstats
path: root/firmware/drivers/lcd-24bit.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/lcd-24bit.c')
-rw-r--r--firmware/drivers/lcd-24bit.c186
1 files changed, 11 insertions, 175 deletions
diff --git a/firmware/drivers/lcd-24bit.c b/firmware/drivers/lcd-24bit.c
index 279ed5924a..d95415e957 100644
--- a/firmware/drivers/lcd-24bit.c
+++ b/firmware/drivers/lcd-24bit.c
@@ -173,31 +173,9 @@ void lcd_fillrect(int x, int y, int width, int height)
fb_data bits;
memset(&bits, 0, sizeof(fb_data));
- /******************** 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;
-
/* drawmode and optimisation */
if (lcd_current_viewport->drawmode & DRMODE_INVERSEVID)
{
@@ -287,33 +265,9 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
int drmode = lcd_current_viewport->drawmode;
int row;
- /******************** 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;
src_end = src + width;
@@ -491,32 +445,9 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
fb_data *dst, *dst_row;
unsigned dmask = 0x00000000;
int drmode = lcd_current_viewport->drawmode;
- /* nothing to draw? */
- if ((width <= 0) || (height <= 0) || (x >= lcd_current_viewport->width) ||
- (y >= lcd_current_viewport->height) || (x + width <= 0) || (y + height <= 0))
- return;
- /* clipping */
- 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;
+ if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
+ return;
/* the following drawmode combinations are possible:
* 1) COMPLEMENT: just negates the framebuffer contents
@@ -758,38 +689,16 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
/* Draw a horizontal line (optimised) */
void lcd_hline(int x1, int x2, int y)
{
- int x, width;
+ int width;
fb_data *dst, *dst_end;
lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[lcd_current_viewport->drawmode];
- /* 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;
- dst = FBADDR(x1 , y);
+ dst = FBADDR(x1, y);
dst_end = dst + width;
do
{
@@ -801,36 +710,13 @@ void lcd_hline(int x1, int x2, int y)
/* Draw a vertical line (optimised) */
void lcd_vline(int x, int y1, int y2)
{
- int y;
fb_data *dst, *dst_end;
lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[lcd_current_viewport->drawmode];
- /* direction flip */
- if (y2 < y1)
- {
- y = y1;
- y1 = y2;
- y2 = y;
- }
-
- /******************** 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 */
- x += lcd_current_viewport->x;
- y1 += lcd_current_viewport->y;
- y2 += lcd_current_viewport->y;
-
- dst = FBADDR(x , y1);
+ dst = FBADDR(x, y1);
dst_end = dst + (y2 - y1) * LCD_WIDTH;
do
@@ -848,34 +734,9 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
{
fb_data *dst;
- /******************** 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 + src_x; /* move starting point */
dst = FBADDR(x, y);
@@ -896,34 +757,9 @@ void ICODE_ATTR lcd_bitmap_transparent_part(const fb_data *src, int src_x,
fb_data *dst;
fb_data fg, transparent, replacewithfg;
- /******************** 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 + src_x; /* move starting point */
dst = FBADDR(x, y);