static void fz_test_fill_shade(fz_context *ctx, fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha) { if (shade->use_function) { int i; for (i = 0; i < 256; i++) fz_test_color(ctx, dev, shade->colorspace, shade->function[i]); } else { struct shadearg arg; arg.dev = dev; arg.shade = shade; fz_process_mesh(ctx, shade, ctm, prepare_vertex, NULL, &arg); } }
fz_rect * fz_bound_shade(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz_rect *s) { fz_matrix local_ctm; struct bound_mesh_data bmd; fz_concat(&local_ctm, &shade->matrix, ctm); *s = shade->bbox; fz_transform_rect(s, &local_ctm); if (shade->type == FZ_LINEAR) return s; if (shade->type == FZ_RADIAL) return s; bmd.rect = fz_empty_rect; bmd.first = 1; fz_process_mesh(ctx, shade, &local_ctm, &bound_tri, &bmd); fz_intersect_rect(s, &bmd.rect); return s; }
void fz_paint_shade(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz_pixmap *dest, const fz_irect *bbox) { unsigned char clut[256][FZ_MAX_COLORS]; fz_pixmap *temp = NULL; fz_pixmap *conv = NULL; float color[FZ_MAX_COLORS]; struct paint_tri_data ptd; int i, k; fz_matrix local_ctm; fz_var(temp); fz_var(conv); fz_try(ctx) { fz_concat(&local_ctm, &shade->matrix, ctm); if (shade->use_function) { fz_color_converter cc; fz_find_color_converter(&cc, ctx, dest->colorspace, shade->colorspace); for (i = 0; i < 256; i++) { cc.convert(&cc, color, shade->function[i]); for (k = 0; k < dest->colorspace->n; k++) clut[i][k] = color[k] * 255; clut[i][k] = shade->function[i][shade->colorspace->n] * 255; } conv = fz_new_pixmap_with_bbox(ctx, dest->colorspace, bbox); temp = fz_new_pixmap_with_bbox(ctx, fz_device_gray, bbox); fz_clear_pixmap(ctx, temp); } else { temp = dest; } ptd.ctx = ctx; ptd.dest = temp; ptd.shade = shade; ptd.bbox = bbox; fz_process_mesh(ctx, shade, &local_ctm, &do_paint_tri, &ptd); if (shade->use_function) { unsigned char *s = temp->samples; unsigned char *d = conv->samples; int len = temp->w * temp->h; while (len--) { int v = *s++; int a = fz_mul255(*s++, clut[v][conv->n - 1]); for (k = 0; k < conv->n - 1; k++) *d++ = fz_mul255(clut[v][k], a); *d++ = a; } fz_paint_pixmap(dest, conv, 255); fz_drop_pixmap(ctx, conv); fz_drop_pixmap(ctx, temp); } } fz_catch(ctx) { fz_drop_pixmap(ctx, conv); fz_drop_pixmap(ctx, temp); fz_rethrow(ctx); } }