Blame synfig-core/src/synfig/rendering/primitive/polyspan.h

d46c23
/* === S Y N F I G ========================================================= */
248685
/*!	\file synfig/rendering/primitive/polyspan.h
d46c23
**	\brief Polyspan Header
d46c23
**
d46c23
**	$Id$
d46c23
**
d46c23
**	\legal
d46c23
**	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
d46c23
**	Copyright (c) 2007, 2008 Chris Moore
d46c23
**	Copyright (c) 2012-2013 Carlos Lรณpez
d46c23
**	......... ... 2015 Ivan Mahonin
d46c23
**
d46c23
**	This package is free software; you can redistribute it and/or
d46c23
**	modify it under the terms of the GNU General Public License as
d46c23
**	published by the Free Software Foundation; either version 2 of
d46c23
**	the License, or (at your option) any later version.
d46c23
**
d46c23
**	This package is distributed in the hope that it will be useful,
d46c23
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
d46c23
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d46c23
**	General Public License for more details.
d46c23
**	\endlegal
d46c23
*/
d46c23
/* ========================================================================= */
d46c23
d46c23
/* === S T A R T =========================================================== */
d46c23
d46c23
#ifndef __SYNFIG_RENDERING_POLYSPAN_H
d46c23
#define __SYNFIG_RENDERING_POLYSPAN_H
d46c23
d46c23
/* === H E A D E R S ======================================================= */
d46c23
d46c23
#include <vector></vector>
d46c23
e788a2
#include <synfig rect.h=""></synfig>
248685
248685
#include "contour.h"
d46c23
d46c23
/* === M A C R O S ========================================================= */
d46c23
d46c23
/* === T Y P E D E F S ===================================================== */
d46c23
d46c23
/* === C L A S S E S & S T R U C T S ======================================= */
d46c23
d46c23
namespace synfig
d46c23
{
d46c23
namespace rendering
d46c23
{
d46c23
d46c23
class Polyspan
d46c23
{
d46c23
public:
d46c23
	struct PenMark
d46c23
	{
d46c23
		int y, x;
d46c23
		Real cover, area;
d46c23
d46c23
		PenMark(): y(), x(), cover(), area() { }
d46c23
		PenMark(int xin, int yin, Real c, Real a):
d46c23
			y(yin), x(xin), cover(c), area(a) { }
d46c23
		void set(int xin, int yin, Real c, Real a)
d46c23
			{ y = yin; x = xin; cover = c; area = a; }
d46c23
		void setcoord(int xin, int yin)
d46c23
			{ y = yin; x = xin;	}
d46c23
		void setcover(Real c, Real a)
d46c23
			{ cover	= c; area = a; }
d46c23
		void addcover(Real c, Real a)
d46c23
			{ cover += c; area += a; }
d46c23
		bool operator < (const PenMark &rhs) const
d46c23
			{ return y == rhs.y ? x < rhs.x : y < rhs.y; }
d46c23
	};
d46c23
d46c23
	typedef	std::vector<penmark> cover_array;</penmark>
d46c23
d46c23
	//for assignment to flags value
d46c23
	enum PolySpanFlags
d46c23
	{
11c2eb
		NotSorted       = 0x8000,
11c2eb
		NotClosed       = 0x4000,
11c2eb
		NotFinishedLine = 0x2000
d46c23
	};
d46c23
cda1e7
	enum {
85abde
		MAX_SUBDIVISION_SIZE = 64
cda1e7
	};
cda1e7
d46c23
private:
d46c23
	Point			arc[3*MAX_SUBDIVISION_SIZE + 1];
d46c23
d46c23
	cover_array		covers;
d46c23
	PenMark			current;
d46c23
d46c23
	int				open_index;
d46c23
d46c23
	//ending position of last primitive
d46c23
	Real			cur_x;
d46c23
	Real			cur_y;
d46c23
11c2eb
	//ending position of not-finished line
11c2eb
	Real			cur_line_x;
11c2eb
	Real			cur_line_y;
11c2eb
11c2eb
d46c23
	//starting position of current primitive list
d46c23
	Real			close_x;
d46c23
	Real			close_y;
d46c23
d46c23
	//flags for the current segment
d46c23
	int				flags;
d46c23
d46c23
	//the window that will be drawn (used for clipping)
e788a2
	RectInt		    window;
d46c23
d46c23
	//add the current cell, but only if there is information to add
d46c23
	void addcurrent();
d46c23
d46c23
	//move to the next cell (cover values 0 initially), keeping the current if necessary
d46c23
	void move_pen(int x, int y);
d46c23
85abde
	static Real clamp_coord(Real x);
85abde
	static Real clamp_detail(Real x);
85abde
e788a2
	static bool clip_conic(const Point *const p, const RectInt &r);
d46c23
	static Real max_edges_conic(const Point *const p);
d46c23
	static void subd_conic_stack(Point *arc);
d46c23
e788a2
	static bool clip_cubic(const Point *const p, const RectInt &r);
d46c23
	static Real max_edges_cubic(const Point *const p);
d46c23
	static void subd_cubic_stack(Point *arc);
d46c23
11c2eb
	void finish_line();
11c2eb
d46c23
public:
d46c23
	Polyspan();
d46c23
e788a2
	const RectInt& get_window() const { return window; }
d46c23
	const cover_array& get_covers() const { return covers; }
d46c23
d46c23
	bool notclosed() const
d46c23
		{ return (flags & NotClosed) || (cur_x != close_x) || (cur_y != close_y); }
d46c23
d46c23
	//0 out all the variables involved in processing
d46c23
	void clear();
e788a2
	void init(const RectInt &window)
d46c23
		{ clear(); this->window = window; }
d46c23
	void init(int minx, int miny, int maxx, int maxy)
d46c23
	{
d46c23
		clear();
d46c23
		window.minx = minx;
d46c23
		window.miny = miny;
d46c23
		window.maxx = maxx;
d46c23
		window.maxy = maxy;
d46c23
	}
d46c23
d46c23
	//close the primitives with a line (or rendering will not work as expected)
d46c23
	void close();
d46c23
d46c23
	// Not recommended - destroys any separation of spans currently held
d46c23
	void merge_all();
d46c23
d46c23
	//will sort the marks if they are not sorted
d46c23
	void sort_marks();
d46c23
d46c23
	//encapsulate the current sublist of marks (used for drawing)
d46c23
	void encapsulate_current();
d46c23
d46c23
	//move to start a new primitive list (enclose the last primitive if need be)
d46c23
	void move_to(Real x, Real y);
d46c23
d46c23
	//primitive_to functions
92b146
	void line_to(Real x, Real y, Real detail = 1.0);
92b146
	void conic_to(Real x, Real y, Real x1, Real y1, Real detail = 1.0);
92b146
	void cubic_to(Real x, Real y, Real x1, Real y1, Real x2, Real y2, Real detail = 1.0);
d46c23
d46c23
	void draw_scanline(int y, Real x1, Real y1, Real x2, Real y2);
d46c23
	void draw_line(Real x1, Real y1, Real x2, Real y2);
d46c23
248685
	Real extract_alpha(Real area, Contour::WindingStyle winding_style) const;
0bce9d
e788a2
	RectInt calc_bounds() const;
d46c23
};
d46c23
d46c23
} /* end namespace rendering */
d46c23
} /* end namespace synfig */
d46c23
d46c23
/* -- E N D ----------------------------------------------------------------- */
d46c23
d46c23
#endif