diff options
author | Robin Watts <robin.watts@artifex.com> | 2014-03-11 19:04:17 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2014-03-17 19:38:40 +0000 |
commit | 551de42088c58dc69fba06fb53e36c2ddb12367f (patch) | |
tree | f073b5ac7d3dee2de2f5609a13fd9c47e605d3d8 /source/fitz/filter-jbig2.c | |
parent | 8fdcb140930c3027841af28a4632ce6d23aa44b6 (diff) | |
download | mupdf-551de42088c58dc69fba06fb53e36c2ddb12367f.tar.xz |
Rework fz_streams.
Currently fz_streams have a 4K buffer within their header. The call
to read from a stream fills this buffer, resulting in more data being
pulled from any underlying stream than we might like. This causes
problems with the forthcoming 'leech' filter.
Here we simplify the fields available in the public stream header.
No specific buffer is given; simply the read and write pointers.
The underlying 'read' function is replaced by a 'next' function
that makes the next block of data available and returns the first
character of it (or EOF).
A caller to the 'next' function should supply the maximum number of
bytes that it knows it will need (possibly not now, but eventually).
This enables the underlying stream to efficiently decode just enough.
The underlying stream is free to return fewer, or a greater number
if it wants to.
The exact size of the 'block' of data returned will depend on the
filter in use and (possibly) the data therein.
Callers can get the currently available amount of data by calling
fz_available (but again should pass the maximum amount of data they know
they will need). The only time this will ever return 0 is if we have
hit EOF.
Diffstat (limited to 'source/fitz/filter-jbig2.c')
-rw-r--r-- | source/fitz/filter-jbig2.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/source/fitz/filter-jbig2.c b/source/fitz/filter-jbig2.c index 592f7ab6..98919dcb 100644 --- a/source/fitz/filter-jbig2.c +++ b/source/fitz/filter-jbig2.c @@ -17,6 +17,7 @@ struct fz_jbig2d_s fz_jbig2_globals *gctx; Jbig2Image *page; int idx; + unsigned char buffer[4096]; }; static void @@ -39,15 +40,20 @@ close_jbig2d(fz_context *ctx, void *state_) } static int -read_jbig2d(fz_stream *stm, unsigned char *buf, int len) +next_jbig2d(fz_stream *stm, int len) { fz_jbig2d *state = stm->state; unsigned char tmp[4096]; + unsigned char *buf = state->buffer; unsigned char *p = buf; - unsigned char *ep = buf + len; + unsigned char *ep; unsigned char *s; int x, w, n; + if (len > sizeof(state->buffer)) + len = sizeof(state->buffer); + ep = buf + len; + if (!state->page) { while (1) @@ -72,7 +78,12 @@ read_jbig2d(fz_stream *stm, unsigned char *buf, int len) *p++ = s[x++] ^ 0xff; state->idx = x; - return p - buf; + stm->rp = buf; + stm->wp = p; + if (p == buf) + return EOF; + stm->pos += p - buf; + return *stm->rp++; } static fz_stream * @@ -146,5 +157,5 @@ fz_open_jbig2d(fz_stream *chain, fz_jbig2_globals *globals) fz_rethrow(ctx); } - return fz_new_stream(ctx, state, read_jbig2d, close_jbig2d, rebind_jbig2d); + return fz_new_stream(ctx, state, next_jbig2d, close_jbig2d, rebind_jbig2d); } |