summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <Robin.Watts@artifex.com>2020-02-24 11:24:28 +0000
committerChris Liddell <chris.liddell@artifex.com>2020-02-26 08:18:49 +0000
commit389324fd827e1172eb358b616a32af5fcb2633f6 (patch)
treed29b06c2d5a078748f6e3644e1a85d4bbae16012
parent449433ff6689c603a56186dbde5721f6139aa939 (diff)
downloadghostpdl-389324fd827e1172eb358b616a32af5fcb2633f6.tar.gz
Squash some warnings with gs_swapcolors_quick breaking const.
At various places in the code, we call gs_swapcolors_quick where we only have a const pgs. Properly, we should copy the pgs to a non-const pgs, and then use that, but that would be a performance hit. In all cases, we change the graphics state, then restore it before exit, so effectively it is const over the entire call of the enclosing procedure. Rather than having lots of small hacky casts removing const, we push the const breakage into gs_swapcolors_quick itself where we do it in the "approved" way using a union.
-rw-r--r--base/gdevp14.c22
-rw-r--r--base/gsstate.c12
-rw-r--r--base/gxfill.c4
-rw-r--r--base/gxgstate.h10
-rw-r--r--devices/vector/gdevpdfd.c12
5 files changed, 42 insertions, 18 deletions
diff --git a/base/gdevp14.c b/base/gdevp14.c
index 9666dea51..fc58e2c95 100644
--- a/base/gdevp14.c
+++ b/base/gdevp14.c
@@ -3316,10 +3316,10 @@ pdf14_fill_stroke_path(gx_device *dev, const gs_gstate *pgs, gx_path *ppath,
}
if (pgs->strokeconstantalpha > 0) {
- gs_swapcolors_quick((gs_gstate*)pgs); /* flips stroke_color_index (to stroke) */
+ gs_swapcolors_quick(pgs); /* flips stroke_color_index (to stroke) */
((pdf14_device*)dev)->op_state = PDF14_OP_STATE_STROKE;
code = pdf14_stroke_path(dev, pgs, ppath, stroke_params, pdcolor_stroke, pcpath);
- gs_swapcolors_quick((gs_gstate*)pgs); /* this flips pgs->stroke_color_index back as well */
+ gs_swapcolors_quick(pgs); /* this flips pgs->stroke_color_index back as well */
if (code < 0)
goto cleanup; /* bail out (with colors swapped back to fill) */
}
@@ -3373,23 +3373,29 @@ pdf14_fill_stroke_path(gx_device *dev, const gs_gstate *pgs, gx_path *ppath,
code = gs_setopacityalpha((gs_gstate*) pgs, pgs->strokeconstantalpha);
if (code < 0)
goto cleanup;
- gs_swapcolors_quick((gs_gstate*) pgs);
+ gs_swapcolors_quick(pgs);
((pdf14_device*)dev)->op_state = PDF14_OP_STATE_STROKE;
if (pgs->stroke_overprint && dev->color_info.polarity == GX_CINFO_POLARITY_SUBTRACTIVE) {
code = gs_setblendmode((gs_gstate*)pgs, BLEND_MODE_CompatibleOverprint);
- if (code < 0)
+ if (code < 0) {
+ gs_swapcolors_quick(pgs);
goto cleanup;
+ }
}
code = pdf14_stroke_path(dev, pgs, ppath, stroke_params, pdcolor_stroke, pcpath);
- if (code < 0)
+ if (code < 0) {
+ gs_swapcolors_quick(pgs);
goto cleanup;
+ }
if (pgs->stroke_overprint && dev->color_info.polarity == GX_CINFO_POLARITY_SUBTRACTIVE) {
code = gs_setblendmode((gs_gstate*)pgs, blend_mode);
- if (code < 0)
+ if (code < 0) {
+ gs_swapcolors_quick(pgs);
goto cleanup;
+ }
}
- gs_swapcolors_quick((gs_gstate*) pgs);
+ gs_swapcolors_quick(pgs);
}
/* Now during the pop do the compositing with alpha of 1.0 and normal blend */
@@ -4367,7 +4373,7 @@ pdf14_set_params(gs_gstate * pgs,
if (pparams->changed & PDF14_SET_STROKECONSTANTALPHA)
pgs->strokeconstantalpha = pparams->strokeconstantalpha;
if (pparams->changed & PDF_SET_FILLSTROKE_STATE) {
- gs_swapcolors_quick((gs_gstate*)pgs);
+ gs_swapcolors_quick(pgs);
}
pdf14_set_marking_params(dev, pgs);
}
diff --git a/base/gsstate.c b/base/gsstate.c
index 90cb28718..cbb70548a 100644
--- a/base/gsstate.c
+++ b/base/gsstate.c
@@ -1436,8 +1436,13 @@ gs_id gx_get_clip_path_id(gs_gstate *pgs)
return pgs->clip_path->id;
}
-void gs_swapcolors_quick(gs_gstate *pgs)
+void gs_swapcolors_quick(const gs_gstate *cpgs)
{
+ union {
+ const gs_gstate *cpgs;
+ gs_gstate *pgs;
+ } const_breaker;
+ gs_gstate *pgs;
struct gx_cie_joint_caches_s *tmp_cie;
gs_devicen_color_map tmp_ccm;
gs_client_color *tmp_cc;
@@ -1445,6 +1450,11 @@ void gs_swapcolors_quick(gs_gstate *pgs)
gx_device_color *tmp_dc;
gs_color_space *tmp_cs;
+ /* Break const just once, neatly, here rather than
+ * hackily in every caller. */
+ const_breaker.cpgs = cpgs;
+ pgs = const_breaker.pgs;
+
tmp_cc = pgs->color[0].ccolor;
pgs->color[0].ccolor = pgs->color[1].ccolor;
pgs->color[1].ccolor = tmp_cc;
diff --git a/base/gxfill.c b/base/gxfill.c
index 1abea4911..68bcdafcc 100644
--- a/base/gxfill.c
+++ b/base/gxfill.c
@@ -681,9 +681,9 @@ gx_default_fill_stroke_path(gx_device * pdev, const gs_gstate * pgs,
if (code < 0)
return code;
/* Swap colors to make sure the pgs colorspace is correct for stroke */
- gs_swapcolors_quick((gs_gstate *) pgs);
+ gs_swapcolors_quick(pgs);
code = dev_proc(pdev, stroke_path)(pdev, pgs, ppath, params_stroke, pdevc_stroke, pcpath);
- gs_swapcolors_quick((gs_gstate*) pgs);
+ gs_swapcolors_quick(pgs);
return code;
}
diff --git a/base/gxgstate.h b/base/gxgstate.h
index 33f642027..e6dd92f75 100644
--- a/base/gxgstate.h
+++ b/base/gxgstate.h
@@ -438,7 +438,15 @@ int gs_currentscreenphase_pgs(const gs_gstate *, gs_int_point *, gs_color_select
(pgs)->current_point.x = xx;\
(pgs)->current_point.y = yy;
-void gs_swapcolors_quick(gs_gstate *);
+/* The const is a lie. The swapcolors stuff is a bit of a hack; a late
+ * addition to the graphics library, which has to be used in many places
+ * where the device interface only has a const gs_gstate available to it
+ * rather than a non-const one. In all these cases, we flip the colors
+ * during a call to a function, then swap it back again before we leave,
+ * so the net effect of the call remains that the gstate is not changed.
+ * Rather than breaking const at every single callsite, we move the const
+ * breaking into the function itself. */
+void gs_swapcolors_quick(const gs_gstate *);
/* Set the graphics_type_tag iff the requested tag bit is not set in the dev_color and */
/* unset the dev_color so that gx_set_dev_color will remap (encode) with the new tag. */
diff --git a/devices/vector/gdevpdfd.c b/devices/vector/gdevpdfd.c
index 4973d71fd..1e62bad1c 100644
--- a/devices/vector/gdevpdfd.c
+++ b/devices/vector/gdevpdfd.c
@@ -1896,9 +1896,9 @@ gdev_pdf_fill_stroke_path(gx_device *dev, const gs_gstate *pgs, gx_path *ppath,
code = gdev_pdf_fill_path(dev, pgs, ppath, fill_params, pdcolor_fill, pcpath);
if (code < 0)
return code;
- gs_swapcolors_quick((gs_gstate *)pgs);
+ gs_swapcolors_quick(pgs);
code = gdev_pdf_stroke_path(dev, pgs, ppath, stroke_params, pdcolor_stroke, pcpath);
- gs_swapcolors_quick((gs_gstate *)pgs);
+ gs_swapcolors_quick(pgs);
return code;
} else {
bool set_ctm;
@@ -2031,17 +2031,17 @@ gdev_pdf_fill_stroke_path(gx_device *dev, const gs_gstate *pgs, gx_path *ppath,
if (code < 0)
return code;
/* Swap colors to make sure the pgs colorspace is correct for stroke */
- gs_swapcolors_quick((gs_gstate*) pgs);
+ gs_swapcolors_quick(pgs);
code = gdev_pdf_stroke_path(dev, pgs, ppath, stroke_params, pdcolor_stroke, pcpath);
- gs_swapcolors_quick((gs_gstate*) pgs);
+ gs_swapcolors_quick(pgs);
return code;
}
/* Swap colors to make sure the pgs colorspace is correct for stroke */
- gs_swapcolors_quick((gs_gstate*) pgs);
+ gs_swapcolors_quick(pgs);
code = gdev_vector_prepare_stroke((gx_device_vector *)pdev, pgs, stroke_params,
pdcolor_stroke, scale);
- gs_swapcolors_quick((gs_gstate*) pgs);
+ gs_swapcolors_quick(pgs);
if (code < 0) {
code = gdev_pdf_fill_path(dev, pgs, ppath, fill_params, pdcolor_fill, pcpath);
if (code < 0)