MPEGPlayer: Skip to next file when there is a problem with a video file in all-play...
[kugel-rb.git] / firmware / drivers / lcd-16bit.c
blobbe4f21f4121bd3425855a6ca76e6ff449f32e531
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 by Dave Chapman
12 * Rockbox driver for 16-bit colour LCDs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
23 #include "config.h"
25 #include "cpu.h"
26 #include "lcd.h"
27 #include "kernel.h"
28 #include "thread.h"
29 #include <stdlib.h>
30 #include "string-extra.h" /* mem*() */
31 #include "file.h"
32 #include "debug.h"
33 #include "system.h"
34 #include "font.h"
35 #include "rbunicode.h"
36 #include "bidi.h"
37 #include "scroll_engine.h"
39 enum fill_opt {
40 OPT_NONE = 0,
41 OPT_SET,
42 OPT_COPY
45 /*** globals ***/
46 fb_data lcd_framebuffer[LCD_FBHEIGHT][LCD_FBWIDTH]
47 IRAM_LCDFRAMEBUFFER CACHEALIGN_AT_LEAST_ATTR(16);
50 static fb_data* lcd_backdrop = NULL;
51 static long lcd_backdrop_offset IDATA_ATTR = 0;
53 static struct viewport default_vp =
55 .x = 0,
56 .y = 0,
57 .width = LCD_WIDTH,
58 .height = LCD_HEIGHT,
59 .font = FONT_SYSFIXED,
60 .drawmode = DRMODE_SOLID,
61 .fg_pattern = LCD_DEFAULT_FG,
62 .bg_pattern = LCD_DEFAULT_BG,
63 .lss_pattern = LCD_DEFAULT_BG,
64 .lse_pattern = LCD_DEFAULT_BG,
65 .lst_pattern = LCD_DEFAULT_BG,
68 static struct viewport* current_vp IDATA_ATTR = &default_vp;
70 /* LCD init */
71 void lcd_init(void)
73 lcd_clear_display();
75 /* Call device specific init */
76 lcd_init_device();
77 scroll_init();
79 /*** Viewports ***/
81 void lcd_set_viewport(struct viewport* vp)
83 if (vp == NULL)
84 current_vp = &default_vp;
85 else
86 current_vp = vp;
88 #if defined(SIMULATOR)
89 /* Force the viewport to be within bounds. If this happens it should
90 * be considered an error - the viewport will not draw as it might be
91 * expected.
93 if((unsigned) current_vp->x > (unsigned) LCD_WIDTH
94 || (unsigned) current_vp->y > (unsigned) LCD_HEIGHT
95 || current_vp->x + current_vp->width > LCD_WIDTH
96 || current_vp->y + current_vp->height > LCD_HEIGHT)
98 #if !defined(HAVE_VIEWPORT_CLIP)
99 DEBUGF("ERROR: "
100 #else
101 DEBUGF("NOTE: "
102 #endif
103 "set_viewport out of bounds: x: %d y: %d width: %d height:%d\n",
104 current_vp->x, current_vp->y,
105 current_vp->width, current_vp->height);
108 #endif
111 void lcd_update_viewport(void)
113 lcd_update_rect(current_vp->x, current_vp->y,
114 current_vp->width, current_vp->height);
117 void lcd_update_viewport_rect(int x, int y, int width, int height)
119 lcd_update_rect(current_vp->x + x, current_vp->y + y, width, height);
122 /*** parameter handling ***/
124 void lcd_set_drawmode(int mode)
126 current_vp->drawmode = mode & (DRMODE_SOLID|DRMODE_INVERSEVID);
129 int lcd_get_drawmode(void)
131 return current_vp->drawmode;
134 void lcd_set_foreground(unsigned color)
136 current_vp->fg_pattern = color;
139 unsigned lcd_get_foreground(void)
141 return current_vp->fg_pattern;
144 void lcd_set_background(unsigned color)
146 current_vp->bg_pattern = color;
149 unsigned lcd_get_background(void)
151 return current_vp->bg_pattern;
154 void lcd_set_selector_start(unsigned color)
156 current_vp->lss_pattern = color;
159 void lcd_set_selector_end(unsigned color)
161 current_vp->lse_pattern = color;
164 void lcd_set_selector_text(unsigned color)
166 current_vp->lst_pattern = color;
169 void lcd_set_drawinfo(int mode, unsigned fg_color, unsigned bg_color)
171 lcd_set_drawmode(mode);
172 current_vp->fg_pattern = fg_color;
173 current_vp->bg_pattern = bg_color;
176 int lcd_getwidth(void)
178 return current_vp->width;
181 int lcd_getheight(void)
183 return current_vp->height;
186 void lcd_setfont(int newfont)
188 current_vp->font = newfont;
191 int lcd_getfont(void)
193 return current_vp->font;
196 int lcd_getstringsize(const unsigned char *str, int *w, int *h)
198 return font_getstringsize(str, w, h, current_vp->font);
201 /*** low-level drawing functions ***/
203 #define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)])
205 static void ICODE_ATTR setpixel(fb_data *address)
207 *address = current_vp->fg_pattern;
210 static void ICODE_ATTR clearpixel(fb_data *address)
212 *address = current_vp->bg_pattern;
215 static void ICODE_ATTR clearimgpixel(fb_data *address)
217 *address = *(fb_data *)((long)address + lcd_backdrop_offset);
220 static void ICODE_ATTR flippixel(fb_data *address)
222 *address = ~(*address);
225 static void ICODE_ATTR nopixel(fb_data *address)
227 (void)address;
230 lcd_fastpixelfunc_type* const lcd_fastpixelfuncs_bgcolor[8] = {
231 flippixel, nopixel, setpixel, setpixel,
232 nopixel, clearpixel, nopixel, clearpixel
235 lcd_fastpixelfunc_type* const lcd_fastpixelfuncs_backdrop[8] = {
236 flippixel, nopixel, setpixel, setpixel,
237 nopixel, clearimgpixel, nopixel, clearimgpixel
240 lcd_fastpixelfunc_type* const * lcd_fastpixelfuncs = lcd_fastpixelfuncs_bgcolor;
242 void lcd_set_backdrop(fb_data* backdrop)
244 lcd_backdrop = backdrop;
245 if (backdrop)
247 lcd_backdrop_offset = (long)backdrop - (long)&lcd_framebuffer[0][0];
248 lcd_fastpixelfuncs = lcd_fastpixelfuncs_backdrop;
250 else
252 lcd_backdrop_offset = 0;
253 lcd_fastpixelfuncs = lcd_fastpixelfuncs_bgcolor;
257 fb_data* lcd_get_backdrop(void)
259 return lcd_backdrop;
262 /*** drawing functions ***/
264 /* Clear the current viewport */
265 void lcd_clear_viewport(void)
267 fb_data *dst, *dst_end;
269 dst = LCDADDR(current_vp->x, current_vp->y);
270 dst_end = dst + current_vp->height * LCD_WIDTH;
272 if (current_vp->drawmode & DRMODE_INVERSEVID)
276 memset16(dst, current_vp->fg_pattern, current_vp->width);
277 dst += LCD_WIDTH;
279 while (dst < dst_end);
281 else
283 if (!lcd_backdrop)
287 memset16(dst, current_vp->bg_pattern, current_vp->width);
288 dst += LCD_WIDTH;
290 while (dst < dst_end);
292 else
296 memcpy(dst, (void *)((long)dst + lcd_backdrop_offset),
297 current_vp->width * sizeof(fb_data));
298 dst += LCD_WIDTH;
300 while (dst < dst_end);
304 if (current_vp == &default_vp)
306 lcd_scroll_info.lines = 0;
308 else
310 lcd_scroll_stop(current_vp);
314 /* Clear the whole display */
315 void lcd_clear_display(void)
317 struct viewport* old_vp = current_vp;
319 current_vp = &default_vp;
321 lcd_clear_viewport();
323 current_vp = old_vp;
326 /* Set a single pixel */
327 void lcd_drawpixel(int x, int y)
329 if ( ((unsigned)x < (unsigned)current_vp->width)
330 && ((unsigned)y < (unsigned)current_vp->height)
331 #if defined(HAVE_VIEWPORT_CLIP)
332 && ((unsigned)x < (unsigned)LCD_WIDTH)
333 && ((unsigned)y < (unsigned)LCD_HEIGHT)
334 #endif
336 lcd_fastpixelfuncs[current_vp->drawmode](LCDADDR(current_vp->x+x, current_vp->y+y));
339 /* Draw a line */
340 void lcd_drawline(int x1, int y1, int x2, int y2)
342 int numpixels;
343 int i;
344 int deltax, deltay;
345 int d, dinc1, dinc2;
346 int x, xinc1, xinc2;
347 int y, yinc1, yinc2;
348 lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[current_vp->drawmode];
350 deltay = abs(y2 - y1);
351 if (deltay == 0)
353 /* DEBUGF("lcd_drawline() called for horizontal line - optimisation.\n"); */
354 lcd_hline(x1, x2, y1);
355 return;
357 deltax = abs(x2 - x1);
358 if (deltax == 0)
360 /* DEBUGF("lcd_drawline() called for vertical line - optimisation.\n"); */
361 lcd_vline(x1, y1, y2);
362 return;
364 xinc2 = 1;
365 yinc2 = 1;
367 if (deltax >= deltay)
369 numpixels = deltax;
370 d = 2 * deltay - deltax;
371 dinc1 = deltay * 2;
372 dinc2 = (deltay - deltax) * 2;
373 xinc1 = 1;
374 yinc1 = 0;
376 else
378 numpixels = deltay;
379 d = 2 * deltax - deltay;
380 dinc1 = deltax * 2;
381 dinc2 = (deltax - deltay) * 2;
382 xinc1 = 0;
383 yinc1 = 1;
385 numpixels++; /* include endpoints */
387 if (x1 > x2)
389 xinc1 = -xinc1;
390 xinc2 = -xinc2;
393 if (y1 > y2)
395 yinc1 = -yinc1;
396 yinc2 = -yinc2;
399 x = x1;
400 y = y1;
402 for (i = 0; i < numpixels; i++)
404 if ( ((unsigned)x < (unsigned)current_vp->width)
405 && ((unsigned)y < (unsigned)current_vp->height)
406 #if defined(HAVE_VIEWPORT_CLIP)
407 && ((unsigned)x < (unsigned)LCD_WIDTH)
408 && ((unsigned)y < (unsigned)LCD_HEIGHT)
409 #endif
411 pfunc(LCDADDR(x + current_vp->x, y + current_vp->y));
413 if (d < 0)
415 d += dinc1;
416 x += xinc1;
417 y += yinc1;
419 else
421 d += dinc2;
422 x += xinc2;
423 y += yinc2;
428 /* Draw a horizontal line (optimised) */
429 void lcd_hline(int x1, int x2, int y)
431 int x, width;
432 unsigned bits = 0;
433 enum fill_opt fillopt = OPT_NONE;
434 fb_data *dst, *dst_end;
436 /* direction flip */
437 if (x2 < x1)
439 x = x1;
440 x1 = x2;
441 x2 = x;
444 /******************** In viewport clipping **********************/
445 /* nothing to draw? */
446 if (((unsigned)y >= (unsigned)current_vp->height) ||
447 (x1 >= current_vp->width) ||
448 (x2 < 0))
449 return;
451 if (x1 < 0)
452 x1 = 0;
453 if (x2 >= current_vp->width)
454 x2 = current_vp->width-1;
456 /* Adjust x1 and y to viewport */
457 x1 += current_vp->x;
458 x2 += current_vp->x;
459 y += current_vp->y;
461 #if defined(HAVE_VIEWPORT_CLIP)
462 /********************* Viewport on screen clipping ********************/
463 /* nothing to draw? */
464 if (((unsigned)y >= (unsigned) LCD_HEIGHT) || (x1 >= LCD_WIDTH)
465 || (x2 < 0))
466 return;
468 /* clipping */
469 if (x1 < 0)
470 x1 = 0;
471 if (x2 >= LCD_WIDTH)
472 x2 = LCD_WIDTH-1;
473 #endif
475 width = x2 - x1 + 1;
477 /* drawmode and optimisation */
478 if (current_vp->drawmode & DRMODE_INVERSEVID)
480 if (current_vp->drawmode & DRMODE_BG)
482 if (!lcd_backdrop)
484 fillopt = OPT_SET;
485 bits = current_vp->bg_pattern;
487 else
488 fillopt = OPT_COPY;
491 else
493 if (current_vp->drawmode & DRMODE_FG)
495 fillopt = OPT_SET;
496 bits = current_vp->fg_pattern;
499 if (fillopt == OPT_NONE && current_vp->drawmode != DRMODE_COMPLEMENT)
500 return;
502 dst = LCDADDR(x1, y);
504 switch (fillopt)
506 case OPT_SET:
507 memset16(dst, bits, width);
508 break;
510 case OPT_COPY:
511 memcpy(dst, (void *)((long)dst + lcd_backdrop_offset),
512 width * sizeof(fb_data));
513 break;
515 case OPT_NONE: /* DRMODE_COMPLEMENT */
516 dst_end = dst + width;
518 *dst = ~(*dst);
519 while (++dst < dst_end);
520 break;
524 /* Draw a vertical line (optimised) */
525 void lcd_vline(int x, int y1, int y2)
527 int y;
528 fb_data *dst, *dst_end;
529 lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[current_vp->drawmode];
531 /* direction flip */
532 if (y2 < y1)
534 y = y1;
535 y1 = y2;
536 y2 = y;
539 /******************** In viewport clipping **********************/
540 /* nothing to draw? */
541 if (((unsigned)x >= (unsigned)current_vp->width) ||
542 (y1 >= current_vp->height) ||
543 (y2 < 0))
544 return;
546 if (y1 < 0)
547 y1 = 0;
548 if (y2 >= current_vp->height)
549 y2 = current_vp->height-1;
551 /* adjust for viewport */
552 x += current_vp->x;
553 y1 += current_vp->y;
554 y2 += current_vp->y;
556 #if defined(HAVE_VIEWPORT_CLIP)
557 /********************* Viewport on screen clipping ********************/
558 /* nothing to draw? */
559 if (( (unsigned) x >= (unsigned)LCD_WIDTH) || (y1 >= LCD_HEIGHT)
560 || (y2 < 0))
561 return;
563 /* clipping */
564 if (y1 < 0)
565 y1 = 0;
566 if (y2 >= LCD_HEIGHT)
567 y2 = LCD_HEIGHT-1;
568 #endif
570 dst = LCDADDR(x , y1);
571 dst_end = dst + (y2 - y1) * LCD_WIDTH;
575 pfunc(dst);
576 dst += LCD_WIDTH;
578 while (dst <= dst_end);
581 /* Draw a rectangular box */
582 void lcd_drawrect(int x, int y, int width, int height)
584 if ((width <= 0) || (height <= 0))
585 return;
587 int x2 = x + width - 1;
588 int y2 = y + height - 1;
590 lcd_vline(x, y, y2);
591 lcd_vline(x2, y, y2);
592 lcd_hline(x, x2, y);
593 lcd_hline(x, x2, y2);
596 /* Fill a rectangular area */
597 void lcd_fillrect(int x, int y, int width, int height)
599 unsigned bits = 0;
600 enum fill_opt fillopt = OPT_NONE;
601 fb_data *dst, *dst_end;
603 /******************** In viewport clipping **********************/
604 /* nothing to draw? */
605 if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
606 (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
607 return;
609 if (x < 0)
611 width += x;
612 x = 0;
614 if (y < 0)
616 height += y;
617 y = 0;
619 if (x + width > current_vp->width)
620 width = current_vp->width - x;
621 if (y + height > current_vp->height)
622 height = current_vp->height - y;
624 /* adjust for viewport */
625 x += current_vp->x;
626 y += current_vp->y;
628 #if defined(HAVE_VIEWPORT_CLIP)
629 /********************* Viewport on screen clipping ********************/
630 /* nothing to draw? */
631 if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
632 || (x + width <= 0) || (y + height <= 0))
633 return;
635 /* clip image in viewport in screen */
636 if (x < 0)
638 width += x;
639 x = 0;
641 if (y < 0)
643 height += y;
644 y = 0;
646 if (x + width > LCD_WIDTH)
647 width = LCD_WIDTH - x;
648 if (y + height > LCD_HEIGHT)
649 height = LCD_HEIGHT - y;
650 #endif
652 /* drawmode and optimisation */
653 if (current_vp->drawmode & DRMODE_INVERSEVID)
655 if (current_vp->drawmode & DRMODE_BG)
657 if (!lcd_backdrop)
659 fillopt = OPT_SET;
660 bits = current_vp->bg_pattern;
662 else
663 fillopt = OPT_COPY;
666 else
668 if (current_vp->drawmode & DRMODE_FG)
670 fillopt = OPT_SET;
671 bits = current_vp->fg_pattern;
674 if (fillopt == OPT_NONE && current_vp->drawmode != DRMODE_COMPLEMENT)
675 return;
677 dst = LCDADDR(x, y);
678 dst_end = dst + height * LCD_WIDTH;
682 fb_data *dst_row, *row_end;
684 switch (fillopt)
686 case OPT_SET:
687 memset16(dst, bits, width);
688 break;
690 case OPT_COPY:
691 memcpy(dst, (void *)((long)dst + lcd_backdrop_offset),
692 width * sizeof(fb_data));
693 break;
695 case OPT_NONE: /* DRMODE_COMPLEMENT */
696 dst_row = dst;
697 row_end = dst_row + width;
699 *dst_row = ~(*dst_row);
700 while (++dst_row < row_end);
701 break;
703 dst += LCD_WIDTH;
705 while (dst < dst_end);
708 /* About Rockbox' internal monochrome bitmap format:
710 * A bitmap contains one bit for every pixel that defines if that pixel is
711 * black (1) or white (0). Bits within a byte are arranged vertically, LSB
712 * at top.
713 * The bytes are stored in row-major order, with byte 0 being top left,
714 * byte 1 2nd from left etc. The first row of bytes defines pixel rows
715 * 0..7, the second row defines pixel row 8..15 etc.
717 * This is the mono bitmap format used on all other targets so far; the
718 * pixel packing doesn't really matter on a 8bit+ target. */
720 /* Draw a partial monochrome bitmap */
722 void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
723 int src_y, int stride, int x, int y,
724 int width, int height)
726 const unsigned char *src_end;
727 fb_data *dst, *dst_end;
728 unsigned dmask = 0x100; /* bit 8 == sentinel */
729 int drmode = current_vp->drawmode;
731 /******************** Image in viewport clipping **********************/
732 /* nothing to draw? */
733 if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
734 (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
735 return;
737 if (x < 0)
739 width += x;
740 src_x -= x;
741 x = 0;
743 if (y < 0)
745 height += y;
746 src_y -= y;
747 y = 0;
749 if (x + width > current_vp->width)
750 width = current_vp->width - x;
751 if (y + height > current_vp->height)
752 height = current_vp->height - y;
754 /* adjust for viewport */
755 x += current_vp->x;
756 y += current_vp->y;
758 #if defined(HAVE_VIEWPORT_CLIP)
759 /********************* Viewport on screen clipping ********************/
760 /* nothing to draw? */
761 if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
762 || (x + width <= 0) || (y + height <= 0))
763 return;
765 /* clip image in viewport in screen */
766 if (x < 0)
768 width += x;
769 src_x -= x;
770 x = 0;
772 if (y < 0)
774 height += y;
775 src_y -= y;
776 y = 0;
778 if (x + width > LCD_WIDTH)
779 width = LCD_WIDTH - x;
780 if (y + height > LCD_HEIGHT)
781 height = LCD_HEIGHT - y;
782 #endif
784 src += stride * (src_y >> 3) + src_x; /* move starting point */
785 src_y &= 7;
786 src_end = src + width;
787 dst = LCDADDR(x, y);
788 dst_end = dst + height * LCD_WIDTH;
790 if (drmode & DRMODE_INVERSEVID)
792 dmask = 0x1ff; /* bit 8 == sentinel */
793 drmode &= DRMODE_SOLID; /* mask out inversevid */
798 const unsigned char *src_col = src++;
799 unsigned data = (*src_col ^ dmask) >> src_y;
800 fb_data *dst_col = dst++;
801 int fg, bg;
802 long bo;
804 #define UPDATE_SRC do { \
805 data >>= 1; \
806 if (data == 0x001) { \
807 src_col += stride; \
808 data = *src_col ^ dmask; \
810 } while (0)
812 switch (drmode)
814 case DRMODE_COMPLEMENT:
817 if (data & 0x01)
818 *dst_col = ~(*dst_col);
820 dst_col += LCD_WIDTH;
821 UPDATE_SRC;
823 while (dst_col < dst_end);
824 break;
826 case DRMODE_BG:
827 if (lcd_backdrop)
829 bo = lcd_backdrop_offset;
832 if (!(data & 0x01))
833 *dst_col = *(fb_data *)((long)dst_col + bo);
835 dst_col += LCD_WIDTH;
836 UPDATE_SRC;
838 while (dst_col < dst_end);
840 else
842 bg = current_vp->bg_pattern;
845 if (!(data & 0x01))
846 *dst_col = bg;
848 dst_col += LCD_WIDTH;
849 UPDATE_SRC;
851 while (dst_col < dst_end);
853 break;
855 case DRMODE_FG:
856 fg = current_vp->fg_pattern;
859 if (data & 0x01)
860 *dst_col = fg;
862 dst_col += LCD_WIDTH;
863 UPDATE_SRC;
865 while (dst_col < dst_end);
866 break;
868 case DRMODE_SOLID:
869 fg = current_vp->fg_pattern;
870 if (lcd_backdrop)
872 bo = lcd_backdrop_offset;
875 *dst_col = (data & 0x01) ? fg
876 : *(fb_data *)((long)dst_col + bo);
877 dst_col += LCD_WIDTH;
878 UPDATE_SRC;
880 while (dst_col < dst_end);
882 else
884 bg = current_vp->bg_pattern;
887 *dst_col = (data & 0x01) ? fg : bg;
888 dst_col += LCD_WIDTH;
889 UPDATE_SRC;
891 while (dst_col < dst_end);
893 break;
896 while (src < src_end);
898 /* Draw a full monochrome bitmap */
899 void lcd_mono_bitmap(const unsigned char *src, int x, int y, int width, int height)
901 lcd_mono_bitmap_part(src, 0, 0, width, x, y, width, height);
904 /* Draw a partial native bitmap */
905 void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
906 int stride, int x, int y, int width,
907 int height)
909 fb_data *dst;
911 /******************** Image in viewport clipping **********************/
912 /* nothing to draw? */
913 if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
914 (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
915 return;
917 if (x < 0)
919 width += x;
920 src_x -= x;
921 x = 0;
923 if (y < 0)
925 height += y;
926 src_y -= y;
927 y = 0;
930 if (x + width > current_vp->width)
931 width = current_vp->width - x;
932 if (y + height > current_vp->height)
933 height = current_vp->height - y;
935 /* adjust for viewport */
936 x += current_vp->x;
937 y += current_vp->y;
939 #if defined(HAVE_VIEWPORT_CLIP)
940 /********************* Viewport on screen clipping ********************/
941 /* nothing to draw? */
942 if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
943 || (x + width <= 0) || (y + height <= 0))
944 return;
946 /* clip image in viewport in screen */
947 if (x < 0)
949 width += x;
950 src_x -= x;
951 x = 0;
953 if (y < 0)
955 height += y;
956 src_y -= y;
957 y = 0;
959 if (x + width > LCD_WIDTH)
960 width = LCD_WIDTH - x;
961 if (y + height > LCD_HEIGHT)
962 height = LCD_HEIGHT - y;
963 #endif
965 src += stride * src_y + src_x; /* move starting point */
966 dst = LCDADDR(x, y);
970 memcpy(dst, src, width * sizeof(fb_data));
971 src += stride;
972 dst += LCD_WIDTH;
974 while (--height > 0);
977 /* Draw a full native bitmap */
978 void lcd_bitmap(const fb_data *src, int x, int y, int width, int height)
980 lcd_bitmap_part(src, 0, 0, width, x, y, width, height);
983 /* Draw a partial native bitmap with transparency and foreground colors */
984 void ICODE_ATTR lcd_bitmap_transparent_part(const fb_data *src, int src_x,
985 int src_y, int stride, int x,
986 int y, int width, int height)
988 fb_data *dst;
989 unsigned fg = current_vp->fg_pattern;
991 /******************** Image in viewport clipping **********************/
992 /* nothing to draw? */
993 if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
994 (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
995 return;
997 if (x < 0)
999 width += x;
1000 src_x -= x;
1001 x = 0;
1003 if (y < 0)
1005 height += y;
1006 src_y -= y;
1007 y = 0;
1010 if (x + width > current_vp->width)
1011 width = current_vp->width - x;
1012 if (y + height > current_vp->height)
1013 height = current_vp->height - y;
1015 /* adjust for viewport */
1016 x += current_vp->x;
1017 y += current_vp->y;
1019 #if defined(HAVE_VIEWPORT_CLIP)
1020 /********************* Viewport on screen clipping ********************/
1021 /* nothing to draw? */
1022 if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
1023 || (x + width <= 0) || (y + height <= 0))
1024 return;
1026 /* clip image in viewport in screen */
1027 if (x < 0)
1029 width += x;
1030 src_x -= x;
1031 x = 0;
1033 if (y < 0)
1035 height += y;
1036 src_y -= y;
1037 y = 0;
1039 if (x + width > LCD_WIDTH)
1040 width = LCD_WIDTH - x;
1041 if (y + height > LCD_HEIGHT)
1042 height = LCD_HEIGHT - y;
1043 #endif
1045 src += stride * src_y + src_x; /* move starting point */
1046 dst = LCDADDR(x, y);
1048 #ifdef CPU_ARM
1050 int w, px;
1051 asm volatile (
1052 ".rowstart: \n"
1053 "mov %[w], %[width] \n" /* Load width for inner loop */
1054 ".nextpixel: \n"
1055 "ldrh %[px], [%[s]], #2 \n" /* Load src pixel */
1056 "add %[d], %[d], #2 \n" /* Uncoditionally increment dst */
1057 /* done here for better pipelining */
1058 "cmp %[px], %[fgcolor] \n" /* Compare to foreground color */
1059 "streqh %[fgpat], [%[d], #-2] \n" /* Store foregroud if match */
1060 "cmpne %[px], %[transcolor] \n" /* Compare to transparent color */
1061 "strneh %[px], [%[d], #-2] \n" /* Store dst if not transparent */
1062 "subs %[w], %[w], #1 \n" /* Width counter has run down? */
1063 "bgt .nextpixel \n" /* More in this row? */
1064 "add %[s], %[s], %[sstp], lsl #1 \n" /* Skip over to start of next line */
1065 "add %[d], %[d], %[dstp], lsl #1 \n"
1066 "subs %[h], %[h], #1 \n" /* Height counter has run down? */
1067 "bgt .rowstart \n" /* More rows? */
1068 : [w]"=&r"(w), [h]"+&r"(height), [px]"=&r"(px),
1069 [s]"+&r"(src), [d]"+&r"(dst)
1070 : [width]"r"(width),
1071 [sstp]"r"(stride - width),
1072 [dstp]"r"(LCD_WIDTH - width),
1073 [transcolor]"r"(TRANSPARENT_COLOR),
1074 [fgcolor]"r"(REPLACEWITHFG_COLOR),
1075 [fgpat]"r"(fg)
1078 #else /* optimized C version */
1081 const fb_data *src_row = src;
1082 fb_data *dst_row = dst;
1083 fb_data *row_end = dst_row + width;
1086 unsigned data = *src_row++;
1087 if (data != TRANSPARENT_COLOR)
1089 if (data == REPLACEWITHFG_COLOR)
1090 data = fg;
1091 *dst_row = data;
1094 while (++dst_row < row_end);
1095 src += stride;
1096 dst += LCD_WIDTH;
1098 while (--height > 0);
1099 #endif
1102 /* Draw a full native bitmap with transparent and foreground colors */
1103 void lcd_bitmap_transparent(const fb_data *src, int x, int y,
1104 int width, int height)
1106 lcd_bitmap_transparent_part(src, 0, 0, width, x, y, width, height);
1109 #include "lcd-bitmap-common.c"