A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* New greyscale framework
11*
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.
14*
15* Copyright (C) 2008 Jens Arnold
16*
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.
21*
22* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
23* KIND, either express or implied.
24*
25****************************************************************************/
26
27#ifndef __GREY_H__
28#define __GREY_H__
29
30#include "plugin.h"
31
32#if (LCD_DEPTH < 4)
33
34/* The greyscale lib uses 8 bit brightness values natively on input. */
35#define GREY_BRIGHTNESS(y) (y)
36
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)
42
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;
48
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) */
53
54/* Library initialisation and release */
55bool grey_init(unsigned char *gbuf, long gbuf_size,
56 unsigned features, int width, int height, long *buf_taken);
57void grey_release(void);
58
59/* Special functions */
60void grey_show(bool enable);
61void grey_deferred_lcd_update(void);
62
63/* Viewports and framebuffers */
64void grey_clear_viewport(void);
65struct viewport *grey_set_viewport(struct viewport *vp);
66void grey_viewport_set_fullscreen(struct viewport *vp,
67 const enum screen_type screen);
68void grey_viewport_set_pos(struct viewport *vp,
69 int x, int y, int width, int height);
70void grey_set_framebuffer(unsigned char *buffer);
71void grey_framebuffer_set_pos(int x, int y, int width, int height);
72
73/* Update functions */
74void grey_update(void);
75void grey_update_rect(int x, int y, int width, int height);
76
77/* Parameter handling */
78void grey_set_position(int x, int y);
79void grey_set_drawmode(int mode);
80int grey_get_drawmode(void);
81void grey_set_foreground(unsigned brightness);
82unsigned grey_get_foreground(void);
83void grey_set_background(unsigned brightness);
84unsigned grey_get_background(void);
85void grey_set_drawinfo(int mode, unsigned fg_brightness, unsigned bg_brightness);
86void grey_setfont(int newfont);
87int grey_getstringsize(const unsigned char *str, int *w, int *h);
88
89/* Whole display */
90void grey_clear_display(void);
91void grey_ub_clear_display(void);
92
93/* Pixel */
94void grey_drawpixel(int x, int y);
95
96/* Lines */
97void grey_drawline(int x1, int y1, int x2, int y2);
98void grey_hline(int x1, int x2, int y);
99void grey_vline(int x, int y1, int y2);
100void grey_drawrect(int x, int y, int nx, int ny);
101
102/* Filled primitives */
103void grey_fillrect(int x, int y, int nx, int ny);
104void grey_filltriangle(int x1, int y1, int x2, int y2, int x3, int y3);
105
106/* Bitmaps */
107void 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);
109void grey_mono_bitmap(const unsigned char *src, int x, int y, int width,
110 int height);
111void 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);
113void grey_gray_bitmap(const unsigned char *src, int x, int y, int width,
114 int height);
115void 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);
117void grey_ub_gray_bitmap(const unsigned char *src, int x, int y, int width,
118 int height);
119extern const struct custom_format format_grey;
120
121/* Text */
122void grey_putsxyofs(int x, int y, int ofs, const unsigned char *str);
123void grey_putsxy(int x, int y, const unsigned char *str);
124
125/* Scrolling */
126void grey_scroll_left(int count);
127void grey_scroll_right(int count);
128void grey_scroll_up(int count);
129void grey_scroll_down(int count);
130void grey_ub_scroll_left(int count);
131void grey_ub_scroll_right(int count);
132void grey_ub_scroll_up(int count);
133void grey_ub_scroll_down(int count);
134
135/*** Internal stuff ***/
136
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
143
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 */
148
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
156
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 */
166
167#define _GREY_BSIZE (1<<_GREY_BSHIFT)
168#define _GREY_BMASK (_GREY_BSIZE-1)
169
170/* The greyscale buffer management structure */
171struct _grey_info
172{
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 */
199};
200
201/* Global variable, defined in the plugin */
202extern struct _grey_info _grey_info;
203
204#endif /* (LCD_DEPTH < 4) */
205#endif /* __GREY_H__ */