Blame c++/freetype/src/surface.h

b8976b
#ifndef SURFACE_H
b8976b
#define SURFACE_H
b8976b
b8976b
b8976b
#include <cassert></cassert>
b8976b
#include <cstddef></cstddef>
b8976b
b8976b
#include <gdkmm pixbuf.h=""></gdkmm>
b8976b
#include <cairomm surface.h=""></cairomm>
b8976b
b8976b
#include "common.h"
b8976b
b8976b
b8976b
class Surface: public Shared {
b8976b
protected:
b8976b
	int m_width;
b8976b
	int m_height;
b8976b
	int m_pitch;
b8976b
	Color *m_origin;
b8976b
	
b8976b
	Surface();
b8976b
	Surface(const Surface &);
b8976b
	Surface& operator= (const Surface &) { return *this; }
b8976b
	void reset();
b8976b
	
b8976b
public:
b8976b
	virtual ~Surface() { }
b8976b
	
b8976b
	inline int width() const { return m_width; }
b8976b
	inline int height() const { return m_height; }
b8976b
	inline int pitch() const { return m_pitch; }
b8976b
	inline int count() const { return m_width*m_height; }
b8976b
	inline bool empty() const { return !count(); }
b8976b
	
b8976b
	inline Color* origin() { return m_origin; }
b8976b
	inline const Color* origin() const { return m_origin; }
b8976b
	
b8976b
	inline int data_count()   const { return data_count  (width(), height(), pitch()); }
b8976b
	inline size_t data_size() const { return data_size   (width(), height(), pitch()); }
b8976b
	inline int begin_offset() const { return begin_offset(width(), height(), pitch()); }
b8976b
	inline int end_offset()   const { return end_offset  (width(), height(), pitch()); }
b8976b
	
b8976b
	inline Color* data_begin() { return m_origin ? m_origin + begin_offset() : NULL; }
b8976b
	inline const Color* data_begin() const { return m_origin ? m_origin + begin_offset() : NULL; }
b8976b
	inline Color* data_end() { return m_origin ? m_origin + end_offset() : NULL; }
b8976b
	inline const Color* data_end() const { return m_origin ? m_origin + end_offset() : NULL; }
b8976b
	
b8976b
	inline Color* row(int index)
b8976b
		{ assert(index >= 0 && index < m_height); return m_origin + index*m_pitch; }
b8976b
	inline const Color* row(int index) const
b8976b
		{ assert(index >= 0 && index < m_height); return m_origin + index*m_pitch; }
b8976b
	
b8976b
	inline Color* operator[] (int index) { return row(index); }
b8976b
	inline const Color* operator[] (int index) const { return row(index); }
b8976b
	
b8976b
	inline void put_pixel(int x, int y, const Color &color) {
b8976b
		if (x >= 0 && y >= 0 && x < width() && y < height())
b8976b
			row(y)[x] = color;
b8976b
	}
b8976b
	
b8976b
	void mult_alpha();
b8976b
	void demult_alpha();
b8976b
	Color get_pixel(Real x, Real y) const;
b8976b
	Color get_pixel_premulted(Real x, Real y) const;
b8976b
	
b8976b
	static inline int data_count(int width, int height, int pitch)
b8976b
		{ return width + abs(pitch)*(height - 1); }
b8976b
	static inline size_t data_size(int width, int height, int pitch)
b8976b
		{ return data_count(width, height, pitch)*sizeof(Color); }
b8976b
	static inline int begin_offset(int width, int height, int pitch)
b8976b
		{ return pitch > 0 ? 0 : width - data_count(width, height, pitch); }
b8976b
	static inline int end_offset(int width, int height, int pitch)
b8976b
		{ return pitch > 0 ? data_count(width, height, pitch) : width; }
b8976b
b8976b
	static void copy(int width, int height, const Color *src_origin, Color *dest_origin, int src_pitch = 0, int dest_pitch = 0);
b8976b
	
b8976b
	Glib::RefPtr<gdk::pixbuf> to_pixbuf() const;</gdk::pixbuf>
b8976b
	Cairo::RefPtr<cairo::imagesurface> to_cairo_surface(bool premulted = false) const;</cairo::imagesurface>
b8976b
};
b8976b
b8976b
b8976b
class DataSurface: public Surface {
b8976b
public:
b8976b
	explicit DataSurface(int width = 0, int height = 0, int pitch = 0, const Color *src_origin = NULL, int src_pitch = 0)
b8976b
		{ init(width, height, pitch, src_origin, src_pitch); }
b8976b
	DataSurface(const Surface &other)
b8976b
		{ *this = other; }
b8976b
	~DataSurface()
b8976b
		{ clear(); }
b8976b
	DataSurface& operator= (const Surface &other)
b8976b
		{ init(other); return *this; }
b8976b
	
b8976b
	void clear();
b8976b
	void init(int width, int height, int pitch = 0, const Color *src_origin = NULL, int src_pitch = 0);
b8976b
	inline void init(const Surface &other)
b8976b
		{ init(other.width(), other.height(), other.pitch(), other.origin(), other.pitch()); }
b8976b
};
b8976b
b8976b
b8976b
class AliasSurface: public Surface {
b8976b
public:
b8976b
	AliasSurface() { }
b8976b
	AliasSurface(Color *origin, int width, int height, int pitch = 0)
b8976b
		{ init(origin, width, height, pitch); }
b8976b
	AliasSurface(const AliasSurface &other)
b8976b
		{ *this = other; }
b8976b
	AliasSurface(Surface &other)
b8976b
		{ init(other); }
b8976b
	AliasSurface& operator= (const AliasSurface &other)
b8976b
		{ init(other); return *this; }
b8976b
	
b8976b
	inline Color* origin() const { return m_origin; }
b8976b
	
b8976b
	void init(Color *origin, int width, int height, int pitch = 0);
b8976b
b8976b
	inline void clear() { reset(); }
b8976b
	inline void init(Surface &other)
b8976b
		{ init(other.origin(), other.width(), other.height(), other.pitch()); }
b8976b
	inline void init(const AliasSurface &other)
b8976b
		{ init(other.origin(), other.width(), other.height(), other.pitch()); }
b8976b
};
b8976b
b8976b
b8976b
#endif