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, gint x1, gint y1, gint c1)
39 g_assert (height > 0);
41 dest = dest + y0 * stride + x0;
43 for (i = 0; i < height; i++) {
44 for (j = 0; j < width; j++) {
45 dest[j] = (c1 * j + c0 * (width - j)) / width;
52 gst_smpte_paint_hbox (guint32 * dest, gint stride,
53 gint x0, gint y0, gint c0, gint x1, gint y1, gint c1)
62 g_assert (height > 0);
64 g_print ("vbox: %d %d %d %d %d %d\n", x0, y0, c0, x1, y1, c1);
66 dest = dest + y0 * stride + x0;
68 for (i = 0; i < height; i++) {
69 guint32 value = (c1 * i + c0 * (height - i)) / height;
71 for (j = 0; j < width; j++) {
78 #define STEP_3D_LINE(dxabs,dyabs,dzabs,sdx,sdy,sdz,xr,yr,zr,px,py,pz) \
80 if (dxabs >= dyabs && dxabs >= dzabs) { \
92 } else if (dyabs >= dxabs && dyabs >= dzabs) { \
119 #define SWAP_INT(a,b) \
127 #define SIGN(a) ((a) < 0 ? -1 : 1)
129 #define PREPARE_3D_LINE(x0,y0,z0,x1,y1,z1,dxabs,dyabs,dzabs,sdx,sdy,sdz,xr,yr,zr,px,py,pz)\
150 gst_smpte_paint_triangle_linear (guint32 * dest, gint stride,
151 gint x0, gint y0, gint c0,
152 gint x1, gint y1, gint c1, gint x2, gint y2, gint c2)
154 gint sdxl, sdyl, sdcl, dxlabs, dylabs, dclabs, xrl, yrl, crl, pxl, pyl, pcl;
155 gint sdxr, sdyr, sdcr, dxrabs, dyrabs, dcrabs, xrr, yrr, crr, pxr, pyr, pcr;
156 gint i, j, k, seg_start, seg_end;
174 PREPARE_3D_LINE (x0, y0, c0, x2, y2, c2,
175 dxlabs, dylabs, dclabs, sdxl, sdyl, sdcl, xrl, yrl, crl, pxl, pyl, pcl);
177 PREPARE_3D_LINE (x0, y0, c0, x1, y1, c1,
178 dxrabs, dyrabs, dcrabs, sdxr, sdyr, sdcr, xrr, yrr, crr, pxr, pyr, pcr);
180 dest = dest + stride * y0;
185 for (k = 0; k < 2; k++) {
186 for (i = seg_start; i < seg_end; i++) {
187 gint s = pxl, e = pxr, sc = pcl, ec = pcr;
188 gint sign = SIGN (e - s);
191 for (j = s; j != e; j += sign) {
192 dest[j] = (ec * (j - s) + sc * (e - j)) / (e - s);
196 STEP_3D_LINE (dxrabs, dyrabs, dcrabs, sdxr, sdyr, sdcr,
197 xrr, yrr, crr, pxr, pyr, pcr);
200 STEP_3D_LINE (dxlabs, dylabs, dclabs, sdxl, sdyl, sdcl,
201 xrl, yrl, crl, pxl, pyl, pcl);
206 PREPARE_3D_LINE (x1, y1, c1, x2, y2, c2,
207 dxrabs, dyrabs, dcrabs, sdxr, sdyr, sdcr, xrr, yrr, crr, pxr, pyr, pcr);
215 draw_bresenham_line (guint32 * dest, gint stride,
216 gint x0, gint y0, gint x1, gint y1, guint32 col)
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;
238 dpru = dpr - (i << 1);
241 for (; i >= 0; i--) {
256 gst_smpte_paint_triangle_clock (guint32 * dest, gint stride,
257 gint x0, gint y0, gint c0,
258 gint x1, gint y1, gint c1, gint x2, gint y2, gint c2)
262 gfloat angle, angle_s, angle_e;
266 angle_e = acos (((x1 - x0) * (x2 - x0) + (y1 - y0) * (y2 - y0)) /
267 (sqrt ((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)) *
268 sqrt ((x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0))));
270 len1 = sqrt ((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
273 sign = SIGN (y2 - y1);
275 for (i = y1; i != (y2 + sign); i += sign) {
279 angle = acos (((x1 - x0) * (x2 - x0) + (y1 - y0) * (i - y0)) /
280 (len1 * sqrt ((x1 - x0) * (x1 - x0) + (i - y0) * (i -
283 draw_bresenham_line (dest, stride,
284 x0, y0, x1, i, (c2 * angle + c1 * (1.0 - angle)));
286 } else if (y1 == y2) {
287 sign = SIGN (x2 - x1);
289 for (i = x1; i != (x2 + sign); i += sign) {
293 angle = acos (((x1 - x0) * (i - x0) + (y1 - y0) * (y2 - y0)) /
294 (len1 * sqrt ((i - x0) * (i - x0) + (y2 - y0) * (y2 -
297 draw_bresenham_line (dest, stride,
298 x0, y0, i, y1, (c2 * angle + c1 * (1.0 - angle)));
304 gst_smpte_paint_box_clock (guint32 * dest, gint stride,
305 gint x0, gint y0, gint c0,
306 gint x1, gint y1, gint c1, gint x2, gint y2, gint c2)
308 gfloat angle_m, col_m;
314 } else if (y1 == y0) {
318 g_warning ("paint box clock: not supported");
322 angle_m = 2 * acos (((x1 - x0) * (xv - x0) + (y1 - y0) * (yv - y0)) /
323 (sqrt ((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)) *
324 sqrt ((xv - x0) * (xv - x0) + (yv - y0) * (yv - y0)))) / M_PI;
326 col_m = c2 * angle_m + c1 * (1.0 - angle_m);
328 gst_smpte_paint_triangle_clock (dest, stride,
329 x0, y0, c0, x1, y1, c1, xv, yv, col_m);
330 gst_smpte_paint_triangle_clock (dest, stride,
331 x0, y0, c0, xv, yv, col_m, x2, y2, c2);