summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2004-11-25 07:06:56 +0100
committerTor Andersson <tor@ghostscript.com>2004-11-25 07:06:56 +0100
commit6796693d6b7db5933aaf5c6a33793abbfd3dd93c (patch)
tree43d01faf8fba5e36315714d629a2b910d1d7dce6
parent3e799920074ffaa718dfa671f3ed424f80c71b71 (diff)
downloadmupdf-6796693d6b7db5933aaf5c6a33793abbfd3dd93c.tar.xz
cleanups and c89 fixes
-rw-r--r--Jamfile2
-rw-r--r--base/rune.c2
-rw-r--r--include/fitz/shade.h2
-rw-r--r--include/fitz/sysdep.h2
-rw-r--r--mupdf/cmap.c4
-rw-r--r--mupdf/font.c21
-rw-r--r--mupdf/function.c55
-rw-r--r--mupdf/image1.c2
-rw-r--r--mupdf/interpret.c11
-rw-r--r--mupdf/resources.c57
-rw-r--r--mupdf/shade.c2
-rw-r--r--render/glyphcache.c20
-rw-r--r--render/rastport.c3
-rw-r--r--render/rastshade.c (renamed from render/shade.c)0
-rw-r--r--render/render.c5
-rw-r--r--test/pdfrip.c4
-rw-r--r--tree/optimize.c29
17 files changed, 148 insertions, 73 deletions
diff --git a/Jamfile b/Jamfile
index bd6da3e6..ed7718fb 100644
--- a/Jamfile
+++ b/Jamfile
@@ -90,7 +90,7 @@ Library libfitz :
render/fill.c
render/stroke.c
render/scale.c
- render/shade.c
+ render/rastshade.c
render/rastport.c
render/render.c
;
diff --git a/base/rune.c b/base/rune.c
index 8b886637..4aa81df3 100644
--- a/base/rune.c
+++ b/base/rune.c
@@ -27,7 +27,7 @@ enum
Maskx = (1<<Bitx)-1, /* 0011 1111 */
Testx = Maskx ^ 0xFF, /* 1100 0000 */
- Bad = Runeerror,
+ Bad = Runeerror
};
int
diff --git a/include/fitz/shade.h b/include/fitz/shade.h
index 7641f609..542581c9 100644
--- a/include/fitz/shade.h
+++ b/include/fitz/shade.h
@@ -4,7 +4,7 @@ struct fz_shade_s
{
int refs;
fz_colorspace *cs;
- // ...
+ /* ... */
};
fz_shade *fz_keepshade(fz_shade *shade);
diff --git a/include/fitz/sysdep.h b/include/fitz/sysdep.h
index dd4b8fd3..79948d80 100644
--- a/include/fitz/sysdep.h
+++ b/include/fitz/sysdep.h
@@ -20,7 +20,7 @@
#else
-#define FZ_FLEX 0
+#define FZ_FLEX 1
#define restrict
#define inline __inline__
#define va_copy(a,b) (a) = (b)
diff --git a/mupdf/cmap.c b/mupdf/cmap.c
index a5768748..b7a261d4 100644
--- a/mupdf/cmap.c
+++ b/mupdf/cmap.c
@@ -13,7 +13,7 @@ enum
TBEGINCIDCHAR,
TENDCIDCHAR,
TBEGINCIDRANGE,
- TENDCIDRANGE,
+ TENDCIDRANGE
};
static int tokenfromkeyword(char *key)
@@ -32,7 +32,7 @@ static int tokenfromkeyword(char *key)
return PDF_TKEYWORD;
}
-static int codefromstring(unsigned char *buf, int len)
+static int codefromstring(char *buf, int len)
{
int a = 0;
while (len--)
diff --git a/mupdf/font.c b/mupdf/font.c
index 464d8c11..b27403d6 100644
--- a/mupdf/font.c
+++ b/mupdf/font.c
@@ -80,6 +80,7 @@ ftrender(fz_glyph *glyph, fz_font *fzfont, int cid, fz_matrix trm)
FT_Error fterr;
float scale;
int gid;
+ int x, y;
if (font->cidtogid)
gid = font->cidtogid[cid];
@@ -165,16 +166,16 @@ ftrender(fz_glyph *glyph, fz_font *fzfont, int cid, fz_matrix trm)
glyph->y = face->glyph->bitmap_top - glyph->h;
glyph->samples = face->glyph->bitmap.buffer;
- int i;
- unsigned char tmp[glyph->w * glyph->h];
- memcpy(tmp, glyph->samples, glyph->w * glyph->h);
-
- for (i = 0; i < glyph->h; i++)
- {
- memcpy( glyph->samples + i * glyph->w,
- tmp + (glyph->h - i - 1) * glyph->w,
- glyph->w );
- }
+ for (y = 0; y < glyph->h / 2; y++)
+ {
+ for (x = 0; x < glyph->w; x++)
+ {
+ unsigned char a = glyph->samples[y * glyph->w + x ];
+ unsigned char b = glyph->samples[(glyph->h - y - 1) * glyph->w + x];
+ glyph->samples[y * glyph->w + x ] = b;
+ glyph->samples[(glyph->h - y - 1) * glyph->w + x] = a;
+ }
+ }
return nil;
}
diff --git a/mupdf/function.c b/mupdf/function.c
index 49420f6f..9838d4df 100644
--- a/mupdf/function.c
+++ b/mupdf/function.c
@@ -1,6 +1,8 @@
#include <fitz.h>
#include <mupdf.h>
+#define index psindex /* collide with string.h index() */
+
typedef struct psobj_s psobj;
struct pdf_function_s
@@ -42,12 +44,12 @@ struct psobj_s
{
unsigned short type;
union {
- int booln; /* boolean (stack only) */
- int intg; /* integer (stack and code) */
- float real; /* real (stack and code) */
+ int b; /* boolean (stack only) */
+ int i; /* integer (stack and code) */
+ float f; /* real (stack and code) */
int op; /* operator (code only) */
int blk; /* if/ifelse block pointer (code only) */
- };
+ } u;
};
#define ARRAY_SIZE(a) sizeof(a) / sizeof(a[0])
@@ -254,7 +256,7 @@ pushbool(psstack *st, int booln)
{
if (checkoverflow(st, 1)) {
st->stack[--st->sp].type = psBool;
- st->stack[st->sp].booln = booln;
+ st->stack[st->sp].u.b = booln;
}
else
return fz_stackoverflow;
@@ -267,7 +269,7 @@ pushint(psstack *st, int intg)
{
if (checkoverflow(st, 1)) {
st->stack[--st->sp].type = psInt;
- st->stack[st->sp].intg = intg;
+ st->stack[st->sp].u.i = intg;
}
else
return fz_stackoverflow;
@@ -280,7 +282,7 @@ pushreal(psstack *st, float real)
{
if (checkoverflow(st, 1)) {
st->stack[--st->sp].type = psReal;
- st->stack[st->sp].real = real;
+ st->stack[st->sp].u.f = real;
}
else
return fz_stackoverflow;
@@ -292,7 +294,7 @@ static fz_error *
popbool(psstack *st, int *booln)
{
if (checkunderflow(st) && checktype(st, psBool, psBool)) {
- *booln = st->stack[st->sp++].booln;
+ *booln = st->stack[st->sp++].u.b;
}
else if(checkunderflow(st))
return fz_stackunderflow;
@@ -306,7 +308,7 @@ static fz_error *
popint(psstack *st, int *intg)
{
if (checkunderflow(st) && checktype(st, psInt, psInt)) {
- *intg = st->stack[st->sp++].intg;
+ *intg = st->stack[st->sp++].u.i;
}
else if(checkunderflow(st))
return fz_stackunderflow;
@@ -322,7 +324,7 @@ popnum(psstack *st, float *real)
if (checkunderflow(st) && checktype(st, psInt, psReal)) {
float ret;
ret = (st->stack[st->sp].type == psInt) ?
- (float)st->stack[st->sp].intg : st->stack[st->sp].real;
+ (float)st->stack[st->sp].u.i : st->stack[st->sp].u.f;
++st->sp;
*real = ret;
}
@@ -679,6 +681,8 @@ loadexponentialfunc(pdf_function *func, fz_obj *dict)
/* optional */
tmpobj = fz_dictgets(dict,"C0");
if(fz_isarray(tmpobj)) {
+ fz_obj *objnum;
+
if(func->range && fz_arraylen(tmpobj) != func->n)
goto cleanup;
@@ -686,7 +690,6 @@ loadexponentialfunc(pdf_function *func, fz_obj *dict)
func->u.e.c0 = c0 = fz_malloc(func->n * sizeof(float));
if(!c0) { err = fz_outofmem; goto cleanup; }
- fz_obj *objnum;
for(i = 0; i < func->n; ++i) {
objnum = fz_arrayget(tmpobj,i);
if(!fz_isint(objnum) && !fz_isreal(objnum))
@@ -928,13 +931,13 @@ parsecode(pdf_function *func, fz_file *stream, int *codeptr)
case PDF_TINT:
resizecode(func,*codeptr);
func->u.p.code[*codeptr].type = psInt;
- func->u.p.code[*codeptr].intg = atoi(buf);
+ func->u.p.code[*codeptr].u.i = atoi(buf);
++*codeptr;
break;
case PDF_TREAL:
resizecode(func,*codeptr);
func->u.p.code[*codeptr].type = psReal;
- func->u.p.code[*codeptr].real = atof(buf);
+ func->u.p.code[*codeptr].u.f = atof(buf);
++*codeptr;
break;
case PDF_TOBRACE:
@@ -965,19 +968,19 @@ parsecode(pdf_function *func, fz_file *stream, int *codeptr)
if (elsePtr >= 0)
goto cleanup;
func->u.p.code[opPtr].type = psOperator;
- func->u.p.code[opPtr].op = psOpIf;
+ func->u.p.code[opPtr].u.op = psOpIf;
func->u.p.code[opPtr+2].type = psBlock;
- func->u.p.code[opPtr+2].blk = *codeptr;
+ func->u.p.code[opPtr+2].u.blk = *codeptr;
}
else if(!strcmp(buf,"ifelse")) {
if (elsePtr < 0)
goto cleanup;
func->u.p.code[opPtr].type = psOperator;
- func->u.p.code[opPtr].op = psOpIfelse;
+ func->u.p.code[opPtr].u.op = psOpIfelse;
func->u.p.code[opPtr+1].type = psBlock;
- func->u.p.code[opPtr+1].blk = elsePtr;
+ func->u.p.code[opPtr+1].u.blk = elsePtr;
func->u.p.code[opPtr+2].type = psBlock;
- func->u.p.code[opPtr+2].blk = *codeptr;
+ func->u.p.code[opPtr+2].u.blk = *codeptr;
}
else
goto cleanup;
@@ -988,7 +991,7 @@ parsecode(pdf_function *func, fz_file *stream, int *codeptr)
case PDF_TCBRACE:
resizecode(func,*codeptr);
func->u.p.code[*codeptr].type = psOperator;
- func->u.p.code[*codeptr].op = psOpReturn;
+ func->u.p.code[*codeptr].u.op = psOpReturn;
++*codeptr;
return nil;
case PDF_TKEYWORD:
@@ -1011,7 +1014,7 @@ parsecode(pdf_function *func, fz_file *stream, int *codeptr)
resizecode(func,*codeptr);
func->u.p.code[*codeptr].type = psOperator;
- func->u.p.code[*codeptr].op = a;
+ func->u.p.code[*codeptr].u.op = a;
++*codeptr;
break;
default:
@@ -1061,13 +1064,13 @@ evalpostscriptfunc(pdf_function *func, psstack *st, int codeptr)
while (1) {
switch (func->u.p.code[codeptr].type) {
case psInt:
- SAFE_PUSHINT(st,func->u.p.code[codeptr++].intg);
+ SAFE_PUSHINT(st,func->u.p.code[codeptr++].u.i);
break;
case psReal:
- SAFE_PUSHREAL(st,func->u.p.code[codeptr++].real);
+ SAFE_PUSHREAL(st,func->u.p.code[codeptr++].u.f);
break;
case psOperator:
- switch (func->u.p.code[codeptr++].op) {
+ switch (func->u.p.code[codeptr++].u.op) {
case psOpAbs:
if (topisint(st)) {
SAFE_POPINT(st,&i1);
@@ -1361,16 +1364,16 @@ evalpostscriptfunc(pdf_function *func, psstack *st, int codeptr)
if (b1) {
evalpostscriptfunc(func, st, codeptr + 2);
}
- codeptr = func->u.p.code[codeptr + 1].blk;
+ codeptr = func->u.p.code[codeptr + 1].u.blk;
break;
case psOpIfelse:
SAFE_POPBOOL(st, &b1);
if (b1) {
evalpostscriptfunc(func, st, codeptr + 2);
} else {
- evalpostscriptfunc(func, st, func->u.p.code[codeptr].blk);
+ evalpostscriptfunc(func, st, func->u.p.code[codeptr].u.blk);
}
- codeptr = func->u.p.code[codeptr + 1].blk;
+ codeptr = func->u.p.code[codeptr + 1].u.blk;
break;
case psOpReturn:
return nil;
diff --git a/mupdf/image1.c b/mupdf/image1.c
index 295af901..ee1ff5b3 100644
--- a/mupdf/image1.c
+++ b/mupdf/image1.c
@@ -49,6 +49,8 @@ pdf_loadinlineimage(pdf_image **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict,
if (cs)
{
+ img->super.cs = nil;
+
if (fz_isname(cs))
{
fz_obj *csd = fz_dictgets(rdb, "ColorSpace");
diff --git a/mupdf/interpret.c b/mupdf/interpret.c
index 0ec70667..578dc72c 100644
--- a/mupdf/interpret.c
+++ b/mupdf/interpret.c
@@ -761,17 +761,20 @@ fz_debugobj(rdb);
fz_obj *obj;
fz_shade *shd;
- dict = fz_dictgets(rdb, "Pattern");
+ if (csi->top != 1)
+ goto syntaxerror;
+
+ dict = fz_dictgets(rdb, "Shading");
if (!dict)
- return fz_throw("syntaxerror: missing pattern resource");
+ return fz_throw("syntaxerror: missing shading resource");
obj = fz_dictget(dict, csi->stack[csi->top - 1]);
if (!obj)
- return fz_throw("syntaxerror: missing pattern resource");
+ return fz_throw("syntaxerror: missing shading resource");
shd = pdf_findresource(xref->rshade, obj);
if (!shd)
- return fz_throw("syntaxerror: missing pattern resource");
+ return fz_throw("syntaxerror: missing shading resource");
error = pdf_addshade(gstate, shd);
if (error) return error;
diff --git a/mupdf/resources.c b/mupdf/resources.c
index dbf15a7c..1db57a1b 100644
--- a/mupdf/resources.c
+++ b/mupdf/resources.c
@@ -38,6 +38,9 @@ indirect references so we end up with a stylized structure:
/Pattern <<
/Pat0 20 0 R
>>
+ /Shading <<
+ /Sh0 30 0 R
+ >>
/XObject <<
/Im0 10 0 R
/Fm0 11 0 R
@@ -146,6 +149,38 @@ preloadpattern(pdf_xref *xref, fz_obj *ref)
}
static fz_error *
+preloadshading(pdf_xref *xref, fz_obj *ref)
+{
+ fz_error *error;
+ pdf_rsrc *rsrc;
+ fz_obj *obj;
+
+ if (pdf_findresource(xref->rshade, ref))
+ return nil;
+
+ rsrc = fz_malloc(sizeof(pdf_rsrc));
+ if (!rsrc)
+ return fz_outofmem;
+ rsrc->oid = fz_tonum(ref);
+ rsrc->gen = fz_togen(ref);
+
+ error = pdf_loadindirect(&obj, xref, ref);
+ if (error)
+ return error;
+
+ error = pdf_loadshade((fz_shade**)&rsrc->val, xref, obj, ref);
+ fz_dropobj(obj);
+ if (error) {
+ fz_free(rsrc);
+ return error;
+ }
+
+ rsrc->next = xref->rshade;
+ xref->rshade = rsrc;
+ return nil;
+}
+
+static fz_error *
preloadxobject(pdf_xref *xref, fz_obj *ref)
{
fz_error *error;
@@ -212,6 +247,9 @@ preloadfont(pdf_xref *xref, fz_obj *ref)
pdf_rsrc *rsrc;
fz_obj *obj;
+if (!fz_isindirect(ref))
+ fz_warn("inline font resource");
+
if (pdf_findresource(xref->rfont, ref))
return nil;
@@ -366,6 +404,7 @@ pdf_loadresources(fz_obj **rdbp, pdf_xref *xref, fz_obj *orig)
if (error)
return error;
}
+else fz_warn("inline colorspace resource");
}
}
@@ -385,6 +424,23 @@ pdf_loadresources(fz_obj **rdbp, pdf_xref *xref, fz_obj *orig)
if (error)
return error;
}
+else fz_warn("inline pattern resource");
+ }
+ }
+
+ dict = fz_dictgets(copy, "Shading");
+ if (dict)
+ {
+ for (i = 0; i < fz_dictlen(dict); i++)
+ {
+ obj = fz_dictgetval(dict, i);
+ if (fz_isindirect(obj))
+ {
+ error = preloadshading(xref, obj);
+ if (error)
+ return error;
+ }
+else fz_warn("inline shading resource");
}
}
@@ -404,6 +460,7 @@ pdf_loadresources(fz_obj **rdbp, pdf_xref *xref, fz_obj *orig)
if (error)
return error;
}
+else fz_warn("inline xobject resource");
}
}
diff --git a/mupdf/shade.c b/mupdf/shade.c
index 762e3897..9d5e4568 100644
--- a/mupdf/shade.c
+++ b/mupdf/shade.c
@@ -13,7 +13,7 @@ pdf_loadshade(fz_shade **shadep, pdf_xref *xref, fz_obj *obj, fz_obj *ref)
printf("loading shade pattern\n");
- // ...
+ /* ... */
*shadep = shade;
return nil;
diff --git a/render/glyphcache.c b/render/glyphcache.c
index c47ed0ed..517a67ef 100644
--- a/render/glyphcache.c
+++ b/render/glyphcache.c
@@ -340,14 +340,22 @@ fz_renderglyph(fz_glyphcache *arena, fz_glyph *glyph, fz_font *font, int cid, fz
if (size > arena->size / 6)
return nil;
- while (arena->load > arena->slots * 75 / 100) {
- covf ++;
- evictlast(arena);
+ while (arena->load > arena->slots * 75 / 100)
+ {
+ while (arena->load > arena->slots * 60 / 100)
+ {
+ covf ++;
+ evictlast(arena);
+ }
}
- while (arena->used + size >= arena->size) {
- coos ++;
- evictlast(arena);
+ if (arena->used + size >= arena->size)
+ {
+ while (arena->used + size >= arena->size * 80 / 100)
+ {
+ coos ++;
+ evictlast(arena);
+ }
}
val = &arena->lru[arena->load++];
diff --git a/render/rastport.c b/render/rastport.c
index 0daf3458..112ab5ea 100644
--- a/render/rastport.c
+++ b/render/rastport.c
@@ -357,6 +357,7 @@ static void img_1o1(FZ_PSRC, FZ_PDST, FZ_PCTM)
static void img_4o4(FZ_PSRC, FZ_PDST, FZ_PCTM)
{
byte argb[4];
+ byte ssa;
while (h--)
{
byte *dstp = dst0;
@@ -366,7 +367,7 @@ static void img_4o4(FZ_PSRC, FZ_PDST, FZ_PCTM)
while (w--)
{
sampleargb(src, srcw, srch, u, v, argb);
- byte ssa = 255 - argb[0];
+ ssa = 255 - argb[0];
dstp[0] = argb[0] + fz_mul255(dstp[0], ssa);
dstp[1] = argb[1] + fz_mul255((short)dstp[1] - argb[1], ssa);
dstp[2] = argb[2] + fz_mul255((short)dstp[2] - argb[2], ssa);
diff --git a/render/shade.c b/render/rastshade.c
index 7e7f82ce..7e7f82ce 100644
--- a/render/shade.c
+++ b/render/rastshade.c
diff --git a/render/render.c b/render/render.c
index 58e4b6f0..b72f069e 100644
--- a/render/render.c
+++ b/render/render.c
@@ -25,7 +25,7 @@ fz_newrenderer(fz_renderer **gcp, fz_colorspace *pcm, int maskonly, int gcmem)
gc->gel = nil;
gc->ael = nil;
- error = fz_newglyphcache(&gc->cache, gcmem / 32, gcmem);
+ error = fz_newglyphcache(&gc->cache, gcmem / 24, gcmem);
if (error)
goto cleanup;
@@ -413,6 +413,7 @@ renderimage(fz_renderer *gc, fz_imagenode *node, fz_matrix ctm)
fz_irect clip;
int dx, dy;
fz_pixmap *tile;
+ fz_pixmap *temp;
fz_matrix imgmat;
fz_matrix invmat;
int fa, fb, fc, fd;
@@ -442,7 +443,6 @@ DEBUG(" load image\n");
if (dx != 1 || dy != 1)
{
DEBUG(" scale image 1/%d 1/%d\n", dx, dy);
- fz_pixmap *temp;
error = fz_scalepixmap(&temp, tile, dx, dy);
if (error)
goto cleanup;
@@ -452,7 +452,6 @@ DEBUG(" scale image 1/%d 1/%d\n", dx, dy);
if (image->cs && image->cs != gc->model)
{
- fz_pixmap *temp;
DEBUG(" convert from %s to %s\n", image->cs->name, gc->model->name);
error = fz_newpixmap(&temp, tile->x, tile->y, tile->w, tile->h, gc->model->n + 1);
if (error)
diff --git a/test/pdfrip.c b/test/pdfrip.c
index b34dfb11..f5f762da 100644
--- a/test/pdfrip.c
+++ b/test/pdfrip.c
@@ -121,8 +121,8 @@ int main(int argc, char **argv)
if (error) fz_abort(error);
outlines = nil;
-// error = pdf_loadoutlinetree(&outlines, xref);
-// if (error) { fz_warn(error->msg); fz_droperror(error); }
+/* error = pdf_loadoutlinetree(&outlines, xref); */
+/* if (error) { fz_warn(error->msg); fz_droperror(error); } */
if (optind == argc)
{
diff --git a/tree/optimize.c b/tree/optimize.c
index 6371ddec..b37df876 100644
--- a/tree/optimize.c
+++ b/tree/optimize.c
@@ -16,8 +16,6 @@ static void cleanovers(fz_node *node)
{
next = current->next;
- cleanovers(current);
-
if (fz_isovernode(current))
{
if (current->first == current->last)
@@ -31,13 +29,16 @@ static void cleanovers(fz_node *node)
else
fz_insertnodefirst(node, child);
}
- current = nil;
+ current = child;
}
}
if (current)
prev = current;
}
+
+ for (current = node->first; current; current = current->next)
+ cleanovers(current);
}
/*
@@ -95,19 +96,15 @@ static int fitsinside(fz_node *node, fz_rect clip)
static void cleanmasks(fz_node *node)
{
fz_node *prev;
- fz_node *next;
fz_node *current;
fz_node *shape;
fz_node *color;
fz_rect bbox;
prev = nil;
- for (current = node->first; current; current = next)
+ for (current = node->first; current; current = current->next)
{
- next = current->next;
-
- cleanmasks(current);
-
+retry:
if (fz_ismasknode(current))
{
shape = current->first;
@@ -119,21 +116,23 @@ static void cleanmasks(fz_node *node)
{
if (fitsinside(color, bbox))
{
- printf("removed useless mask\n");
fz_removenode(current);
if (prev)
fz_insertnodeafter(prev, color);
else
fz_insertnodefirst(node, color);
- current = nil;
+ current = color;
+ goto retry;
}
}
}
}
- if (current)
- prev = current;
+ prev = current;
}
+
+ for (current = node->first; current; current = current->next)
+ cleanmasks(current);
}
/*
@@ -143,7 +142,9 @@ static void cleanmasks(fz_node *node)
fz_error *
fz_optimizetree(fz_tree *tree)
{
- cleanovers(tree->root);
+ if (getenv("DONTOPT"))
+ return nil;
+// cleanovers(tree->root);
cleanmasks(tree->root);
return nil;
}