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) */
52 /* Library initialisation and release */
53 bool grey_init(struct plugin_api
* newrb
, unsigned char *gbuf
, long gbuf_size
,
54 unsigned features
, int width
, int height
, long *buf_taken
);
55 void grey_release(void);
57 /* Special functions */
58 void grey_show(bool enable
);
59 void grey_deferred_lcd_update(void);
61 /* Update functions */
62 void grey_update(void);
63 void grey_update_rect(int x
, int y
, int width
, int height
);
65 /* Parameter handling */
66 void grey_set_position(int x
, int y
);
67 void grey_set_drawmode(int mode
);
68 int grey_get_drawmode(void);
69 void grey_set_foreground(unsigned brightness
);
70 unsigned grey_get_foreground(void);
71 void grey_set_background(unsigned brightness
);
72 unsigned grey_get_background(void);
73 void grey_set_drawinfo(int mode
, unsigned fg_brightness
, unsigned bg_brightness
);
74 void grey_setfont(int newfont
);
75 int grey_getstringsize(const unsigned char *str
, int *w
, int *h
);
78 void grey_clear_display(void);
79 void grey_ub_clear_display(void);
82 void grey_drawpixel(int x
, int y
);
85 void grey_drawline(int x1
, int y1
, int x2
, int y2
);
86 void grey_hline(int x1
, int x2
, int y
);
87 void grey_vline(int x
, int y1
, int y2
);
88 void grey_drawrect(int x
, int y
, int nx
, int ny
);
90 /* Filled primitives */
91 void grey_fillrect(int x
, int y
, int nx
, int ny
);
92 void grey_filltriangle(int x1
, int y1
, int x2
, int y2
, int x3
, int y3
);
95 void grey_mono_bitmap_part(const unsigned char *src
, int src_x
, int src_y
,
96 int stride
, int x
, int y
, int width
, int height
);
97 void grey_mono_bitmap(const unsigned char *src
, int x
, int y
, int width
,
99 void grey_gray_bitmap_part(const unsigned char *src
, int src_x
, int src_y
,
100 int stride
, int x
, int y
, int width
, int height
);
101 void grey_gray_bitmap(const unsigned char *src
, int x
, int y
, int width
,
103 void grey_ub_gray_bitmap_part(const unsigned char *src
, int src_x
, int src_y
,
104 int stride
, int x
, int y
, int width
, int height
);
105 void grey_ub_gray_bitmap(const unsigned char *src
, int x
, int y
, int width
,
109 void grey_putsxyofs(int x
, int y
, int ofs
, const unsigned char *str
);
110 void grey_putsxy(int x
, int y
, const unsigned char *str
);
113 void grey_scroll_left(int count
);
114 void grey_scroll_right(int count
);
115 void grey_scroll_up(int count
);
116 void grey_scroll_down(int count
);
117 void grey_ub_scroll_left(int count
);
118 void grey_ub_scroll_right(int count
);
119 void grey_ub_scroll_up(int count
);
120 void grey_ub_scroll_down(int count
);
122 /*** Internal stuff ***/
124 /* standard gamma (s23p8) */
125 #ifdef SIMULATOR /* Standard PC gamma */
126 #define _GREY_GAMMA ((200<<8)/100)
127 #else /* Target LCDs have a smaller contrast range */
128 #define _GREY_GAMMA ((180<<8)/100)
131 /* flag definitions */
132 #define _GREY_RUNNING 0x8000 /* greyscale overlay is running */
133 #define _GREY_DEFERRED_UPDATE 0x4000 /* lcd_update() requested */
134 #define _GREY_BACKLIGHT_ON 0x2000 /* backlight is active - only used on 1st+2nd Gen */
136 /* fast unsigned multiplication (16x16bit->32bit or 32x32bit->32bit,
137 * whichever is faster for the architecture) */
139 #define _GREY_MULUQ(a, b) ((uint32_t) (((uint32_t) (a)) * ((uint32_t) (b))))
141 #define _GREY_MULUQ(a, b) ((uint32_t) (((uint16_t) (a)) * ((uint16_t) (b))))
144 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
145 #define _GREY_BSHIFT 0
146 #else /* vertical packing or vertical interleaved */
147 #if (LCD_DEPTH == 1) || (LCD_PIXELFORMAT == VERTICAL_INTERLEAVED)
148 #define _GREY_BSHIFT 3
150 #define _GREY_BSHIFT 2
152 #endif /* LCD_PIXELFORMAT */
154 #define _GREY_BSIZE (1<<_GREY_BSHIFT)
155 #define _GREY_BMASK (_GREY_BSIZE-1)
157 /* The greyscale buffer management structure */
164 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
165 int bx
; /* 8-pixel units */
166 int bwidth
; /* 8-pixel units */
167 #else /* vertical packing or vertical interleaved */
168 int by
; /* 4-pixel or 8-pixel units */
169 int bheight
; /* 4-pixel or 8-pixel units */
171 unsigned long flags
; /* various flags, see #defines */
172 struct plugin_api
*rb
; /* plugin API pointer */
173 unsigned char *values
; /* start of greyscale pixel values */
174 unsigned char *phases
; /* start of greyscale pixel phases */
175 unsigned char *buffer
; /* start of chunky pixel buffer (for buffered mode) */
176 unsigned char gvalue
[256]; /* calculated brightness -> greyvalue table */
177 int fg_brightness
; /* current foreground brightness */
178 int bg_brightness
; /* current background brightness */
179 int drawmode
; /* current draw mode */
180 int curfont
; /* current selected font */
183 /* Global variable, defined in the plugin */
184 extern struct _grey_info _grey_info
;
186 #endif /* HAVE_LCD_BITMAP && (LCD_DEPTH < 4) */
187 #endif /* __GREY_H__ */