示例#1
0
static void
fz_process_mesh_type2(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz_mesh_processor *painter)
{
	fz_point p0, p1, dir;
	fz_vertex v0, v1, v2, v3;
	fz_vertex e0, e1;
	float theta;
	float zero = 0;
	float one = 1;

	p0.x = shade->u.l_or_r.coords[0][0];
	p0.y = shade->u.l_or_r.coords[0][1];
	p1.x = shade->u.l_or_r.coords[1][0];
	p1.y = shade->u.l_or_r.coords[1][1];
	dir.x = p0.y - p1.y;
	dir.y = p1.x - p0.x;
	fz_transform_point(&p0, ctm);
	fz_transform_point(&p1, ctm);
	fz_transform_vector(&dir, ctm);
	theta = atan2f(dir.y, dir.x);

	v0.p = fz_point_on_circle(p0, HUGENUM, theta);
	v1.p = fz_point_on_circle(p1, HUGENUM, theta);
	v2.p = fz_point_on_circle(p0, -HUGENUM, theta);
	v3.p = fz_point_on_circle(p1, -HUGENUM, theta);

	fz_prepare_color(ctx, painter, &v0, &zero);
	fz_prepare_color(ctx, painter, &v1, &one);
	fz_prepare_color(ctx, painter, &v2, &zero);
	fz_prepare_color(ctx, painter, &v3, &one);

	paint_quad(ctx, painter, &v0, &v2, &v3, &v1);

	if (shade->u.l_or_r.extend[0])
	{
		e0.p.x = v0.p.x - (p1.x - p0.x) * HUGENUM;
		e0.p.y = v0.p.y - (p1.y - p0.y) * HUGENUM;
		fz_prepare_color(ctx, painter, &e0, &zero);

		e1.p.x = v2.p.x - (p1.x - p0.x) * HUGENUM;
		e1.p.y = v2.p.y - (p1.y - p0.y) * HUGENUM;
		fz_prepare_color(ctx, painter, &e1, &zero);

		paint_quad(ctx, painter, &e0, &v0, &v2, &e1);
	}

	if (shade->u.l_or_r.extend[1])
	{
		e0.p.x = v1.p.x + (p1.x - p0.x) * HUGENUM;
		e0.p.y = v1.p.y + (p1.y - p0.y) * HUGENUM;
		fz_prepare_color(ctx, painter, &e0, &one);

		e1.p.x = v3.p.x + (p1.x - p0.x) * HUGENUM;
		e1.p.y = v3.p.y + (p1.y - p0.y) * HUGENUM;
		fz_prepare_color(ctx, painter, &e1, &one);

		paint_quad(ctx, painter, &e0, &v1, &v3, &e1);
	}
}
示例#2
0
static void
fz_paint_annulus(fz_context *ctx, const fz_matrix *ctm,
		fz_point p0, float r0, float c0,
		fz_point p1, float r1, float c1,
		int count,
		fz_mesh_processor *painter)
{
	fz_vertex t0, t1, t2, t3, b0, b1, b2, b3;
	float theta, step, a, b;
	int i;

	theta = atan2f(p1.y - p0.y, p1.x - p0.x);
	step = (float)M_PI / count;

	a = 0;
	for (i = 1; i <= count; i++)
	{
		b = i * step;

		t0.p = fz_point_on_circle(p0, r0, theta + a);
		t1.p = fz_point_on_circle(p0, r0, theta + b);
		t2.p = fz_point_on_circle(p1, r1, theta + a);
		t3.p = fz_point_on_circle(p1, r1, theta + b);
		b0.p = fz_point_on_circle(p0, r0, theta - a);
		b1.p = fz_point_on_circle(p0, r0, theta - b);
		b2.p = fz_point_on_circle(p1, r1, theta - a);
		b3.p = fz_point_on_circle(p1, r1, theta - b);

		fz_transform_point(&t0.p, ctm);
		fz_transform_point(&t1.p, ctm);
		fz_transform_point(&t2.p, ctm);
		fz_transform_point(&t3.p, ctm);
		fz_transform_point(&b0.p, ctm);
		fz_transform_point(&b1.p, ctm);
		fz_transform_point(&b2.p, ctm);
		fz_transform_point(&b3.p, ctm);

		fz_prepare_color(ctx, painter, &t0, &c0);
		fz_prepare_color(ctx, painter, &t1, &c0);
		fz_prepare_color(ctx, painter, &t2, &c1);
		fz_prepare_color(ctx, painter, &t3, &c1);
		fz_prepare_color(ctx, painter, &b0, &c0);
		fz_prepare_color(ctx, painter, &b1, &c0);
		fz_prepare_color(ctx, painter, &b2, &c1);
		fz_prepare_color(ctx, painter, &b3, &c1);

		paint_quad(ctx, painter, &t0, &t2, &t3, &t1);
		paint_quad(ctx, painter, &b0, &b2, &b3, &b1);

		a = b;
	}
}
示例#3
0
static void
fz_mesh_type5_process(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz_mesh_processor *painter)
{
	fz_stream *stream = fz_open_compressed_buffer(ctx, shade->buffer);
	fz_vertex *buf = NULL;
	fz_vertex *ref = NULL;
	int first;
	int ncomp;
	int i, k;
	int vprow = shade->u.m.vprow;
	int bpcoord = shade->u.m.bpcoord;
	int bpcomp = shade->u.m.bpcomp;
	float x0 = shade->u.m.x0;
	float x1 = shade->u.m.x1;
	float y0 = shade->u.m.y0;
	float y1 = shade->u.m.y1;
	float *c0 = shade->u.m.c0;
	float *c1 = shade->u.m.c1;

	fz_var(buf);
	fz_var(ref);

	fz_try(ctx)
	{
		ref = fz_malloc_array(ctx, vprow, sizeof(fz_vertex));
		buf = fz_malloc_array(ctx, vprow, sizeof(fz_vertex));
		first = 1;

		ncomp = (shade->use_function > 0 ? 1 : shade->colorspace->n);
		while (!fz_is_eof_bits(stream))
		{
			for (i = 0; i < vprow; i++)
			{
				buf[i].p.x = read_sample(stream, bpcoord, x0, x1);
				buf[i].p.y = read_sample(stream, bpcoord, y0, y1);
				fz_transform_point(&buf[i].p, ctm);
				for (k = 0; k < ncomp; k++)
					buf[i].c[k] = read_sample(stream, bpcomp, c0[k], c1[k]);
			}

			if (!first)
				for (i = 0; i < vprow - 1; i++)
					paint_quad(painter, &ref[i], &ref[i+1], &buf[i+1], &buf[i]);

			SWAP(ref,buf);
			first = 0;
		}
	}
	fz_always(ctx)
	{
		fz_free(ctx, ref);
		fz_free(ctx, buf);
		fz_close(stream);
	}
	fz_catch(ctx)
	{
		fz_rethrow(ctx);
	}
}
示例#4
0
static void
fz_process_mesh_type5(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz_mesh_processor *painter)
{
	fz_stream *stream = fz_open_compressed_buffer(ctx, shade->buffer);
	fz_vertex *buf = NULL;
	fz_vertex *ref = NULL;
	int first;
	int ncomp = painter->ncomp;
	int i, k;
	int vprow = shade->u.m.vprow;
	int bpcoord = shade->u.m.bpcoord;
	int bpcomp = shade->u.m.bpcomp;
	float x0 = shade->u.m.x0;
	float x1 = shade->u.m.x1;
	float y0 = shade->u.m.y0;
	float y1 = shade->u.m.y1;
	float *c0 = shade->u.m.c0;
	float *c1 = shade->u.m.c1;
	float x, y, c[FZ_MAX_COLORS];

	fz_var(buf);
	fz_var(ref);

	fz_try(ctx)
	{
		ref = fz_malloc_array(ctx, vprow, sizeof(fz_vertex));
		buf = fz_malloc_array(ctx, vprow, sizeof(fz_vertex));
		first = 1;

		while (!fz_is_eof_bits(ctx, stream))
		{
			for (i = 0; i < vprow; i++)
			{
				x = read_sample(ctx, stream, bpcoord, x0, x1);
				y = read_sample(ctx, stream, bpcoord, y0, y1);
				for (k = 0; k < ncomp; k++)
					c[k] = read_sample(ctx, stream, bpcomp, c0[k], c1[k]);
				fz_prepare_vertex(ctx, painter, &buf[i], ctm, x, y, c);
			}

			if (!first)
				for (i = 0; i < vprow - 1; i++)
					paint_quad(ctx, painter, &ref[i], &ref[i+1], &buf[i+1], &buf[i]);

			SWAP(ref,buf);
			first = 0;
		}
	}
	fz_always(ctx)
	{
		fz_free(ctx, ref);
		fz_free(ctx, buf);
		fz_drop_stream(ctx, stream);
	}
	fz_catch(ctx)
	{
		fz_rethrow(ctx);
	}
}
示例#5
0
static void
fz_paint_annulus(const fz_matrix *ctm,
		fz_point p0, float r0, float c0,
		fz_point p1, float r1, float c1,
		fz_mesh_processor *painter)
{
	fz_vertex t0, t1, t2, t3, b0, b1, b2, b3;
	float theta, step;
	int i;

	theta = atan2f(p1.y - p0.y, p1.x - p0.x);
	step = (float)M_PI * 2 / RADSEGS;

	for (i = 0; i < RADSEGS / 2; i++)
	{
		t0.p = fz_point_on_circle(p0, r0, theta + i * step);
		t1.p = fz_point_on_circle(p0, r0, theta + i * step + step);
		t2.p = fz_point_on_circle(p1, r1, theta + i * step);
		t3.p = fz_point_on_circle(p1, r1, theta + i * step + step);
		b0.p = fz_point_on_circle(p0, r0, theta - i * step);
		b1.p = fz_point_on_circle(p0, r0, theta - i * step - step);
		b2.p = fz_point_on_circle(p1, r1, theta - i * step);
		b3.p = fz_point_on_circle(p1, r1, theta - i * step - step);

		fz_transform_point(&t0.p, ctm);
		fz_transform_point(&t1.p, ctm);
		fz_transform_point(&t2.p, ctm);
		fz_transform_point(&t3.p, ctm);
		fz_transform_point(&b0.p, ctm);
		fz_transform_point(&b1.p, ctm);
		fz_transform_point(&b2.p, ctm);
		fz_transform_point(&b3.p, ctm);

		t0.c[0] = c0;
		t1.c[0] = c0;
		t2.c[0] = c1;
		t3.c[0] = c1;
		b0.c[0] = c0;
		b1.c[0] = c0;
		b2.c[0] = c1;
		b3.c[0] = c1;

		paint_quad(painter, &t0, &t2, &t3, &t1);
		paint_quad(painter, &b0, &b2, &b3, &b1);
	}
}
示例#6
0
static void
fz_mesh_type1_process(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz_mesh_processor *painter)
{
	float *p = shade->u.f.fn_vals;
	int xdivs = shade->u.f.xdivs;
	int ydivs = shade->u.f.ydivs;
	float x0 = shade->u.f.domain[0][0];
	float y0 = shade->u.f.domain[0][1];
	float x1 = shade->u.f.domain[1][0];
	float y1 = shade->u.f.domain[1][1];
	int xx, yy;
	float y, yn, x;
	fz_vertex vs[2][2];
	fz_vertex *v = vs[0];
	fz_vertex *vn = vs[1];
	int n = shade->colorspace->n;
	fz_matrix local_ctm;

	fz_concat(&local_ctm, &shade->u.f.matrix, ctm);

	y = y0;
	for (yy = 0; yy < ydivs; yy++)
	{
		yn = y0 + (y1 - y0) * (yy + 1) / ydivs;

		x = x0;
		v[0].p.x = x; v[0].p.y = y;
		fz_transform_point(&v[0].p, &local_ctm);
		memcpy(v[0].c, p, n*sizeof(float));
		p += n;
		v[1].p.x = x; v[1].p.y = yn;
		fz_transform_point(&v[1].p, &local_ctm);
		memcpy(v[1].c, p + xdivs*n, n*sizeof(float));
		for (xx = 0; xx < xdivs; xx++)
		{
			x = x0 + (x1 - x0) * (xx + 1) / xdivs;

			vn[0].p.x = x; vn[0].p.y = y;
			fz_transform_point(&vn[0].p, &local_ctm);
			memcpy(vn[0].c, p, n*sizeof(float));
			p += n;
			vn[1].p.x = x; vn[1].p.y = yn;
			fz_transform_point(&vn[1].p, &local_ctm);
			memcpy(vn[1].c, p + xdivs*n, n*sizeof(float));

			paint_quad(painter, &v[0], &vn[0], &vn[1], &v[1]);
			SWAP(v,vn);
		}
		y = yn;
	}
}
示例#7
0
static void
triangulate_patch(fz_context *ctx, fz_mesh_processor *painter, tensor_patch p)
{
	fz_vertex v0, v1, v2, v3;

	v0.p = p.pole[0][0];
	v1.p = p.pole[0][3];
	v2.p = p.pole[3][3];
	v3.p = p.pole[3][0];

	fz_prepare_color(ctx, painter, &v0, p.color[0]);
	fz_prepare_color(ctx, painter, &v1, p.color[1]);
	fz_prepare_color(ctx, painter, &v2, p.color[2]);
	fz_prepare_color(ctx, painter, &v3, p.color[3]);

	paint_quad(ctx, painter, &v0, &v1, &v2, &v3);
}
示例#8
0
static void
fz_process_mesh_type1(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz_mesh_processor *painter)
{
	float *p = shade->u.f.fn_vals;
	int xdivs = shade->u.f.xdivs;
	int ydivs = shade->u.f.ydivs;
	float x0 = shade->u.f.domain[0][0];
	float y0 = shade->u.f.domain[0][1];
	float x1 = shade->u.f.domain[1][0];
	float y1 = shade->u.f.domain[1][1];
	int xx, yy;
	float y, yn, x;
	fz_vertex vs[2][2];
	fz_vertex *v = vs[0];
	fz_vertex *vn = vs[1];
	int n = shade->colorspace->n;
	fz_matrix local_ctm;

	fz_concat(&local_ctm, &shade->u.f.matrix, ctm);

	y = y0;
	for (yy = 0; yy < ydivs; yy++)
	{
		yn = y0 + (y1 - y0) * (yy + 1) / ydivs;

		x = x0;

		fz_prepare_vertex(ctx, painter, &v[0], &local_ctm, x, y, p);
		p += n;
		fz_prepare_vertex(ctx, painter, &v[1], &local_ctm, x, yn, p + xdivs * n);

		for (xx = 0; xx < xdivs; xx++)
		{
			x = x0 + (x1 - x0) * (xx + 1) / xdivs;

			fz_prepare_vertex(ctx, painter, &vn[0], &local_ctm, x, y, p);
			p += n;
			fz_prepare_vertex(ctx, painter, &vn[1], &local_ctm, x, yn, p + xdivs * n);

			paint_quad(ctx, painter, &v[0], &vn[0], &vn[1], &v[1]);
			SWAP(v,vn);
		}
		y = yn;
	}
}
示例#9
0
static void
triangulate_patch(fz_mesh_processor *painter, tensor_patch p)
{
	fz_vertex v0, v1, v2, v3;

	v0.p = p.pole[0][0];
	memcpy(v0.c, p.color[0], sizeof(v0.c));

	v1.p = p.pole[0][3];
	memcpy(v1.c, p.color[1], sizeof(v1.c));

	v2.p = p.pole[3][3];
	memcpy(v2.c, p.color[2], sizeof(v2.c));

	v3.p = p.pole[3][0];
	memcpy(v3.c, p.color[3], sizeof(v3.c));

	paint_quad(painter, &v0, &v1, &v2, &v3);
}