From b3f90095897b64f854efc4b2f37df428a71fd508 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 31 Mar 2011 03:18:51 +0200 Subject: xps: Clean up image loading code, and handle images with alpha. --- fitz/fitz.h | 1 + fitz/res_pixmap.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) (limited to 'fitz') diff --git a/fitz/fitz.h b/fitz/fitz.h index 72af4532..5d3ba1c1 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -685,6 +685,7 @@ fz_pixmap *fz_keeppixmap(fz_pixmap *pix); void fz_droppixmap(fz_pixmap *pix); void fz_clearpixmap(fz_pixmap *pix); void fz_clearpixmapwithcolor(fz_pixmap *pix, int value); +void fz_premultiplypixmap(fz_pixmap *pix); fz_pixmap *fz_alphafromgray(fz_pixmap *gray, int luminosity); fz_bbox fz_boundpixmap(fz_pixmap *pix); diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c index e70d084d..b37b7a3e 100644 --- a/fitz/res_pixmap.c +++ b/fitz/res_pixmap.c @@ -97,6 +97,24 @@ fz_clearpixmapwithcolor(fz_pixmap *pix, int value) } } +void +fz_premultiplypixmap(fz_pixmap *pix) +{ + unsigned char *s = pix->samples; + unsigned char a; + int k, x, y; + for (y = 0; y < pix->h; y++) + { + for (x = 0; x < pix->w; x++) + { + a = s[pix->n - 1]; + for (k = 0; k < pix->n - 1; k++) + s[k] = fz_mul255(s[k], a); + s += pix->n; + } + } +} + fz_bbox fz_boundpixmap(fz_pixmap *pix) { -- cgit v1.2.3 From af6d16923fab4597e364c891fee2deb89998bdde Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 31 Mar 2011 15:04:30 +0200 Subject: xps: Fix bugs in TIFF reader. WhiteIsBlack was flipped for fax images. re-multiplying alpha with CMYK images needs special care because of subtractive colors. --- fitz/res_pixmap.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'fitz') diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c index b37b7a3e..93fdb307 100644 --- a/fitz/res_pixmap.c +++ b/fitz/res_pixmap.c @@ -103,14 +103,32 @@ fz_premultiplypixmap(fz_pixmap *pix) unsigned char *s = pix->samples; unsigned char a; int k, x, y; - for (y = 0; y < pix->h; y++) + + /* special case for CMYK (subtractive colors) */ + if (pix->n == 5) + { + for (y = 0; y < pix->h; y++) + { + for (x = 0; x < pix->w; x++) + { + a = s[pix->n - 1]; + for (k = 0; k < pix->n - 1; k++) + s[k] = 255 - fz_mul255(255 - s[k], a); + s += pix->n; + } + } + } + else { - for (x = 0; x < pix->w; x++) + for (y = 0; y < pix->h; y++) { - a = s[pix->n - 1]; - for (k = 0; k < pix->n - 1; k++) - s[k] = fz_mul255(s[k], a); - s += pix->n; + for (x = 0; x < pix->w; x++) + { + a = s[pix->n - 1]; + for (k = 0; k < pix->n - 1; k++) + s[k] = fz_mul255(s[k], a); + s += pix->n; + } } } } -- cgit v1.2.3 From 7c6ae0b110d0a29558305878482023ad7e8a66dc Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 1 Apr 2011 02:24:08 +0200 Subject: xps: Respect PathGeometry.Transform attribute. --- fitz/fitz.h | 2 ++ fitz/res_path.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) (limited to 'fitz') diff --git a/fitz/fitz.h b/fitz/fitz.h index 5d3ba1c1..5cff40b8 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -830,6 +830,8 @@ void fz_curvetoy(fz_path*, float, float, float, float); void fz_closepath(fz_path*); void fz_freepath(fz_path *path); +void fz_transformpath(fz_path *path, fz_matrix transform); + fz_path *fz_clonepath(fz_path *old); fz_rect fz_boundpath(fz_path *path, fz_strokestate *stroke, fz_matrix ctm); diff --git a/fitz/res_path.c b/fitz/res_path.c index ebfb3cdc..b4ac415a 100644 --- a/fitz/res_path.c +++ b/fitz/res_path.c @@ -170,6 +170,42 @@ fz_boundpath(fz_path *path, fz_strokestate *stroke, fz_matrix ctm) return r; } +void +fz_transformpath(fz_path *path, fz_matrix ctm) +{ + fz_point p; + int k, i = 0; + + while (i < path->len) + { + switch (path->els[i++].k) + { + case FZ_CURVETO: + for (k = 0; k < 3; k++) + { + p.x = path->els[i].v; + p.y = path->els[i+1].v; + p = fz_transformpoint(ctm, p); + path->els[i].v = p.x; + path->els[i+1].v = p.y; + i += 2; + } + break; + case FZ_MOVETO: + case FZ_LINETO: + p.x = path->els[i].v; + p.y = path->els[i+1].v; + p = fz_transformpoint(ctm, p); + path->els[i].v = p.x; + path->els[i+1].v = p.y; + i += 2; + break; + case FZ_CLOSEPATH: + break; + } + } +} + void fz_debugpath(fz_path *path, int indent) { -- cgit v1.2.3 From 5a18d4874159ba759863a3dc29ef11fcd23924f9 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 1 Apr 2011 03:50:43 +0200 Subject: xps: Use opacity masks, and draw gradients with opacity. --- fitz/fitz.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'fitz') diff --git a/fitz/fitz.h b/fitz/fitz.h index 5cff40b8..f8bef4c3 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -900,7 +900,7 @@ struct fz_shade_s float background[FZ_MAXCOLORS]; int usefunction; - float function[256][FZ_MAXCOLORS]; + float function[256][FZ_MAXCOLORS + 1]; int type; /* linear, radial, mesh */ int extend[2]; -- cgit v1.2.3 From d2250034a7e629455b9bfbf735473ea39638a701 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 1 Apr 2011 16:02:09 +0200 Subject: Use a function pointer for resolveindirect. This removes a static dependency between fitz and mupdf. Fitz should now be link time independent of mupdf again. --- fitz/fitz.h | 6 +++--- fitz/obj_simple.c | 32 ++++++++------------------------ 2 files changed, 11 insertions(+), 27 deletions(-) (limited to 'fitz') diff --git a/fitz/fitz.h b/fitz/fitz.h index f8bef4c3..d4ab8ff4 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -406,13 +406,15 @@ struct fz_obj_s } u; }; +extern fz_obj* (*fz_resolveindirect)(fz_obj*); + 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_newindirect(int num, int gen, void *xref); fz_obj *fz_newarray(int initialcap); fz_obj *fz_newdict(int initialcap); @@ -435,8 +437,6 @@ 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); diff --git a/fitz/obj_simple.c b/fitz/obj_simple.c index f279bd55..b629974e 100644 --- a/fitz/obj_simple.c +++ b/fitz/obj_simple.c @@ -1,9 +1,15 @@ #include "fitz.h" -#include "mupdf.h" /* for pdf_loadobject */ extern void fz_freearray(fz_obj *array); extern void fz_freedict(fz_obj *dict); +static fz_obj *fz_resolve_indirect_null(fz_obj *ref) +{ + return ref; +} + +fz_obj* (*fz_resolveindirect)(fz_obj*) = fz_resolve_indirect_null; + fz_obj * fz_newnull(void) { @@ -66,7 +72,7 @@ fz_newname(char *str) } fz_obj * -fz_newindirect(int num, int gen, pdf_xref *xref) +fz_newindirect(int num, int gen, void *xref) { fz_obj *o = fz_malloc(sizeof(fz_obj)); o->refs = 1; @@ -219,28 +225,6 @@ int fz_togen(fz_obj *obj) return 0; } -fz_obj *fz_resolveindirect(fz_obj *ref) -{ - if (fz_isindirect(ref)) - { - pdf_xref *xref = ref->u.r.xref; - int num = fz_tonum(ref); - int gen = fz_togen(ref); - if (xref) - { - fz_error error = pdf_cacheobject(xref, num, gen); - if (error) - { - fz_catch(error, "cannot load object (%d %d R) into cache", num, gen); - return ref; - } - if (xref->table[num].obj) - return xref->table[num].obj; - } - } - return ref; -} - int fz_objcmp(fz_obj *a, fz_obj *b) { -- cgit v1.2.3 From 8975aec496710bb9e35a4a1cb635ee0d4eaa60cc Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 3 Apr 2011 15:17:00 +0200 Subject: xps: Use fz_pixmap directly instead of wrapping it in xps_image. --- fitz/fitz.h | 1 + fitz/res_pixmap.c | 2 ++ 2 files changed, 3 insertions(+) (limited to 'fitz') diff --git a/fitz/fitz.h b/fitz/fitz.h index d4ab8ff4..39542c0d 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -673,6 +673,7 @@ struct fz_pixmap_s int x, y, w, h, n; fz_pixmap *mask; /* explicit soft/image mask */ int interpolate; + int xres, yres; fz_colorspace *colorspace; unsigned char *samples; int freesamples; diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c index 93fdb307..9f336ab1 100644 --- a/fitz/res_pixmap.c +++ b/fitz/res_pixmap.c @@ -13,6 +13,8 @@ fz_newpixmapwithdata(fz_colorspace *colorspace, int x, int y, int w, int h, unsi pix->h = h; pix->mask = nil; pix->interpolate = 1; + pix->xres = 96; + pix->yres = 96; pix->colorspace = nil; pix->n = 1; -- cgit v1.2.3 From a85b58e0548fb4e45f35bcbb7d0ee6e35bde35b4 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 3 Apr 2011 17:49:32 +0200 Subject: xps: Fix bugs uncovered by QualityLogicMinBar tests. --- fitz/res_font.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'fitz') diff --git a/fitz/res_font.c b/fitz/res_font.c index 1df8b2e6..44046451 100644 --- a/fitz/res_font.c +++ b/fitz/res_font.c @@ -176,6 +176,7 @@ fz_finalizefreetype(void) fz_error fz_newfontfromfile(fz_font **fontp, char *path, int index) { + FT_Face face; fz_error error; fz_font *font; int fterr; @@ -184,14 +185,16 @@ fz_newfontfromfile(fz_font **fontp, char *path, int index) if (error) return fz_rethrow(error, "cannot init freetype library"); - font = fz_newfont(); - - fterr = FT_New_Face(fz_ftlib, path, index, (FT_Face*)&font->ftface); + fterr = FT_New_Face(fz_ftlib, path, index, &face); if (fterr) - { - fz_free(font); return fz_throw("freetype: cannot load font: %s", ft_errorstring(fterr)); - } + + font = fz_newfont(); + font->ftface = face; + font->bbox.x0 = face->bbox.xMin * 1000 / face->units_per_EM; + font->bbox.y0 = face->bbox.yMin * 1000 / face->units_per_EM; + font->bbox.x1 = face->bbox.xMax * 1000 / face->units_per_EM; + font->bbox.y1 = face->bbox.yMax * 1000 / face->units_per_EM; *fontp = font; return fz_okay; @@ -200,6 +203,7 @@ fz_newfontfromfile(fz_font **fontp, char *path, int index) fz_error fz_newfontfrombuffer(fz_font **fontp, unsigned char *data, int len, int index) { + FT_Face face; fz_error error; fz_font *font; int fterr; @@ -210,12 +214,16 @@ fz_newfontfrombuffer(fz_font **fontp, unsigned char *data, int len, int index) font = fz_newfont(); - fterr = FT_New_Memory_Face(fz_ftlib, data, len, index, (FT_Face*)&font->ftface); + fterr = FT_New_Memory_Face(fz_ftlib, data, len, index, &face); if (fterr) - { - fz_free(font); return fz_throw("freetype: cannot load font: %s", ft_errorstring(fterr)); - } + + font = fz_newfont(); + font->ftface = face; + font->bbox.x0 = face->bbox.xMin * 1000 / face->units_per_EM; + font->bbox.y0 = face->bbox.yMin * 1000 / face->units_per_EM; + font->bbox.x1 = face->bbox.xMax * 1000 / face->units_per_EM; + font->bbox.y1 = face->bbox.yMax * 1000 / face->units_per_EM; *fontp = font; return fz_okay; -- cgit v1.2.3