Blame c++/contourgl/swrender.h

93cbac
/*
93cbac
    ......... 2015 Ivan Mahonin
93cbac
93cbac
    This program is free software: you can redistribute it and/or modify
93cbac
    it under the terms of the GNU General Public License as published by
93cbac
    the Free Software Foundation, either version 3 of the License, or
93cbac
    (at your option) any later version.
93cbac
93cbac
    This program is distributed in the hope that it will be useful,
93cbac
    but WITHOUT ANY WARRANTY; without even the implied warranty of
93cbac
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
93cbac
    GNU General Public License for more details.
93cbac
93cbac
    You should have received a copy of the GNU General Public License
93cbac
    along with this program.  If not, see <http: licenses="" www.gnu.org="">.</http:>
93cbac
*/
93cbac
572d9c
#ifndef _SWRENDER_H_
572d9c
#define _SWRENDER_H_
93cbac
93cbac
#include <cstring></cstring>
93cbac
93cbac
#include "polyspan.h"
93cbac
93cbac
class Color {
93cbac
public:
93cbac
	typedef float type;
7c6b57
	union {
7c6b57
		struct { type r, g, b, a; };
7c6b57
		struct { type channels[4]; };
7c6b57
	};
7c6b57
93cbac
	Color(): r(), g(), b(), a() { }
93cbac
	Color(type r, type g, type b, type a): r(r), g(g), b(b), a(a) { }
93cbac
	Color(const Color &color, type a): r(color.r), g(color.g), b(color.b), a(color.a*a) { }
93cbac
};
93cbac
93cbac
class Surface {
93cbac
public:
93cbac
	const int width, height;
93cbac
	Color * const data;
93cbac
93cbac
	Surface(int width, int height):
93cbac
		width(width), height(height), data(new Color[width*height])
93cbac
		{ clear(); }
93cbac
93cbac
	~Surface()
93cbac
		{ delete data; }
93cbac
93cbac
	void clear() { memset(data, 0, count()*sizeof(Color)); }
93cbac
	int count() const { return width*height; }
f83e6b
	int data_size() const { return count()*sizeof(Color); }
93cbac
	Color* operator[] (int row) { return data + row*width; }
93cbac
	const Color* operator[] (int row) const { return data + row*width; }
93cbac
};
93cbac
572d9c
class SwRender {
93cbac
public:
93cbac
	static void fill(
93cbac
		Surface &target,
93cbac
		const Color &color );
93cbac
93cbac
	static void fill(
93cbac
		Surface &target,
93cbac
		const Color &color,
93cbac
		int left,
93cbac
		int top,
93cbac
		int width,
93cbac
		int height );
93cbac
93cbac
	static void row(
93cbac
		Surface &target,
93cbac
		const Color &color,
93cbac
		int left,
93cbac
		int top,
93cbac
		int length );
93cbac
93cbac
	static void row_alpha(
93cbac
		Surface &target,
93cbac
		const Color &color,
93cbac
		Color::type alpha,
93cbac
		int left,
93cbac
		int top,
93cbac
		int length );
93cbac
93cbac
	static void polyspan(
93cbac
		Surface &target,
93cbac
		const Polyspan &polyspan,
93cbac
		const Color &color,
93cbac
		bool evenodd,
93cbac
		bool invert );
93cbac
};
93cbac
93cbac
#endif