From 52ded6dcabb7f2d43f90ec06d5ad77314186fd56 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Tue, 16 Apr 2013 11:01:23 +0100 Subject: Try to copy less needless information in mesh processing --- fitz/fitz-internal.h | 1 + fitz/res_shade.c | 76 +++++++++++++++++++++------------------------------- 2 files changed, 31 insertions(+), 46 deletions(-) diff --git a/fitz/fitz-internal.h b/fitz/fitz-internal.h index 856ace5e..2bacef87 100644 --- a/fitz/fitz-internal.h +++ b/fitz/fitz-internal.h @@ -1427,6 +1427,7 @@ struct fz_mesh_processor_s { fz_shade *shade; fz_mesh_process_fn *process; void *process_arg; + int ncomp; }; void fz_process_mesh(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, diff --git a/fitz/res_shade.c b/fitz/res_shade.c index 1d09c354..0369830d 100644 --- a/fitz/res_shade.c +++ b/fitz/res_shade.c @@ -256,7 +256,7 @@ fz_mesh_type4_process(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz fz_vertex *vb = &v[1]; fz_vertex *vc = &v[2]; fz_vertex *vd = &v[3]; - int flag, i, ncomp; + int flag, i, ncomp = painter->ncomp; int bpflag = shade->u.m.bpflag; int bpcoord = shade->u.m.bpcoord; int bpcomp = shade->u.m.bpcomp; @@ -269,7 +269,6 @@ fz_mesh_type4_process(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz fz_try(ctx) { - ncomp = (shade->use_function > 0 ? 1 : shade->colorspace->n); while (!fz_is_eof_bits(stream)) { flag = fz_read_bits(stream, bpflag); @@ -333,7 +332,7 @@ fz_mesh_type5_process(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz fz_vertex *buf = NULL; fz_vertex *ref = NULL; int first; - int ncomp; + int ncomp = painter->ncomp; int i, k; int vprow = shade->u.m.vprow; int bpcoord = shade->u.m.bpcoord; @@ -354,7 +353,6 @@ fz_mesh_type5_process(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz 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++) @@ -400,18 +398,19 @@ static void triangulate_patch(fz_mesh_processor *painter, tensor_patch p) { fz_vertex v0, v1, v2, v3; + int col_len = painter->ncomp * sizeof(v0.c[0]); v0.p = p.pole[0][0]; - memcpy(v0.c, p.color[0], sizeof(v0.c)); + memcpy(v0.c, p.color[0], col_len); v1.p = p.pole[0][3]; - memcpy(v1.c, p.color[1], sizeof(v1.c)); + memcpy(v1.c, p.color[1], col_len); v2.p = p.pole[3][3]; - memcpy(v2.c, p.color[2], sizeof(v2.c)); + memcpy(v2.c, p.color[2], col_len); v3.p = p.pole[3][0]; - memcpy(v3.c, p.color[3], sizeof(v3.c)); + memcpy(v3.c, p.color[3], col_len); paint_quad(painter, &v0, &v1, &v2, &v3); } @@ -650,7 +649,7 @@ fz_mesh_type6_process(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz int haspatch, hasprevpatch; float prevc[4][FZ_MAX_COLORS]; fz_point prevp[12]; - int ncomp; + int ncomp = painter->ncomp; int i, k; int bpflag = shade->u.m.bpflag; int bpcoord = shade->u.m.bpcoord; @@ -665,7 +664,6 @@ fz_mesh_type6_process(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz fz_try(ctx) { hasprevpatch = 0; - ncomp = (shade->use_function > 0 ? 1 : shade->colorspace->n); while (!fz_is_eof_bits(stream)) { float c[4][FZ_MAX_COLORS]; @@ -784,23 +782,24 @@ fz_mesh_type7_process(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz float y1 = shade->u.m.y1; float *c0 = shade->u.m.c0; float *c1 = shade->u.m.c1; - float prevc[4][FZ_MAX_COLORS]; - fz_point prevp[16]; - int ncomp; + float color_storage[2][4][FZ_MAX_COLORS]; + fz_point point_storage[2][16]; + int store = 0; + int ncomp = painter->ncomp; int i, k; - int haspatch, hasprevpatch; + float (*prevc)[FZ_MAX_COLORS] = NULL; + fz_point (*prevp) = NULL; fz_try(ctx) { - hasprevpatch = 0; - ncomp = (shade->use_function > 0 ? 1 : shade->colorspace->n); while (!fz_is_eof_bits(stream)) { - float c[4][FZ_MAX_COLORS]; - fz_point v[16]; + float (*c)[FZ_MAX_COLORS] = color_storage[store]; + fz_point *v = point_storage[store]; int startcolor; int startpt; int flag; + tensor_patch patch; flag = fz_read_bits(stream, bpflag); @@ -828,13 +827,10 @@ fz_mesh_type7_process(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz c[i][k] = read_sample(stream, bpcomp, c0[k], c1[k]); } - haspatch = 0; - if (flag == 0) { - haspatch = 1; } - else if (flag == 1 && hasprevpatch) + else if (flag == 1 && prevc) { v[0] = prevp[3]; v[1] = prevp[4]; @@ -842,10 +838,8 @@ fz_mesh_type7_process(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz v[3] = prevp[6]; memcpy(c[0], prevc[1], ncomp * sizeof(float)); memcpy(c[1], prevc[2], ncomp * sizeof(float)); - - haspatch = 1; } - else if (flag == 2 && hasprevpatch) + else if (flag == 2 && prevc) { v[0] = prevp[6]; v[1] = prevp[7]; @@ -853,10 +847,8 @@ fz_mesh_type7_process(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz v[3] = prevp[9]; memcpy(c[0], prevc[2], ncomp * sizeof(float)); memcpy(c[1], prevc[3], ncomp * sizeof(float)); - - haspatch = 1; } - else if (flag == 3 && hasprevpatch) + else if (flag == 3 && prevc) { v[0] = prevp[ 9]; v[1] = prevp[10]; @@ -864,29 +856,20 @@ fz_mesh_type7_process(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz v[3] = prevp[ 0]; memcpy(c[0], prevc[3], ncomp * sizeof(float)); memcpy(c[1], prevc[0], ncomp * sizeof(float)); - - haspatch = 1; } + else + continue; /* We have no patch! */ - if (haspatch) - { - tensor_patch patch; - - make_tensor_patch(&patch, 7, v); - - for (i = 0; i < 4; i++) - memcpy(patch.color[i], c[i], ncomp * sizeof(float)); - - draw_patch(painter, &patch, SUBDIV, SUBDIV); + make_tensor_patch(&patch, 7, v); - for (i = 0; i < 16; i++) - prevp[i] = v[i]; + for (i = 0; i < 4; i++) + memcpy(patch.color[i], c[i], ncomp * sizeof(float)); - for (i = 0; i < 4; i++) - memcpy(prevc[i], c[i], FZ_MAX_COLORS * sizeof(float)); + draw_patch(painter, &patch, SUBDIV, SUBDIV); - hasprevpatch = 1; - } + prevp = v; + prevc = c; + store ^= 1; } } fz_always(ctx) @@ -909,6 +892,7 @@ fz_process_mesh(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, painter.shade = shade; painter.process = process; painter.process_arg = process_arg; + painter.ncomp = (shade->use_function > 0 ? 1 : shade->colorspace->n); if (shade->type == FZ_FUNCTION_BASED) fz_mesh_type1_process(ctx, shade, ctm, &painter); -- cgit v1.2.3