Add support to buildzip.pl for Lua scripts
[kugel-rb.git] / firmware / drivers / lcd-2bit-vi.c
blob9ce952b9e0e58c711d011a1dc5a5ec796eb92aee
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 Jens Arnold
12 * Rockbox driver for 2bit vertically interleaved 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 ****************************************************************************/
24 #include "config.h"
26 #include "lcd.h"
27 #include "kernel.h"
28 #include "thread.h"
29 #include <string.h>
30 #include <stdlib.h>
31 #include "memory.h"
32 #include "file.h"
33 #include "debug.h"
34 #include "system.h"
35 #include "font.h"
36 #include "rbunicode.h"
37 #include "bidi.h"
38 #include "scroll_engine.h"
40 #ifndef LCDFN /* Not compiling for remote - define macros for main LCD. */
41 #define LCDFN(fn) lcd_ ## fn
42 #define FBFN(fn) fb_ ## fn
43 #define LCDM(ma) LCD_ ## ma
44 #define LCDNAME "lcd_"
45 #define MAIN_LCD
46 #endif
48 /*** globals ***/
50 FBFN(data) LCDFN(framebuffer)[LCDM(FBHEIGHT)][LCDM(FBWIDTH)] IRAM_LCDFRAMEBUFFER;
52 static const FBFN(data) patterns[4] = {0xFFFF, 0xFF00, 0x00FF, 0x0000};
54 static FBFN(data) *backdrop = NULL;
55 static long backdrop_offset IDATA_ATTR = 0;
57 static struct viewport default_vp =
59 .x = 0,
60 .y = 0,
61 .width = LCDM(WIDTH),
62 .height = LCDM(HEIGHT),
63 .font = FONT_SYSFIXED,
64 .drawmode = DRMODE_SOLID,
65 .fg_pattern = LCDM(DEFAULT_FG),
66 .bg_pattern = LCDM(DEFAULT_BG)
69 static struct viewport * current_vp IBSS_ATTR;
71 static unsigned fg_pattern IBSS_ATTR;
72 static unsigned bg_pattern IBSS_ATTR;
74 /*** Viewports ***/
76 void LCDFN(set_viewport)(struct viewport* vp)
78 if (vp == NULL)
79 current_vp = &default_vp;
80 else
81 current_vp = vp;
83 fg_pattern = patterns[current_vp->fg_pattern & 3];
84 bg_pattern = patterns[current_vp->bg_pattern & 3];
87 void LCDFN(update_viewport)(void)
89 LCDFN(update_rect)(current_vp->x, current_vp->y,
90 current_vp->width, current_vp->height);
93 void LCDFN(update_viewport_rect)(int x, int y, int width, int height)
95 LCDFN(update_rect)(current_vp->x + x, current_vp->y + y, width, height);
98 /* LCD init */
99 void LCDFN(init)(void)
101 LCDFN(set_viewport)(NULL);
102 LCDFN(clear_display)();
103 #ifndef SIMULATOR
104 LCDFN(init_device)();
105 #endif
106 #ifdef MAIN_LCD
107 scroll_init();
108 #endif
111 /*** parameter handling ***/
113 #if !defined(MAIN_LCD) && defined(HAVE_LCD_COLOR)
114 /* When compiling for remote LCD and the main LCD is colour. */
115 unsigned lcd_remote_color_to_native(unsigned color)
117 unsigned r = (color & 0xf800) >> 10;
118 unsigned g = (color & 0x07e0) >> 5;
119 unsigned b = (color & 0x001f) << 2;
121 * |R|
122 * |Y'| = |0.299000 0.587000 0.114000| |G|
123 * |B|
125 return (5*r + 9*g + b) >> 8;
127 #endif
129 void LCDFN(set_drawmode)(int mode)
131 current_vp->drawmode = mode & (DRMODE_SOLID|DRMODE_INVERSEVID);
134 int LCDFN(get_drawmode)(void)
136 return current_vp->drawmode;
139 void LCDFN(set_foreground)(unsigned brightness)
141 current_vp->fg_pattern = brightness;
142 fg_pattern = patterns[brightness & 3];
145 unsigned LCDFN(get_foreground)(void)
147 return current_vp->fg_pattern;
150 void LCDFN(set_background)(unsigned brightness)
152 current_vp->bg_pattern = brightness;
153 bg_pattern = patterns[brightness & 3];
156 unsigned LCDFN(get_background)(void)
158 return current_vp->bg_pattern;
161 void LCDFN(set_drawinfo)(int mode, unsigned fg_brightness,
162 unsigned bg_brightness)
164 LCDFN(set_drawmode)(mode);
165 LCDFN(set_foreground)(fg_brightness);
166 LCDFN(set_background)(bg_brightness);
169 int LCDFN(getwidth)(void)
171 return current_vp->width;
174 int LCDFN(getheight)(void)
176 return current_vp->height;
178 void LCDFN(setfont)(int newfont)
180 current_vp->font = newfont;
183 int LCDFN(getfont)(void)
185 return current_vp->font;
188 int LCDFN(getstringsize)(const unsigned char *str, int *w, int *h)
190 return font_getstringsize(str, w, h, current_vp->font);
193 /*** low-level drawing functions ***/
195 static void setpixel(int x, int y)
197 unsigned mask = 0x0101 << (y & 7);
198 FBFN(data) *address = &LCDFN(framebuffer)[y>>3][x];
199 unsigned data = *address;
201 *address = data ^ ((data ^ fg_pattern) & mask);
204 static void clearpixel(int x, int y)
206 unsigned mask = 0x0101 << (y & 7);
207 FBFN(data) *address = &LCDFN(framebuffer)[y>>3][x];
208 unsigned data = *address;
210 *address = data ^ ((data ^ bg_pattern) & mask);
213 static void clearimgpixel(int x, int y)
215 unsigned mask = 0x0101 << (y & 7);
216 FBFN(data) *address = &LCDFN(framebuffer)[y>>3][x];
217 unsigned data = *address;
219 *address = data ^ ((data ^ *(FBFN(data) *)((long)address
220 + backdrop_offset)) & mask);
223 static void flippixel(int x, int y)
225 unsigned mask = 0x0101 << (y & 7);
226 FBFN(data) *address = &LCDFN(framebuffer)[y>>3][x];
228 *address ^= mask;
231 static void nopixel(int x, int y)
233 (void)x;
234 (void)y;
237 LCDFN(pixelfunc_type)* const LCDFN(pixelfuncs_bgcolor)[8] = {
238 flippixel, nopixel, setpixel, setpixel,
239 nopixel, clearpixel, nopixel, clearpixel
242 LCDFN(pixelfunc_type)* const LCDFN(pixelfuncs_backdrop)[8] = {
243 flippixel, nopixel, setpixel, setpixel,
244 nopixel, clearimgpixel, nopixel, clearimgpixel
247 LCDFN(pixelfunc_type)* const *LCDFN(pixelfuncs) = LCDFN(pixelfuncs_bgcolor);
249 /* 'mask' and 'bits' contain 2 bits per pixel */
250 static void ICODE_ATTR flipblock(FBFN(data) *address, unsigned mask,
251 unsigned bits)
253 *address ^= bits & mask;
256 static void ICODE_ATTR bgblock(FBFN(data) *address, unsigned mask,
257 unsigned bits)
259 unsigned data = *address;
261 *address = data ^ ((data ^ bg_pattern) & mask & ~bits);
264 static void ICODE_ATTR bgimgblock(FBFN(data) *address, unsigned mask,
265 unsigned bits)
267 unsigned data = *address;
269 *address = data ^ ((data ^ *(FBFN(data) *)((long)address
270 + backdrop_offset)) & mask & ~bits);
273 static void ICODE_ATTR fgblock(FBFN(data) *address, unsigned mask,
274 unsigned bits)
276 unsigned data = *address;
278 *address = data ^ ((data ^ fg_pattern) & mask & bits);
281 static void ICODE_ATTR solidblock(FBFN(data) *address, unsigned mask,
282 unsigned bits)
284 unsigned data = *address;
285 unsigned bgp = bg_pattern;
287 bits = bgp ^ ((bgp ^ fg_pattern) & bits);
288 *address = data ^ ((data ^ bits) & mask);
291 static void ICODE_ATTR solidimgblock(FBFN(data) *address, unsigned mask,
292 unsigned bits)
294 unsigned data = *address;
295 unsigned bgp = *(FBFN(data) *)((long)address + backdrop_offset);
297 bits = bgp ^ ((bgp ^ fg_pattern) & bits);
298 *address = data ^ ((data ^ bits) & mask);
301 static void ICODE_ATTR flipinvblock(FBFN(data) *address, unsigned mask,
302 unsigned bits)
304 *address ^= ~bits & mask;
307 static void ICODE_ATTR bginvblock(FBFN(data) *address, unsigned mask,
308 unsigned bits)
310 unsigned data = *address;
312 *address = data ^ ((data ^ bg_pattern) & mask & bits);
315 static void ICODE_ATTR bgimginvblock(FBFN(data) *address, unsigned mask,
316 unsigned bits)
318 unsigned data = *address;
320 *address = data ^ ((data ^ *(FBFN(data) *)((long)address
321 + backdrop_offset)) & mask & bits);
324 static void ICODE_ATTR fginvblock(FBFN(data) *address, unsigned mask,
325 unsigned bits)
327 unsigned data = *address;
329 *address = data ^ ((data ^ fg_pattern) & mask & ~bits);
332 static void ICODE_ATTR solidinvblock(FBFN(data) *address, unsigned mask,
333 unsigned bits)
335 unsigned data = *address;
336 unsigned fgp = fg_pattern;
338 bits = fgp ^ ((fgp ^ bg_pattern) & bits);
339 *address = data ^ ((data ^ bits) & mask);
342 static void ICODE_ATTR solidimginvblock(FBFN(data) *address, unsigned mask,
343 unsigned bits)
345 unsigned data = *address;
346 unsigned fgp = fg_pattern;
348 bits = fgp ^ ((fgp ^ *(FBFN(data) *)((long)address
349 + backdrop_offset)) & bits);
350 *address = data ^ ((data ^ bits) & mask);
353 LCDFN(blockfunc_type)* const LCDFN(blockfuncs_bgcolor)[8] = {
354 flipblock, bgblock, fgblock, solidblock,
355 flipinvblock, bginvblock, fginvblock, solidinvblock
358 LCDFN(blockfunc_type)* const LCDFN(blockfuncs_backdrop)[8] = {
359 flipblock, bgimgblock, fgblock, solidimgblock,
360 flipinvblock, bgimginvblock, fginvblock, solidimginvblock
363 LCDFN(blockfunc_type)* const *LCDFN(blockfuncs) = LCDFN(blockfuncs_bgcolor);
366 void LCDFN(set_backdrop)(FBFN(data) *bd)
368 backdrop = bd;
369 if (bd)
371 backdrop_offset = (long)bd - (long)LCDFN(framebuffer);
372 LCDFN(pixelfuncs) = LCDFN(pixelfuncs_backdrop);
373 LCDFN(blockfuncs) = LCDFN(blockfuncs_backdrop);
375 else
377 backdrop_offset = 0;
378 LCDFN(pixelfuncs) = LCDFN(pixelfuncs_bgcolor);
379 LCDFN(blockfuncs) = LCDFN(blockfuncs_bgcolor);
383 FBFN(data)* LCDFN(get_backdrop)(void)
385 return backdrop;
388 static inline void setblock(FBFN(data) *address, unsigned mask, unsigned bits)
390 unsigned data = *address;
392 bits ^= data;
393 *address = data ^ (bits & mask);
396 /*** drawing functions ***/
398 /* Clear the whole display */
399 void LCDFN(clear_display)(void)
401 if (default_vp.drawmode & DRMODE_INVERSEVID)
403 memset(LCDFN(framebuffer), patterns[default_vp.fg_pattern & 3],
404 sizeof LCDFN(framebuffer));
406 else
408 if (backdrop)
409 memcpy(LCDFN(framebuffer), backdrop, sizeof LCDFN(framebuffer));
410 else
411 memset(LCDFN(framebuffer), patterns[default_vp.bg_pattern & 3],
412 sizeof LCDFN(framebuffer));
415 LCDFN(scroll_info).lines = 0;
418 /* Clear the current viewport */
419 void LCDFN(clear_viewport)(void)
421 int lastmode;
423 if (current_vp == &default_vp)
425 LCDFN(clear_display)();
427 else
429 lastmode = current_vp->drawmode;
431 /* Invert the INVERSEVID bit and set basic mode to SOLID */
432 current_vp->drawmode = (~lastmode & DRMODE_INVERSEVID) |
433 DRMODE_SOLID;
435 LCDFN(fillrect)(0, 0, current_vp->width, current_vp->height);
437 current_vp->drawmode = lastmode;
439 LCDFN(scroll_stop)(current_vp);
443 /* Set a single pixel */
444 void LCDFN(drawpixel)(int x, int y)
446 if (((unsigned)x < (unsigned)current_vp->width) &&
447 ((unsigned)y < (unsigned)current_vp->height))
448 LCDFN(pixelfuncs)[current_vp->drawmode](current_vp->x+x, current_vp->y+y);
451 /* Draw a line */
452 void LCDFN(drawline)(int x1, int y1, int x2, int y2)
454 int numpixels;
455 int i;
456 int deltax, deltay;
457 int d, dinc1, dinc2;
458 int x, xinc1, xinc2;
459 int y, yinc1, yinc2;
460 LCDFN(pixelfunc_type) *pfunc = LCDFN(pixelfuncs)[current_vp->drawmode];
462 deltax = abs(x2 - x1);
463 if (deltax == 0)
465 DEBUGF(LCDNAME "drawline() called for vertical line - optimisation.\n");
466 LCDFN(vline)(x1, y1, y2);
467 return;
469 deltay = abs(y2 - y1);
470 if (deltay == 0)
472 DEBUGF(LCDNAME "drawline() called for horizontal line - optimisation.\n");
473 LCDFN(hline)(x1, x2, y1);
474 return;
476 xinc2 = 1;
477 yinc2 = 1;
479 if (deltax >= deltay)
481 numpixels = deltax;
482 d = 2 * deltay - deltax;
483 dinc1 = deltay * 2;
484 dinc2 = (deltay - deltax) * 2;
485 xinc1 = 1;
486 yinc1 = 0;
488 else
490 numpixels = deltay;
491 d = 2 * deltax - deltay;
492 dinc1 = deltax * 2;
493 dinc2 = (deltax - deltay) * 2;
494 xinc1 = 0;
495 yinc1 = 1;
497 numpixels++; /* include endpoints */
499 if (x1 > x2)
501 xinc1 = -xinc1;
502 xinc2 = -xinc2;
505 if (y1 > y2)
507 yinc1 = -yinc1;
508 yinc2 = -yinc2;
511 x = x1;
512 y = y1;
514 for (i = 0; i < numpixels; i++)
516 if (((unsigned)x < (unsigned)current_vp->width) &&
517 ((unsigned)y < (unsigned)current_vp->height))
518 pfunc(current_vp->x + x, current_vp->y + y);
520 if (d < 0)
522 d += dinc1;
523 x += xinc1;
524 y += yinc1;
526 else
528 d += dinc2;
529 x += xinc2;
530 y += yinc2;
535 /* Draw a horizontal line (optimised) */
536 void LCDFN(hline)(int x1, int x2, int y)
538 int x;
539 int width;
540 FBFN(data) *dst, *dst_end;
541 unsigned mask;
542 LCDFN(blockfunc_type) *bfunc;
544 /* direction flip */
545 if (x2 < x1)
547 x = x1;
548 x1 = x2;
549 x2 = x;
552 /* nothing to draw? */
553 if (((unsigned)y >= (unsigned)current_vp->height) || (x1 >= current_vp->width)
554 || (x2 < 0))
555 return;
557 /* clipping */
558 if (x1 < 0)
559 x1 = 0;
560 if (x2 >= current_vp->width)
561 x2 = current_vp->width-1;
563 width = x2 - x1 + 1;
565 /* adjust x1 and y to viewport */
566 x1 += current_vp->x;
567 y += current_vp->y;
569 bfunc = LCDFN(blockfuncs)[current_vp->drawmode];
570 dst = &LCDFN(framebuffer)[y>>3][x1];
571 mask = 0x0101 << (y & 7);
573 dst_end = dst + width;
575 bfunc(dst++, mask, 0xFFFFu);
576 while (dst < dst_end);
579 /* Draw a vertical line (optimised) */
580 void LCDFN(vline)(int x, int y1, int y2)
582 int ny;
583 FBFN(data) *dst;
584 unsigned mask, mask_bottom;
585 LCDFN(blockfunc_type) *bfunc;
587 /* direction flip */
588 if (y2 < y1)
590 ny = y1;
591 y1 = y2;
592 y2 = ny;
595 /* nothing to draw? */
596 if (((unsigned)x >= (unsigned)current_vp->width) || (y1 >= current_vp->height)
597 || (y2 < 0))
598 return;
600 /* clipping */
601 if (y1 < 0)
602 y1 = 0;
603 if (y2 >= current_vp->height)
604 y2 = current_vp->height-1;
606 /* adjust for viewport */
607 y1 += current_vp->y;
608 y2 += current_vp->y;
609 x += current_vp->x;
611 bfunc = LCDFN(blockfuncs)[current_vp->drawmode];
612 dst = &LCDFN(framebuffer)[y1>>3][x];
613 ny = y2 - (y1 & ~7);
614 mask = (0xFFu << (y1 & 7)) & 0xFFu;
615 mask |= mask << 8;
616 mask_bottom = 0xFFu >> (~ny & 7);
617 mask_bottom |= mask_bottom << 8;
619 for (; ny >= 8; ny -= 8)
621 bfunc(dst, mask, 0xFFFFu);
622 dst += LCDM(WIDTH);
623 mask = 0xFFFFu;
625 mask &= mask_bottom;
626 bfunc(dst, mask, 0xFFFFu);
629 /* Draw a rectangular box */
630 void LCDFN(drawrect)(int x, int y, int width, int height)
632 if ((width <= 0) || (height <= 0))
633 return;
635 int x2 = x + width - 1;
636 int y2 = y + height - 1;
638 LCDFN(vline)(x, y, y2);
639 LCDFN(vline)(x2, y, y2);
640 LCDFN(hline)(x, x2, y);
641 LCDFN(hline)(x, x2, y2);
644 /* Fill a rectangular area */
645 void LCDFN(fillrect)(int x, int y, int width, int height)
647 int ny;
648 FBFN(data) *dst, *dst_end;
649 unsigned mask, mask_bottom;
650 unsigned bits = 0;
651 LCDFN(blockfunc_type) *bfunc;
652 bool fillopt = false;
654 /* nothing to draw? */
655 if ((width <= 0) || (height <= 0) || (x >= current_vp->width)
656 || (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
657 return;
659 /* clipping */
660 if (x < 0)
662 width += x;
663 x = 0;
665 if (y < 0)
667 height += y;
668 y = 0;
670 if (x + width > current_vp->width)
671 width = current_vp->width - x;
672 if (y + height > current_vp->height)
673 height = current_vp->height - y;
675 /* adjust for viewport */
676 x += current_vp->x;
677 y += current_vp->y;
679 if (current_vp->drawmode & DRMODE_INVERSEVID)
681 if ((current_vp->drawmode & DRMODE_BG) && !backdrop)
683 fillopt = true;
684 bits = bg_pattern;
687 else
689 if (current_vp->drawmode & DRMODE_FG)
691 fillopt = true;
692 bits = fg_pattern;
695 bfunc = LCDFN(blockfuncs)[current_vp->drawmode];
696 dst = &LCDFN(framebuffer)[y>>3][x];
697 ny = height - 1 + (y & 7);
698 mask = (0xFFu << (y & 7)) & 0xFFu;
699 mask |= mask << 8;
700 mask_bottom = 0xFFu >> (~ny & 7);
701 mask_bottom |= mask_bottom << 8;
703 for (; ny >= 8; ny -= 8)
705 if (fillopt && (mask == 0xFFFFu))
706 memset16(dst, bits, width);
707 else
709 FBFN(data) *dst_row = dst;
711 dst_end = dst_row + width;
713 bfunc(dst_row++, mask, 0xFFFFu);
714 while (dst_row < dst_end);
717 dst += LCDM(WIDTH);
718 mask = 0xFFFFu;
720 mask &= mask_bottom;
722 if (fillopt && (mask == 0xFFFFu))
723 memset16(dst, bits, width);
724 else
726 dst_end = dst + width;
728 bfunc(dst++, mask, 0xFFFFu);
729 while (dst < dst_end);
733 /* About Rockbox' internal monochrome bitmap format:
735 * A bitmap contains one bit for every pixel that defines if that pixel is
736 * black (1) or white (0). Bits within a byte are arranged vertically, LSB
737 * at top.
738 * The bytes are stored in row-major order, with byte 0 being top left,
739 * byte 1 2nd from left etc. The first row of bytes defines pixel rows
740 * 0..7, the second row defines pixel row 8..15 etc.
742 * This is similar to the internal lcd hw format. */
744 /* Draw a partial monochrome bitmap */
745 void ICODE_ATTR LCDFN(mono_bitmap_part)(const unsigned char *src, int src_x,
746 int src_y, int stride, int x, int y,
747 int width, int height)
749 int shift, ny;
750 FBFN(data) *dst, *dst_end;
751 unsigned data, mask, mask_bottom;
752 LCDFN(blockfunc_type) *bfunc;
754 /* nothing to draw? */
755 if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
756 (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
757 return;
759 /* clipping */
760 if (x < 0)
762 width += x;
763 src_x -= x;
764 x = 0;
766 if (y < 0)
768 height += y;
769 src_y -= y;
770 y = 0;
772 if (x + width > current_vp->width)
773 width = current_vp->width - x;
774 if (y + height > current_vp->height)
775 height = current_vp->height - y;
777 /* adjust for viewport */
778 x += current_vp->x;
779 y += current_vp->y;
781 src += stride * (src_y >> 3) + src_x; /* move starting point */
782 src_y &= 7;
783 y -= src_y;
784 dst = &LCDFN(framebuffer)[y>>3][x];
785 shift = y & 7;
786 ny = height - 1 + shift + src_y;
788 bfunc = LCDFN(blockfuncs)[current_vp->drawmode];
789 mask = 0xFFu << (shift + src_y);
790 /* not byte-doubled here because shift+src_y can be > 7 */
791 mask_bottom = 0xFFu >> (~ny & 7);
792 mask_bottom |= mask_bottom << 8;
794 if (shift == 0)
796 mask &= 0xFFu;
797 mask |= mask << 8;
799 for (; ny >= 8; ny -= 8)
801 const unsigned char *src_row = src;
802 FBFN(data) *dst_row = dst;
804 dst_end = dst_row + width;
807 data = *src_row++;
808 bfunc(dst_row++, mask, data | (data << 8));
810 while (dst_row < dst_end);
812 src += stride;
813 dst += LCDM(WIDTH);
814 mask = 0xFFFFu;
816 mask &= mask_bottom;
818 dst_end = dst + width;
821 data = *src++;
822 bfunc(dst++, mask, data | (data << 8));
824 while (dst < dst_end);
826 else
828 unsigned ddata;
830 dst_end = dst + width;
833 const unsigned char *src_col = src++;
834 FBFN(data) *dst_col = dst++;
835 unsigned mask_col = mask & 0xFFu;
837 mask_col |= mask_col << 8;
838 data = 0;
840 for (y = ny; y >= 8; y -= 8)
842 data |= *src_col << shift;
844 if (mask_col)
846 ddata = data & 0xFFu;
847 bfunc(dst_col, mask_col, ddata | (ddata << 8));
848 mask_col = 0xFFFFu;
850 else
852 mask_col = (mask >> 8) & 0xFFu;
853 mask_col |= mask_col << 8;
856 src_col += stride;
857 dst_col += LCDM(WIDTH);
858 data >>= 8;
860 data |= *src_col << shift;
861 mask_col &= mask_bottom;
862 ddata = data & 0xFFu;
863 bfunc(dst_col, mask_col, ddata | (ddata << 8));
865 while (dst < dst_end);
869 /* Draw a full monochrome bitmap */
870 void LCDFN(mono_bitmap)(const unsigned char *src, int x, int y, int width,
871 int height)
873 LCDFN(mono_bitmap_part)(src, 0, 0, width, x, y, width, height);
876 /* About Rockbox' internal native bitmap format:
878 * A bitmap contains one bit in each byte of a pair of bytes for every pixel.
879 * 00 = white, 01 = light grey, 10 = dark grey, 11 = black. Bits within a byte
880 * are arranged vertically, LSB at top.
881 * The pairs of bytes are stored as shorts, in row-major order, with word 0
882 * being top left, word 1 2nd from left etc. The first row of words defines
883 * pixel rows 0..7, the second row defines pixel row 8..15 etc.
885 * This is the same as the internal lcd hw format. */
887 /* Draw a partial native bitmap */
888 void ICODE_ATTR LCDFN(bitmap_part)(const FBFN(data) *src, int src_x,
889 int src_y, int stride, int x, int y,
890 int width, int height)
892 int shift, ny;
893 FBFN(data) *dst, *dst_end;
894 unsigned mask, mask_bottom;
896 /* nothing to draw? */
897 if ((width <= 0) || (height <= 0) || (x >= current_vp->width)
898 || (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
899 return;
901 /* clipping */
902 if (x < 0)
904 width += x;
905 src_x -= x;
906 x = 0;
908 if (y < 0)
910 height += y;
911 src_y -= y;
912 y = 0;
914 if (x + width > current_vp->width)
915 width = current_vp->width - x;
916 if (y + height > current_vp->height)
917 height = current_vp->height - y;
919 /* adjust for viewport */
920 x += current_vp->x;
921 y += current_vp->y;
923 src += stride * (src_y >> 3) + src_x; /* move starting point */
924 src_y &= 7;
925 y -= src_y;
926 dst = &LCDFN(framebuffer)[y>>3][x];
927 shift = y & 7;
928 ny = height - 1 + shift + src_y;
930 mask = 0xFFu << (shift + src_y);
931 /* not byte-doubled here because shift+src_y can be > 7 */
932 mask_bottom = 0xFFu >> (~ny & 7);
933 mask_bottom |= mask_bottom << 8;
935 if (shift == 0)
937 mask &= 0xFFu;
938 mask |= mask << 8;
940 for (; ny >= 8; ny -= 8)
942 if (mask == 0xFFFFu)
943 memcpy(dst, src, width * sizeof(FBFN(data)));
944 else
946 const FBFN(data) *src_row = src;
947 FBFN(data) *dst_row = dst;
949 dst_end = dst_row + width;
951 setblock(dst_row++, mask, *src_row++);
952 while (dst_row < dst_end);
954 src += stride;
955 dst += LCDM(WIDTH);
956 mask = 0xFFFFu;
958 mask &= mask_bottom;
960 if (mask == 0xFFFFu)
961 memcpy(dst, src, width * sizeof(FBFN(data)));
962 else
964 dst_end = dst + width;
966 setblock(dst++, mask, *src++);
967 while (dst < dst_end);
970 else
972 unsigned datamask = (0xFFu << shift) & 0xFFu;
974 datamask |= datamask << 8;
976 dst_end = dst + width;
979 const FBFN(data) *src_col = src++;
980 FBFN(data) *dst_col = dst++;
981 unsigned mask_col = mask & 0xFFu;
982 unsigned data, olddata = 0;
984 mask_col |= mask_col << 8;
986 for (y = ny; y >= 8; y -= 8)
988 data = *src_col << shift;
990 if (mask_col)
992 setblock(dst_col, mask_col,
993 olddata ^((olddata ^ data) & datamask));
994 mask_col = 0xFFFFu;
996 else
998 mask_col = (mask >> 8) & 0xFFu;
999 mask_col |= mask_col << 8;
1001 src_col += stride;
1002 dst_col += LCDM(WIDTH);
1003 olddata = data >> 8;
1005 data = *src_col << shift;
1006 setblock(dst_col, mask_col & mask_bottom,
1007 olddata ^((olddata ^ data) & datamask));
1009 while (dst < dst_end);
1013 /* Draw a full native bitmap */
1014 void LCDFN(bitmap)(const FBFN(data) *src, int x, int y, int width, int height)
1016 LCDFN(bitmap_part)(src, 0, 0, width, x, y, width, height);
1019 #include "lcd-bitmap-common.c"