summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile143
-rw-r--r--Makethird113
-rw-r--r--apps/mozilla/moz_main.c2
-rw-r--r--apps/pdfapp.c4
-rw-r--r--apps/pdfdraw.c8
-rw-r--r--draw/glyphcache.c2
-rw-r--r--fitz/base_geometry.c (renamed from fitz/base_matrix.c)102
-rw-r--r--fitz/base_getopt.c (renamed from fitz/util_getopt.c)0
-rw-r--r--fitz/base_hash.c6
-rw-r--r--fitz/base_memory.c23
-rw-r--r--fitz/base_rect.c50
-rw-r--r--fitz/base_string.c191
-rw-r--r--fitz/base_time.c (renamed from fitz/util_gettimeofday.c)0
-rw-r--r--fitz/base_unicode.c179
-rw-r--r--fitz/dev_list.c2
-rw-r--r--fitz/filt_aesd.c69
-rw-r--r--fitz/filt_arc4.c46
-rw-r--r--fitz/filt_basic.c154
-rw-r--r--fitz/filt_faxd.c176
-rw-r--r--fitz/filt_faxd.h61
-rw-r--r--fitz/filt_faxdtab.c932
-rw-r--r--fitz/fitz.h1157
-rw-r--r--fitz/fitz_base.h252
-rw-r--r--fitz/fitz_draw.h519
-rw-r--r--fitz/fitz_stream.h398
-rw-r--r--fitz/obj_array.c2
-rw-r--r--fitz/res_font.c2
-rw-r--r--fitz/stm_misc.c92
-rw-r--r--fitz/stm_open.c4
-rw-r--r--fitz/stm_read.c91
-rw-r--r--mupdf/pdf_interpret.c8
-rw-r--r--mupdf/pdf_pattern.c2
-rw-r--r--mupdf/pdf_shade.c6
-rw-r--r--mupdf/pdf_xobject.c2
-rw-r--r--win32/mupdf/mupdf.vcproj50
35 files changed, 2026 insertions, 2822 deletions
diff --git a/Makefile b/Makefile
index e0545614..a288afdf 100644
--- a/Makefile
+++ b/Makefile
@@ -72,40 +72,101 @@ $(CMAPDUMP_EXE): $(OBJDIR)/cmapdump.o
# Sources
#
-FITZ_HDR := fitz/fitz.h fitz/fitz_base.h fitz/fitz_draw.h fitz/fitz_stream.h
-FITZ_SRC := $(addprefix fitz/, \
- base_error.c base_memory.c base_string.c base_unicode.c \
- base_hash.c base_matrix.c base_rect.c \
- crypt_aes.c crypt_arc4.c crypt_md5.c \
- filt_aesd.c filt_arc4.c filt_basic.c \
- filt_dctd.c filt_faxd.c filt_faxdtab.c filt_flate.c \
- filt_jbig2d.c filt_jpxd.c filt_lzwd.c filt_pipeline.c filt_predict.c \
- dev_null.c dev_text.c dev_draw.c dev_bbox.c dev_list.c dev_trace.c \
- obj_array.c obj_dict.c obj_print.c obj_simple.c \
- res_colorspace.c res_font.c res_shade.c res_pixmap.c \
- res_path.c res_text.c \
- stm_buffer.c stm_filter.c stm_misc.c stm_open.c stm_read.c \
- util_getopt.c util_gettimeofday.c )
+FITZ_HDR := fitz/fitz.h
+FITZ_SRC := \
+ fitz/base_error.c \
+ fitz/base_geometry.c \
+ fitz/base_getopt.c \
+ fitz/base_hash.c \
+ fitz/base_memory.c \
+ fitz/base_string.c \
+ fitz/base_time.c \
+ fitz/crypt_aes.c \
+ fitz/crypt_arc4.c \
+ fitz/crypt_md5.c \
+ fitz/dev_bbox.c \
+ fitz/dev_draw.c \
+ fitz/dev_list.c \
+ fitz/dev_null.c \
+ fitz/dev_text.c \
+ fitz/dev_trace.c \
+ fitz/filt_basic.c \
+ fitz/filt_dctd.c \
+ fitz/filt_faxd.c \
+ fitz/filt_flate.c \
+ fitz/filt_jbig2d.c \
+ fitz/filt_jpxd.c \
+ fitz/filt_lzwd.c \
+ fitz/filt_pipeline.c \
+ fitz/filt_predict.c \
+ fitz/obj_array.c \
+ fitz/obj_dict.c \
+ fitz/obj_print.c \
+ fitz/obj_simple.c \
+ fitz/res_colorspace.c \
+ fitz/res_font.c \
+ fitz/res_path.c \
+ fitz/res_pixmap.c \
+ fitz/res_shade.c \
+ fitz/res_text.c \
+ fitz/stm_buffer.c \
+ fitz/stm_filter.c \
+ fitz/stm_open.c \
+ fitz/stm_read.c
FITZ_OBJ := $(FITZ_SRC:fitz/%.c=$(OBJDIR)/%.o)
$(FITZ_OBJ): $(FITZ_HDR)
-DRAW_SRC := $(addprefix draw/, $(DRAW_ARCH_SRC) \
- archport.c blendmodes.c glyphcache.c \
- imagedraw.c imagescale.c imageunpack.c meshdraw.c \
- pathfill.c pathscan.c pathstroke.c porterduff.c )
+DRAW_SRC := $(DRAW_ARCH_SRC) \
+ draw/archport.c \
+ draw/blendmodes.c \
+ draw/glyphcache.c \
+ draw/imagedraw.c \
+ draw/imagescale.c \
+ draw/imageunpack.c \
+ draw/meshdraw.c \
+ draw/pathfill.c \
+ draw/pathscan.c \
+ draw/pathstroke.c \
+ draw/porterduff.c
DRAW_OBJ := $(DRAW_SRC:draw/%.c=$(OBJDIR)/%.o)
DRAW_OBJ := $(DRAW_OBJ:draw/%.s=$(OBJDIR)/%.o)
$(DRAW_OBJ): $(FITZ_HDR)
MUPDF_HDR := $(FITZ_HDR) mupdf/mupdf.h
-MUPDF_SRC := $(addprefix mupdf/, \
- pdf_annot.c pdf_build.c pdf_cmap.c pdf_cmap_load.c pdf_cmap_parse.c \
- pdf_cmap_table.c pdf_colorspace.c pdf_crypt.c pdf_debug.c \
- pdf_font.c pdf_fontagl.c pdf_fontenc.c pdf_fontfile.c pdf_fontmtx.c \
- pdf_function.c pdf_image.c pdf_interpret.c pdf_lex.c pdf_nametree.c \
- pdf_open.c pdf_outline.c pdf_page.c pdf_pagetree.c pdf_parse.c \
- pdf_pattern.c pdf_repair.c pdf_shade.c pdf_store.c pdf_stream.c \
- pdf_type3.c pdf_unicode.c pdf_xobject.c pdf_xref.c )
+MUPDF_SRC := \
+ mupdf/pdf_annot.c \
+ mupdf/pdf_build.c \
+ mupdf/pdf_cmap.c \
+ mupdf/pdf_cmap_load.c \
+ mupdf/pdf_cmap_parse.c \
+ mupdf/pdf_cmap_table.c \
+ mupdf/pdf_colorspace.c \
+ mupdf/pdf_crypt.c \
+ mupdf/pdf_debug.c \
+ mupdf/pdf_font.c \
+ mupdf/pdf_fontagl.c \
+ mupdf/pdf_fontenc.c \
+ mupdf/pdf_fontfile.c \
+ mupdf/pdf_fontmtx.c \
+ mupdf/pdf_function.c \
+ mupdf/pdf_image.c \
+ mupdf/pdf_interpret.c \
+ mupdf/pdf_lex.c \
+ mupdf/pdf_nametree.c \
+ mupdf/pdf_open.c \
+ mupdf/pdf_outline.c \
+ mupdf/pdf_page.c \
+ mupdf/pdf_pagetree.c \
+ mupdf/pdf_parse.c \
+ mupdf/pdf_pattern.c \
+ mupdf/pdf_repair.c \
+ mupdf/pdf_shade.c \
+ mupdf/pdf_store.c \
+ mupdf/pdf_stream.c \
+ mupdf/pdf_type3.c \
+ mupdf/pdf_unicode.c \
+ mupdf/pdf_xobject.c \
+ mupdf/pdf_xref.c
MUPDF_OBJ := $(MUPDF_SRC:mupdf/%.c=$(OBJDIR)/%.o)
$(MUPDF_OBJ): $(MUPDF_HDR)
@@ -124,17 +185,25 @@ $(OBJDIR)/%.o: $(GENDIR)/%.c
# Generated font file dumps
#
-BASEFONT_FILES := $(addprefix fonts/, \
- Dingbats.cff \
- NimbusMonL-Bold.cff NimbusMonL-BoldObli.cff \
- NimbusMonL-Regu.cff NimbusMonL-ReguObli.cff \
- NimbusRomNo9L-Medi.cff NimbusRomNo9L-MediItal.cff \
- NimbusRomNo9L-Regu.cff NimbusRomNo9L-ReguItal.cff \
- NimbusSanL-Bold.cff NimbusSanL-BoldItal.cff \
- NimbusSanL-Regu.cff NimbusSanL-ReguItal.cff \
- StandardSymL.cff URWChanceryL-MediItal.cff )
-
-CJKFONT_FILES := fonts/droid/DroidSansFallback.ttf
+BASEFONT_FILES := \
+ fonts/Dingbats.cff \
+ fonts/NimbusMonL-Bold.cff \
+ fonts/NimbusMonL-BoldObli.cff \
+ fonts/NimbusMonL-Regu.cff \
+ fonts/NimbusMonL-ReguObli.cff \
+ fonts/NimbusRomNo9L-Medi.cff \
+ fonts/NimbusRomNo9L-MediItal.cff \
+ fonts/NimbusRomNo9L-Regu.cff \
+ fonts/NimbusRomNo9L-ReguItal.cff \
+ fonts/NimbusSanL-Bold.cff \
+ fonts/NimbusSanL-BoldItal.cff \
+ fonts/NimbusSanL-Regu.cff \
+ fonts/NimbusSanL-ReguItal.cff \
+ fonts/StandardSymL.cff \
+ fonts/URWChanceryL-MediItal.cff
+
+CJKFONT_FILES := \
+ fonts/droid/DroidSansFallback.ttf
ifeq "$(pregen)" ""
diff --git a/Makethird b/Makethird
index d447a9d3..a8e3e516 100644
--- a/Makethird
+++ b/Makethird
@@ -17,11 +17,20 @@ THIRD_INCS += -I$(jbig2dec_dir)
LIBS := $(filter-out -ljbig2dec, $(LIBS))
JBIG2DEC_SRC=$(addprefix $(jbig2dec_dir)/, \
- jbig2.c jbig2_arith.c jbig2_arith_int.c jbig2_arith_iaid.c \
- jbig2_huffman.c jbig2_segment.c jbig2_page.c \
- jbig2_symbol_dict.c jbig2_text.c \
- jbig2_generic.c jbig2_refinement.c jbig2_mmr.c \
- jbig2_image.c jbig2_metadata.c )
+ jbig2.c \
+ jbig2_arith.c \
+ jbig2_arith_int.c \
+ jbig2_arith_iaid.c \
+ jbig2_huffman.c \
+ jbig2_segment.c \
+ jbig2_page.c \
+ jbig2_symbol_dict.c \
+ jbig2_text.c \
+ jbig2_generic.c \
+ jbig2_refinement.c \
+ jbig2_mmr.c \
+ jbig2_image.c \
+ jbig2_metadata.c )
JBIG2DEC_OBJ=$(JBIG2DEC_SRC:$(jbig2dec_dir)/%.c=$(OBJDIR)/%.o)
JBIG2DEC_LIB=$(OBJDIR)/libjbig2dec.a
$(JBIG2DEC_LIB): $(JBIG2DEC_OBJ)
@@ -38,10 +47,24 @@ THIRD_INCS += -I$(openjpeg_dir)
LIBS := $(filter-out -lopenjpeg, $(LIBS))
OPENJPEG_SRC=$(addprefix $(openjpeg_dir)/, \
- bio.c cio.c dwt.c event.c image.c \
- j2k.c j2k_lib.c jp2.c jpt.c mct.c \
- mqc.c openjpeg.c pi.c raw.c t1.c \
- t2.c tcd.c tgt.c )
+ bio.c \
+ cio.c \
+ dwt.c \
+ event.c \
+ image.c \
+ j2k.c \
+ j2k_lib.c \
+ jp2.c \
+ jpt.c \
+ mct.c \
+ mqc.c \
+ openjpeg.c \
+ pi.c \
+ raw.c \
+ t1.c \
+ t2.c \
+ tcd.c \
+ tgt.c )
OPENJPEG_OBJ=$(OPENJPEG_SRC:$(openjpeg_dir)/%.c=$(OBJDIR)/opj_%.o)
OPENJPEG_LIB=$(OBJDIR)/libopenjpeg.a
$(OPENJPEG_LIB): $(OPENJPEG_OBJ)
@@ -58,14 +81,52 @@ THIRD_INCS += -I$(jpeg_dir)
LIBS := $(filter-out -ljpeg, $(LIBS))
JPEG_SRC=$(addprefix $(jpeg_dir)/, \
- jaricom.c jcapimin.c jcapistd.c jcarith.c jccoefct.c jccolor.c \
- jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \
- jcomapi.c jcparam.c jcprepct.c jcsample.c jctrans.c jdapimin.c \
- jdapistd.c jdarith.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \
- jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \
- jdmerge.c jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c \
- jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jquant1.c \
- jquant2.c jutils.c jmemmgr.c jmemansi.c )
+ jaricom.c \
+ jcapimin.c \
+ jcapistd.c \
+ jcarith.c \
+ jccoefct.c \
+ jccolor.c \
+ jcdctmgr.c \
+ jchuff.c \
+ jcinit.c \
+ jcmainct.c \
+ jcmarker.c \
+ jcmaster.c \
+ jcomapi.c \
+ jcparam.c \
+ jcprepct.c \
+ jcsample.c \
+ jctrans.c \
+ jdapimin.c \
+ jdapistd.c \
+ jdarith.c \
+ jdatadst.c \
+ jdatasrc.c \
+ jdcoefct.c \
+ jdcolor.c \
+ jddctmgr.c \
+ jdhuff.c \
+ jdinput.c \
+ jdmainct.c \
+ jdmarker.c \
+ jdmaster.c \
+ jdmerge.c \
+ jdpostct.c \
+ jdsample.c \
+ jdtrans.c \
+ jerror.c \
+ jfdctflt.c \
+ jfdctfst.c \
+ jfdctint.c \
+ jidctflt.c \
+ jidctfst.c \
+ jidctint.c \
+ jquant1.c \
+ jquant2.c \
+ jutils.c \
+ jmemmgr.c \
+ jmemansi.c)
JPEG_OBJ=$(JPEG_SRC:$(jpeg_dir)/%.c=$(OBJDIR)/jpeg_%.o)
JPEG_LIB=$(OBJDIR)/libjpeg.a
$(JPEG_LIB): $(JPEG_OBJ)
@@ -82,9 +143,21 @@ THIRD_INCS += -I$(zlib_dir)
LIBS := $(filter-out -lz, $(LIBS))
ZLIB_SRC=$(addprefix $(zlib_dir)/, \
- adler32.c compress.c crc32.c deflate.c \
- gzclose.c gzlib.c gzread.c gzwrite.c \
- infback.c inffast.c inflate.c inftrees.c trees.c uncompr.c zutil.c )
+ adler32.c \
+ compress.c \
+ crc32.c \
+ deflate.c \
+ gzclose.c \
+ gzlib.c \
+ gzread.c \
+ gzwrite.c \
+ infback.c \
+ inffast.c \
+ inflate.c \
+ inftrees.c \
+ trees.c \
+ uncompr.c \
+ zutil.c )
ZLIB_OBJ=$(ZLIB_SRC:$(zlib_dir)/%.c=$(OBJDIR)/zlib_%.o)
ZLIB_LIB=$(OBJDIR)/libz.a
$(ZLIB_LIB): $(ZLIB_OBJ)
diff --git a/apps/mozilla/moz_main.c b/apps/mozilla/moz_main.c
index 551c34c1..b5ba7e7a 100644
--- a/apps/mozilla/moz_main.c
+++ b/apps/mozilla/moz_main.c
@@ -214,7 +214,7 @@ fz_matrix pdfmoz_pagectm(pdfmoz_t *moz, int pagenum)
zoom = (rc.right - rc.left) / (float) page->w;
- ctm = fz_identity();
+ ctm = fz_identity;
ctm = fz_concat(ctm, fz_translate(0, -page->page->mediabox.y1));
ctm = fz_concat(ctm, fz_scale(zoom, -zoom));
ctm = fz_concat(ctm, fz_rotate(page->page->rotate));
diff --git a/apps/pdfapp.c b/apps/pdfapp.c
index 608d62f9..92ce7dd3 100644
--- a/apps/pdfapp.c
+++ b/apps/pdfapp.c
@@ -200,7 +200,7 @@ void pdfapp_close(pdfapp_t *app)
static fz_matrix pdfapp_viewctm(pdfapp_t *app)
{
fz_matrix ctm;
- ctm = fz_identity();
+ ctm = fz_identity;
ctm = fz_concat(ctm, fz_translate(0, -app->page->mediabox.y1));
ctm = fz_concat(ctm, fz_scale(app->resolution/72.0f, -app->resolution/72.0f));
ctm = fz_concat(ctm, fz_rotate(app->rotate + app->page->rotate));
@@ -264,7 +264,7 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage)
/* Create display list */
app->page->list = fz_newdisplaylist();
mdev = fz_newlistdevice(app->page->list);
- error = pdf_runcontentstream(mdev, fz_identity(), app->xref, app->page->resources, app->page->contents);
+ error = pdf_runcontentstream(mdev, fz_identity, app->xref, app->page->resources, app->page->contents);
if (error)
{
error = fz_rethrow(error, "cannot draw page %d in '%s'", app->pageno, app->doctitle);
diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c
index 8608fe62..ebc51290 100644
--- a/apps/pdfdraw.c
+++ b/apps/pdfdraw.c
@@ -168,7 +168,7 @@ static void drawpnm(int pagenum, struct benchmark *loadtimes, struct benchmark *
if (benchmark)
gettime(&start);
- ctm = fz_identity();
+ ctm = fz_identity;
ctm = fz_concat(ctm, fz_translate(0, -drawpage->mediabox.y1));
ctm = fz_concat(ctm, fz_scale(drawzoom, -drawzoom));
ctm = fz_concat(ctm, fz_rotate(drawrotate + drawpage->rotate));
@@ -212,7 +212,7 @@ static void drawpnm(int pagenum, struct benchmark *loadtimes, struct benchmark *
fprintf(stdout, "creating display list for banded rendering\n");
list = fz_newdisplaylist();
dev = fz_newlistdevice(list);
- error = pdf_runcontentstream(dev, fz_identity(), xref, drawpage->resources, drawpage->contents);
+ error = pdf_runcontentstream(dev, fz_identity, xref, drawpage->resources, drawpage->contents);
if (error)
die(fz_rethrow(error, "cannot draw page %d in PDF file '%s'", pagenum, basename));
fz_freedevice(dev);
@@ -337,7 +337,7 @@ static void drawtxt(int pagenum, struct benchmark *loadtimes)
drawloadpage(pagenum, loadtimes);
- ctm = fz_identity();
+ ctm = fz_identity;
text = fz_newtextspan();
dev = fz_newtextdevice(text);
@@ -369,7 +369,7 @@ static void drawxml(int pagenum)
if (error)
die(fz_rethrow(error, "cannot load page %d (%d %d R) from PDF file '%s'", pagenum, fz_tonum(pageobj), fz_togen(pageobj), basename));
- ctm = fz_identity();
+ ctm = fz_identity;
dev = fz_newtracedevice();
printf("<?xml version=\"1.0\"?>\n");
diff --git a/draw/glyphcache.c b/draw/glyphcache.c
index e98373d9..10991bbf 100644
--- a/draw/glyphcache.c
+++ b/draw/glyphcache.c
@@ -33,7 +33,7 @@ fz_newglyphcache(void)
return cache;
}
-void
+static void
fz_evictglyphcache(fz_glyphcache *cache)
{
fz_glyphkey *key;
diff --git a/fitz/base_matrix.c b/fitz/base_geometry.c
index 7fd6009b..61ff88d9 100644
--- a/fitz/base_matrix.c
+++ b/fitz/base_geometry.c
@@ -3,40 +3,11 @@
#define MAX4(a,b,c,d) MAX(MAX(a,b), MAX(c,d))
#define MIN4(a,b,c,d) MIN(MIN(a,b), MIN(c,d))
-void fz_invert3x3(float *dst, float *m)
-{
- float det;
- int i;
-
-#define M3(m,i,j) (m)[3*i+j]
-#define D2(a,b,c,d) (a * d - b * c)
-#define D3(a1,a2,a3,b1,b2,b3,c1,c2,c3) \
- (a1 * D2(b2,b3,c2,c3)) - \
- (b1 * D2(a2,a3,c2,c3)) + \
- (c1 * D2(a2,a3,b2,b3))
-
- det = D3(M3(m,0,0), M3(m,1,0), M3(m,2,0),
- M3(m,0,1), M3(m,1,1), M3(m,2,1),
- M3(m,0,2), M3(m,1,2), M3(m,2,2));
- if (det == 0)
- det = 1;
- det = 1 / det;
-
- M3(dst,0,0) = M3(m,1,1) * M3(m,2,2) - M3(m,1,2) * M3(m,2,1);
- M3(dst,0,1) = -M3(m,0,1) * M3(m,2,2) + M3(m,0,2) * M3(m,2,1);
- M3(dst,0,2) = M3(m,0,1) * M3(m,1,2) - M3(m,0,2) * M3(m,1,1);
-
- M3(dst,1,0) = -M3(m,1,0) * M3(m,2,2) + M3(m,1,2) * M3(m,2,0);
- M3(dst,1,1) = M3(m,0,0) * M3(m,2,2) - M3(m,0,2) * M3(m,2,0);
- M3(dst,1,2) = -M3(m,0,0) * M3(m,1,2) + M3(m,0,2) * M3(m,1,0);
-
- M3(dst,2,0) = M3(m,1,0) * M3(m,2,1) - M3(m,1,1) * M3(m,2,0);
- M3(dst,2,1) = -M3(m,0,0) * M3(m,2,1) + M3(m,0,1) * M3(m,2,0);
- M3(dst,2,2) = M3(m,0,0) * M3(m,1,1) - M3(m,0,1) * M3(m,1,0);
-
- for (i = 0; i < 9; i++)
- dst[i] *= det;
-}
+/*
+ * Matrices, points and affine transformations
+ */
+
+const fz_matrix fz_identity = { 1, 0, 0, 1, 0, 0 };
fz_matrix
fz_concat(fz_matrix one, fz_matrix two)
@@ -52,16 +23,6 @@ fz_concat(fz_matrix one, fz_matrix two)
}
fz_matrix
-fz_identity(void)
-{
- fz_matrix m;
- m.a = 1; m.b = 0;
- m.c = 0; m.d = 1;
- m.e = 0; m.f = 0;
- return m;
-}
-
-fz_matrix
fz_scale(float sx, float sy)
{
fz_matrix m;
@@ -170,6 +131,59 @@ fz_transformvector(fz_matrix m, fz_point p)
return t;
}
+/*
+ * Rectangles and bounding boxes
+ */
+
+const fz_rect fz_infiniterect = { 1, 1, -1, -1 };
+const fz_rect fz_emptyrect = { 0, 0, 0, 0 };
+const fz_rect fz_unitrect = { 0, 0, 1, 1 };
+
+const fz_bbox fz_infinitebbox = { 1, 1, -1, -1 };
+const fz_bbox fz_emptybbox = { 0, 0, 0, 0 };
+const fz_bbox fz_unitbbox = { 0, 0, 1, 1 };
+
+fz_bbox
+fz_roundrect(fz_rect f)
+{
+ fz_bbox i;
+ i.x0 = floorf(f.x0);
+ i.y0 = floorf(f.y0);
+ i.x1 = ceilf(f.x1);
+ i.y1 = ceilf(f.y1);
+ return i;
+}
+
+fz_bbox
+fz_intersectbbox(fz_bbox a, fz_bbox b)
+{
+ fz_bbox r;
+ if (fz_isinfiniterect(a)) return b;
+ if (fz_isinfiniterect(b)) return a;
+ if (fz_isemptyrect(a)) return fz_emptybbox;
+ if (fz_isemptyrect(b)) return fz_emptybbox;
+ r.x0 = MAX(a.x0, b.x0);
+ r.y0 = MAX(a.y0, b.y0);
+ r.x1 = MIN(a.x1, b.x1);
+ r.y1 = MIN(a.y1, b.y1);
+ return (r.x1 < r.x0 || r.y1 < r.y0) ? fz_emptybbox : r;
+}
+
+fz_bbox
+fz_unionbbox(fz_bbox a, fz_bbox b)
+{
+ fz_bbox r;
+ if (fz_isinfiniterect(a)) return a;
+ if (fz_isinfiniterect(b)) return b;
+ if (fz_isemptyrect(a)) return b;
+ if (fz_isemptyrect(b)) return a;
+ r.x0 = MIN(a.x0, b.x0);
+ r.y0 = MIN(a.y0, b.y0);
+ r.x1 = MAX(a.x1, b.x1);
+ r.y1 = MAX(a.y1, b.y1);
+ return r;
+}
+
fz_rect
fz_transformrect(fz_matrix m, fz_rect r)
{
diff --git a/fitz/util_getopt.c b/fitz/base_getopt.c
index 2c198ba1..2c198ba1 100644
--- a/fitz/util_getopt.c
+++ b/fitz/base_getopt.c
diff --git a/fitz/base_hash.c b/fitz/base_hash.c
index a1c46a7d..b5423eb3 100644
--- a/fitz/base_hash.c
+++ b/fitz/base_hash.c
@@ -1,8 +1,4 @@
-/* Linear probe hash table.
- * 2004 (C) Tor Andersson.
- * BSD license.
- *
- * Simple hashtable with open adressing linear probe.
+/* Simple hashtable with open adressing linear probe.
* Unlike text book examples, removing entries works
* correctly in this implementation so it wont start
* exhibiting bad behaviour if entries are inserted
diff --git a/fitz/base_memory.c b/fitz/base_memory.c
index 3209b333..1f03faa5 100644
--- a/fitz/base_memory.c
+++ b/fitz/base_memory.c
@@ -1,6 +1,7 @@
#include "fitz.h"
-void * fz_malloc(int n)
+void *
+fz_malloc(int n)
{
void *p = malloc(n);
if (!p)
@@ -11,7 +12,8 @@ void * fz_malloc(int n)
return p;
}
-void * fz_realloc(void *p, int n)
+void *
+fz_realloc(void *p, int n)
{
void *np = realloc(p, n);
if (np == nil)
@@ -22,20 +24,17 @@ void * fz_realloc(void *p, int n)
return np;
}
-void fz_free(void *p)
+void
+fz_free(void *p)
{
free(p);
}
-char * fz_strdup(char *s)
+char *
+fz_strdup(char *s)
{
- char *ns = malloc(strlen(s) + 1);
- if (!ns)
- {
- fprintf(stderr, "fatal error: out of memory\n");
- abort();
- }
- memcpy(ns, s, strlen(s) + 1);
+ int len = strlen(s) + 1;
+ char *ns = fz_malloc(len);
+ memcpy(ns, s, len);
return ns;
}
-
diff --git a/fitz/base_rect.c b/fitz/base_rect.c
deleted file mode 100644
index 971153c8..00000000
--- a/fitz/base_rect.c
+++ /dev/null
@@ -1,50 +0,0 @@
-#include "fitz.h"
-
-const fz_rect fz_infiniterect = { 1, 1, -1, -1 };
-const fz_rect fz_emptyrect = { 0, 0, 0, 0 };
-const fz_rect fz_unitrect = { 0, 0, 1, 1 };
-
-const fz_bbox fz_infinitebbox = { 1, 1, -1, -1 };
-const fz_bbox fz_emptybbox = { 0, 0, 0, 0 };
-const fz_bbox fz_unitbbox = { 0, 0, 1, 1 };
-
-fz_bbox
-fz_roundrect(fz_rect f)
-{
- fz_bbox i;
- i.x0 = floorf(f.x0);
- i.y0 = floorf(f.y0);
- i.x1 = ceilf(f.x1);
- i.y1 = ceilf(f.y1);
- return i;
-}
-
-fz_bbox
-fz_intersectbbox(fz_bbox a, fz_bbox b)
-{
- fz_bbox r;
- if (fz_isinfiniterect(a)) return b;
- if (fz_isinfiniterect(b)) return a;
- if (fz_isemptyrect(a)) return fz_emptybbox;
- if (fz_isemptyrect(b)) return fz_emptybbox;
- r.x0 = MAX(a.x0, b.x0);
- r.y0 = MAX(a.y0, b.y0);
- r.x1 = MIN(a.x1, b.x1);
- r.y1 = MIN(a.y1, b.y1);
- return (r.x1 < r.x0 || r.y1 < r.y0) ? fz_emptybbox : r;
-}
-
-fz_bbox
-fz_unionbbox(fz_bbox a, fz_bbox b)
-{
- fz_bbox r;
- if (fz_isinfiniterect(a)) return a;
- if (fz_isinfiniterect(b)) return b;
- if (fz_isemptyrect(a)) return b;
- if (fz_isemptyrect(b)) return a;
- r.x0 = MIN(a.x0, b.x0);
- r.y0 = MIN(a.y0, b.y0);
- r.x1 = MAX(a.x1, b.x1);
- r.y1 = MAX(a.y1, b.y1);
- return r;
-}
diff --git a/fitz/base_string.c b/fitz/base_string.c
index b6b85865..f6950cd3 100644
--- a/fitz/base_string.c
+++ b/fitz/base_string.c
@@ -1,14 +1,14 @@
#include "fitz.h"
-#include <string.h>
-
-int fz_isbigendian(void)
+int
+fz_isbigendian(void)
{
static const int one = 1;
return *(char*)&one == 0;
}
-char *fz_strsep(char **stringp, const char *delim)
+char *
+fz_strsep(char **stringp, const char *delim)
{
char *ret = *stringp;
if (ret == NULL) return NULL;
@@ -17,7 +17,8 @@ char *fz_strsep(char **stringp, const char *delim)
return ret;
}
-int fz_strlcpy(char *dst, const char *src, int siz)
+int
+fz_strlcpy(char *dst, const char *src, int siz)
{
register char *d = dst;
register const char *s = src;
@@ -42,7 +43,8 @@ int fz_strlcpy(char *dst, const char *src, int siz)
return(s - src - 1); /* count does not include NUL */
}
-int fz_strlcat(char *dst, const char *src, int siz)
+int
+fz_strlcat(char *dst, const char *src, int siz)
{
register char *d = dst;
register const char *s = src;
@@ -69,3 +71,180 @@ int fz_strlcat(char *dst, const char *src, int siz)
return dlen + (s - src); /* count does not include NUL */
}
+enum
+{
+ UTFmax = 4, /* maximum bytes per rune */
+ Runesync = 0x80, /* cannot represent part of a UTF sequence (<) */
+ Runeself = 0x80, /* rune and UTF sequences are the same (<) */
+ Runeerror = 0xFFFD, /* decoding error in UTF */
+ Runemax = 0x10FFFF, /* maximum rune value */
+};
+
+enum
+{
+ Bit1 = 7,
+ Bitx = 6,
+ Bit2 = 5,
+ Bit3 = 4,
+ Bit4 = 3,
+ Bit5 = 2,
+
+ T1 = ((1<<(Bit1+1))-1) ^ 0xFF, /* 0000 0000 */
+ Tx = ((1<<(Bitx+1))-1) ^ 0xFF, /* 1000 0000 */
+ T2 = ((1<<(Bit2+1))-1) ^ 0xFF, /* 1100 0000 */
+ T3 = ((1<<(Bit3+1))-1) ^ 0xFF, /* 1110 0000 */
+ T4 = ((1<<(Bit4+1))-1) ^ 0xFF, /* 1111 0000 */
+ T5 = ((1<<(Bit5+1))-1) ^ 0xFF, /* 1111 1000 */
+
+ Rune1 = (1<<(Bit1+0*Bitx))-1, /* 0000 0000 0111 1111 */
+ Rune2 = (1<<(Bit2+1*Bitx))-1, /* 0000 0111 1111 1111 */
+ Rune3 = (1<<(Bit3+2*Bitx))-1, /* 1111 1111 1111 1111 */
+ Rune4 = (1<<(Bit4+3*Bitx))-1, /* 0001 1111 1111 1111 1111 1111 */
+
+ Maskx = (1<<Bitx)-1, /* 0011 1111 */
+ Testx = Maskx ^ 0xFF, /* 1100 0000 */
+
+ Bad = Runeerror,
+};
+
+int
+chartorune(int *rune, char *str)
+{
+ int c, c1, c2, c3;
+ long l;
+
+ /*
+ * one character sequence
+ * 00000-0007F => T1
+ */
+ c = *(unsigned char*)str;
+ if(c < Tx) {
+ *rune = c;
+ return 1;
+ }
+
+ /*
+ * two character sequence
+ * 0080-07FF => T2 Tx
+ */
+ c1 = *(unsigned char*)(str+1) ^ Tx;
+ if(c1 & Testx)
+ goto bad;
+ if(c < T3) {
+ if(c < T2)
+ goto bad;
+ l = ((c << Bitx) | c1) & Rune2;
+ if(l <= Rune1)
+ goto bad;
+ *rune = l;
+ return 2;
+ }
+
+ /*
+ * three character sequence
+ * 0800-FFFF => T3 Tx Tx
+ */
+ c2 = *(unsigned char*)(str+2) ^ Tx;
+ if(c2 & Testx)
+ goto bad;
+ if(c < T4) {
+ l = ((((c << Bitx) | c1) << Bitx) | c2) & Rune3;
+ if(l <= Rune2)
+ goto bad;
+ *rune = l;
+ return 3;
+ }
+
+ /*
+ * four character sequence (21-bit value)
+ * 10000-1FFFFF => T4 Tx Tx Tx
+ */
+ c3 = *(unsigned char*)(str+3) ^ Tx;
+ if (c3 & Testx)
+ goto bad;
+ if (c < T5) {
+ l = ((((((c << Bitx) | c1) << Bitx) | c2) << Bitx) | c3) & Rune4;
+ if (l <= Rune3)
+ goto bad;
+ *rune = l;
+ return 4;
+ }
+ /*
+ * Support for 5-byte or longer UTF-8 would go here, but
+ * since we don't have that, we'll just fall through to bad.
+ */
+
+ /*
+ * bad decoding
+ */
+bad:
+ *rune = Bad;
+ return 1;
+}
+
+
+int
+runetochar(char *str, int *rune)
+{
+ /* Runes are signed, so convert to unsigned for range check. */
+ unsigned long c;
+
+ /*
+ * one character sequence
+ * 00000-0007F => 00-7F
+ */
+ c = *rune;
+ if(c <= Rune1) {
+ str[0] = c;
+ return 1;
+ }
+
+ /*
+ * two character sequence
+ * 0080-07FF => T2 Tx
+ */
+ if(c <= Rune2) {
+ str[0] = T2 | (c >> 1*Bitx);
+ str[1] = Tx | (c & Maskx);
+ return 2;
+ }
+
+ /*
+ * If the Rune is out of range, convert it to the error rune.
+ * Do this test here because the error rune encodes to three bytes.
+ * Doing it earlier would duplicate work, since an out of range
+ * Rune wouldn't have fit in one or two bytes.
+ */
+ if (c > Runemax)
+ c = Runeerror;
+
+ /*
+ * three character sequence
+ * 0800-FFFF => T3 Tx Tx
+ */
+ if (c <= Rune3) {
+ str[0] = T3 | (c >> 2*Bitx);
+ str[1] = Tx | ((c >> 1*Bitx) & Maskx);
+ str[2] = Tx | (c & Maskx);
+ return 3;
+ }
+
+ /*
+ * four character sequence (21-bit value)
+ * 10000-1FFFFF => T4 Tx Tx Tx
+ */
+ str[0] = T4 | (c >> 3*Bitx);
+ str[1] = Tx | ((c >> 2*Bitx) & Maskx);
+ str[2] = Tx | ((c >> 1*Bitx) & Maskx);
+ str[3] = Tx | (c & Maskx);
+ return 4;
+}
+
+
+int
+runelen(int c)
+{
+ char str[10];
+ return runetochar(str, &c);
+}
+
diff --git a/fitz/util_gettimeofday.c b/fitz/base_time.c
index 425c6440..425c6440 100644
--- a/fitz/util_gettimeofday.c
+++ b/fitz/base_time.c
diff --git a/fitz/base_unicode.c b/fitz/base_unicode.c
deleted file mode 100644
index c7f8219a..00000000
--- a/fitz/base_unicode.c
+++ /dev/null
@@ -1,179 +0,0 @@
-#include "fitz.h"
-
-enum
-{
- UTFmax = 4, /* maximum bytes per rune */
- Runesync = 0x80, /* cannot represent part of a UTF sequence (<) */
- Runeself = 0x80, /* rune and UTF sequences are the same (<) */
- Runeerror = 0xFFFD, /* decoding error in UTF */
- Runemax = 0x10FFFF, /* maximum rune value */
-};
-
-enum
-{
- Bit1 = 7,
- Bitx = 6,
- Bit2 = 5,
- Bit3 = 4,
- Bit4 = 3,
- Bit5 = 2,
-
- T1 = ((1<<(Bit1+1))-1) ^ 0xFF, /* 0000 0000 */
- Tx = ((1<<(Bitx+1))-1) ^ 0xFF, /* 1000 0000 */
- T2 = ((1<<(Bit2+1))-1) ^ 0xFF, /* 1100 0000 */
- T3 = ((1<<(Bit3+1))-1) ^ 0xFF, /* 1110 0000 */
- T4 = ((1<<(Bit4+1))-1) ^ 0xFF, /* 1111 0000 */
- T5 = ((1<<(Bit5+1))-1) ^ 0xFF, /* 1111 1000 */
-
- Rune1 = (1<<(Bit1+0*Bitx))-1, /* 0000 0000 0111 1111 */
- Rune2 = (1<<(Bit2+1*Bitx))-1, /* 0000 0111 1111 1111 */
- Rune3 = (1<<(Bit3+2*Bitx))-1, /* 1111 1111 1111 1111 */
- Rune4 = (1<<(Bit4+3*Bitx))-1, /* 0001 1111 1111 1111 1111 1111 */
-
- Maskx = (1<<Bitx)-1, /* 0011 1111 */
- Testx = Maskx ^ 0xFF, /* 1100 0000 */
-
- Bad = Runeerror,
-};
-
-int
-chartorune(int *rune, char *str)
-{
- int c, c1, c2, c3;
- long l;
-
- /*
- * one character sequence
- * 00000-0007F => T1
- */
- c = *(unsigned char*)str;
- if(c < Tx) {
- *rune = c;
- return 1;
- }
-
- /*
- * two character sequence
- * 0080-07FF => T2 Tx
- */
- c1 = *(unsigned char*)(str+1) ^ Tx;
- if(c1 & Testx)
- goto bad;
- if(c < T3) {
- if(c < T2)
- goto bad;
- l = ((c << Bitx) | c1) & Rune2;
- if(l <= Rune1)
- goto bad;
- *rune = l;
- return 2;
- }
-
- /*
- * three character sequence
- * 0800-FFFF => T3 Tx Tx
- */
- c2 = *(unsigned char*)(str+2) ^ Tx;
- if(c2 & Testx)
- goto bad;
- if(c < T4) {
- l = ((((c << Bitx) | c1) << Bitx) | c2) & Rune3;
- if(l <= Rune2)
- goto bad;
- *rune = l;
- return 3;
- }
-
- /*
- * four character sequence (21-bit value)
- * 10000-1FFFFF => T4 Tx Tx Tx
- */
- c3 = *(unsigned char*)(str+3) ^ Tx;
- if (c3 & Testx)
- goto bad;
- if (c < T5) {
- l = ((((((c << Bitx) | c1) << Bitx) | c2) << Bitx) | c3) & Rune4;
- if (l <= Rune3)
- goto bad;
- *rune = l;
- return 4;
- }
- /*
- * Support for 5-byte or longer UTF-8 would go here, but
- * since we don't have that, we'll just fall through to bad.
- */
-
- /*
- * bad decoding
- */
-bad:
- *rune = Bad;
- return 1;
-}
-
-
-int
-runetochar(char *str, int *rune)
-{
- /* Runes are signed, so convert to unsigned for range check. */
- unsigned long c;
-
- /*
- * one character sequence
- * 00000-0007F => 00-7F
- */
- c = *rune;
- if(c <= Rune1) {
- str[0] = c;
- return 1;
- }
-
- /*
- * two character sequence
- * 0080-07FF => T2 Tx
- */
- if(c <= Rune2) {
- str[0] = T2 | (c >> 1*Bitx);
- str[1] = Tx | (c & Maskx);
- return 2;
- }
-
- /*
- * If the Rune is out of range, convert it to the error rune.
- * Do this test here because the error rune encodes to three bytes.
- * Doing it earlier would duplicate work, since an out of range
- * Rune wouldn't have fit in one or two bytes.
- */
- if (c > Runemax)
- c = Runeerror;
-
- /*
- * three character sequence
- * 0800-FFFF => T3 Tx Tx
- */
- if (c <= Rune3) {
- str[0] = T3 | (c >> 2*Bitx);
- str[1] = Tx | ((c >> 1*Bitx) & Maskx);
- str[2] = Tx | (c & Maskx);
- return 3;
- }
-
- /*
- * four character sequence (21-bit value)
- * 10000-1FFFFF => T4 Tx Tx Tx
- */
- str[0] = T4 | (c >> 3*Bitx);
- str[1] = Tx | ((c >> 2*Bitx) & Maskx);
- str[2] = Tx | ((c >> 1*Bitx) & Maskx);
- str[3] = Tx | (c & Maskx);
- return 4;
-}
-
-
-int
-runelen(int c)
-{
- char str[10];
- return runetochar(str, &c);
-}
-
diff --git a/fitz/dev_list.c b/fitz/dev_list.c
index 4a48778b..3ca6fca6 100644
--- a/fitz/dev_list.c
+++ b/fitz/dev_list.c
@@ -184,7 +184,7 @@ static void
fz_listpopclip(void *user)
{
fz_displaynode *node;
- node = fz_newdisplaynode(FZ_CMDPOPCLIP, fz_identity(), nil, nil, 0);
+ node = fz_newdisplaynode(FZ_CMDPOPCLIP, fz_identity, nil, nil, 0);
fz_appenddisplaynode(user, node);
}
diff --git a/fitz/filt_aesd.c b/fitz/filt_aesd.c
deleted file mode 100644
index 914d28e0..00000000
--- a/fitz/filt_aesd.c
+++ /dev/null
@@ -1,69 +0,0 @@
-#include "fitz.h"
-
-typedef struct fz_aesd_s fz_aesd;
-
-struct fz_aesd_s
-{
- fz_filter super;
- fz_aes aes;
- unsigned char iv[16];
- int ivcount;
-};
-
-fz_filter *
-fz_newaesdfilter(unsigned char *key, unsigned keylen)
-{
- FZ_NEWFILTER(fz_aesd, f, aesdfilter);
- aes_setkey_dec(&f->aes, key, keylen * 8);
- f->ivcount = 0;
- return (fz_filter *)f;
-}
-
-void
-fz_dropaesdfilter(fz_filter *f)
-{
-}
-
-fz_error
-fz_processaesdfilter(fz_filter *filter, fz_buffer *in, fz_buffer *out)
-{
- fz_aesd *f = (fz_aesd*)filter;
- int n;
-
- while (1)
- {
- if (in->rp + 16 > in->wp)
- {
- if (in->eof)
- return fz_iodone;
- return fz_ioneedin;
- }
-
- if (f->ivcount < 16)
- {
- f->iv[f->ivcount++] = *in->rp++;
- }
- else
- {
- if (out->wp + 16 > out->ep)
- return fz_ioneedout;
-
- n = MIN(in->wp - in->rp, out->ep - out->wp);
- n = (n / 16) * 16;
-
- aes_crypt_cbc(&f->aes, AES_DECRYPT, n, f->iv, in->rp, out->wp);
- in->rp += n;
- out->wp += n;
-
- /* Remove padding bytes */
- if (in->eof && in->rp == in->wp)
- {
- int pad = out->wp[-1];
- if (pad < 1 || pad > 16)
- return fz_throw("aes padding out of range: %d", pad);
- out->wp -= pad;
- }
- }
- }
-}
-
diff --git a/fitz/filt_arc4.c b/fitz/filt_arc4.c
deleted file mode 100644
index 79154460..00000000
--- a/fitz/filt_arc4.c
+++ /dev/null
@@ -1,46 +0,0 @@
-#include "fitz.h"
-
-typedef struct fz_arc4c_s fz_arc4c;
-
-struct fz_arc4c_s
-{
- fz_filter super;
- fz_arc4 arc4;
-};
-
-fz_filter *
-fz_newarc4filter(unsigned char *key, unsigned keylen)
-{
- FZ_NEWFILTER(fz_arc4c, f, arc4filter);
- fz_arc4init(&f->arc4, key, keylen);
- return (fz_filter *)f;
-}
-
-void
-fz_droparc4filter(fz_filter *f)
-{
-}
-
-fz_error
-fz_processarc4filter(fz_filter *filter, fz_buffer *in, fz_buffer *out)
-{
- fz_arc4c *f = (fz_arc4c*)filter;
- int n;
-
- while (1)
- {
- if (in->rp + 1 > in->wp) {
- if (in->eof)
- return fz_iodone;
- return fz_ioneedin;
- }
- if (out->wp + 1 > out->ep)
- return fz_ioneedout;
-
- n = MIN(in->wp - in->rp, out->ep - out->wp);
- fz_arc4encrypt(&f->arc4, out->wp, in->rp, n);
- in->rp += n;
- out->wp += n;
- }
-}
-
diff --git a/fitz/filt_basic.c b/fitz/filt_basic.c
index b5b9f3c9..6ab80c32 100644
--- a/fitz/filt_basic.c
+++ b/fitz/filt_basic.c
@@ -1,5 +1,9 @@
#include "fitz.h"
+/*
+ * Identity filter.
+ */
+
fz_filter *
fz_newcopyfilter(void)
{
@@ -39,6 +43,10 @@ fz_processcopyfilter(fz_filter *filter, fz_buffer *in, fz_buffer *out)
}
}
+/*
+ * Null filter copies data until a specified length.
+ */
+
typedef struct fz_nullfilter_s fz_nullfilter;
struct fz_nullfilter_s
@@ -90,6 +98,10 @@ fz_processnullfilter(fz_filter *filter, fz_buffer *in, fz_buffer *out)
return fz_throw("braindead programmer trapped in nullfilter");
}
+/*
+ * ASCII Hex Decode
+ */
+
typedef struct fz_ahxd_s fz_ahxd;
struct fz_ahxd_s
@@ -181,23 +193,9 @@ fz_processahxd(fz_filter *filter, fz_buffer *in, fz_buffer *out)
}
}
-void
-fz_pushbackahxd(fz_filter *filter, fz_buffer *in, fz_buffer *out, int n)
-{
- int k;
-
- assert(filter->process == fz_processahxd);
- assert(out->wp - n >= out->rp);
-
- k = 0;
- while (k < n * 2) {
- in->rp --;
- if (ishex(*in->rp))
- k ++;
- }
-
- out->wp -= n;
-}
+/*
+ * ASCII 85 Decode
+ */
typedef struct fz_a85d_s fz_a85d;
@@ -314,6 +312,10 @@ fz_processa85d(fz_filter *filter, fz_buffer *in, fz_buffer *out)
}
}
+/*
+ * Run Length Decode
+ */
+
fz_filter *
fz_newrld(fz_obj *params)
{
@@ -384,3 +386,121 @@ fz_processrld(fz_filter *filter, fz_buffer *in, fz_buffer *out)
}
}
+/*
+ * RC4 Filter
+ */
+
+typedef struct fz_arc4c_s fz_arc4c;
+
+struct fz_arc4c_s
+{
+ fz_filter super;
+ fz_arc4 arc4;
+};
+
+fz_filter *
+fz_newarc4filter(unsigned char *key, unsigned keylen)
+{
+ FZ_NEWFILTER(fz_arc4c, f, arc4filter);
+ fz_arc4init(&f->arc4, key, keylen);
+ return (fz_filter *)f;
+}
+
+void
+fz_droparc4filter(fz_filter *f)
+{
+}
+
+fz_error
+fz_processarc4filter(fz_filter *filter, fz_buffer *in, fz_buffer *out)
+{
+ fz_arc4c *f = (fz_arc4c*)filter;
+ int n;
+
+ while (1)
+ {
+ if (in->rp + 1 > in->wp) {
+ if (in->eof)
+ return fz_iodone;
+ return fz_ioneedin;
+ }
+ if (out->wp + 1 > out->ep)
+ return fz_ioneedout;
+
+ n = MIN(in->wp - in->rp, out->ep - out->wp);
+ fz_arc4encrypt(&f->arc4, out->wp, in->rp, n);
+ in->rp += n;
+ out->wp += n;
+ }
+}
+
+/*
+ * AES Filter
+ */
+
+typedef struct fz_aesd_s fz_aesd;
+
+struct fz_aesd_s
+{
+ fz_filter super;
+ fz_aes aes;
+ unsigned char iv[16];
+ int ivcount;
+};
+
+fz_filter *
+fz_newaesdfilter(unsigned char *key, unsigned keylen)
+{
+ FZ_NEWFILTER(fz_aesd, f, aesdfilter);
+ aes_setkey_dec(&f->aes, key, keylen * 8);
+ f->ivcount = 0;
+ return (fz_filter *)f;
+}
+
+void
+fz_dropaesdfilter(fz_filter *f)
+{
+}
+
+fz_error
+fz_processaesdfilter(fz_filter *filter, fz_buffer *in, fz_buffer *out)
+{
+ fz_aesd *f = (fz_aesd*)filter;
+ int n;
+
+ while (1)
+ {
+ if (in->rp + 16 > in->wp)
+ {
+ if (in->eof)
+ return fz_iodone;
+ return fz_ioneedin;
+ }
+
+ if (f->ivcount < 16)
+ {
+ f->iv[f->ivcount++] = *in->rp++;
+ }
+ else
+ {
+ if (out->wp + 16 > out->ep)
+ return fz_ioneedout;
+
+ n = MIN(in->wp - in->rp, out->ep - out->wp);
+ n = (n / 16) * 16;
+
+ aes_crypt_cbc(&f->aes, AES_DECRYPT, n, f->iv, in->rp, out->wp);
+ in->rp += n;
+ out->wp += n;
+
+ /* Remove padding bytes */
+ if (in->eof && in->rp == in->wp)
+ {
+ int pad = out->wp[-1];
+ if (pad < 1 || pad > 16)
+ return fz_throw("aes padding out of range: %d", pad);
+ out->wp -= pad;
+ }
+ }
+ }
+}
diff --git a/fitz/filt_faxd.c b/fitz/filt_faxd.c
index c31a7ea2..b53cdd29 100644
--- a/fitz/filt_faxd.c
+++ b/fitz/filt_faxd.c
@@ -1,8 +1,174 @@
#include "fitz.h"
-#include "filt_faxd.h"
+/* Fax G3/G4 decoder */
-/* common bit magic */
+/* TODO: uncompressed */
+
+/*
+<raph> the first 2^(initialbits) entries map bit patterns to decodes
+<raph> let's say initial_bits is 8 for the sake of example
+<raph> and that the code is 1001
+<raph> that means that entries 0x90 .. 0x9f have the entry { val, 4 }
+<raph> because those are all the bytes that start with the code
+<raph> and the 4 is the length of the code
+... if (n_bits > initial_bits) ...
+<raph> anyway, in that case, it basically points to a mini table
+<raph> the n_bits is the maximum length of all codes beginning with that byte
+<raph> so 2^(n_bits - initial_bits) is the size of the mini-table
+<raph> peter came up with this, and it makes sense
+*/
+
+typedef struct cfd_node_s cfd_node;
+
+struct cfd_node_s
+{
+ short val;
+ short nbits;
+};
+
+enum
+{
+ cfd_white_initial_bits = 8,
+ cfd_black_initial_bits = 7,
+ cfd_2d_initial_bits = 7,
+ cfd_uncompressed_initial_bits = 6 /* must be 6 */
+};
+
+/* non-run codes in tables */
+enum
+{
+ ERROR = -1,
+ ZEROS = -2, /* EOL follows, possibly with more padding first */
+ UNCOMPRESSED = -3
+};
+
+/* semantic codes for cf_2d_decode */
+enum
+{
+ P = -4,
+ H = -5,
+ VR3 = 0,
+ VR2 = 1,
+ VR1 = 2,
+ V0 = 3,
+ VL1 = 4,
+ VL2 = 5,
+ VL3 = 6
+};
+
+/* White decoding table. */
+const cfd_node cf_white_decode[] = {
+ {256,12},{272,12},{29,8},{30,8},{45,8},{46,8},{22,7},{22,7},
+ {23,7},{23,7},{47,8},{48,8},{13,6},{13,6},{13,6},{13,6},{20,7},
+ {20,7},{33,8},{34,8},{35,8},{36,8},{37,8},{38,8},{19,7},{19,7},
+ {31,8},{32,8},{1,6},{1,6},{1,6},{1,6},{12,6},{12,6},{12,6},{12,6},
+ {53,8},{54,8},{26,7},{26,7},{39,8},{40,8},{41,8},{42,8},{43,8},
+ {44,8},{21,7},{21,7},{28,7},{28,7},{61,8},{62,8},{63,8},{0,8},
+ {320,8},{384,8},{10,5},{10,5},{10,5},{10,5},{10,5},{10,5},{10,5},
+ {10,5},{11,5},{11,5},{11,5},{11,5},{11,5},{11,5},{11,5},{11,5},
+ {27,7},{27,7},{59,8},{60,8},{288,9},{290,9},{18,7},{18,7},{24,7},
+ {24,7},{49,8},{50,8},{51,8},{52,8},{25,7},{25,7},{55,8},{56,8},
+ {57,8},{58,8},{192,6},{192,6},{192,6},{192,6},{1664,6},{1664,6},
+ {1664,6},{1664,6},{448,8},{512,8},{292,9},{640,8},{576,8},{294,9},
+ {296,9},{298,9},{300,9},{302,9},{256,7},{256,7},{2,4},{2,4},{2,4},
+ {2,4},{2,4},{2,4},{2,4},{2,4},{2,4},{2,4},{2,4},{2,4},{2,4},{2,4},
+ {2,4},{2,4},{3,4},{3,4},{3,4},{3,4},{3,4},{3,4},{3,4},{3,4},{3,4},
+ {3,4},{3,4},{3,4},{3,4},{3,4},{3,4},{3,4},{128,5},{128,5},{128,5},
+ {128,5},{128,5},{128,5},{128,5},{128,5},{8,5},{8,5},{8,5},{8,5},
+ {8,5},{8,5},{8,5},{8,5},{9,5},{9,5},{9,5},{9,5},{9,5},{9,5},{9,5},
+ {9,5},{16,6},{16,6},{16,6},{16,6},{17,6},{17,6},{17,6},{17,6},
+ {4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},{4,4},
+ {4,4},{4,4},{4,4},{4,4},{4,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},
+ {5,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},
+ {14,6},{14,6},{14,6},{14,6},{15,6},{15,6},{15,6},{15,6},{64,5},
+ {64,5},{64,5},{64,5},{64,5},{64,5},{64,5},{64,5},{6,4},{6,4},
+ {6,4},{6,4},{6,4},{6,4},{6,4},{6,4},{6,4},{6,4},{6,4},{6,4},{6,4},
+ {6,4},{6,4},{6,4},{7,4},{7,4},{7,4},{7,4},{7,4},{7,4},{7,4},{7,4},
+ {7,4},{7,4},{7,4},{7,4},{7,4},{7,4},{7,4},{7,4},{-2,3},{-2,3},
+ {-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},
+ {-1,0},{-1,0},{-1,0},{-1,0},{-3,4},{1792,3},{1792,3},{1984,4},
+ {2048,4},{2112,4},{2176,4},{2240,4},{2304,4},{1856,3},{1856,3},
+ {1920,3},{1920,3},{2368,4},{2432,4},{2496,4},{2560,4},{1472,1},
+ {1536,1},{1600,1},{1728,1},{704,1},{768,1},{832,1},{896,1},
+ {960,1},{1024,1},{1088,1},{1152,1},{1216,1},{1280,1},{1344,1},
+ {1408,1}
+};
+
+/* Black decoding table. */
+const cfd_node cf_black_decode[] = {
+ {128,12},{160,13},{224,12},{256,12},{10,7},{11,7},{288,12},{12,7},
+ {9,6},{9,6},{8,6},{8,6},{7,5},{7,5},{7,5},{7,5},{6,4},{6,4},{6,4},
+ {6,4},{6,4},{6,4},{6,4},{6,4},{5,4},{5,4},{5,4},{5,4},{5,4},{5,4},
+ {5,4},{5,4},{1,3},{1,3},{1,3},{1,3},{1,3},{1,3},{1,3},{1,3},{1,3},
+ {1,3},{1,3},{1,3},{1,3},{1,3},{1,3},{1,3},{4,3},{4,3},{4,3},{4,3},
+ {4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},
+ {4,3},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},
+ {3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},
+ {3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},{3,2},
+ {2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
+ {2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
+ {2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},{2,2},
+ {-2,4},{-2,4},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},
+ {-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-3,5},{1792,4},
+ {1792,4},{1984,5},{2048,5},{2112,5},{2176,5},{2240,5},{2304,5},
+ {1856,4},{1856,4},{1920,4},{1920,4},{2368,5},{2432,5},{2496,5},
+ {2560,5},{18,3},{18,3},{18,3},{18,3},{18,3},{18,3},{18,3},{18,3},
+ {52,5},{52,5},{640,6},{704,6},{768,6},{832,6},{55,5},{55,5},
+ {56,5},{56,5},{1280,6},{1344,6},{1408,6},{1472,6},{59,5},{59,5},
+ {60,5},{60,5},{1536,6},{1600,6},{24,4},{24,4},{24,4},{24,4},
+ {25,4},{25,4},{25,4},{25,4},{1664,6},{1728,6},{320,5},{320,5},
+ {384,5},{384,5},{448,5},{448,5},{512,6},{576,6},{53,5},{53,5},
+ {54,5},{54,5},{896,6},{960,6},{1024,6},{1088,6},{1152,6},{1216,6},
+ {64,3},{64,3},{64,3},{64,3},{64,3},{64,3},{64,3},{64,3},{13,1},
+ {13,1},{13,1},{13,1},{13,1},{13,1},{13,1},{13,1},{13,1},{13,1},
+ {13,1},{13,1},{13,1},{13,1},{13,1},{13,1},{23,4},{23,4},{50,5},
+ {51,5},{44,5},{45,5},{46,5},{47,5},{57,5},{58,5},{61,5},{256,5},
+ {16,3},{16,3},{16,3},{16,3},{17,3},{17,3},{17,3},{17,3},{48,5},
+ {49,5},{62,5},{63,5},{30,5},{31,5},{32,5},{33,5},{40,5},{41,5},
+ {22,4},{22,4},{14,1},{14,1},{14,1},{14,1},{14,1},{14,1},{14,1},
+ {14,1},{14,1},{14,1},{14,1},{14,1},{14,1},{14,1},{14,1},{14,1},
+ {15,2},{15,2},{15,2},{15,2},{15,2},{15,2},{15,2},{15,2},{128,5},
+ {192,5},{26,5},{27,5},{28,5},{29,5},{19,4},{19,4},{20,4},{20,4},
+ {34,5},{35,5},{36,5},{37,5},{38,5},{39,5},{21,4},{21,4},{42,5},
+ {43,5},{0,3},{0,3},{0,3},{0,3}
+};
+
+/* 2-D decoding table. */
+const cfd_node cf_2d_decode[] = {
+ {128,11},{144,10},{6,7},{0,7},{5,6},{5,6},{1,6},{1,6},{-4,4},
+ {-4,4},{-4,4},{-4,4},{-4,4},{-4,4},{-4,4},{-4,4},{-5,3},{-5,3},
+ {-5,3},{-5,3},{-5,3},{-5,3},{-5,3},{-5,3},{-5,3},{-5,3},{-5,3},
+ {-5,3},{-5,3},{-5,3},{-5,3},{-5,3},{4,3},{4,3},{4,3},{4,3},{4,3},
+ {4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},{4,3},
+ {2,3},{2,3},{2,3},{2,3},{2,3},{2,3},{2,3},{2,3},{2,3},{2,3},{2,3},
+ {2,3},{2,3},{2,3},{2,3},{2,3},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},
+ {3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},
+ {3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},
+ {3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},
+ {3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},
+ {3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},{3,1},
+ {3,1},{3,1},{3,1},{-2,4},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},
+ {-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},
+ {-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-1,0},{-3,3}
+};
+
+/* Uncompresssed decoding table. */
+const cfd_node cf_uncompressed_decode[] = {
+ {64,12},{5,6},{4,5},{4,5},{3,4},{3,4},{3,4},{3,4},{2,3},{2,3},
+ {2,3},{2,3},{2,3},{2,3},{2,3},{2,3},{1,2},{1,2},{1,2},{1,2},{1,2},
+ {1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
+ {0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},
+ {0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},
+ {0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},
+ {-1,0},{-1,0},{8,6},{9,6},{6,5},{6,5},{7,5},{7,5},{4,4},{4,4},
+ {4,4},{4,4},{5,4},{5,4},{5,4},{5,4},{2,3},{2,3},{2,3},{2,3},{2,3},
+ {2,3},{2,3},{2,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},{3,3},
+ {0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
+ {0,2},{0,2},{0,2},{0,2},{0,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},
+ {1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2},{1,2}
+};
+
+/* bit magic */
static inline void
printbits(FILE *f, int code, int nbits)
@@ -127,6 +293,8 @@ setbits(unsigned char *line, int x0, int x1)
}
}
+typedef struct fz_faxd_s fz_faxd;
+
typedef enum fax_stage_e
{
SNORMAL, /* neutral state, waiting for any code */
@@ -135,10 +303,6 @@ typedef enum fax_stage_e
SH1, SH2 /* in H part 1 and 2 (both makeup and terminating codes) */
} fax_stage_e;
-/* TODO: uncompressed */
-
-typedef struct fz_faxd_s fz_faxd;
-
struct fz_faxd_s
{
fz_filter super;
diff --git a/fitz/filt_faxd.h b/fitz/filt_faxd.h
deleted file mode 100644
index 9f3fb470..00000000
--- a/fitz/filt_faxd.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/* Fax G3/G4 tables */
-
-/*
-<raph> the first 2^(initialbits) entries map bit patterns to decodes
-<raph> let's say initial_bits is 8 for the sake of example
-<raph> and that the code is 1001
-<raph> that means that entries 0x90 .. 0x9f have the entry { val, 4 }
-<raph> because those are all the bytes that start with the code
-<raph> and the 4 is the length of the code
-... if (n_bits > initial_bits) ...
-<raph> anyway, in that case, it basically points to a mini table
-<raph> the n_bits is the maximum length of all codes beginning with that byte
-<raph> so 2^(n_bits - initial_bits) is the size of the mini-table
-<raph> peter came up with this, and it makes sense
-*/
-
-typedef struct cfd_node_s cfd_node;
-
-struct cfd_node_s
-{
- short val;
- short nbits;
-};
-
-enum
-{
- cfd_white_initial_bits = 8,
- cfd_black_initial_bits = 7,
- cfd_2d_initial_bits = 7,
- cfd_uncompressed_initial_bits = 6 /* must be 6 */
-};
-
-/* non-run codes in tables */
-enum
-{
- ERROR = -1,
- ZEROS = -2, /* EOL follows, possibly with more padding first */
- UNCOMPRESSED = -3
-};
-
-/* semantic codes for cf_2d_decode */
-enum
-{
- P = -4,
- H = -5,
- VR3 = 0,
- VR2 = 1,
- VR1 = 2,
- V0 = 3,
- VL1 = 4,
- VL2 = 5,
- VL3 = 6
-};
-
-/* Decoding tables */
-
-extern const cfd_node cf_white_decode[];
-extern const cfd_node cf_black_decode[];
-extern const cfd_node cf_2d_decode[];
-extern const cfd_node cf_uncompressed_decode[];
-
diff --git a/fitz/filt_faxdtab.c b/fitz/filt_faxdtab.c
deleted file mode 100644
index b1ad0b25..00000000
--- a/fitz/filt_faxdtab.c
+++ /dev/null
@@ -1,932 +0,0 @@
-/* Tables for CCITTFaxDecode filter. */
-/*
-This file was generated automatically. It is governed by the same terms
-as the files scfetab.c and scfdgen.c from which it was derived.
-Consult those files for the licensing terms and conditions.
-*/
-
-#include "filt_faxd.h"
-
-/* White decoding table. */
-const cfd_node cf_white_decode[] = {
- { 256, 12 },
- { 272, 12 },
- { 29, 8 },
- { 30, 8 },
- { 45, 8 },
- { 46, 8 },
- { 22, 7 },
- { 22, 7 },
- { 23, 7 },
- { 23, 7 },
- { 47, 8 },
- { 48, 8 },
- { 13, 6 },
- { 13, 6 },
- { 13, 6 },
- { 13, 6 },
- { 20, 7 },
- { 20, 7 },
- { 33, 8 },
- { 34, 8 },
- { 35, 8 },
- { 36, 8 },
- { 37, 8 },
- { 38, 8 },
- { 19, 7 },
- { 19, 7 },
- { 31, 8 },
- { 32, 8 },
- { 1, 6 },
- { 1, 6 },
- { 1, 6 },
- { 1, 6 },
- { 12, 6 },
- { 12, 6 },
- { 12, 6 },
- { 12, 6 },
- { 53, 8 },
- { 54, 8 },
- { 26, 7 },
- { 26, 7 },
- { 39, 8 },
- { 40, 8 },
- { 41, 8 },
- { 42, 8 },
- { 43, 8 },
- { 44, 8 },
- { 21, 7 },
- { 21, 7 },
- { 28, 7 },
- { 28, 7 },
- { 61, 8 },
- { 62, 8 },
- { 63, 8 },
- { 0, 8 },
- { 320, 8 },
- { 384, 8 },
- { 10, 5 },
- { 10, 5 },
- { 10, 5 },
- { 10, 5 },
- { 10, 5 },
- { 10, 5 },
- { 10, 5 },
- { 10, 5 },
- { 11, 5 },
- { 11, 5 },
- { 11, 5 },
- { 11, 5 },
- { 11, 5 },
- { 11, 5 },
- { 11, 5 },
- { 11, 5 },
- { 27, 7 },
- { 27, 7 },
- { 59, 8 },
- { 60, 8 },
- { 288, 9 },
- { 290, 9 },
- { 18, 7 },
- { 18, 7 },
- { 24, 7 },
- { 24, 7 },
- { 49, 8 },
- { 50, 8 },
- { 51, 8 },
- { 52, 8 },
- { 25, 7 },
- { 25, 7 },
- { 55, 8 },
- { 56, 8 },
- { 57, 8 },
- { 58, 8 },
- { 192, 6 },
- { 192, 6 },
- { 192, 6 },
- { 192, 6 },
- { 1664, 6 },
- { 1664, 6 },
- { 1664, 6 },
- { 1664, 6 },
- { 448, 8 },
- { 512, 8 },
- { 292, 9 },
- { 640, 8 },
- { 576, 8 },
- { 294, 9 },
- { 296, 9 },
- { 298, 9 },
- { 300, 9 },
- { 302, 9 },
- { 256, 7 },
- { 256, 7 },
- { 2, 4 },
- { 2, 4 },
- { 2, 4 },
- { 2, 4 },
- { 2, 4 },
- { 2, 4 },
- { 2, 4 },
- { 2, 4 },
- { 2, 4 },
- { 2, 4 },
- { 2, 4 },
- { 2, 4 },
- { 2, 4 },
- { 2, 4 },
- { 2, 4 },
- { 2, 4 },
- { 3, 4 },
- { 3, 4 },
- { 3, 4 },
- { 3, 4 },
- { 3, 4 },
- { 3, 4 },
- { 3, 4 },
- { 3, 4 },
- { 3, 4 },
- { 3, 4 },
- { 3, 4 },
- { 3, 4 },
- { 3, 4 },
- { 3, 4 },
- { 3, 4 },
- { 3, 4 },
- { 128, 5 },
- { 128, 5 },
- { 128, 5 },
- { 128, 5 },
- { 128, 5 },
- { 128, 5 },
- { 128, 5 },
- { 128, 5 },
- { 8, 5 },
- { 8, 5 },
- { 8, 5 },
- { 8, 5 },
- { 8, 5 },
- { 8, 5 },
- { 8, 5 },
- { 8, 5 },
- { 9, 5 },
- { 9, 5 },
- { 9, 5 },
- { 9, 5 },
- { 9, 5 },
- { 9, 5 },
- { 9, 5 },
- { 9, 5 },
- { 16, 6 },
- { 16, 6 },
- { 16, 6 },
- { 16, 6 },
- { 17, 6 },
- { 17, 6 },
- { 17, 6 },
- { 17, 6 },
- { 4, 4 },
- { 4, 4 },
- { 4, 4 },
- { 4, 4 },
- { 4, 4 },
- { 4, 4 },
- { 4, 4 },
- { 4, 4 },
- { 4, 4 },
- { 4, 4 },
- { 4, 4 },
- { 4, 4 },
- { 4, 4 },
- { 4, 4 },
- { 4, 4 },
- { 4, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 14, 6 },
- { 14, 6 },
- { 14, 6 },
- { 14, 6 },
- { 15, 6 },
- { 15, 6 },
- { 15, 6 },
- { 15, 6 },
- { 64, 5 },
- { 64, 5 },
- { 64, 5 },
- { 64, 5 },
- { 64, 5 },
- { 64, 5 },
- { 64, 5 },
- { 64, 5 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 7, 4 },
- { 7, 4 },
- { 7, 4 },
- { 7, 4 },
- { 7, 4 },
- { 7, 4 },
- { 7, 4 },
- { 7, 4 },
- { 7, 4 },
- { 7, 4 },
- { 7, 4 },
- { 7, 4 },
- { 7, 4 },
- { 7, 4 },
- { 7, 4 },
- { 7, 4 },
- { -2, 3 },
- { -2, 3 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -3, 4 },
- { 1792, 3 },
- { 1792, 3 },
- { 1984, 4 },
- { 2048, 4 },
- { 2112, 4 },
- { 2176, 4 },
- { 2240, 4 },
- { 2304, 4 },
- { 1856, 3 },
- { 1856, 3 },
- { 1920, 3 },
- { 1920, 3 },
- { 2368, 4 },
- { 2432, 4 },
- { 2496, 4 },
- { 2560, 4 },
- { 1472, 1 },
- { 1536, 1 },
- { 1600, 1 },
- { 1728, 1 },
- { 704, 1 },
- { 768, 1 },
- { 832, 1 },
- { 896, 1 },
- { 960, 1 },
- { 1024, 1 },
- { 1088, 1 },
- { 1152, 1 },
- { 1216, 1 },
- { 1280, 1 },
- { 1344, 1 },
- { 1408, 1 }
-};
-
-/* Black decoding table. */
-const cfd_node cf_black_decode[] = {
- { 128, 12 },
- { 160, 13 },
- { 224, 12 },
- { 256, 12 },
- { 10, 7 },
- { 11, 7 },
- { 288, 12 },
- { 12, 7 },
- { 9, 6 },
- { 9, 6 },
- { 8, 6 },
- { 8, 6 },
- { 7, 5 },
- { 7, 5 },
- { 7, 5 },
- { 7, 5 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 6, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 1, 3 },
- { 1, 3 },
- { 1, 3 },
- { 1, 3 },
- { 1, 3 },
- { 1, 3 },
- { 1, 3 },
- { 1, 3 },
- { 1, 3 },
- { 1, 3 },
- { 1, 3 },
- { 1, 3 },
- { 1, 3 },
- { 1, 3 },
- { 1, 3 },
- { 1, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 3, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { 2, 2 },
- { -2, 4 },
- { -2, 4 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -3, 5 },
- { 1792, 4 },
- { 1792, 4 },
- { 1984, 5 },
- { 2048, 5 },
- { 2112, 5 },
- { 2176, 5 },
- { 2240, 5 },
- { 2304, 5 },
- { 1856, 4 },
- { 1856, 4 },
- { 1920, 4 },
- { 1920, 4 },
- { 2368, 5 },
- { 2432, 5 },
- { 2496, 5 },
- { 2560, 5 },
- { 18, 3 },
- { 18, 3 },
- { 18, 3 },
- { 18, 3 },
- { 18, 3 },
- { 18, 3 },
- { 18, 3 },
- { 18, 3 },
- { 52, 5 },
- { 52, 5 },
- { 640, 6 },
- { 704, 6 },
- { 768, 6 },
- { 832, 6 },
- { 55, 5 },
- { 55, 5 },
- { 56, 5 },
- { 56, 5 },
- { 1280, 6 },
- { 1344, 6 },
- { 1408, 6 },
- { 1472, 6 },
- { 59, 5 },
- { 59, 5 },
- { 60, 5 },
- { 60, 5 },
- { 1536, 6 },
- { 1600, 6 },
- { 24, 4 },
- { 24, 4 },
- { 24, 4 },
- { 24, 4 },
- { 25, 4 },
- { 25, 4 },
- { 25, 4 },
- { 25, 4 },
- { 1664, 6 },
- { 1728, 6 },
- { 320, 5 },
- { 320, 5 },
- { 384, 5 },
- { 384, 5 },
- { 448, 5 },
- { 448, 5 },
- { 512, 6 },
- { 576, 6 },
- { 53, 5 },
- { 53, 5 },
- { 54, 5 },
- { 54, 5 },
- { 896, 6 },
- { 960, 6 },
- { 1024, 6 },
- { 1088, 6 },
- { 1152, 6 },
- { 1216, 6 },
- { 64, 3 },
- { 64, 3 },
- { 64, 3 },
- { 64, 3 },
- { 64, 3 },
- { 64, 3 },
- { 64, 3 },
- { 64, 3 },
- { 13, 1 },
- { 13, 1 },
- { 13, 1 },
- { 13, 1 },
- { 13, 1 },
- { 13, 1 },
- { 13, 1 },
- { 13, 1 },
- { 13, 1 },
- { 13, 1 },
- { 13, 1 },
- { 13, 1 },
- { 13, 1 },
- { 13, 1 },
- { 13, 1 },
- { 13, 1 },
- { 23, 4 },
- { 23, 4 },
- { 50, 5 },
- { 51, 5 },
- { 44, 5 },
- { 45, 5 },
- { 46, 5 },
- { 47, 5 },
- { 57, 5 },
- { 58, 5 },
- { 61, 5 },
- { 256, 5 },
- { 16, 3 },
- { 16, 3 },
- { 16, 3 },
- { 16, 3 },
- { 17, 3 },
- { 17, 3 },
- { 17, 3 },
- { 17, 3 },
- { 48, 5 },
- { 49, 5 },
- { 62, 5 },
- { 63, 5 },
- { 30, 5 },
- { 31, 5 },
- { 32, 5 },
- { 33, 5 },
- { 40, 5 },
- { 41, 5 },
- { 22, 4 },
- { 22, 4 },
- { 14, 1 },
- { 14, 1 },
- { 14, 1 },
- { 14, 1 },
- { 14, 1 },
- { 14, 1 },
- { 14, 1 },
- { 14, 1 },
- { 14, 1 },
- { 14, 1 },
- { 14, 1 },
- { 14, 1 },
- { 14, 1 },
- { 14, 1 },
- { 14, 1 },
- { 14, 1 },
- { 15, 2 },
- { 15, 2 },
- { 15, 2 },
- { 15, 2 },
- { 15, 2 },
- { 15, 2 },
- { 15, 2 },
- { 15, 2 },
- { 128, 5 },
- { 192, 5 },
- { 26, 5 },
- { 27, 5 },
- { 28, 5 },
- { 29, 5 },
- { 19, 4 },
- { 19, 4 },
- { 20, 4 },
- { 20, 4 },
- { 34, 5 },
- { 35, 5 },
- { 36, 5 },
- { 37, 5 },
- { 38, 5 },
- { 39, 5 },
- { 21, 4 },
- { 21, 4 },
- { 42, 5 },
- { 43, 5 },
- { 0, 3 },
- { 0, 3 },
- { 0, 3 },
- { 0, 3 }
-};
-
-/* 2-D decoding table. */
-const cfd_node cf_2d_decode[] = {
- { 128, 11 },
- { 144, 10 },
- { 6, 7 },
- { 0, 7 },
- { 5, 6 },
- { 5, 6 },
- { 1, 6 },
- { 1, 6 },
- { -4, 4 },
- { -4, 4 },
- { -4, 4 },
- { -4, 4 },
- { -4, 4 },
- { -4, 4 },
- { -4, 4 },
- { -4, 4 },
- { -5, 3 },
- { -5, 3 },
- { -5, 3 },
- { -5, 3 },
- { -5, 3 },
- { -5, 3 },
- { -5, 3 },
- { -5, 3 },
- { -5, 3 },
- { -5, 3 },
- { -5, 3 },
- { -5, 3 },
- { -5, 3 },
- { -5, 3 },
- { -5, 3 },
- { -5, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 4, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { 3, 1 },
- { -2, 4 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -1, 0 },
- { -3, 3 }
-};
-
-/* Uncompresssed decoding table. */
-const cfd_node cf_uncompressed_decode[] = {
- { 64, 12 },
- { 5, 6 },
- { 4, 5 },
- { 4, 5 },
- { 3, 4 },
- { 3, 4 },
- { 3, 4 },
- { 3, 4 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { 0, 1 },
- { -1, 0 },
- { -1, 0 },
- { 8, 6 },
- { 9, 6 },
- { 6, 5 },
- { 6, 5 },
- { 7, 5 },
- { 7, 5 },
- { 4, 4 },
- { 4, 4 },
- { 4, 4 },
- { 4, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 5, 4 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 2, 3 },
- { 3, 3 },
- { 3, 3 },
- { 3, 3 },
- { 3, 3 },
- { 3, 3 },
- { 3, 3 },
- { 3, 3 },
- { 3, 3 },
- { 0, 2 },
- { 0, 2 },
- { 0, 2 },
- { 0, 2 },
- { 0, 2 },
- { 0, 2 },
- { 0, 2 },
- { 0, 2 },
- { 0, 2 },
- { 0, 2 },
- { 0, 2 },
- { 0, 2 },
- { 0, 2 },
- { 0, 2 },
- { 0, 2 },
- { 0, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 },
- { 1, 2 }
-};
-
-/* Dummy executable code to pacify compilers. */
-void scfdtab_dummy(void) { }
-
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 231fe6f0..e64af123 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -1,8 +1,1159 @@
#ifndef _FITZ_H_
#define _FITZ_H_
-#include "fitz_base.h"
-#include "fitz_stream.h"
-#include "fitz_draw.h"
+/*
+ * Include the standard libc headers.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <stdarg.h>
+#include <string.h>
+#include <math.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <float.h> /* FLT_EPSILON */
+#include <fcntl.h> /* O_RDONLY & co */
+
+#define nil ((void*)0)
+
+#define nelem(x) (sizeof(x)/sizeof((x)[0]))
+
+/*
+ * Some differences in libc can be smoothed over
+ */
+
+#ifdef _MSC_VER /* Microsoft Visual C */
+
+#pragma warning( disable: 4244 ) /* conversion from X to Y, possible loss of data */
+#pragma warning( disable: 4996 ) /* The POSIX name for this item is deprecated */
+#pragma warning( disable: 4996 ) /* This function or variable may be unsafe */
+
+#include <io.h>
+
+int gettimeofday(struct timeval *tv, struct timezone *tz);
+
+#define snprintf _snprintf
+#define hypotf _hypotf
+#define strtoll _strtoi64
+
+#else /* Unix or close enough */
+
+#include <unistd.h>
+
+#define O_BINARY 0
+
+#endif
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+#ifndef M_SQRT2
+#define M_SQRT2 1.41421356237309504880
+#endif
+
+/*
+ * Variadic macros, inline and restrict keywords
+ */
+
+#if __STDC_VERSION__ == 199901L /* C99 */
+
+#define fz_throw(...) fz_throwimp(__FILE__, __LINE__, __func__, __VA_ARGS__)
+#define fz_rethrow(cause, ...) fz_rethrowimp(__FILE__, __LINE__, __func__, cause, __VA_ARGS__)
+#define fz_catch(cause, ...) fz_catchimp(__FILE__, __LINE__, __func__, cause, __VA_ARGS__)
+
+#elif _MSC_VER >= 1500 /* MSVC 9 or newer */
+
+#define inline __inline
+#define restrict __restrict
+#define fz_throw(...) fz_throwimp(__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
+#define fz_rethrow(cause, ...) fz_rethrowimp(__FILE__, __LINE__, __FUNCTION__, cause, __VA_ARGS__)
+#define fz_catch(cause, ...) fz_catchimp(__FILE__, __LINE__, __FUNCTION__, cause, __VA_ARGS__)
+
+#elif __GNUC__ >= 3 /* GCC 3 or newer */
+
+#define inline __inline
+#define restrict __restrict
+#define fz_throw(fmt...) fz_throwimp(__FILE__, __LINE__, __FUNCTION__, fmt)
+#define fz_rethrow(cause, fmt...) fz_rethrowimp(__FILE__, __LINE__, __FUNCTION__, cause, fmt)
+#define fz_catch(cause, fmt...) fz_catchimp(__FILE__, __LINE__, __FUNCTION__, cause, fmt)
+
+#else /* Unknown or ancient */
+
+#define inline
+#define restrict
+#define fz_throw fz_throwimpx
+#define fz_rethrow fz_rethrowimpx
+#define fz_catch fz_catchimpx
+
+#endif
+
+/*
+ * GCC can do type checking of printf strings
+ */
+
+#ifndef __printflike
+#if __GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ >= 7
+#define __printflike(fmtarg, firstvararg) \
+ __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
+#else
+#define __printflike(fmtarg, firstvararg)
+#endif
+#endif
+
+/*
+ * Error handling
+ */
+
+typedef int fz_error;
+
+void fz_warn(char *fmt, ...) __printflike(1, 2);
+
+fz_error fz_throwimp(const char *file, int line, const char *func, char *fmt, ...) __printflike(4, 5);
+fz_error fz_rethrowimp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...) __printflike(5, 6);
+void fz_catchimp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...) __printflike(5, 6);
+
+fz_error fz_throwimpx(char *fmt, ...) __printflike(1, 2);
+fz_error fz_rethrowimpx(fz_error cause, char *fmt, ...) __printflike(2, 3);
+void fz_catchimpx(fz_error cause, char *fmt, ...) __printflike(2, 3);
+
+#define fz_okay ((fz_error)0)
+
+/*
+ * Basic runtime and utility functions
+ */
+
+#define ABS(x) ( (x) < 0 ? -(x) : (x) )
+#define MIN(a,b) ( (a) < (b) ? (a) : (b) )
+#define MAX(a,b) ( (a) > (b) ? (a) : (b) )
+#define CLAMP(x,a,b) ( (x) > (b) ? (b) : ( (x) < (a) ? (a) : (x) ) )
+
+/* memory allocation */
+void *fz_malloc(int n);
+void *fz_realloc(void *p, int n);
+void fz_free(void *p);
+char *fz_strdup(char *s);
+
+/* runtime (hah!) test for endian-ness */
+int fz_isbigendian(void);
+
+/* safe string functions */
+char *fz_strsep(char **stringp, const char *delim);
+int fz_strlcpy(char *dst, const char *src, int n);
+int fz_strlcat(char *dst, const char *src, int n);
+
+/* utf-8 encoding and decoding */
+int chartorune(int *rune, char *str);
+int runetochar(char *str, int *rune);
+int runelen(int c);
+
+/* getopt */
+extern int fz_getopt(int nargc, char * const * nargv, const char *ostr);
+extern int fz_optind;
+extern char *fz_optarg;
+
+/*
+ * Generic hash-table with fixed-length keys.
+ */
+
+typedef struct fz_hashtable_s fz_hashtable;
+
+fz_hashtable * fz_newhash(int initialsize, int keylen);
+void fz_debughash(fz_hashtable *table);
+void fz_emptyhash(fz_hashtable *table);
+void fz_freehash(fz_hashtable *table);
+
+void *fz_hashfind(fz_hashtable *table, void *key);
+void fz_hashinsert(fz_hashtable *table, void *key, void *val);
+void fz_hashremove(fz_hashtable *table, void *key);
+
+int fz_hashlen(fz_hashtable *table);
+void *fz_hashgetkey(fz_hashtable *table, int idx);
+void *fz_hashgetval(fz_hashtable *table, int idx);
+
+/*
+ * Math and geometry
+ */
+
+/* Multiply scaled two integers in the 0..255 range */
+static inline int fz_mul255(int a, int b)
+{
+ /* see Jim Blinn's book "Dirty Pixels" for how this works */
+ int x = a * b + 128;
+ x += x >> 8;
+ return x >> 8;
+}
+
+/* Expand a value A from the 0...255 range to the 0..256 range */
+#define FZ_EXPAND(A) ((A)+((A)>>7))
+
+/* Combine values A (in any range) and B (in the 0..256 range),
+ * to give a single value in the same range as A was. */
+#define FZ_COMBINE(A,B) (((A)*(B))>>8)
+
+/* Blend SRC and DST (in the same range) together according to
+ * AMOUNT (in the 0...256 range). */
+#define FZ_BLEND(SRC, DST, AMOUNT) ((((SRC)-(DST))*(AMOUNT) + ((DST)<<8))>>8)
+
+typedef struct fz_matrix_s fz_matrix;
+typedef struct fz_point_s fz_point;
+typedef struct fz_rect_s fz_rect;
+typedef struct fz_bbox_s fz_bbox;
+
+extern const fz_rect fz_unitrect;
+extern const fz_rect fz_emptyrect;
+extern const fz_rect fz_infiniterect;
+
+extern const fz_bbox fz_unitbbox;
+extern const fz_bbox fz_emptybbox;
+extern const fz_bbox fz_infinitebbox;
+
+#define fz_isemptyrect(r) ((r).x0 == (r).x1)
+#define fz_isinfiniterect(r) ((r).x0 > (r).x1)
+
+struct fz_matrix_s
+{
+ float a, b, c, d, e, f;
+};
+
+struct fz_point_s
+{
+ float x, y;
+};
+
+struct fz_rect_s
+{
+ float x0, y0;
+ float x1, y1;
+};
+
+struct fz_bbox_s
+{
+ int x0, y0;
+ int x1, y1;
+};
+
+extern const fz_matrix fz_identity;
+
+fz_matrix fz_concat(fz_matrix one, fz_matrix two);
+fz_matrix fz_scale(float sx, float sy);
+fz_matrix fz_rotate(float theta);
+fz_matrix fz_translate(float tx, float ty);
+fz_matrix fz_invertmatrix(fz_matrix m);
+int fz_isrectilinear(fz_matrix m);
+float fz_matrixexpansion(fz_matrix m);
+
+fz_bbox fz_roundrect(fz_rect r);
+fz_bbox fz_intersectbbox(fz_bbox a, fz_bbox b);
+fz_bbox fz_unionbbox(fz_bbox a, fz_bbox b);
+
+fz_point fz_transformpoint(fz_matrix m, fz_point p);
+fz_point fz_transformvector(fz_matrix m, fz_point p);
+fz_rect fz_transformrect(fz_matrix m, fz_rect r);
+
+/*
+ * Basic crypto functions.
+ * Independent of the rest of fitz.
+ * For further encapsulation in filters, or not.
+ */
+
+/* md5 digests */
+
+typedef struct fz_md5_s fz_md5;
+
+struct fz_md5_s
+{
+ unsigned int state[4];
+ unsigned int count[2];
+ unsigned char buffer[64];
+};
+
+void fz_md5init(fz_md5 *state);
+void fz_md5update(fz_md5 *state, const unsigned char *input, const unsigned inlen);
+void fz_md5final(fz_md5 *state, unsigned char digest[16]);
+
+/* arc4 crypto */
+
+typedef struct fz_arc4_s fz_arc4;
+
+struct fz_arc4_s
+{
+ unsigned x;
+ unsigned y;
+ unsigned char state[256];
+};
+
+void fz_arc4init(fz_arc4 *state, const unsigned char *key, const unsigned len);
+unsigned char fz_arc4next(fz_arc4 *state);
+void fz_arc4encrypt(fz_arc4 *state, unsigned char *dest, const unsigned char *src, const unsigned len);
+
+/* AES block cipher implementation from XYSSL */
+
+typedef struct fz_aes_s fz_aes;
+
+#define AES_DECRYPT 0
+#define AES_ENCRYPT 1
+
+struct fz_aes_s
+{
+ int nr; /* number of rounds */
+ unsigned long *rk; /* AES round keys */
+ unsigned long buf[68]; /* unaligned data */
+};
+
+void aes_setkey_enc( fz_aes *ctx, const unsigned char *key, int keysize );
+void aes_setkey_dec( fz_aes *ctx, const unsigned char *key, int keysize );
+void aes_crypt_cbc( fz_aes *ctx, int mode, int length,
+ unsigned char iv[16],
+ const unsigned char *input,
+ unsigned char *output );
+
+/*
+ * Dynamic objects.
+ * The same type of objects as found in PDF and PostScript.
+ * Used by the filters and the mupdf parser.
+ */
+
+typedef struct fz_obj_s fz_obj;
+typedef struct fz_keyval_s fz_keyval;
+
+struct pdf_xref_s;
+
+typedef enum fz_objkind_e
+{
+ FZ_NULL,
+ FZ_BOOL,
+ FZ_INT,
+ FZ_REAL,
+ FZ_STRING,
+ FZ_NAME,
+ FZ_ARRAY,
+ FZ_DICT,
+ FZ_INDIRECT
+} fz_objkind;
+
+struct fz_keyval_s
+{
+ fz_obj *k;
+ fz_obj *v;
+};
+
+struct fz_obj_s
+{
+ int refs;
+ fz_objkind kind;
+ union
+ {
+ int b;
+ int i;
+ float f;
+ struct {
+ unsigned short len;
+ char buf[1];
+ } s;
+ char n[1];
+ struct {
+ int len;
+ int cap;
+ fz_obj **items;
+ } a;
+ struct {
+ char sorted;
+ int len;
+ int cap;
+ fz_keyval *items;
+ } d;
+ struct {
+ int num;
+ int gen;
+ struct pdf_xref_s *xref;
+ fz_obj *obj;
+ } r;
+ } u;
+};
+
+fz_obj * fz_newnull(void);
+fz_obj * fz_newbool(int b);
+fz_obj * fz_newint(int i);
+fz_obj * fz_newreal(float f);
+fz_obj * fz_newname(char *str);
+fz_obj * fz_newstring(char *str, int len);
+fz_obj * fz_newindirect(int num, int gen, struct pdf_xref_s *xref);
+
+fz_obj * fz_newarray(int initialcap);
+fz_obj * fz_newdict(int initialcap);
+fz_obj * fz_copyarray(fz_obj *array);
+fz_obj * fz_copydict(fz_obj *dict);
+
+fz_obj *fz_keepobj(fz_obj *obj);
+void fz_dropobj(fz_obj *obj);
+
+/* type queries */
+int fz_isnull(fz_obj *obj);
+int fz_isbool(fz_obj *obj);
+int fz_isint(fz_obj *obj);
+int fz_isreal(fz_obj *obj);
+int fz_isname(fz_obj *obj);
+int fz_isstring(fz_obj *obj);
+int fz_isarray(fz_obj *obj);
+int fz_isdict(fz_obj *obj);
+int fz_isindirect(fz_obj *obj);
+
+int fz_objcmp(fz_obj *a, fz_obj *b);
+
+fz_obj *fz_resolveindirect(fz_obj *obj);
+
+/* silent failure, no error reporting */
+int fz_tobool(fz_obj *obj);
+int fz_toint(fz_obj *obj);
+float fz_toreal(fz_obj *obj);
+char *fz_toname(fz_obj *obj);
+char *fz_tostrbuf(fz_obj *obj);
+int fz_tostrlen(fz_obj *obj);
+int fz_tonum(fz_obj *obj);
+int fz_togen(fz_obj *obj);
+
+int fz_arraylen(fz_obj *array);
+fz_obj *fz_arrayget(fz_obj *array, int i);
+void fz_arrayput(fz_obj *array, int i, fz_obj *obj);
+void fz_arraypush(fz_obj *array, fz_obj *obj);
+
+int fz_dictlen(fz_obj *dict);
+fz_obj *fz_dictgetkey(fz_obj *dict, int idx);
+fz_obj *fz_dictgetval(fz_obj *dict, int idx);
+fz_obj *fz_dictget(fz_obj *dict, fz_obj *key);
+fz_obj *fz_dictgets(fz_obj *dict, char *key);
+fz_obj *fz_dictgetsa(fz_obj *dict, char *key, char *abbrev);
+void fz_dictput(fz_obj *dict, fz_obj *key, fz_obj *val);
+void fz_dictputs(fz_obj *dict, char *key, fz_obj *val);
+void fz_dictdel(fz_obj *dict, fz_obj *key);
+void fz_dictdels(fz_obj *dict, char *key);
+void fz_sortdict(fz_obj *dict);
+
+int fz_sprintobj(char *s, int n, fz_obj *obj, int tight);
+int fz_fprintobj(FILE *fp, fz_obj *obj, int tight);
+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.
+ *
+ * A buffer owns the memory it has allocated, unless ownsdata is false,
+ * in which case the creator of the buffer owns it.
+ */
+
+typedef struct fz_buffer_s fz_buffer;
+
+#define FZ_BUFSIZE (8 * 1024)
+
+struct fz_buffer_s
+{
+ int refs;
+ int ownsdata;
+ unsigned char *bp;
+ unsigned char *rp;
+ unsigned char *wp;
+ unsigned char *ep;
+ int eof;
+};
+
+fz_buffer * fz_newbuffer(int size);
+fz_buffer * fz_newbufferwithmemory(unsigned char *data, 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.
+ */
+
+typedef struct fz_stream_s fz_stream;
+
+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;
+};
+
+/*
+ * 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_keepstream(fz_stream *stm);
+void fz_dropstream(fz_stream *stm);
+
+int fz_tell(fz_stream *stm);
+fz_error fz_seek(fz_stream *stm, int offset, int whence);
+
+/*
+ * Input stream functions.
+ */
+
+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);
+
+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);
+}
+
+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);
+}
+
+static inline void fz_unreadbyte(fz_stream *stm)
+{
+ fz_buffer *buf = stm->buffer;
+ buf->rp--;
+}
+
+/*
+ * Resources and other graphics related objects.
+ */
+
+enum { FZ_MAXCOLORS = 32 };
+
+typedef enum fz_blendkind_e
+{
+ /* PDF 1.4 -- standard separable */
+ FZ_BNORMAL,
+ FZ_BMULTIPLY,
+ FZ_BSCREEN,
+ FZ_BOVERLAY,
+ FZ_BDARKEN,
+ FZ_BLIGHTEN,
+ FZ_BCOLORDODGE,
+ FZ_BCOLORBURN,
+ FZ_BHARDLIGHT,
+ FZ_BSOFTLIGHT,
+ FZ_BDIFFERENCE,
+ FZ_BEXCLUSION,
+
+ /* PDF 1.4 -- standard non-separable */
+ FZ_BHUE,
+ FZ_BSATURATION,
+ FZ_BCOLOR,
+ FZ_BLUMINOSITY,
+} fz_blendkind;
+
+/*
+ * Pixmaps have n components per pixel. the last is always alpha.
+ * premultiplied alpha when rendering, but non-premultiplied for colorspace
+ * conversions and rescaling.
+ */
+
+typedef struct fz_pixmap_s fz_pixmap;
+typedef struct fz_colorspace_s fz_colorspace;
+
+struct fz_pixmap_s
+{
+ int refs;
+ int x, y, w, h, n;
+ fz_colorspace *colorspace;
+ unsigned char *samples;
+};
+
+fz_pixmap * fz_newpixmapwithrect(fz_colorspace *, fz_bbox bbox);
+fz_pixmap * fz_newpixmap(fz_colorspace *, int x, int y, int w, int h);
+fz_pixmap *fz_keeppixmap(fz_pixmap *map);
+void fz_droppixmap(fz_pixmap *map);
+
+void fz_debugpixmap(fz_pixmap *map, char *prefix);
+void fz_clearpixmap(fz_pixmap *map, unsigned char value);
+
+fz_pixmap * fz_scalepixmap(fz_pixmap *src, int xdenom, int ydenom);
+
+/*
+ * Colorspace resources.
+ */
+
+extern fz_colorspace *pdf_devicegray;
+extern fz_colorspace *pdf_devicergb;
+extern fz_colorspace *pdf_devicebgr;
+extern fz_colorspace *pdf_devicecmyk;
+extern fz_colorspace *pdf_devicelab;
+extern fz_colorspace *pdf_devicepattern;
+
+struct fz_colorspace_s
+{
+ int refs;
+ char name[16];
+ int n;
+ void (*convpixmap)(fz_colorspace *ss, fz_pixmap *sp, fz_colorspace *ds, fz_pixmap *dp);
+ void (*convcolor)(fz_colorspace *ss, float *sv, fz_colorspace *ds, float *dv);
+ void (*toxyz)(fz_colorspace *, float *src, float *xyz);
+ void (*fromxyz)(fz_colorspace *, float *xyz, float *dst);
+ void (*freefunc)(fz_colorspace *);
+};
+
+fz_colorspace *fz_keepcolorspace(fz_colorspace *cs);
+void fz_dropcolorspace(fz_colorspace *cs);
+
+void fz_convertcolor(fz_colorspace *srcs, float *srcv, fz_colorspace *dsts, float *dstv);
+void fz_convertpixmap(fz_colorspace *srcs, fz_pixmap *srcv, fz_colorspace *dsts, fz_pixmap *dstv);
+
+void fz_stdconvcolor(fz_colorspace *srcs, float *srcv, fz_colorspace *dsts, float *dstv);
+void fz_stdconvpixmap(fz_colorspace *srcs, fz_pixmap *srcv, fz_colorspace *dsts, fz_pixmap *dstv);
+
+/*
+ * Fonts come in two variants:
+ * Regular fonts are handled by FreeType.
+ * Type 3 fonts have callbacks to the interpreter.
+ */
+
+struct fz_device_s;
+struct pdf_xref_s;
+
+typedef struct fz_font_s fz_font;
+char *ft_errorstring(int err);
+
+struct fz_font_s
+{
+ int refs;
+ char name[32];
+
+ void *ftface; /* has an FT_Face if used */
+ int ftsubstitute; /* ... substitute metrics */
+ int fthint; /* ... force hinting for DynaLab fonts */
+
+ fz_matrix t3matrix;
+ fz_obj *t3resources;
+ fz_buffer **t3procs; /* has 256 entries if used */
+ float *t3widths; /* has 256 entries if used */
+ void *t3xref; /* a pdf_xref for the callback */
+ fz_error (*t3runcontentstream)(struct fz_device_s *dev, fz_matrix ctm,
+ struct pdf_xref_s *xref, fz_obj *resources, fz_buffer *contents);
+
+ fz_rect bbox;
+
+ /* substitute metrics */
+ int widthcount;
+ int *widthtable;
+};
+
+fz_error fz_newfreetypefont(fz_font **fontp, char *name, int substitute);
+fz_error fz_loadfreetypefontfile(fz_font *font, char *path, int index);
+fz_error fz_loadfreetypefontbuffer(fz_font *font, unsigned char *data, int len, int index);
+fz_font * fz_newtype3font(char *name, fz_matrix matrix);
+
+fz_error fz_newfontfrombuffer(fz_font **fontp, unsigned char *data, int len, int index);
+fz_error fz_newfontfromfile(fz_font **fontp, char *path, int index);
+
+fz_font * fz_keepfont(fz_font *font);
+void fz_dropfont(fz_font *font);
+
+void fz_debugfont(fz_font *font);
+void fz_setfontbbox(fz_font *font, float xmin, float ymin, float xmax, float ymax);
+
+/*
+ * Vector path buffer.
+ * It can be stroked and dashed, or be filled.
+ * It has a fill rule (nonzero or evenodd).
+ *
+ * When rendering, they are flattened, stroked and dashed straight
+ * into the Global Edge List.
+ */
+
+typedef struct fz_path_s fz_path;
+typedef struct fz_strokestate_s fz_strokestate;
+
+typedef union fz_pathel_s fz_pathel;
+
+typedef enum fz_pathelkind_e
+{
+ FZ_MOVETO,
+ FZ_LINETO,
+ FZ_CURVETO,
+ FZ_CLOSEPATH
+} fz_pathelkind;
+
+union fz_pathel_s
+{
+ fz_pathelkind k;
+ float v;
+};
+
+struct fz_strokestate_s
+{
+ int linecap;
+ int linejoin;
+ float linewidth;
+ float miterlimit;
+ float dashphase;
+ int dashlen;
+ float dashlist[32];
+};
+
+struct fz_path_s
+{
+ int len, cap;
+ fz_pathel *els;
+};
+
+fz_path *fz_newpath(void);
+void fz_moveto(fz_path*, float x, float y);
+void fz_lineto(fz_path*, float x, float y);
+void fz_curveto(fz_path*, float, float, float, float, float, float);
+void fz_curvetov(fz_path*, float, float, float, float);
+void fz_curvetoy(fz_path*, float, float, float, float);
+void fz_closepath(fz_path*);
+void fz_freepath(fz_path *path);
+
+fz_path *fz_clonepath(fz_path *old);
+
+fz_rect fz_boundpath(fz_path *path, fz_strokestate *stroke, fz_matrix ctm);
+void fz_debugpath(fz_path *, int indent);
+
+/*
+ * Text buffer.
+ *
+ * The trm field contains the a, b, c and d coefficients.
+ * The e and f coefficients come from the individual elements,
+ * together they form the transform matrix for the glyph.
+ *
+ * Glyphs are referenced by glyph ID.
+ * The Unicode text equivalent is kept in a separate array
+ * with indexes into the glyph array.
+ */
+
+typedef struct fz_text_s fz_text;
+typedef struct fz_textel_s fz_textel;
+
+struct fz_textel_s
+{
+ float x, y;
+ int gid; /* -1 for one gid to many ucs mappings */
+ int ucs; /* -1 for one ucs to many gid mappings */
+};
+
+struct fz_text_s
+{
+ fz_font *font;
+ fz_matrix trm;
+ int wmode;
+ int len, cap;
+ fz_textel *els;
+};
+
+fz_text * fz_newtext(fz_font *face, fz_matrix trm, int wmode);
+void fz_addtext(fz_text *text, int gid, int ucs, float x, float y);
+void fz_endtext(fz_text *text);
+void fz_freetext(fz_text *text);
+void fz_debugtext(fz_text*, int indent);
+fz_rect fz_boundtext(fz_text *text, fz_matrix ctm);
+fz_text *fz_clonetext(fz_text *old);
+
+/*
+ * The shading code uses gouraud shaded triangle meshes.
+ */
+
+typedef struct fz_shade_s fz_shade;
+
+struct fz_shade_s
+{
+ int refs;
+
+ fz_rect bbox; /* can be fz_infiniterect */
+ fz_colorspace *cs;
+
+ fz_matrix matrix; /* matrix from pattern dict */
+ int usebackground; /* background color for fills but not 'sh' */
+ float background[FZ_MAXCOLORS];
+
+ int usefunction;
+ float function[256][FZ_MAXCOLORS];
+
+ int meshlen;
+ int meshcap;
+ float *mesh; /* [x y t] or [x y c1 ... cn] */
+};
+
+fz_shade *fz_keepshade(fz_shade *shade);
+void fz_dropshade(fz_shade *shade);
+void fz_debugshade(fz_shade *shade);
+
+fz_rect fz_boundshade(fz_shade *shade, fz_matrix ctm);
+void fz_rendershade(fz_shade *shade, fz_matrix ctm, fz_pixmap *dst, fz_bbox bbox);
+
+/*
+ * Glyph cache
+ */
+
+typedef struct fz_glyphcache_s fz_glyphcache;
+
+fz_glyphcache * fz_newglyphcache(void);
+fz_pixmap * fz_renderftglyph(fz_font *font, int cid, fz_matrix trm);
+fz_pixmap * fz_rendert3glyph(fz_font *font, int cid, fz_matrix trm);
+fz_pixmap * fz_renderglyph(fz_glyphcache*, fz_font*, int, fz_matrix);
+void fz_freeglyphcache(fz_glyphcache *);
+
+/*
+ * Scan converter
+ */
+
+typedef struct fz_edge_s fz_edge;
+typedef struct fz_gel_s fz_gel;
+typedef struct fz_ael_s fz_ael;
+
+struct fz_edge_s
+{
+ int x, e, h, y;
+ int adjup, adjdown;
+ int xmove;
+ int xdir, ydir; /* -1 or +1 */
+};
+
+struct fz_gel_s
+{
+ fz_bbox clip;
+ fz_bbox bbox;
+ int cap;
+ int len;
+ fz_edge *edges;
+};
+
+struct fz_ael_s
+{
+ int cap;
+ int len;
+ fz_edge **edges;
+};
+
+fz_gel * fz_newgel(void);
+void fz_insertgel(fz_gel *gel, float x0, float y0, float x1, float y1);
+fz_bbox fz_boundgel(fz_gel *gel);
+void fz_resetgel(fz_gel *gel, fz_bbox clip);
+void fz_sortgel(fz_gel *gel);
+void fz_freegel(fz_gel *gel);
+int fz_isrectgel(fz_gel *gel);
+
+fz_ael * fz_newael(void);
+void fz_freeael(fz_ael *ael);
+
+fz_error fz_scanconvert(fz_gel *gel, fz_ael *ael, int eofill,
+ fz_bbox clip, fz_pixmap *pix, unsigned char *colorbv, fz_pixmap *image, fz_matrix *invmat);
+
+void fz_fillpath(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness);
+void fz_strokepath(fz_gel *gel, fz_path *path, fz_strokestate *stroke, fz_matrix ctm, float flatness, float linewidth);
+void fz_dashpath(fz_gel *gel, fz_path *path, fz_strokestate *stroke, fz_matrix ctm, float flatness, float linewidth);
+
+/*
+ * The device interface.
+ */
+
+enum
+{
+ FZ_IGNOREIMAGE = 1,
+ FZ_IGNORESHADE = 2,
+};
+
+typedef struct fz_device_s fz_device;
+
+struct fz_device_s
+{
+ int hints;
+
+ void *user;
+ void (*freeuser)(void *);
+
+ void (*fillpath)(void *, fz_path *, int evenodd, fz_matrix, fz_colorspace *, float *color, float alpha);
+ void (*strokepath)(void *, fz_path *, fz_strokestate *, fz_matrix, fz_colorspace *, float *color, float alpha);
+ void (*clippath)(void *, fz_path *, int evenodd, fz_matrix);
+ void (*clipstrokepath)(void *, fz_path *, fz_strokestate *, fz_matrix);
+
+ void (*filltext)(void *, fz_text *, fz_matrix, fz_colorspace *, float *color, float alpha);
+ void (*stroketext)(void *, fz_text *, fz_strokestate *, fz_matrix, fz_colorspace *, float *color, float alpha);
+ void (*cliptext)(void *, fz_text *, fz_matrix, int accumulate);
+ void (*clipstroketext)(void *, fz_text *, fz_strokestate *, fz_matrix);
+ void (*ignoretext)(void *, fz_text *, fz_matrix);
+
+ void (*fillshade)(void *, fz_shade *shd, fz_matrix ctm);
+ void (*fillimage)(void *, fz_pixmap *img, fz_matrix ctm);
+ void (*fillimagemask)(void *, fz_pixmap *img, fz_matrix ctm, fz_colorspace *, float *color, float alpha);
+ void (*clipimagemask)(void *, fz_pixmap *img, fz_matrix ctm);
+
+ void (*popclip)(void *);
+};
+
+fz_device *fz_newdevice(void *user);
+void fz_freedevice(fz_device *dev);
+
+fz_device *fz_newtracedevice(void);
+
+fz_device *fz_newbboxdevice(fz_bbox *bboxp);
+
+fz_device *fz_newdrawdevice(fz_glyphcache *cache, fz_pixmap *dest);
+
+/*
+ * Text extraction device
+ */
+
+typedef struct fz_textspan_s fz_textspan;
+typedef struct fz_textchar_s fz_textchar;
+
+struct fz_textchar_s
+{
+ int c;
+ fz_bbox bbox;
+};
+
+struct fz_textspan_s
+{
+ fz_font *font;
+ float size;
+ int wmode;
+ int len, cap;
+ fz_textchar *text;
+ fz_textspan *next;
+ int eol;
+};
+
+fz_textspan * fz_newtextspan(void);
+void fz_freetextspan(fz_textspan *line);
+void fz_debugtextspan(fz_textspan *line);
+void fz_debugtextspanxml(fz_textspan *span);
+
+fz_device *fz_newtextdevice(fz_textspan *text);
+
+/*
+ * Display list device -- record and play back device commands.
+ */
+
+typedef struct fz_displaylist_s fz_displaylist;
+typedef struct fz_displaynode_s fz_displaynode;
+
+typedef enum fz_displaycommand_e
+{
+ FZ_CMDFILLPATH,
+ FZ_CMDSTROKEPATH,
+ FZ_CMDCLIPPATH,
+ FZ_CMDCLIPSTROKEPATH,
+ FZ_CMDFILLTEXT,
+ FZ_CMDSTROKETEXT,
+ FZ_CMDCLIPTEXT,
+ FZ_CMDCLIPSTROKETEXT,
+ FZ_CMDIGNORETEXT,
+ FZ_CMDFILLSHADE,
+ FZ_CMDFILLIMAGE,
+ FZ_CMDFILLIMAGEMASK,
+ FZ_CMDCLIPIMAGEMASK,
+ FZ_CMDPOPCLIP,
+} fz_displaycommand;
+
+struct fz_displaylist_s
+{
+ fz_displaynode *first;
+ fz_displaynode *last;
+};
+
+struct fz_displaynode_s
+{
+ fz_displaycommand cmd;
+ fz_displaynode *next;
+ union {
+ fz_path *path;
+ fz_text *text;
+ fz_shade *shade;
+ fz_pixmap *image;
+ } item;
+ fz_strokestate *stroke;
+ int flag; /* evenodd, accumulate, ... */
+ fz_matrix ctm;
+ fz_colorspace *colorspace;
+ float alpha;
+ float color[FZ_MAXCOLORS];
+};
+
+fz_displaylist *fz_newdisplaylist(void);
+void fz_freedisplaylist(fz_displaylist *list);
+fz_device *fz_newlistdevice(fz_displaylist *list);
+void fz_executedisplaylist(fz_displaylist *list, fz_device *dev, fz_matrix ctm);
+
+/*
+ * Function pointers for plotting functions.
+ * They can be replaced by cpu-optimized versions.
+ */
+
+extern void fz_accelerate(void);
+extern void fz_acceleratearch(void);
+
+extern void (*fz_duff_ni1on)(unsigned char*,int,int,unsigned char*,int,unsigned char*,int,int,int);
+extern void (*fz_duff_1i1o1)(unsigned char*,int,unsigned char*,int,unsigned char*,int,int,int);
+extern void (*fz_duff_2i1o2)(unsigned char*,int,unsigned char*,int,unsigned char*,int,int,int);
+extern void (*fz_duff_4i1o4)(unsigned char*,int,unsigned char*,int,unsigned char*,int,int,int);
+
+extern void (*fz_path_1o1)(unsigned char*,unsigned char,int,unsigned char*);
+extern void (*fz_path_w2i1o2)(unsigned char*,unsigned char*,unsigned char,int,unsigned char*);
+extern void (*fz_path_w4i1o4)(unsigned char*,unsigned char*,unsigned char,int,unsigned char*);
+
+extern void (*fz_text_1o1)(unsigned char*,int,unsigned char*,int,int,int);
+extern void (*fz_text_w2i1o2)(unsigned char*,unsigned char*,int,unsigned char*,int,int,int);
+extern void (*fz_text_w4i1o4)(unsigned char*,unsigned char*,int,unsigned char*,int,int,int);
+
+extern void (*fz_img_non)(unsigned char*,unsigned char,int,unsigned char*,fz_pixmap*,fz_matrix*);
+extern void (*fz_img_1o1)(unsigned char*,unsigned char,int,unsigned char*,fz_pixmap*,int u, int v, int fa, int fb);
+extern void (*fz_img_4o4)(unsigned char*,unsigned char,int,unsigned char*,fz_pixmap*,int u, int v, int fa, int fb);
+extern void (*fz_img_2o2)(unsigned char*,unsigned char,int,unsigned char*,fz_pixmap*,int u, int v, int fa, int fb);
+extern void (*fz_img_w2i1o2)(unsigned char*,unsigned char*,unsigned char,int,unsigned char*,fz_pixmap*,int u, int v, int fa, int fb);
+extern void (*fz_img_w4i1o4)(unsigned char*,unsigned char*,unsigned char,int,unsigned char*,fz_pixmap*,int u, int v, int fa, int fb);
+
+extern void (*fz_decodetile)(fz_pixmap *pix, int skip, float *decode);
+extern void (*fz_loadtile1)(unsigned char*, int sw, unsigned char*, int dw, int w, int h, int pad);
+extern void (*fz_loadtile2)(unsigned char*, int sw, unsigned char*, int dw, int w, int h, int pad);
+extern void (*fz_loadtile4)(unsigned char*, int sw, unsigned char*, int dw, int w, int h, int pad);
+extern void (*fz_loadtile8)(unsigned char*, int sw, unsigned char*, int dw, int w, int h, int pad);
+extern void (*fz_loadtile16)(unsigned char*, int sw, unsigned char*, int dw, int w, int h, int pad);
+
+extern void (*fz_srown)(unsigned char *src, unsigned char *dst, int w, int denom, int n);
+extern void (*fz_srow1)(unsigned char *src, unsigned char *dst, int w, int denom);
+extern void (*fz_srow2)(unsigned char *src, unsigned char *dst, int w, int denom);
+extern void (*fz_srow4)(unsigned char *src, unsigned char *dst, int w, int denom);
+extern void (*fz_srow5)(unsigned char *src, unsigned char *dst, int w, int denom);
+
+extern void (*fz_scoln)(unsigned char *src, unsigned char *dst, int w, int denom, int n);
+extern void (*fz_scol1)(unsigned char *src, unsigned char *dst, int w, int denom);
+extern void (*fz_scol2)(unsigned char *src, unsigned char *dst, int w, int denom);
+extern void (*fz_scol4)(unsigned char *src, unsigned char *dst, int w, int denom);
+extern void (*fz_scol5)(unsigned char *src, unsigned char *dst, int w, int denom);
#endif
diff --git a/fitz/fitz_base.h b/fitz/fitz_base.h
deleted file mode 100644
index 2f810709..00000000
--- a/fitz/fitz_base.h
+++ /dev/null
@@ -1,252 +0,0 @@
-#ifndef _FITZ_BASE_H_
-#define _FITZ_BASE_H_
-
-/*
- * Include the standard libc headers.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <stdarg.h>
-#include <string.h>
-#include <math.h>
-
-#include <assert.h>
-#include <errno.h>
-#include <float.h> /* FLT_EPSILON */
-#include <fcntl.h> /* O_RDONLY & co */
-
-#define nil ((void*)0)
-
-#define nelem(x) (sizeof(x)/sizeof((x)[0]))
-
-/*
- * Some differences in libc can be smoothed over
- */
-
-#ifdef _MSC_VER /* Microsoft Visual C */
-
-#pragma warning( disable: 4244 ) /* conversion from X to Y, possible loss of data */
-#pragma warning( disable: 4996 ) /* The POSIX name for this item is deprecated */
-#pragma warning( disable: 4996 ) /* This function or variable may be unsafe */
-
-#include <io.h>
-
-int gettimeofday(struct timeval *tv, struct timezone *tz);
-
-#define snprintf _snprintf
-#define hypotf _hypotf
-#define strtoll _strtoi64
-
-#else /* Unix or close enough */
-
-#include <unistd.h>
-
-#define O_BINARY 0
-
-#endif
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
-
-#ifndef M_SQRT2
-#define M_SQRT2 1.41421356237309504880
-#endif
-
-/*
- * Variadic macros, inline and restrict keywords
- */
-
-#if __STDC_VERSION__ == 199901L /* C99 */
-
-#define fz_throw(...) fz_throwimp(__FILE__, __LINE__, __func__, __VA_ARGS__)
-#define fz_rethrow(cause, ...) fz_rethrowimp(__FILE__, __LINE__, __func__, cause, __VA_ARGS__)
-#define fz_catch(cause, ...) fz_catchimp(__FILE__, __LINE__, __func__, cause, __VA_ARGS__)
-
-#elif _MSC_VER >= 1500 /* MSVC 9 or newer */
-
-#define inline __inline
-#define restrict __restrict
-#define fz_throw(...) fz_throwimp(__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
-#define fz_rethrow(cause, ...) fz_rethrowimp(__FILE__, __LINE__, __FUNCTION__, cause, __VA_ARGS__)
-#define fz_catch(cause, ...) fz_catchimp(__FILE__, __LINE__, __FUNCTION__, cause, __VA_ARGS__)
-
-#elif __GNUC__ >= 3 /* GCC 3 or newer */
-
-#define inline __inline
-#define restrict __restrict
-#define fz_throw(fmt...) fz_throwimp(__FILE__, __LINE__, __FUNCTION__, fmt)
-#define fz_rethrow(cause, fmt...) fz_rethrowimp(__FILE__, __LINE__, __FUNCTION__, cause, fmt)
-#define fz_catch(cause, fmt...) fz_catchimp(__FILE__, __LINE__, __FUNCTION__, cause, fmt)
-
-#else /* Unknown or ancient */
-
-#define inline
-#define restrict
-#define fz_throw fz_throwimpx
-#define fz_rethrow fz_rethrowimpx
-#define fz_catch fz_catchimpx
-
-#endif
-
-/*
- * GCC can do type checking of printf strings
- */
-
-#ifndef __printflike
-#if __GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ >= 7
-#define __printflike(fmtarg, firstvararg) \
- __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
-#else
-#define __printflike(fmtarg, firstvararg)
-#endif
-#endif
-
-/*
- * Error handling
- */
-
-typedef int fz_error;
-
-void fz_warn(char *fmt, ...) __printflike(1, 2);
-
-fz_error fz_throwimp(const char *file, int line, const char *func, char *fmt, ...) __printflike(4, 5);
-fz_error fz_rethrowimp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...) __printflike(5, 6);
-void fz_catchimp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...) __printflike(5, 6);
-
-fz_error fz_throwimpx(char *fmt, ...) __printflike(1, 2);
-fz_error fz_rethrowimpx(fz_error cause, char *fmt, ...) __printflike(2, 3);
-void fz_catchimpx(fz_error cause, char *fmt, ...) __printflike(2, 3);
-
-#define fz_okay ((fz_error)0)
-
-/*
- * Basic runtime and utility functions
- */
-
-#define ABS(x) ( (x) < 0 ? -(x) : (x) )
-#define MIN(a,b) ( (a) < (b) ? (a) : (b) )
-#define MAX(a,b) ( (a) > (b) ? (a) : (b) )
-#define CLAMP(x,a,b) ( (x) > (b) ? (b) : ( (x) < (a) ? (a) : (x) ) )
-
-/* memory allocation */
-void *fz_malloc(int n);
-void *fz_realloc(void *p, int n);
-void fz_free(void *p);
-char *fz_strdup(char *s);
-
-/* runtime (hah!) test for endian-ness */
-int fz_isbigendian(void);
-
-/* safe string functions */
-char *fz_strsep(char **stringp, const char *delim);
-int fz_strlcpy(char *dst, const char *src, int n);
-int fz_strlcat(char *dst, const char *src, int n);
-
-/* utf-8 encoding and decoding */
-int chartorune(int *rune, char *str);
-int runetochar(char *str, int *rune);
-int runelen(int c);
-
-/* getopt */
-extern int fz_getopt(int nargc, char * const * nargv, const char *ostr);
-extern int fz_optind;
-extern char *fz_optarg;
-
-/*
- * Generic hash-table with fixed-length keys.
- */
-
-typedef struct fz_hashtable_s fz_hashtable;
-
-fz_hashtable * fz_newhash(int initialsize, int keylen);
-void fz_debughash(fz_hashtable *table);
-void fz_emptyhash(fz_hashtable *table);
-void fz_freehash(fz_hashtable *table);
-
-void *fz_hashfind(fz_hashtable *table, void *key);
-void fz_hashinsert(fz_hashtable *table, void *key, void *val);
-void fz_hashremove(fz_hashtable *table, void *key);
-
-int fz_hashlen(fz_hashtable *table);
-void *fz_hashgetkey(fz_hashtable *table, int idx);
-void *fz_hashgetval(fz_hashtable *table, int idx);
-
-/*
- * Math and geometry
- */
-
-/* multiply 8-bit fixpoint (0..1) so that 0*0==0 and 255*255==255 */
-static inline int fz_mul255(int a, int b)
-{
- int x = a * b + 0x80;
- x += x >> 8;
- return x >> 8;
-}
-
-typedef struct fz_matrix_s fz_matrix;
-typedef struct fz_point_s fz_point;
-typedef struct fz_rect_s fz_rect;
-typedef struct fz_bbox_s fz_bbox;
-
-extern const fz_rect fz_unitrect;
-extern const fz_rect fz_emptyrect;
-extern const fz_rect fz_infiniterect;
-
-extern const fz_bbox fz_unitbbox;
-extern const fz_bbox fz_emptybbox;
-extern const fz_bbox fz_infinitebbox;
-
-#define fz_isemptyrect(r) ((r).x0 == (r).x1)
-#define fz_isinfiniterect(r) ((r).x0 > (r).x1)
-
-/*
- / a b 0 \
- | c d 0 |
- \ e f 1 /
-*/
-struct fz_matrix_s
-{
- float a, b, c, d, e, f;
-};
-
-struct fz_point_s
-{
- float x, y;
-};
-
-struct fz_rect_s
-{
- float x0, y0;
- float x1, y1;
-};
-
-struct fz_bbox_s
-{
- int x0, y0;
- int x1, y1;
-};
-
-void fz_invert3x3(float *dst, float *m);
-
-fz_matrix fz_concat(fz_matrix one, fz_matrix two);
-fz_matrix fz_identity(void);
-fz_matrix fz_scale(float sx, float sy);
-fz_matrix fz_rotate(float theta);
-fz_matrix fz_translate(float tx, float ty);
-fz_matrix fz_invertmatrix(fz_matrix m);
-int fz_isrectilinear(fz_matrix m);
-float fz_matrixexpansion(fz_matrix m);
-
-fz_bbox fz_roundrect(fz_rect r);
-fz_bbox fz_intersectbbox(fz_bbox a, fz_bbox b);
-fz_bbox fz_unionbbox(fz_bbox a, fz_bbox b);
-
-fz_point fz_transformpoint(fz_matrix m, fz_point p);
-fz_point fz_transformvector(fz_matrix m, fz_point p);
-fz_rect fz_transformrect(fz_matrix m, fz_rect r);
-
-#endif
-
diff --git a/fitz/fitz_draw.h b/fitz/fitz_draw.h
deleted file mode 100644
index a2f65579..00000000
--- a/fitz/fitz_draw.h
+++ /dev/null
@@ -1,519 +0,0 @@
-/*
- * Resources and other graphics related objects.
- */
-
-typedef struct fz_pixmap_s fz_pixmap;
-typedef struct fz_colorspace_s fz_colorspace;
-typedef struct fz_path_s fz_path;
-typedef struct fz_text_s fz_text;
-typedef struct fz_font_s fz_font;
-typedef struct fz_shade_s fz_shade;
-typedef struct fz_glyphcache_s fz_glyphcache;
-
-typedef struct fz_strokestate_s fz_strokestate;
-
-enum { FZ_MAXCOLORS = 32 };
-
-typedef enum fz_blendkind_e
-{
- /* PDF 1.4 -- standard separable */
- FZ_BNORMAL,
- FZ_BMULTIPLY,
- FZ_BSCREEN,
- FZ_BOVERLAY,
- FZ_BDARKEN,
- FZ_BLIGHTEN,
- FZ_BCOLORDODGE,
- FZ_BCOLORBURN,
- FZ_BHARDLIGHT,
- FZ_BSOFTLIGHT,
- FZ_BDIFFERENCE,
- FZ_BEXCLUSION,
-
- /* PDF 1.4 -- standard non-separable */
- FZ_BHUE,
- FZ_BSATURATION,
- FZ_BCOLOR,
- FZ_BLUMINOSITY,
-} fz_blendkind;
-
-/*
-pixmaps have n components per pixel. the last is always alpha.
-premultiplied alpha when rendering, but non-premultiplied for colorspace
-conversions and rescaling.
-*/
-
-extern fz_colorspace *pdf_devicegray;
-extern fz_colorspace *pdf_devicergb;
-extern fz_colorspace *pdf_devicebgr;
-extern fz_colorspace *pdf_devicecmyk;
-extern fz_colorspace *pdf_devicelab;
-extern fz_colorspace *pdf_devicepattern;
-
-struct fz_pixmap_s
-{
- int refs;
- int x, y, w, h, n;
- fz_colorspace *colorspace;
- unsigned char *samples;
-};
-
-fz_pixmap * fz_newpixmapwithrect(fz_colorspace *, fz_bbox bbox);
-fz_pixmap * fz_newpixmap(fz_colorspace *, int x, int y, int w, int h);
-fz_pixmap *fz_keeppixmap(fz_pixmap *map);
-void fz_droppixmap(fz_pixmap *map);
-
-void fz_debugpixmap(fz_pixmap *map, char *prefix);
-void fz_clearpixmap(fz_pixmap *map, unsigned char value);
-
-fz_pixmap * fz_scalepixmap(fz_pixmap *src, int xdenom, int ydenom);
-
-/*
- * The device interface.
- */
-
-enum
-{
- FZ_IGNOREIMAGE = 1,
- FZ_IGNORESHADE = 2,
-};
-
-typedef struct fz_device_s fz_device;
-
-struct fz_device_s
-{
- int hints;
-
- void *user;
- void (*freeuser)(void *);
-
- void (*fillpath)(void *, fz_path *, int evenodd, fz_matrix, fz_colorspace *, float *color, float alpha);
- void (*strokepath)(void *, fz_path *, fz_strokestate *, fz_matrix, fz_colorspace *, float *color, float alpha);
- void (*clippath)(void *, fz_path *, int evenodd, fz_matrix);
- void (*clipstrokepath)(void *, fz_path *, fz_strokestate *, fz_matrix);
-
- void (*filltext)(void *, fz_text *, fz_matrix, fz_colorspace *, float *color, float alpha);
- void (*stroketext)(void *, fz_text *, fz_strokestate *, fz_matrix, fz_colorspace *, float *color, float alpha);
- void (*cliptext)(void *, fz_text *, fz_matrix, int accumulate);
- void (*clipstroketext)(void *, fz_text *, fz_strokestate *, fz_matrix);
- void (*ignoretext)(void *, fz_text *, fz_matrix);
-
- void (*fillshade)(void *, fz_shade *shd, fz_matrix ctm);
- void (*fillimage)(void *, fz_pixmap *img, fz_matrix ctm);
- void (*fillimagemask)(void *, fz_pixmap *img, fz_matrix ctm, fz_colorspace *, float *color, float alpha);
- void (*clipimagemask)(void *, fz_pixmap *img, fz_matrix ctm);
-
- void (*popclip)(void *);
-};
-
-fz_device *fz_newdevice(void *user);
-void fz_freedevice(fz_device *dev);
-
-fz_device *fz_newtracedevice(void);
-
-fz_device *fz_newbboxdevice(fz_bbox *bboxp);
-
-fz_device *fz_newdrawdevice(fz_glyphcache *cache, fz_pixmap *dest);
-
-/* Text extraction device */
-
-typedef struct fz_textspan_s fz_textspan;
-typedef struct fz_textchar_s fz_textchar;
-
-struct fz_textchar_s
-{
- int c;
- fz_bbox bbox;
-};
-
-struct fz_textspan_s
-{
- fz_font *font;
- float size;
- int wmode;
- int len, cap;
- fz_textchar *text;
- fz_textspan *next;
- int eol;
-};
-
-fz_textspan * fz_newtextspan(void);
-void fz_freetextspan(fz_textspan *line);
-void fz_debugtextspan(fz_textspan *line);
-void fz_debugtextspanxml(fz_textspan *span);
-
-fz_device *fz_newtextdevice(fz_textspan *text);
-
-/* Display list device -- record and play back device commands. */
-
-typedef struct fz_displaylist_s fz_displaylist;
-typedef struct fz_displaynode_s fz_displaynode;
-
-typedef enum fz_displaycommand_e
-{
- FZ_CMDFILLPATH,
- FZ_CMDSTROKEPATH,
- FZ_CMDCLIPPATH,
- FZ_CMDCLIPSTROKEPATH,
- FZ_CMDFILLTEXT,
- FZ_CMDSTROKETEXT,
- FZ_CMDCLIPTEXT,
- FZ_CMDCLIPSTROKETEXT,
- FZ_CMDIGNORETEXT,
- FZ_CMDFILLSHADE,
- FZ_CMDFILLIMAGE,
- FZ_CMDFILLIMAGEMASK,
- FZ_CMDCLIPIMAGEMASK,
- FZ_CMDPOPCLIP,
-} fz_displaycommand;
-
-struct fz_displaylist_s
-{
- fz_displaynode *first;
- fz_displaynode *last;
-};
-
-struct fz_displaynode_s
-{
- fz_displaycommand cmd;
- fz_displaynode *next;
- union {
- fz_path *path;
- fz_text *text;
- fz_shade *shade;
- fz_pixmap *image;
- } item;
- fz_strokestate *stroke;
- int flag; /* evenodd, accumulate, ... */
- fz_matrix ctm;
- fz_colorspace *colorspace;
- float alpha;
- float color[FZ_MAXCOLORS];
-};
-
-fz_displaylist *fz_newdisplaylist(void);
-void fz_freedisplaylist(fz_displaylist *list);
-fz_device *fz_newlistdevice(fz_displaylist *list);
-void fz_executedisplaylist(fz_displaylist *list, fz_device *dev, fz_matrix ctm);
-
-/*
- * Vector path buffer.
- * It can be stroked and dashed, or be filled.
- * It has a fill rule (nonzero or evenodd).
- *
- * When rendering, they are flattened, stroked and dashed straight
- * into the Global Edge List.
- */
-
-typedef union fz_pathel_s fz_pathel;
-
-typedef enum fz_pathelkind_e
-{
- FZ_MOVETO,
- FZ_LINETO,
- FZ_CURVETO,
- FZ_CLOSEPATH
-} fz_pathelkind;
-
-union fz_pathel_s
-{
- fz_pathelkind k;
- float v;
-};
-
-struct fz_strokestate_s
-{
- int linecap;
- int linejoin;
- float linewidth;
- float miterlimit;
- float dashphase;
- int dashlen;
- float dashlist[32];
-};
-
-struct fz_path_s
-{
- int len, cap;
- fz_pathel *els;
-};
-
-fz_path *fz_newpath(void);
-void fz_moveto(fz_path*, float x, float y);
-void fz_lineto(fz_path*, float x, float y);
-void fz_curveto(fz_path*, float, float, float, float, float, float);
-void fz_curvetov(fz_path*, float, float, float, float);
-void fz_curvetoy(fz_path*, float, float, float, float);
-void fz_closepath(fz_path*);
-void fz_freepath(fz_path *path);
-
-fz_path *fz_clonepath(fz_path *old);
-
-fz_rect fz_boundpath(fz_path *path, fz_strokestate *stroke, fz_matrix ctm);
-void fz_debugpath(fz_path *, int indent);
-
-/*
- * Text buffer.
- *
- * The trm field contains the a, b, c and d coefficients.
- * The e and f coefficients come from the individual elements,
- * together they form the transform matrix for the glyph.
- *
- * Glyphs are referenced by glyph ID.
- * The Unicode text equivalent is kept in a separate array
- * with indexes into the glyph array.
- */
-
-typedef struct fz_textel_s fz_textel;
-
-struct fz_textel_s
-{
- float x, y;
- int gid; /* -1 for one gid to many ucs mappings */
- int ucs; /* -1 for one ucs to many gid mappings */
-};
-
-struct fz_text_s
-{
- fz_font *font;
- fz_matrix trm;
- int wmode;
- int len, cap;
- fz_textel *els;
-};
-
-fz_text * fz_newtext(fz_font *face, fz_matrix trm, int wmode);
-void fz_addtext(fz_text *text, int gid, int ucs, float x, float y);
-void fz_endtext(fz_text *text);
-void fz_freetext(fz_text *text);
-void fz_debugtext(fz_text*, int indent);
-fz_rect fz_boundtext(fz_text *text, fz_matrix ctm);
-fz_text *fz_clonetext(fz_text *old);
-
-/*
- * Colorspace resources.
- *
- * TODO: use lcms
- */
-
-struct fz_colorspace_s
-{
- int refs;
- char name[16];
- int n;
- void (*convpixmap)(fz_colorspace *ss, fz_pixmap *sp, fz_colorspace *ds, fz_pixmap *dp);
- void (*convcolor)(fz_colorspace *ss, float *sv, fz_colorspace *ds, float *dv);
- void (*toxyz)(fz_colorspace *, float *src, float *xyz);
- void (*fromxyz)(fz_colorspace *, float *xyz, float *dst);
- void (*freefunc)(fz_colorspace *);
-};
-
-fz_colorspace *fz_keepcolorspace(fz_colorspace *cs);
-void fz_dropcolorspace(fz_colorspace *cs);
-
-void fz_convertcolor(fz_colorspace *srcs, float *srcv, fz_colorspace *dsts, float *dstv);
-void fz_convertpixmap(fz_colorspace *srcs, fz_pixmap *srcv, fz_colorspace *dsts, fz_pixmap *dstv);
-
-void fz_stdconvcolor(fz_colorspace *srcs, float *srcv, fz_colorspace *dsts, float *dstv);
-void fz_stdconvpixmap(fz_colorspace *srcs, fz_pixmap *srcv, fz_colorspace *dsts, fz_pixmap *dstv);
-
-/*
- * Fonts.
- *
- * Fonts come in three variants:
- * Regular fonts are handled by FreeType.
- * Type 3 fonts have callbacks to the interpreter.
- * Substitute fonts are a thin wrapper over a regular font that adjusts metrics.
- */
-
-char *ft_errorstring(int err);
-
-struct fz_font_s
-{
- int refs;
- char name[32];
-
- void *ftface; /* has an FT_Face if used */
- int ftsubstitute; /* ... substitute metrics */
- int fthint; /* ... force hinting for DynaLab fonts */
-
- fz_matrix t3matrix;
- fz_obj *t3resources;
- fz_buffer **t3procs; /* has 256 entries if used */
- float *t3widths; /* has 256 entries if used */
- void *t3xref; /* a pdf_xref for the callback */
- fz_error (*t3runcontentstream)(fz_device *dev, fz_matrix ctm,
- struct pdf_xref_s *xref, fz_obj *resources, fz_buffer *contents);
-
- fz_rect bbox;
-
- /* substitute metrics */
- int widthcount;
- int *widthtable;
-};
-
-fz_error fz_newfreetypefont(fz_font **fontp, char *name, int substitute);
-fz_error fz_loadfreetypefontfile(fz_font *font, char *path, int index);
-fz_error fz_loadfreetypefontbuffer(fz_font *font, unsigned char *data, int len, int index);
-fz_font * fz_newtype3font(char *name, fz_matrix matrix);
-
-fz_error fz_newfontfrombuffer(fz_font **fontp, unsigned char *data, int len, int index);
-fz_error fz_newfontfromfile(fz_font **fontp, char *path, int index);
-
-fz_font * fz_keepfont(fz_font *font);
-void fz_dropfont(fz_font *font);
-
-void fz_debugfont(fz_font *font);
-void fz_setfontbbox(fz_font *font, float xmin, float ymin, float xmax, float ymax);
-
-/*
- * The shading code is in rough shape but the general architecture is sound.
- */
-
-struct fz_shade_s
-{
- int refs;
-
- fz_rect bbox; /* can be fz_infiniterect */
- fz_colorspace *cs;
-
- fz_matrix matrix; /* matrix from pattern dict */
- int usebackground; /* background color for fills but not 'sh' */
- float background[FZ_MAXCOLORS];
-
- int usefunction;
- float function[256][FZ_MAXCOLORS];
-
- int meshlen;
- int meshcap;
- float *mesh; /* [x y t] or [x y c1 ... cn] */
-};
-
-fz_shade *fz_keepshade(fz_shade *shade);
-void fz_dropshade(fz_shade *shade);
-void fz_debugshade(fz_shade *shade);
-
-fz_rect fz_boundshade(fz_shade *shade, fz_matrix ctm);
-void fz_rendershade(fz_shade *shade, fz_matrix ctm, fz_pixmap *dst, fz_bbox bbox);
-
-/*
- * Glyph cache
- */
-
-fz_glyphcache * fz_newglyphcache(void);
-fz_pixmap * fz_renderftglyph(fz_font *font, int cid, fz_matrix trm);
-fz_pixmap * fz_rendert3glyph(fz_font *font, int cid, fz_matrix trm);
-fz_pixmap * fz_renderglyph(fz_glyphcache*, fz_font*, int, fz_matrix);
-void fz_evictglyphcache(fz_glyphcache *);
-void fz_freeglyphcache(fz_glyphcache *);
-
-/*
- * Scan converter
- */
-
-typedef struct fz_edge_s fz_edge;
-typedef struct fz_gel_s fz_gel;
-typedef struct fz_ael_s fz_ael;
-
-struct fz_edge_s
-{
- int x, e, h, y;
- int adjup, adjdown;
- int xmove;
- int xdir, ydir; /* -1 or +1 */
-};
-
-struct fz_gel_s
-{
- fz_bbox clip;
- fz_bbox bbox;
- int cap;
- int len;
- fz_edge *edges;
-};
-
-struct fz_ael_s
-{
- int cap;
- int len;
- fz_edge **edges;
-};
-
-fz_gel * fz_newgel(void);
-void fz_insertgel(fz_gel *gel, float x0, float y0, float x1, float y1);
-fz_bbox fz_boundgel(fz_gel *gel);
-void fz_resetgel(fz_gel *gel, fz_bbox clip);
-void fz_sortgel(fz_gel *gel);
-void fz_freegel(fz_gel *gel);
-int fz_isrectgel(fz_gel *gel);
-
-fz_ael * fz_newael(void);
-void fz_freeael(fz_ael *ael);
-
-fz_error fz_scanconvert(fz_gel *gel, fz_ael *ael, int eofill,
- fz_bbox clip, fz_pixmap *pix, unsigned char *colorbv, fz_pixmap *image, fz_matrix *invmat);
-
-void fz_fillpath(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness);
-void fz_strokepath(fz_gel *gel, fz_path *path, fz_strokestate *stroke, fz_matrix ctm, float flatness, float linewidth);
-void fz_dashpath(fz_gel *gel, fz_path *path, fz_strokestate *stroke, fz_matrix ctm, float flatness, float linewidth);
-
-/*
- * Macros used to do blending
- */
-
-/* Expand a value A from the 0...255 range to the 0..256 range */
-#define FZ_EXPAND(A) ((A)+((A)>>7))
-
-/* Combine values A (in any range) and B (in the 0..256 range),
- * to give a single value in the same range as A was. */
-#define FZ_COMBINE(A,B) (((A)*(B))>>8)
-
-/* Blend SRC and DST (in the same range) together according to
- * AMOUNT (in the 0...256 range). */
-#define FZ_BLEND(SRC, DST, AMOUNT) ((((SRC)-(DST))*(AMOUNT) + ((DST)<<8))>>8)
-
-/*
- * Function pointers -- they can be replaced by cpu-optimized versions
- */
-
-extern void fz_accelerate(void);
-extern void fz_acceleratearch(void);
-
-extern void (*fz_duff_ni1on)(unsigned char*,int,int,unsigned char*,int,unsigned char*,int,int,int);
-extern void (*fz_duff_1i1o1)(unsigned char*,int,unsigned char*,int,unsigned char*,int,int,int);
-extern void (*fz_duff_2i1o2)(unsigned char*,int,unsigned char*,int,unsigned char*,int,int,int);
-extern void (*fz_duff_4i1o4)(unsigned char*,int,unsigned char*,int,unsigned char*,int,int,int);
-
-extern void (*fz_path_1o1)(unsigned char*,unsigned char,int,unsigned char*);
-extern void (*fz_path_w2i1o2)(unsigned char*,unsigned char*,unsigned char,int,unsigned char*);
-extern void (*fz_path_w4i1o4)(unsigned char*,unsigned char*,unsigned char,int,unsigned char*);
-
-extern void (*fz_text_1o1)(unsigned char*,int,unsigned char*,int,int,int);
-extern void (*fz_text_w2i1o2)(unsigned char*,unsigned char*,int,unsigned char*,int,int,int);
-extern void (*fz_text_w4i1o4)(unsigned char*,unsigned char*,int,unsigned char*,int,int,int);
-
-extern void (*fz_img_non)(unsigned char*,unsigned char,int,unsigned char*,fz_pixmap*,fz_matrix*);
-extern void (*fz_img_1o1)(unsigned char*,unsigned char,int,unsigned char*,fz_pixmap*,int u, int v, int fa, int fb);
-extern void (*fz_img_4o4)(unsigned char*,unsigned char,int,unsigned char*,fz_pixmap*,int u, int v, int fa, int fb);
-extern void (*fz_img_2o2)(unsigned char*,unsigned char,int,unsigned char*,fz_pixmap*,int u, int v, int fa, int fb);
-extern void (*fz_img_w2i1o2)(unsigned char*,unsigned char*,unsigned char,int,unsigned char*,fz_pixmap*,int u, int v, int fa, int fb);
-extern void (*fz_img_w4i1o4)(unsigned char*,unsigned char*,unsigned char,int,unsigned char*,fz_pixmap*,int u, int v, int fa, int fb);
-
-extern void (*fz_decodetile)(fz_pixmap *pix, int skip, float *decode);
-extern void (*fz_loadtile1)(unsigned char*, int sw, unsigned char*, int dw, int w, int h, int pad);
-extern void (*fz_loadtile2)(unsigned char*, int sw, unsigned char*, int dw, int w, int h, int pad);
-extern void (*fz_loadtile4)(unsigned char*, int sw, unsigned char*, int dw, int w, int h, int pad);
-extern void (*fz_loadtile8)(unsigned char*, int sw, unsigned char*, int dw, int w, int h, int pad);
-extern void (*fz_loadtile16)(unsigned char*, int sw, unsigned char*, int dw, int w, int h, int pad);
-
-extern void (*fz_srown)(unsigned char *src, unsigned char *dst, int w, int denom, int n);
-extern void (*fz_srow1)(unsigned char *src, unsigned char *dst, int w, int denom);
-extern void (*fz_srow2)(unsigned char *src, unsigned char *dst, int w, int denom);
-extern void (*fz_srow4)(unsigned char *src, unsigned char *dst, int w, int denom);
-extern void (*fz_srow5)(unsigned char *src, unsigned char *dst, int w, int denom);
-
-extern void (*fz_scoln)(unsigned char *src, unsigned char *dst, int w, int denom, int n);
-extern void (*fz_scol1)(unsigned char *src, unsigned char *dst, int w, int denom);
-extern void (*fz_scol2)(unsigned char *src, unsigned char *dst, int w, int denom);
-extern void (*fz_scol4)(unsigned char *src, unsigned char *dst, int w, int denom);
-extern void (*fz_scol5)(unsigned char *src, unsigned char *dst, int w, int denom);
diff --git a/fitz/fitz_stream.h b/fitz/fitz_stream.h
deleted file mode 100644
index c425d7c8..00000000
--- a/fitz/fitz_stream.h
+++ /dev/null
@@ -1,398 +0,0 @@
-/*
- * Dynamic objects.
- * The same type of objects as found in PDF and PostScript.
- * Used by the filter library and the mupdf parser.
- */
-
-#ifndef _FITZ_STREAM_H_
-#define _FITZ_STREAM_H_
-
-typedef struct fz_obj_s fz_obj;
-typedef struct fz_keyval_s fz_keyval;
-
-typedef enum fz_objkind_e
-{
- FZ_NULL,
- FZ_BOOL,
- FZ_INT,
- FZ_REAL,
- FZ_STRING,
- FZ_NAME,
- FZ_ARRAY,
- FZ_DICT,
- FZ_INDIRECT
-} fz_objkind;
-
-struct fz_keyval_s
-{
- fz_obj *k;
- fz_obj *v;
-};
-
-struct fz_obj_s
-{
- int refs;
- fz_objkind kind;
- union
- {
- int b;
- int i;
- float f;
- struct {
- unsigned short len;
- char buf[1];
- } s;
- char n[1];
- struct {
- int len;
- int cap;
- fz_obj **items;
- } a;
- struct {
- char sorted;
- int len;
- int cap;
- fz_keyval *items;
- } d;
- struct {
- int num;
- int gen;
- struct pdf_xref_s *xref;
- fz_obj *obj;
- } r;
- } u;
-};
-
-fz_obj * fz_newnull(void);
-fz_obj * fz_newbool(int b);
-fz_obj * fz_newint(int i);
-fz_obj * fz_newreal(float f);
-fz_obj * fz_newname(char *str);
-fz_obj * fz_newstring(char *str, int len);
-fz_obj * fz_newindirect(int num, int gen, struct pdf_xref_s *xref);
-
-fz_obj * fz_newarray(int initialcap);
-fz_obj * fz_newdict(int initialcap);
-fz_obj * fz_copyarray(fz_obj *array);
-fz_obj * fz_copydict(fz_obj *dict);
-
-fz_obj *fz_keepobj(fz_obj *obj);
-void fz_dropobj(fz_obj *obj);
-
-/* type queries */
-int fz_isnull(fz_obj *obj);
-int fz_isbool(fz_obj *obj);
-int fz_isint(fz_obj *obj);
-int fz_isreal(fz_obj *obj);
-int fz_isname(fz_obj *obj);
-int fz_isstring(fz_obj *obj);
-int fz_isarray(fz_obj *obj);
-int fz_isdict(fz_obj *obj);
-int fz_isindirect(fz_obj *obj);
-
-int fz_objcmp(fz_obj *a, fz_obj *b);
-
-fz_obj *fz_resolveindirect(fz_obj *obj);
-
-/* silent failure, no error reporting */
-int fz_tobool(fz_obj *obj);
-int fz_toint(fz_obj *obj);
-float fz_toreal(fz_obj *obj);
-char *fz_toname(fz_obj *obj);
-char *fz_tostrbuf(fz_obj *obj);
-int fz_tostrlen(fz_obj *obj);
-int fz_tonum(fz_obj *obj);
-int fz_togen(fz_obj *obj);
-
-int fz_arraylen(fz_obj *array);
-fz_obj *fz_arrayget(fz_obj *array, int i);
-void fz_arrayput(fz_obj *array, int i, fz_obj *obj);
-void fz_arraypush(fz_obj *array, fz_obj *obj);
-
-int fz_dictlen(fz_obj *dict);
-fz_obj *fz_dictgetkey(fz_obj *dict, int idx);
-fz_obj *fz_dictgetval(fz_obj *dict, int idx);
-fz_obj *fz_dictget(fz_obj *dict, fz_obj *key);
-fz_obj *fz_dictgets(fz_obj *dict, char *key);
-fz_obj *fz_dictgetsa(fz_obj *dict, char *key, char *abbrev);
-void fz_dictput(fz_obj *dict, fz_obj *key, fz_obj *val);
-void fz_dictputs(fz_obj *dict, char *key, fz_obj *val);
-void fz_dictdel(fz_obj *dict, fz_obj *key);
-void fz_dictdels(fz_obj *dict, char *key);
-void fz_sortdict(fz_obj *dict);
-
-int fz_sprintobj(char *s, int n, fz_obj *obj, int tight);
-int fz_fprintobj(FILE *fp, fz_obj *obj, int tight);
-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.
- *
- * A buffer owns the memory it has allocated, unless ownsdata is false,
- * in which case the creator of the buffer owns it.
- */
-
-typedef struct fz_buffer_s fz_buffer;
-
-#define FZ_BUFSIZE (8 * 1024)
-
-struct fz_buffer_s
-{
- int refs;
- int ownsdata;
- unsigned char *bp;
- unsigned char *rp;
- unsigned char *wp;
- unsigned char *ep;
- int eof;
-};
-
-fz_buffer * fz_newbuffer(int size);
-fz_buffer * fz_newbufferwithmemory(unsigned char *data, 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);
-
-/* stop and reverse! special case needed for postscript only */
-void fz_pushbackahxd(fz_filter *filter, fz_buffer *in, fz_buffer *out, int n);
-
-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);
-
-/*
- * Basic crypto functions.
- * Independent of the rest of fitz.
- * For further encapsulation in filters, or not.
- */
-
-/* md5 digests */
-
-typedef struct fz_md5_s fz_md5;
-
-struct fz_md5_s
-{
- unsigned int state[4];
- unsigned int count[2];
- unsigned char buffer[64];
-};
-
-void fz_md5init(fz_md5 *state);
-void fz_md5update(fz_md5 *state, const unsigned char *input, const unsigned inlen);
-void fz_md5final(fz_md5 *state, unsigned char digest[16]);
-
-/* arc4 crypto */
-
-typedef struct fz_arc4_s fz_arc4;
-
-struct fz_arc4_s
-{
- unsigned x;
- unsigned y;
- unsigned char state[256];
-};
-
-void fz_arc4init(fz_arc4 *state, const unsigned char *key, const unsigned len);
-unsigned char fz_arc4next(fz_arc4 *state);
-void fz_arc4encrypt(fz_arc4 *state, unsigned char *dest, const unsigned char *src, const unsigned len);
-
-/* AES block cipher implementation from XYSSL */
-
-#define AES_DECRYPT 0
-#define AES_ENCRYPT 1
-
-struct fz_aes_s
-{
- int nr; /* number of rounds */
- unsigned long *rk; /* AES round keys */
- unsigned long buf[68]; /* unaligned data */
-};
-
-typedef struct fz_aes_s fz_aes;
-
-void aes_setkey_enc( fz_aes *ctx, const unsigned char *key, int keysize );
-void aes_setkey_dec( fz_aes *ctx, const unsigned char *key, int keysize );
-void aes_crypt_cbc( fz_aes *ctx, int mode, int length,
- unsigned char iv[16],
- const unsigned char *input,
- unsigned char *output );
-
-/*
- * Stream API for Fitz.
- * Read and write data to and from files, memory buffers and filters.
- */
-
-typedef struct fz_stream_s fz_stream;
-
-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;
-};
-
-/*
- * 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_keepstream(fz_stream *stm);
-void fz_dropstream(fz_stream *stm);
-
-int fz_tell(fz_stream *stm);
-fz_error fz_seek(fz_stream *stm, int offset, int whence);
-
-/*
- * Input stream functions.
- */
-
-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);
-
-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);
-}
-
-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);
-}
-
-static inline void fz_unreadbyte(fz_stream *stm)
-{
- fz_buffer *buf = stm->buffer;
- buf->rp--;
-}
-
-#endif
diff --git a/fitz/obj_array.c b/fitz/obj_array.c
index 8c9ae553..78fc4294 100644
--- a/fitz/obj_array.c
+++ b/fitz/obj_array.c
@@ -1,7 +1,5 @@
#include "fitz.h"
-void fz_freearray(fz_obj *obj);
-
fz_obj *
fz_newarray(int initialcap)
{
diff --git a/fitz/res_font.c b/fitz/res_font.c
index 448484c9..419acc5c 100644
--- a/fitz/res_font.c
+++ b/fitz/res_font.c
@@ -18,7 +18,7 @@ fz_newfont(void)
font->ftsubstitute = 0;
font->fthint = 0;
- font->t3matrix = fz_identity();
+ font->t3matrix = fz_identity;
font->t3resources = nil;
font->t3procs = nil;
font->t3widths = nil;
diff --git a/fitz/stm_misc.c b/fitz/stm_misc.c
deleted file mode 100644
index 398d4388..00000000
--- a/fitz/stm_misc.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Miscellaneous I/O functions
- */
-
-#include "fitz.h"
-
-/*
- * Read a line terminated by LF or CR or CRLF.
- */
-
-fz_error
-fz_readline(fz_stream *stm, char *mem, int n)
-{
- fz_error error;
-
- char *s = mem;
- int c = EOF;
- while (n > 1)
- {
- c = fz_readbyte(stm);
- if (c == EOF)
- break;
- if (c == '\r') {
- c = fz_peekbyte(stm);
- if (c == '\n')
- c = fz_readbyte(stm);
- break;
- }
- if (c == '\n')
- break;
- *s++ = c;
- n--;
- }
- if (n)
- *s = '\0';
-
- error = fz_readerror(stm);
- if (error)
- return fz_rethrow(error, "cannot read line");
- return fz_okay;
-}
-
-static inline int
-fz_fillbuf(fz_stream *stm, fz_buffer *buf)
-{
- int remaining = buf->ep - buf->wp;
- int available = stm->buffer->wp - stm->buffer->rp;
-
- if (available == 0 && remaining > 0)
- {
- int c = fz_readbytex(stm);
- if (c == EOF)
- return EOF;
-
- *buf->wp++ = c;
-
- remaining = buf->ep - buf->wp;
- available = stm->buffer->wp - stm->buffer->rp;
- }
-
- memmove(buf->wp, stm->buffer->rp, MIN(remaining, available));
- buf->wp += MIN(remaining, available);
- stm->buffer->rp += MIN(remaining, available);
-
- if (stm->buffer->rp == stm->buffer->wp && stm->buffer->eof)
- return EOF;
- return 0;
-}
-
-/*
- * Utility function to consume all the contents of an input stream into
- * a freshly allocated buffer.
- */
-
-fz_buffer *
-fz_readall(fz_stream *stm, int sizehint)
-{
- fz_buffer *buf;
-
- if (sizehint == 0)
- sizehint = 4 * 1024;
-
- buf = fz_newbuffer(sizehint);
-
- while (fz_fillbuf(stm, buf) != EOF)
- {
- if (buf->wp == buf->ep)
- fz_growbuffer(buf);
- }
-
- return buf;
-}
diff --git a/fitz/stm_open.c b/fitz/stm_open.c
index 793504af..e70a4580 100644
--- a/fitz/stm_open.c
+++ b/fitz/stm_open.c
@@ -1,7 +1,3 @@
-/*
- * Creation and destruction.
- */
-
#include "fitz.h"
static fz_stream *
diff --git a/fitz/stm_read.c b/fitz/stm_read.c
index 9f6b45a5..aeded131 100644
--- a/fitz/stm_read.c
+++ b/fitz/stm_read.c
@@ -1,7 +1,3 @@
-/*
- * Input streams.
- */
-
#include "fitz.h"
fz_error
@@ -274,3 +270,90 @@ fz_peekbytex(fz_stream *stm)
return buf->rp < buf->wp ? *buf->rp : EOF ;
}
+
+/*
+ * Read a line terminated by LF or CR or CRLF.
+ */
+
+fz_error
+fz_readline(fz_stream *stm, char *mem, int n)
+{
+ fz_error error;
+
+ char *s = mem;
+ int c = EOF;
+ while (n > 1)
+ {
+ c = fz_readbyte(stm);
+ if (c == EOF)
+ break;
+ if (c == '\r') {
+ c = fz_peekbyte(stm);
+ if (c == '\n')
+ c = fz_readbyte(stm);
+ break;
+ }
+ if (c == '\n')
+ break;
+ *s++ = c;
+ n--;
+ }
+ if (n)
+ *s = '\0';
+
+ error = fz_readerror(stm);
+ if (error)
+ return fz_rethrow(error, "cannot read line");
+ return fz_okay;
+}
+
+static inline int
+fz_fillbuf(fz_stream *stm, fz_buffer *buf)
+{
+ int remaining = buf->ep - buf->wp;
+ int available = stm->buffer->wp - stm->buffer->rp;
+
+ if (available == 0 && remaining > 0)
+ {
+ int c = fz_readbytex(stm);
+ if (c == EOF)
+ return EOF;
+
+ *buf->wp++ = c;
+
+ remaining = buf->ep - buf->wp;
+ available = stm->buffer->wp - stm->buffer->rp;
+ }
+
+ memmove(buf->wp, stm->buffer->rp, MIN(remaining, available));
+ buf->wp += MIN(remaining, available);
+ stm->buffer->rp += MIN(remaining, available);
+
+ if (stm->buffer->rp == stm->buffer->wp && stm->buffer->eof)
+ return EOF;
+ return 0;
+}
+
+/*
+ * Utility function to consume all the contents of an input stream into
+ * a freshly allocated buffer.
+ */
+
+fz_buffer *
+fz_readall(fz_stream *stm, int sizehint)
+{
+ fz_buffer *buf;
+
+ if (sizehint == 0)
+ sizehint = 4 * 1024;
+
+ buf = fz_newbuffer(sizehint);
+
+ while (fz_fillbuf(stm, buf) != EOF)
+ {
+ if (buf->wp == buf->ep)
+ fz_growbuffer(buf);
+ }
+
+ return buf;
+}
diff --git a/mupdf/pdf_interpret.c b/mupdf/pdf_interpret.c
index 53ba2ee7..bda4a601 100644
--- a/mupdf/pdf_interpret.c
+++ b/mupdf/pdf_interpret.c
@@ -19,8 +19,8 @@ pdf_newcsi(fz_device *dev, pdf_xref *xref, fz_matrix ctm)
csi->clipevenodd = 0;
csi->text = nil;
- csi->tlm = fz_identity();
- csi->tm = fz_identity();
+ csi->tlm = fz_identity;
+ csi->tm = fz_identity;
csi->textmode = 0;
csi->accumulate = 1;
@@ -439,8 +439,8 @@ pdf_runkeyword(pdf_csi *csi, fz_obj *rdb, char *buf)
goto defaultcase;
if (csi->top < 0)
goto syntaxerror;
- csi->tm = fz_identity();
- csi->tlm = fz_identity();
+ csi->tm = fz_identity;
+ csi->tlm = fz_identity;
break;
case 'X':
if (buf[2] != 0)
diff --git a/mupdf/pdf_pattern.c b/mupdf/pdf_pattern.c
index 0997a849..678698ef 100644
--- a/mupdf/pdf_pattern.c
+++ b/mupdf/pdf_pattern.c
@@ -43,7 +43,7 @@ pdf_loadpattern(pdf_pattern **patp, pdf_xref *xref, fz_obj *dict)
if (obj)
pat->matrix = pdf_tomatrix(obj);
else
- pat->matrix = fz_identity();
+ pat->matrix = fz_identity;
pdf_logrsrc("matrix [%g %g %g %g %g %g]\n",
pat->matrix.a, pat->matrix.b,
diff --git a/mupdf/pdf_shade.c b/mupdf/pdf_shade.c
index e7ba8749..6afb114a 100644
--- a/mupdf/pdf_shade.c
+++ b/mupdf/pdf_shade.c
@@ -411,7 +411,7 @@ pdf_loadfunctionbasedshading(fz_shade *shade, pdf_xref *xref, fz_obj *dict, pdf_
y1 = fz_toreal(fz_arrayget(obj, 3));
}
- matrix = fz_identity();
+ matrix = fz_identity;
obj = fz_dictgets(dict, "Matrix");
if (fz_arraylen(obj) == 6)
matrix = pdf_tomatrix(obj);
@@ -1325,7 +1325,7 @@ pdf_loadshading(fz_shade **shadep, pdf_xref *xref, fz_obj *dict)
}
else
{
- mat = fz_identity();
+ mat = fz_identity;
}
obj = fz_dictgets(dict, "ExtGState");
@@ -1353,7 +1353,7 @@ pdf_loadshading(fz_shade **shadep, pdf_xref *xref, fz_obj *dict)
*/
else
{
- error = pdf_loadshadingdict(shadep, xref, dict, fz_identity());
+ error = pdf_loadshadingdict(shadep, xref, dict, fz_identity);
if (error)
return fz_rethrow(error, "cannot load shading dictionary (%d %d R)", fz_tonum(dict), fz_togen(dict));
}
diff --git a/mupdf/pdf_xobject.c b/mupdf/pdf_xobject.c
index 6d0c94ed..a083a38d 100644
--- a/mupdf/pdf_xobject.c
+++ b/mupdf/pdf_xobject.c
@@ -35,7 +35,7 @@ pdf_loadxobject(pdf_xobject **formp, pdf_xref *xref, fz_obj *dict)
if (obj)
form->matrix = pdf_tomatrix(obj);
else
- form->matrix = fz_identity();
+ form->matrix = fz_identity;
pdf_logrsrc("matrix [%g %g %g %g %g %g]\n",
form->matrix.a, form->matrix.b,
diff --git a/win32/mupdf/mupdf.vcproj b/win32/mupdf/mupdf.vcproj
index 4d7ac6c0..385fa63f 100644
--- a/win32/mupdf/mupdf.vcproj
+++ b/win32/mupdf/mupdf.vcproj
@@ -293,19 +293,19 @@
>
</File>
<File
- RelativePath="..\..\fitz\base_hash.c"
+ RelativePath="..\..\fitz\base_geometry.c"
>
</File>
<File
- RelativePath="..\..\fitz\base_matrix.c"
+ RelativePath="..\..\fitz\base_getopt.c"
>
</File>
<File
- RelativePath="..\..\fitz\base_memory.c"
+ RelativePath="..\..\fitz\base_hash.c"
>
</File>
<File
- RelativePath="..\..\fitz\base_rect.c"
+ RelativePath="..\..\fitz\base_memory.c"
>
</File>
<File
@@ -313,7 +313,7 @@
>
</File>
<File
- RelativePath="..\..\fitz\base_unicode.c"
+ RelativePath="..\..\fitz\base_time.c"
>
</File>
<File
@@ -353,14 +353,6 @@
>
</File>
<File
- RelativePath="..\..\fitz\filt_aesd.c"
- >
- </File>
- <File
- RelativePath="..\..\fitz\filt_arc4.c"
- >
- </File>
- <File
RelativePath="..\..\fitz\filt_basic.c"
>
</File>
@@ -377,10 +369,6 @@
>
</File>
<File
- RelativePath="..\..\fitz\filt_faxdtab.c"
- >
- </File>
- <File
RelativePath="..\..\fitz\filt_flate.c"
>
</File>
@@ -409,22 +397,6 @@
>
</File>
<File
- RelativePath="..\..\fitz\fitz_base.h"
- >
- </File>
- <File
- RelativePath="..\..\fitz\fitz_draw.h"
- >
- </File>
- <File
- RelativePath="..\..\fitz\fitz_res.h"
- >
- </File>
- <File
- RelativePath="..\..\fitz\fitz_stream.h"
- >
- </File>
- <File
RelativePath="..\..\fitz\obj_array.c"
>
</File>
@@ -473,10 +445,6 @@
>
</File>
<File
- RelativePath="..\..\fitz\stm_misc.c"
- >
- </File>
- <File
RelativePath="..\..\fitz\stm_open.c"
>
</File>
@@ -484,14 +452,6 @@
RelativePath="..\..\fitz\stm_read.c"
>
</File>
- <File
- RelativePath="..\..\fitz\util_getopt.c"
- >
- </File>
- <File
- RelativePath="..\..\fitz\util_gettimeofday.c"
- >
- </File>
</Filter>
<Filter
Name="draw"