summaryrefslogtreecommitdiff
path: root/apps/plugins/lib/gray_parm.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lib/gray_parm.c')
-rw-r--r--apps/plugins/lib/gray_parm.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/apps/plugins/lib/gray_parm.c b/apps/plugins/lib/gray_parm.c
new file mode 100644
index 0000000000..c66cc33339
--- /dev/null
+++ b/apps/plugins/lib/gray_parm.c
@@ -0,0 +1,107 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Greyscale framework
11* Parameter handling
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-2005 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/* Set position of the top left corner of the greyscale overlay
33 Note that by is in pixel-block units (8 on Archos/SH1, 4 on H1x0) */
34void gray_set_position(int x, int by)
35{
36 _gray_info.x = x;
37 _gray_info.by = by;
38
39 if (_gray_info.flags & _GRAY_RUNNING)
40 _gray_info.flags |= _GRAY_DEFERRED_UPDATE;
41}
42
43/* Set the draw mode for subsequent drawing operations */
44void gray_set_drawmode(int mode)
45{
46 _gray_info.drawmode = mode & (DRMODE_SOLID|DRMODE_INVERSEVID);
47}
48
49/* Return the current draw mode */
50int gray_get_drawmode(void)
51{
52 return _gray_info.drawmode;
53}
54
55/* Set the foreground shade for subsequent drawing operations */
56void gray_set_foreground(int brightness)
57{
58 unsigned data = MULU16(_LEVEL_FAC * _gray_info.depth, brightness & 0xFF) + 127;
59
60 _gray_info.fg_brightness = (data + (data >> 8)) >> 8; /* approx. data / 255 */
61}
62
63/* Return the current foreground shade */
64int gray_get_foreground(void)
65{
66 return (_gray_info.fg_brightness * 255 + ((_LEVEL_FAC * _gray_info.depth) >> 1))
67 / (_LEVEL_FAC * _gray_info.depth);
68}
69
70/* Set the background shade for subsequent drawing operations */
71void gray_set_background(int brightness)
72{
73 unsigned data = MULU16(_LEVEL_FAC * _gray_info.depth, brightness & 0xFF) + 127;
74
75 _gray_info.bg_brightness = (data + (data >> 8)) >> 8; /* approx. data / 255 */
76}
77
78/* Return the current background shade */
79int gray_get_background(void)
80{
81 return (_gray_info.bg_brightness * 255 + ((_LEVEL_FAC * _gray_info.depth) >> 1))
82 / (_LEVEL_FAC * _gray_info.depth);
83}
84
85/* Set draw mode, foreground and background shades at once */
86void gray_set_drawinfo(int mode, int fg_brightness, int bg_brightness)
87{
88 gray_set_drawmode(mode);
89 gray_set_foreground(fg_brightness);
90 gray_set_background(bg_brightness);
91}
92
93/* Set font for the text output routines */
94void gray_setfont(int newfont)
95{
96 _gray_info.curfont = newfont;
97}
98
99/* Get width and height of a text when printed with the current font */
100int gray_getstringsize(const unsigned char *str, int *w, int *h)
101{
102 return _gray_rb->font_getstringsize(str, w, h, _gray_info.curfont);
103}
104
105#endif /* HAVE_LCD_BITMAP */
106#endif /* !SIMULATOR */
107