[libbluray-devel] DVBAlphaComposite: cleanup, add error checks

hpi1 git at videolan.org
Wed Apr 6 10:06:18 CEST 2016


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Mon Apr  4 11:27:58 2016 +0300| [81b2cf57f2762e956930e1f315b3a9c3c89cb05b] | committer: hpi1

DVBAlphaComposite: cleanup, add error checks

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

 .../bdj/java/org/dvb/ui/DVBAlphaComposite.java     |   44 ++++++++++++--------
 1 file changed, 26 insertions(+), 18 deletions(-)

diff --git a/src/libbluray/bdj/java/org/dvb/ui/DVBAlphaComposite.java b/src/libbluray/bdj/java/org/dvb/ui/DVBAlphaComposite.java
index d93e666..87892be 100644
--- a/src/libbluray/bdj/java/org/dvb/ui/DVBAlphaComposite.java
+++ b/src/libbluray/bdj/java/org/dvb/ui/DVBAlphaComposite.java
@@ -1,6 +1,7 @@
 /*
  * This file is part of libbluray
  * Copyright (C) 2010  William Hahne
+ * Copyright (C) 2016  Petri Hintukainen <phintuka at users.sourceforge.net>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -23,8 +24,7 @@ public final class DVBAlphaComposite {
 
     private DVBAlphaComposite(int rule)
     {
-        this.rule = rule;
-        this.alpha = 1.0f;
+        this(rule, 1.0f);
     }
 
     private DVBAlphaComposite(int rule, float alpha)
@@ -63,12 +63,26 @@ public final class DVBAlphaComposite {
         case DST_OUT:
             return DstOut;
         default:
+            System.err.println("Unknown composite rule");
             throw new IllegalArgumentException("Unknown rule");
         }
     }
 
     public static DVBAlphaComposite getInstance(int rule, float alpha)
     {
+        if (rule < 1 || rule > 8) {
+            System.err.println("Unknown composite rule");
+            throw new IllegalArgumentException("Unknown rule");
+        }
+
+        if (alpha < 0.0f || alpha > 1.0f) {
+            System.err.println("Alpha value out of range");
+            throw new IllegalArgumentException("invalid alpha");
+        }
+
+        if (alpha >= 1.0f)
+            return getInstance(rule);
+
         return new DVBAlphaComposite(rule, alpha);
     }
 
@@ -83,14 +97,12 @@ public final class DVBAlphaComposite {
 
     public boolean equals(Object obj)
     {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
+        if (!(obj instanceof DVBAlphaComposite))
             return false;
+
         DVBAlphaComposite other = (DVBAlphaComposite) obj;
-        if (Float.floatToIntBits(alpha) != Float.floatToIntBits(other.alpha))
+        //if (Float.floatToIntBits(alpha) != Float.floatToIntBits(other.alpha))
+        if (Float.compare(alpha, other.alpha) != 0)
             return false;
         if (rule != other.rule)
             return false;
@@ -108,17 +120,13 @@ public final class DVBAlphaComposite {
 
     public static final DVBAlphaComposite Clear = new DVBAlphaComposite(CLEAR);
     public static final DVBAlphaComposite Src = new DVBAlphaComposite(SRC);
-    public static final DVBAlphaComposite SrcOver = new DVBAlphaComposite(
-            SRC_OVER);
-    public static final DVBAlphaComposite DstOver = new DVBAlphaComposite(
-            DST_OVER);
+    public static final DVBAlphaComposite SrcOver = new DVBAlphaComposite(SRC_OVER);
+    public static final DVBAlphaComposite DstOver = new DVBAlphaComposite(DST_OVER);
     public static final DVBAlphaComposite SrcIn = new DVBAlphaComposite(SRC_IN);
     public static final DVBAlphaComposite DstIn = new DVBAlphaComposite(DST_IN);
-    public static final DVBAlphaComposite SrcOut = new DVBAlphaComposite(
-            SRC_OUT);
-    public static final DVBAlphaComposite DstOut = new DVBAlphaComposite(
-            DST_OUT);
+    public static final DVBAlphaComposite SrcOut = new DVBAlphaComposite(SRC_OUT);
+    public static final DVBAlphaComposite DstOut = new DVBAlphaComposite(DST_OUT);
 
-    float alpha;
-    int rule;
+    private float alpha;
+    private int rule;
 }



More information about the libbluray-devel mailing list