Build doom on clipv2 and clip+
[kugel-rb.git] / apps / plugins / lib / grey.h
blob7c990ad792ba68d47485b5c0e29d7e8a1e8c89bf
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 /* Update functions */
64 void grey_update(void);
65 void grey_update_rect(int x, int y, int width, int height);
67 /* Parameter handling */
68 void grey_set_position(int x, int y);
69 void grey_set_drawmode(int mode);
70 int grey_get_drawmode(void);
71 void grey_set_foreground(unsigned brightness);
72 unsigned grey_get_foreground(void);
73 void grey_set_background(unsigned brightness);
74 unsigned grey_get_background(void);
75 void grey_set_drawinfo(int mode, unsigned fg_brightness, unsigned bg_brightness);
76 void grey_setfont(int newfont);
77 int grey_getstringsize(const unsigned char *str, int *w, int *h);
79 /* Whole display */
80 void grey_clear_display(void);
81 void grey_ub_clear_display(void);
83 /* Pixel */
84 void grey_drawpixel(int x, int y);
86 /* Lines */
87 void grey_drawline(int x1, int y1, int x2, int y2);
88 void grey_hline(int x1, int x2, int y);
89 void grey_vline(int x, int y1, int y2);
90 void grey_drawrect(int x, int y, int nx, int ny);
92 /* Filled primitives */
93 void grey_fillrect(int x, int y, int nx, int ny);
94 void grey_filltriangle(int x1, int y1, int x2, int y2, int x3, int y3);
96 /* Bitmaps */
97 void grey_mono_bitmap_part(const unsigned char *src, int src_x, int src_y,
98 int stride, int x, int y, int width, int height);
99 void grey_mono_bitmap(const unsigned char *src, int x, int y, int width,
100 int height);
101 void grey_gray_bitmap_part(const unsigned char *src, int src_x, int src_y,
102 int stride, int x, int y, int width, int height);
103 void grey_gray_bitmap(const unsigned char *src, int x, int y, int width,
104 int height);
105 void grey_ub_gray_bitmap_part(const unsigned char *src, int src_x, int src_y,
106 int stride, int x, int y, int width, int height);
107 void grey_ub_gray_bitmap(const unsigned char *src, int x, int y, int width,
108 int height);
109 extern const struct custom_format format_grey;
111 /* Text */
112 void grey_putsxyofs(int x, int y, int ofs, const unsigned char *str);
113 void grey_putsxy(int x, int y, const unsigned char *str);
115 /* Scrolling */
116 void grey_scroll_left(int count);
117 void grey_scroll_right(int count);
118 void grey_scroll_up(int count);
119 void grey_scroll_down(int count);
120 void grey_ub_scroll_left(int count);
121 void grey_ub_scroll_right(int count);
122 void grey_ub_scroll_up(int count);
123 void grey_ub_scroll_down(int count);
125 /*** Internal stuff ***/
127 /* standard gamma (s23p8) */
128 #ifdef SIMULATOR /* Standard PC gamma */
129 #define _GREY_GAMMA ((200<<8)/100)
130 #else /* Target LCDs have a smaller contrast range */
131 #define _GREY_GAMMA ((180<<8)/100)
132 #endif
134 /* flag definitions */
135 #define _GREY_RUNNING 0x8000 /* greyscale overlay is running */
136 #define _GREY_DEFERRED_UPDATE 0x4000 /* lcd_update() requested */
137 #define _GREY_BACKLIGHT_ON 0x2000 /* backlight is active - only used on 1st+2nd Gen */
139 /* fast unsigned multiplication (16x16bit->32bit or 32x32bit->32bit,
140 * whichever is faster for the architecture) */
141 #ifdef CPU_ARM
142 #define _GREY_MULUQ(a, b) ((uint32_t) (((uint32_t) (a)) * ((uint32_t) (b))))
143 #else
144 #define _GREY_MULUQ(a, b) ((uint32_t) (((uint16_t) (a)) * ((uint16_t) (b))))
145 #endif
147 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
148 #define _GREY_BSHIFT 0
149 #else /* vertical packing or vertical interleaved */
150 #if (LCD_DEPTH == 1) || (LCD_PIXELFORMAT == VERTICAL_INTERLEAVED)
151 #define _GREY_BSHIFT 3
152 #elif LCD_DEPTH == 2
153 #define _GREY_BSHIFT 2
154 #endif
155 #endif /* LCD_PIXELFORMAT */
157 #define _GREY_BSIZE (1<<_GREY_BSHIFT)
158 #define _GREY_BMASK (_GREY_BSIZE-1)
160 /* The greyscale buffer management structure */
161 struct _grey_info
163 int x;
164 int y;
165 int width;
166 int height;
167 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
168 int bx; /* 8-pixel units */
169 int bwidth; /* 8-pixel units */
170 #else /* vertical packing or vertical interleaved */
171 int by; /* 4-pixel or 8-pixel units */
172 int bheight; /* 4-pixel or 8-pixel units */
173 #endif
174 unsigned long flags; /* various flags, see #defines */
175 unsigned char *values; /* start of greyscale pixel values */
176 unsigned char *phases; /* start of greyscale pixel phases */
177 unsigned char *buffer; /* start of chunky pixel buffer (for buffered mode) */
178 unsigned char gvalue[256]; /* calculated brightness -> greyvalue table */
179 int fg_brightness; /* current foreground brightness */
180 int bg_brightness; /* current background brightness */
181 int drawmode; /* current draw mode */
182 int curfont; /* current selected font */
185 /* Global variable, defined in the plugin */
186 extern struct _grey_info _grey_info;
188 #endif /* HAVE_LCD_BITMAP && (LCD_DEPTH < 4) */
189 #endif /* __GREY_H__ */