summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-04-10 01:24:01 +0200
committerTor Andersson <tor.andersson@artifex.com>2011-04-10 01:24:01 +0200
commitd914e3415af1c9c7d8644dfa50fdcf9a79cc01d5 (patch)
tree42b1abdc4ebe58dd008d9f8906db24fa5187324d
parente8e507b38b8c4429abd6e7b32fe8e3029bfab065 (diff)
downloadmupdf-d914e3415af1c9c7d8644dfa50fdcf9a79cc01d5.tar.xz
Make blendmode opaque.
-rw-r--r--draw/draw_blend.c48
-rw-r--r--draw/draw_device.c8
-rw-r--r--fitz/dev_list.c2
-rw-r--r--fitz/dev_null.c2
-rw-r--r--fitz/dev_trace.c4
-rw-r--r--fitz/fitz.h34
-rw-r--r--pdf/mupdf.h2
-rw-r--r--pdf/pdf_build.c10
-rw-r--r--pdf/pdf_interpret.c11
9 files changed, 66 insertions, 55 deletions
diff --git a/draw/draw_blend.c b/draw/draw_blend.c
index 2d68758a..ef9d8c7c 100644
--- a/draw/draw_blend.c
+++ b/draw/draw_blend.c
@@ -4,7 +4,30 @@
typedef unsigned char byte;
-const char *fz_blendmode_names[] =
+enum
+{
+ /* PDF 1.4 -- standard separable */
+ FZ_BLEND_NORMAL,
+ FZ_BLEND_MULTIPLY,
+ FZ_BLEND_SCREEN,
+ FZ_BLEND_OVERLAY,
+ FZ_BLEND_DARKEN,
+ FZ_BLEND_LIGHTEN,
+ FZ_BLEND_COLOR_DODGE,
+ FZ_BLEND_COLOR_BURN,
+ FZ_BLEND_HARD_LIGHT,
+ FZ_BLEND_SOFT_LIGHT,
+ FZ_BLEND_DIFFERENCE,
+ FZ_BLEND_EXCLUSION,
+
+ /* PDF 1.4 -- standard non-separable */
+ FZ_BLEND_HUE,
+ FZ_BLEND_SATURATION,
+ FZ_BLEND_COLOR,
+ FZ_BLEND_LUMINOSITY,
+};
+
+static const char *fz_blendmode_names[] =
{
"Normal",
"Multiply",
@@ -22,9 +45,24 @@ const char *fz_blendmode_names[] =
"Saturation",
"Color",
"Luminosity",
- NULL
};
+int fz_find_blendmode(char *name)
+{
+ int i;
+ for (i = 0; i < nelem(fz_blendmode_names); i++)
+ if (!strcmp(name, fz_blendmode_names[i]))
+ return i;
+ return FZ_BLEND_NORMAL;
+}
+
+char *fz_blendmode_name(int blendmode)
+{
+ if (blendmode >= 0 && blendmode < nelem(fz_blendmode_names))
+ return (char*)fz_blendmode_names[blendmode];
+ return "Normal";
+}
+
/* Separable blend modes */
static inline int fz_screen_byte(int b, int s)
@@ -218,7 +256,7 @@ fz_hue_rgb(int *rr, int *rg, int *rb, int br, int bg, int bb, int sr, int sg, in
/* Blending loops */
void
-fz_blend_separable(byte * restrict bp, byte * restrict sp, int n, int w, fz_blendmode blendmode)
+fz_blend_separable(byte * restrict bp, byte * restrict sp, int n, int w, int blendmode)
{
int k;
int n1 = n - 1;
@@ -266,7 +304,7 @@ fz_blend_separable(byte * restrict bp, byte * restrict sp, int n, int w, fz_blen
}
void
-fz_blend_nonseparable(byte * restrict bp, byte * restrict sp, int w, fz_blendmode blendmode)
+fz_blend_nonseparable(byte * restrict bp, byte * restrict sp, int w, int blendmode)
{
while (w--)
{
@@ -316,7 +354,7 @@ fz_blend_nonseparable(byte * restrict bp, byte * restrict sp, int w, fz_blendmod
}
void
-fz_blend_pixmap(fz_pixmap *dst, fz_pixmap *src, int alpha, fz_blendmode blendmode)
+fz_blend_pixmap(fz_pixmap *dst, fz_pixmap *src, int alpha, int blendmode)
{
unsigned char *sp, *dp;
fz_bbox bbox;
diff --git a/draw/draw_device.c b/draw/draw_device.c
index 1e011b30..ab33dc35 100644
--- a/draw/draw_device.c
+++ b/draw/draw_device.c
@@ -22,7 +22,7 @@ struct fz_draw_device_s
fz_bbox scissor;
fz_pixmap *dest;
fz_pixmap *mask;
- fz_blendmode blendmode;
+ int blendmode;
int luminosity;
float alpha;
fz_matrix ctm;
@@ -848,7 +848,7 @@ fz_draw_end_mask(void *user)
}
static void
-fz_draw_begin_group(void *user, fz_rect rect, int isolated, int knockout, fz_blendmode blendmode, float alpha)
+fz_draw_begin_group(void *user, fz_rect rect, int isolated, int knockout, int blendmode, float alpha)
{
fz_draw_device *dev = user;
fz_colorspace *model = dev->dest->colorspace;
@@ -882,7 +882,7 @@ fz_draw_end_group(void *user)
{
fz_draw_device *dev = user;
fz_pixmap *group = dev->dest;
- fz_blendmode blendmode;
+ int blendmode;
float alpha;
if (dev->top > 0)
@@ -893,7 +893,7 @@ fz_draw_end_group(void *user)
dev->dest = dev->stack[dev->top].dest;
dev->scissor = dev->stack[dev->top].scissor;
- if (blendmode == FZ_BLEND_NORMAL)
+ if (blendmode == 0)
fz_paint_pixmap(dev->dest, group, alpha * 255);
else
fz_blend_pixmap(dev->dest, group, alpha * 255, blendmode);
diff --git a/fitz/dev_list.c b/fitz/dev_list.c
index 33e86b73..fc9342fc 100644
--- a/fitz/dev_list.c
+++ b/fitz/dev_list.c
@@ -273,7 +273,7 @@ fz_list_end_mask(void *user)
}
static void
-fz_list_begin_group(void *user, fz_rect rect, int isolated, int knockout, fz_blendmode blendmode, float alpha)
+fz_list_begin_group(void *user, fz_rect rect, int isolated, int knockout, int blendmode, float alpha)
{
fz_display_node *node;
node = fz_new_display_node(FZ_CMD_BEGIN_GROUP, fz_identity, NULL, NULL, alpha);
diff --git a/fitz/dev_null.c b/fitz/dev_null.c
index d351c0a0..f81b330c 100644
--- a/fitz/dev_null.c
+++ b/fitz/dev_null.c
@@ -136,7 +136,7 @@ fz_end_mask(fz_device *dev)
}
void
-fz_begin_group(fz_device *dev, fz_rect area, int isolated, int knockout, fz_blendmode blendmode, float alpha)
+fz_begin_group(fz_device *dev, fz_rect area, int isolated, int knockout, int blendmode, float alpha)
{
if (dev->begin_group)
dev->begin_group(dev->user, area, isolated, knockout, blendmode, alpha);
diff --git a/fitz/dev_trace.c b/fitz/dev_trace.c
index 2bc171de..758a18f9 100644
--- a/fitz/dev_trace.c
+++ b/fitz/dev_trace.c
@@ -240,11 +240,11 @@ fz_trace_end_mask(void *user)
}
static void
-fz_trace_begin_group(void *user, fz_rect bbox, int isolated, int knockout, fz_blendmode blendmode, float alpha)
+fz_trace_begin_group(void *user, fz_rect bbox, int isolated, int knockout, int blendmode, float alpha)
{
printf("<group bbox=\"%g %g %g %g\" isolated=\"%d\" knockout=\"%d\" blendmode=\"%s\" alpha=\"%g\">\n",
bbox.x0, bbox.y0, bbox.x1, bbox.y1,
- isolated, knockout, fz_blendmode_names[blendmode], alpha);
+ isolated, knockout, fz_blendmode_name(blendmode), alpha);
}
static void
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 15ac5e28..2ee28f86 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -579,30 +579,8 @@ fz_stream *fz_open_jbig2d(fz_stream *chain, fz_buffer *global);
enum { FZ_MAX_COLORS = 32 };
-typedef enum fz_blendmode_e
-{
- /* PDF 1.4 -- standard separable */
- FZ_BLEND_NORMAL,
- FZ_BLEND_MULTIPLY,
- FZ_BLEND_SCREEN,
- FZ_BLEND_OVERLAY,
- FZ_BLEND_DARKEN,
- FZ_BLEND_LIGHTEN,
- FZ_BLEND_COLOR_DODGE,
- FZ_BLEND_COLOR_BURN,
- FZ_BLEND_HARD_LIGHT,
- FZ_BLEND_SOFT_LIGHT,
- FZ_BLEND_DIFFERENCE,
- FZ_BLEND_EXCLUSION,
-
- /* PDF 1.4 -- standard non-separable */
- FZ_BLEND_HUE,
- FZ_BLEND_SATURATION,
- FZ_BLEND_COLOR,
- FZ_BLEND_LUMINOSITY,
-} fz_blendmode;
-
-extern const char *fz_blendmode_names[];
+int fz_find_blendmode(char *name);
+char *fz_blendmode_name(int blendmode);
/*
* Pixmaps have n components per pixel. the last is always alpha.
@@ -1017,7 +995,7 @@ struct fz_device_s
void (*begin_mask)(void *, fz_rect, int luminosity, fz_colorspace *, float *bc);
void (*end_mask)(void *);
- void (*begin_group)(void *, fz_rect, int isolated, int knockout, fz_blendmode blendmode, float alpha);
+ void (*begin_group)(void *, fz_rect, int isolated, int knockout, int blendmode, float alpha);
void (*end_group)(void *);
void (*begin_tile)(void *, fz_rect area, fz_rect view, float xstep, float ystep, fz_matrix ctm);
@@ -1040,7 +1018,7 @@ void fz_fill_image_mask(fz_device *dev, fz_pixmap *image, fz_matrix ctm, fz_colo
void fz_clip_image_mask(fz_device *dev, fz_pixmap *image, fz_matrix ctm);
void fz_begin_mask(fz_device *dev, fz_rect area, int luminosity, fz_colorspace *colorspace, float *bc);
void fz_end_mask(fz_device *dev);
-void fz_begin_group(fz_device *dev, fz_rect area, int isolated, int knockout, fz_blendmode blendmode, float alpha);
+void fz_begin_group(fz_device *dev, fz_rect area, int isolated, int knockout, int blendmode, float alpha);
void fz_end_group(fz_device *dev);
void fz_begin_tile(fz_device *dev, fz_rect area, fz_rect view, float xstep, float ystep, fz_matrix ctm);
void fz_end_tile(fz_device *dev);
@@ -1124,7 +1102,7 @@ struct fz_display_node_s
fz_text *text;
fz_shade *shade;
fz_pixmap *image;
- fz_blendmode blendmode;
+ int blendmode;
} item;
fz_stroke_state *stroke;
int flag; /* even_odd, accumulate, isolated/knockout... */
@@ -1169,6 +1147,6 @@ void fz_paint_pixmap(fz_pixmap *dst, fz_pixmap *src, int alpha);
void fz_paint_pixmap_with_mask(fz_pixmap *dst, fz_pixmap *src, fz_pixmap *msk);
void fz_paint_pixmap_with_rect(fz_pixmap *dst, fz_pixmap *src, int alpha, fz_bbox bbox);
-void fz_blend_pixmap(fz_pixmap *dst, fz_pixmap *src, int alpha, fz_blendmode blendmode);
+void fz_blend_pixmap(fz_pixmap *dst, fz_pixmap *src, int alpha, int blendmode);
#endif
diff --git a/pdf/mupdf.h b/pdf/mupdf.h
index 80942a80..228cd714 100644
--- a/pdf/mupdf.h
+++ b/pdf/mupdf.h
@@ -591,7 +591,7 @@ struct pdf_gstate_s
float rise;
/* transparency */
- fz_blendmode blendmode;
+ int blendmode;
pdf_xobject *softmask;
fz_matrix softmask_ctm;
float softmask_bc[FZ_MAX_COLORS];
diff --git a/pdf/pdf_build.c b/pdf/pdf_build.c
index 8c043107..e22b50c9 100644
--- a/pdf/pdf_build.c
+++ b/pdf/pdf_build.c
@@ -40,7 +40,7 @@ pdf_init_gstate(pdf_gstate *gs, fz_matrix ctm)
gs->render = 0;
gs->rise = 0;
- gs->blendmode = FZ_BLEND_NORMAL;
+ gs->blendmode = 0;
gs->softmask = NULL;
gs->softmask_ctm = fz_identity;
gs->luminosity = 0;
@@ -274,7 +274,7 @@ pdf_begin_group(pdf_csi *csi, fz_rect bbox)
gstate->softmask = softmask;
}
- if (gstate->blendmode != FZ_BLEND_NORMAL)
+ if (gstate->blendmode)
fz_begin_group(csi->dev, bbox, 0, 0, gstate->blendmode, 1);
}
@@ -283,7 +283,7 @@ pdf_end_group(pdf_csi *csi)
{
pdf_gstate *gstate = csi->gstate + csi->gtop;
- if (gstate->blendmode != FZ_BLEND_NORMAL)
+ if (gstate->blendmode)
fz_end_group(csi->dev);
if (gstate->softmask)
@@ -316,7 +316,7 @@ pdf_show_image(pdf_csi *csi, fz_pixmap *image)
if (image->mask)
{
/* apply blend group even though we skip the softmask */
- if (gstate->blendmode != FZ_BLEND_NORMAL)
+ if (gstate->blendmode)
fz_begin_group(csi->dev, bbox, 0, 0, gstate->blendmode, 1);
fz_clip_image_mask(csi->dev, image->mask, gstate->ctm);
}
@@ -360,7 +360,7 @@ pdf_show_image(pdf_csi *csi, fz_pixmap *image)
if (image->mask)
{
fz_pop_clip(csi->dev);
- if (gstate->blendmode != FZ_BLEND_NORMAL)
+ if (gstate->blendmode)
fz_end_group(csi->dev);
}
else
diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c
index d045d54f..d2f0df1c 100644
--- a/pdf/pdf_interpret.c
+++ b/pdf/pdf_interpret.c
@@ -218,7 +218,7 @@ pdf_run_xobject(pdf_csi *csi, fz_obj *resources, pdf_xobject *xobj, fz_matrix tr
fz_transform_rect(gstate->ctm, xobj->bbox),
xobj->isolated, xobj->knockout, gstate->blendmode, gstate->fill.alpha);
- gstate->blendmode = FZ_BLEND_NORMAL;
+ gstate->blendmode = 0;
gstate->stroke.alpha = 1;
gstate->fill.alpha = 1;
}
@@ -364,11 +364,7 @@ pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate)
{
if (fz_is_array(val))
val = fz_array_get(val, 0);
-
- gstate->blendmode = FZ_BLEND_NORMAL;
- for (k = 0; fz_blendmode_names[k]; k++)
- if (!strcmp(fz_blendmode_names[k], fz_to_name(val)))
- gstate->blendmode = k;
+ gstate->blendmode = fz_find_blendmode(fz_to_name(val));
}
else if (!strcmp(s, "SMask"))
@@ -1408,8 +1404,7 @@ pdf_run_page_with_usage(pdf_xref *xref, pdf_page *page, fz_device *dev, fz_matri
int flags;
if (page->transparency)
- fz_begin_group(dev, fz_transform_rect(ctm, page->mediabox),
- 0, 0, FZ_BLEND_NORMAL, 1);
+ fz_begin_group(dev, fz_transform_rect(ctm, page->mediabox), 0, 0, 0, 1);
csi = pdf_new_csi(xref, dev, ctm, target);
error = pdf_run_csi_buffer(csi, page->resources, page->contents);