Color.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*!
  2. \file cairodriver/Color.c
  3. \brief GRASS cairo display driver - colors management
  4. (C) 2007-2008 by Lars Ahlzen and the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
  8. \author Glynn Clements
  9. */
  10. #include "cairodriver.h"
  11. /*!
  12. \brief Set source color (opaque)
  13. This color will then be used for any subsequent drawing operation
  14. until a new source pattern is set.
  15. \param color value
  16. */
  17. void Cairo_color(int color)
  18. {
  19. static int previous_color = 0x7FFFFFFF;
  20. G_debug(3, "Cairo_color: %d", color);
  21. if (color != previous_color) {
  22. int r = (color >> 16) & 0xFF;
  23. int g = (color >> 8) & 0xFF;
  24. int b = (color >> 0) & 0xFF;
  25. cairo_set_source_rgba(cairo, CAIROCOLOR(r), CAIROCOLOR(g),
  26. CAIROCOLOR(b), 1.0);
  27. previous_color = color;
  28. G_debug(3, "Set color to: %g %g %g", CAIROCOLOR(r), CAIROCOLOR(g),
  29. CAIROCOLOR(b));
  30. }
  31. }
  32. /*!
  33. \brief Get color value
  34. \param r,g,b red,green,blue
  35. \return value
  36. */
  37. int Cairo_lookup_color(int r, int g, int b)
  38. {
  39. G_debug(3, "Cairo_lookup_color: %d %d %d", r, g, b);
  40. return (r << 16) + (g << 8) + (b << 0);
  41. }