diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2018-01-03 15:11:33 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2018-01-04 13:15:42 +0100 |
commit | 2d5b4683e912d6e6e1f1e2ca5aa0297beb3e6807 (patch) | |
tree | de2343f1280afd1ae32a1b8d7805a42f0fc5f8e7 /source/fitz/context.c | |
parent | a292539cc9e5e91843d48e691038d9c1b529422c (diff) | |
download | mupdf-2d5b4683e912d6e6e1f1e2ca5aa0297beb3e6807.tar.xz |
Add portable pseudo-random number generator based on the lrand48 family.
Diffstat (limited to 'source/fitz/context.c')
-rw-r--r-- | source/fitz/context.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/source/fitz/context.c b/source/fitz/context.c index f4ebdc98..67fef05b 100644 --- a/source/fitz/context.c +++ b/source/fitz/context.c @@ -3,6 +3,7 @@ #include <assert.h> #include <string.h> #include <stdio.h> +#include <time.h> struct fz_id_context_s { @@ -132,6 +133,22 @@ void fz_tune_image_scale(fz_context *ctx, fz_tune_image_scale_fn *image_scale, v ctx->tuning->image_scale_arg = arg; } +static void fz_init_random_context(fz_context *ctx) +{ + if (!ctx) + return; + + ctx->seed48[0] = 0; + ctx->seed48[1] = 0; + ctx->seed48[2] = 0; + ctx->seed48[3] = 0xe66d; + ctx->seed48[4] = 0xdeec; + ctx->seed48[5] = 0x5; + ctx->seed48[6] = 0xb; + + fz_srand48(ctx, (uint32_t)time(NULL)); +} + void fz_drop_context(fz_context *ctx) { @@ -250,6 +267,7 @@ fz_new_context_imp(const fz_alloc_context *alloc, const fz_locks_context *locks, fz_new_document_handler_context(ctx); fz_new_style_context(ctx); fz_new_tuning_context(ctx); + fz_init_random_context(ctx); } fz_catch(ctx) { @@ -304,6 +322,7 @@ fz_clone_context_internal(fz_context *ctx) new_ctx->id = fz_keep_id_context(new_ctx); new_ctx->tuning = ctx->tuning; new_ctx->tuning = fz_keep_tuning_context(new_ctx); + memcpy(new_ctx->seed48, ctx->seed48, sizeof ctx->seed48); new_ctx->handler = ctx->handler; new_ctx->handler = fz_keep_document_handler_context(new_ctx); |