United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4151636 : Rendering of ellipse arcs is unbalanced

Details
Type:
Bug
Submit Date:
1998-06-23
Status:
Closed
Updated Date:
1998-07-27
Project Name:
JDK
Resolved Date:
1998-07-27
Component:
client-libs
OS:
windows_nt
Sub-Component:
2d
CPU:
x86
Priority:
P4
Resolution:
Duplicate
Affected Versions:
1.2.0
Fixed Versions:

Related Reports
Duplicate:

Sub Tasks

Description

Name: bk70084			Date: 06/23/98


/* What algorithm are you using to scan convert
 * ellipses/circles?  It doesn't appear to be any of the
 * famous ones, e.g.: Pitteway, Van Aken, Kappel, Da Silva.
 * I am working on the next edition of the Addison-Wesley
 * textbook "Computer Graphics -- Fundamentals and
 * Practice", in which we use Java as the model graphics
 * package, and I am distressed at the poor quality of
 * filled ellipses/circles coming from JDK 1.2beta3.  (I
 * refer to those rendered *without* antialiasing, which
 * allows me to see exactly what the rendering algorithm was
 * doing.)
 * 
 * Generated circles/ellipses are strange in that the top
 * and left "sides" experience a kind of clipping that
 * yields a rather long portion which is essentially a
 * straight line segment.  This doesn't happen on the right
 * and bottom "sides"; they look as though they were
 * generated by one of the famous algorithms.
 * 
 * Attached is an applet that generates a number of filled
 * primitives.  The white circle (atop a dark grey filled
 * ellipse) is the one that shows the problem best; look at
 * how non-symmetrical the circle's shape is on both the
 * vert and horiz axes.  Note that the left "side" is the
 * worst of them; it looks as though clipping has occurred
 * (except for a 1-pixel "escape" exactly at the vertical
 * center).
 * 
 * The grey filled ellipse arc's left "side" exhibits the
 * same "clip" problem exhibited in the white circle's left
 * side.
 * 
 * Show the generated image to anyone who teaches computer
 * graphics rendering algorithms and I guarantee he/she will
 * cry "foul".  There is definitely something wrong in the
 * scan conversion algorithm.
 * 
 * Please note that I have not tested drawn (as opposed to
 * filled) circles/ellipses; it would be important for you
 * to ensure any fixes get translated into outline
 * generation as well, of course.
 * 
 * Here's the code to my demo applet:
*/
import java.applet.Applet;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.lang.*;
import java.net.*;

public class EArc extends Applet {
  static Frame appletFrame;
  BufferedImage offscrbuff;

  public synchronized void init() {
    System.out.println("java.version = " +
		       System.getProperty("java.version"));
    appletFrame = new Frame();
    appletFrame.setSize(600, 500);
    offscrbuff = 
      new BufferedImage (600, 500, BufferedImage.TYPE_INT_ARGB/*_PRE*/);
    ppaint (offscrbuff.createGraphics());
  }

  public void stop() {
  }

  public void start() {
	//	appletFrame.pack();
	try {
	    appletFrame.show();
	} catch(NullPointerException e) {
	    System.out.println("Exception thrown by f.show(): "
			       + e.getMessage());
	    e.printStackTrace();
	}
  }

  public void destroy() {
  }


  public void update(Graphics g) {
  }

  public void paint(Graphics g) {
    g.drawImage(offscrbuff, 0, 0, this);
  }



  public void ppaint(Graphics g) {
    Graphics2D g2d = (Graphics2D)g;

    Polygon starshape = new Polygon();

    g2d.setStroke (new BasicStroke(2));

    //CONTROL IMAGE QUALITY
    //g2d.setRenderingHints (Graphics2D.ANTIALIASING, Graphics2D.ANTIALIAS_ON);
    g2d.setRenderingHints (Graphics2D.RENDERING, Graphics2D.RENDER_QUALITY);

    // FILL A STAR (a) WITH BLACK
    g2d.setColor (new Color(0,0,0));
    starshape.addPoint (80, 30);
    starshape.addPoint (30, 130);
    starshape.addPoint (130, 60);
    starshape.addPoint (30, 60);
    starshape.addPoint (130, 130);
    g2d.fill (starshape);

    // FILL A PIESLICE (b) WITH DARK GREY
    g2d.setColor (new Color(150,150,150));
    g2d.fillArc (150,60, 130,75, 45, 270);

    // FILL A CIRCLE (c) IN WHITE
    g2d.setColor (new Color(255,255,255));
    g2d.fillOval (165,80, 40,40);

    // FILL A RECTANGLE (d) WITH MEDIUM GREY
    g2d.setColor (new Color(180,180,180));
    g2d.fill (new Rectangle(200,30, 80,50));

    // FILL (e) WITH SAME COLOR BUT IN TRANSLUCENT MODE
    AlphaComposite acDestOverTranslu =
      AlphaComposite.getInstance(AlphaComposite.DST_OVER, (float)0.65);
    g2d.setComposite(acDestOverTranslu);
    g2d.fill (new Rectangle(200,115, 80,50));
  }

  public String getAppletInfo() {
    return "Filled shapes";
  }
      
  public String[][] getParameterInfo() {
    String[][] info = {};
    return info;
  }

  public static void main (String[] args) {
    Applet theApplet = new EArc();

    theApplet.init();

    //appletFrame.pack();
    appletFrame.add(theApplet, "Center");

    appletFrame.setLocation(140,100);
    appletFrame.addWindowListener( new AppQuitter());

    theApplet.start();
    theApplet.stop();
    theApplet.destroy();

  } // end "public static void main"

  /*
   * An inner class for quitting the application
   */
  static class AppQuitter extends WindowAdapter {
    public void windowClosing(WindowEvent e) {
      e.getWindow().dispose();
      System.exit(0);
    } // end "public void windowClosing"
  } // end "static class AppQuitter"
} // End "public class EArc extends Applet"
(Review ID: 34052)
======================================================================

                                    

Comments
EVALUATION

We currently use flattened Bezier approximations.  We agree that this is a
very clumsy way to render Arcs.  We are hoping that better Bezier stepping
code will do an acceptable job (since the antialiasing code is rendering
Bezier approximations also and looks fine).

jim.graham@Eng 1998-06-23
                                     
1998-06-23



Hardware and Software, Engineered to Work Together