| 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: [email protected] |
| 12 |
// [email protected] |
| 13 |
// http://www.antigrain.com |
| 14 |
//---------------------------------------------------------------------------- |
| 15 |
|
| 16 |
#ifndef AGG_PIXFMT_BASE_INCLUDED |
| 17 |
#define AGG_PIXFMT_BASE_INCLUDED |
| 18 |
|
| 19 |
#include "agg_basics.h" |
| 20 |
#include "agg_color_gray.h" |
| 21 |
#include "agg_color_rgba.h" |
| 22 |
|
| 23 |
namespace agg |
| 24 |
{ |
| 25 |
struct pixfmt_gray_tag |
| 26 |
{ |
| 27 |
}; |
| 28 |
|
| 29 |
struct pixfmt_rgb_tag |
| 30 |
{ |
| 31 |
}; |
| 32 |
|
| 33 |
struct pixfmt_rgba_tag |
| 34 |
{ |
| 35 |
}; |
| 36 |
|
| 37 |
//--------------------------------------------------------------blender_base |
| 38 |
template<class ColorT, class Order = void> |
| 39 |
struct blender_base |
| 40 |
{ |
| 41 |
typedef ColorT color_type; |
| 42 |
typedef Order order_type; |
| 43 |
typedef typename color_type::value_type value_type; |
| 44 |
|
| 45 |
static rgba get(value_type r, value_type g, value_type b, value_type a, cover_type cover = cover_full) |
| 46 |
{ |
| 47 |
if (cover > cover_none) |
| 48 |
{ |
| 49 |
rgba c( |
| 50 |
color_type::to_double(r), |
| 51 |
color_type::to_double(g), |
| 52 |
color_type::to_double(b), |
| 53 |
color_type::to_double(a)); |
| 54 |
|
| 55 |
if (cover < cover_full) |
| 56 |
{ |
| 57 |
double x = double(cover) / cover_full; |
| 58 |
c.r *= x; |
| 59 |
c.g *= x; |
| 60 |
c.b *= x; |
| 61 |
c.a *= x; |
| 62 |
} |
| 63 |
|
| 64 |
return c; |
| 65 |
} |
| 66 |
else return rgba::no_color(); |
| 67 |
} |
| 68 |
|
| 69 |
static rgba get(const value_type* p, cover_type cover = cover_full) |
| 70 |
{ |
| 71 |
return get( |
| 72 |
p[order_type::R], |
| 73 |
p[order_type::G], |
| 74 |
p[order_type::B], |
| 75 |
p[order_type::A], |
| 76 |
cover); |
| 77 |
} |
| 78 |
|
| 79 |
static void set(value_type* p, value_type r, value_type g, value_type b, value_type a) |
| 80 |
{ |
| 81 |
p[order_type::R] = r; |
| 82 |
p[order_type::G] = g; |
| 83 |
p[order_type::B] = b; |
| 84 |
p[order_type::A] = a; |
| 85 |
} |
| 86 |
|
| 87 |
static void set(value_type* p, const rgba& c) |
| 88 |
{ |
| 89 |
p[order_type::R] = color_type::from_double(c.r); |
| 90 |
p[order_type::G] = color_type::from_double(c.g); |
| 91 |
p[order_type::B] = color_type::from_double(c.b); |
| 92 |
p[order_type::A] = color_type::from_double(c.a); |
| 93 |
} |
| 94 |
}; |
| 95 |
} |
| 96 |
|
| 97 |
#endif |