Patch by Andrej Spielmann (GSOC):

Two new AGG classes were needed to handle subpixel scanline coverage values.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26358 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2008-07-10 08:15:59 +00:00
parent 0a0622a6de
commit 185d13d5de
2 changed files with 202 additions and 0 deletions
+117
View File
@@ -0,0 +1,117 @@
/*
* Copyright 2008, Andrej Spielmann <[email protected]>.
* All rights reserved. Distributed under the terms of the MIT License.
*
* Copyright 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
*
*
* Class scanline_u8_subpix, a slightly modified version of
* scanline_u8 customized to store 3 covers per pixel
*
*/
#ifndef AGG_SCANLINE_U_SUBPIX_INCLUDED
#define AGG_SCANLINE_U_SUBPIX_INCLUDED
#include <agg_array.h>
namespace agg
{
//======================================================scanline_u8_subpix
//------------------------------------------------------------------------
class scanline_u8_subpix
{
public:
typedef scanline_u8_subpix self_type;
typedef int8u cover_type;
typedef int16 coord_type;
//--------------------------------------------------------------------
struct span
{
coord_type x;
coord_type len;
cover_type* covers;
};
typedef span* iterator;
typedef const span* const_iterator;
//--------------------------------------------------------------------
scanline_u8_subpix() :
m_min_x(0),
m_last_x(0x7FFFFFF0),
m_cur_span(0)
{}
//--------------------------------------------------------------------
void reset(int min_x, int max_x)
{
unsigned max_len = 3*(max_x - min_x + 2);
if(max_len > m_spans.size())
{
m_spans.resize(max_len);
m_covers.resize(max_len);
}
m_last_x = 0x7FFFFFF0;
m_min_x = min_x;
m_cur_span = &m_spans[0];
}
//--------------------------------------------------------------------
void add_cell(int x, unsigned cover1, unsigned cover2, unsigned cover3)
{
x -= m_min_x;
m_covers[3*x] = (cover_type)cover1;
m_covers[3*x+1] = (cover_type)cover2;
m_covers[3*x+2] = (cover_type)cover3;
if(x == m_last_x+1)
{
m_cur_span->len += 3;
}
else
{
m_cur_span++;
m_cur_span->x = (coord_type)(x + m_min_x);
m_cur_span->len = 3;
m_cur_span->covers = &m_covers[3*x];
}
m_last_x = x;
}
//--------------------------------------------------------------------
void finalize(int y)
{
m_y = y;
}
//--------------------------------------------------------------------
void reset_spans()
{
m_last_x = 0x7FFFFFF0;
m_cur_span = &m_spans[0];
}
//--------------------------------------------------------------------
int y() const { return m_y; }
unsigned num_spans() const { return unsigned(m_cur_span - &m_spans[0]); }
const_iterator begin() const { return &m_spans[1]; }
iterator begin() { return &m_spans[1]; }
private:
scanline_u8_subpix(const self_type&);
const self_type& operator = (const self_type&);
private:
int m_min_x;
int m_last_x;
int m_y;
pod_array<cover_type> m_covers;
pod_array<span> m_spans;
span* m_cur_span;
};
}
#endif
@@ -0,0 +1,85 @@
/*
* Copyright 2008, Andrej Spielmann <[email protected]>.
* All rights reserved. Distributed under the terms of the MIT License.
*
* Copyright 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
*
*
*/
#include <Region.h>
#include "agg_basics.h"
#include "agg_array.h"
#include "agg_renderer_base.h"
#include "agg_renderer_scanline.h"
namespace agg
{
//============================================render_scanline_subpix_solid
template<class Scanline, class BaseRenderer, class ColorT>
void render_scanline_subpix_solid(const Scanline& sl,
BaseRenderer& ren,
const ColorT& color)
{
int y = sl.y();
unsigned num_spans = sl.num_spans();
typename Scanline::const_iterator span = sl.begin();
for(;;)
{
int x = span->x;
if(span->len > 0)
{
ren.blend_solid_hspan_subpix(x, y, (unsigned)span->len,
color,
span->covers);
}
else
{
ren.blend_hline_subpix(x, y, (unsigned)(x - span->len - 1),
color,
*(span->covers));
}
if(--num_spans == 0) break;
++span;
}
}
//==========================================renderer_scanline_subpix_solid
template<class BaseRenderer> class renderer_scanline_subpix_solid
{
public:
typedef BaseRenderer base_ren_type;
typedef typename base_ren_type::color_type color_type;
//--------------------------------------------------------------------
renderer_scanline_subpix_solid() : m_ren(0) {}
renderer_scanline_subpix_solid(base_ren_type& ren) : m_ren(&ren) {}
void attach(base_ren_type& ren)
{
m_ren = &ren;
}
//--------------------------------------------------------------------
void color(const color_type& c) { m_color = c; }
const color_type& color() const { return m_color; }
//--------------------------------------------------------------------
void prepare() {}
//--------------------------------------------------------------------
template<class Scanline> void render(const Scanline& sl)
{
render_scanline_subpix_solid(sl, *m_ren, m_color);
}
private:
base_ren_type* m_ren;
color_type m_color;
};
}