summaryrefslogtreecommitdiff
path: root/fitz/filt_predict.c
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2010-08-02 12:31:39 +0000
committerTor Andersson <tor@ghostscript.com>2010-08-02 12:31:39 +0000
commit51790988f8409bd636714316fd4bccac63252d3f (patch)
tree4d2c9d63680d4449d735b34c36fa42764eeae0dd /fitz/filt_predict.c
parent28a0e6c34e956fa0e37521647a61a41d096fbc75 (diff)
downloadmupdf-51790988f8409bd636714316fd4bccac63252d3f.tar.xz
Use 'while (rp < wp)' idiom for filter output buffering state.
Diffstat (limited to 'fitz/filt_predict.c')
-rw-r--r--fitz/filt_predict.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/fitz/filt_predict.c b/fitz/filt_predict.c
index b0ef8d3c..ae2d1aaf 100644
--- a/fitz/filt_predict.c
+++ b/fitz/filt_predict.c
@@ -20,7 +20,7 @@ struct fz_predict_s
unsigned char *in;
unsigned char *out;
unsigned char *ref;
- int outlen, outidx;
+ unsigned char *rp, *wp;
};
static inline int
@@ -145,13 +145,14 @@ readpredict(fz_stream *stm, unsigned char *buf, int len)
{
fz_predict *state = stm->state;
unsigned char *p = buf;
+ unsigned char *ep = buf + len;
int ispng = state->predictor >= 10;
int n;
- while (state->outidx < state->outlen && p < buf + len)
- *p++ = state->out[state->outidx++];
+ while (state->rp < state->wp && p < ep)
+ *p++ = *state->rp++;
- while (p < buf + len)
+ while (p < ep)
{
n = fz_read(state->chain, state->in, state->stride + ispng);
if (n < 0)
@@ -169,11 +170,11 @@ readpredict(fz_stream *stm, unsigned char *buf, int len)
memcpy(state->ref, state->out, state->stride);
}
- state->outlen = n - ispng;
- state->outidx = 0;
+ state->rp = state->out;
+ state->wp = state->out + n - ispng;
- while (state->outidx < state->outlen && p < buf + len)
- *p++ = state->out[state->outidx++];
+ while (state->rp < state->wp && p < ep)
+ *p++ = *state->rp++;
}
return p - buf;
@@ -235,8 +236,8 @@ fz_openpredict(fz_stream *chain, fz_obj *params)
state->in = fz_malloc(state->stride + 1);
state->out = fz_malloc(state->stride);
state->ref = fz_malloc(state->stride);
- state->outlen = 0;
- state->outidx = 0;
+ state->rp = state->out;
+ state->wp = state->out;
memset(state->ref, 0, state->stride);