color.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * File : color.c
  3. * This file is part of RT-Thread GUI Engine
  4. * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2009-10-16 Bernard first version
  23. */
  24. #include <rtgui/color.h>
  25. const rtgui_color_t red = RTGUI_RGB(0xff, 0x00, 0x00);
  26. const rtgui_color_t green = RTGUI_RGB(0x00, 0xff, 0x00);
  27. const rtgui_color_t blue = RTGUI_RGB(0x00, 0x00, 0xff);
  28. const rtgui_color_t black = RTGUI_RGB(0x00, 0x00, 0x00);
  29. const rtgui_color_t white = RTGUI_RGB(0xff, 0xff, 0xff);
  30. const rtgui_color_t high_light = RTGUI_RGB(0xfc, 0xfc, 0xfc);
  31. const rtgui_color_t dark_grey = RTGUI_RGB(0x7f, 0x7f, 0x7f);
  32. const rtgui_color_t light_grey = RTGUI_RGB(0xc0, 0xc0, 0xc0);
  33. const static rt_uint8_t pixel_bits_table[] =
  34. {
  35. 1, /* mono */
  36. 2, /* 4 level for gray */
  37. 4, /* 16 level for gray */
  38. 8, /* RGB332 */
  39. 12, /* RGB444 */
  40. 16, /* RGB565 */
  41. 16, /* BGR565 */
  42. 18, /* RGB666 */
  43. 24, /* RGB888 */
  44. 32, /* ARGB888 */
  45. };
  46. rt_uint8_t rtgui_color_get_bits(rt_uint8_t pixel_format)
  47. {
  48. if (pixel_format <= RTGRAPHIC_PIXEL_FORMAT_ARGB888)
  49. return pixel_bits_table[pixel_format];
  50. /* use 32 as the default */
  51. return 32;
  52. }
  53. RTM_EXPORT(rtgui_color_get_bits);
  54. rt_uint8_t rtgui_color_get_bpp(rt_uint8_t pixel_format)
  55. {
  56. rt_uint8_t bpp = 4;
  57. if (pixel_format <= RTGRAPHIC_PIXEL_FORMAT_ARGB888)
  58. {
  59. bpp = _UI_BITBYTES(pixel_bits_table[pixel_format]);
  60. }
  61. return bpp;
  62. }
  63. RTM_EXPORT(rtgui_color_get_bpp);