summaryrefslogtreecommitdiff
path: root/draw
diff options
context:
space:
mode:
Diffstat (limited to 'draw')
-rw-r--r--draw/draw_device.c258
-rw-r--r--draw/draw_edge.c30
-rw-r--r--draw/draw_glyph.c36
-rw-r--r--draw/draw_mesh.c18
-rw-r--r--draw/draw_path.c6
-rw-r--r--draw/draw_scale.c25
-rw-r--r--draw/draw_simple_scale.c24
7 files changed, 197 insertions, 200 deletions
diff --git a/draw/draw_device.c b/draw/draw_device.c
index 165cb1a9..7e40ef3f 100644
--- a/draw/draw_device.c
+++ b/draw/draw_device.c
@@ -53,6 +53,7 @@ struct fz_draw_device_s
{
fz_glyph_cache *cache;
fz_gel *gel;
+ fz_context *ctx;
fz_pixmap *dest;
fz_pixmap *shape;
@@ -101,20 +102,19 @@ static void fz_grow_stack(fz_draw_device *dev)
if (dev->stack == &dev->init_stack[0])
{
- stack = fz_malloc(sizeof(*stack) * max);
+ stack = fz_malloc(dev->ctx, sizeof(*stack) * max);
memcpy(stack, dev->stack, sizeof(*stack) * dev->stack_max);
}
else
{
- stack = fz_realloc(dev->stack, max, sizeof(*stack));
+ stack = fz_resize_array(dev->ctx, dev->stack, max, sizeof(*stack));
}
dev->stack = stack;
dev->stack_max = max;
}
-static void fz_knockout_begin(void *user)
+static void fz_knockout_begin(fz_draw_device *dev)
{
- fz_draw_device *dev = user;
fz_bbox bbox;
fz_pixmap *dest, *shape;
int isolated = dev->blendmode & FZ_BLEND_ISOLATED;
@@ -127,7 +127,7 @@ static void fz_knockout_begin(void *user)
bbox = fz_bound_pixmap(dev->dest);
bbox = fz_intersect_bbox(bbox, dev->scissor);
- dest = fz_new_pixmap_with_rect(dev->dest->colorspace, bbox);
+ dest = fz_new_pixmap_with_rect(dev->ctx, dev->dest->colorspace, bbox);
if (isolated)
{
@@ -151,7 +151,7 @@ static void fz_knockout_begin(void *user)
}
else
{
- shape = fz_new_pixmap_with_rect(NULL, bbox);
+ shape = fz_new_pixmap_with_rect(dev->ctx, NULL, bbox);
fz_clear_pixmap(shape);
}
dev->stack[dev->top].blendmode = dev->blendmode;
@@ -169,9 +169,8 @@ static void fz_knockout_begin(void *user)
dev->blendmode &= ~FZ_BLEND_MODEMASK;
}
-static void fz_knockout_end(void *user)
+static void fz_knockout_end(fz_draw_device *dev)
{
- fz_draw_device *dev = user;
fz_pixmap *group = dev->dest;
fz_pixmap *shape = dev->shape;
int blendmode;
@@ -212,14 +211,14 @@ static void fz_knockout_end(void *user)
else
fz_blend_pixmap(dev->dest, group, 255, blendmode, isolated, shape);
- fz_drop_pixmap(group);
+ fz_drop_pixmap(dev->ctx, group);
if (shape != dev->shape)
{
if (dev->shape)
{
fz_paint_pixmap(dev->shape, shape, 255);
}
- fz_drop_pixmap(shape);
+ fz_drop_pixmap(dev->ctx, shape);
}
#ifdef DUMP_GROUP_BLENDS
fz_dump_blend(dev->dest, " to get ");
@@ -231,10 +230,10 @@ static void fz_knockout_end(void *user)
}
static void
-fz_draw_fill_path(void *user, fz_path *path, int even_odd, fz_matrix ctm,
+fz_draw_fill_path(fz_device *devp, fz_path *path, int even_odd, fz_matrix ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
fz_colorspace *model = dev->dest->colorspace;
float expansion = fz_matrix_expansion(ctm);
float flatness = 0.3f / expansion;
@@ -256,7 +255,7 @@ fz_draw_fill_path(void *user, fz_path *path, int even_odd, fz_matrix ctm,
if (dev->blendmode & FZ_BLEND_KNOCKOUT)
fz_knockout_begin(dev);
- fz_convert_color(colorspace, color, model, colorfv);
+ fz_convert_color(dev->ctx, colorspace, color, model, colorfv);
for (i = 0; i < model->n; i++)
colorbv[i] = colorfv[i] * 255;
colorbv[i] = alpha * 255;
@@ -277,10 +276,10 @@ fz_draw_fill_path(void *user, fz_path *path, int even_odd, fz_matrix ctm,
}
static void
-fz_draw_stroke_path(void *user, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm,
+fz_draw_stroke_path(fz_device *devp, fz_path *path, fz_stroke_state *stroke, fz_matrix ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
fz_colorspace *model = dev->dest->colorspace;
float expansion = fz_matrix_expansion(ctm);
float flatness = 0.3f / expansion;
@@ -309,7 +308,7 @@ fz_draw_stroke_path(void *user, fz_path *path, fz_stroke_state *stroke, fz_matri
if (dev->blendmode & FZ_BLEND_KNOCKOUT)
fz_knockout_begin(dev);
- fz_convert_color(colorspace, color, model, colorfv);
+ fz_convert_color(dev->ctx, colorspace, color, model, colorfv);
for (i = 0; i < model->n; i++)
colorbv[i] = colorfv[i] * 255;
colorbv[i] = alpha * 255;
@@ -333,9 +332,9 @@ fz_draw_stroke_path(void *user, fz_path *path, fz_stroke_state *stroke, fz_matri
}
static void
-fz_draw_clip_path(void *user, fz_path *path, fz_rect *rect, int even_odd, fz_matrix ctm)
+fz_draw_clip_path(fz_device *devp, fz_path *path, fz_rect *rect, int even_odd, fz_matrix ctm)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
fz_colorspace *model = dev->dest->colorspace;
float expansion = fz_matrix_expansion(ctm);
float flatness = 0.3f / expansion;
@@ -369,14 +368,14 @@ fz_draw_clip_path(void *user, fz_path *path, fz_rect *rect, int even_odd, fz_mat
return;
}
- mask = fz_new_pixmap_with_rect(NULL, bbox);
+ mask = fz_new_pixmap_with_rect(dev->ctx, NULL, bbox);
fz_clear_pixmap(mask);
- dest = fz_new_pixmap_with_rect(model, bbox);
+ dest = fz_new_pixmap_with_rect(dev->ctx, model, bbox);
/* FIXME: See note #1 */
fz_clear_pixmap(dest);
if (dev->shape)
{
- shape = fz_new_pixmap_with_rect(NULL, bbox);
+ shape = fz_new_pixmap_with_rect(dev->ctx, NULL, bbox);
fz_clear_pixmap(shape);
}
else
@@ -400,9 +399,9 @@ fz_draw_clip_path(void *user, fz_path *path, fz_rect *rect, int even_odd, fz_mat
}
static void
-fz_draw_clip_stroke_path(void *user, fz_path *path, fz_rect *rect, fz_stroke_state *stroke, fz_matrix ctm)
+fz_draw_clip_stroke_path(fz_device *devp, fz_path *path, fz_rect *rect, fz_stroke_state *stroke, fz_matrix ctm)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
fz_colorspace *model = dev->dest->colorspace;
float expansion = fz_matrix_expansion(ctm);
float flatness = 0.3f / expansion;
@@ -428,14 +427,14 @@ fz_draw_clip_stroke_path(void *user, fz_path *path, fz_rect *rect, fz_stroke_sta
if (rect)
bbox = fz_intersect_bbox(bbox, fz_round_rect(*rect));
- mask = fz_new_pixmap_with_rect(NULL, bbox);
+ mask = fz_new_pixmap_with_rect(dev->ctx, NULL, bbox);
fz_clear_pixmap(mask);
- dest = fz_new_pixmap_with_rect(model, bbox);
+ dest = fz_new_pixmap_with_rect(dev->ctx, model, bbox);
/* FIXME: See note #1 */
fz_clear_pixmap(dest);
if (dev->shape)
{
- shape = fz_new_pixmap_with_rect(NULL, bbox);
+ shape = fz_new_pixmap_with_rect(dev->ctx, NULL, bbox);
fz_clear_pixmap(shape);
}
else
@@ -496,10 +495,10 @@ draw_glyph(unsigned char *colorbv, fz_pixmap *dst, fz_pixmap *msk,
}
static void
-fz_draw_fill_text(void *user, fz_text *text, fz_matrix ctm,
+fz_draw_fill_text(fz_device *devp, fz_text *text, fz_matrix ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
fz_colorspace *model = dev->dest->colorspace;
unsigned char colorbv[FZ_MAX_COLORS + 1];
unsigned char shapebv;
@@ -511,7 +510,7 @@ fz_draw_fill_text(void *user, fz_text *text, fz_matrix ctm,
if (dev->blendmode & FZ_BLEND_KNOCKOUT)
fz_knockout_begin(dev);
- fz_convert_color(colorspace, color, model, colorfv);
+ fz_convert_color(dev->ctx, colorspace, color, model, colorfv);
for (i = 0; i < model->n; i++)
colorbv[i] = colorfv[i] * 255;
colorbv[i] = alpha * 255;
@@ -533,7 +532,7 @@ fz_draw_fill_text(void *user, fz_text *text, fz_matrix ctm,
trm.e = QUANT(trm.e - floorf(trm.e), HSUBPIX);
trm.f = QUANT(trm.f - floorf(trm.f), VSUBPIX);
- glyph = fz_render_glyph(dev->cache, text->font, gid, trm, model);
+ glyph = fz_render_glyph(dev->ctx, dev->cache, text->font, gid, trm, model);
if (glyph)
{
if (glyph->n == 1)
@@ -547,7 +546,7 @@ fz_draw_fill_text(void *user, fz_text *text, fz_matrix ctm,
fz_matrix ctm = {glyph->w, 0.0, 0.0, -glyph->h, x + glyph->x, y + glyph->y + glyph->h};
fz_paint_image(dev->dest, dev->scissor, dev->shape, glyph, ctm, alpha * 255);
}
- fz_drop_pixmap(glyph);
+ fz_drop_pixmap(dev->ctx, glyph);
}
}
@@ -556,10 +555,10 @@ fz_draw_fill_text(void *user, fz_text *text, fz_matrix ctm,
}
static void
-fz_draw_stroke_text(void *user, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm,
+fz_draw_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
fz_colorspace *model = dev->dest->colorspace;
unsigned char colorbv[FZ_MAX_COLORS + 1];
float colorfv[FZ_MAX_COLORS];
@@ -570,7 +569,7 @@ fz_draw_stroke_text(void *user, fz_text *text, fz_stroke_state *stroke, fz_matri
if (dev->blendmode & FZ_BLEND_KNOCKOUT)
fz_knockout_begin(dev);
- fz_convert_color(colorspace, color, model, colorfv);
+ fz_convert_color(dev->ctx, colorspace, color, model, colorfv);
for (i = 0; i < model->n; i++)
colorbv[i] = colorfv[i] * 255;
colorbv[i] = alpha * 255;
@@ -591,13 +590,13 @@ fz_draw_stroke_text(void *user, fz_text *text, fz_stroke_state *stroke, fz_matri
trm.e = QUANT(trm.e - floorf(trm.e), HSUBPIX);
trm.f = QUANT(trm.f - floorf(trm.f), VSUBPIX);
- glyph = fz_render_stroked_glyph(dev->cache, text->font, gid, trm, ctm, stroke);
+ glyph = fz_render_stroked_glyph(dev->ctx, dev->cache, text->font, gid, trm, ctm, stroke);
if (glyph)
{
draw_glyph(colorbv, dev->dest, glyph, x, y, dev->scissor);
if (dev->shape)
draw_glyph(colorbv, dev->shape, glyph, x, y, dev->scissor);
- fz_drop_pixmap(glyph);
+ fz_drop_pixmap(dev->ctx, glyph);
}
}
@@ -606,9 +605,9 @@ fz_draw_stroke_text(void *user, fz_text *text, fz_stroke_state *stroke, fz_matri
}
static void
-fz_draw_clip_text(void *user, fz_text *text, fz_matrix ctm, int accumulate)
+fz_draw_clip_text(fz_device *devp, fz_text *text, fz_matrix ctm, int accumulate)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
fz_colorspace *model = dev->dest->colorspace;
fz_bbox bbox;
fz_pixmap *mask, *dest, *shape;
@@ -637,14 +636,14 @@ fz_draw_clip_text(void *user, fz_text *text, fz_matrix ctm, int accumulate)
if (accumulate == 0 || accumulate == 1)
{
- mask = fz_new_pixmap_with_rect(NULL, bbox);
+ mask = fz_new_pixmap_with_rect(dev->ctx, NULL, bbox);
fz_clear_pixmap(mask);
- dest = fz_new_pixmap_with_rect(model, bbox);
+ dest = fz_new_pixmap_with_rect(dev->ctx, model, bbox);
/* FIXME: See note #1 */
fz_clear_pixmap(dest);
if (dev->shape)
{
- shape = fz_new_pixmap_with_rect(NULL, bbox);
+ shape = fz_new_pixmap_with_rect(dev->ctx, NULL, bbox);
fz_clear_pixmap(shape);
}
else
@@ -687,22 +686,22 @@ fz_draw_clip_text(void *user, fz_text *text, fz_matrix ctm, int accumulate)
trm.e = QUANT(trm.e - floorf(trm.e), HSUBPIX);
trm.f = QUANT(trm.f - floorf(trm.f), VSUBPIX);
- glyph = fz_render_glyph(dev->cache, text->font, gid, trm, model);
+ glyph = fz_render_glyph(dev->ctx, dev->cache, text->font, gid, trm, model);
if (glyph)
{
draw_glyph(NULL, mask, glyph, x, y, bbox);
if (dev->shape)
draw_glyph(NULL, dev->shape, glyph, x, y, bbox);
- fz_drop_pixmap(glyph);
+ fz_drop_pixmap(dev->ctx, glyph);
}
}
}
}
static void
-fz_draw_clip_stroke_text(void *user, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm)
+fz_draw_clip_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
fz_colorspace *model = dev->dest->colorspace;
fz_bbox bbox;
fz_pixmap *mask, *dest, *shape;
@@ -717,14 +716,14 @@ fz_draw_clip_stroke_text(void *user, fz_text *text, fz_stroke_state *stroke, fz_
bbox = fz_round_rect(fz_bound_text(text, ctm));
bbox = fz_intersect_bbox(bbox, dev->scissor);
- mask = fz_new_pixmap_with_rect(NULL, bbox);
+ mask = fz_new_pixmap_with_rect(dev->ctx, NULL, bbox);
fz_clear_pixmap(mask);
- dest = fz_new_pixmap_with_rect(model, bbox);
+ dest = fz_new_pixmap_with_rect(dev->ctx, model, bbox);
/* FIXME: See note #1 */
fz_clear_pixmap(dest);
if (dev->shape)
{
- shape = fz_new_pixmap_with_rect(NULL, bbox);
+ shape = fz_new_pixmap_with_rect(dev->ctx, NULL, bbox);
fz_clear_pixmap(shape);
}
else
@@ -762,27 +761,27 @@ fz_draw_clip_stroke_text(void *user, fz_text *text, fz_stroke_state *stroke, fz_
trm.e = QUANT(trm.e - floorf(trm.e), HSUBPIX);
trm.f = QUANT(trm.f - floorf(trm.f), VSUBPIX);
- glyph = fz_render_stroked_glyph(dev->cache, text->font, gid, trm, ctm, stroke);
+ glyph = fz_render_stroked_glyph(dev->ctx, dev->cache, text->font, gid, trm, ctm, stroke);
if (glyph)
{
draw_glyph(NULL, mask, glyph, x, y, bbox);
if (dev->shape)
draw_glyph(NULL, dev->shape, glyph, x, y, bbox);
- fz_drop_pixmap(glyph);
+ fz_drop_pixmap(dev->ctx, glyph);
}
}
}
}
static void
-fz_draw_ignore_text(void *user, fz_text *text, fz_matrix ctm)
+fz_draw_ignore_text(fz_device *dev, fz_text *text, fz_matrix ctm)
{
}
static void
-fz_draw_fill_shade(void *user, fz_shade *shade, fz_matrix ctm, float alpha)
+fz_draw_fill_shade(fz_device *devp, fz_shade *shade, fz_matrix ctm, float alpha)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
fz_colorspace *model = dev->dest->colorspace;
fz_pixmap *dest = dev->dest;
fz_rect bounds;
@@ -801,13 +800,13 @@ fz_draw_fill_shade(void *user, fz_shade *shade, fz_matrix ctm, float alpha)
if (!model)
{
- fz_warn("cannot render shading directly to an alpha mask");
+ fz_warn(dev->ctx, "cannot render shading directly to an alpha mask");
return;
}
if (alpha < 1)
{
- dest = fz_new_pixmap_with_rect(dev->dest->colorspace, bbox);
+ dest = fz_new_pixmap_with_rect(dev->ctx, dev->dest->colorspace, bbox);
fz_clear_pixmap(dest);
}
@@ -818,7 +817,7 @@ fz_draw_fill_shade(void *user, fz_shade *shade, fz_matrix ctm, float alpha)
{
unsigned char *s;
int x, y, n, i;
- fz_convert_color(shade->colorspace, shade->background, model, colorfv);
+ fz_convert_color(dev->ctx, shade->colorspace, shade->background, model, colorfv);
for (i = 0; i < model->n; i++)
colorbv[i] = colorfv[i] * 255;
colorbv[i] = 255;
@@ -846,14 +845,14 @@ fz_draw_fill_shade(void *user, fz_shade *shade, fz_matrix ctm, float alpha)
}
}
- fz_paint_shade(shade, ctm, dest, bbox);
+ fz_paint_shade(dev->ctx, shade, ctm, dest, bbox);
if (dev->shape)
fz_clear_pixmap_rect_with_color(dev->shape, 255, bbox);
if (alpha < 1)
{
fz_paint_pixmap(dev->dest, dest, alpha * 255);
- fz_drop_pixmap(dest);
+ fz_drop_pixmap(dev->ctx, dest);
}
if (dev->blendmode & FZ_BLEND_KNOCKOUT)
@@ -861,7 +860,7 @@ fz_draw_fill_shade(void *user, fz_shade *shade, fz_matrix ctm, float alpha)
}
static fz_pixmap *
-fz_transform_pixmap(fz_pixmap *image, fz_matrix *ctm, int x, int y, int dx, int dy, int gridfit)
+fz_transform_pixmap(fz_context *ctx, fz_pixmap *image, fz_matrix *ctm, int x, int y, int dx, int dy, int gridfit)
{
fz_pixmap *scaled;
@@ -871,7 +870,7 @@ fz_transform_pixmap(fz_pixmap *image, fz_matrix *ctm, int x, int y, int dx, int
fz_matrix m = *ctm;
if (gridfit)
fz_gridfit_matrix(&m);
- scaled = fz_scale_pixmap(image, m.e, m.f, m.a, m.d);
+ scaled = fz_scale_pixmap(ctx, image, m.e, m.f, m.a, m.d);
if (scaled == NULL)
return NULL;
ctm->a = scaled->w;
@@ -887,7 +886,7 @@ fz_transform_pixmap(fz_pixmap *image, fz_matrix *ctm, int x, int y, int dx, int
fz_matrix m = *ctm;
if (gridfit)
fz_gridfit_matrix(&m);
- scaled = fz_scale_pixmap(image, m.f, m.e, m.b, m.c);
+ scaled = fz_scale_pixmap(ctx, image, m.f, m.e, m.b, m.c);
if (scaled == NULL)
return NULL;
ctm->b = scaled->w;
@@ -900,7 +899,7 @@ fz_transform_pixmap(fz_pixmap *image, fz_matrix *ctm, int x, int y, int dx, int
/* Downscale, non rectilinear case */
if (dx > 0 && dy > 0)
{
- scaled = fz_scale_pixmap(image, 0, 0, (float)dx, (float)dy);
+ scaled = fz_scale_pixmap(ctx, image, 0, 0, (float)dx, (float)dy);
return scaled;
}
@@ -908,9 +907,9 @@ fz_transform_pixmap(fz_pixmap *image, fz_matrix *ctm, int x, int y, int dx, int
}
static void
-fz_draw_fill_image(void *user, fz_pixmap *image, fz_matrix ctm, float alpha)
+fz_draw_fill_image(fz_device *devp, fz_pixmap *image, fz_matrix ctm, float alpha)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
fz_colorspace *model = dev->dest->colorspace;
fz_pixmap *converted = NULL;
fz_pixmap *scaled = NULL;
@@ -919,7 +918,7 @@ fz_draw_fill_image(void *user, fz_pixmap *image, fz_matrix ctm, float alpha)
if (!model)
{
- fz_warn("cannot render image directly to an alpha mask");
+ fz_warn(dev->ctx, "cannot render image directly to an alpha mask");
return;
}
@@ -939,8 +938,8 @@ fz_draw_fill_image(void *user, fz_pixmap *image, fz_matrix ctm, float alpha)
if (image->colorspace != model && !after)
{
- converted = fz_new_pixmap_with_rect(model, fz_bound_pixmap(image));
- fz_convert_pixmap(image, converted);
+ converted = fz_new_pixmap_with_rect(dev->ctx, model, fz_bound_pixmap(image));
+ fz_convert_pixmap(dev->ctx, image, converted);
image = converted;
}
@@ -949,14 +948,14 @@ fz_draw_fill_image(void *user, fz_pixmap *image, fz_matrix ctm, float alpha)
if (dx < image->w && dy < image->h)
{
int gridfit = alpha == 1.0f && !(dev->flags & FZ_DRAWDEV_FLAGS_TYPE3);
- scaled = fz_transform_pixmap(image, &ctm, dev->dest->x, dev->dest->y, dx, dy, gridfit);
+ scaled = fz_transform_pixmap(dev->ctx, image, &ctm, dev->dest->x, dev->dest->y, dx, dy, gridfit);
if (scaled == NULL)
{
if (dx < 1)
dx = 1;
if (dy < 1)
dy = 1;
- scaled = fz_scale_pixmap(image, image->x, image->y, dx, dy);
+ scaled = fz_scale_pixmap(dev->ctx, image, image->x, image->y, dx, dy);
}
if (scaled != NULL)
image = scaled;
@@ -971,8 +970,8 @@ fz_draw_fill_image(void *user, fz_pixmap *image, fz_matrix ctm, float alpha)
}
else
{
- converted = fz_new_pixmap_with_rect(model, fz_bound_pixmap(image));
- fz_convert_pixmap(image, converted);
+ converted = fz_new_pixmap_with_rect(dev->ctx, model, fz_bound_pixmap(image));
+ fz_convert_pixmap(dev->ctx, image, converted);
image = converted;
}
}
@@ -980,19 +979,19 @@ fz_draw_fill_image(void *user, fz_pixmap *image, fz_matrix ctm, float alpha)
fz_paint_image(dev->dest, dev->scissor, dev->shape, image, ctm, alpha * 255);
if (scaled)
- fz_drop_pixmap(scaled);
+ fz_drop_pixmap(dev->ctx, scaled);
if (converted)
- fz_drop_pixmap(converted);
+ fz_drop_pixmap(dev->ctx, converted);
if (dev->blendmode & FZ_BLEND_KNOCKOUT)
fz_knockout_end(dev);
}
static void
-fz_draw_fill_image_mask(void *user, fz_pixmap *image, fz_matrix ctm,
+fz_draw_fill_image_mask(fz_device *devp, fz_pixmap *image, fz_matrix ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
fz_colorspace *model = dev->dest->colorspace;
unsigned char colorbv[FZ_MAX_COLORS + 1];
float colorfv[FZ_MAX_COLORS];
@@ -1011,20 +1010,20 @@ fz_draw_fill_image_mask(void *user, fz_pixmap *image, fz_matrix ctm,
if (dx < image->w && dy < image->h)
{
int gridfit = alpha == 1.0f && !(dev->flags & FZ_DRAWDEV_FLAGS_TYPE3);
- scaled = fz_transform_pixmap(image, &ctm, dev->dest->x, dev->dest->y, dx, dy, gridfit);
+ scaled = fz_transform_pixmap(dev->ctx, image, &ctm, dev->dest->x, dev->dest->y, dx, dy, gridfit);
if (scaled == NULL)
{
if (dx < 1)
dx = 1;
if (dy < 1)
dy = 1;
- scaled = fz_scale_pixmap(image, image->x, image->y, dx, dy);
+ scaled = fz_scale_pixmap(dev->ctx, image, image->x, image->y, dx, dy);
}
if (scaled != NULL)
image = scaled;
}
- fz_convert_color(colorspace, color, model, colorfv);
+ fz_convert_color(dev->ctx, colorspace, color, model, colorfv);
for (i = 0; i < model->n; i++)
colorbv[i] = colorfv[i] * 255;
colorbv[i] = alpha * 255;
@@ -1032,16 +1031,16 @@ fz_draw_fill_image_mask(void *user, fz_pixmap *image, fz_matrix ctm,
fz_paint_image_with_color(dev->dest, dev->scissor, dev->shape, image, ctm, colorbv);
if (scaled)
- fz_drop_pixmap(scaled);
+ fz_drop_pixmap(dev->ctx, scaled);
if (dev->blendmode & FZ_BLEND_KNOCKOUT)
fz_knockout_begin(dev);
}
static void
-fz_draw_clip_image_mask(void *user, fz_pixmap *image, fz_rect *rect, fz_matrix ctm)
+fz_draw_clip_image_mask(fz_device *devp, fz_pixmap *image, fz_rect *rect, fz_matrix ctm)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
fz_colorspace *model = dev->dest->colorspace;
fz_bbox bbox;
fz_pixmap *mask, *dest, *shape;
@@ -1071,14 +1070,14 @@ fz_draw_clip_image_mask(void *user, fz_pixmap *image, fz_rect *rect, fz_matrix c
if (rect)
bbox = fz_intersect_bbox(bbox, fz_round_rect(*rect));
- mask = fz_new_pixmap_with_rect(NULL, bbox);
+ mask = fz_new_pixmap_with_rect(dev->ctx, NULL, bbox);
fz_clear_pixmap(mask);
- dest = fz_new_pixmap_with_rect(model, bbox);
+ dest = fz_new_pixmap_with_rect(dev->ctx, model, bbox);
/* FIXME: See note #1 */
fz_clear_pixmap(dest);
if (dev->shape)
{
- shape = fz_new_pixmap_with_rect(NULL, bbox);
+ shape = fz_new_pixmap_with_rect(dev->ctx, NULL, bbox);
fz_clear_pixmap(shape);
}
else
@@ -1089,14 +1088,14 @@ fz_draw_clip_image_mask(void *user, fz_pixmap *image, fz_rect *rect, fz_matrix c
if (dx < image->w && dy < image->h)
{
int gridfit = !(dev->flags & FZ_DRAWDEV_FLAGS_TYPE3);
- scaled = fz_transform_pixmap(image, &ctm, dev->dest->x, dev->dest->y, dx, dy, gridfit);
+ scaled = fz_transform_pixmap(dev->ctx, image, &ctm, dev->dest->x, dev->dest->y, dx, dy, gridfit);
if (scaled == NULL)
{
if (dx < 1)
dx = 1;
if (dy < 1)
dy = 1;
- scaled = fz_scale_pixmap(image, image->x, image->y, dx, dy);
+ scaled = fz_scale_pixmap(dev->ctx, image, image->x, image->y, dx, dy);
}
if (scaled != NULL)
image = scaled;
@@ -1105,7 +1104,7 @@ fz_draw_clip_image_mask(void *user, fz_pixmap *image, fz_rect *rect, fz_matrix c
fz_paint_image(mask, bbox, dev->shape, image, ctm, 255);
if (scaled)
- fz_drop_pixmap(scaled);
+ fz_drop_pixmap(dev->ctx, scaled);
dev->stack[dev->top].scissor = dev->scissor;
dev->stack[dev->top].mask = mask;
@@ -1120,9 +1119,9 @@ fz_draw_clip_image_mask(void *user, fz_pixmap *image, fz_rect *rect, fz_matrix c
}
static void
-fz_draw_pop_clip(void *user)
+fz_draw_pop_clip(fz_device *devp)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
fz_pixmap *mask, *dest, *shape;
if (dev->top > 0)
{
@@ -1156,11 +1155,11 @@ fz_draw_pop_clip(void *user)
{
assert(shape != dev->shape);
fz_paint_pixmap_with_mask(shape, dev->shape, mask);
- fz_drop_pixmap(dev->shape);
+ fz_drop_pixmap(dev->ctx, dev->shape);
dev->shape = shape;
}
- fz_drop_pixmap(mask);
- fz_drop_pixmap(dev->dest);
+ fz_drop_pixmap(dev->ctx, mask);
+ fz_drop_pixmap(dev->ctx, dev->dest);
dev->dest = dest;
#ifdef DUMP_GROUP_BLENDS
fz_dump_blend(dev->dest, " to get ");
@@ -1181,9 +1180,9 @@ fz_draw_pop_clip(void *user)
}
static void
-fz_draw_begin_mask(void *user, fz_rect rect, int luminosity, fz_colorspace *colorspace, float *colorfv)
+fz_draw_begin_mask(fz_device *devp, fz_rect rect, int luminosity, fz_colorspace *colorspace, float *colorfv)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
fz_pixmap *dest;
fz_pixmap *shape = dev->shape;
fz_bbox bbox;
@@ -1193,7 +1192,7 @@ fz_draw_begin_mask(void *user, fz_rect rect, int luminosity, fz_colorspace *colo
bbox = fz_round_rect(rect);
bbox = fz_intersect_bbox(bbox, dev->scissor);
- dest = fz_new_pixmap_with_rect(fz_device_gray, bbox);
+ dest = fz_new_pixmap_with_rect(dev->ctx, fz_device_gray, bbox);
if (dev->shape)
{
/* FIXME: If we ever want to support AIS true, then we
@@ -1210,7 +1209,7 @@ fz_draw_begin_mask(void *user, fz_rect rect, int luminosity, fz_colorspace *colo
float bc;
if (!colorspace)
colorspace = fz_device_gray;
- fz_convert_color(colorspace, colorfv, fz_device_gray, &bc);
+ fz_convert_color(dev->ctx, colorspace, colorfv, fz_device_gray, &bc);
fz_clear_pixmap_with_color(dest, bc * 255);
if (shape)
fz_clear_pixmap_with_color(shape, 255);
@@ -1238,9 +1237,9 @@ fz_draw_begin_mask(void *user, fz_rect rect, int luminosity, fz_colorspace *colo
}
static void
-fz_draw_end_mask(void *user)
+fz_draw_end_mask(fz_device *devp)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
fz_pixmap *mask = dev->dest;
fz_pixmap *maskshape = dev->shape;
fz_pixmap *temp, *dest;
@@ -1260,13 +1259,13 @@ fz_draw_end_mask(void *user)
dev->shape = dev->stack[dev->top].shape;
/* convert to alpha mask */
- temp = fz_alpha_from_gray(mask, luminosity);
- fz_drop_pixmap(mask);
- fz_drop_pixmap(maskshape);
+ temp = fz_alpha_from_gray(dev->ctx, mask, luminosity);
+ fz_drop_pixmap(dev->ctx, mask);
+ fz_drop_pixmap(dev->ctx, maskshape);
/* create new dest scratch buffer */
bbox = fz_bound_pixmap(temp);
- dest = fz_new_pixmap_with_rect(dev->dest->colorspace, bbox);
+ dest = fz_new_pixmap_with_rect(dev->ctx, dev->dest->colorspace, bbox);
/* FIXME: See note #1 */
fz_clear_pixmap(dest);
@@ -1281,7 +1280,7 @@ fz_draw_end_mask(void *user)
if (dev->shape)
{
dev->stack[dev->top].shape = dev->shape;
- dev->shape = fz_new_pixmap_with_rect(NULL, bbox);
+ dev->shape = fz_new_pixmap_with_rect(dev->ctx, NULL, bbox);
fz_clear_pixmap(dev->shape);
}
dev->scissor = bbox;
@@ -1294,16 +1293,16 @@ fz_draw_end_mask(void *user)
}
static void
-fz_draw_begin_group(void *user, fz_rect rect, int isolated, int knockout, int blendmode, float alpha)
+fz_draw_begin_group(fz_device *devp, fz_rect rect, int isolated, int knockout, int blendmode, float alpha)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
fz_colorspace *model = dev->dest->colorspace;
fz_bbox bbox;
fz_pixmap *dest, *shape;
if (dev->top == dev->stack_max)
{
- fz_warn("assert: too many buffers on stack");
+ fz_warn(dev->ctx, "assert: too many buffers on stack");
return;
}
@@ -1312,7 +1311,7 @@ fz_draw_begin_group(void *user, fz_rect rect, int isolated, int knockout, int bl
bbox = fz_round_rect(rect);
bbox = fz_intersect_bbox(bbox, dev->scissor);
- dest = fz_new_pixmap_with_rect(model, bbox);
+ dest = fz_new_pixmap_with_rect(dev->ctx, model, bbox);
#ifndef ATTEMPT_KNOCKOUT_AND_ISOLATED
knockout = 0;
@@ -1336,7 +1335,7 @@ fz_draw_begin_group(void *user, fz_rect rect, int isolated, int knockout, int bl
}
else
{
- shape = fz_new_pixmap_with_rect(NULL, bbox);
+ shape = fz_new_pixmap_with_rect(dev->ctx, NULL, bbox);
fz_clear_pixmap(shape);
}
@@ -1357,9 +1356,9 @@ fz_draw_begin_group(void *user, fz_rect rect, int isolated, int knockout, int bl
}
static void
-fz_draw_end_group(void *user)
+fz_draw_end_group(fz_device *devp)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
fz_pixmap *group = dev->dest;
fz_pixmap *shape = dev->shape;
int blendmode;
@@ -1399,14 +1398,14 @@ fz_draw_end_group(void *user)
else
fz_blend_pixmap(dev->dest, group, alpha * 255, blendmode, isolated, shape);
- fz_drop_pixmap(group);
+ fz_drop_pixmap(dev->ctx, group);
if (shape != dev->shape)
{
if (dev->shape)
{
fz_paint_pixmap(dev->shape, shape, alpha * 255);
}
- fz_drop_pixmap(shape);
+ fz_drop_pixmap(dev->ctx, shape);
}
#ifdef DUMP_GROUP_BLENDS
fz_dump_blend(dev->dest, " to get ");
@@ -1421,9 +1420,9 @@ fz_draw_end_group(void *user)
}
static void
-fz_draw_begin_tile(void *user, fz_rect area, fz_rect view, float xstep, float ystep, fz_matrix ctm)
+fz_draw_begin_tile(fz_device *devp, fz_rect area, fz_rect view, float xstep, float ystep, fz_matrix ctm)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
fz_colorspace *model = dev->dest->colorspace;
fz_pixmap *dest;
fz_bbox bbox;
@@ -1438,7 +1437,7 @@ fz_draw_begin_tile(void *user, fz_rect area, fz_rect view, float xstep, float ys
fz_knockout_begin(dev);
bbox = fz_round_rect(fz_transform_rect(ctm, view));
- dest = fz_new_pixmap_with_rect(model, bbox);
+ dest = fz_new_pixmap_with_rect(dev->ctx, model, bbox);
/* FIXME: See note #1 */
fz_clear_pixmap(dest);
@@ -1461,9 +1460,9 @@ fz_draw_begin_tile(void *user, fz_rect area, fz_rect view, float xstep, float ys
}
static void
-fz_draw_end_tile(void *user)
+fz_draw_end_tile(fz_device *devp)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
fz_pixmap *tile = dev->dest;
float xstep, ystep;
fz_matrix ctm, ttm;
@@ -1504,7 +1503,7 @@ fz_draw_end_tile(void *user)
}
}
- fz_drop_pixmap(tile);
+ fz_drop_pixmap(dev->ctx, tile);
}
if (dev->blendmode & FZ_BLEND_KNOCKOUT)
@@ -1512,30 +1511,31 @@ fz_draw_end_tile(void *user)
}
static void
-fz_draw_free_user(void *user)
+fz_draw_free_user(fz_device *devp)
{
- fz_draw_device *dev = user;
+ fz_draw_device *dev = devp->user;
/* TODO: pop and free the stacks */
if (dev->top > 0)
- fz_warn("items left on stack in draw device: %d", dev->top);
+ fz_warn(dev->ctx, "items left on stack in draw device: %d", dev->top);
if (dev->stack != &dev->init_stack[0])
- fz_free(dev->stack);
+ fz_free(dev->ctx, dev->stack);
fz_free_gel(dev->gel);
- fz_free(dev);
+ fz_free(devp->ctx, dev);
}
fz_device *
-fz_new_draw_device(fz_glyph_cache *cache, fz_pixmap *dest)
+fz_new_draw_device(fz_context *ctx, fz_glyph_cache *cache, fz_pixmap *dest)
{
fz_device *dev;
- fz_draw_device *ddev = fz_malloc(sizeof(fz_draw_device));
+ fz_draw_device *ddev = fz_malloc(ctx, sizeof(fz_draw_device));
ddev->cache = cache;
- ddev->gel = fz_new_gel();
+ ddev->gel = fz_new_gel(ctx);
ddev->dest = dest;
ddev->shape = NULL;
ddev->top = 0;
ddev->blendmode = 0;
ddev->flags = 0;
+ ddev->ctx = ctx;
ddev->stack = &ddev->init_stack[0];
ddev->stack_max = STACK_SIZE;
@@ -1544,7 +1544,7 @@ fz_new_draw_device(fz_glyph_cache *cache, fz_pixmap *dest)
ddev->scissor.x1 = dest->x + dest->w;
ddev->scissor.y1 = dest->y + dest->h;
- dev = fz_new_device(ddev);
+ dev = fz_new_device(ctx, ddev);
dev->free_user = fz_draw_free_user;
dev->fill_path = fz_draw_fill_path;
@@ -1577,9 +1577,9 @@ fz_new_draw_device(fz_glyph_cache *cache, fz_pixmap *dest)
}
fz_device *
-fz_new_draw_device_type3(fz_glyph_cache *cache, fz_pixmap *dest)
+fz_new_draw_device_type3(fz_context *ctx, fz_glyph_cache *cache, fz_pixmap *dest)
{
- fz_device *dev = fz_new_draw_device(cache, dest);
+ fz_device *dev = fz_new_draw_device(ctx, cache, dest);
fz_draw_device *ddev = dev->user;
ddev->flags |= FZ_DRAWDEV_FLAGS_TYPE3;
return dev;
diff --git a/draw/draw_edge.c b/draw/draw_edge.c
index 123c3268..e6408bf3 100644
--- a/draw/draw_edge.c
+++ b/draw/draw_edge.c
@@ -65,7 +65,7 @@ void
fz_set_aa_level(int level)
{
#ifdef AA_BITS
- fz_warn("anti-aliasing was compiled with a fixed precision of %d bits", fz_aa_level);
+ fz_warn(ctx, "anti-aliasing was compiled with a fixed precision of %d bits", fz_aa_level);
#else
if (level > 6)
{
@@ -127,17 +127,19 @@ struct fz_gel_s
fz_edge *edges;
int acap, alen;
fz_edge **active;
+ fz_context *ctx;
};
fz_gel *
-fz_new_gel(void)
+fz_new_gel(fz_context *ctx)
{
fz_gel *gel;
- gel = fz_malloc(sizeof(fz_gel));
+ gel = fz_malloc(ctx, sizeof(fz_gel));
+ gel->ctx = ctx;
gel->cap = 512;
gel->len = 0;
- gel->edges = fz_calloc(gel->cap, sizeof(fz_edge));
+ gel->edges = fz_malloc_array(ctx, gel->cap, sizeof(fz_edge));
gel->clip.x0 = gel->clip.y0 = BBOX_MAX;
gel->clip.x1 = gel->clip.y1 = BBOX_MIN;
@@ -147,7 +149,7 @@ fz_new_gel(void)
gel->acap = 64;
gel->alen = 0;
- gel->active = fz_calloc(gel->acap, sizeof(fz_edge*));
+ gel->active = fz_malloc_array(ctx, gel->acap, sizeof(fz_edge*));
return gel;
}
@@ -176,9 +178,9 @@ fz_reset_gel(fz_gel *gel, fz_bbox clip)
void
fz_free_gel(fz_gel *gel)
{
- fz_free(gel->active);
- fz_free(gel->edges);
- fz_free(gel);
+ fz_free(gel->ctx, gel->active);
+ fz_free(gel->ctx, gel->edges);
+ fz_free(gel->ctx, gel);
}
fz_bbox
@@ -253,7 +255,7 @@ fz_insert_gel_raw(fz_gel *gel, int x0, int y0, int x1, int y1)
if (gel->len + 1 == gel->cap) {
gel->cap = gel->cap + 512;
- gel->edges = fz_realloc(gel->edges, gel->cap, sizeof(fz_edge));
+ gel->edges = fz_resize_array(gel->ctx, gel->edges, gel->cap, sizeof(fz_edge));
}
edge = &gel->edges[gel->len++];
@@ -443,7 +445,7 @@ insert_active(fz_gel *gel, int y, int *e)
while (*e < gel->len && gel->edges[*e].y == y) {
if (gel->alen + 1 == gel->acap) {
int newcap = gel->acap + 64;
- fz_edge **newactive = fz_realloc(gel->active, newcap, sizeof(fz_edge*));
+ fz_edge **newactive = fz_resize_array(gel->ctx, gel->active, newcap, sizeof(fz_edge*));
gel->active = newactive;
gel->acap = newcap;
}
@@ -593,8 +595,8 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, fz_bbox clip,
assert(clip.x0 >= xmin);
assert(clip.x1 <= xmax);
- alphas = fz_malloc(xmax - xmin + 1);
- deltas = fz_malloc((xmax - xmin + 1) * sizeof(int));
+ alphas = fz_malloc(gel->ctx, xmax - xmin + 1);
+ deltas = fz_malloc(gel->ctx, (xmax - xmin + 1) * sizeof(int));
memset(deltas, 0, (xmax - xmin + 1) * sizeof(int));
e = 0;
@@ -640,8 +642,8 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, fz_bbox clip,
blit_aa(dst, xmin + skipx, yd, alphas + skipx, clipn, color);
}
- fz_free(deltas);
- fz_free(alphas);
+ fz_free(gel->ctx, deltas);
+ fz_free(gel->ctx, alphas);
}
/*
diff --git a/draw/draw_glyph.c b/draw/draw_glyph.c
index 95f3955d..6cb1518a 100644
--- a/draw/draw_glyph.c
+++ b/draw/draw_glyph.c
@@ -22,19 +22,19 @@ struct fz_glyph_key_s
};
fz_glyph_cache *
-fz_new_glyph_cache(void)
+fz_new_glyph_cache(fz_context *ctx)
{
fz_glyph_cache *cache;
- cache = fz_malloc(sizeof(fz_glyph_cache));
- cache->hash = fz_new_hash_table(509, sizeof(fz_glyph_key));
+ cache = fz_malloc(ctx, sizeof(fz_glyph_cache));
+ cache->hash = fz_new_hash_table(ctx, 509, sizeof(fz_glyph_key));
cache->total = 0;
return cache;
}
static void
-fz_evict_glyph_cache(fz_glyph_cache *cache)
+fz_evict_glyph_cache(fz_context *ctx, fz_glyph_cache *cache)
{
fz_glyph_key *key;
fz_pixmap *pixmap;
@@ -44,10 +44,10 @@ fz_evict_glyph_cache(fz_glyph_cache *cache)
{
key = fz_hash_get_key(cache->hash, i);
if (key->font)
- fz_drop_font(key->font);
+ fz_drop_font(ctx, key->font);
pixmap = fz_hash_get_val(cache->hash, i);
if (pixmap)
- fz_drop_pixmap(pixmap);
+ fz_drop_pixmap(ctx, pixmap);
}
cache->total = 0;
@@ -56,23 +56,23 @@ fz_evict_glyph_cache(fz_glyph_cache *cache)
}
void
-fz_free_glyph_cache(fz_glyph_cache *cache)
+fz_free_glyph_cache(fz_context *ctx, fz_glyph_cache *cache)
{
- fz_evict_glyph_cache(cache);
+ fz_evict_glyph_cache(ctx, cache);
fz_free_hash(cache->hash);
- fz_free(cache);
+ fz_free(ctx, cache);
}
fz_pixmap *
-fz_render_stroked_glyph(fz_glyph_cache *cache, fz_font *font, int gid, fz_matrix trm, fz_matrix ctm, fz_stroke_state *stroke)
+fz_render_stroked_glyph(fz_context *ctx, fz_glyph_cache *cache, fz_font *font, int gid, fz_matrix trm, fz_matrix ctm, fz_stroke_state *stroke)
{
if (font->ft_face)
- return fz_render_ft_stroked_glyph(font, gid, trm, ctm, stroke);
- return fz_render_glyph(cache, font, gid, trm, NULL);
+ return fz_render_ft_stroked_glyph(ctx, font, gid, trm, ctm, stroke);
+ return fz_render_glyph(ctx, cache, font, gid, trm, NULL);
}
fz_pixmap *
-fz_render_glyph(fz_glyph_cache *cache, fz_font *font, int gid, fz_matrix ctm, fz_colorspace *model)
+fz_render_glyph(fz_context *ctx, fz_glyph_cache *cache, fz_font *font, int gid, fz_matrix ctm, fz_colorspace *model)
{
fz_glyph_key key;
fz_pixmap *val;
@@ -81,7 +81,7 @@ fz_render_glyph(fz_glyph_cache *cache, fz_font *font, int gid, fz_matrix ctm, fz
if (size > MAX_FONT_SIZE)
{
/* TODO: this case should be handled by rendering glyph as a path fill */
- fz_warn("font size too large (%g), not rendering glyph", size);
+ fz_warn(ctx, "font size too large (%g), not rendering glyph", size);
return NULL;
}
@@ -104,15 +104,15 @@ fz_render_glyph(fz_glyph_cache *cache, fz_font *font, int gid, fz_matrix ctm, fz
if (font->ft_face)
{
- val = fz_render_ft_glyph(font, gid, ctm);
+ val = fz_render_ft_glyph(ctx, font, gid, ctm);
}
else if (font->t3procs)
{
- val = fz_render_t3_glyph(font, gid, ctm, model);
+ val = fz_render_t3_glyph(ctx, font, gid, ctm, model);
}
else
{
- fz_warn("assert: uninitialized font structure");
+ fz_warn(ctx, "assert: uninitialized font structure");
return NULL;
}
@@ -121,7 +121,7 @@ fz_render_glyph(fz_glyph_cache *cache, fz_font *font, int gid, fz_matrix ctm, fz
if (val->w < MAX_GLYPH_SIZE && val->h < MAX_GLYPH_SIZE)
{
if (cache->total + val->w * val->h > MAX_CACHE_SIZE)
- fz_evict_glyph_cache(cache);
+ fz_evict_glyph_cache(ctx, cache);
fz_keep_font(key.font);
fz_hash_insert(cache->hash, &key, val);
cache->total += val->w * val->h;
diff --git a/draw/draw_mesh.c b/draw/draw_mesh.c
index 4254cb64..ef4ed95b 100644
--- a/draw/draw_mesh.c
+++ b/draw/draw_mesh.c
@@ -481,7 +481,7 @@ fz_paint_radial(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox)
}
static void
-fz_paint_mesh(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox)
+fz_paint_mesh(fz_context *ctx, fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox)
{
float tri[3][MAXN];
fz_point p;
@@ -509,7 +509,7 @@ fz_paint_mesh(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox)
tri[k][2] = *mesh++ * 255;
else
{
- fz_convert_color(shade->colorspace, mesh, dest->colorspace, tri[k] + 2);
+ fz_convert_color(ctx, shade->colorspace, mesh, dest->colorspace, tri[k] + 2);
for (i = 0; i < dest->colorspace->n; i++)
tri[k][i + 2] *= 255;
mesh += shade->colorspace->n;
@@ -520,7 +520,7 @@ fz_paint_mesh(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox)
}
void
-fz_paint_shade(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox)
+fz_paint_shade(fz_context *ctx, fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox)
{
unsigned char clut[256][FZ_MAX_COLORS];
fz_pixmap *temp, *conv;
@@ -533,13 +533,13 @@ fz_paint_shade(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox)
{
for (i = 0; i < 256; i++)
{
- fz_convert_color(shade->colorspace, shade->function[i], dest->colorspace, color);
+ fz_convert_color(ctx, shade->colorspace, shade->function[i], dest->colorspace, color);
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_rect(dest->colorspace, bbox);
- temp = fz_new_pixmap_with_rect(fz_device_gray, bbox);
+ conv = fz_new_pixmap_with_rect(ctx, dest->colorspace, bbox);
+ temp = fz_new_pixmap_with_rect(ctx, fz_device_gray, bbox);
fz_clear_pixmap(temp);
}
else
@@ -551,7 +551,7 @@ fz_paint_shade(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox)
{
case FZ_LINEAR: fz_paint_linear(shade, ctm, temp, bbox); break;
case FZ_RADIAL: fz_paint_radial(shade, ctm, temp, bbox); break;
- case FZ_MESH: fz_paint_mesh(shade, ctm, temp, bbox); break;
+ case FZ_MESH: fz_paint_mesh(ctx, shade, ctm, temp, bbox); break;
}
if (shade->use_function)
@@ -568,7 +568,7 @@ fz_paint_shade(fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox)
*d++ = a;
}
fz_paint_pixmap(dest, conv, 255);
- fz_drop_pixmap(conv);
- fz_drop_pixmap(temp);
+ fz_drop_pixmap(ctx, conv);
+ fz_drop_pixmap(ctx, temp);
}
}
diff --git a/draw/draw_path.c b/draw/draw_path.c
index efa881ef..ca33f5f2 100644
--- a/draw/draw_path.c
+++ b/draw/draw_path.c
@@ -542,10 +542,7 @@ fz_flatten_stroke_path(fz_gel *gel, fz_path *path, fz_stroke_state *stroke, fz_m
i = 0;
if (path->len > 0 && path->items[0].k != FZ_MOVETO)
- {
- fz_warn("assert: path must begin with moveto");
return;
- }
p0.x = p0.y = 0;
@@ -750,10 +747,7 @@ fz_flatten_dash_path(fz_gel *gel, fz_path *path, fz_stroke_state *stroke, fz_mat
s.cap = stroke->start_cap;
if (path->len > 0 && path->items[0].k != FZ_MOVETO)
- {
- fz_warn("assert: path must begin with moveto");
return;
- }
phase_len = 0;
for (i = 0; i < stroke->dash_len; i++)
diff --git a/draw/draw_scale.c b/draw/draw_scale.c
index b7aa72f3..fd3c3798 100644
--- a/draw/draw_scale.c
+++ b/draw/draw_scale.c
@@ -271,7 +271,7 @@ struct fz_weights_s
};
static fz_weights *
-new_weights(fz_scale_filter *filter, int src_w, float dst_w, int dst_w_i, int n, int flip)
+new_weights(fz_context *ctx, fz_scale_filter *filter, int src_w, float dst_w, int dst_w_i, int n, int flip)
{
int max_len;
fz_weights *weights;
@@ -297,7 +297,7 @@ new_weights(fz_scale_filter *filter, int src_w, float dst_w, int dst_w_i, int n,
* plus (2+max_len)*sizeof(int) for the weights
* plus room for an extra set of weights for reordering.
*/
- weights = fz_malloc(sizeof(*weights)+(max_len+3)*(dst_w_i+1)*sizeof(int));
+ weights = fz_malloc(ctx, sizeof(*weights)+(max_len+3)*(dst_w_i+1)*sizeof(int));
if (weights == NULL)
return NULL;
weights->count = -1;
@@ -505,7 +505,7 @@ check_weights(fz_weights *weights, int j, int w, float x, float wf)
}
static fz_weights *
-make_weights(int src_w, float x, float dst_w, fz_scale_filter *filter, int vertical, int dst_w_int, int n, int flip)
+make_weights(fz_context *ctx, int src_w, float x, float dst_w, fz_scale_filter *filter, int vertical, int dst_w_int, int n, int flip)
{
fz_weights *weights;
float F, G;
@@ -526,7 +526,7 @@ make_weights(int src_w, float x, float dst_w, fz_scale_filter *filter, int verti
}
window = filter->width / F;
DBUG(("make_weights src_w=%d x=%g dst_w=%g dst_w_int=%d F=%g window=%g\n", src_w, x, dst_w, dst_w_int, F, window));
- weights = new_weights(filter, src_w, dst_w, dst_w_int, n, flip);
+ weights = new_weights(ctx, filter, src_w, dst_w, dst_w_int, n, flip);
if (weights == NULL)
return NULL;
for (j = 0; j < dst_w_int; j++)
@@ -1206,8 +1206,9 @@ scale_single_col(unsigned char *dst, unsigned char *src, fz_weights *weights, in
}
#endif /* SINGLE_PIXEL_SPECIALS */
+
fz_pixmap *
-fz_scale_pixmap(fz_pixmap *src, float x, float y, float w, float h)
+fz_scale_pixmap(fz_context *ctx, fz_pixmap *src, float x, float y, float w, float h)
{
fz_scale_filter *filter = &fz_scale_filter_simple;
fz_weights *contrib_rows = NULL;
@@ -1289,7 +1290,7 @@ fz_scale_pixmap(fz_pixmap *src, float x, float y, float w, float h)
else
#endif /* SINGLE_PIXEL_SPECIALS */
{
- contrib_cols = make_weights(src->w, x, w, filter, 0, dst_w_int, src->n, flip_x);
+ contrib_cols = make_weights(ctx, src->w, x, w, filter, 0, dst_w_int, src->n, flip_x);
if (contrib_cols == NULL)
goto cleanup;
}
@@ -1301,14 +1302,14 @@ fz_scale_pixmap(fz_pixmap *src, float x, float y, float w, float h)
else
#endif /* SINGLE_PIXEL_SPECIALS */
{
- contrib_rows = make_weights(src->h, y, h, filter, 1, dst_h_int, src->n, flip_y);
+ contrib_rows = make_weights(ctx, src->h, y, h, filter, 1, dst_h_int, src->n, flip_y);
if (contrib_rows == NULL)
goto cleanup;
}
assert(contrib_cols == NULL || contrib_cols->count == dst_w_int);
assert(contrib_rows == NULL || contrib_rows->count == dst_h_int);
- output = fz_new_pixmap(src->colorspace, dst_w_int, dst_h_int);
+ output = fz_new_pixmap(ctx, src->colorspace, dst_w_int, dst_h_int);
output->x = dst_x_int;
output->y = dst_y_int;
@@ -1342,7 +1343,7 @@ fz_scale_pixmap(fz_pixmap *src, float x, float y, float w, float h)
temp_rows = contrib_rows->max_len;
if (temp_span <= 0 || temp_rows > INT_MAX / temp_span)
goto cleanup;
- temp = fz_calloc(temp_span*temp_rows, sizeof(int));
+ temp = fz_malloc_array(ctx, temp_span*temp_rows, sizeof(int));
if (temp == NULL)
goto cleanup;
switch (src->n)
@@ -1383,11 +1384,11 @@ fz_scale_pixmap(fz_pixmap *src, float x, float y, float w, float h)
DBUG(("scaling row %d from temp\n", row));
scale_row_from_temp(&output->samples[row*output->w*output->n], temp, contrib_rows, temp_span, row);
}
- fz_free(temp);
+ fz_free(ctx, temp);
}
cleanup:
- fz_free(contrib_rows);
- fz_free(contrib_cols);
+ fz_free(ctx, contrib_rows);
+ fz_free(ctx, contrib_cols);
return output;
}
diff --git a/draw/draw_simple_scale.c b/draw/draw_simple_scale.c
index c2d429b1..dcd5cd68 100644
--- a/draw/draw_simple_scale.c
+++ b/draw/draw_simple_scale.c
@@ -227,7 +227,7 @@ struct fz_weights_s
};
static fz_weights *
-new_weights(fz_scale_filter *filter, int src_w, float dst_w, int dst_w_i, int n, int flip)
+new_weights(fz_context *ctx, fz_scale_filter *filter, int src_w, float dst_w, int dst_w_i, int n, int flip)
{
int max_len;
fz_weights *weights;
@@ -253,7 +253,7 @@ new_weights(fz_scale_filter *filter, int src_w, float dst_w, int dst_w_i, int n,
* plus (2+max_len)*sizeof(int) for the weights
* plus room for an extra set of weights for reordering.
*/
- weights = fz_malloc(sizeof(*weights)+(max_len+3)*(dst_w_i+1)*sizeof(int));
+ weights = fz_malloc(ctx, sizeof(*weights)+(max_len+3)*(dst_w_i+1)*sizeof(int));
if (weights == NULL)
return NULL;
weights->count = -1;
@@ -443,7 +443,7 @@ check_weights(fz_weights *weights, int j, int w, float x, float wf)
}
static fz_weights *
-make_weights(int src_w, float x, float dst_w, fz_scale_filter *filter, int vertical, int dst_w_int, int n, int flip)
+make_weights(fz_context *ctx, int src_w, float x, float dst_w, fz_scale_filter *filter, int vertical, int dst_w_int, int n, int flip)
{
fz_weights *weights;
float F, G;
@@ -464,7 +464,7 @@ make_weights(int src_w, float x, float dst_w, fz_scale_filter *filter, int verti
}
window = filter->width / F;
DBUG(("make_weights src_w=%d x=%g dst_w=%g dst_w_int=%d F=%g window=%g\n", src_w, x, dst_w, dst_w_int, F, window));
- weights = new_weights(filter, src_w, dst_w, dst_w_int, n, flip);
+ weights = new_weights(ctx, filter, src_w, dst_w, dst_w_int, n, flip);
if (weights == NULL)
return NULL;
for (j = 0; j < dst_w_int; j++)
@@ -1167,7 +1167,7 @@ scale_single_col(unsigned char *dst, unsigned char *src, fz_weights *weights, in
#endif /* SINGLE_PIXEL_SPECIALS */
fz_pixmap *
-fz_scale_pixmap(fz_pixmap *src, float x, float y, float w, float h)
+fz_scale_pixmap(fz_context *ctx, fz_pixmap *src, float x, float y, float w, float h)
{
fz_scale_filter *filter = &fz_scale_filter_simple;
fz_weights *contrib_rows = NULL;
@@ -1249,7 +1249,7 @@ fz_scale_pixmap(fz_pixmap *src, float x, float y, float w, float h)
else
#endif /* SINGLE_PIXEL_SPECIALS */
{
- contrib_cols = make_weights(src->w, x, w, filter, 0, dst_w_int, src->n, flip_x);
+ contrib_cols = make_weights(ctx, src->w, x, w, filter, 0, dst_w_int, src->n, flip_x);
if (contrib_cols == NULL)
goto cleanup;
}
@@ -1261,14 +1261,14 @@ fz_scale_pixmap(fz_pixmap *src, float x, float y, float w, float h)
else
#endif /* SINGLE_PIXEL_SPECIALS */
{
- contrib_rows = make_weights(src->h, y, h, filter, 1, dst_h_int, src->n, flip_y);
+ contrib_rows = make_weights(ctx, src->h, y, h, filter, 1, dst_h_int, src->n, flip_y);
if (contrib_rows == NULL)
goto cleanup;
}
assert(contrib_cols == NULL || contrib_cols->count == dst_w_int);
assert(contrib_rows == NULL || contrib_rows->count == dst_h_int);
- output = fz_new_pixmap(src->colorspace, dst_w_int, dst_h_int);
+ output = fz_new_pixmap(ctx, src->colorspace, dst_w_int, dst_h_int);
output->x = dst_x_int;
output->y = dst_y_int;
@@ -1302,7 +1302,7 @@ fz_scale_pixmap(fz_pixmap *src, float x, float y, float w, float h)
temp_rows = contrib_rows->max_len;
if (temp_span <= 0 || temp_rows > INT_MAX / temp_span)
goto cleanup;
- temp = fz_calloc(temp_span*temp_rows, sizeof(unsigned char));
+ temp = fz_calloc(ctx, temp_span*temp_rows, sizeof(unsigned char));
if (temp == NULL)
goto cleanup;
switch (src->n)
@@ -1343,11 +1343,11 @@ fz_scale_pixmap(fz_pixmap *src, float x, float y, float w, float h)
DBUG(("scaling row %d from temp\n", row));
scale_row_from_temp(&output->samples[row*output->w*output->n], temp, contrib_rows, temp_span, row);
}
- fz_free(temp);
+ fz_free(ctx, temp);
}
cleanup:
- fz_free(contrib_rows);
- fz_free(contrib_cols);
+ fz_free(ctx, contrib_rows);
+ fz_free(ctx, contrib_cols);
return output;
}