summaryrefslogtreecommitdiff
path: root/apps/plugins/lib/gray.h
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2004-06-02 23:53:27 +0000
committerJens Arnold <amiconn@rockbox.org>2004-06-02 23:53:27 +0000
commitca2bb463d3312f83afdd27d1098390bc6372a7da (patch)
tree4e212aa22b6592fa4ef18317378e966d751a498b /apps/plugins/lib/gray.h
parent0600cb13f1bf693b067291a3c90d6bd42972b591 (diff)
downloadrockbox-ca2bb463d3312f83afdd27d1098390bc6372a7da.tar.gz
rockbox-ca2bb463d3312f83afdd27d1098390bc6372a7da.zip
Major rework of the grayscale framework:
* api change - all drawing functions now use draw mode, foreground and background shades set globally by separate functions * There are now 4 draw modes for all drawing functions, no more separate functions for inverse drawing * Significant speedup of 1-bit bitmap (and font) drawing (2..3 times) * Some more speed tweaks * Additional functions for horizontal and vertical lines * Copied describing comments to the header file for easier reference * The safety net against an uninitialized grayscale buffer is gone git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4711 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/lib/gray.h')
-rw-r--r--apps/plugins/lib/gray.h300
1 files changed, 276 insertions, 24 deletions
diff --git a/apps/plugins/lib/gray.h b/apps/plugins/lib/gray.h
index 218fb282c8..18be88a2f2 100644
--- a/apps/plugins/lib/gray.h
+++ b/apps/plugins/lib/gray.h
@@ -9,6 +9,9 @@
9* 9*
10* Grayscale framework 10* Grayscale framework
11* 11*
12* This is a generic framework to use grayscale display within Rockbox
13* plugins. It obviously does not work for the player.
14*
12* Copyright (C) 2004 Jens Arnold 15* Copyright (C) 2004 Jens Arnold
13* 16*
14* All files in this archive are subject to the GNU General Public License. 17* All files in this archive are subject to the GNU General Public License.
@@ -27,59 +30,308 @@
27 30
28#ifdef HAVE_LCD_BITMAP /* and also not for the Player */ 31#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
29 32
30/* This is a generic framework to use grayscale display within rockbox 33/* Initialize the framework
31 * plugins. It obviously does not work for the player. 34 *
35 * every framework needs such a function, and it has to be called as
36 * the very first one
32 */ 37 */
33
34/* every framework needs such a function, and it has to be called as
35 * the very first one */
36void gray_init(struct plugin_api* newrb); 38void gray_init(struct plugin_api* newrb);
37 39
38/* general functions */ 40/**** general functions ****/
41
42/* Prepare the grayscale display buffer
43 *
44 * arguments:
45 * gbuf = pointer to the memory area to use (e.g. plugin buffer)
46 * gbuf_size = max usable size of the buffer
47 * width = width in pixels (1..112)
48 * bheight = height in 8-pixel units (1..8)
49 * depth = desired number of shades - 1 (1..32)
50 *
51 * result:
52 * = depth if there was enough memory
53 * < depth if there wasn't enough memory. The number of displayable
54 * shades is smaller than desired, but it still works
55 * = 0 if there wasn't even enough memory for 1 bitplane (black & white)
56 *
57 * You can request any depth from 1 to 32, not just powers of 2. The routine
58 * performs "graceful degradation" if the memory is not sufficient for the
59 * desired depth. As long as there is at least enough memory for 1 bitplane,
60 * it creates as many bitplanes as fit into memory, although 1 bitplane will
61 * only deliver black & white display.
62 *
63 * If you need info about the memory taken by the grayscale buffer, supply an
64 * int* as the last parameter. This int will then contain the number of bytes
65 * used. The total memory needed can be calculated as follows:
66 * total_mem =
67 * sizeof(tGraybuf) (= 64 bytes currently)
68 * + sizeof(long) (= 4 bytes)
69 * + (width * bheight + sizeof(long)) * depth
70 * + 0..3 (longword alignment of grayscale display buffer)
71 */
39int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width, 72int gray_init_buffer(unsigned char *gbuf, int gbuf_size, int width,
40 int bheight, int depth, int *buf_taken); 73 int bheight, int depth, int *buf_taken);
74
75/* Release the grayscale display buffer
76 *
77 * Switches the grayscale overlay off at first if it is still running,
78 * then sets the pointer to NULL.
79 * DO CALL either this function or at least gray_show_display(false)
80 * before you exit, otherwise nasty things may happen.
81 */
41void gray_release_buffer(void); 82void gray_release_buffer(void);
83
84/* Set position of the top left corner of the grayscale overlay
85 *
86 * x = left margin in pixels
87 * by = top margin in 8-pixel units
88 *
89 * You may set this in a way that the overlay spills across the right or
90 * bottom display border. In this case it will simply be clipped by the
91 * LCD controller. You can even set negative values, this will clip at the
92 * left or top border. I did not test it, but the limits may be +127 / -128
93 *
94 * If you use this while the grayscale overlay is running, the now-freed area
95 * will be restored.
96 */
42void gray_position_display(int x, int by); 97void gray_position_display(int x, int by);
98
99/* Switch the grayscale overlay on or off
100 *
101 * enable = true: the grayscale overlay is switched on if initialized
102 * = false: the grayscale overlay is switched off and the regular lcd
103 * content is restored
104 *
105 * DO NOT call lcd_update() or any other api function that directly accesses
106 * the lcd while the grayscale overlay is running! If you need to do
107 * lcd_update() to update something outside the grayscale overlay area, use
108 * gray_deferred_update() instead.
109 *
110 * Other functions to avoid are:
111 * lcd_blit() (obviously), lcd_update_rect(), lcd_set_contrast(),
112 * lcd_set_invert_display(), lcd_set_flip(), lcd_roll()
113 *
114 * The grayscale display consumes ~50 % CPU power (for a full screen overlay,
115 * less if the overlay is smaller) when switched on. You can switch the overlay
116 * on and off as many times as you want.
117 */
43void gray_show_display(bool enable); 118void gray_show_display(bool enable);
44 119
45/* functions affecting the whole display */ 120/* Set the draw mode for subsequent drawing operations
121 *
122 * drawmode =
123 * GRAY_DRAW_INVERSE: Foreground pixels are inverted, background pixels are
124 * left untouched
125 * GRAY_DRAW_FG: Only foreground pixels are drawn
126 * GRAY_DRAW_BG: Only background pixels are drawn
127 * GRAY_DRAW_SOLID: Foreground and background pixels are drawn
128 */
129void gray_set_drawmode(int drawmode);
130
131/* Draw modes */
132#define GRAY_DRAW_INVERSE 0
133#define GRAY_DRAW_FG 1
134#define GRAY_DRAW_BG 2
135#define GRAY_DRAW_SOLID 3
136
137/* Set the foreground shade for subsequent drawing operations
138 *
139 * brightness = 0 (black) .. 255 (white)
140 */
141void gray_set_foreground(int brightness);
142
143/* Set the background shade for subsequent drawing operations
144 *
145 * brightness = 0 (black) .. 255 (white)
146 */
147void gray_set_background(int brightness);
148
149/* Set draw mode, foreground and background shades at once
150 *
151 * If you hand it -1 (or in fact any other out-of-bounds value) for a
152 * parameter, that particular setting won't be changed
153 */
154void gray_set_drawinfo(int drawmode, int fg_brightness, int bg_brightness);
155
156/**** functions affecting the whole display ****/
157
158/* Clear the grayscale display (sets all pixels to white) */
46void gray_clear_display(void); 159void gray_clear_display(void);
160
161/* Set the grayscale display to all black */
47void gray_black_display(void); 162void gray_black_display(void);
163
164/* Do an lcd_update() to show changes done by rb->lcd_xxx() functions (in areas
165 * of the screen not covered by the grayscale overlay).
166 *
167 * If the grayscale overlay is running, the update will be done in the next
168 * call of the interrupt routine, otherwise it will be performed right away.
169 * See also comment for the gray_show_display() function.
170 */
48void gray_deferred_update(void); 171void gray_deferred_update(void);
49 172
50/* scrolling functions */ 173/**** Scrolling functions ****/
174
175/* Scroll the whole grayscale buffer left by <count> pixels
176 *
177 * black_border determines if the pixels scrolled in at the right are black
178 * or white
179 *
180 * Scrolling left/right by an even pixel count is almost twice as fast as
181 * scrolling by an odd pixel count.
182 */
51void gray_scroll_left(int count, bool black_border); 183void gray_scroll_left(int count, bool black_border);
184
185/* Scroll the whole grayscale buffer right by <count> pixels
186 *
187 * black_border determines if the pixels scrolled in at the left are black
188 * or white
189 *
190 * Scrolling left/right by an even pixel count is almost twice as fast as
191 * scrolling by an odd pixel count.
192 */
52void gray_scroll_right(int count, bool black_border); 193void gray_scroll_right(int count, bool black_border);
194
195/* Scroll the whole grayscale buffer up by 8 pixels
196 *
197 * black_border determines if the pixels scrolled in at the bottom are black
198 * or white
199 *
200 * Scrolling up/down by 8 pixels is very fast.
201 */
53void gray_scroll_up8(bool black_border); 202void gray_scroll_up8(bool black_border);
203
204/* Scroll the whole grayscale buffer down by 8 pixels
205 *
206 * black_border determines if the pixels scrolled in at the top are black
207 * or white
208 *
209 * Scrolling up/down by 8 pixels is very fast.
210 */
54void gray_scroll_down8(bool black_border); 211void gray_scroll_down8(bool black_border);
212
213/* Scroll the whole grayscale buffer up by <count> pixels (<= 7)
214 *
215 * black_border determines if the pixels scrolled in at the bottom are black
216 * or white
217 *
218 * Scrolling up/down pixel-wise is significantly slower than scrolling
219 * left/right or scrolling up/down byte-wise because it involves bit
220 * shifting. That's why it is asm optimized.
221 */
55void gray_scroll_up(int count, bool black_border); 222void gray_scroll_up(int count, bool black_border);
223
224/* Scroll the whole grayscale buffer down by <count> pixels (<= 7)
225 *
226 * black_border determines if the pixels scrolled in at the top are black
227 * or white
228 *
229 * Scrolling up/down pixel-wise is significantly slower than scrolling
230 * left/right or scrolling up/down byte-wise because it involves bit
231 * shifting. That's why it is asm optimized.
232 */
56void gray_scroll_down(int count, bool black_border); 233void gray_scroll_down(int count, bool black_border);
57 234
58/* pixel functions */ 235/**** Pixel and line functions ****/
59void gray_drawpixel(int x, int y, int brightness); 236
60void gray_invertpixel(int x, int y); 237/* Set a pixel with the current drawinfo
238 *
239 * If the drawmode is GRAY_DRAW_INVERSE, the pixel is inverted
240 * GRAY_DRAW_FG and GRAY_DRAW_SOLID draw the pixel in the foreground shade
241 * GRAY_DRAW_BG draws the pixel in the background shade
242 */
243void gray_drawpixel(int x, int y);
244
245/* Draw a line from (x1, y1) to (x2, y2) with the current drawinfo,
246 * See gray_drawpixel() for details
247 */
248void gray_drawline(int x1, int y1, int x2, int y2);
249
250/* Draw a horizontal line from (x1, y) to (x2, y) with the current drawinfo,
251 * See gray_drawpixel() for details
252 */
253void gray_horline(int x1, int x2, int y);
254
255/* Draw a vertical line from (x, y1) to (x, y2) with the current drawinfo,
256 * See gray_drawpixel() for details
257 *
258 * This one uses the block drawing optimization, so it is rather fast.
259 */
260void gray_verline(int x, int y1, int y2);
261
262/**** Rectangle functions ****/
263
264/* Draw a (hollow) rectangle with the current drawinfo,
265 * See gray_drawpixel() for details
266 */
267void gray_drawrect(int x, int y, int nx, int ny);
61 268
62/* line functions */ 269/* Draw a filled rectangle with the current drawinfo,
63void gray_drawline(int x1, int y1, int x2, int y2, int brightness); 270 * See gray_drawpixel() for details
64void gray_invertline(int x1, int y1, int x2, int y2); 271 *
272 * This one uses the block drawing optimization, so it is rather fast.
273 */
274void gray_fillrect(int x, int y, int nx, int ny);
65 275
66/* rectangle functions */ 276/**** Bitmap functions ****/
67void gray_drawrect(int x1, int y1, int x2, int y2, int brightness);
68void gray_fillrect(int x1, int y1, int x2, int y2, int brightness);
69void gray_invertrect(int x1, int y1, int x2, int y2);
70 277
71/* bitmap functions */ 278/* Copy a grayscale bitmap into the display
279 *
280 * A grayscale bitmap contains one byte for every pixel that defines the
281 * brightness of the pixel (0..255). Bytes are read in row-major order.
282 * The <stride> parameter is useful if you want to show only a part of a
283 * bitmap. It should always be set to the "row length" of the bitmap, so
284 * for displaying the whole bitmap, nx == stride.
285 *
286 * This is the only drawing function NOT using the drawinfo.
287 */
72void gray_drawgraymap(unsigned char *src, int x, int y, int nx, int ny, 288void gray_drawgraymap(unsigned char *src, int x, int y, int nx, int ny,
73 int stride); 289 int stride);
290
291/* Display a bitmap with the current drawinfo
292 *
293 * The drawmode is used as described for gray_set_drawmode()
294 *
295 * This (now) uses the same bitmap format as the core b&w graphics routines,
296 * so you can use bmp2rb to generate bitmaps for use with this function as
297 * well.
298 *
299 * A bitmap contains one bit for every pixel that defines if that pixel is
300 * foreground (1) or background (0). Bits within a byte are arranged
301 * vertically, LSB at top.
302 * The bytes are stored in row-major order, with byte 0 being top left,
303 * byte 1 2nd from left etc. The first row of bytes defines pixel rows
304 * 0..7, the second row defines pixel row 8..15 etc.
305 *
306 * The <stride> parameter is useful if you want to show only a part of a
307 * bitmap. It should always be set to the "row length" of the bitmap.
308 */
74void gray_drawbitmap(unsigned char *src, int x, int y, int nx, int ny, 309void gray_drawbitmap(unsigned char *src, int x, int y, int nx, int ny,
75 int stride, bool draw_bg, int fg_brightness, 310 int stride);
76 int bg_brightness);
77 311
78/* font support */ 312/**** Font support ****/
313
314/* Set font for the font routines
315 *
316 * newfont can be FONT_SYSFIXED or FONT_UI the same way as with the Rockbox
317 * core routines
318 */
79void gray_setfont(int newfont); 319void gray_setfont(int newfont);
320
321/* Calculate width and height of the given text in pixels when rendered with
322 * the currently selected font.
323 *
324 * This works exactly the same way as the core lcd_getstringsize(), only that
325 * it uses the selected font for grayscale.
326 */
80int gray_getstringsize(unsigned char *str, int *w, int *h); 327int gray_getstringsize(unsigned char *str, int *w, int *h);
81void gray_putsxy(int x, int y, unsigned char *str, bool draw_bg, 328
82 int fg_brightness, int bg_brightness); 329/* Display text starting at (x, y) with the current font and drawinfo
330 *
331 * The drawmode is used as described for gray_set_drawmode()
332 */
333void gray_putsxy(int x, int y, unsigned char *str);
334
83#endif /* HAVE_LCD_BITMAP */ 335#endif /* HAVE_LCD_BITMAP */
84#endif /* SIMULATOR */ 336#endif /* SIMULATOR */
85#endif /* __GRAY_H__ */ 337#endif /* __GRAY_H__ */