[libbluray-devel] BDGraphics: Improved drawOval() and fillOval()

Ian Curtis git at videolan.org
Wed Mar 26 00:10:49 CET 2014


libbluray | branch: master | Ian Curtis <i.curtis at gmail.com> | Wed Mar 26 00:41:48 2014 +0200| [6a297cc4ecaad5808b68efac53866753f015159f] | committer: hpi1

BDGraphics: Improved drawOval() and fillOval()

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=6a297cc4ecaad5808b68efac53866753f015159f
---

 .../bdj/java-j2me/java/awt/BDGraphics.java         |   76 ++++++++++++++++----
 .../bdj/java-j2se/java/awt/BDGraphics.java         |   76 ++++++++++++++++----
 2 files changed, 122 insertions(+), 30 deletions(-)

diff --git a/src/libbluray/bdj/java-j2me/java/awt/BDGraphics.java b/src/libbluray/bdj/java-j2me/java/awt/BDGraphics.java
index a2c2530..e5c4f9f 100644
--- a/src/libbluray/bdj/java-j2me/java/awt/BDGraphics.java
+++ b/src/libbluray/bdj/java-j2me/java/awt/BDGraphics.java
@@ -630,31 +630,77 @@ class BDGraphics extends Graphics2D implements ConstrainableGraphics {
     /** Draws an oval to fit in the given rectangle */
     public void drawOval(int x, int y, int w, int h) {
 
-        float angleIncriment = 180 / h;
-        int   rgb = foreground.getRGB();
+        int     startX;
+        int     endX;
+        int     offset;
+        int[]   xList;
+        int[]   yList;
+        int     numPoints;
+        int     count;
+        float   as;
+        float   bs;
+
+        if (w <= 0 || h <=0 ) {
+            return;
+        }
 
-        for (int i = 0; i < h; i++) {
-            int offset = (int) (w/2 * Math.sin(angleIncriment*i));
-            int startX = x + w/2 - offset;
-            int endX   = x + w/2 + offset;
+        count = 0;
+        numPoints = ((h/2) + (h/2) + 1) * 2;
+        numPoints += 1; // to close
+        xList = new int[numPoints];
+        yList = new int[numPoints];
+
+        as = (w/2.0f) * (w/2.0f);
+        bs = (h/2.0f) * (h/2.0f);
+
+        for (int i = -h/2; i <= h/2; i++) {
+            offset = (int) Math.sqrt( (1.0 - ((i*i)/bs)) * as );
+            startX  = x - offset + w/2;
+
+            xList[count] = startX;
+            yList[count] = y + i + h/2;
+            count++;
+        }
+
+        for (int i = h/2; i >= -h/2; i--) {
+            offset = (int) Math.sqrt( (1.0 - ((i*i)/bs)) * as );
+            endX    = x + offset + w/2;
 
-            drawPoint(startX, y + i, rgb);
-            drawPoint(endX, y + i, rgb);
+            xList[count] = endX;
+            yList[count] = y + i + h/2;
+            count++;
         }
+
+        xList[count] = xList[0];        // close the loop
+        yList[count] = yList[0];        // close the loop
+
+        drawPolyline(xList, yList, numPoints);
     }
 
     /** Fills an oval to fit in the given rectangle */
     public void fillOval(int x, int y, int w, int h) {
 
-        float angleIncriment = angleIncriment = 180 / h;
-        int   rgb = foreground.getRGB();
+        int     startX;
+        int     endX;
+        int     offset;
+        int     colour;
+        float   as;
+        float   bs;
 
-        for (int i = 0; i < h; i++) {
-            int offset = (int) (w/2 * Math.sin(angleIncriment*i));
-            int startX = x + w/2 - offset;
-            int endX   = x + w/2 + offset;
+        if (w <= 0 || h <= 0) {
+            return;
+        }
+
+        as = (w/2.0f) * (w/2.0f);
+        bs = (h/2.0f) * (h/2.0f);
+        colour = foreground.getRGB();
+
+        for(int i=-h/2; i<=h/2; i++) {
+            offset  = (int) Math.sqrt( (1.0 - ((i*i)/bs)) * as );
+            startX  = x - offset + w/2;
+            endX    = x + offset + w/2;
 
-            drawSpan(startX, y + i, endX - startX, rgb);
+            drawSpan(startX, y + i + h/2, endX - startX + 1, colour);
         }
     }
 
diff --git a/src/libbluray/bdj/java-j2se/java/awt/BDGraphics.java b/src/libbluray/bdj/java-j2se/java/awt/BDGraphics.java
index bc1016b..2056dc5 100644
--- a/src/libbluray/bdj/java-j2se/java/awt/BDGraphics.java
+++ b/src/libbluray/bdj/java-j2se/java/awt/BDGraphics.java
@@ -713,31 +713,77 @@ class BDGraphics extends Graphics2D implements ConstrainableGraphics {
     /** Draws an oval to fit in the given rectangle */
     public void drawOval(int x, int y, int w, int h) {
 
-        float angleIncriment = 180 / h;
-        int   rgb = foreground.getRGB();
+        int     startX;
+        int     endX;
+        int     offset;
+        int[]   xList;
+        int[]   yList;
+        int     numPoints;
+        int     count;
+        float   as;
+        float   bs;
+
+        if (w <= 0 || h <=0 ) {
+            return;
+        }
 
-        for (int i = 0; i < h; i++) {
-            int offset = (int) (w/2 * Math.sin(angleIncriment*i));
-            int startX = x + w/2 - offset;
-            int endX   = x + w/2 + offset;
+        count = 0;
+        numPoints = ((h/2) + (h/2) + 1) * 2;
+        numPoints += 1; // to close
+        xList = new int[numPoints];
+        yList = new int[numPoints];
+
+        as = (w/2.0f) * (w/2.0f);
+        bs = (h/2.0f) * (h/2.0f);
+
+        for (int i = -h/2; i <= h/2; i++) {
+            offset = (int) Math.sqrt( (1.0 - ((i*i)/bs)) * as );
+            startX  = x - offset + w/2;
+
+            xList[count] = startX;
+            yList[count] = y + i + h/2;
+            count++;
+        }
+
+        for (int i = h/2; i >= -h/2; i--) {
+            offset = (int) Math.sqrt( (1.0 - ((i*i)/bs)) * as );
+            endX    = x + offset + w/2;
 
-            drawPoint(startX, y + i, rgb);
-            drawPoint(endX, y + i, rgb);
+            xList[count] = endX;
+            yList[count] = y + i + h/2;
+            count++;
         }
+
+        xList[count] = xList[0];        // close the loop
+        yList[count] = yList[0];        // close the loop
+
+        drawPolyline(xList, yList, numPoints);
     }
 
     /** Fills an oval to fit in the given rectangle */
     public void fillOval(int x, int y, int w, int h) {
 
-        float angleIncriment = angleIncriment = 180 / h;
-        int   rgb = foreground.getRGB();
+        int     startX;
+        int     endX;
+        int     offset;
+        int     colour;
+        float   as;
+        float   bs;
 
-        for (int i = 0; i < h; i++) {
-            int offset = (int) (w/2 * Math.sin(angleIncriment*i));
-            int startX = x + w/2 - offset;
-            int endX   = x + w/2 + offset;
+        if (w <= 0 || h <= 0) {
+            return;
+        }
+
+        as = (w/2.0f) * (w/2.0f);
+        bs = (h/2.0f) * (h/2.0f);
+        colour = foreground.getRGB();
+
+        for(int i=-h/2; i<=h/2; i++) {
+            offset  = (int) Math.sqrt( (1.0 - ((i*i)/bs)) * as );
+            startX  = x - offset + w/2;
+            endX    = x + offset + w/2;
 
-            drawSpan(startX, y + i, endX - startX, rgb);
+            drawSpan(startX, y + i + h/2, endX - startX + 1, colour);
         }
     }
 



More information about the libbluray-devel mailing list