agg_pixfmt_base.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //----------------------------------------------------------------------------
  2. // Anti-Grain Geometry - Version 2.4
  3. // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
  4. //
  5. // Permission to copy, use, modify, sell and distribute this software
  6. // is granted provided this copyright notice appears in all copies.
  7. // This software is provided "as is" without express or implied
  8. // warranty, and with no claim as to its suitability for any purpose.
  9. //
  10. //----------------------------------------------------------------------------
  11. // Contact: mcseem@antigrain.com
  12. // mcseemagg@yahoo.com
  13. // http://www.antigrain.com
  14. //----------------------------------------------------------------------------
  15. #ifndef AGG_PIXFMT_BASE_INCLUDED
  16. #define AGG_PIXFMT_BASE_INCLUDED
  17. #include "agg_basics.h"
  18. #include "agg_color_gray.h"
  19. #include "agg_color_rgba.h"
  20. namespace agg
  21. {
  22. struct pixfmt_gray_tag
  23. {
  24. };
  25. struct pixfmt_rgb_tag
  26. {
  27. };
  28. struct pixfmt_rgba_tag
  29. {
  30. };
  31. //--------------------------------------------------------------blender_base
  32. template<class ColorT, class Order = void>
  33. struct blender_base
  34. {
  35. typedef ColorT color_type;
  36. typedef Order order_type;
  37. typedef typename color_type::value_type value_type;
  38. static rgba get(value_type r, value_type g, value_type b, value_type a, cover_type cover = cover_full)
  39. {
  40. if (cover > cover_none)
  41. {
  42. rgba c(
  43. color_type::to_double(r),
  44. color_type::to_double(g),
  45. color_type::to_double(b),
  46. color_type::to_double(a));
  47. if (cover < cover_full)
  48. {
  49. double x = double(cover) / cover_full;
  50. c.r *= x;
  51. c.g *= x;
  52. c.b *= x;
  53. c.a *= x;
  54. }
  55. return c;
  56. }
  57. else return rgba::no_color();
  58. }
  59. static rgba get(const value_type* p, cover_type cover = cover_full)
  60. {
  61. return get(
  62. p[order_type::R],
  63. p[order_type::G],
  64. p[order_type::B],
  65. p[order_type::A],
  66. cover);
  67. }
  68. static void set(value_type* p, value_type r, value_type g, value_type b, value_type a)
  69. {
  70. p[order_type::R] = r;
  71. p[order_type::G] = g;
  72. p[order_type::B] = b;
  73. p[order_type::A] = a;
  74. }
  75. static void set(value_type* p, const rgba& c)
  76. {
  77. p[order_type::R] = color_type::from_double(c.r);
  78. p[order_type::G] = color_type::from_double(c.g);
  79. p[order_type::B] = color_type::from_double(c.b);
  80. p[order_type::A] = color_type::from_double(c.a);
  81. }
  82. };
  83. }
  84. #endif