third_party/cairo/src/cairo-mesh-pattern-rasterizer.c
static inline void
rasterize_bezier_patch (unsigned char *data, int width, int height, int stride, int vshift,
			cairo_point_double_t p[4][4], double col[4][4])
{
    double pv[4][2][4], cstart[4], cend[4], dcstart[4], dcend[4];
    int v, i, k;

    v = 1 << vshift;

    /*
     * pv[i][0] is the function (represented using forward
     * differences) mapping v to the x coordinate of the i-th node of
     * the Bezier curve with parameter u.
     * (Likewise p[i][0] gives the y coordinate).
     *
     * This means that (pv[0][0][0],pv[0][1][0]),
     * (pv[1][0][0],pv[1][1][0]), (pv[2][0][0],pv[2][1][0]) and
     * (pv[3][0][0],pv[3][1][0]) are the nodes of the Bezier curve for
     * the "current" v value (see the FD comments for more details).
     */
    for (i = 0; i < 4; ++i) {
	fd_init (p[i][0].x, p[i][1].x, p[i][2].x, p[i][3].x, pv[i][0]);
	fd_init (p[i][0].y, p[i][1].y, p[i][2].y, p[i][3].y, pv[i][1]);
	for (k = 0; k < vshift; ++k) {
	    fd_down (pv[i][0]);
	    fd_down (pv[i][1]);
	}
    }

    for (i = 0; i < 4; ++i) {
	cstart[i]  = col[0][i];
	cend[i]    = col[1][i];
	dcstart[i] = (col[2][i] - col[0][i]) / v;
	dcend[i]   = (col[3][i] - col[1][i]) / v;
    }

    v++;
    while (v--) {
	cairo_point_double_t nodes[4];
	for (i = 0; i < 4; ++i) {
	    nodes[i].x = pv[i][0][0];
	    nodes[i].y = pv[i][1][0];
	}

	draw_bezier_curve (data, width, height, stride, nodes, cstart, cend);

	for (i = 0; i < 4; ++i) {
	    fd_fwd (pv[i][0]);
	    fd_fwd (pv[i][1]);
	    cstart[i] += dcstart[i];
	    cend[i] += dcend[i];
	}
    }
}
/*
 * Forward-rasterize a cubic Bezier patch using forward differences.
 *
 * Input: data is the base pointer of the image
 *        width, height are the dimensions of the image
 *        stride is the stride in bytes between adjacent rows
 *        vshift is log2(n) if n is the number of desired steps
 *        p[i][j], p[i][j] are the the nodes of the Bezier patch
 *        col[i][j] is the j-th color component of the i-th corner
 *
 * Output: data will be changed to have the requested patch drawn in
 *         the specified colors
 *
 * The nodes of the patch are as follows:
 *
 * u\v 0    - >    1
 * 0  p00 p01 p02 p03
 * |  p10 p11 p12 p13
 * v  p20 p21 p22 p23
 * 1  p30 p31 p32 p33
 *
 * i.e. u varies along the first component (rows), v varies along the
 * second one (columns).
 *
 * The color components are red, green, blue and alpha, in this order.
 * c[0..3] are the colors in p00, p30, p03, p33 respectively
 *
 * The input color components are not premultiplied, but the data
 * stored in the image is assumed to be in CAIRO_FORMAT_ARGB32 (8 bpc,
 * premultiplied).
 *
 * If the patch folds over itself, the part with the highest v
 * parameter is considered above. If both have the same v, the one
 * with the highest u parameter is above.
 *
 * The function draws n+1 curves, that is from the curve at step 0 to
 * the curve at step n, both included. This is the discrete equivalent
 * to drawing the patch for values of the interpolation parameter in
 * [0,1] (including both extremes).
 */
Forward-rasterize a cubic Bezier patch using forward differences.
Input: data is the base pointer of the image
width, height are the dimensions of the image
stride is the stride in bytes between adjacent rows
vshift is log2(n) if n is the number of desired steps
p[i][j], p[i][j] are the the nodes of the Bezier patch
col[i][j] is the j-th color component of the i-th corner

data will be changed to have the requested patch drawn in
the specified colors

The nodes of the patch are as follows.





The color components are red, green, blue and alpha, in this order.

The input color components are not premultiplied, but the data
stored in the image is assumed to be in CAIRO_FORMAT_ARGB32 (8 bpc,
premultiplied).

If the patch folds over itself, the part with the highest v
parameter is considered above. If both have the same v, the one
with the highest u parameter is above.

The function draws n+1 curves, that is from the curve at step 0 to
the curve at step n, both included. This is the discrete equivalent
to drawing the patch for values of the interpolation parameter in
[0,1] (including both extremes).
Forward - rasterize a cubic Bezier patch using forward differences . Input : data is the base pointer of the image width height are the dimensions of the image stride is the stride in bytes between adjacent rows vshift is log2 ( n ) if n is the number of desired steps p [ i ] [ j ] p [ i ] [ j ] are the the nodes of the Bezier patch col [ i ] [ j ] is the j - th color component of the i - th corner data will be changed to have the requested patch drawn in the specified colors The nodes of the patch are as follows . The color components are red green blue and alpha in this order . The input color components are not premultiplied but the data stored in the image is assumed to be in CAIRO_FORMAT_ARGB32 ( 8 bpc premultiplied ) . If the patch folds over itself the part with the highest v parameter is considered above . If both have the same v the one with the highest u parameter is above . The function draws n + 1 curves that is from the curve at step 0 to the curve at step n both included . This is the discrete equivalent to drawing the patch for values of the interpolation parameter in [ 0 1 ] ( including both extremes ) .
static inline void
rasterize_bezier_patch (unsigned char *data, int width, int height, int stride, int vshift,
			cairo_point_double_t p[4][4], double col[4][4])
{
    double pv[4][2][4], cstart[4], cend[4], dcstart[4], dcend[4];
    int v, i, k;
    v = 1 << vshift;
    for (i = 0; i < 4; ++i) {
	fd_init (p[i][0].x, p[i][1].x, p[i][2].x, p[i][3].x, pv[i][0]);
	fd_init (p[i][0].y, p[i][1].y, p[i][2].y, p[i][3].y, pv[i][1]);
	for (k = 0; k < vshift; ++k) {
	    fd_down (pv[i][0]);
	    fd_down (pv[i][1]);
	}
    }
    for (i = 0; i < 4; ++i) {
	cstart[i]  = col[0][i];
	cend[i]    = col[1][i];
	dcstart[i] = (col[2][i] - col[0][i]) / v;
	dcend[i]   = (col[3][i] - col[1][i]) / v;
    }
    v++;
    while (v--) {
	cairo_point_double_t nodes[4];
	for (i = 0; i < 4; ++i) {
	    nodes[i].x = pv[i][0][0];
	    nodes[i].y = pv[i][1][0];
	}
	draw_bezier_curve (data, width, height, stride, nodes, cstart, cend);
	for (i = 0; i < 4; ++i) {
	    fd_fwd (pv[i][0]);
	    fd_fwd (pv[i][1]);
	    cstart[i] += dcstart[i];
	    cend[i] += dcend[i];
	}
    }
}
static inline void rasterize_bezier_patch ( unsigned char * data , int width , int height , int stride , int vshift , cairo_point_double_t p [ 4 ] [ 4 ] , double col [ 4 ] [ 4 ] ) { double pv [ 4 ] [ 2 ] [ 4 ] , cstart [ 4 ] , cend [ 4 ] , dcstart [ 4 ] , dcend [ 4 ] ; int v , i , k ; v = 1 << vshift ; for ( i = 0 ; i < 4 ; ++ i ) { fd_init ( p [ i ] [ 0 ] . x , p [ i ] [ 1 ] . x , p [ i ] [ 2 ] . x , p [ i ] [ 3 ] . x , pv [ i ] [ 0 ] ) ; fd_init ( p [ i ] [ 0 ] . y , p [ i ] [ 1 ] . y , p [ i ] [ 2 ] . y , p [ i ] [ 3 ] . y , pv [ i ] [ 1 ] ) ; for ( k = 0 ; k < vshift ; ++ k ) { fd_down ( pv [ i ] [ 0 ] ) ; fd_down ( pv [ i ] [ 1 ] ) ; } } for ( i = 0 ; i < 4 ; ++ i ) { cstart [ i ] = col [ 0 ] [ i ] ; cend [ i ] = col [ 1 ] [ i ] ; dcstart [ i ] = ( col [ 2 ] [ i ] - col [ 0 ] [ i ] ) / v ; dcend [ i ] = ( col [ 3 ] [ i ] - col [ 1 ] [ i ] ) / v ; } v ++ ; while ( v -- ) { cairo_point_double_t nodes [ 4 ] ; for ( i = 0 ; i < 4 ; ++ i ) { nodes [ i ] . x = pv [ i ] [ 0 ] [ 0 ] ; nodes [ i ] . y = pv [ i ] [ 1 ] [ 0 ] ; } draw_bezier_curve ( data , width , height , stride , nodes , cstart , cend ) ; for ( i = 0 ; i < 4 ; ++ i ) { fd_fwd ( pv [ i ] [ 0 ] ) ; fd_fwd ( pv [ i ] [ 1 ] ) ; cstart [ i ] += dcstart [ i ] ; cend [ i ] += dcend [ i ] ; } } }
Forward-rasterize a cubic Bezier patch using forward differences.
Forward - rasterize a cubic Bezier patch using forward differences .
/*
     * pv[i][0] is the function (represented using forward
     * differences) mapping v to the x coordinate of the i-th node of
     * the Bezier curve with parameter u.
     * (Likewise p[i][0] gives the y coordinate).
     *
     * This means that (pv[0][0][0],pv[0][1][0]),
     * (pv[1][0][0],pv[1][1][0]), (pv[2][0][0],pv[2][1][0]) and
     * (pv[3][0][0],pv[3][1][0]) are the nodes of the Bezier curve for
     * the "current" v value (see the FD comments for more details).
     */