summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2011-12-06 15:03:35 +0000
committerRobin Watts <robin.watts@artifex.com>2011-12-06 15:03:35 +0000
commit51ea850c2f8464a7245268af3d496141b513d6ba (patch)
treeb39e88b4f06690bbd14e571934c7b88df4336bc4
parent3a207e707b352b8031409f3851705fbc7eccff36 (diff)
downloadmupdf-51ea850c2f8464a7245268af3d496141b513d6ba.tar.xz
Move antialias levels into context.
In builds that support configurable layers of antialiasing, move the variables that control this into the context. This makes it possible to safely use different levels of antialiasing in different threads.
-rw-r--r--apps/pdfdraw.c4
-rw-r--r--draw/draw_edge.c77
-rw-r--r--fitz/base_context.c2
-rw-r--r--fitz/fitz.h9
-rw-r--r--fitz/res_font.c6
-rw-r--r--scripts/cmapdump.c8
6 files changed, 82 insertions, 24 deletions
diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c
index fd7cc57f..69fae0ba 100644
--- a/apps/pdfdraw.c
+++ b/apps/pdfdraw.c
@@ -351,8 +351,6 @@ int main(int argc, char **argv)
}
}
- fz_set_aa_level(alphabits);
-
if (fz_optind == argc)
usage();
@@ -372,6 +370,8 @@ int main(int argc, char **argv)
exit(1);
}
+ fz_set_aa_level(ctx, alphabits);
+
glyphcache = fz_new_glyph_cache(ctx);
colorspace = fz_device_rgb;
diff --git a/draw/draw_edge.c b/draw/draw_edge.c
index e6408bf3..ec1c1ea8 100644
--- a/draw/draw_edge.c
+++ b/draw/draw_edge.c
@@ -15,15 +15,43 @@ static inline int fz_idiv(int a, int b)
* antialiasing is done. If it is undefined to we will leave the antialiasing
* accuracy as a run time choice.
*/
+struct fz_aa_context_s
+{
+ int hscale;
+ int vscale;
+ int scale;
+ int level;
+};
+void fz_new_aa_context(fz_context *ctx)
+{
#ifndef AA_BITS
+ ctx->aa = fz_malloc(ctx, sizeof(*ctx->aa));
+ ctx->aa->hscale = 17;
+ ctx->aa->vscale = 15;
+ ctx->aa->scale = 256;
+ ctx->aa->level = 8;
+
+#define fz_aa_hscale ((ctxaa)->hscale)
+#define fz_aa_vscale ((ctxaa)->vscale)
+#define fz_aa_scale ((ctxaa)->scale)
+#define fz_aa_level ((ctxaa)->level)
#define AA_SCALE(x) ((x * fz_aa_scale) >> 8)
-static int fz_aa_hscale = 17;
-static int fz_aa_vscale = 15;
-static int fz_aa_scale = 256;
-static int fz_aa_level = 8;
-#elif AA_BITS > 6
+#endif
+}
+
+void fz_free_aa_context(fz_context *ctx)
+{
+#ifndef AA_BITS
+ fz_free(ctx, ctx->aa);
+ ctx->aa = NULL;
+#endif
+}
+
+#ifdef AA_BITS
+
+#if AA_BITS > 6
#define AA_SCALE(x) (x)
#define fz_aa_hscale 17
#define fz_aa_vscale 15
@@ -54,16 +82,19 @@ static int fz_aa_level = 8;
#define fz_aa_level 0
#endif
+#endif
int
-fz_get_aa_level(void)
+fz_get_aa_level(fz_context *ctx)
{
+ fz_aa_context *ctxaa = ctx->aa;
return fz_aa_level;
}
void
-fz_set_aa_level(int level)
+fz_set_aa_level(fz_context *ctx, int level)
{
+ fz_aa_context *ctxaa = ctx->aa;
#ifdef AA_BITS
fz_warn(ctx, "anti-aliasing was compiled with a fixed precision of %d bits", fz_aa_level);
#else
@@ -157,6 +188,8 @@ fz_new_gel(fz_context *ctx)
void
fz_reset_gel(fz_gel *gel, fz_bbox clip)
{
+ fz_aa_context *ctxaa = gel->ctx->aa;
+
if (fz_is_infinite_rect(clip))
{
gel->clip.x0 = gel->clip.y0 = BBOX_MAX;
@@ -187,6 +220,7 @@ fz_bbox
fz_bound_gel(fz_gel *gel)
{
fz_bbox bbox;
+ fz_aa_context *ctxaa = gel->ctx->aa;
if (gel->len == 0)
return fz_empty_bbox;
bbox.x0 = fz_idiv(gel->bbox.x0, fz_aa_hscale);
@@ -295,6 +329,7 @@ fz_insert_gel(fz_gel *gel, float fx0, float fy0, float fx1, float fy1)
{
int x0, y0, x1, y1;
int d, v;
+ fz_aa_context *ctxaa = gel->ctx->aa;
fx0 = floorf(fx0 * fz_aa_hscale);
fx1 = floorf(fx1 * fz_aa_hscale);
@@ -489,7 +524,7 @@ advance_active(fz_gel *gel)
* Anti-aliased scan conversion.
*/
-static inline void add_span_aa(int *list, int x0, int x1, int xofs)
+static inline void add_span_aa(fz_aa_context *ctxaa, int *list, int x0, int x1, int xofs)
{
int x0pix, x0sub;
int x1pix, x1sub;
@@ -526,12 +561,14 @@ static inline void non_zero_winding_aa(fz_gel *gel, int *list, int xofs)
int winding = 0;
int x = 0;
int i;
+ fz_aa_context *ctxaa = gel->ctx->aa;
+
for (i = 0; i < gel->alen; i++)
{
if (!winding && (winding + gel->active[i]->ydir))
x = gel->active[i]->x;
if (winding && !(winding + gel->active[i]->ydir))
- add_span_aa(list, x, gel->active[i]->x, xofs);
+ add_span_aa(ctxaa, list, x, gel->active[i]->x, xofs);
winding += gel->active[i]->ydir;
}
}
@@ -541,17 +578,19 @@ static inline void even_odd_aa(fz_gel *gel, int *list, int xofs)
int even = 0;
int x = 0;
int i;
+ fz_aa_context *ctxaa = gel->ctx->aa;
+
for (i = 0; i < gel->alen; i++)
{
if (!even)
x = gel->active[i]->x;
else
- add_span_aa(list, x, gel->active[i]->x, xofs);
+ add_span_aa(ctxaa, list, x, gel->active[i]->x, xofs);
even = !even;
}
}
-static inline void undelta_aa(unsigned char * restrict out, int * restrict in, int n)
+static inline void undelta_aa(fz_aa_context *ctxaa, unsigned char * restrict out, int * restrict in, int n)
{
int d = 0;
while (n--)
@@ -580,6 +619,8 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, fz_bbox clip,
int *deltas;
int y, e;
int yd, yc;
+ fz_context *ctx = gel->ctx;
+ fz_aa_context *ctxaa = ctx->aa;
int xmin = fz_idiv(gel->bbox.x0, fz_aa_hscale);
int xmax = fz_idiv(gel->bbox.x1, fz_aa_hscale) + 1;
@@ -595,8 +636,8 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, fz_bbox clip,
assert(clip.x0 >= xmin);
assert(clip.x1 <= xmax);
- alphas = fz_malloc(gel->ctx, xmax - xmin + 1);
- deltas = fz_malloc(gel->ctx, (xmax - xmin + 1) * sizeof(int));
+ alphas = fz_malloc(ctx, xmax - xmin + 1);
+ deltas = fz_malloc(ctx, (xmax - xmin + 1) * sizeof(int));
memset(deltas, 0, (xmax - xmin + 1) * sizeof(int));
e = 0;
@@ -611,7 +652,7 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, fz_bbox clip,
{
if (yd >= clip.y0 && yd < clip.y1)
{
- undelta_aa(alphas, deltas, skipx + clipn);
+ undelta_aa(ctxaa, alphas, deltas, skipx + clipn);
blit_aa(dst, xmin + skipx, yd, alphas + skipx, clipn, color);
memset(deltas, 0, (skipx + clipn) * sizeof(int));
}
@@ -638,12 +679,12 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, fz_bbox clip,
if (yd >= clip.y0 && yd < clip.y1)
{
- undelta_aa(alphas, deltas, skipx + clipn);
+ undelta_aa(ctxaa, alphas, deltas, skipx + clipn);
blit_aa(dst, xmin + skipx, yd, alphas + skipx, clipn, color);
}
- fz_free(gel->ctx, deltas);
- fz_free(gel->ctx, alphas);
+ fz_free(ctx, deltas);
+ fz_free(ctx, alphas);
}
/*
@@ -730,6 +771,8 @@ void
fz_scan_convert(fz_gel *gel, int eofill, fz_bbox clip,
fz_pixmap *dst, unsigned char *color)
{
+ fz_aa_context *ctxaa = gel->ctx->aa;
+
if (fz_aa_level > 0)
fz_scan_convert_aa(gel, eofill, clip, dst, color);
else
diff --git a/fitz/base_context.c b/fitz/base_context.c
index 2986a8f8..d828509e 100644
--- a/fitz/base_context.c
+++ b/fitz/base_context.c
@@ -15,6 +15,7 @@ fz_free_context(fz_context *ctx)
return;
/* Other finalisation calls go here (in reverse order) */
+ fz_free_aa_context(ctx);
fz_free_font_context(ctx);
if (ctx->error)
@@ -54,6 +55,7 @@ fz_new_context(fz_alloc_context *alloc)
fz_try(ctx)
{
fz_new_font_context(ctx);
+ fz_new_aa_context(ctx);
}
fz_catch(ctx)
{
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 1ae803a4..c3c33487 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -139,6 +139,7 @@ typedef struct fz_alloc_context_s fz_alloc_context;
typedef struct fz_error_context_s fz_error_context;
typedef struct fz_warn_context_s fz_warn_context;
typedef struct fz_font_context_s fz_font_context;
+typedef struct fz_aa_context_s fz_aa_context;
typedef struct fz_context_s fz_context;
struct fz_alloc_context_s
@@ -191,12 +192,16 @@ struct fz_context_s
fz_error_context *error;
fz_warn_context *warn;
fz_font_context *font;
+ fz_aa_context *aa;
};
fz_context *fz_new_context(fz_alloc_context *alloc);
fz_context *fz_clone_context(fz_context *ctx);
void fz_free_context(fz_context *ctx);
+void fz_new_aa_context(fz_context *ctx);
+void fz_free_aa_context(fz_context *ctx);
+
/*
* Basic runtime and utility functions
*/
@@ -1004,8 +1009,8 @@ void fz_free_glyph_cache(fz_context *ctx, fz_glyph_cache *);
* Scan converter
*/
-int fz_get_aa_level(void);
-void fz_set_aa_level(int bits);
+int fz_get_aa_level(fz_context *ctx);
+void fz_set_aa_level(fz_context *ctx, int bits);
typedef struct fz_gel_s fz_gel;
diff --git a/fitz/res_font.c b/fitz/res_font.c
index fa011d24..4b30d424 100644
--- a/fitz/res_font.c
+++ b/fitz/res_font.c
@@ -361,7 +361,7 @@ fz_render_ft_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm)
fz_warn(ctx, "freetype setting character size: %s", ft_error_string(fterr));
FT_Set_Transform(face, &m, &v);
- if (fz_get_aa_level() == 0)
+ if (fz_get_aa_level(ctx) == 0)
{
/* If you really want grid fitting, enable this code. */
float scale = fz_matrix_expansion(trm);
@@ -410,7 +410,7 @@ fz_render_ft_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix trm)
FT_Outline_Translate(&face->glyph->outline, -strength * 32, -strength * 32);
}
- fterr = FT_Render_Glyph(face->glyph, fz_get_aa_level() > 0 ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO);
+ fterr = FT_Render_Glyph(face->glyph, fz_get_aa_level(ctx) > 0 ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO);
if (fterr)
{
fz_warn(ctx, "freetype render glyph (gid %d): %s", gid, ft_error_string(fterr));
@@ -490,7 +490,7 @@ fz_render_ft_stroked_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix tr
FT_Stroker_Done(stroker);
- fterr = FT_Glyph_To_Bitmap(&glyph, fz_get_aa_level() > 0 ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, 0, 1);
+ fterr = FT_Glyph_To_Bitmap(&glyph, fz_get_aa_level(ctx) > 0 ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, 0, 1);
if (fterr)
{
fz_warn(ctx, "FT_Glyph_To_Bitmap: %s", ft_error_string(fterr));
diff --git a/scripts/cmapdump.c b/scripts/cmapdump.c
index af148765..be7a456e 100644
--- a/scripts/cmapdump.c
+++ b/scripts/cmapdump.c
@@ -180,3 +180,11 @@ void fz_new_font_context(fz_context *ctx)
void fz_free_font_context(fz_context *ctx)
{
}
+
+void fz_new_aa_context(fz_context *ctx)
+{
+}
+
+void fz_free_aa_context(fz_context *ctx)
+{
+}