/usr/include/agg2/agg_span_gouraud_rgba.h is in libagg-dev 2.5+dfsg1-9.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | //----------------------------------------------------------------------------
// Anti-Grain Geometry (AGG) - Version 2.5
// A high quality rendering engine for C++
// Copyright (C) 2002-2006 Maxim Shemanarev
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://antigrain.com
//
// AGG is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// AGG is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with AGG; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
//----------------------------------------------------------------------------
//
// Adaptation for high precision colors has been sponsored by
// Liberty Technology Systems, Inc., visit http://lib-sys.com
//
// Liberty Technology Systems, Inc. is the provider of
// PostScript and PDF technology for software developers.
//
//----------------------------------------------------------------------------
#ifndef AGG_SPAN_GOURAUD_RGBA_INCLUDED
#define AGG_SPAN_GOURAUD_RGBA_INCLUDED
#include "agg_basics.h"
#include "agg_color_rgba.h"
#include "agg_dda_line.h"
#include "agg_span_gouraud.h"
namespace agg
{
//=======================================================span_gouraud_rgba
template<class ColorT> class span_gouraud_rgba : public span_gouraud<ColorT>
{
public:
typedef ColorT color_type;
typedef typename ColorT::value_type value_type;
typedef span_gouraud<color_type> base_type;
typedef typename base_type::coord_type coord_type;
enum subpixel_scale_e
{
subpixel_shift = 4,
subpixel_scale = 1 << subpixel_shift
};
private:
//--------------------------------------------------------------------
struct rgba_calc
{
void init(const coord_type& c1, const coord_type& c2)
{
m_x1 = c1.x - 0.5;
m_y1 = c1.y - 0.5;
m_dx = c2.x - c1.x;
double dy = c2.y - c1.y;
m_1dy = (dy < 1e-5) ? 1e5 : 1.0 / dy;
m_r1 = c1.color.r;
m_g1 = c1.color.g;
m_b1 = c1.color.b;
m_a1 = c1.color.a;
m_dr = c2.color.r - m_r1;
m_dg = c2.color.g - m_g1;
m_db = c2.color.b - m_b1;
m_da = c2.color.a - m_a1;
}
void calc(double y)
{
double k = (y - m_y1) * m_1dy;
if(k < 0.0) k = 0.0;
if(k > 1.0) k = 1.0;
m_r = m_r1 + iround(m_dr * k);
m_g = m_g1 + iround(m_dg * k);
m_b = m_b1 + iround(m_db * k);
m_a = m_a1 + iround(m_da * k);
m_x = iround((m_x1 + m_dx * k) * subpixel_scale);
}
double m_x1;
double m_y1;
double m_dx;
double m_1dy;
int m_r1;
int m_g1;
int m_b1;
int m_a1;
int m_dr;
int m_dg;
int m_db;
int m_da;
int m_r;
int m_g;
int m_b;
int m_a;
int m_x;
};
public:
//--------------------------------------------------------------------
span_gouraud_rgba() {}
span_gouraud_rgba(const color_type& c1,
const color_type& c2,
const color_type& c3,
double x1, double y1,
double x2, double y2,
double x3, double y3,
double d = 0) :
base_type(c1, c2, c3, x1, y1, x2, y2, x3, y3, d)
{}
//--------------------------------------------------------------------
void prepare()
{
coord_type coord[3];
base_type::arrange_vertices(coord);
m_y2 = int(coord[1].y);
m_swap = cross_product(coord[0].x, coord[0].y,
coord[2].x, coord[2].y,
coord[1].x, coord[1].y) < 0.0;
m_rgba1.init(coord[0], coord[2]);
m_rgba2.init(coord[0], coord[1]);
m_rgba3.init(coord[1], coord[2]);
}
//--------------------------------------------------------------------
void generate(color_type* span, int x, int y, unsigned len)
{
m_rgba1.calc(y);//(m_rgba1.m_1dy > 2) ? m_rgba1.m_y1 : y);
const rgba_calc* pc1 = &m_rgba1;
const rgba_calc* pc2 = &m_rgba2;
if(y <= m_y2)
{
// Bottom part of the triangle (first subtriangle)
//-------------------------
m_rgba2.calc(y + m_rgba2.m_1dy);
}
else
{
// Upper part (second subtriangle)
m_rgba3.calc(y - m_rgba3.m_1dy);
//-------------------------
pc2 = &m_rgba3;
}
if(m_swap)
{
// It means that the triangle is oriented clockwise,
// so that we need to swap the controlling structures
//-------------------------
const rgba_calc* t = pc2;
pc2 = pc1;
pc1 = t;
}
// Get the horizontal length with subpixel accuracy
// and protect it from division by zero
//-------------------------
int nlen = abs(pc2->m_x - pc1->m_x);
if(nlen <= 0) nlen = 1;
dda_line_interpolator<14> r(pc1->m_r, pc2->m_r, nlen);
dda_line_interpolator<14> g(pc1->m_g, pc2->m_g, nlen);
dda_line_interpolator<14> b(pc1->m_b, pc2->m_b, nlen);
dda_line_interpolator<14> a(pc1->m_a, pc2->m_a, nlen);
// Calculate the starting point of the gradient with subpixel
// accuracy and correct (roll back) the interpolators.
// This operation will also clip the beginning of the span
// if necessary.
//-------------------------
int start = pc1->m_x - (x << subpixel_shift);
r -= start;
g -= start;
b -= start;
a -= start;
nlen += start;
int vr, vg, vb, va;
enum lim_e { lim = color_type::base_mask };
// Beginning part of the span. Since we rolled back the
// interpolators, the color values may have overflow.
// So that, we render the beginning part with checking
// for overflow. It lasts until "start" is positive;
// typically it's 1-2 pixels, but may be more in some cases.
//-------------------------
while(len && start > 0)
{
vr = r.y();
vg = g.y();
vb = b.y();
va = a.y();
if(vr < 0) vr = 0; if(vr > lim) vr = lim;
if(vg < 0) vg = 0; if(vg > lim) vg = lim;
if(vb < 0) vb = 0; if(vb > lim) vb = lim;
if(va < 0) va = 0; if(va > lim) va = lim;
span->r = (value_type)vr;
span->g = (value_type)vg;
span->b = (value_type)vb;
span->a = (value_type)va;
r += subpixel_scale;
g += subpixel_scale;
b += subpixel_scale;
a += subpixel_scale;
nlen -= subpixel_scale;
start -= subpixel_scale;
++span;
--len;
}
// Middle part, no checking for overflow.
// Actual spans can be longer than the calculated length
// because of anti-aliasing, thus, the interpolators can
// overflow. But while "nlen" is positive we are safe.
//-------------------------
while(len && nlen > 0)
{
span->r = (value_type)r.y();
span->g = (value_type)g.y();
span->b = (value_type)b.y();
span->a = (value_type)a.y();
r += subpixel_scale;
g += subpixel_scale;
b += subpixel_scale;
a += subpixel_scale;
nlen -= subpixel_scale;
++span;
--len;
}
// Ending part; checking for overflow.
// Typically it's 1-2 pixels, but may be more in some cases.
//-------------------------
while(len)
{
vr = r.y();
vg = g.y();
vb = b.y();
va = a.y();
if(vr < 0) vr = 0; if(vr > lim) vr = lim;
if(vg < 0) vg = 0; if(vg > lim) vg = lim;
if(vb < 0) vb = 0; if(vb > lim) vb = lim;
if(va < 0) va = 0; if(va > lim) va = lim;
span->r = (value_type)vr;
span->g = (value_type)vg;
span->b = (value_type)vb;
span->a = (value_type)va;
r += subpixel_scale;
g += subpixel_scale;
b += subpixel_scale;
a += subpixel_scale;
++span;
--len;
}
}
private:
bool m_swap;
int m_y2;
rgba_calc m_rgba1;
rgba_calc m_rgba2;
rgba_calc m_rgba3;
};
}
#endif
|