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 gst_smpte_paint_vbox (guint32 *dest, gint stride,
30 gint x0, gint y0, gint c0,
31 gint x1, gint y1, gint c1)
40 g_assert (height > 0);
42 dest = dest + y0 * stride + x0;
44 for (i = 0; i < height; i++) {
45 for (j = 0; j < width; j++) {
46 dest[j] = (c1 * j + c0 * (width - j)) / width;
53 gst_smpte_paint_hbox (guint32 *dest, gint stride,
54 gint x0, gint y0, gint c0,
55 gint x1, gint y1, gint c1)
64 g_assert (height > 0);
66 g_print ("vbox: %d %d %d %d %d %d\n", x0, y0, c0, x1, y1, c1);
68 dest = dest + y0 * stride + x0;
70 for (i = 0; i < height; i++) {
71 guint32 value = (c1 * i + c0 * (height - i)) / height;
72 for (j = 0; j < width; j++) {
79 #define STEP_3D_LINE(dxabs,dyabs,dzabs,sdx,sdy,sdz,xr,yr,zr,px,py,pz) \
81 if (dxabs >= dyabs && dxabs >= dzabs) { \
93 } else if (dyabs >= dxabs && dyabs >= dzabs) { \
120 #define SWAP_INT(a,b) \
128 #define SIGN(a) ((a) < 0 ? -1 : 1)
130 #define PREPARE_3D_LINE(x0,y0,z0,x1,y1,z1,dxabs,dyabs,dzabs,sdx,sdy,sdz,xr,yr,zr,px,py,pz)\
151 gst_smpte_paint_triangle_linear (guint32 *dest, gint stride,
152 gint x0, gint y0, gint c0,
153 gint x1, gint y1, gint c1, gint x2, gint y2, gint c2)
155 gint sdxl, sdyl, sdcl, dxlabs, dylabs, dclabs, xrl, yrl, crl, pxl, pyl, pcl;
156 gint sdxr, sdyr, sdcr, dxrabs, dyrabs, dcrabs, xrr, yrr, crr, pxr, pyr, pcr;
157 gint i, j, k, seg_start, seg_end;
159 if (y0 > y1) { SWAP_INT (x0, x1); SWAP_INT (y0, y1); SWAP_INT (c0, c1); }
160 if (y0 > y2) { SWAP_INT (x0, x2); SWAP_INT (y0, y2); SWAP_INT (c0, c2); }
161 if (y1 > y2) { SWAP_INT (x1, x2); SWAP_INT (y1, y2); SWAP_INT (c1, c2); }
163 PREPARE_3D_LINE (x0,y0,c0,x2,y2,c2,
164 dxlabs,dylabs,dclabs,
169 PREPARE_3D_LINE (x0,y0,c0,x1,y1,c1,
170 dxrabs,dyrabs,dcrabs,
175 dest = dest + stride * y0;
180 for (k = 0; k < 2; k++) {
181 for (i = seg_start; i < seg_end; i++) {
182 gint s = pxl, e = pxr, sc = pcl, ec = pcr;
183 gint sign = SIGN (e - s);
186 for (j = s; j != e; j+=sign) {
187 dest[j] = (ec * (j - s) + sc * (e - j)) / (e - s);
191 STEP_3D_LINE (dxrabs, dyrabs, dcrabs, sdxr, sdyr, sdcr,
192 xrr, yrr, crr, pxr, pyr, pcr);
195 STEP_3D_LINE (dxlabs, dylabs, dclabs, sdxl, sdyl, sdcl,
196 xrl, yrl, crl, pxl, pyl, pcl);
201 PREPARE_3D_LINE (x1,y1,c1,x2,y2,c2,
202 dxrabs,dyrabs,dcrabs,
213 draw_bresenham_line (guint32 *dest, gint stride,
218 gint dx = abs (x1 - x0);
219 gint dy = abs (y1 - y0);
221 gint i, dpr, dpru, P, indep;
223 dest = dest + y0 * stride + x0;
225 x_incr = SIGN (x1 - x0);
226 y_incr = SIGN (y1 - y0) * stride;
239 dpru = dpr - (i << 1);
242 for (; i >= 0; i--) {
257 gst_smpte_paint_triangle_clock (guint32 *dest, gint stride,
258 gint x0, gint y0, gint c0,
259 gint x1, gint y1, gint c1,
260 gint x2, gint y2, gint c2)
264 gfloat angle, angle_s, angle_e;
268 angle_e = acos (((x1-x0) * (x2-x0) + (y1-y0) * (y2-y0))/
269 (sqrt ((x1-x0) * (x1-x0) + (y1-y0) * (y1-y0)) *
270 sqrt ((x2-x0) * (x2-x0) + (y2-y0) * (y2-y0))));
272 len1 = sqrt ((x1-x0) * (x1-x0) + (y1-y0) * (y1-y0));
275 sign = SIGN (y2 - y1);
277 for (i = y1; i != (y2 + sign); i += sign) {
281 angle = acos (((x1-x0) * (x2-x0) + (y1-y0) * (i-y0)) /
282 (len1 * sqrt ((x1-x0) * (x1-x0) + (i-y0) * (i-y0)))) / angle_e;
284 draw_bresenham_line (dest, stride,
286 (c2 * angle + c1 * (1.0-angle)));
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-y0)))) / angle_e;
299 draw_bresenham_line (dest, stride,
301 (c2 * angle + c1 * (1.0-angle)));
307 gst_smpte_paint_box_clock (guint32 *dest, gint stride,
308 gint x0, gint y0, gint c0,
309 gint x1, gint y1, gint c1,
310 gint x2, gint y2, gint c2)
312 gfloat angle_m, col_m;
318 } else if (y1 == y0) {
323 g_warning ("paint box clock: not supported");
327 angle_m = 2 * acos (((x1-x0) * (xv-x0) + (y1-y0) * (yv-y0))/
328 (sqrt ((x1-x0) * (x1-x0) + (y1-y0) * (y1-y0)) *
329 sqrt ((xv-x0) * (xv-x0) + (yv-y0) * (yv-y0)))) / M_PI;
331 col_m = c2 * angle_m + c1 * (1.0-angle_m);
333 gst_smpte_paint_triangle_clock (dest, stride,
337 gst_smpte_paint_triangle_clock (dest, stride,