1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * New greyscale framework
12 * This is a generic framework to display 129 shades of grey on low-depth
13 * bitmap LCDs (Archos b&w, Iriver & Ipod 4-grey) within plugins.
15 * Copyright (C) 2008 Jens Arnold
17 * All files in this archive are subject to the GNU General Public License.
18 * See the file COPYING in the source tree root for full license agreement.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ****************************************************************************/
30 #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4)
32 /* The greyscale lib uses 8 bit brightness values natively on input. */
33 #define GREY_BRIGHTNESS(y) (y)
35 /* Some predefined levels for convenience: */
36 #define GREY_BLACK GREY_BRIGHTNESS(0)
37 #define GREY_DARKGRAY GREY_BRIGHTNESS(85)
38 #define GREY_LIGHTGRAY GREY_BRIGHTNESS(170)
39 #define GREY_WHITE GREY_BRIGHTNESS(255)
41 /* Greyscale library management structure declaration. You need one of these
42 * in every plugin using the library, depending on whether the structure should
44 #define GREY_INFO_STRUCT struct _grey_info _grey_info SHAREDBSS_ATTR;
45 #define GREY_INFO_STRUCT_IRAM struct _grey_info _grey_info IBSS_ATTR;
47 /* Features you can request on library init (ORed together): */
48 #define GREY_BUFFERED 0x0001 /* Use a chunky buffer */
49 #define GREY_RAWMAPPED 0x0002 /* No gamma & LCD linearisation */
50 #define GREY_ON_COP 0x0004 /* Run ISR on COP (PP targets) */
51 /* TODO: only usable in conjunction with GREY_INFO_STRUCT_IRAM atm */
53 /* Library initialisation and release */
54 bool grey_init(struct plugin_api
* newrb
, unsigned char *gbuf
, long gbuf_size
,
55 unsigned features
, int width
, int height
, long *buf_taken
);
56 void grey_release(void);
58 /* Special functions */
59 void grey_show(bool enable
);
60 void grey_deferred_lcd_update(void);
62 /* Update functions */
63 void grey_update(void);
64 void grey_update_rect(int x
, int y
, int width
, int height
);
66 /* Parameter handling */
67 void grey_set_position(int x
, int y
);
68 void grey_set_drawmode(int mode
);
69 int grey_get_drawmode(void);
70 void grey_set_foreground(unsigned brightness
);
71 unsigned grey_get_foreground(void);
72 void grey_set_background(unsigned brightness
);
73 unsigned grey_get_background(void);
74 void grey_set_drawinfo(int mode
, unsigned fg_brightness
, unsigned bg_brightness
);
75 void grey_setfont(int newfont
);
76 int grey_getstringsize(const unsigned char *str
, int *w
, int *h
);
79 void grey_clear_display(void);
80 void grey_ub_clear_display(void);
83 void grey_drawpixel(int x
, int y
);
86 void grey_drawline(int x1
, int y1
, int x2
, int y2
);
87 void grey_hline(int x1
, int x2
, int y
);
88 void grey_vline(int x
, int y1
, int y2
);
89 void grey_drawrect(int x
, int y
, int nx
, int ny
);
91 /* Filled primitives */
92 void grey_fillrect(int x
, int y
, int nx
, int ny
);
93 void grey_filltriangle(int x1
, int y1
, int x2
, int y2
, int x3
, int y3
);
96 void grey_mono_bitmap_part(const unsigned char *src
, int src_x
, int src_y
,
97 int stride
, int x
, int y
, int width
, int height
);
98 void grey_mono_bitmap(const unsigned char *src
, int x
, int y
, int width
,
100 void grey_gray_bitmap_part(const unsigned char *src
, int src_x
, int src_y
,
101 int stride
, int x
, int y
, int width
, int height
);
102 void grey_gray_bitmap(const unsigned char *src
, int x
, int y
, int width
,
104 void grey_ub_gray_bitmap_part(const unsigned char *src
, int src_x
, int src_y
,
105 int stride
, int x
, int y
, int width
, int height
);
106 void grey_ub_gray_bitmap(const unsigned char *src
, int x
, int y
, int width
,
110 void grey_putsxyofs(int x
, int y
, int ofs
, const unsigned char *str
);
111 void grey_putsxy(int x
, int y
, const unsigned char *str
);
114 void grey_scroll_left(int count
);
115 void grey_scroll_right(int count
);
116 void grey_scroll_up(int count
);
117 void grey_scroll_down(int count
);
118 void grey_ub_scroll_left(int count
);
119 void grey_ub_scroll_right(int count
);
120 void grey_ub_scroll_up(int count
);
121 void grey_ub_scroll_down(int count
);
123 /*** Internal stuff ***/
125 /* standard gamma (s23p8) */
126 #ifdef SIMULATOR /* Standard PC gamma */
127 #define _GREY_GAMMA ((200<<8)/100)
128 #else /* Target LCDs have a smaller contrast range */
129 #define _GREY_GAMMA ((180<<8)/100)
132 /* flag definitions */
133 #define _GREY_RUNNING 0x8000 /* greyscale overlay is running */
134 #define _GREY_DEFERRED_UPDATE 0x4000 /* lcd_update() requested */
135 #define _GREY_BACKLIGHT_ON 0x2000 /* backlight is active - only used on 1st+2nd Gen */
137 /* fast unsigned multiplication (16x16bit->32bit or 32x32bit->32bit,
138 * whichever is faster for the architecture) */
140 #define _GREY_MULUQ(a, b) ((uint32_t) (((uint32_t) (a)) * ((uint32_t) (b))))
142 #define _GREY_MULUQ(a, b) ((uint32_t) (((uint16_t) (a)) * ((uint16_t) (b))))
145 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
146 #define _GREY_BSHIFT 0
147 #else /* vertical packing or vertical interleaved */
148 #if (LCD_DEPTH == 1) || (LCD_PIXELFORMAT == VERTICAL_INTERLEAVED)
149 #define _GREY_BSHIFT 3
151 #define _GREY_BSHIFT 2
153 #endif /* LCD_PIXELFORMAT */
155 #define _GREY_BSIZE (1<<_GREY_BSHIFT)
156 #define _GREY_BMASK (_GREY_BSIZE-1)
158 /* The greyscale buffer management structure */
165 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
166 int bx
; /* 8-pixel units */
167 int bwidth
; /* 8-pixel units */
168 #else /* vertical packing or vertical interleaved */
169 int by
; /* 4-pixel or 8-pixel units */
170 int bheight
; /* 4-pixel or 8-pixel units */
172 unsigned long flags
; /* various flags, see #defines */
173 struct plugin_api
*rb
; /* plugin API pointer */
174 unsigned char *values
; /* start of greyscale pixel values */
175 unsigned char *phases
; /* start of greyscale pixel phases */
176 unsigned char *buffer
; /* start of chunky pixel buffer (for buffered mode) */
177 unsigned char gvalue
[256]; /* calculated brightness -> greyvalue table */
178 int fg_brightness
; /* current foreground brightness */
179 int bg_brightness
; /* current background brightness */
180 int drawmode
; /* current draw mode */
181 int curfont
; /* current selected font */
184 /* Global variable, defined in the plugin */
185 extern struct _grey_info _grey_info
;
187 #endif /* HAVE_LCD_BITMAP && (LCD_DEPTH < 4) */
188 #endif /* __GREY_H__ */