diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2006-10-15 17:51:00 +0000 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2006-10-15 17:51:00 +0000 |
commit | e0710b2af13cc7a4994cbcb0e50af97c02055c5b (patch) | |
tree | 35ffd56e0108d20ab6cb3422c04e0476301a92ff | |
parent | 70587527898345fdb7245be7c8723b338323fceb (diff) | |
download | rockbox-e0710b2af13cc7a4994cbcb0e50af97c02055c5b.tar.gz rockbox-e0710b2af13cc7a4994cbcb0e50af97c02055c5b.zip |
More color adjustments. Better translation to and from native colors with even distribution of levels. Macros for extracting native depth components and packing them.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11227 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/gui/color_picker.c | 64 | ||||
-rw-r--r-- | apps/gui/color_picker.h | 3 | ||||
-rw-r--r-- | apps/recorder/bmp.c | 59 | ||||
-rw-r--r-- | apps/settings_menu.c | 6 | ||||
-rw-r--r-- | firmware/export/lcd.h | 71 |
5 files changed, 110 insertions, 93 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 | 59 | static const fb_data prim_rgb[][3] = |
60 | static 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, | 76 | static 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 */ |
83 | static void unpack_rgb(struct rgb_pick *rgb) | 84 | static 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 */ |
98 | static void pack_rgb(struct rgb_pick *rgb) | 96 | static 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 | ***********/ |
346 | bool set_color(struct screen *display, char *title, int* color, int banned_color) | 338 | bool 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; |
diff --git a/apps/gui/color_picker.h b/apps/gui/color_picker.h index f5200832ad..3bd232580b 100644 --- a/apps/gui/color_picker.h +++ b/apps/gui/color_picker.h | |||
@@ -20,6 +20,7 @@ | |||
20 | 20 | ||
21 | #ifdef HAVE_LCD_COLOR /* this file is a bit useless on non color lcds.. */ | 21 | #ifdef HAVE_LCD_COLOR /* this file is a bit useless on non color lcds.. */ |
22 | 22 | ||
23 | bool set_color(struct screen *display,char *title, int* color, int banned_color); | 23 | bool set_color(struct screen *display, char *title, unsigned *color, |
24 | unsigned banned_color); | ||
24 | 25 | ||
25 | #endif | 26 | #endif |
diff --git a/apps/recorder/bmp.c b/apps/recorder/bmp.c index 19376bfb47..3044e8e3a5 100644 --- a/apps/recorder/bmp.c +++ b/apps/recorder/bmp.c | |||
@@ -63,11 +63,11 @@ struct Fileheader { | |||
63 | } STRUCT_PACKED; | 63 | } STRUCT_PACKED; |
64 | 64 | ||
65 | struct rgb_quad { /* Little endian */ | 65 | struct rgb_quad { /* Little endian */ |
66 | unsigned char blue; | 66 | unsigned char blue; |
67 | unsigned char green; | 67 | unsigned char green; |
68 | unsigned char red; | 68 | unsigned char red; |
69 | unsigned char reserved; | 69 | unsigned char reserved; |
70 | } STRUCT_PACKED; | 70 | } STRUCT_PACKED; |
71 | 71 | ||
72 | /* big endian functions */ | 72 | /* big endian functions */ |
73 | static short readshort(short *value) { | 73 | static short readshort(short *value) { |
@@ -96,8 +96,8 @@ inline int getpix(int px, unsigned char *bmpbuf) { | |||
96 | } | 96 | } |
97 | 97 | ||
98 | #if LCD_DEPTH == 16 | 98 | #if LCD_DEPTH == 16 |
99 | /* Cheapo 24 -> 16 bit dither */ | 99 | /* 24 -> lcd depth dither */ |
100 | static unsigned short dither_24_to_16(struct rgb_quad rgb, int row, int col) | 100 | static fb_data dither_24_to_lcd(struct rgb_quad rgb, int row, int col) |
101 | { | 101 | { |
102 | static const unsigned char dith[][16] = | 102 | static const unsigned char dith[][16] = |
103 | { | 103 | { |
@@ -115,22 +115,17 @@ static unsigned short dither_24_to_16(struct rgb_quad rgb, int row, int col) | |||
115 | }, | 115 | }, |
116 | }; | 116 | }; |
117 | 117 | ||
118 | const int elm = (row & 3) + ((col & 3) << 2); | 118 | const unsigned elm = (row & 3) + ((col & 3) << 2); |
119 | unsigned short color; | 119 | unsigned b, g, r; |
120 | |||
121 | unsigned b = ((unsigned)rgb.blue + dith[0][elm]) >> 3; | ||
122 | if (b > 0x1f) b = 0x1f; | ||
123 | unsigned g = ((unsigned)rgb.green + dith[1][elm]) >> 2; | ||
124 | if (g > 0x3f) g = 0x3f; | ||
125 | unsigned r = ((unsigned)rgb.red + dith[0][elm]) >> 3; | ||
126 | if (r > 0x1f) r = 0x1f; | ||
127 | 120 | ||
128 | color = (unsigned short)(b | (g << 5) | (r << 11)); | 121 | b = ((unsigned)rgb.blue + dith[0][elm]) >> (8-LCD_BLUE_BITS); |
122 | if (b > LCD_MAX_BLUE) b = LCD_MAX_BLUE; | ||
123 | g = ((unsigned)rgb.green + dith[1][elm]) >> (8-LCD_GREEN_BITS); | ||
124 | if (g > LCD_MAX_GREEN) g = LCD_MAX_GREEN; | ||
125 | r = ((unsigned)rgb.red + dith[0][elm]) >> (8-LCD_RED_BITS); | ||
126 | if (r > LCD_MAX_RED) r = LCD_MAX_RED; | ||
129 | 127 | ||
130 | #if LCD_PIXELFORMAT == RGB565SWAPPED | 128 | return LCD_RGBPACK_LCD(r, g, b); |
131 | color = swap16(color); | ||
132 | #endif | ||
133 | return color; | ||
134 | } | 129 | } |
135 | #endif /* LCD_DEPTH == 16 */ | 130 | #endif /* LCD_DEPTH == 16 */ |
136 | 131 | ||
@@ -179,7 +174,7 @@ int read_bmp_file(char* filename, | |||
179 | /* Exit if file opening failed */ | 174 | /* Exit if file opening failed */ |
180 | if (fd < 0) { | 175 | if (fd < 0) { |
181 | DEBUGF("error - can't open '%s' open returned: %d\n", filename, fd); | 176 | DEBUGF("error - can't open '%s' open returned: %d\n", filename, fd); |
182 | return (fd * 10) - 1; | 177 | return (fd * 10) - 1; |
183 | } | 178 | } |
184 | 179 | ||
185 | /* read fileheader */ | 180 | /* read fileheader */ |
@@ -188,7 +183,7 @@ int read_bmp_file(char* filename, | |||
188 | close(fd); | 183 | close(fd); |
189 | return (ret * 10 - 2); | 184 | return (ret * 10 - 2); |
190 | } | 185 | } |
191 | 186 | ||
192 | if(ret != sizeof(struct Fileheader)) { | 187 | if(ret != sizeof(struct Fileheader)) { |
193 | DEBUGF("error - can't read Fileheader structure."); | 188 | DEBUGF("error - can't read Fileheader structure."); |
194 | close(fd); | 189 | close(fd); |
@@ -250,7 +245,7 @@ int read_bmp_file(char* filename, | |||
250 | } | 245 | } |
251 | 246 | ||
252 | /* Check if this fits the buffer */ | 247 | /* Check if this fits the buffer */ |
253 | 248 | ||
254 | if (totalsize > maxsize) { | 249 | if (totalsize > maxsize) { |
255 | DEBUGF("error - Bitmap is too large to fit the supplied buffer: " | 250 | DEBUGF("error - Bitmap is too large to fit the supplied buffer: " |
256 | "%d bytes.\n", (PaddedHeight * dst_width)); | 251 | "%d bytes.\n", (PaddedHeight * dst_width)); |
@@ -278,7 +273,7 @@ int read_bmp_file(char* filename, | |||
278 | if(brightness(palette[0]) < brightness(palette[1])) | 273 | if(brightness(palette[0]) < brightness(palette[1])) |
279 | invert_pixel = 1; | 274 | invert_pixel = 1; |
280 | } | 275 | } |
281 | 276 | ||
282 | /* Search to the beginning of the image data */ | 277 | /* Search to the beginning of the image data */ |
283 | lseek(fd, (off_t)readlong(&fh.OffBits), SEEK_SET); | 278 | lseek(fd, (off_t)readlong(&fh.OffBits), SEEK_SET); |
284 | 279 | ||
@@ -286,15 +281,15 @@ int read_bmp_file(char* filename, | |||
286 | if(format == FORMAT_NATIVE) | 281 | if(format == FORMAT_NATIVE) |
287 | memset(bitmap, 0, totalsize); | 282 | memset(bitmap, 0, totalsize); |
288 | #endif | 283 | #endif |
289 | 284 | ||
290 | #if LCD_DEPTH > 1 | 285 | #if LCD_DEPTH > 1 |
291 | fb_data *dest = (fb_data *)bitmap; | 286 | fb_data *dest = (fb_data *)bitmap; |
292 | #endif | 287 | #endif |
293 | 288 | ||
294 | /* loop to read rows and put them to buffer */ | 289 | /* loop to read rows and put them to buffer */ |
295 | for (row = 0; row < height; row++) { | 290 | for (row = 0; row < height; row++) { |
296 | unsigned char *p; | 291 | unsigned char *p; |
297 | 292 | ||
298 | /* read one row */ | 293 | /* read one row */ |
299 | ret = read(fd, bmpbuf, PaddedWidth); | 294 | ret = read(fd, bmpbuf, PaddedWidth); |
300 | if (ret != PaddedWidth) { | 295 | if (ret != PaddedWidth) { |
@@ -326,7 +321,7 @@ int read_bmp_file(char* filename, | |||
326 | /* Mono -> 2gray (iriver H1xx) */ | 321 | /* Mono -> 2gray (iriver H1xx) */ |
327 | for (col = 0; col < width; col++) { | 322 | for (col = 0; col < width; col++) { |
328 | ret = getpix(col, bmpbuf) ^ invert_pixel; | 323 | ret = getpix(col, bmpbuf) ^ invert_pixel; |
329 | 324 | ||
330 | if (ret) | 325 | if (ret) |
331 | dest[((height - row - 1)/4) * width + col] |= | 326 | dest[((height - row - 1)/4) * width + col] |= |
332 | 0xC0 >> (2 * (~(height - row - 1) & 3)); | 327 | 0xC0 >> (2 * (~(height - row - 1) & 3)); |
@@ -337,7 +332,7 @@ int read_bmp_file(char* filename, | |||
337 | /* Mono -> 2gray (ipod) */ | 332 | /* Mono -> 2gray (ipod) */ |
338 | for (col = 0; col < width; col++) { | 333 | for (col = 0; col < width; col++) { |
339 | ret = getpix(col, bmpbuf) ^ invert_pixel; | 334 | ret = getpix(col, bmpbuf) ^ invert_pixel; |
340 | 335 | ||
341 | if (ret) | 336 | if (ret) |
342 | dest[(height - row - 1) * dst_width + col/4] |= | 337 | dest[(height - row - 1) * dst_width + col/4] |= |
343 | 0xC0 >> (2 * (col & 3)); | 338 | 0xC0 >> (2 * (col & 3)); |
@@ -409,8 +404,8 @@ int read_bmp_file(char* filename, | |||
409 | for (col = 0; col < width; col++, p++) { | 404 | for (col = 0; col < width; col++, p++) { |
410 | struct rgb_quad rgb = palette[*p]; | 405 | struct rgb_quad rgb = palette[*p]; |
411 | dest[width * (height - row - 1) + col] = dither ? | 406 | dest[width * (height - row - 1) + col] = dither ? |
412 | dither_24_to_16(rgb, row, col) : | 407 | dither_24_to_lcd(rgb, row, col) : |
413 | LCD_RGBPACK(rgb.red, rgb.green, rgb.blue); | 408 | (fb_data)LCD_RGBPACK(rgb.red, rgb.green, rgb.blue); |
414 | } | 409 | } |
415 | } | 410 | } |
416 | #endif | 411 | #endif |
@@ -474,8 +469,8 @@ int read_bmp_file(char* filename, | |||
474 | /* RGB24 -> RGB16 */ | 469 | /* RGB24 -> RGB16 */ |
475 | for (col = 0; col < width; col++, p += 3) { | 470 | for (col = 0; col < width; col++, p += 3) { |
476 | dest[width * (height - row - 1) + col] = dither ? | 471 | dest[width * (height - row - 1) + col] = dither ? |
477 | dither_24_to_16(*(struct rgb_quad *)p, row, col) : | 472 | dither_24_to_lcd(*(struct rgb_quad *)p, row, col) : |
478 | LCD_RGBPACK(p[2], p[1], p[0]); | 473 | (fb_data)LCD_RGBPACK(p[2], p[1], p[0]); |
479 | } | 474 | } |
480 | } | 475 | } |
481 | #endif | 476 | #endif |
diff --git a/apps/settings_menu.c b/apps/settings_menu.c index 35bdccb49c..eabe153810 100644 --- a/apps/settings_menu.c +++ b/apps/settings_menu.c | |||
@@ -409,7 +409,7 @@ static bool set_fg_color(void) | |||
409 | { | 409 | { |
410 | bool res; | 410 | bool res; |
411 | 411 | ||
412 | res = set_color(&screens[SCREEN_MAIN],str(LANG_FOREGROUND_COLOR), | 412 | res = set_color(NULL,str(LANG_FOREGROUND_COLOR), |
413 | &global_settings.fg_color,global_settings.bg_color); | 413 | &global_settings.fg_color,global_settings.bg_color); |
414 | 414 | ||
415 | screens[SCREEN_MAIN].set_foreground(global_settings.fg_color); | 415 | screens[SCREEN_MAIN].set_foreground(global_settings.fg_color); |
@@ -421,7 +421,7 @@ static bool set_bg_color(void) | |||
421 | { | 421 | { |
422 | bool res; | 422 | bool res; |
423 | 423 | ||
424 | res = set_color(&screens[SCREEN_MAIN],str(LANG_BACKGROUND_COLOR), | 424 | res = set_color(NULL,str(LANG_BACKGROUND_COLOR), |
425 | &global_settings.bg_color,global_settings.fg_color); | 425 | &global_settings.bg_color,global_settings.fg_color); |
426 | 426 | ||
427 | screens[SCREEN_MAIN].set_background(global_settings.bg_color); | 427 | screens[SCREEN_MAIN].set_background(global_settings.bg_color); |
@@ -1699,7 +1699,7 @@ static bool unplug_rw(void) | |||
1699 | 1699 | ||
1700 | static bool unplug_autoresume(void) | 1700 | static bool unplug_autoresume(void) |
1701 | { | 1701 | { |
1702 | return set_bool( str(LANG_UNPLUG_DISABLE_AUTORESUME), | 1702 | return set_bool( str(LANG_UNPLUG_DISABLE_AUTORESUME), |
1703 | &global_settings.unplug_autoresume ); | 1703 | &global_settings.unplug_autoresume ); |
1704 | } | 1704 | } |
1705 | 1705 | ||
diff --git a/firmware/export/lcd.h b/firmware/export/lcd.h index 4949f51cdb..22ae5a3763 100644 --- a/firmware/export/lcd.h +++ b/firmware/export/lcd.h | |||
@@ -161,37 +161,58 @@ static inline unsigned lcd_color_to_native(unsigned color) | |||
161 | #endif | 161 | #endif |
162 | 162 | ||
163 | #ifdef HAVE_LCD_COLOR | 163 | #ifdef HAVE_LCD_COLOR |
164 | #if LCD_DEPTH == 16 | 164 | #if LCD_PIXELFORMAT == RGB565 || LCD_PIXELFORMAT == RGB565SWAPPED |
165 | #define LCD_MAX_RED 31 | 165 | #define LCD_MAX_RED 31 |
166 | #define LCD_MAX_GREEN 63 | 166 | #define LCD_MAX_GREEN 63 |
167 | #define LCD_MAX_BLUE 31 | 167 | #define LCD_MAX_BLUE 31 |
168 | #define _RGB_UNPACK_RED(x) ((((x) >> 8) & 0xf8) | ((x) >> 13)) | 168 | #define LCD_RED_BITS 5 |
169 | #define _RGB_UNPACK_GREEN(x) ((((x) >> 3) & 0xfc) | (((x) >> 9) & 0x03)) | 169 | #define LCD_GREEN_BITS 6 |
170 | #define _RGB_UNPACK_BLUE(x) ((((x) << 3) & 0xf8) | (((x) >> 2) & 0x07)) | 170 | #define LCD_BLUE_BITS 5 |
171 | #define _RGBPACK(r, g, b) ( ((((r) * (31*257) + (127*257)) >> 16) << 11) \ | 171 | |
172 | |((((g) * (63*257) + (127*257)) >> 16) << 5) \ | 172 | /* pack/unpack native RGB values */ |
173 | | (((b) * (31*257) + (127*257)) >> 16)) | 173 | #define _RGBPACK_LCD(r, g, b) ( ((r) << 11) | ((g) << 5) | (b) ) |
174 | /* Note: ((x * 257) >> 16) almost equals (x / 255), but it avoids the division, | 174 | #define _RGB_UNPACK_RED_LCD(x) ( (((x) >> 11) ) ) |
175 | * so it's faster when the macro is used for variable r, g, b in the source. */ | 175 | #define _RGB_UNPACK_GREEN_LCD(x) ( (((x) >> 5) & 0x3f) ) |
176 | #define _RGB_UNPACK_BLUE_LCD(x) ( (((x) ) & 0x1f) ) | ||
177 | |||
178 | /* pack/unpack 24-bit RGB values */ | ||
179 | #define _RGBPACK(r, g, b) _RGBPACK_LCD((r) >> 3, (g) >> 2, (b) >> 3) | ||
180 | #define _RGB_UNPACK_RED(x) ( (((x) >> 8) & 0xf8) | (((x) >> 11) & 0x07) ) | ||
181 | #define _RGB_UNPACK_GREEN(x) ( (((x) >> 3) & 0xfc) | (((x) >> 5) & 0x03) ) | ||
182 | #define _RGB_UNPACK_BLUE(x) ( (((x) << 3) & 0xf8) | (((x) ) & 0x07) ) | ||
183 | |||
176 | #if (LCD_PIXELFORMAT == RGB565SWAPPED) | 184 | #if (LCD_PIXELFORMAT == RGB565SWAPPED) |
177 | #define LCD_RGBPACK(r, g, b) ( ((_RGBPACK((r), (g), (b)) & 0xff00) >> 8) \ | 185 | /* RGB3553 */ |
178 | |((_RGBPACK((r), (g), (b)) & 0x00ff) << 8)) | 186 | #define _LCD_UNSWAP_COLOR(x) swap16(x) |
179 | #define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(swap16(x)) | 187 | #define LCD_RGBPACK_LCD(r, g, b) ( (((r) << 3) ) | \ |
180 | #define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(swap16(x)) | 188 | (((g) >> 3) ) | \ |
181 | #define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(swap16(x)) | 189 | (((g) & 0x07) << 13) | \ |
190 | (((b) << 8) ) ) | ||
191 | #define LCD_RGBPACK(r, g, b) ( (((r) >> 3) << 3) | \ | ||
192 | (((g) >> 5) ) | \ | ||
193 | (((g) & 0x1c) << 11) | \ | ||
194 | (((b) >> 3) << 8) ) | ||
195 | /* swap color once - not currenly used in static inits */ | ||
196 | #define _SWAPUNPACK(x, _unp_) \ | ||
197 | ({ typeof (x) _x_ = swap16(x); _unp_(_x_); }) | ||
198 | #define RGB_UNPACK_RED(x) _SWAPUNPACK((x), _RGB_UNPACK_RED) | ||
199 | #define RGB_UNPACK_GREEN(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN) | ||
200 | #define RGB_UNPACK_BLUE(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE) | ||
201 | #define RGB_UNPACK_RED_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_RED_LCD) | ||
202 | #define RGB_UNPACK_GREEN_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN_LCD) | ||
203 | #define RGB_UNPACK_BLUE_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE_LCD) | ||
182 | #else | 204 | #else |
183 | #define LCD_RGBPACK(r, g, b) _RGBPACK((r), (g), (b)) | 205 | /* RGB565 */ |
184 | #define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(x) | 206 | #define _LCD_UNSWAP_COLOR(x) (x) |
185 | #define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(x) | 207 | #define LCD_RGBPACK(r, g, b) _RGBPACK((r), (g), (b)) |
186 | #define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(x) | 208 | #define LCD_RGBPACK_LCD(r, g, b) _RGBPACK_LCD((r), (g), (b)) |
209 | #define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(x) | ||
210 | #define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(x) | ||
211 | #define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(x) | ||
212 | #define RGB_UNPACK_RED_LCD(x) _RGB_UNPACK_RED(x) | ||
213 | #define RGB_UNPACK_GREEN_LCD(x) _RGB_UNPACK_GREEN(x) | ||
214 | #define RGB_UNPACK_BLUE_LCD(x) _RGB_UNPACK_BLUE(x) | ||
187 | #endif | 215 | #endif |
188 | #elif LCD_DEPTH == 18 | ||
189 | #define LCD_MAX_RED 63 | ||
190 | #define LCD_MAX_GREEN 63 | ||
191 | #define LCD_MAX_BLUE 63 | ||
192 | #define LCD_RGBPACK(r, g, b) ( ((((r) * (63*257) + (127*257)) >> 16) << 12) \ | ||
193 | |((((g) * (63*257) + (127*257)) >> 16) << 6) \ | ||
194 | | (((b) * (63*257) + (127*257)) >> 16)) | ||
195 | #else | 216 | #else |
196 | /* other colour depths */ | 217 | /* other colour depths */ |
197 | #endif | 218 | #endif |