diff options
author | Robin Watts <robin.watts@artifex.com> | 2016-04-12 13:17:02 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2016-04-28 12:30:41 +0100 |
commit | 3dc16d54db4669415412bb44790d4653962747f6 (patch) | |
tree | f45096e35afbd29f22e4e2c7c2a16c61ec9da468 /source/fitz/context.c | |
parent | b944f16a564f8a31d9a064980318ad690be31f8e (diff) | |
download | mupdf-3dc16d54db4669415412bb44790d4653962747f6.tar.xz |
Introduce tuning context.
For now, just use it for controlling image decoding and image scaling.
Diffstat (limited to 'source/fitz/context.c')
-rw-r--r-- | source/fitz/context.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/source/fitz/context.c b/source/fitz/context.c index 0f9a8b77..bfc7a1cd 100644 --- a/source/fitz/context.c +++ b/source/fitz/context.c @@ -76,6 +76,46 @@ const char *fz_user_css(fz_context *ctx) return ctx->style->user_css; } +static void fz_new_tuning_context(fz_context *ctx) +{ + if (ctx) + { + ctx->tuning = fz_malloc_struct(ctx, fz_tuning_context); + ctx->tuning->refs = 1; + ctx->tuning->image_decode = &fz_default_image_decode; + ctx->tuning->image_scale = &fz_default_image_scale; + } +} + +static fz_tuning_context *fz_keep_tuning_context(fz_context *ctx) +{ + if (!ctx) + return NULL; + return fz_keep_imp(ctx, ctx->tuning, &ctx->tuning->refs); +} + +static void fz_drop_tuning_context(fz_context *ctx) +{ + if (!ctx) + return; + if (fz_drop_imp(ctx, ctx->tuning, &ctx->tuning->refs)) + { + fz_free(ctx, ctx->tuning); + } +} + +void fz_tune_image_decode(fz_context *ctx, fz_tune_image_decode_fn *image_decode, void *arg) +{ + ctx->tuning->image_decode = image_decode ? image_decode : fz_default_image_decode; + ctx->tuning->image_decode_arg = arg; +} + +void fz_tune_image_scale(fz_context *ctx, fz_tune_image_scale_fn *image_scale, void *arg) +{ + ctx->tuning->image_scale = image_scale ? image_scale : fz_default_image_scale; + ctx->tuning->image_scale_arg = arg; +} + void fz_drop_context(fz_context *ctx) { @@ -88,6 +128,7 @@ fz_drop_context(fz_context *ctx) fz_drop_store_context(ctx); fz_drop_aa_context(ctx); fz_drop_style_context(ctx); + fz_drop_tuning_context(ctx); fz_drop_colorspace_context(ctx); fz_drop_font_context(ctx); fz_drop_id_context(ctx); @@ -188,6 +229,7 @@ fz_new_context_imp(const fz_alloc_context *alloc, const fz_locks_context *locks, fz_new_id_context(ctx); fz_new_document_handler_context(ctx); fz_new_style_context(ctx); + fz_new_tuning_context(ctx); } fz_catch(ctx) { @@ -237,6 +279,8 @@ fz_clone_context_internal(fz_context *ctx) new_ctx->style = fz_keep_style_context(new_ctx); new_ctx->id = ctx->id; new_ctx->id = fz_keep_id_context(new_ctx); + new_ctx->tuning = ctx->tuning; + new_ctx->tuning = fz_keep_tuning_context(new_ctx); new_ctx->handler = ctx->handler; new_ctx->handler = fz_keep_document_handler_context(new_ctx); |