1
0
Fork 0
forked from len0rd/rockbox

Add optional viewport clipping, can be enabled with HAVE_VIEWPORT_CLIP. A simulator check is also added to set_viewport that will show an error/note when DEBUGF is enabled.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23551 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Karl Kurbjun 2009-11-07 18:38:46 +00:00
parent b1783c3c64
commit 765ff0130a
8 changed files with 1100 additions and 174 deletions

View file

@ -92,6 +92,28 @@ void lcd_set_viewport(struct viewport* vp)
current_vp = &default_vp; current_vp = &default_vp;
else else
current_vp = vp; current_vp = vp;
#if defined(SIMULATOR)
/* Force the viewport to be within bounds. If this happens it should
* be considered an error - the viewport will not draw as it might be
* expected.
*/
if((unsigned) current_vp->x > (unsigned) LCD_WIDTH
|| (unsigned) current_vp->y > (unsigned) LCD_HEIGHT
|| current_vp->x + current_vp->width > LCD_WIDTH
|| current_vp->y + current_vp->height > LCD_HEIGHT)
{
#if !defined(HAVE_VIEWPORT_CLIP)
DEBUGF("ERROR: "
#else
DEBUGF("NOTE: "
#endif
"set_viewport out of bounds: x: %d y: %d width: %d height:%d\n",
current_vp->x, current_vp->y,
current_vp->width, current_vp->height);
}
#endif
} }
void lcd_update_viewport(void) void lcd_update_viewport(void)
@ -312,8 +334,13 @@ void lcd_clear_display(void)
/* Set a single pixel */ /* Set a single pixel */
void lcd_drawpixel(int x, int y) void lcd_drawpixel(int x, int y)
{ {
if (((unsigned)x < (unsigned)current_vp->width) && if ( ((unsigned)x < (unsigned)current_vp->width)
((unsigned)y < (unsigned)current_vp->height)) && ((unsigned)y < (unsigned)current_vp->height)
#if defined(HAVE_VIEWPORT_CLIP)
&& ((unsigned)x < (unsigned)LCD_WIDTH)
&& ((unsigned)y < (unsigned)LCD_HEIGHT)
#endif
)
lcd_fastpixelfuncs[current_vp->drawmode](LCDADDR(current_vp->x+x, current_vp->y+y)); lcd_fastpixelfuncs[current_vp->drawmode](LCDADDR(current_vp->x+x, current_vp->y+y));
} }
@ -382,7 +409,13 @@ void lcd_drawline(int x1, int y1, int x2, int y2)
for (i = 0; i < numpixels; i++) for (i = 0; i < numpixels; i++)
{ {
if (((unsigned)x < (unsigned)current_vp->width) && ((unsigned)y < (unsigned)current_vp->height)) if ( ((unsigned)x < (unsigned)current_vp->width)
&& ((unsigned)y < (unsigned)current_vp->height)
#if defined(HAVE_VIEWPORT_CLIP)
&& ((unsigned)x < (unsigned)LCD_WIDTH)
&& ((unsigned)y < (unsigned)LCD_HEIGHT)
#endif
)
pfunc(LCDADDR(x + current_vp->x, y + current_vp->y)); pfunc(LCDADDR(x + current_vp->x, y + current_vp->y));
if (d < 0) if (d < 0)
@ -415,19 +448,38 @@ void lcd_hline(int x1, int x2, int y)
x2 = x; x2 = x;
} }
/******************** In viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if (((unsigned)y >= (unsigned)current_vp->height) || if (((unsigned)y >= (unsigned)current_vp->height) ||
(x1 >= current_vp->width) || (x1 >= current_vp->width) ||
(x2 < 0)) (x2 < 0))
return; return;
/* clipping */
if (x1 < 0) if (x1 < 0)
x1 = 0; x1 = 0;
if (x2 >= current_vp->width) if (x2 >= current_vp->width)
x2 = current_vp->width-1; x2 = current_vp->width-1;
/* Adjust x1 and y to viewport */
x1 += current_vp->x;
x2 += current_vp->x;
y += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if (((unsigned)y >= (unsigned) LCD_HEIGHT) || (x1 >= LCD_WIDTH)
|| (x2 < 0))
return;
/* clipping */
if (x1 < 0)
x1 = 0;
if (x2 >= LCD_WIDTH)
x2 = LCD_WIDTH-1;
#endif
dst = LCDADDR(x1 + current_vp->x, y + current_vp->y); dst = LCDADDR(x1 , y );
dst_end = dst + (x2 - x1) * LCD_HEIGHT; dst_end = dst + (x2 - x1) * LCD_HEIGHT;
do do
@ -454,12 +506,39 @@ void lcd_vline(int x, int y1, int y2)
y2 = y; y2 = y;
} }
/******************** In viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if (((unsigned)x >= (unsigned)current_vp->width) || if (((unsigned)x >= (unsigned)current_vp->width) ||
(y1 >= current_vp->height) || (y1 >= current_vp->height) ||
(y2 < 0)) (y2 < 0))
return; return;
if (y1 < 0)
y1 = 0;
if (y2 >= current_vp->height)
y2 = current_vp->height-1;
/* adjust for viewport */
x += current_vp->x;
y1 += current_vp->y;
y2 += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if (( (unsigned) x >= (unsigned)LCD_WIDTH) || (y1 >= LCD_HEIGHT)
|| (y2 < 0))
return;
/* clipping */
if (y1 < 0)
y1 = 0;
if (y2 >= LCD_HEIGHT)
y2 = LCD_HEIGHT-1;
#endif
height = y2 - y1 + 1;
/* drawmode and optimisation */ /* drawmode and optimisation */
if (current_vp->drawmode & DRMODE_INVERSEVID) if (current_vp->drawmode & DRMODE_INVERSEVID)
{ {
@ -485,18 +564,6 @@ void lcd_vline(int x, int y1, int y2)
if (fillopt == OPT_NONE && current_vp->drawmode != DRMODE_COMPLEMENT) if (fillopt == OPT_NONE && current_vp->drawmode != DRMODE_COMPLEMENT)
return; return;
/* clipping */
if (y1 < 0)
y1 = 0;
if (y2 >= current_vp->height)
y2 = current_vp->height-1;
height = y2 - y1 + 1;
/* Adjust y1 and x to viewport */
y1 += current_vp->y;
x += current_vp->x;
dst = LCDADDR(x, y1); dst = LCDADDR(x, y1);
switch (fillopt) switch (fillopt)
@ -541,11 +608,55 @@ void lcd_fillrect(int x, int y, int width, int height)
enum fill_opt fillopt = OPT_NONE; enum fill_opt fillopt = OPT_NONE;
fb_data *dst, *dst_end; fb_data *dst, *dst_end;
/******************** In viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) || if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return; 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 defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|| (x + width <= 0) || (y + height <= 0))
return;
/* clip image in viewport in screen */
if (x < 0)
{
width += x;
x = 0;
}
if (y < 0)
{
height += y;
y = 0;
}
if (x + width > LCD_WIDTH)
width = LCD_WIDTH - x;
if (y + height > LCD_HEIGHT)
height = LCD_HEIGHT - y;
#endif
/* drawmode and optimisation */ /* drawmode and optimisation */
if (current_vp->drawmode & DRMODE_INVERSEVID) if (current_vp->drawmode & DRMODE_INVERSEVID)
{ {
@ -571,23 +682,7 @@ void lcd_fillrect(int x, int y, int width, int height)
if (fillopt == OPT_NONE && current_vp->drawmode != DRMODE_COMPLEMENT) if (fillopt == OPT_NONE && current_vp->drawmode != DRMODE_COMPLEMENT)
return; return;
/* clipping */ dst = LCDADDR(x, y);
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;
dst = LCDADDR(current_vp->x + x, current_vp->y + y);
dst_end = dst + width * LCD_HEIGHT; dst_end = dst + width * LCD_HEIGHT;
do do
@ -641,12 +736,12 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
unsigned dmask = 0x100; /* bit 8 == sentinel */ unsigned dmask = 0x100; /* bit 8 == sentinel */
int drmode = current_vp->drawmode; int drmode = current_vp->drawmode;
/******************** Image in viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) || if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return; return;
/* clipping */
if (x < 0) if (x < 0)
{ {
width += x; width += x;
@ -663,11 +758,41 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
width = current_vp->width - x; width = current_vp->width - x;
if (y + height > current_vp->height) if (y + height > current_vp->height)
height = current_vp->height - y; height = current_vp->height - y;
/* adjust for viewport */
x += current_vp->x;
y += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|| (x + width <= 0) || (y + height <= 0))
return;
/* clip image in viewport in screen */
if (x < 0)
{
width += x;
src_x -= x;
x = 0;
}
if (y < 0)
{
height += y;
src_y -= y;
y = 0;
}
if (x + width > LCD_WIDTH)
width = LCD_WIDTH - x;
if (y + height > LCD_HEIGHT)
height = LCD_HEIGHT - y;
#endif
src += stride * (src_y >> 3) + src_x; /* move starting point */ src += stride * (src_y >> 3) + src_x; /* move starting point */
src_y &= 7; src_y &= 7;
src_end = src + width; src_end = src + width;
dst = LCDADDR(current_vp->x + x, current_vp->y + y); dst = LCDADDR(x, y);
dst_end = dst + height; dst_end = dst + height;
if (drmode & DRMODE_INVERSEVID) if (drmode & DRMODE_INVERSEVID)
@ -793,12 +918,12 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
{ {
fb_data *dst, *dst_end; fb_data *dst, *dst_end;
/******************** Image in viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) || if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return; return;
/* clipping */
if (x < 0) if (x < 0)
{ {
width += x; width += x;
@ -811,13 +936,44 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
src_y -= y; src_y -= y;
y = 0; y = 0;
} }
if (x + width > current_vp->width) if (x + width > current_vp->width)
width = current_vp->width - x; width = current_vp->width - x;
if (y + height > current_vp->height) if (y + height > current_vp->height)
height = current_vp->height - y; height = current_vp->height - y;
/* adjust for viewport */
x += current_vp->x;
y += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|| (x + width <= 0) || (y + height <= 0))
return;
/* clip image in viewport in screen */
if (x < 0)
{
width += x;
src_x -= x;
x = 0;
}
if (y < 0)
{
height += y;
src_y -= y;
y = 0;
}
if (x + width > LCD_WIDTH)
width = LCD_WIDTH - x;
if (y + height > LCD_HEIGHT)
height = LCD_HEIGHT - y;
#endif
src += stride * src_x + src_y; /* move starting point */ src += stride * src_x + src_y; /* move starting point */
dst = LCDADDR(current_vp->x + x, current_vp->y + y); dst = LCDADDR(x, y);
dst_end = dst + width * LCD_HEIGHT; dst_end = dst + width * LCD_HEIGHT;
do do
@ -843,13 +999,13 @@ void ICODE_ATTR lcd_bitmap_transparent_part(const fb_data *src, int src_x,
int y, int width, int height) int y, int width, int height)
{ {
fb_data *dst, *dst_end; fb_data *dst, *dst_end;
/******************** Image in viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) || if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return; return;
/* clipping */
if (x < 0) if (x < 0)
{ {
width += x; width += x;
@ -862,13 +1018,44 @@ void ICODE_ATTR lcd_bitmap_transparent_part(const fb_data *src, int src_x,
src_y -= y; src_y -= y;
y = 0; y = 0;
} }
if (x + width > current_vp->width) if (x + width > current_vp->width)
width = current_vp->width - x; width = current_vp->width - x;
if (y + height > current_vp->height) if (y + height > current_vp->height)
height = current_vp->height - y; height = current_vp->height - y;
/* adjust for viewport */
x += current_vp->x;
y += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|| (x + width <= 0) || (y + height <= 0))
return;
/* clip image in viewport in screen */
if (x < 0)
{
width += x;
src_x -= x;
x = 0;
}
if (y < 0)
{
height += y;
src_y -= y;
y = 0;
}
if (x + width > LCD_WIDTH)
width = LCD_WIDTH - x;
if (y + height > LCD_HEIGHT)
height = LCD_HEIGHT - y;
#endif
src += stride * src_x + src_y; /* move starting point */ src += stride * src_x + src_y; /* move starting point */
dst = LCDADDR(current_vp->x + x, current_vp->y + y); dst = LCDADDR(x, y);
dst_end = dst + width * LCD_HEIGHT; dst_end = dst + width * LCD_HEIGHT;
do do

View file

@ -85,6 +85,28 @@ void lcd_set_viewport(struct viewport* vp)
current_vp = &default_vp; current_vp = &default_vp;
else else
current_vp = vp; current_vp = vp;
#if defined(SIMULATOR)
/* Force the viewport to be within bounds. If this happens it should
* be considered an error - the viewport will not draw as it might be
* expected.
*/
if((unsigned) current_vp->x > (unsigned) LCD_WIDTH
|| (unsigned) current_vp->y > (unsigned) LCD_HEIGHT
|| current_vp->x + current_vp->width > LCD_WIDTH
|| current_vp->y + current_vp->height > LCD_HEIGHT)
{
#if !defined(HAVE_VIEWPORT_CLIP)
DEBUGF("ERROR: "
#else
DEBUGF("NOTE: "
#endif
"set_viewport out of bounds: x: %d y: %d width: %d height:%d\n",
current_vp->x, current_vp->y,
current_vp->width, current_vp->height);
}
#endif
} }
void lcd_update_viewport(void) void lcd_update_viewport(void)
@ -305,8 +327,13 @@ void lcd_clear_display(void)
/* Set a single pixel */ /* Set a single pixel */
void lcd_drawpixel(int x, int y) void lcd_drawpixel(int x, int y)
{ {
if (((unsigned)x < (unsigned)current_vp->width) && if ( ((unsigned)x < (unsigned)current_vp->width)
((unsigned)y < (unsigned)current_vp->height)) && ((unsigned)y < (unsigned)current_vp->height)
#if defined(HAVE_VIEWPORT_CLIP)
&& ((unsigned)x < (unsigned)LCD_WIDTH)
&& ((unsigned)y < (unsigned)LCD_HEIGHT)
#endif
)
lcd_fastpixelfuncs[current_vp->drawmode](LCDADDR(current_vp->x+x, current_vp->y+y)); lcd_fastpixelfuncs[current_vp->drawmode](LCDADDR(current_vp->x+x, current_vp->y+y));
} }
@ -375,7 +402,13 @@ void lcd_drawline(int x1, int y1, int x2, int y2)
for (i = 0; i < numpixels; i++) for (i = 0; i < numpixels; i++)
{ {
if (((unsigned)x < (unsigned)current_vp->width) && ((unsigned)y < (unsigned)current_vp->height)) if ( ((unsigned)x < (unsigned)current_vp->width)
&& ((unsigned)y < (unsigned)current_vp->height)
#if defined(HAVE_VIEWPORT_CLIP)
&& ((unsigned)x < (unsigned)LCD_WIDTH)
&& ((unsigned)y < (unsigned)LCD_HEIGHT)
#endif
)
pfunc(LCDADDR(x + current_vp->x, y + current_vp->y)); pfunc(LCDADDR(x + current_vp->x, y + current_vp->y));
if (d < 0) if (d < 0)
@ -409,11 +442,38 @@ void lcd_hline(int x1, int x2, int y)
x2 = x; x2 = x;
} }
/******************** In viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if (((unsigned)y >= (unsigned)current_vp->height) || if (((unsigned)y >= (unsigned)current_vp->height) ||
(x1 >= current_vp->width) || (x1 >= current_vp->width) ||
(x2 < 0)) (x2 < 0))
return; 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;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if (((unsigned)y >= (unsigned) LCD_HEIGHT) || (x1 >= LCD_WIDTH)
|| (x2 < 0))
return;
/* clipping */
if (x1 < 0)
x1 = 0;
if (x2 >= LCD_WIDTH)
x2 = LCD_WIDTH-1;
#endif
width = x2 - x1 + 1;
/* drawmode and optimisation */ /* drawmode and optimisation */
if (current_vp->drawmode & DRMODE_INVERSEVID) if (current_vp->drawmode & DRMODE_INVERSEVID)
@ -440,18 +500,6 @@ void lcd_hline(int x1, int x2, int y)
if (fillopt == OPT_NONE && current_vp->drawmode != DRMODE_COMPLEMENT) if (fillopt == OPT_NONE && current_vp->drawmode != DRMODE_COMPLEMENT)
return; return;
/* clipping */
if (x1 < 0)
x1 = 0;
if (x2 >= current_vp->width)
x2 = current_vp->width-1;
width = x2 - x1 + 1;
/* Adjust x1 and y to viewport */
x1 += current_vp->x;
y += current_vp->y;
dst = LCDADDR(x1, y); dst = LCDADDR(x1, y);
switch (fillopt) switch (fillopt)
@ -489,19 +537,38 @@ void lcd_vline(int x, int y1, int y2)
y2 = y; y2 = y;
} }
/******************** In viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if (((unsigned)x >= (unsigned)current_vp->width) || if (((unsigned)x >= (unsigned)current_vp->width) ||
(y1 >= current_vp->height) || (y1 >= current_vp->height) ||
(y2 < 0)) (y2 < 0))
return; return;
/* clipping */
if (y1 < 0) if (y1 < 0)
y1 = 0; y1 = 0;
if (y2 >= current_vp->height) if (y2 >= current_vp->height)
y2 = current_vp->height-1; y2 = current_vp->height-1;
/* adjust for viewport */
x += current_vp->x;
y1 += current_vp->y;
y2 += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if (( (unsigned) x >= (unsigned)LCD_WIDTH) || (y1 >= LCD_HEIGHT)
|| (y2 < 0))
return;
/* clipping */
if (y1 < 0)
y1 = 0;
if (y2 >= LCD_HEIGHT)
y2 = LCD_HEIGHT-1;
#endif
dst = LCDADDR(x + current_vp->x, y1 + current_vp->y); dst = LCDADDR(x , y1);
dst_end = dst + (y2 - y1) * LCD_WIDTH; dst_end = dst + (y2 - y1) * LCD_WIDTH;
do do
@ -534,11 +601,55 @@ void lcd_fillrect(int x, int y, int width, int height)
enum fill_opt fillopt = OPT_NONE; enum fill_opt fillopt = OPT_NONE;
fb_data *dst, *dst_end; fb_data *dst, *dst_end;
/******************** In viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) || if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return; 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 defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|| (x + width <= 0) || (y + height <= 0))
return;
/* clip image in viewport in screen */
if (x < 0)
{
width += x;
x = 0;
}
if (y < 0)
{
height += y;
y = 0;
}
if (x + width > LCD_WIDTH)
width = LCD_WIDTH - x;
if (y + height > LCD_HEIGHT)
height = LCD_HEIGHT - y;
#endif
/* drawmode and optimisation */ /* drawmode and optimisation */
if (current_vp->drawmode & DRMODE_INVERSEVID) if (current_vp->drawmode & DRMODE_INVERSEVID)
{ {
@ -564,23 +675,7 @@ void lcd_fillrect(int x, int y, int width, int height)
if (fillopt == OPT_NONE && current_vp->drawmode != DRMODE_COMPLEMENT) if (fillopt == OPT_NONE && current_vp->drawmode != DRMODE_COMPLEMENT)
return; return;
/* clipping */ dst = LCDADDR(x, y);
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;
dst = LCDADDR(current_vp->x + x, current_vp->y + y);
dst_end = dst + height * LCD_WIDTH; dst_end = dst + height * LCD_WIDTH;
do do
@ -634,12 +729,12 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
unsigned dmask = 0x100; /* bit 8 == sentinel */ unsigned dmask = 0x100; /* bit 8 == sentinel */
int drmode = current_vp->drawmode; int drmode = current_vp->drawmode;
/******************** Image in viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) || if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return; return;
/* clipping */
if (x < 0) if (x < 0)
{ {
width += x; width += x;
@ -656,11 +751,41 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
width = current_vp->width - x; width = current_vp->width - x;
if (y + height > current_vp->height) if (y + height > current_vp->height)
height = current_vp->height - y; height = current_vp->height - y;
/* adjust for viewport */
x += current_vp->x;
y += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|| (x + width <= 0) || (y + height <= 0))
return;
/* clip image in viewport in screen */
if (x < 0)
{
width += x;
src_x -= x;
x = 0;
}
if (y < 0)
{
height += y;
src_y -= y;
y = 0;
}
if (x + width > LCD_WIDTH)
width = LCD_WIDTH - x;
if (y + height > LCD_HEIGHT)
height = LCD_HEIGHT - y;
#endif
src += stride * (src_y >> 3) + src_x; /* move starting point */ src += stride * (src_y >> 3) + src_x; /* move starting point */
src_y &= 7; src_y &= 7;
src_end = src + width; src_end = src + width;
dst = LCDADDR(current_vp->x + x, current_vp->y + y); dst = LCDADDR(x, y);
dst_end = dst + height * LCD_WIDTH; dst_end = dst + height * LCD_WIDTH;
if (drmode & DRMODE_INVERSEVID) if (drmode & DRMODE_INVERSEVID)
@ -784,34 +909,62 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
{ {
fb_data *dst; fb_data *dst;
if (x + width > current_vp->width) /******************** Image in viewport clipping **********************/
width = current_vp->width - x; /* Clip right */ /* nothing to draw? */
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
if (x < 0) /* Clip left */ (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return;
if (x < 0)
{ {
width += x; width += x;
src_x -= x; src_x -= x;
x = 0; x = 0;
} }
if (y < 0)
if (width <= 0)
return; /* nothing left to do */
if (y + height > current_vp->height)
height = current_vp->height - y; /* Clip bottom */
if (y < 0) /* Clip top */
{ {
height += y; height += y;
src_y -= y; src_y -= y;
y = 0; y = 0;
} }
if (height <= 0) if (x + width > current_vp->width)
return; /* nothing left to do */ 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 defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|| (x + width <= 0) || (y + height <= 0))
return;
/* clip image in viewport in screen */
if (x < 0)
{
width += x;
src_x -= x;
x = 0;
}
if (y < 0)
{
height += y;
src_y -= y;
y = 0;
}
if (x + width > LCD_WIDTH)
width = LCD_WIDTH - x;
if (y + height > LCD_HEIGHT)
height = LCD_HEIGHT - y;
#endif
src += stride * src_y + src_x; /* move starting point */ src += stride * src_y + src_x; /* move starting point */
dst = LCDADDR(current_vp->x + x, current_vp->y + y); dst = LCDADDR(x, y);
do do
{ {
@ -836,34 +989,62 @@ void ICODE_ATTR lcd_bitmap_transparent_part(const fb_data *src, int src_x,
fb_data *dst; fb_data *dst;
unsigned fg = current_vp->fg_pattern; unsigned fg = current_vp->fg_pattern;
if (x + width > current_vp->width) /******************** Image in viewport clipping **********************/
width = current_vp->width - x; /* Clip right */ /* nothing to draw? */
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
if (x < 0) /* Clip left */ (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return;
if (x < 0)
{ {
width += x; width += x;
src_x -= x; src_x -= x;
x = 0; x = 0;
} }
if (y < 0)
if (width <= 0)
return; /* nothing left to do */
if (y + height > current_vp->height)
height = current_vp->height - y; /* Clip bottom */
if (y < 0) /* Clip top */
{ {
height += y; height += y;
src_y -= y; src_y -= y;
y = 0; y = 0;
} }
if (height <= 0) if (x + width > current_vp->width)
return; /* nothing left to do */ 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 defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|| (x + width <= 0) || (y + height <= 0))
return;
/* clip image in viewport in screen */
if (x < 0)
{
width += x;
src_x -= x;
x = 0;
}
if (y < 0)
{
height += y;
src_y -= y;
y = 0;
}
if (x + width > LCD_WIDTH)
width = LCD_WIDTH - x;
if (y + height > LCD_HEIGHT)
height = LCD_HEIGHT - y;
#endif
src += stride * src_y + src_x; /* move starting point */ src += stride * src_y + src_x; /* move starting point */
dst = LCDADDR(current_vp->x + x, current_vp->y + y); dst = LCDADDR(x, y);
#ifdef CPU_ARM #ifdef CPU_ARM
{ {

View file

@ -66,6 +66,28 @@ void LCDFN(set_viewport)(struct viewport* vp)
current_vp = &default_vp; current_vp = &default_vp;
else else
current_vp = vp; current_vp = vp;
#if defined(SIMULATOR)
/* Force the viewport to be within bounds. If this happens it should
* be considered an error - the viewport will not draw as it might be
* expected.
*/
if((unsigned) current_vp->x > (unsigned) LCDM(WIDTH)
|| (unsigned) current_vp->y > (unsigned) LCDM(HEIGHT)
|| current_vp->x + current_vp->width > LCDM(WIDTH)
|| current_vp->y + current_vp->height > LCDM(HEIGHT))
{
#if !defined(HAVE_VIEWPORT_CLIP)
DEBUGF("ERROR: "
#else
DEBUGF("NOTE: "
#endif
"set_viewport out of bounds: x: %d y: %d width: %d height:%d\n",
current_vp->x, current_vp->y,
current_vp->width, current_vp->height);
}
#endif
} }
void LCDFN(update_viewport)(void) void LCDFN(update_viewport)(void)
@ -254,8 +276,13 @@ void LCDFN(clear_viewport)(void)
/* Set a single pixel */ /* Set a single pixel */
void LCDFN(drawpixel)(int x, int y) void LCDFN(drawpixel)(int x, int y)
{ {
if (((unsigned)x < (unsigned)current_vp->width) && if ( ((unsigned)x < (unsigned)current_vp->width)
((unsigned)y < (unsigned)current_vp->height)) && ((unsigned)y < (unsigned)current_vp->height)
#if defined(HAVE_VIEWPORT_CLIP)
&& ((unsigned)x < (unsigned)LCDM(WIDTH))
&& ((unsigned)y < (unsigned)LCDM(HEIGHT))
#endif
)
LCDFN(pixelfuncs)[current_vp->drawmode](current_vp->x + x, current_vp->y + y); LCDFN(pixelfuncs)[current_vp->drawmode](current_vp->x + x, current_vp->y + y);
} }
@ -324,8 +351,13 @@ void LCDFN(drawline)(int x1, int y1, int x2, int y2)
for (i = 0; i < numpixels; i++) for (i = 0; i < numpixels; i++)
{ {
if (((unsigned)x < (unsigned)current_vp->width) if ( ((unsigned)x < (unsigned)current_vp->width)
&& ((unsigned)y < (unsigned)current_vp->height)) && ((unsigned)y < (unsigned)current_vp->height)
#if defined(HAVE_VIEWPORT_CLIP)
&& ((unsigned)x < (unsigned)LCDM(WIDTH))
&& ((unsigned)y < (unsigned)LCDM(HEIGHT))
#endif
)
pfunc(current_vp->x + x, current_vp->y + y); pfunc(current_vp->x + x, current_vp->y + y);
if (d < 0) if (d < 0)
@ -359,22 +391,38 @@ void LCDFN(hline)(int x1, int x2, int y)
x2 = x; x2 = x;
} }
/******************** In viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if (((unsigned)y >= (unsigned)current_vp->height) || (x1 >= current_vp->width) if (((unsigned)y >= (unsigned)current_vp->height) || (x1 >= current_vp->width)
|| (x2 < 0)) || (x2 < 0))
return; return;
if (x1 < 0)
x1 = 0;
if (x2 >= current_vp->width)
x2 = current_vp->width-1;
/* adjust to viewport */
x1 += current_vp->x;
y += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
x2 += current_vp->x;
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if (((unsigned)y >= (unsigned) LCDM(HEIGHT)) || (x1 >= LCDM(WIDTH))
|| (x2 < 0))
return;
/* clipping */ /* clipping */
if (x1 < 0) if (x1 < 0)
x1 = 0; x1 = 0;
if (x2 >= current_vp->width) if (x2 >= LCDM(WIDTH))
x2 = current_vp->width-1; x2 = LCDM(WIDTH)-1;
#endif
width = x2 - x1 + 1;
/* adjust to viewport */ width = x2 - x1 + 1;
x1 += current_vp->x;
y += current_vp->y;
bfunc = LCDFN(blockfuncs)[current_vp->drawmode]; bfunc = LCDFN(blockfuncs)[current_vp->drawmode];
dst = &LCDFN(framebuffer)[y>>3][x1]; dst = &LCDFN(framebuffer)[y>>3][x1];
@ -402,12 +450,12 @@ void LCDFN(vline)(int x, int y1, int y2)
y2 = ny; y2 = ny;
} }
/******************** In viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if (((unsigned)x >= (unsigned)current_vp->width) || (y1 >= current_vp->height) if (((unsigned)x >= (unsigned)current_vp->width) || (y1 >= current_vp->height)
|| (y2 < 0)) || (y2 < 0))
return; return;
/* clipping */
if (y1 < 0) if (y1 < 0)
y1 = 0; y1 = 0;
if (y2 >= current_vp->height) if (y2 >= current_vp->height)
@ -417,6 +465,20 @@ void LCDFN(vline)(int x, int y1, int y2)
y1 += current_vp->y; y1 += current_vp->y;
y2 += current_vp->y; y2 += current_vp->y;
x += current_vp->x; x += current_vp->x;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if (( (unsigned) x >= (unsigned)LCDM(WIDTH)) || (y1 >= LCDM(HEIGHT))
|| (y2 < 0))
return;
/* clipping */
if (y1 < 0)
y1 = 0;
if (y2 >= LCDM(HEIGHT))
y2 = LCDM(HEIGHT)-1;
#endif
bfunc = LCDFN(blockfuncs)[current_vp->drawmode]; bfunc = LCDFN(blockfuncs)[current_vp->drawmode];
dst = &LCDFN(framebuffer)[y1>>3][x]; dst = &LCDFN(framebuffer)[y1>>3][x];
@ -459,12 +521,12 @@ void LCDFN(fillrect)(int x, int y, int width, int height)
LCDFN(blockfunc_type) *bfunc; LCDFN(blockfunc_type) *bfunc;
bool fillopt = false; bool fillopt = false;
/******************** In viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) if ((width <= 0) || (height <= 0) || (x >= current_vp->width)
|| (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) || (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return; return;
/* clipping */
if (x < 0) if (x < 0)
{ {
width += x; width += x;
@ -483,6 +545,30 @@ void LCDFN(fillrect)(int x, int y, int width, int height)
/* adjust for viewport */ /* adjust for viewport */
x += current_vp->x; x += current_vp->x;
y += current_vp->y; y += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if ((x >= LCDM(WIDTH)) || (y >= LCDM(HEIGHT))
|| (x + width <= 0) || (y + height <= 0))
return;
/* clip image in viewport in screen */
if (x < 0)
{
width += x;
x = 0;
}
if (y < 0)
{
height += y;
y = 0;
}
if (x + width > LCDM(WIDTH))
width = LCDM(WIDTH) - x;
if (y + height > LCDM(HEIGHT))
height = LCDM(HEIGHT) - y;
#endif
if (current_vp->drawmode & DRMODE_INVERSEVID) if (current_vp->drawmode & DRMODE_INVERSEVID)
{ {
@ -556,12 +642,13 @@ void ICODE_ATTR LCDFN(bitmap_part)(const unsigned char *src, int src_x,
unsigned mask, mask_bottom; unsigned mask, mask_bottom;
LCDFN(blockfunc_type) *bfunc; LCDFN(blockfunc_type) *bfunc;
/******************** Image in viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) if ((width <= 0) || (height <= 0) || (x >= current_vp->width)
|| (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) || (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return; return;
/* clipping */ /* clip image in viewport */
if (x < 0) if (x < 0)
{ {
width += x; width += x;
@ -582,6 +669,32 @@ void ICODE_ATTR LCDFN(bitmap_part)(const unsigned char *src, int src_x,
/* adjust for viewport */ /* adjust for viewport */
x += current_vp->x; x += current_vp->x;
y += current_vp->y; y += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if ((x >= LCDM(WIDTH)) || (y >= LCDM(HEIGHT))
|| (x + width <= 0) || (y + height <= 0))
return;
/* clip image in viewport in screen */
if (x < 0)
{
width += x;
src_x -= x;
x = 0;
}
if (y < 0)
{
height += y;
src_y -= y;
y = 0;
}
if (x + width > LCDM(WIDTH))
width = LCDM(WIDTH) - x;
if (y + height > LCDM(HEIGHT))
height = LCDM(HEIGHT) - y;
#endif
src += stride * (src_y >> 3) + src_x; /* move starting point */ src += stride * (src_y >> 3) + src_x; /* move starting point */
src_y &= 7; src_y &= 7;

View file

@ -87,6 +87,28 @@ void lcd_set_viewport(struct viewport* vp)
fg_pattern = 0x55 * (~current_vp->fg_pattern & 3); fg_pattern = 0x55 * (~current_vp->fg_pattern & 3);
bg_pattern = 0x55 * (~current_vp->bg_pattern & 3); bg_pattern = 0x55 * (~current_vp->bg_pattern & 3);
#if defined(SIMULATOR)
/* Force the viewport to be within bounds. If this happens it should
* be considered an error - the viewport will not draw as it might be
* expected.
*/
if((unsigned) current_vp->x > (unsigned) LCD_WIDTH
|| (unsigned) current_vp->y > (unsigned) LCD_HEIGHT
|| current_vp->x + current_vp->width > LCD_WIDTH
|| current_vp->y + current_vp->height > LCD_HEIGHT)
{
#if !defined(HAVE_VIEWPORT_CLIP)
DEBUGF("ERROR: "
#else
DEBUGF("NOTE: "
#endif
"set_viewport out of bounds: x: %d y: %d width: %d height:%d\n",
current_vp->x, current_vp->y,
current_vp->width, current_vp->height);
}
#endif
} }
void lcd_update_viewport(void) void lcd_update_viewport(void)
@ -415,8 +437,13 @@ void lcd_clear_viewport(void)
/* Set a single pixel */ /* Set a single pixel */
void lcd_drawpixel(int x, int y) void lcd_drawpixel(int x, int y)
{ {
if (((unsigned)x < (unsigned)current_vp->width) && if ( ((unsigned)x < (unsigned)current_vp->width)
((unsigned)y < (unsigned)current_vp->height)) && ((unsigned)y < (unsigned)current_vp->height)
#if defined(HAVE_VIEWPORT_CLIP)
&& ((unsigned)x < (unsigned)LCD_WIDTH)
&& ((unsigned)y < (unsigned)LCD_HEIGHT)
#endif
)
lcd_pixelfuncs[current_vp->drawmode](current_vp->x + x, current_vp->y + y); lcd_pixelfuncs[current_vp->drawmode](current_vp->x + x, current_vp->y + y);
} }
@ -485,8 +512,13 @@ void lcd_drawline(int x1, int y1, int x2, int y2)
for (i = 0; i < numpixels; i++) for (i = 0; i < numpixels; i++)
{ {
if (((unsigned)x < (unsigned)current_vp->width) && if ( ((unsigned)x < (unsigned)current_vp->width)
((unsigned)y < (unsigned)current_vp->height)) && ((unsigned)y < (unsigned)current_vp->height)
#if defined(HAVE_VIEWPORT_CLIP)
&& ((unsigned)x < (unsigned)LCD_WIDTH)
&& ((unsigned)y < (unsigned)LCD_HEIGHT)
#endif
)
pfunc(current_vp->x + x, current_vp->y + y); pfunc(current_vp->x + x, current_vp->y + y);
if (d < 0) if (d < 0)
@ -520,12 +552,12 @@ void lcd_hline(int x1, int x2, int y)
x2 = nx; x2 = nx;
} }
/******************** In viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if (((unsigned)y >= (unsigned)current_vp->height) || (x1 >= current_vp->width) if (((unsigned)y >= (unsigned)current_vp->height) || (x1 >= current_vp->width)
|| (x2 < 0)) || (x2 < 0))
return; return;
/* clipping */
if (x1 < 0) if (x1 < 0)
x1 = 0; x1 = 0;
if (x2 >= current_vp->width) if (x2 >= current_vp->width)
@ -535,6 +567,20 @@ void lcd_hline(int x1, int x2, int y)
x1 += current_vp->x; x1 += current_vp->x;
x2 += current_vp->x; x2 += current_vp->x;
y += current_vp->y; y += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if (((unsigned)y >= (unsigned) LCD_HEIGHT) || (x1 >= LCD_WIDTH)
|| (x2 < 0))
return;
/* clipping */
if (x1 < 0)
x1 = 0;
if (x2 >= LCD_WIDTH)
x2 = LCD_WIDTH-1;
#endif
bfunc = lcd_blockfuncs[current_vp->drawmode]; bfunc = lcd_blockfuncs[current_vp->drawmode];
dst = &lcd_framebuffer[y][x1>>2]; dst = &lcd_framebuffer[y][x1>>2];
@ -567,12 +613,12 @@ void lcd_vline(int x, int y1, int y2)
y2 = y; y2 = y;
} }
/******************** In viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if (((unsigned)x >= (unsigned)current_vp->width) || (y1 >= current_vp->height) if (((unsigned)x >= (unsigned)current_vp->width) || (y1 >= current_vp->height)
|| (y2 < 0)) || (y2 < 0))
return; return;
/* clipping */
if (y1 < 0) if (y1 < 0)
y1 = 0; y1 = 0;
if (y2 >= current_vp->height) if (y2 >= current_vp->height)
@ -582,6 +628,20 @@ void lcd_vline(int x, int y1, int y2)
y1 += current_vp->y; y1 += current_vp->y;
y2 += current_vp->y; y2 += current_vp->y;
x += current_vp->x; x += current_vp->x;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if (( (unsigned) x >= (unsigned)LCD_WIDTH) || (y1 >= LCD_HEIGHT)
|| (y2 < 0))
return;
/* clipping */
if (y1 < 0)
y1 = 0;
if (y2 >= LCD_HEIGHT)
y2 = LCD_HEIGHT-1;
#endif
bfunc = lcd_blockfuncs[current_vp->drawmode]; bfunc = lcd_blockfuncs[current_vp->drawmode];
dst = &lcd_framebuffer[y1][x>>2]; dst = &lcd_framebuffer[y1][x>>2];
@ -619,12 +679,12 @@ void lcd_fillrect(int x, int y, int width, int height)
unsigned mask, mask_right; unsigned mask, mask_right;
lcd_blockfunc_type *bfunc; lcd_blockfunc_type *bfunc;
/******************** In viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) || (y >= current_vp->height) if ((width <= 0) || (height <= 0) || (x >= current_vp->width) || (y >= current_vp->height)
|| (x + width <= 0) || (y + height <= 0)) || (x + width <= 0) || (y + height <= 0))
return; return;
/* clipping */
if (x < 0) if (x < 0)
{ {
width += x; width += x;
@ -643,6 +703,30 @@ void lcd_fillrect(int x, int y, int width, int height)
/* adjust for viewport */ /* adjust for viewport */
x += current_vp->x; x += current_vp->x;
y += current_vp->y; y += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|| (x + width <= 0) || (y + height <= 0))
return;
/* clip image in viewport in screen */
if (x < 0)
{
width += x;
x = 0;
}
if (y < 0)
{
height += y;
y = 0;
}
if (x + width > LCD_WIDTH)
width = LCD_WIDTH - x;
if (y + height > LCD_HEIGHT)
height = LCD_HEIGHT - y;
#endif
bfunc = lcd_blockfuncs[current_vp->drawmode]; bfunc = lcd_blockfuncs[current_vp->drawmode];
dst = &lcd_framebuffer[y][x>>2]; dst = &lcd_framebuffer[y][x>>2];
@ -696,12 +780,12 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
unsigned dst_mask; unsigned dst_mask;
int drmode = current_vp->drawmode; int drmode = current_vp->drawmode;
/******************** Image in viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) || if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return; return;
/* clipping */
if (x < 0) if (x < 0)
{ {
width += x; width += x;
@ -718,12 +802,41 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
width = current_vp->width - x; width = current_vp->width - x;
if (y + height > current_vp->height) if (y + height > current_vp->height)
height = current_vp->height - y; height = current_vp->height - y;
x += current_vp->x; /* adjust for viewport */
y += current_vp->y; /* adjust for viewport */
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|| (x + width <= 0) || (y + height <= 0))
return;
/* clip image in viewport in screen */
if (x < 0)
{
width += x;
src_x -= x;
x = 0;
}
if (y < 0)
{
height += y;
src_y -= y;
y = 0;
}
if (x + width > LCD_WIDTH)
width = LCD_WIDTH - x;
if (y + height > LCD_HEIGHT)
height = LCD_HEIGHT - y;
#endif
src += stride * (src_y >> 3) + src_x; /* move starting point */ src += stride * (src_y >> 3) + src_x; /* move starting point */
src_y &= 7; src_y &= 7;
src_end = src + width; src_end = src + width;
x += current_vp->x; /* adjust for viewport */
dst = &lcd_framebuffer[current_vp->y + y][x >> 2]; dst = &lcd_framebuffer[y][x >> 2];
dst_end = dst + height * LCD_FBWIDTH; dst_end = dst + height * LCD_FBWIDTH;
dst_mask = pixmask[x & 3]; dst_mask = pixmask[x & 3];
@ -879,12 +992,12 @@ void ICODE_ATTR lcd_bitmap_part(const unsigned char *src, int src_x,
unsigned char *dst, *dst_end; unsigned char *dst, *dst_end;
unsigned mask, mask_right; unsigned mask, mask_right;
/******************** Image in viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) || if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return; return;
/* clipping */
if (x < 0) if (x < 0)
{ {
width += x; width += x;
@ -905,6 +1018,32 @@ void ICODE_ATTR lcd_bitmap_part(const unsigned char *src, int src_x,
/* adjust for viewport */ /* adjust for viewport */
x += current_vp->x; x += current_vp->x;
y += current_vp->y; y += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|| (x + width <= 0) || (y + height <= 0))
return;
/* clip image in viewport in screen */
if (x < 0)
{
width += x;
src_x -= x;
x = 0;
}
if (y < 0)
{
height += y;
src_y -= y;
y = 0;
}
if (x + width > LCD_WIDTH)
width = LCD_WIDTH - x;
if (y + height > LCD_HEIGHT)
height = LCD_HEIGHT - y;
#endif
stride = (stride + 3) >> 2; /* convert to no. of bytes */ stride = (stride + 3) >> 2; /* convert to no. of bytes */

View file

@ -89,6 +89,28 @@ void lcd_set_viewport(struct viewport* vp)
fg_pattern = 0x55 * (~current_vp->fg_pattern & 3); fg_pattern = 0x55 * (~current_vp->fg_pattern & 3);
bg_pattern = 0x55 * (~current_vp->bg_pattern & 3); bg_pattern = 0x55 * (~current_vp->bg_pattern & 3);
#if defined(SIMULATOR)
/* Force the viewport to be within bounds. If this happens it should
* be considered an error - the viewport will not draw as it might be
* expected.
*/
if((unsigned) current_vp->x > (unsigned) LCD_WIDTH
|| (unsigned) current_vp->y > (unsigned) LCD_HEIGHT
|| current_vp->x + current_vp->width > LCD_WIDTH
|| current_vp->y + current_vp->height > LCD_HEIGHT)
{
#if !defined(HAVE_VIEWPORT_CLIP)
DEBUGF("ERROR: "
#else
DEBUGF("NOTE: "
#endif
"set_viewport out of bounds: x: %d y: %d width: %d height:%d\n",
current_vp->x, current_vp->y,
current_vp->width, current_vp->height);
}
#endif
} }
void lcd_update_viewport(void) void lcd_update_viewport(void)
@ -418,8 +440,13 @@ void lcd_clear_viewport(void)
/* Set a single pixel */ /* Set a single pixel */
void lcd_drawpixel(int x, int y) void lcd_drawpixel(int x, int y)
{ {
if (((unsigned)x < (unsigned)current_vp->width) && if ( ((unsigned)x < (unsigned)current_vp->width)
((unsigned)y < (unsigned)current_vp->height)) && ((unsigned)y < (unsigned)current_vp->height)
#if defined(HAVE_VIEWPORT_CLIP)
&& ((unsigned)x < (unsigned)LCD_WIDTH)
&& ((unsigned)y < (unsigned)LCD_HEIGHT)
#endif
)
lcd_pixelfuncs[current_vp->drawmode](current_vp->x + x, current_vp->y + y); lcd_pixelfuncs[current_vp->drawmode](current_vp->x + x, current_vp->y + y);
} }
@ -488,8 +515,13 @@ void lcd_drawline(int x1, int y1, int x2, int y2)
for (i = 0; i < numpixels; i++) for (i = 0; i < numpixels; i++)
{ {
if (((unsigned)x < (unsigned)current_vp->width) && if ( ((unsigned)x < (unsigned)current_vp->width)
((unsigned)y < (unsigned)current_vp->height)) && ((unsigned)y < (unsigned)current_vp->height)
#if defined(HAVE_VIEWPORT_CLIP)
&& ((unsigned)x < (unsigned)LCD_WIDTH)
&& ((unsigned)y < (unsigned)LCD_HEIGHT)
#endif
)
pfunc(current_vp->x + x, current_vp->y + y); pfunc(current_vp->x + x, current_vp->y + y);
if (d < 0) if (d < 0)
@ -524,23 +556,38 @@ void lcd_hline(int x1, int x2, int y)
x2 = x; x2 = x;
} }
/******************** In viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if (((unsigned)y >= (unsigned)current_vp->height) || (x1 >= current_vp->width) if (((unsigned)y >= (unsigned)current_vp->height) || (x1 >= current_vp->width)
|| (x2 < 0)) || (x2 < 0))
return; 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;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if (((unsigned)y >= (unsigned) LCD_HEIGHT) || (x1 >= LCD_WIDTH)
|| (x2 < 0))
return;
/* clipping */ /* clipping */
if (x1 < 0) if (x1 < 0)
x1 = 0; x1 = 0;
if (x2 >= current_vp->width) if (x2 >= LCD_WIDTH)
x2 = current_vp->width-1; x2 = LCD_WIDTH-1;
#endif
width = x2 - x1 + 1; width = x2 - x1 + 1;
/* adjust x1 and y to viewport */
x1 += current_vp->x;
y += current_vp->y;
bfunc = lcd_blockfuncs[current_vp->drawmode]; bfunc = lcd_blockfuncs[current_vp->drawmode];
dst = &lcd_framebuffer[y>>2][x1]; dst = &lcd_framebuffer[y>>2][x1];
mask = pixmask[y & 3]; mask = pixmask[y & 3];
@ -567,12 +614,12 @@ void lcd_vline(int x, int y1, int y2)
y2 = ny; y2 = ny;
} }
/******************** In viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if (((unsigned)x >= (unsigned)current_vp->width) || (y1 >= current_vp->height) if (((unsigned)x >= (unsigned)current_vp->width) || (y1 >= current_vp->height)
|| (y2 < 0)) || (y2 < 0))
return; return;
/* clipping */
if (y1 < 0) if (y1 < 0)
y1 = 0; y1 = 0;
if (y2 >= current_vp->height) if (y2 >= current_vp->height)
@ -582,6 +629,20 @@ void lcd_vline(int x, int y1, int y2)
y1 += current_vp->y; y1 += current_vp->y;
y2 += current_vp->y; y2 += current_vp->y;
x += current_vp->x; x += current_vp->x;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if (( (unsigned) x >= (unsigned)LCD_WIDTH) || (y1 >= LCD_HEIGHT)
|| (y2 < 0))
return;
/* clipping */
if (y1 < 0)
y1 = 0;
if (y2 >= LCD_HEIGHT)
y2 = LCD_HEIGHT-1;
#endif
bfunc = lcd_blockfuncs[current_vp->drawmode]; bfunc = lcd_blockfuncs[current_vp->drawmode];
dst = &lcd_framebuffer[y1>>2][x]; dst = &lcd_framebuffer[y1>>2][x];
@ -624,12 +685,12 @@ void lcd_fillrect(int x, int y, int width, int height)
lcd_blockfunc_type *bfunc; lcd_blockfunc_type *bfunc;
bool fillopt = false; bool fillopt = false;
/******************** In viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) if ((width <= 0) || (height <= 0) || (x >= current_vp->width)
|| (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) || (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return; return;
/* clipping */
if (x < 0) if (x < 0)
{ {
width += x; width += x;
@ -648,6 +709,30 @@ void lcd_fillrect(int x, int y, int width, int height)
/* adjust for viewport */ /* adjust for viewport */
x += current_vp->x; x += current_vp->x;
y += current_vp->y; y += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|| (x + width <= 0) || (y + height <= 0))
return;
/* clip image in viewport in screen */
if (x < 0)
{
width += x;
x = 0;
}
if (y < 0)
{
height += y;
y = 0;
}
if (x + width > LCD_WIDTH)
width = LCD_WIDTH - x;
if (y + height > LCD_HEIGHT)
height = LCD_HEIGHT - y;
#endif
if (current_vp->drawmode & DRMODE_INVERSEVID) if (current_vp->drawmode & DRMODE_INVERSEVID)
{ {
@ -722,12 +807,12 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
unsigned mask, mask_bottom; unsigned mask, mask_bottom;
lcd_blockfunc_type *bfunc; lcd_blockfunc_type *bfunc;
/******************** Image in viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) || if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return; return;
/* clipping */
if (x < 0) if (x < 0)
{ {
width += x; width += x;
@ -748,6 +833,32 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
/* adjust for viewport */ /* adjust for viewport */
x += current_vp->x; x += current_vp->x;
y += current_vp->y; y += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|| (x + width <= 0) || (y + height <= 0))
return;
/* clip image in viewport in screen */
if (x < 0)
{
width += x;
src_x -= x;
x = 0;
}
if (y < 0)
{
height += y;
src_y -= y;
y = 0;
}
if (x + width > LCD_WIDTH)
width = LCD_WIDTH - x;
if (y + height > LCD_HEIGHT)
height = LCD_HEIGHT - y;
#endif
src += stride * (src_y >> 3) + src_x; /* move starting point */ src += stride * (src_y >> 3) + src_x; /* move starting point */
src_y &= 7; src_y &= 7;
@ -893,12 +1004,12 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
fb_data *dst, *dst_end; fb_data *dst, *dst_end;
unsigned mask, mask_bottom; unsigned mask, mask_bottom;
/******************** Image in viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) if ((width <= 0) || (height <= 0) || (x >= current_vp->width)
|| (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) || (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return; return;
/* clipping */
if (x < 0) if (x < 0)
{ {
width += x; width += x;
@ -919,6 +1030,32 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
/* adjust for viewport */ /* adjust for viewport */
x += current_vp->x; x += current_vp->x;
y += current_vp->y; y += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|| (x + width <= 0) || (y + height <= 0))
return;
/* clip image in viewport in screen */
if (x < 0)
{
width += x;
src_x -= x;
x = 0;
}
if (y < 0)
{
height += y;
src_y -= y;
y = 0;
}
if (x + width > LCD_WIDTH)
width = LCD_WIDTH - x;
if (y + height > LCD_HEIGHT)
height = LCD_HEIGHT - y;
#endif
src += stride * (src_y >> 2) + src_x; /* move starting point */ src += stride * (src_y >> 2) + src_x; /* move starting point */
src_y &= 3; src_y &= 3;

View file

@ -82,6 +82,28 @@ void LCDFN(set_viewport)(struct viewport* vp)
fg_pattern = patterns[current_vp->fg_pattern & 3]; fg_pattern = patterns[current_vp->fg_pattern & 3];
bg_pattern = patterns[current_vp->bg_pattern & 3]; bg_pattern = patterns[current_vp->bg_pattern & 3];
#if defined(SIMULATOR)
/* Force the viewport to be within bounds. If this happens it should
* be considered an error - the viewport will not draw as it might be
* expected.
*/
if((unsigned) current_vp->x > (unsigned) LCDM(WIDTH)
|| (unsigned) current_vp->y > (unsigned) LCDM(HEIGHT)
|| current_vp->x + current_vp->width > LCDM(WIDTH)
|| current_vp->y + current_vp->height > LCDM(HEIGHT))
{
#if !defined(HAVE_VIEWPORT_CLIP)
DEBUGF("ERROR: "
#else
DEBUGF("NOTE: "
#endif
"set_viewport out of bounds: x: %d y: %d width: %d height:%d\n",
current_vp->x, current_vp->y,
current_vp->width, current_vp->height);
}
#endif
} }
void LCDFN(update_viewport)(void) void LCDFN(update_viewport)(void)
@ -443,8 +465,13 @@ void LCDFN(clear_viewport)(void)
/* Set a single pixel */ /* Set a single pixel */
void LCDFN(drawpixel)(int x, int y) void LCDFN(drawpixel)(int x, int y)
{ {
if (((unsigned)x < (unsigned)current_vp->width) && if ( ((unsigned)x < (unsigned)current_vp->width)
((unsigned)y < (unsigned)current_vp->height)) && ((unsigned)y < (unsigned)current_vp->height)
#if defined(HAVE_VIEWPORT_CLIP)
&& ((unsigned)x < (unsigned)LCDM(WIDTH))
&& ((unsigned)y < (unsigned)LCDM(HEIGHT))
#endif
)
LCDFN(pixelfuncs)[current_vp->drawmode](current_vp->x+x, current_vp->y+y); LCDFN(pixelfuncs)[current_vp->drawmode](current_vp->x+x, current_vp->y+y);
} }
@ -513,8 +540,13 @@ void LCDFN(drawline)(int x1, int y1, int x2, int y2)
for (i = 0; i < numpixels; i++) for (i = 0; i < numpixels; i++)
{ {
if (((unsigned)x < (unsigned)current_vp->width) && if ( ((unsigned)x < (unsigned)current_vp->width)
((unsigned)y < (unsigned)current_vp->height)) && ((unsigned)y < (unsigned)current_vp->height)
#if defined(HAVE_VIEWPORT_CLIP)
&& ((unsigned)x < (unsigned)LCDM(WIDTH))
&& ((unsigned)y < (unsigned)LCDM(HEIGHT))
#endif
)
pfunc(current_vp->x + x, current_vp->y + y); pfunc(current_vp->x + x, current_vp->y + y);
if (d < 0) if (d < 0)
@ -548,24 +580,40 @@ void LCDFN(hline)(int x1, int x2, int y)
x1 = x2; x1 = x2;
x2 = x; x2 = x;
} }
/******************** In viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if (((unsigned)y >= (unsigned)current_vp->height) || (x1 >= current_vp->width) if (((unsigned)y >= (unsigned)current_vp->height) || (x1 >= current_vp->width)
|| (x2 < 0)) || (x2 < 0))
return; return;
/* clipping */
if (x1 < 0) if (x1 < 0)
x1 = 0; x1 = 0;
if (x2 >= current_vp->width) if (x2 >= current_vp->width)
x2 = current_vp->width-1; x2 = current_vp->width-1;
width = x2 - x1 + 1;
/* adjust x1 and y to viewport */ /* adjust x1 and y to viewport */
x1 += current_vp->x; x1 += current_vp->x;
y += current_vp->y; y += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
x2 += current_vp->x;
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if (((unsigned)y >= (unsigned) LCDM(HEIGHT)) || (x1 >= LCDM(WIDTH))
|| (x2 < 0))
return;
/* clipping */
if (x1 < 0)
x1 = 0;
if (x2 >= LCDM(WIDTH))
x2 = LCDM(WIDTH)-1;
#endif
width = x2 - x1 + 1;
bfunc = LCDFN(blockfuncs)[current_vp->drawmode]; bfunc = LCDFN(blockfuncs)[current_vp->drawmode];
dst = &LCDFN(framebuffer)[y>>3][x1]; dst = &LCDFN(framebuffer)[y>>3][x1];
mask = 0x0101 << (y & 7); mask = 0x0101 << (y & 7);
@ -592,12 +640,12 @@ void LCDFN(vline)(int x, int y1, int y2)
y2 = ny; y2 = ny;
} }
/******************** In viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if (((unsigned)x >= (unsigned)current_vp->width) || (y1 >= current_vp->height) if (((unsigned)x >= (unsigned)current_vp->width) || (y1 >= current_vp->height)
|| (y2 < 0)) || (y2 < 0))
return; return;
/* clipping */
if (y1 < 0) if (y1 < 0)
y1 = 0; y1 = 0;
if (y2 >= current_vp->height) if (y2 >= current_vp->height)
@ -607,6 +655,20 @@ void LCDFN(vline)(int x, int y1, int y2)
y1 += current_vp->y; y1 += current_vp->y;
y2 += current_vp->y; y2 += current_vp->y;
x += current_vp->x; x += current_vp->x;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if (( (unsigned) x >= (unsigned)LCDM(WIDTH)) || (y1 >= LCDM(HEIGHT))
|| (y2 < 0))
return;
/* clipping */
if (y1 < 0)
y1 = 0;
if (y2 >= LCDM(HEIGHT))
y2 = LCDM(HEIGHT)-1;
#endif
bfunc = LCDFN(blockfuncs)[current_vp->drawmode]; bfunc = LCDFN(blockfuncs)[current_vp->drawmode];
dst = &LCDFN(framebuffer)[y1>>3][x]; dst = &LCDFN(framebuffer)[y1>>3][x];
@ -651,12 +713,12 @@ void LCDFN(fillrect)(int x, int y, int width, int height)
LCDFN(blockfunc_type) *bfunc; LCDFN(blockfunc_type) *bfunc;
bool fillopt = false; bool fillopt = false;
/******************** In viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) if ((width <= 0) || (height <= 0) || (x >= current_vp->width)
|| (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) || (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return; return;
/* clipping */
if (x < 0) if (x < 0)
{ {
width += x; width += x;
@ -675,6 +737,31 @@ void LCDFN(fillrect)(int x, int y, int width, int height)
/* adjust for viewport */ /* adjust for viewport */
x += current_vp->x; x += current_vp->x;
y += current_vp->y; y += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if ((x >= LCDM(WIDTH)) || (y >= LCDM(HEIGHT))
|| (x + width <= 0) || (y + height <= 0))
return;
/* clip image in viewport in screen */
if (x < 0)
{
width += x;
x = 0;
}
if (y < 0)
{
height += y;
y = 0;
}
if (x + width > LCDM(WIDTH))
width = LCDM(WIDTH) - x;
if (y + height > LCDM(HEIGHT))
height = LCDM(HEIGHT) - y;
#endif
if (current_vp->drawmode & DRMODE_INVERSEVID) if (current_vp->drawmode & DRMODE_INVERSEVID)
{ {
@ -751,12 +838,12 @@ void ICODE_ATTR LCDFN(mono_bitmap_part)(const unsigned char *src, int src_x,
unsigned data, mask, mask_bottom; unsigned data, mask, mask_bottom;
LCDFN(blockfunc_type) *bfunc; LCDFN(blockfunc_type) *bfunc;
/******************** Image in viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) || if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return; return;
/* clipping */
if (x < 0) if (x < 0)
{ {
width += x; width += x;
@ -777,6 +864,32 @@ void ICODE_ATTR LCDFN(mono_bitmap_part)(const unsigned char *src, int src_x,
/* adjust for viewport */ /* adjust for viewport */
x += current_vp->x; x += current_vp->x;
y += current_vp->y; y += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if ((x >= LCDM(WIDTH)) || (y >= LCDM(HEIGHT))
|| (x + width <= 0) || (y + height <= 0))
return;
/* clip image in viewport in screen */
if (x < 0)
{
width += x;
src_x -= x;
x = 0;
}
if (y < 0)
{
height += y;
src_y -= y;
y = 0;
}
if (x + width > LCDM(WIDTH))
width = LCDM(WIDTH) - x;
if (y + height > LCDM(HEIGHT))
height = LCDM(HEIGHT) - y;
#endif
src += stride * (src_y >> 3) + src_x; /* move starting point */ src += stride * (src_y >> 3) + src_x; /* move starting point */
src_y &= 7; src_y &= 7;
@ -893,12 +1006,12 @@ void ICODE_ATTR LCDFN(bitmap_part)(const FBFN(data) *src, int src_x,
FBFN(data) *dst, *dst_end; FBFN(data) *dst, *dst_end;
unsigned mask, mask_bottom; unsigned mask, mask_bottom;
/******************** Image in viewport clipping **********************/
/* nothing to draw? */ /* nothing to draw? */
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) if ((width <= 0) || (height <= 0) || (x >= current_vp->width)
|| (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0)) || (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
return; return;
/* clipping */
if (x < 0) if (x < 0)
{ {
width += x; width += x;
@ -920,6 +1033,32 @@ void ICODE_ATTR LCDFN(bitmap_part)(const FBFN(data) *src, int src_x,
x += current_vp->x; x += current_vp->x;
y += current_vp->y; y += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
/********************* Viewport on screen clipping ********************/
/* nothing to draw? */
if ((x >= LCDM(WIDTH)) || (y >= LCDM(HEIGHT))
|| (x + width <= 0) || (y + height <= 0))
return;
/* clip image in viewport in screen */
if (x < 0)
{
width += x;
src_x -= x;
x = 0;
}
if (y < 0)
{
height += y;
src_y -= y;
y = 0;
}
if (x + width > LCDM(WIDTH))
width = LCDM(WIDTH) - x;
if (y + height > LCDM(HEIGHT))
height = LCDM(HEIGHT) - y;
#endif
src += stride * (src_y >> 3) + src_x; /* move starting point */ src += stride * (src_y >> 3) + src_x; /* move starting point */
src_y &= 7; src_y &= 7;
y -= src_y; y -= src_y;

View file

@ -84,6 +84,28 @@ void lcd_set_viewport(struct viewport* vp)
current_vp = &default_vp; current_vp = &default_vp;
else else
current_vp = vp; current_vp = vp;
#if defined(SIMULATOR)
/* Force the viewport to be within bounds. If this happens it should
* be considered an error - the viewport will not draw as it might be
* expected.
*/
if((unsigned) current_vp->x > (unsigned) LCD_WIDTH
|| (unsigned) current_vp->y > (unsigned) LCD_HEIGHT
|| current_vp->x + current_vp->width > LCD_WIDTH
|| current_vp->y + current_vp->height > LCD_HEIGHT)
{
#if !defined(HAVE_VIEWPORT_CLIP)
DEBUGF("ERROR: "
#else
DEBUGF("NOTE: "
#endif
"set_viewport out of bounds: x: %d y: %d width: %d height:%d\n",
current_vp->x, current_vp->y,
current_vp->width, current_vp->height);
}
#endif
} }
void lcd_update_viewport(void) void lcd_update_viewport(void)
@ -250,6 +272,11 @@ static void lcd_putxchar(int x, int y, int xchar)
x += current_vp->x; x += current_vp->x;
y += current_vp->y; y += current_vp->y;
#if defined(HAVE_VIEWPORT_CLIP)
if((unsigned)x > (unsigned)LCD_WIDTH || (unsigned)y > (unsigned)LCD_HEIGHT)
return;
#endif
lcd_char = lcd_charbuffer[y][x]; lcd_char = lcd_charbuffer[y][x];
if (lcd_char < lcd_pattern_count) /* old char was soft */ if (lcd_char < lcd_pattern_count) /* old char was soft */

View file

@ -65,6 +65,9 @@
/* define this if the target has volume keys which can be used in the lists */ /* define this if the target has volume keys which can be used in the lists */
#define HAVE_VOLUME_IN_LIST #define HAVE_VOLUME_IN_LIST
/* define this if you want viewport clipping enabled for safe LCD functions */
#define HAVE_VIEWPORT_CLIP
/* LCD dimensions */ /* LCD dimensions */
#define CONFIG_LCD LCD_MROBE500 #define CONFIG_LCD LCD_MROBE500