Bug 219588 - Dropouts in rendering Coons patch meshes
Summary: Dropouts in rendering Coons patch meshes
Status: NOTIFIED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: Graphics Library (show other bugs)
Version: master
Hardware: All All
: P2 normal
Assignee: Raph Levien
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2000-10-27 16:27 UTC by Raph Levien
Modified: 2007-12-13 12:55 UTC (History)
0 users

See Also:
Customer:
Word Size: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Raph Levien 2000-10-27 16:27:43 UTC
Originally reported by: raph@users.sourceforge.net
------------------------------------------------------------------------
Symptoms:

When rendering Coons patch meshes as generated by Adobe Illustrator 9's gradient mesh tool, some pixels are not painted, leading to the appearance of "dropouts" where the underlying color shows through.

------------------------------------------------------------------------
Ghostscript version (or include output from "gs -h"):

Ghostscript GS_6_5 branch from CVS, 2000-10-27.

------------------------------------------------------------------------
Where you got Ghostscript:

SourceForge CVS

------------------------------------------------------------------------
Hardware system you are using (including printer model if the problem
involves printing):

Dual Celeron 400

------------------------------------------------------------------------
Operating system you are using:

Red Hat Linux 6.2

------------------------------------------------------------------------
If you are using X Windows, and your problem involved output to the
screen, the output from running xdpyinfo and xwininfo:

------------------------------------------------------------------------
C compiler you are using, including its version, if you compiled
Ghostscript yourself:

gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)


------------------------------------------------------------------------
If you compiled Ghostscript yourself, changes you made to the makefiles:

X11R6 pathname changes only.

------------------------------------------------------------------------
Environment variables:

        GS_DEVICE

        GS_FONTPATH

        GS_LIB

        GS_OPTIONS

------------------------------------------------------------------------
Command line:

bin/gs -sDEVICE=ppmraw -sOutputFile="|xv -" -DNOPAUSE -- gradmesh.ai

------------------------------------------------------------------------
URL or FTP location of test files (include the data at the end of this
form if 500K or less):

http://www.levien.com/pdf/gradmesh.ai

------------------------------------------------------------------------
Suggested fix, if any:

I think the problem here is roundoff error when subdividing the Coons patch into triangles, ie the pixels covered by painting the subdivided pixels don't necessarily match those covered by painting the original triangle.

I think a reasonable fix would be to paint each of the finally subdivided triangles using the "any part of pixel" rule. This will cause some pixels to be painted over more than once, and may slightly change the results when painting a shading without a clipping path, but should still fix the dropouts.
Comment 1 Raph Levien 2000-10-27 22:48:05 UTC
Comment originally by raph@users.sourceforge.net
The following patch (intended more as a test to probe the bug rather than a proposed solution) eliminates the symptoms. It works by "fattening" the filling of triangles.

Index: src/gsptype2.c
===================================================================
RCS file: /cvsroot/ghostscript/gs/src/gsptype2.c,v
retrieving revision 1.3
diff -c -r1.3 gsptype2.c
*** src/gsptype2.c      2000/09/19 19:00:32     1.3
--- src/gsptype2.c      2000/10/28 05:44:22
***************
*** 167,173 ****
      rect.q.y = int2fixed(y + h);
      /* We don't want any adjustment of the box. */
      gs_currentfilladjust(pgs, &save_adjust);
!     gs_setfilladjust(pgs, 0.0, 0.0);
      /****** DOESN'T HANDLE RASTER OP ******/
      code = gs_shading_fill_path(pinst->template.Shading, NULL, &rect, dev,
                                (gs_imager_state *)pgs, true);
--- 167,173 ----
      rect.q.y = int2fixed(y + h);
      /* We don't want any adjustment of the box. */
      gs_currentfilladjust(pgs, &save_adjust);
!     gs_setfilladjust(pgs, 0.25, 0.25);
      /****** DOESN'T HANDLE RASTER OP ******/
      code = gs_shading_fill_path(pinst->template.Shading, NULL, &rect, dev,
                                (gs_imager_state *)pgs, true);
Index: src/gxshade4.c
===================================================================
RCS file: /cvsroot/ghostscript/gs/src/gxshade4.c,v
retrieving revision 1.3
diff -c -r1.3 gxshade4.c
*** src/gxshade4.c      2000/09/19 19:00:40     1.3
--- src/gxshade4.c      2000/10/28 05:44:22
***************
*** 133,139 ****
            (*pcs->type->remap_color)(&fcc, pcs, &dev_color, pis,
                                      pfs->dev, gs_color_select_texture);
            /****** SHOULD ADD adjust ON ANY OUTSIDE EDGES ******/
! #if 0
            {
                gx_path *ppath = gx_path_alloc(pis->memory, "Gt_fill");
  
--- 133,139 ----
            (*pcs->type->remap_color)(&fcc, pcs, &dev_color, pis,
                                      pfs->dev, gs_color_select_texture);
            /****** SHOULD ADD adjust ON ANY OUTSIDE EDGES ******/
! #if 1
            {
                gx_path *ppath = gx_path_alloc(pis->memory, "Gt_fill");
  
Comment 2 Raph Levien 2000-11-10 14:47:02 UTC
Comment originally by raph@users.sourceforge.net
After a little more digging, I now see that there are two sources of dropouts. Pixel roundoffs in triangulation, as discussed previously, do seem to contribute to dropouts. However, a more significant source seems to be inconsistent flattening of edges.

In particular, each edge is subdivided according to the flatness criteria for that edge and the one on the opposite side of the patch. Thus, the coinciding edge of two adjoining patches is likely to be flattened differently. This is the largest source of dropouts, and becomes even more pronounced when the flatness parameter is increased.

A general solution of triangulating a mesh of patches is thus quite difficult. Some mechanism will be needed to deal with changes in subdivision fineness from one patch to the next. This will have to wait for a substantial rework of the shading machinery. In the meantime, increasing fill_adjust should be a reasonable stopgap.
Comment 3 Raph Levien 2000-11-28 17:34:29 UTC
Comment originally by raph@users.sourceforge.net
The workaround posted here:

http://www.ghostscript.com/pipermail/gs-code-review/2000-November/000023.html

...and committed here:

http://www.ghostscript.com/pipermail/gs-cvs/2000-November/000147.html
http://www.ghostscript.com/pipermail/gs-cvs/2000-November/000148.html

...works around the problem. Thus, I am closing the bug. However, there remains considerable room for improvement in both performance and quality. I expect to rework shadings considerably.