summaryrefslogtreecommitdiff
path: root/apps/plugins/lib/gray_drawbitmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lib/gray_drawbitmap.c')
-rw-r--r--apps/plugins/lib/gray_drawbitmap.c115
1 files changed, 115 insertions, 0 deletions
diff --git a/apps/plugins/lib/gray_drawbitmap.c b/apps/plugins/lib/gray_drawbitmap.c
new file mode 100644
index 0000000000..5ddb19568a
--- /dev/null
+++ b/apps/plugins/lib/gray_drawbitmap.c
@@ -0,0 +1,115 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Grayscale framework
11* gray_drawbitmap() function
12*
13* This is a generic framework to use grayscale display within Rockbox
14* plugins. It obviously does not work for the player.
15*
16* Copyright (C) 2004 Jens Arnold
17*
18* All files in this archive are subject to the GNU General Public License.
19* See the file COPYING in the source tree root for full license agreement.
20*
21* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22* KIND, either express or implied.
23*
24****************************************************************************/
25
26#ifndef SIMULATOR /* not for simulator by now */
27#include "plugin.h"
28
29#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
30#include "gray.h"
31
32/*---------------------------------------------------------------------------
33 Display a bitmap with the current drawinfo
34 ----------------------------------------------------------------------------
35 The drawmode is used as described for gray_set_drawmode()
36
37 This (now) uses the same bitmap format as the core b&w graphics routines,
38 so you can use bmp2rb to generate bitmaps for use with this function as
39 well.
40
41 A bitmap contains one bit for every pixel that defines if that pixel is
42 foreground (1) or background (0). Bits within a byte are arranged
43 vertically, LSB at top.
44 The bytes are stored in row-major order, with byte 0 being top left,
45 byte 1 2nd from left etc. The first row of bytes defines pixel rows
46 0..7, the second row defines pixel row 8..15 etc.
47
48 The <stride> parameter is useful if you want to show only a part of a
49 bitmap. It should always be set to the "row length" of the bitmap.
50 */
51void gray_drawbitmap(unsigned char *src, int x, int y, int nx, int ny,
52 int stride)
53{
54 int shift;
55 unsigned bits, mask_top, mask_bottom;
56 unsigned char *src_col, *dst, *dst_col;
57 void (*blockfunc)(unsigned char *address, unsigned mask, unsigned bits);
58
59 if ((unsigned) x >= (unsigned) _graybuf->width
60 || (unsigned) y >= (unsigned) _graybuf->height)
61 return;
62
63 if ((unsigned) (y + ny) >= (unsigned) _graybuf->height) /* clip bottom */
64 ny = _graybuf->height - y;
65
66 if ((unsigned) (x + nx) >= (unsigned) _graybuf->width) /* clip right */
67 nx = _graybuf->width - x;
68
69 dst = _graybuf->data + x + MULU16(_graybuf->width, y >> 3);
70 shift = y & 7;
71 ny += shift;
72
73 mask_top = 0xFFu << (y & 7);
74 mask_bottom = ~(0xFEu << ((ny - 1) & 7));
75 if (ny <= 8)
76 mask_bottom &= mask_top;
77
78 blockfunc = _gray_blockfuncs[_graybuf->drawmode];
79
80 for(x = 0; x < nx; x++)
81 {
82 src_col = src++;
83 dst_col = dst++;
84 bits = 0;
85 y = 0;
86
87 if (ny > 8)
88 {
89 bits = *src_col << shift;
90 src_col += stride;
91
92 blockfunc(dst_col, mask_top, bits);
93 dst_col += _graybuf->width;
94 bits >>= 8;
95
96 for (y = 8; y < ny - 8; y += 8)
97 {
98 bits |= *src_col << shift;
99 src_col += stride;
100
101 blockfunc(dst_col, 0xFFu, bits);
102 dst_col += _graybuf->width;
103 bits >>= 8;
104 }
105 }
106 if (y + shift < ny)
107 bits |= *src_col << shift;
108
109 blockfunc(dst_col, mask_bottom, bits);
110 }
111}
112
113#endif // #ifdef HAVE_LCD_BITMAP
114#endif // #ifndef SIMULATOR
115