2 * Copyright (C) <2011> Stefan Sauer <ensonic@users.sf.net>
4 * gstdrawhelpers.h: simple drawing helpers
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 /* FIXME: add versions that don't ignore alpha */
23 #define draw_dot(_vd, _x, _y, _st, _c) G_STMT_START { \
24 _vd[(_y * _st) + _x] = _c; \
27 #define draw_dot_c(_vd, _x, _y, _st, _c) G_STMT_START { \
28 _vd[(_y * _st) + _x] |= _c; \
31 #define draw_dot_aa(_vd, _x, _y, _st, _c, _f) G_STMT_START { \
32 guint32 _oc, _c1, _c2, _c3; \
34 _oc = _vd[(_y * _st) + _x]; \
35 _c3 = (_oc & 0xff) + ((_c & 0xff) * _f); \
36 _c3 = MIN(_c3, 255); \
37 _c2 = ((_oc & 0xff00) >> 8) + (((_c & 0xff00) >> 8) * _f); \
38 _c2 = MIN(_c2, 255); \
39 _c1 = ((_oc & 0xff0000) >> 16) + (((_c & 0xff0000) >> 16) * _f); \
40 _c1 = MIN(_c1, 255); \
41 _vd[(_y * _st) + _x] = (_c1 << 16) | (_c2 << 8) | _c3; \
44 #define draw_line(_vd, _x1, _x2, _y1, _y2, _st, _c) G_STMT_START { \
45 guint _i, _j, _x, _y; \
46 gint _dx = _x2 - _x1, _dy = _y2 - _y1; \
49 _j = abs (_dx) > abs (_dy) ? abs (_dx) : abs (_dy); \
50 for (_i = 0; _i < _j; _i++) { \
51 _f = (gfloat) _i / (gfloat) _j; \
52 _x = _x1 + _dx * _f; \
53 _y = _y1 + _dy * _f; \
54 draw_dot (_vd, _x, _y, _st, _c); \
58 #define draw_line_aa(_vd, _x1, _x2, _y1, _y2, _st, _c) G_STMT_START { \
59 guint _i, _j, _x, _y; \
60 gint _dx = _x2 - _x1, _dy = _y2 - _y1; \
61 gfloat _f, _rx, _ry, _fx, _fy; \
63 _j = abs (_dx) > abs (_dy) ? abs (_dx) : abs (_dy); \
64 for (_i = 0; _i < _j; _i++) { \
65 _f = (gfloat) _i / (gfloat) _j; \
66 _rx = _x1 + _dx * _f; \
67 _ry = _y1 + _dy * _f; \
70 _fx = _rx - (gfloat)_x; \
71 _fy = _ry - (gfloat)_y; \
73 _f = ((1.0 - _fx) + (1.0 - _fy)) / 2.0; \
74 draw_dot_aa (_vd, _x, _y, _st, _c, _f); \
76 _f = (_fx + (1.0 - _fy)) / 2.0; \
77 draw_dot_aa (_vd, (_x + 1), _y, _st, _c, _f); \
79 _f = ((1.0 - _fx) + _fy) / 2.0; \
80 draw_dot_aa (_vd, _x, (_y + 1), _st, _c, _f); \
82 _f = (_fx + _fy) / 2.0; \
83 draw_dot_aa (_vd, (_x + 1), (_y + 1), _st, _c, _f); \