summaryrefslogtreecommitdiff
path: root/fitz/fitz.h
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2011-02-23 23:43:55 +0000
committerTor Andersson <tor@ghostscript.com>2011-02-23 23:43:55 +0000
commit7aab191974af3c05d8c2d6595378f6c6e7899b3e (patch)
tree432ad05f56d99b8d258537631b874ebd6bb31dfe /fitz/fitz.h
parent26eb1c46ea350777e9a6970c576bcfb03abba948 (diff)
downloadmupdf-7aab191974af3c05d8c2d6595378f6c6e7899b3e.tar.xz
Add bitstream reader functions.
Diffstat (limited to 'fitz/fitz.h')
-rw-r--r--fitz/fitz.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 685a75f3..bea851fa 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -499,6 +499,8 @@ struct fz_stream_s
int refs;
int dead;
int pos;
+ int avail;
+ int bits;
unsigned char *bp, *rp, *wp, *ep;
void *state;
int (*read)(fz_stream *stm, unsigned char *buf, int len);
@@ -548,6 +550,38 @@ static inline void fz_unreadbyte(fz_stream *stm)
stm->rp--;
}
+static inline unsigned int fz_readbits(fz_stream *stm, int n)
+{
+ unsigned int x;
+
+ if (n <= stm->avail)
+ {
+ stm->avail -= n;
+ x = (stm->bits >> stm->avail) & ((1 << n) - 1);
+ }
+ else
+ {
+ x = stm->bits & ((1 << stm->avail) - 1);
+ n -= stm->avail;
+ stm->avail = 0;
+
+ while (n > 8)
+ {
+ x = (x << 8) | fz_readbyte(stm);
+ n -= 8;
+ }
+
+ if (n > 0)
+ {
+ stm->bits = fz_readbyte(stm);
+ stm->avail = 8 - n;
+ x = (x << n) | (stm->bits >> stm->avail);
+ }
+ }
+
+ return x;
+}
+
/*
* Data filters.
*/