Re: fill-opacity bug fix
Bob Friesenhahn <[email protected]>
| Newsgroups | gmane.comp.video.graphicsmagick.core |
|---|---|
| Message-ID | <[email protected]> |
I should mention that I have learned that this fix breaks WMF
rendering so it is clear that the fix introduces a bug. MVG commands
are being filtered when they shouldn't be. I studied the code last
night but have not yet discovered the cause of the problem.
Bob
On Tue, 9 Mar 2004, Bob Friesenhahn wrote:
> On Tue, 9 Mar 2004, Yi Zhang wrote:
> >
> > I had problem with applying fill-opacity and stroke-opacity at the same
> > time. When I set fill-opacity to 0.0, and stroke-opacity to 1.0, the
> > object's (e.g. rectangle) outline will not be drawn. Someone on the
> > ImageMagick mailing list had a similar experience:
> > http://studio.imagemagick.org/pipermail/magick-users/2003-November/011301.ht
> > ml
> >
> > Eventually, I fixed my problem with the following patch (the first patch
> > chunk is in DrawGetFillOpacity(), the second chunk is in
> > DrawSetFillOpacity()):
>
> These are the fixes I finally ended up applying. The opacity is
> stored inverted internally, but must be passed non-inverted for the
> MVG.
>
> Index: draw.c
> ===================================================================
> RCS file: /GraphicsMagick/GraphicsMagick/magick/draw.c,v
> retrieving revision 1.612
> diff -u -r1.612 draw.c
> --- draw.c 22 Dec 2003 01:06:31 -0000 1.612
> +++ draw.c 9 Mar 2004 17:18:56 -0000
> @@ -1546,7 +1546,7 @@
> assert(context != (DrawContext)NULL);
> assert(context->signature == MagickSignature);
>
> - return ((double)CurrentContext->opacity/MaxRGB);
> + return (((double)(MaxRGB-CurrentContext->fill.opacity))/MaxRGB);
> }
>
> /*
> @@ -1578,17 +1578,21 @@
> const double fill_opacity)
> {
> Quantum
> - opacity;
> + quantum_opacity;
> +
> + double
> + validated_opacity;
>
> assert(context != (DrawContext)NULL);
> assert(context->signature == MagickSignature);
>
> - opacity = (Quantum)((double) MaxRGB*(1.0-(fill_opacity <= 1.0 ? fill_opacity : 1.0 ))+0.5);
> + validated_opacity=(fill_opacity < 0.0 ? 0.0 : (fill_opacity > 1.0 ? 1.0 : fill_opacity));
> + quantum_opacity = (Quantum) (((double) MaxRGB*(1.0-validated_opacity))+0.5);
>
> - if (context->filter_off || (CurrentContext->opacity != opacity))
> + if (context->filter_off || (CurrentContext->fill.opacity != quantum_opacity))
> {
> - CurrentContext->opacity = opacity;
> - MvgPrintf(context, "fill-opacity %.4g\n", fill_opacity);
> + CurrentContext->fill.opacity = quantum_opacity;
> + MvgPrintf(context, "fill-opacity %.4g\n", validated_opacity);
> }
> }
>
> @@ -5398,18 +5402,22 @@
> MagickExport void DrawSetStrokeOpacity(DrawContext context,
> const double stroke_opacity)
> {
> + Quantum
> + quantum_opacity;
> +
> double
> - opacity;
> + validated_opacity;
>
> assert(context != (DrawContext)NULL);
> assert(context->signature == MagickSignature);
>
> - opacity = (Quantum)((double) MaxRGB*(1.0-(stroke_opacity <= 1.0 ? stroke_opacity : 1.0 ))+0.5);
> + validated_opacity=(stroke_opacity < 0.0 ? 0.0 : (stroke_opacity > 1.0 ? 1.0 : stroke_opacity));
> + quantum_opacity = (Quantum) (((double) MaxRGB*(1.0-validated_opacity))+0.5);
>
> - if (context->filter_off || (CurrentContext->stroke.opacity != opacity))
> + if (context->filter_off || (CurrentContext->stroke.opacity != quantum_opacity))
> {
> - CurrentContext->stroke.opacity = (Quantum) ceil(opacity);
> - MvgPrintf(context, "stroke-opacity %.4g\n", stroke_opacity);
> + CurrentContext->stroke.opacity = quantum_opacity;
> + MvgPrintf(context, "stroke-opacity %.4g\n", validated_opacity);
> }
> }
>
>
> ======================================
> Bob Friesenhahn
> [email protected]
> http://www.simplesystems.org/users/bfriesen
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: IBM Linux Tutorials
> Free Linux tutorial presented by Daniel Robbins, President and CEO of
> GenToo technologies. Learn everything from fundamentals to system
> administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> _______________________________________________
> Graphicsmagick-core mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/graphicsmagick-core
>
======================================
Bob Friesenhahn
[email protected]
http://www.simplesystems.org/users/bfriesen
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click