{
guint32 *maskp;
gint value;
- gint i;
+ gint i, j;
gint min, max;
guint8 *in1u, *in1v, *in2u, *in2v, *outu, *outv;
gint lumsize = width * height;
min = pos - border;
max = pos;
- in1u = in1 + lumsize; in1v = in1 + chromsize;
- in2u = in2 + lumsize; in2v = in2 + chromsize;
- outu = out + lumsize; outv = out + chromsize;
+ in1u = in1 + lumsize; in1v = in1u + chromsize;
+ in2u = in2 + lumsize; in2v = in2u + chromsize;
+ outu = out + lumsize; outv = outu + chromsize;
maskp = mask->data;
- for (i = lumsize; i; i--) {
- value = *maskp++;
- value = ((CLAMP (value, min, max) - min) << 8) / border;
+ for (i = 0; i < height; i++) {
+ for (j = 0; j < width; j++) {
+ value = *maskp++;
+ value = ((CLAMP (value, min, max) - min) << 8) / border;
- *out++ = ((*in1++ * value) + (*in2++ * (255 - value))) >> 8;
- if (i % 4) {
- *outu++ = ((*in1u++ * value) + (*in2u++ * (255 - value))) >> 8;
- *outv++ = ((*in1v++ * value) + (*in2v++ * (255 - value))) >> 8;
+ *out++ = ((*in1++ * value) + (*in2++ * (256 - value))) >> 8;
+ if (!(i & 1) && !(j & 1)) {
+ *outu++ = ((*in1u++ * value) + (*in2u++ * (256 - value))) >> 8;
+ *outv++ = ((*in1v++ * value) + (*in2v++ * (256 - value))) >> 8;
+ }
}
}
}
}
}
-
-void
-draw_line (guint32* dest, gint stride, int x, int y, int x2, int y2, int col)
+static void
+draw_bresenham_line (guint32 *dest, gint stride,
+ gint x0, gint y0,
+ gint x1, gint y1,
+ guint32 col)
{
- gboolean yLonger=FALSE;
- int incrementVal, endVal;
- gdouble decInc;
- int shortLen=y2-y;
- int longLen=x2-x;
- gdouble j=0.0;
- int i;
-
- if (abs(shortLen)>abs(longLen)) {
- int swap=shortLen;
- shortLen=longLen;
- longLen=swap;
- yLonger=TRUE;
+ gint dx = abs (x1 - x0);
+ gint dy = abs (y1 - y0);
+ gint x_incr, y_incr;
+ gint i, dpr, dpru, P, indep;
+
+ dest = dest + y0 * stride + x0;
+
+ x_incr = SIGN (x1 - x0);
+ y_incr = SIGN (y1 - y0) * stride;
+
+ if (dx >= dy) {
+ dpr = dy << 1;
+ i = dx;
+ indep = x_incr;
+ }
+ else {
+ dpr = dx << 1;
+ i = dy;
+ indep = y_incr;
}
- endVal=longLen;
- if (longLen<0) {
- incrementVal=-1;
- longLen=-longLen;
- }
- else incrementVal=1;
-
- if (longLen==0) decInc=(gdouble)shortLen;
- else decInc = ((gdouble)shortLen/(gdouble)longLen);
-
- if (yLonger) {
- for (i=0;i!=endVal;i+=incrementVal) {
- *(dest+(x+(int)j) + (y+i)*stride) = col;
- j+=decInc;
- }
- } else {
- for (i=0;i!=endVal;i+=incrementVal) {
- *(dest+(x+i) + (y+(int)j)*stride) = col;
- j+=decInc;
+ dpru = dpr - (i << 1);
+ P = dpr - i;
+
+ for (; i >= 0; i--) {
+ *dest = col;
+
+ if (P > 0) {
+ dest += x_incr;
+ dest += y_incr;
+ P += dpru;
+ } else {
+ dest += indep;
+ P += dpr;
}
}
}
gint i;
gint sign;
gfloat angle, angle_s, angle_e;
+ gfloat len1;
angle_s = 0.0;
angle_e = acos (((x1-x0) * (x2-x0) + (y1-y0) * (y2-y0))/
(sqrt ((x1-x0) * (x1-x0) + (y1-y0) * (y1-y0)) *
sqrt ((x2-x0) * (x2-x0) + (y2-y0) * (y2-y0))));
- if (x1 == x2) {
- gfloat len1 = sqrt ((x1-x0) * (x1-x0) + (y1-y0) * (y1-y0));
+ len1 = sqrt ((x1-x0) * (x1-x0) + (y1-y0) * (y1-y0));
+ if (x1 == x2) {
sign = SIGN (y2 - y1);
- for (i=y1; i != y2+sign; i+=sign) {
- gfloat len2 = sqrt ((x1-x0) * (x1-x0) + (i-y0) * (i-y0));
-
- if (y1==i)
+ for (i = y1; i != (y2 + sign); i += sign) {
+ if (y1 == i)
angle = 0;
else
- angle = acos (((x1-x0) * (x2-x0) + (y1-y0) * (i-y0))/ (len1 * len2)) / angle_e;
+ angle = acos (((x1-x0) * (x2-x0) + (y1-y0) * (i-y0)) /
+ (len1 * sqrt ((x1-x0) * (x1-x0) + (i-y0) * (i-y0)))) / angle_e;
- draw_line (dest, stride,
+ draw_bresenham_line (dest, stride,
x0, y0, x1, i,
(c2 * angle + c1 * (1.0-angle)));
}
}
else if (y1 == y2) {
- gfloat len1 = sqrt ((x1-x0) * (x1-x0) + (y1-y0) * (y1-y0));
-
sign = SIGN (x2 - x1);
- for (i=x1; i != x2+sign; i+=sign) {
- gfloat len2 = sqrt ((i-x0) * (i-x0) + (y2-y0) * (y2-y0));
-
- if (x1==i)
+ for (i = x1; i != (x2 + sign); i += sign) {
+ if (x1 == i)
angle = 0;
else
- angle = acos (((x1-x0) * (i-x0) + (y1-y0) * (y2-y0)) / (len1 * len2)) / angle_e;
+ angle = acos (((x1-x0) * (i-x0) + (y1-y0) * (y2-y0)) /
+ (len1 * sqrt ((i-x0) * (i-x0) + (y2-y0) * (y2-y0)))) / angle_e;
- draw_line (dest, stride,
+ draw_bresenham_line (dest, stride,
x0, y0, i, y1,
(c2 * angle + c1 * (1.0-angle)));
}
gint x1, gint y1, gint c1,
gint x2, gint y2, gint c2)
{
- gfloat angle_m;
+ gfloat angle_m, col_m;
+ gint xv, yv;
+
+ if (x1 == x0) {
+ xv = x2;
+ yv = y1;
+ } else if (y1 == y0) {
+ xv = x1;
+ yv = y2;
+ }
+ else {
+ g_warning ("paint box clock: not supported");
+ return;
+ }
- if (x1 == x0) {
- angle_m = 2* acos (((x1-x0) * (x2-x0) + (y1-y0) * (y1-y0))/
+ angle_m = 2 * acos (((x1-x0) * (xv-x0) + (y1-y0) * (yv-y0))/
(sqrt ((x1-x0) * (x1-x0) + (y1-y0) * (y1-y0)) *
- sqrt ((x2-x0) * (x2-x0) + (y1-y0) * (y1-y0)))) / M_PI;
+ sqrt ((xv-x0) * (xv-x0) + (yv-y0) * (yv-y0)))) / M_PI;
- gst_smpte_paint_triangle_clock (dest, stride,
- x0, y0, c0,
- x1, y1, c1,
- x2, y1, (c2 * angle_m + c1 * (1.0-angle_m)));
- gst_smpte_paint_triangle_clock (dest, stride,
- x0, y0, c0,
- x2, y1, (c2 * angle_m + c1 * (1.0-angle_m)),
- x2, y2, c2);
- }
- else if (y1 == y0) {
- angle_m = 2* acos (((x1-x0) * (x1-x0) + (y1-y0) * (y2-y0))/
- (sqrt ((x1-x0) * (x1-x0) + (y1-y0) * (y1-y0)) *
- sqrt ((x1-x0) * (x1-x0) + (y2-y0) * (y2-y0)))) / M_PI;
+ col_m = c2 * angle_m + c1 * (1.0-angle_m);
- gst_smpte_paint_triangle_clock (dest, stride,
+ gst_smpte_paint_triangle_clock (dest, stride,
x0, y0, c0,
x1, y1, c1,
- x1, y2, (c2 * angle_m + c1 * (1.0-angle_m)));
- gst_smpte_paint_triangle_clock (dest, stride,
+ xv, yv, col_m);
+ gst_smpte_paint_triangle_clock (dest, stride,
x0, y0, c0,
- x1, y2, (c2 * angle_m + c1 * (1.0-angle_m)),
+ xv, yv, col_m,
x2, y2, c2);
- }
}