2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
29 #define M_PI 3.14159265358979323846
33 gst_smpte_paint_vbox (guint32 * dest, gint stride,
34 gint x0, gint y0, gint c0, gint x1, gint y1, gint c1)
43 g_assert (height > 0);
45 dest = dest + y0 * stride + x0;
47 for (i = 0; i < height; i++) {
48 for (j = 0; j < width; j++) {
49 dest[j] = (c1 * j + c0 * (width - j)) / width;
56 gst_smpte_paint_hbox (guint32 * dest, gint stride,
57 gint x0, gint y0, gint c0, gint x1, gint y1, gint c1)
66 g_assert (height > 0);
68 dest = dest + y0 * stride + x0;
70 for (i = 0; i < height; i++) {
71 guint32 value = (c1 * i + c0 * (height - i)) / height;
73 for (j = 0; j < width; j++) {
80 #define STEP_3D_LINE(dxabs,dyabs,dzabs,sdx,sdy,sdz,xr,yr,zr,px,py,pz) \
82 if (dxabs >= dyabs && dxabs >= dzabs) { \
94 } else if (dyabs >= dxabs && dyabs >= dzabs) { \
121 #define SWAP_INT(a,b) \
129 #define SIGN(a) ((a) < 0 ? -1 : 1)
131 #define PREPARE_3D_LINE(x0,y0,z0,x1,y1,z1,dxabs,dyabs,dzabs,sdx,sdy,sdz,xr,yr,zr,px,py,pz)\
152 gst_smpte_paint_triangle_linear (guint32 * dest, gint stride,
153 gint x0, gint y0, gint c0,
154 gint x1, gint y1, gint c1, gint x2, gint y2, gint c2)
156 gint sdxl, sdyl, sdcl, dxlabs, dylabs, dclabs, xrl, yrl, crl, pxl, pyl, pcl;
157 gint sdxr, sdyr, sdcr, dxrabs, dyrabs, dcrabs, xrr, yrr, crr, pxr, pyr, pcr;
158 gint i, j, k, seg_start, seg_end;
176 PREPARE_3D_LINE (x0, y0, c0, x2, y2, c2,
177 dxlabs, dylabs, dclabs, sdxl, sdyl, sdcl, xrl, yrl, crl, pxl, pyl, pcl);
179 PREPARE_3D_LINE (x0, y0, c0, x1, y1, c1,
180 dxrabs, dyrabs, dcrabs, sdxr, sdyr, sdcr, xrr, yrr, crr, pxr, pyr, pcr);
182 dest = dest + stride * y0;
187 for (k = 0; k < 2; k++) {
188 for (i = seg_start; i < seg_end; i++) {
189 gint s = pxl, e = pxr, sc = pcl, ec = pcr;
190 gint sign = SIGN (e - s);
193 for (j = s; j != e; j += sign) {
194 dest[j] = (ec * (j - s) + sc * (e - j)) / (e - s);
198 STEP_3D_LINE (dxrabs, dyrabs, dcrabs, sdxr, sdyr, sdcr,
199 xrr, yrr, crr, pxr, pyr, pcr);
202 STEP_3D_LINE (dxlabs, dylabs, dclabs, sdxl, sdyl, sdcl,
203 xrl, yrl, crl, pxl, pyl, pcl);
208 PREPARE_3D_LINE (x1, y1, c1, x2, y2, c2,
209 dxrabs, dyrabs, dcrabs, sdxr, sdyr, sdcr, xrr, yrr, crr, pxr, pyr, pcr);
217 draw_bresenham_line (guint32 * dest, gint stride,
218 gint x0, gint y0, gint x1, gint y1, guint32 col)
222 gint i, dpr, dpru, P, indep;
227 dest = dest + y0 * stride + x0;
229 x_incr = SIGN (x1 - x0);
230 y_incr = SIGN (y1 - y0) * stride;
242 dpru = dpr - (i << 1);
245 for (; i >= 0; i--) {
260 gst_smpte_paint_triangle_clock (guint32 * dest, gint stride,
261 gint x0, gint y0, gint c0,
262 gint x1, gint y1, gint c1, gint x2, gint y2, gint c2)
266 gfloat angle, angle_e;
269 angle_e = acos (((x1 - x0) * (x2 - x0) + (y1 - y0) * (y2 - y0)) /
270 (sqrt ((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)) *
271 sqrt ((x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0))));
273 len1 = sqrt ((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
276 sign = SIGN (y2 - y1);
278 for (i = y1; i != (y2 + sign); i += sign) {
282 angle = acos (((x1 - x0) * (x2 - x0) + (y1 - y0) * (i - y0)) /
283 (len1 * sqrt ((x1 - x0) * (x1 - x0) + (i - y0) * (i -
286 draw_bresenham_line (dest, stride,
287 x0, y0, x1, i, (c2 * angle + c1 * (1.0 - angle)));
289 } else if (y1 == y2) {
290 sign = SIGN (x2 - x1);
292 for (i = x1; i != (x2 + sign); i += sign) {
296 angle = acos (((x1 - x0) * (i - x0) + (y1 - y0) * (y2 - y0)) /
297 (len1 * sqrt ((i - x0) * (i - x0) + (y2 - y0) * (y2 -
300 draw_bresenham_line (dest, stride,
301 x0, y0, i, y1, (c2 * angle + c1 * (1.0 - angle)));
304 g_warning ("paint triangle clock: not supported");
310 gst_smpte_paint_box_clock (guint32 * dest, gint stride,
311 gint x0, gint y0, gint c0,
312 gint x1, gint y1, gint c1, gint x2, gint y2, gint c2)
314 gfloat angle_m, col_m;
320 } else if (y1 == y0) {
324 g_warning ("paint box clock: not supported");
328 angle_m = 2 * acos (((x1 - x0) * (xv - x0) + (y1 - y0) * (yv - y0)) /
329 (sqrt ((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)) *
330 sqrt ((xv - x0) * (xv - x0) + (yv - y0) * (yv - y0)))) / M_PI;
332 col_m = c2 * angle_m + c1 * (1.0 - angle_m);
334 gst_smpte_paint_triangle_clock (dest, stride,
335 x0, y0, c0, x1, y1, c1, xv, yv, col_m);
336 gst_smpte_paint_triangle_clock (dest, stride,
337 x0, y0, c0, xv, yv, col_m, x2, y2, c2);