summaryrefslogtreecommitdiff
path: root/fitz/fitz.h
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2010-07-29 23:17:46 +0000
committerTor Andersson <tor@ghostscript.com>2010-07-29 23:17:46 +0000
commitd797d4707564bd9c0e1536d1d6355945aa1be740 (patch)
treeb6aef992de0ce2aa306c4dd330512852c1a63ede /fitz/fitz.h
parent0b954421d7908c8b835d96b4a945418c2ae08de7 (diff)
downloadmupdf-d797d4707564bd9c0e1536d1d6355945aa1be740.tar.xz
Use chained reader like interface for filters instead of process interface.
Diffstat (limited to 'fitz/fitz.h')
-rw-r--r--fitz/fitz.h208
1 files changed, 54 insertions, 154 deletions
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 89a1cc63..696a9017 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -440,17 +440,7 @@ void fz_debugobj(fz_obj *obj);
char *fz_objkindstr(fz_obj *obj);
/*
- * Data buffers for streams and filters.
- *
- * bp is the pointer to the allocated memory
- * rp is read-position (*in->rp++ to read data)
- * wp is write-position (*out->wp++ to write data)
- * ep is the sentinel
- *
- * Only the data between rp and wp is valid data.
- *
- * Writers set eof to true at the end.
- * Readers look at eof.
+ * Data buffers.
*
* A buffer owns the memory it has allocated, unless ownsdata is false,
* in which case the creator of the buffer owns it.
@@ -463,112 +453,22 @@ typedef struct fz_buffer_s fz_buffer;
struct fz_buffer_s
{
int refs;
- int ownsdata;
- unsigned char *bp;
- unsigned char *rp;
- unsigned char *wp;
- unsigned char *ep;
- int eof;
+ unsigned char *data;
+ int cap, len;
};
fz_buffer * fz_newbuffer(int size);
fz_buffer * fz_newbufferwithmemory(unsigned char *data, int size);
void fz_resizebuffer(fz_buffer *buf, int size);
-void fz_rewindbuffer(fz_buffer *buf);
void fz_growbuffer(fz_buffer *buf);
fz_buffer *fz_keepbuffer(fz_buffer *buf);
void fz_dropbuffer(fz_buffer *buf);
/*
- * Data filters for encryption, compression and decompression.
- *
- * A filter has one method, process, that takes an input and an output buffer.
- *
- * It returns one of three statuses:
- * ioneedin -- input buffer exhausted, please give me more data (wp-rp)
- * ioneedout -- output buffer exhausted, please provide more space (ep-wp)
- * iodone -- finished, please never call me again. ever!
- * or...
- * any other error code -- oops, something blew up.
- *
- * To make using the filter easier, three variables are updated:
- * produced -- if we actually produced any new data
- * consumed -- like above
- * count -- number of bytes produced in total since the beginning
- * done -- remember if we've ever returned fz_iodone
- *
- * Most filters take fz_obj as a way to specify parameters.
- * In most cases, this is a dictionary that contains the same keys
- * that the corresponding PDF filter would expect.
- *
- * The pipeline filter is special, and needs some care when chaining
- * and unchaining new filters.
- */
-
-typedef struct fz_filter_s fz_filter;
-
-#define fz_ioneedin ((fz_error)1)
-#define fz_ioneedout ((fz_error)2)
-#define fz_iodone ((fz_error)3)
-
-/*
- * Evil looking macro to create an initialize a filter struct.
- */
-
-#define FZ_NEWFILTER(TYPE,VAR,NAME) \
- fz_error fz_process ## NAME (fz_filter*,fz_buffer*,fz_buffer*); \
- void fz_drop ## NAME (fz_filter*); \
- TYPE *VAR; \
- VAR = fz_malloc(sizeof(TYPE)); \
- ((fz_filter*)VAR)->refs = 1; \
- ((fz_filter*)VAR)->process = fz_process ## NAME ; \
- ((fz_filter*)VAR)->drop = fz_drop ## NAME ; \
- ((fz_filter*)VAR)->consumed = 0; \
- ((fz_filter*)VAR)->produced = 0; \
- ((fz_filter*)VAR)->count = 0; \
- ((fz_filter*)VAR)->done = 0;
-
-struct fz_filter_s
-{
- int refs;
- fz_error (*process)(fz_filter *filter, fz_buffer *in, fz_buffer *out);
- void (*drop)(fz_filter *filter);
- int consumed;
- int produced;
- int count;
- int done;
-};
-
-fz_error fz_process(fz_filter *f, fz_buffer *in, fz_buffer *out);
-fz_filter *fz_keepfilter(fz_filter *f);
-void fz_dropfilter(fz_filter *f);
-
-fz_filter * fz_newpipeline(fz_filter *head, fz_filter *tail);
-fz_filter * fz_chainpipeline(fz_filter *head, fz_filter *tail, fz_buffer *buf);
-void fz_unchainpipeline(fz_filter *pipe, fz_filter **oldfp, fz_buffer **oldbp);
-
-fz_filter * fz_newnullfilter(int len);
-fz_filter * fz_newcopyfilter();
-fz_filter * fz_newarc4filter(unsigned char *key, unsigned keylen);
-fz_filter * fz_newaesdfilter(unsigned char *key, unsigned keylen);
-fz_filter * fz_newa85d(fz_obj *param);
-fz_filter * fz_newahxd(fz_obj *param);
-fz_filter * fz_newrld(fz_obj *param);
-fz_filter * fz_newdctd(fz_obj *param);
-fz_filter * fz_newfaxd(fz_obj *param);
-fz_filter * fz_newflated(fz_obj *param);
-fz_filter * fz_newlzwd(fz_obj *param);
-fz_filter * fz_newpredictd(fz_obj *param);
-fz_filter * fz_newjbig2d(fz_obj *param);
-fz_filter * fz_newjpxd(fz_obj *param);
-
-fz_error fz_setjbig2dglobalstream(fz_filter *filter, unsigned char *buf, int len);
-
-/*
- * Stream API for Fitz.
- * Read and write data to and from files, memory buffers and filters.
+ * Buffered reader.
+ * Only the data between rp and wp is valid data.
*/
typedef struct fz_stream_s fz_stream;
@@ -578,77 +478,77 @@ enum { FZ_SFILE, FZ_SBUFFER, FZ_SFILTER };
struct fz_stream_s
{
int refs;
- int kind;
int dead;
- fz_buffer *buffer;
- fz_filter *filter;
- fz_stream *chain;
- fz_error error; /* delayed error from readbyte and peekbyte */
- int file;
+ int pos;
+ unsigned char *bp, *rp, *wp, *ep;
+ void *state;
+ int (*read)(fz_stream *stm, unsigned char *buf, int len);
+ void (*close)(fz_stream *stm);
+ void (*seek)(fz_stream *stm, int offset, int whence);
+ unsigned char buf[4096];
};
-/*
- * Various stream creation functions.
- */
-
-fz_stream * fz_openfile(int file);
-fz_stream * fz_openmemory(unsigned char *mem, int len);
-fz_stream * fz_openbuffer(fz_buffer *buf);
-fz_stream * fz_openfilter(fz_filter *flt, fz_stream *chain);
-
-/*
- * Functions that are common to both input and output streams.
- */
+fz_stream *fz_openfile(int file);
+fz_stream *fz_openbuffer(fz_buffer *buf);
+void fz_close(fz_stream *stm);
+fz_stream *fz_newstream(void*, int(*)(fz_stream*, unsigned char*, int), void(*)(fz_stream *));
fz_stream *fz_keepstream(fz_stream *stm);
-void fz_dropstream(fz_stream *stm);
+void fz_fillbuffer(fz_stream *stm);
int fz_tell(fz_stream *stm);
-fz_error fz_seek(fz_stream *stm, int offset, int whence);
-
-/*
- * Input stream functions.
- */
+void fz_seek(fz_stream *stm, int offset, int whence);
-fz_error fz_readimp(fz_stream *stm);
-fz_error fz_read(int *np, fz_stream *stm, unsigned char *buf, int len);
-fz_error fz_readline(fz_stream *stm, char *buf, int max);
-fz_buffer * fz_readall(fz_stream *stm, int sizehint);
-
-/*
- * Error handling when reading with readbyte/peekbyte is non-standard.
- * The cause of an error is stuck into the stream struct,
- * and EOF is returned. Not good, but any other way is too painful.
- * So we have to be careful to check the error status eventually.
- */
-
-fz_error fz_readerror(fz_stream *stm);
-int fz_readbytex(fz_stream *stm);
-int fz_peekbytex(fz_stream *stm);
+int fz_read(fz_stream *stm, unsigned char *buf, int len);
+void fz_readline(fz_stream *stm, char *buf, int max);
+fz_error fz_readall(fz_buffer **bufp, fz_stream *stm);
static inline int fz_readbyte(fz_stream *stm)
{
- fz_buffer *buf = stm->buffer;
- if (buf->rp < buf->wp)
- return *buf->rp++;
- return fz_readbytex(stm);
+ if (stm->rp == stm->wp)
+ {
+ fz_fillbuffer(stm);
+ return stm->rp < stm->wp ? *stm->rp++ : EOF;
+ }
+ return *stm->rp++;
}
static inline int fz_peekbyte(fz_stream *stm)
{
- fz_buffer *buf = stm->buffer;
- if (buf->rp < buf->wp)
- return *buf->rp;
- return fz_peekbytex(stm);
+ if (stm->rp == stm->wp)
+ {
+ fz_fillbuffer(stm);
+ return stm->rp < stm->wp ? *stm->rp : EOF;
+ }
+ return *stm->rp;
}
static inline void fz_unreadbyte(fz_stream *stm)
{
- fz_buffer *buf = stm->buffer;
- buf->rp--;
+ if (stm->rp > stm->bp)
+ stm->rp--;
}
/*
+ * Data filters.
+ */
+
+fz_stream * fz_opencopy(fz_stream *chain);
+fz_stream * fz_opennull(fz_stream *chain, int len);
+fz_stream * fz_openarc4(fz_stream *chain, unsigned char *key, unsigned keylen);
+fz_stream * fz_openaesd(fz_stream *chain, unsigned char *key, unsigned keylen);
+fz_stream * fz_opena85d(fz_stream *chain);
+fz_stream * fz_openahxd(fz_stream *chain);
+fz_stream * fz_openrld(fz_stream *chain);
+fz_stream * fz_opendctd(fz_stream *chain, fz_obj *param);
+fz_stream * fz_openfaxd(fz_stream *chain, fz_obj *param);
+fz_stream * fz_openflated(fz_stream *chain);
+fz_stream * fz_openlzwd(fz_stream *chain, fz_obj *param);
+fz_stream * fz_openpredict(fz_stream *chain, fz_obj *param);
+fz_stream * fz_openjbig2d(fz_stream *chain, fz_buffer *global);
+fz_stream * fz_openjpxd(fz_stream *chain);
+
+/*
* Resources and other graphics related objects.
*/