summaryrefslogtreecommitdiff
path: root/apps/gui/color_picker.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gui/color_picker.c')
-rw-r--r--apps/gui/color_picker.c64
1 files changed, 32 insertions, 32 deletions
diff --git a/apps/gui/color_picker.c b/apps/gui/color_picker.c
index 32b392c717..08c05d958f 100644
--- a/apps/gui/color_picker.c
+++ b/apps/gui/color_picker.c
@@ -56,8 +56,7 @@ struct rgb_pick
56/* list of primary colors */ 56/* list of primary colors */
57#define SB_PRIM 0 57#define SB_PRIM 0
58#define SB_FILL 1 58#define SB_FILL 1
59#define SB_MAX 2 59static const fb_data prim_rgb[][3] =
60static const unsigned short prim_rgb[][3] =
61{ 60{
62 /* Foreground colors for sliders */ 61 /* Foreground colors for sliders */
63 { 62 {
@@ -71,39 +70,32 @@ static const unsigned short prim_rgb[][3] =
71 LCD_RGBPACK( 0, 85, 0), 70 LCD_RGBPACK( 0, 85, 0),
72 LCD_RGBPACK( 0, 0, 85), 71 LCD_RGBPACK( 0, 0, 85),
73 }, 72 },
74 /* maximum values for components */ 73};
75 { 74
76 LCD_MAX_RED, 75/* maximum values for components */
77 LCD_MAX_GREEN, 76static const unsigned char rgb_max[3] =
78 LCD_MAX_BLUE 77{
79 } 78 LCD_MAX_RED,
79 LCD_MAX_GREEN,
80 LCD_MAX_BLUE
80}; 81};
81 82
82/* Unpacks the color value into native rgb values and 24 bit rgb values */ 83/* Unpacks the color value into native rgb values and 24 bit rgb values */
83static void unpack_rgb(struct rgb_pick *rgb) 84static void unpack_rgb(struct rgb_pick *rgb)
84{ 85{
85 unsigned color = rgb->color; 86 unsigned color = _LCD_UNSWAP_COLOR(rgb->color);
86#if LCD_PIXELFORMAT == RGB565SWAPPED
87 color = swap16(color);
88#endif
89 rgb->red = _RGB_UNPACK_RED(color); 87 rgb->red = _RGB_UNPACK_RED(color);
90 rgb->green = _RGB_UNPACK_GREEN(color); 88 rgb->green = _RGB_UNPACK_GREEN(color);
91 rgb->blue = _RGB_UNPACK_BLUE(color); 89 rgb->blue = _RGB_UNPACK_BLUE(color);
92 rgb->r = (color & 0xf800) >> 11; 90 rgb->r = _RGB_UNPACK_RED_LCD(color);
93 rgb->g = (color & 0x07e0) >> 5; 91 rgb->g = _RGB_UNPACK_GREEN_LCD(color);
94 rgb->b = (color & 0x001f); 92 rgb->b = _RGB_UNPACK_BLUE_LCD(color);
95} 93}
96 94
97/* Packs the native rgb colors into a color value */ 95/* Packs the native rgb colors into a color value */
98static void pack_rgb(struct rgb_pick *rgb) 96static inline void pack_rgb(struct rgb_pick *rgb)
99{ 97{
100 unsigned color = (rgb->r & 0x1f) << 11 | 98 rgb->color = LCD_RGBPACK_LCD(rgb->r, rgb->g, rgb->b);
101 (rgb->g & 0x3f) << 5 |
102 (rgb->b & 0x1f);
103#if LCD_PIXELFORMAT == RGB565SWAPPED
104 color = swap16(color);
105#endif
106 rgb->color = color;
107} 99}
108 100
109/* Returns LCD_BLACK if the color is above a threshold brightness 101/* Returns LCD_BLACK if the color is above a threshold brightness
@@ -265,7 +257,7 @@ static void draw_screen(struct screen *display, char *title,
265 text_top + display->char_height / 4, 257 text_top + display->char_height / 4,
266 slider_width, 258 slider_width,
267 display->char_height / 2, 259 display->char_height / 2,
268 prim_rgb[SB_MAX][i], 260 rgb_max[i],
269 0, 261 0,
270 rgb->rgb_val[i], 262 rgb->rgb_val[i],
271 sb_flags); 263 sb_flags);
@@ -343,22 +335,29 @@ static void draw_screen(struct screen *display, char *title,
343 color is a pointer to the colour (in native format) to modify 335 color is a pointer to the colour (in native format) to modify
344 set banned_color to -1 to allow all 336 set banned_color to -1 to allow all
345 ***********/ 337 ***********/
346bool set_color(struct screen *display, char *title, int* color, int banned_color) 338bool set_color(struct screen *display, char *title, unsigned *color,
339 unsigned banned_color)
347{ 340{
348 int exit = 0, button, slider = 0; 341 int exit = 0, slider = 0;
349 int i;
350 struct rgb_pick rgb; 342 struct rgb_pick rgb;
351 (void)display;
352 343
353 rgb.color = *color; 344 rgb.color = *color;
354 345
355 while (!exit) 346 while (!exit)
356 { 347 {
348 int button;
349
357 unpack_rgb(&rgb); 350 unpack_rgb(&rgb);
358 351
359 FOR_NB_SCREENS(i) 352 if (display != NULL)
353 {
354 draw_screen(display, title, &rgb, slider);
355 }
356 else
360 { 357 {
361 draw_screen(&screens[i], title, &rgb, slider); 358 int i;
359 FOR_NB_SCREENS(i)
360 draw_screen(&screens[i], title, &rgb, slider);
362 } 361 }
363 362
364 button = get_action(CONTEXT_SETTINGS_COLOURCHOOSER, TIMEOUT_BLOCK); 363 button = get_action(CONTEXT_SETTINGS_COLOURCHOOSER, TIMEOUT_BLOCK);
@@ -377,7 +376,7 @@ bool set_color(struct screen *display, char *title, int* color, int banned_color
377 376
378 case ACTION_SETTINGS_INC: 377 case ACTION_SETTINGS_INC:
379 case ACTION_SETTINGS_INCREPEAT: 378 case ACTION_SETTINGS_INCREPEAT:
380 if (rgb.rgb_val[slider] < prim_rgb[SB_MAX][slider]) 379 if (rgb.rgb_val[slider] < rgb_max[slider])
381 rgb.rgb_val[slider]++; 380 rgb.rgb_val[slider]++;
382 pack_rgb(&rgb); 381 pack_rgb(&rgb);
383 break; 382 break;
@@ -390,7 +389,8 @@ bool set_color(struct screen *display, char *title, int* color, int banned_color
390 break; 389 break;
391 390
392 case ACTION_STD_OK: 391 case ACTION_STD_OK:
393 if (banned_color != -1 && (unsigned)banned_color == rgb.color) 392 if (banned_color != (unsigned)-1 &&
393 banned_color == rgb.color)
394 { 394 {
395 gui_syncsplash(HZ*2, true, str(LANG_COLOR_UNACCEPTABLE)); 395 gui_syncsplash(HZ*2, true, str(LANG_COLOR_UNACCEPTABLE));
396 break; 396 break;