aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-09-04 07:55:48 +0200
committerMattias Andrée <maandree@operamail.com>2014-09-04 07:55:48 +0200
commit745553530ce8e967f331f9754aa3f2d9511e615b (patch)
treeece7c07db2be0ea20bf03a2278aa5888781ae5fc
parentadd CRTCInformation (diff)
downloadjlibgamma-745553530ce8e967f331f9754aa3f2d9511e615b.tar.gz
jlibgamma-745553530ce8e967f331f9754aa3f2d9511e615b.tar.bz2
jlibgamma-745553530ce8e967f331f9754aa3f2d9511e615b.tar.xz
add behex and unhex
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--src/libgamma/CRTCInformation.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/libgamma/CRTCInformation.java b/src/libgamma/CRTCInformation.java
index 384ad5c..307ec8b 100644
--- a/src/libgamma/CRTCInformation.java
+++ b/src/libgamma/CRTCInformation.java
@@ -452,5 +452,41 @@ public class CRTCInformation
*/
public final LibgammaException gamma_error;
+
+
+ /**
+ * Convert a raw representation of an EDID to a lowercase hexadecimal representation.
+ *
+ * @param edid The EDID in raw representation.
+ * @return The EDID in lowercase hexadecimal representation,
+ */
+ public static String behex(byte[] edid)
+ {
+ char[] rc = new char[edid.length * 2];
+ for (int i = 0; i < edid.length; i++)
+ { rc[i * 2 + 0] = "0123456789abcdef".charAt((edid[i] >> 4) & 15);
+ rc[i * 2 + 1] = "0123456789abcdef".charAt((edid[i] >> 0) & 15);
+ }
+ return new String(rc);
+ }
+
+ /**
+ * Convert an hexadecimal representation of an EDID to a raw representation.
+ *
+ * @param edid The EDID in hexadecimal representation.
+ * @return The EDID in raw representation, it will be half the length
+ * of <tt>edid</tt> (the input value).
+ */
+ public static byte[] unhex(String edid)
+ {
+ byte[] rc = new byte[edid.length() / 2];
+ edid = edid.toLowerCase();
+ for (int i = 0; i < rc.length; i++)
+ { rc[i] = (byte)("0123456789abcdef".indexOf(edid.charAt(i * 2 + 0)) << 4);
+ rc[i] |= (byte)("0123456789abcdef".indexOf(edid.charAt(i * 2 + 1)) << 0);
+ }
+ return rc;
+ }
+
}