summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2015-05-24 11:45:01 +0200
committerSebastian Rasmussen <sebras@gmail.com>2015-07-29 12:40:57 +0200
commitc680270bdeae2f9eea93b604b63330b48cf4442e (patch)
tree88615bf838451a1f432871a12b36a3148ddf1533
parenta414db2d3f579ce6b6b1d55d1c9110b12dd230c3 (diff)
downloadmupdf-c680270bdeae2f9eea93b604b63330b48cf4442e.tar.xz
Support reading stream bits in reverse order.
-rw-r--r--include/mupdf/fitz/stream.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/include/mupdf/fitz/stream.h b/include/mupdf/fitz/stream.h
index 21958b8a..64f3d704 100644
--- a/include/mupdf/fitz/stream.h
+++ b/include/mupdf/fitz/stream.h
@@ -340,6 +340,46 @@ static inline unsigned int fz_read_bits(fz_context *ctx, fz_stream *stm, int n)
return x;
}
+static inline unsigned int fz_read_rbits(fz_context *ctx, fz_stream *stm, int n)
+{
+ unsigned int x;
+
+ if (n <= stm->avail)
+ {
+ x = stm->bits & ((1 << n) - 1);
+ stm->avail -= n;
+ stm->bits = stm->bits >> n;
+
+ }
+ else
+ {
+ unsigned int used = 0;
+
+ x = stm->bits & ((1 << stm->avail) - 1);
+ n -= stm->avail;
+ used = stm->avail;
+ stm->avail = 0;
+
+ while (n > 8)
+ {
+
+ x = (fz_read_byte(ctx, stm) << used) | x;
+ n -= 8;
+ used += 8;
+ }
+
+ if (n > 0)
+ {
+ stm->bits = fz_read_byte(ctx, stm);
+ x = ((stm->bits & ((1 << n) - 1)) << used) | x;
+ stm->avail = 8 - n;
+ stm->bits = stm->bits >> n;
+ }
+ }
+
+ return x;
+}
+
static inline void fz_sync_bits(fz_context *ctx, fz_stream *stm)
{
stm->avail = 0;