Prepare new maemo release
[maemo-rb.git] / apps / plugins / lib / grey.h
blobd63d19ee4a35de4a905bf286f6182c8d3694c32a
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version 2
20 * of the License, or (at your option) any later version.
22 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
23 * KIND, either express or implied.
25 ****************************************************************************/
27 #ifndef __GREY_H__
28 #define __GREY_H__
30 #include "plugin.h"
32 #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4)
34 /* The greyscale lib uses 8 bit brightness values natively on input. */
35 #define GREY_BRIGHTNESS(y) (y)
37 /* Some predefined levels for convenience: */
38 #define GREY_BLACK GREY_BRIGHTNESS(0)
39 #define GREY_DARKGRAY GREY_BRIGHTNESS(85)
40 #define GREY_LIGHTGRAY GREY_BRIGHTNESS(170)
41 #define GREY_WHITE GREY_BRIGHTNESS(255)
43 /* Greyscale library management structure declaration. You need one of these
44 * in every plugin using the library, depending on whether the structure should
45 * use IRAM or not. */
46 #define GREY_INFO_STRUCT struct _grey_info _grey_info SHAREDBSS_ATTR;
47 #define GREY_INFO_STRUCT_IRAM struct _grey_info _grey_info IBSS_ATTR;
49 /* Features you can request on library init (ORed together): */
50 #define GREY_BUFFERED 0x0001 /* Use a chunky buffer */
51 #define GREY_RAWMAPPED 0x0002 /* No gamma & LCD linearisation */
52 #define GREY_ON_COP 0x0004 /* Run ISR on COP (PP targets) */
54 /* Library initialisation and release */
55 bool grey_init(unsigned char *gbuf, long gbuf_size,
56 unsigned features, int width, int height, long *buf_taken);
57 void grey_release(void);
59 /* Special functions */
60 void grey_show(bool enable);
61 void grey_deferred_lcd_update(void);
63 /* Viewports and framebuffers */
64 void grey_clear_viewport(void);
65 void grey_set_viewport(struct viewport *vp);
66 void grey_viewport_set_fullscreen(struct viewport *vp,
67 const enum screen_type screen);
68 void grey_viewport_set_pos(struct viewport *vp,
69 int x, int y, int width, int height);
70 void grey_set_framebuffer(unsigned char *buffer);
71 void grey_framebuffer_set_pos(int x, int y, int width, int height);
73 /* Update functions */
74 void grey_update(void);
75 void grey_update_rect(int x, int y, int width, int height);
77 /* Parameter handling */
78 void grey_set_position(int x, int y);
79 void grey_set_drawmode(int mode);
80 int grey_get_drawmode(void);
81 void grey_set_foreground(unsigned brightness);
82 unsigned grey_get_foreground(void);
83 void grey_set_background(unsigned brightness);
84 unsigned grey_get_background(void);
85 void grey_set_drawinfo(int mode, unsigned fg_brightness, unsigned bg_brightness);
86 void grey_setfont(int newfont);
87 int grey_getstringsize(const unsigned char *str, int *w, int *h);
89 /* Whole display */
90 void grey_clear_display(void);
91 void grey_ub_clear_display(void);
93 /* Pixel */
94 void grey_drawpixel(int x, int y);
96 /* Lines */
97 void grey_drawline(int x1, int y1, int x2, int y2);
98 void grey_hline(int x1, int x2, int y);
99 void grey_vline(int x, int y1, int y2);
100 void grey_drawrect(int x, int y, int nx, int ny);
102 /* Filled primitives */
103 void grey_fillrect(int x, int y, int nx, int ny);
104 void grey_filltriangle(int x1, int y1, int x2, int y2, int x3, int y3);
106 /* Bitmaps */
107 void grey_mono_bitmap_part(const unsigned char *src, int src_x, int src_y,
108 int stride, int x, int y, int width, int height);
109 void grey_mono_bitmap(const unsigned char *src, int x, int y, int width,
110 int height);
111 void grey_gray_bitmap_part(const unsigned char *src, int src_x, int src_y,
112 int stride, int x, int y, int width, int height);
113 void grey_gray_bitmap(const unsigned char *src, int x, int y, int width,
114 int height);
115 void grey_ub_gray_bitmap_part(const unsigned char *src, int src_x, int src_y,
116 int stride, int x, int y, int width, int height);
117 void grey_ub_gray_bitmap(const unsigned char *src, int x, int y, int width,
118 int height);
119 extern const struct custom_format format_grey;
121 /* Text */
122 void grey_putsxyofs(int x, int y, int ofs, const unsigned char *str);
123 void grey_putsxy(int x, int y, const unsigned char *str);
125 /* Scrolling */
126 void grey_scroll_left(int count);
127 void grey_scroll_right(int count);
128 void grey_scroll_up(int count);
129 void grey_scroll_down(int count);
130 void grey_ub_scroll_left(int count);
131 void grey_ub_scroll_right(int count);
132 void grey_ub_scroll_up(int count);
133 void grey_ub_scroll_down(int count);
135 /*** Internal stuff ***/
137 /* standard gamma (s23p8) */
138 #ifdef SIMULATOR /* Standard PC gamma */
139 #define _GREY_GAMMA ((200<<8)/100)
140 #else /* Target LCDs have a smaller contrast range */
141 #define _GREY_GAMMA ((180<<8)/100)
142 #endif
144 /* flag definitions */
145 #define _GREY_RUNNING 0x8000 /* greyscale overlay is running */
146 #define _GREY_DEFERRED_UPDATE 0x4000 /* lcd_update() requested */
147 #define _GREY_BACKLIGHT_ON 0x2000 /* backlight is active - only used on 1st+2nd Gen */
149 /* fast unsigned multiplication (16x16bit->32bit or 32x32bit->32bit,
150 * whichever is faster for the architecture) */
151 #ifdef CPU_ARM
152 #define _GREY_MULUQ(a, b) ((uint32_t) (((uint32_t) (a)) * ((uint32_t) (b))))
153 #else
154 #define _GREY_MULUQ(a, b) ((uint32_t) (((uint16_t) (a)) * ((uint16_t) (b))))
155 #endif
157 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
158 #define _GREY_BSHIFT 0
159 #else /* vertical packing or vertical interleaved */
160 #if (LCD_DEPTH == 1) || (LCD_PIXELFORMAT == VERTICAL_INTERLEAVED)
161 #define _GREY_BSHIFT 3
162 #elif LCD_DEPTH == 2
163 #define _GREY_BSHIFT 2
164 #endif
165 #endif /* LCD_PIXELFORMAT */
167 #define _GREY_BSIZE (1<<_GREY_BSHIFT)
168 #define _GREY_BMASK (_GREY_BSIZE-1)
170 /* The greyscale buffer management structure */
171 struct _grey_info
173 int x;
174 int y;
175 int width;
176 int height;
177 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
178 int bx; /* 8-pixel units */
179 int bwidth; /* 8-pixel units */
180 #else /* vertical packing or vertical interleaved */
181 int by; /* 4-pixel or 8-pixel units */
182 int bheight; /* 4-pixel or 8-pixel units */
183 #endif
184 unsigned long flags; /* various flags, see #defines */
185 unsigned char *values; /* start of greyscale pixel values */
186 unsigned char *phases; /* start of greyscale pixel phases */
187 unsigned char *buffer; /* start of chunky pixel buffer (for buffered mode) */
188 unsigned char *curbuffer; /* start of current framebuffer (for buffered mode) */
189 int cb_x; /* horizontal position of current framebuffer (for buffered mode) */
190 int cb_y; /* vertical position of current framebuffer (for buffered mode) */
191 int cb_width; /* width of current framebuffer (for buffered mode) */
192 int cb_height; /* height of current framebuffer (for buffered mode) */
193 int clip_l;
194 int clip_t;
195 int clip_r;
196 int clip_b;
197 unsigned char gvalue[256]; /* calculated brightness -> greyvalue table */
198 struct viewport *vp; /* current viewport in use */
201 /* Stuff these here for now. LCD depth of 1 has no 'pattern' members. */
202 #define _GREY_FG_BRIGHTNESS(vp) ((vp)->flags)
203 #define _GREY_BG_BRIGHTNESS(vp) ((vp)->line_height)
205 /* Global variable, defined in the plugin */
206 extern struct _grey_info _grey_info;
208 #endif /* HAVE_LCD_BITMAP && (LCD_DEPTH < 4) */
209 #endif /* __GREY_H__ */