color.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * File : color.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-10-16 Bernard first version
  13. */
  14. #include <rtgui/color.h>
  15. const rtgui_color_t red = RTGUI_RGB(0xff, 0x00, 0x00);
  16. const rtgui_color_t green = RTGUI_RGB(0x00, 0xff, 0x00);
  17. const rtgui_color_t blue = RTGUI_RGB(0x00, 0x00, 0xff);
  18. const rtgui_color_t black = RTGUI_RGB(0x00, 0x00, 0x00);
  19. const rtgui_color_t white = RTGUI_RGB(0xff, 0xff, 0xff);
  20. const rtgui_color_t high_light = RTGUI_RGB(0xfc, 0xfc, 0xfc);
  21. const rtgui_color_t dark_grey = RTGUI_RGB(0x7f, 0x7f, 0x7f);
  22. const rtgui_color_t light_grey = RTGUI_RGB(0xc0, 0xc0, 0xc0);
  23. const static rt_uint8_t pixel_bits_table[] =
  24. {
  25. 1, /* mono */
  26. 2, /* 4 level for gray */
  27. 4, /* 16 level for gray */
  28. 8, /* RGB332 */
  29. 12, /* RGB444 */
  30. 16, /* RGB565 */
  31. 16, /* BGR565 */
  32. 18, /* RGB666 */
  33. 24, /* RGB888 */
  34. 32, /* ARGB888 */
  35. };
  36. rt_uint8_t rtgui_color_get_bits(rt_uint8_t pixel_format)
  37. {
  38. if (pixel_format <= RTGRAPHIC_PIXEL_FORMAT_ARGB888)
  39. return pixel_bits_table[pixel_format];
  40. /* use 32 as the default */
  41. return 32;
  42. }
  43. RTM_EXPORT(rtgui_color_get_bits);
  44. rt_uint8_t rtgui_color_get_bpp(rt_uint8_t pixel_format)
  45. {
  46. rt_uint8_t bpp = 4;
  47. if (pixel_format <= RTGRAPHIC_PIXEL_FORMAT_ARGB888)
  48. {
  49. bpp = _UI_BITBYTES(pixel_bits_table[pixel_format]);
  50. }
  51. return bpp;
  52. }
  53. RTM_EXPORT(rtgui_color_get_bpp);