// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov. // Jad home page: http://www.geocities.com/kpdus/jad.html // Decompiler options: braces fieldsfirst space lnc package com.philips.lighting.hue.sdk.utilities; import com.philips.lighting.hue.sdk.utilities.impl.Color; import com.philips.lighting.hue.sdk.utilities.impl.PHHueHelper; import com.philips.lighting.hue.sdk.utilities.impl.PointF; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Locale; import java.util.TimeZone; public class PHUtilities { private static final int CPT_BLUE = 2; private static final int CPT_GREEN = 1; private static final int CPT_RED = 0; public PHUtilities() { } public static float[] calculateXY(int i, String s) { float f = (float)Color.red(i) / 255F; float f1 = (float)Color.green(i) / 255F; float f2 = (float)Color.blue(i) / 255F; float f3; float f5; Object obj; float af[]; PointF pointf1; if (f > 0.04045F) { f = (float)Math.pow((0.055F + f) / 1.055F, 2.4000000953674316D); } else { f /= 12.92F; } if (f1 > 0.04045F) { f1 = (float)Math.pow((0.055F + f1) / 1.055F, 2.4000000953674316D); } else { f1 /= 12.92F; } if (f2 > 0.04045F) { f2 = (float)Math.pow((0.055F + f2) / 1.055F, 2.4000000953674316D); } else { f2 /= 12.92F; } f3 = 0.649926F * f + 0.103455F * f1 + 0.197109F * f2; f5 = 0.234327F * f + 0.743075F * f1 + 0.022598F * f2; f = 0.0F * f + 0.053077F * f1 + 1.035763F * f2; af = new float[2]; af[0] = f3 / (f3 + f5 + f); af[1] = f5 / (f3 + f5 + f); if (Float.isNaN(af[0])) { af[0] = 0.0F; } if (Float.isNaN(af[1])) { af[1] = 0.0F; } pointf1 = new PointF(af[0], af[1]); obj = colorPointsForModel(s); if (!checkPointInLampsReach(pointf1, ((List) (obj)))) { s = getClosestPointToPoints((PointF)((List) (obj)).get(0), (PointF)((List) (obj)).get(1), pointf1); PointF pointf = getClosestPointToPoints((PointF)((List) (obj)).get(2), (PointF)((List) (obj)).get(0), pointf1); obj = getClosestPointToPoints((PointF)((List) (obj)).get(1), (PointF)((List) (obj)).get(2), pointf1); f = getDistanceBetweenTwoPoints(pointf1, s); f2 = getDistanceBetweenTwoPoints(pointf1, pointf); float f4 = getDistanceBetweenTwoPoints(pointf1, ((PointF) (obj))); f1 = f; if (f2 < f) { f1 = f2; s = pointf; } if (f4 < f1) { s = ((String) (obj)); } af[0] = ((PointF) (s)).x; af[1] = ((PointF) (s)).y; } af[0] = PHHueHelper.precision(4, af[0]); af[1] = PHHueHelper.precision(4, af[1]); return af; } public static float[] calculateXYFromRGB(int i, int j, int k, String s) { return calculateXY(Color.rgb(i, j, k), s); } private static boolean checkPointInLampsReach(PointF pointf, List list) { boolean flag = true; if (pointf == null || list == null) { flag = false; } else { PointF pointf1 = (PointF)list.get(0); PointF pointf2 = (PointF)list.get(1); PointF pointf3 = (PointF)list.get(2); list = new PointF(pointf2.x - pointf1.x, pointf2.y - pointf1.y); pointf2 = new PointF(pointf3.x - pointf1.x, pointf3.y - pointf1.y); pointf = new PointF(pointf.x - pointf1.x, pointf.y - pointf1.y); float f = crossProduct(pointf, pointf2) / crossProduct(list, pointf2); float f1 = crossProduct(list, pointf) / crossProduct(list, pointf2); if (f < 0.0F || f1 < 0.0F || f + f1 > 1.0F) { return false; } } return flag; } public static int colorFromXY(float af[], String s) { if (af == null || s == null) { throw new IllegalArgumentException("Input parameter can't be null"); } PointF pointf1 = new PointF(af[0], af[1]); s = colorPointsForModel(s); if (!checkPointInLampsReach(pointf1, s)) { af = getClosestPointToPoints((PointF)s.get(0), (PointF)s.get(1), pointf1); PointF pointf = getClosestPointToPoints((PointF)s.get(2), (PointF)s.get(0), pointf1); s = getClosestPointToPoints((PointF)s.get(1), (PointF)s.get(2), pointf1); float f = getDistanceBetweenTwoPoints(pointf1, af); float f4 = getDistanceBetweenTwoPoints(pointf1, pointf); float f6 = getDistanceBetweenTwoPoints(pointf1, s); float f2 = f; if (f4 < f) { f2 = f4; af = pointf; } if (f6 < f2) { af = s; } pointf1.x = ((PointF) (af)).x; pointf1.y = ((PointF) (af)).y; } float f3 = pointf1.x; float f5 = pointf1.y; float f1 = (1.0F / f5) * f3; f3 = (1.0F / f5) * (1.0F - f3 - f5); float f8 = 3.2406F * f1 - 1.5372F * 1.0F - 0.4986F * f3; float f7 = -f1 * 0.9689F + 1.8758F * 1.0F + 0.0415F * f3; float f9 = (0.0557F * f1 - 0.204F * 1.0F) + 1.057F * f3; if (f8 > f9 && f8 > f7 && f8 > 1.0F) { f3 = f7 / f8; f1 = f9 / f8; f5 = 1.0F; } else if (f7 > f9 && f7 > f8 && f7 > 1.0F) { f5 = f8 / f7; f1 = f9 / f7; f3 = 1.0F; } else { f1 = f9; f3 = f7; f5 = f8; if (f9 > f8) { f1 = f9; f3 = f7; f5 = f8; if (f9 > f7) { f1 = f9; f3 = f7; f5 = f8; if (f9 > 1.0F) { f5 = f8 / f9; f3 = f7 / f9; f1 = 1.0F; } } } } if (f5 <= 0.0031308F) { f7 = f5 * 12.92F; } else { f7 = 1.055F * (float)Math.pow(f5, 0.4166666567325592D) - 0.055F; } if (f3 <= 0.0031308F) { f8 = f3 * 12.92F; } else { f8 = 1.055F * (float)Math.pow(f3, 0.4166666567325592D) - 0.055F; } if (f1 <= 0.0031308F) { f9 = f1 * 12.92F; } else { f9 = 1.055F * (float)Math.pow(f1, 0.4166666567325592D) - 0.055F; } if (f7 > f9 && f7 > f8) { f1 = f9; f3 = f8; f5 = f7; if (f7 > 1.0F) { f3 = f8 / f7; f1 = f9 / f7; f5 = 1.0F; } } else if (f8 > f9 && f8 > f7) { f1 = f9; f3 = f8; f5 = f7; if (f8 > 1.0F) { f5 = f7 / f8; f1 = f9 / f8; f3 = 1.0F; } } else { f1 = f9; f3 = f8; f5 = f7; if (f9 > f7) { f1 = f9; f3 = f8; f5 = f7; if (f9 > f8) { f1 = f9; f3 = f8; f5 = f7; if (f9 > 1.0F) { f5 = f7 / f9; f3 = f8 / f9; f1 = 1.0F; } } } } f7 = f5; if (f5 < 0.0F) { f7 = 0.0F; } f5 = f3; if (f3 < 0.0F) { f5 = 0.0F; } f3 = f1; if (f1 < 0.0F) { f3 = 0.0F; } return Color.rgb((int)(255F * f7), (int)(255F * f5), (int)(255F * f3)); } private static List colorPointsForModel(String s) { String s1 = s; if (s == null) { s1 = " "; } s = new ArrayList(); ArrayList arraylist = new ArrayList(); arraylist.add("LCT001"); arraylist.add("LCT002"); arraylist.add("LCT003"); ArrayList arraylist1 = new ArrayList(); arraylist1.add("LLC001"); arraylist1.add("LLC005"); arraylist1.add("LLC006"); arraylist1.add("LLC007"); arraylist1.add("LLC010"); arraylist1.add("LLC011"); arraylist1.add("LLC012"); arraylist1.add("LLC014"); arraylist1.add("LLC013"); arraylist1.add("LST001"); if (arraylist.contains(s1)) { s.add(new PointF(0.674F, 0.322F)); s.add(new PointF(0.408F, 0.517F)); s.add(new PointF(0.168F, 0.041F)); return s; } if (arraylist1.contains(s1)) { s.add(new PointF(0.703F, 0.296F)); s.add(new PointF(0.214F, 0.709F)); s.add(new PointF(0.139F, 0.081F)); return s; } else { s.add(new PointF(1.0F, 0.0F)); s.add(new PointF(0.0F, 1.0F)); s.add(new PointF(0.0F, 0.0F)); return s; } } private static float crossProduct(PointF pointf, PointF pointf1) { return pointf.x * pointf1.y - pointf.y * pointf1.x; } private static PointF getClosestPointToPoints(PointF pointf, PointF pointf1, PointF pointf2) { float f2; if (pointf == null || pointf1 == null || pointf2 == null) { return null; } pointf2 = new PointF(pointf2.x - pointf.x, pointf2.y - pointf.y); pointf1 = new PointF(pointf1.x - pointf.x, pointf1.y - pointf.y); float f = pointf1.x; f2 = pointf1.x; float f3 = pointf1.y; float f4 = pointf1.y; f2 = (pointf2.x * pointf1.x + pointf2.y * pointf1.y) / (f * f2 + f3 * f4); if (f2 >= 0.0F) goto _L2; else goto _L1 _L1: float f1 = 0.0F; _L4: return new PointF(pointf.x + pointf1.x * f1, pointf.y + pointf1.y * f1); _L2: f1 = f2; if (f2 > 1.0F) { f1 = 1.0F; } if (true) goto _L4; else goto _L3 _L3: } private static float getDistanceBetweenTwoPoints(PointF pointf, PointF pointf1) { float f = pointf.x - pointf1.x; float f1 = pointf.y - pointf1.y; return (float)Math.sqrt(f * f + f1 * f1); } public static Date stringToDate(String s) { SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", new Locale("nl_NL")); simpledateformat.setTimeZone(TimeZone.getTimeZone("UTC")); try { s = simpledateformat.parse(s); } // Misplaced declaration of an exception variable catch (String s) { return null; } return s; } public static Date stringToDateForTime(String s) { SimpleDateFormat simpledateformat = new SimpleDateFormat("HH:mm:ss", new Locale("nl_NL")); simpledateformat.setTimeZone(TimeZone.getTimeZone("UTC")); try { s = simpledateformat.parse(s); } // Misplaced declaration of an exception variable catch (String s) { return null; } return s; } }