diff options
author | Tor Andersson <tor@ghostscript.com> | 2004-11-29 17:33:59 +0100 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2004-11-29 17:33:59 +0100 |
commit | 4008b4d986b700830fad5086df3acfc1028a9e3b (patch) | |
tree | 9d3f43d95875482d272559eb44a4a7c9fc25882c /tree | |
parent | 9a36550815c3d874ce62650bf06ee85a3f705f1c (diff) | |
download | mupdf-4008b4d986b700830fad5086df3acfc1028a9e3b.tar.xz |
turn 1x1 images into rectangles
Diffstat (limited to 'tree')
-rw-r--r-- | tree/optimize.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/tree/optimize.c b/tree/optimize.c index cbb9ad31..9f85cdd7 100644 --- a/tree/optimize.c +++ b/tree/optimize.c @@ -215,6 +215,84 @@ retry: } /* + * Turn 1x1 images into rectangle fills + */ + +static fz_error *clean1x1(fz_node *node) +{ + fz_error *error; + fz_node *current; + fz_node *color; + fz_pathnode *rect; + fz_node *mask; + fz_image *image; + fz_pixmap *pix; + float v[FZ_MAXCOLORS]; + int i; + + for (current = node->first; current; current = current->next) + { + if (fz_isimagenode(current)) + { + image = ((fz_imagenode*)current)->image; + if (image->w == 1 && image->h == 1) + { + error = fz_newpathnode(&rect); + fz_moveto(rect, 0, 0); + fz_lineto(rect, 1, 0); + fz_lineto(rect, 1, 1); + fz_lineto(rect, 0, 1); + fz_closepath(rect); + fz_endpath(rect, FZ_FILL, nil, nil); + + if (image->cs) + { + error = fz_newpixmap(&pix, 0, 0, 1, 1, image->n + 1); + if (error) + return error; + + error = image->loadtile(image, pix); + if (error) + return error; + + for (i = 0; i < image->n; i++) + v[i] = pix->samples[i + 1] / 255.0; + + fz_droppixmap(pix); + + error = fz_newcolornode(&color, image->cs, image->n, v); + if (error) + return error; + error = fz_newmasknode(&mask); + if (error) + return error; + + fz_insertnodeafter(mask, (fz_node*)rect); + fz_insertnodeafter(mask, color); + fz_insertnodeafter(current, mask); + fz_removenode(current); + current = color; + } + + else + { + /* pray that the 1x1 image mask is all opaque */ + fz_insertnodeafter(current, (fz_node*)rect); + fz_removenode(current); + current = (fz_node*)rect; + } + } + } + + error = clean1x1(current); + if (error) + return error; + } + + return nil; +} + +/* * */ @@ -226,6 +304,7 @@ fz_optimizetree(fz_tree *tree) cleanwhite(tree->root); cleanovers(tree->root); cleanmasks(tree->root); + clean1x1(tree->root); return nil; } |