[libbluray-devel] BDGraphics: factorize common calculations

hpi1 git at videolan.org
Fri Apr 11 12:42:30 CEST 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Thu Apr  3 13:45:21 2014 +0300| [707ad35c88f02f6eee8028d319a5e8b4cb791e27] | committer: hpi1

BDGraphics: factorize common calculations

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

 .../bdj/java/java/awt/BDGraphicsBase.java          |   49 +++++++++++---------
 1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java b/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java
index 491ad7d..7717c04 100644
--- a/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java
+++ b/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java
@@ -1136,43 +1136,46 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
                 c = pixels[index + scansize];
                 d = pixels[index + scansize + 1];
 
-                int aA = (a >> 24) & 0xff;
-                int bA = (b >> 24) & 0xff;
-                int cA = (c >> 24) & 0xff;
-                int dA = (d >> 24) & 0xff;
+                int aA = a >>> 24;
+                int bA = b >>> 24;
+                int cA = c >>> 24;
+                int dA = d >>> 24;
 
                 if (aA + bA + cA + dA < 1) {
                     outImage[position++] = 0;
                     continue;
                 }
 
+                /* calculate areas, weighted with alpha */
+                float aFactor = (1-x_diff) * (1-y_diff) * aA;
+                float bFactor = x_diff     * (1-y_diff) * bA;
+                float cFactor = (1-x_diff) * y_diff     * cA;
+                float dFactor = x_diff     * y_diff     * dA;
+
+                // alpha element
+                // Yr = Ar(1-w)(1-h) + Br(w)(1-h) + Cr(h)(1-w) + Dr(wh)
+                alpha = aFactor + bFactor + cFactor + dFactor;
+
                 // blue element
                 // Yb = Ab(1-w)(1-h) + Bb(w)(1-h) + Cb(h)(1-w) + Db(wh)
-                blue = (a & 0xff) * (1-x_diff) * (1-y_diff) * aA +
-                       (b & 0xff) * x_diff     * (1-y_diff) * bA +
-                       (c & 0xff) * (1-x_diff) * y_diff     * cA +
-                       (d & 0xff) * x_diff     * y_diff     * dA;
+                blue = (a & 0xff) * aFactor +
+                       (b & 0xff) * bFactor +
+                       (c & 0xff) * cFactor +
+                       (d & 0xff) * dFactor;
 
                 // green element
                 // Yg = Ag(1-w)(1-h) + Bg(w)(1-h) + Cg(h)(1-w) + Dg(wh)
-                green = ((a >> 8) & 0xff) * (1-x_diff) * (1-y_diff) * aA +
-                        ((b >> 8) & 0xff) * x_diff     * (1-y_diff) * bA +
-                        ((c >> 8) & 0xff) * (1-x_diff) * y_diff     * cA +
-                        ((d >> 8) & 0xff) * x_diff     * y_diff     * dA;
+                green = ((a >> 8) & 0xff) * aFactor +
+                        ((b >> 8) & 0xff) * bFactor +
+                        ((c >> 8) & 0xff) * cFactor +
+                        ((d >> 8) & 0xff) * dFactor;
 
                 // red element
                 // Yr = Ar(1-w)(1-h) + Br(w)(1-h) + Cr(h)(1-w) + Dr(wh)
-                red = ((a >> 16) & 0xff) * (1-x_diff) * (1-y_diff) * aA +
-                      ((b >> 16) & 0xff) * x_diff     * (1-y_diff) * bA +
-                      ((c >> 16) & 0xff) * (1-x_diff) * y_diff     * cA +
-                      ((d >> 16) & 0xff) *  x_diff    * y_diff     * dA;
-
-                // alpha element
-                // Yr = Ar(1-w)(1-h) + Br(w)(1-h) + Cr(h)(1-w) + Dr(wh)
-                alpha = ((a >> 24) & 0xff) * (1-x_diff) * (1-y_diff) +
-                        ((b >> 24) & 0xff) * x_diff     * (1-y_diff) +
-                        ((c >> 24) & 0xff) * (1-x_diff) * y_diff     +
-                        ((d >> 24) & 0xff) * x_diff     * y_diff;
+                red = ((a >> 16) & 0xff) * aFactor +
+                      ((b >> 16) & 0xff) * bFactor +
+                      ((c >> 16) & 0xff) * cFactor +
+                      ((d >> 16) & 0xff) * dFactor;
 
                 blue  /= alpha;
                 green /= alpha;



More information about the libbluray-devel mailing list