From 5b69f74e29c549b39d2e7a5de55d6cc9a1e1101c Mon Sep 17 00:00:00 2001 From: AndrewFG Date: Sat, 26 Oct 2024 14:27:22 +0100 Subject: [PATCH 1/3] [ColorUtil] extend supported colour temperature range Signed-off-by: AndrewFG --- .../java/org/openhab/core/util/ColorUtil.java | 449 ++++++++++++++++++ .../org/openhab/core/util/ColorUtilTest.java | 32 +- 2 files changed, 469 insertions(+), 12 deletions(-) diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/util/ColorUtil.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/util/ColorUtil.java index d7b1499e3c4..f62bf463848 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/util/ColorUtil.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/util/ColorUtil.java @@ -692,6 +692,106 @@ public Point closest(Point p) { */ private static final double[][] KELVIN_TO_XY_LOOKUP_TABLE = { //@formatter:off + { 1000, 0.652750055750174, 0.34446222719737 }, + { 1010, 0.651338820005714, 0.345710187476526 }, + { 1020, 0.64993006787286, 0.346948777634801 }, + { 1030, 0.648523859077325, 0.348177799899612 }, + { 1040, 0.647120247807274, 0.349397065326079 }, + { 1050, 0.645719283115238, 0.350606393540134 }, + { 1060, 0.644321009299518, 0.351805612493099 }, + { 1070, 0.642925466265835, 0.352994558226964 }, + { 1080, 0.64153268986994, 0.3541730746497 }, + { 1090, 0.640142712241891, 0.355341013319936 }, + { 1100, 0.638755562092687, 0.356498233240403 }, + { 1110, 0.637371265003916, 0.357644600659585 }, + { 1120, 0.63598984370109, 0.358779988881019 }, + { 1130, 0.634611318311292, 0.359904278079781 }, + { 1140, 0.633235706605755, 0.361017355125666 }, + { 1150, 0.631863024228, 0.362119113412632 }, + { 1160, 0.630493284908101, 0.363209452694114 }, + { 1170, 0.629126500663671, 0.36428827892381 }, + { 1180, 0.627762681988133, 0.365355504101598 }, + { 1190, 0.626401838026807, 0.366411046124246 }, + { 1200, 0.625043976741368, 0.367454828640607 }, + { 1210, 0.623689105063183, 0.368486780911013 }, + { 1220, 0.622337229036024, 0.369506837670598 }, + { 1230, 0.620988353948665, 0.370514938996308 }, + { 1240, 0.619642484457822, 0.371511030177355 }, + { 1250, 0.618299624701903, 0.372495061588915 }, + { 1260, 0.616959778406011, 0.37346698856886 }, + { 1270, 0.61562294897864, 0.374426771297343 }, + { 1280, 0.614289139600468, 0.375374374679072 }, + { 1290, 0.612958353305667, 0.376309768228112 }, + { 1300, 0.611630593056105, 0.377232925955066 }, + { 1310, 0.610305861808828, 0.378143826256513 }, + { 1320, 0.608984162577174, 0.379042451806574 }, + { 1330, 0.607665498485884, 0.379928789450492 }, + { 1340, 0.606349872820529, 0.380802830100132 }, + { 1350, 0.605037289071589, 0.381664568631302 }, + { 1360, 0.603727750973495, 0.38251400378281 }, + { 1370, 0.60242126253892, 0.383351138057187 }, + { 1380, 0.601117828088629, 0.384175977622988 }, + { 1390, 0.599817452277141, 0.384988532218637 }, + { 1400, 0.598520140114478, 0.385788815057729 }, + { 1410, 0.597225896984257, 0.386576842735756 }, + { 1420, 0.595934728658356, 0.387352635138207 }, + { 1430, 0.594646641308391, 0.38811621535 }, + { 1440, 0.59336164151423, 0.38886760956621 }, + { 1450, 0.592079736269747, 0.389606847004059 }, + { 1460, 0.590800932986013, 0.390333959816145 }, + { 1470, 0.589525239492135, 0.391048983004883 }, + { 1480, 0.588252664033903, 0.391751954338129 }, + { 1490, 0.586983215270435, 0.392442914265982 }, + { 1500, 0.585716902268969, 0.393121905838739 }, + { 1510, 0.584453734497981, 0.393788974625991 }, + { 1520, 0.583193721818756, 0.394444168636845 }, + { 1530, 0.581936874475565, 0.395087538241273 }, + { 1540, 0.580683203084578, 0.395719136092572 }, + { 1550, 0.579432718621644, 0.396339017050928 }, + { 1560, 0.578185432409047, 0.396947238108083 }, + { 1570, 0.576941356101364, 0.397543858313098 }, + { 1580, 0.575700501670519, 0.398128938699214 }, + { 1590, 0.574462881390147, 0.398702542211806 }, + { 1600, 0.573228507819347, 0.39926473363742 }, + { 1610, 0.571997393785926, 0.399815579533917 }, + { 1620, 0.570769552369208, 0.400355148161688 }, + { 1630, 0.569544996882493, 0.400883509415978 }, + { 1640, 0.568323740855237, 0.401400734760292 }, + { 1650, 0.567105798015014, 0.401906897160888 }, + { 1660, 0.565891182269338, 0.402402071022378 }, + { 1670, 0.564679907687394, 0.402886332124401 }, + { 1680, 0.563471988481735, 0.403359757559409 }, + { 1690, 0.562267438989995, 0.403822425671539 }, + { 1700, 0.561066273656675, 0.40427441599657 }, + { 1710, 0.559868507015037, 0.404715809202991 }, + { 1720, 0.558674153669138, 0.405146687034153 }, + { 1730, 0.557483228276071, 0.405567132251513 }, + { 1740, 0.556295745528408, 0.405977228578975 }, + { 1750, 0.555111720136911, 0.406377060648321 }, + { 1760, 0.553931166813512, 0.40676671394573 }, + { 1770, 0.552754100254617, 0.407146274759384 }, + { 1780, 0.55158053512472, 0.407515830128156 }, + { 1790, 0.550410486040386, 0.407875467791389 }, + { 1800, 0.54924396755459, 0.408225276139745 }, + { 1810, 0.548080994141461, 0.40856534416712 }, + { 1820, 0.5469215801814, 0.408895761423654 }, + { 1830, 0.545765739946639, 0.409216617969775 }, + { 1840, 0.544613487587208, 0.409528004331327 }, + { 1850, 0.543464837117342, 0.409830011455734 }, + { 1860, 0.542319802402326, 0.410122730669222 }, + { 1870, 0.541178397145793, 0.410406253635074 }, + { 1880, 0.540040634877467, 0.410680672312926 }, + { 1890, 0.538906528941369, 0.410946078919076 }, + { 1900, 0.537776092484472, 0.411202565887823 }, + { 1910, 0.53664933844583, 0.411450225833805 }, + { 1920, 0.535526279546149, 0.411689151515339 }, + { 1930, 0.534406928277829, 0.411919435798755 }, + { 1940, 0.533291296895457, 0.412141171623705 }, + { 1950, 0.532179397406758, 0.412354451969443 }, + { 1960, 0.53107124156399, 0.412559369822065 }, + { 1970, 0.529966840855793, 0.412756018142703 }, + { 1980, 0.52886620649948, 0.412944489836645 }, + { 1990, 0.527769349433755, 0.413124877723394 }, { 2000, 0.526676280311873, 0.41329727450763 }, { 2010, 0.52558700949522, 0.413461772751086 }, { 2020, 0.524501547047308, 0.413618464845305 }, @@ -1147,6 +1247,352 @@ public Point closest(Point p) { { 6520, 0.313214100311644, 0.323323912550187 }, { 6530, 0.313059507478705, 0.323172994053855 }, { 6540, 0.312905465587415, 0.323022475478352 }, + { 6550, 0.31275197202918, 0.322872355656855 }, + { 6560, 0.312599024210234, 0.322722633424208 }, + { 6570, 0.312446619551539, 0.322573307616957 }, + { 6580, 0.312294755488698, 0.322424377073377 }, + { 6590, 0.312143429471856, 0.322275840633505 }, + { 6600, 0.311992638965609, 0.322127697139172 }, + { 6610, 0.311842381448913, 0.321979945434026 }, + { 6620, 0.311692654414993, 0.321832584363568 }, + { 6630, 0.31154345537125, 0.321685612775174 }, + { 6640, 0.311394781839175, 0.321539029518129 }, + { 6650, 0.311246631354252, 0.321392833443645 }, + { 6660, 0.311099001465878, 0.321247023404895 }, + { 6670, 0.310951889737268, 0.321101598257035 }, + { 6680, 0.31080529374537, 0.320956556857231 }, + { 6690, 0.310659211080778, 0.320811898064682 }, + { 6700, 0.310513639347644, 0.320667620740643 }, + { 6710, 0.310368576163594, 0.320523723748453 }, + { 6720, 0.310224019159638, 0.320380205953551 }, + { 6730, 0.310079965980093, 0.320237066223504 }, + { 6740, 0.309936414282491, 0.320094303428028 }, + { 6750, 0.309793361737498, 0.319951916439007 }, + { 6760, 0.309650806028835, 0.319809904130516 }, + { 6770, 0.309508744853186, 0.319668265378839 }, + { 6780, 0.309367175920125, 0.319526999062492 }, + { 6790, 0.309226096952031, 0.31938610406224 }, + { 6800, 0.309085505684005, 0.319245579261116 }, + { 6810, 0.308945399863794, 0.319105423544441 }, + { 6820, 0.308805777251706, 0.318965635799842 }, + { 6830, 0.308666635620536, 0.318826214917265 }, + { 6840, 0.308527972755481, 0.318687159788999 }, + { 6850, 0.308389786454069, 0.318548469309687 }, + { 6860, 0.308252074526075, 0.318410142376346 }, + { 6870, 0.308114834793446, 0.318272177888381 }, + { 6880, 0.307978065090227, 0.3181345747476 }, + { 6890, 0.307841763262478, 0.317997331858229 }, + { 6900, 0.307705927168207, 0.317860448126929 }, + { 6910, 0.307570554677287, 0.317723922462805 }, + { 6920, 0.307435643671386, 0.317587753777427 }, + { 6930, 0.307301192043892, 0.317451940984837 }, + { 6940, 0.307167197699838, 0.317316483001564 }, + { 6950, 0.30703365855583, 0.317181378746639 }, + { 6960, 0.306900572539974, 0.317046627141604 }, + { 6970, 0.306767937591803, 0.316912227110525 }, + { 6980, 0.306635751662207, 0.316778177580004 }, + { 6990, 0.306504012713361, 0.316644477479192 }, + { 7000, 0.306372718718652, 0.316511125739794 }, + { 7010, 0.306241867662613, 0.316378121296087 }, + { 7020, 0.306111457540851, 0.316245463084923 }, + { 7030, 0.305981486359977, 0.316113150045747 }, + { 7040, 0.305851952137536, 0.315981181120599 }, + { 7050, 0.305722852901944, 0.315849555254126 }, + { 7060, 0.305594186692414, 0.315718271393593 }, + { 7070, 0.305465951558892, 0.315587328488887 }, + { 7080, 0.305338145561988, 0.315456725492532 }, + { 7090, 0.305210766772912, 0.315326461359691 }, + { 7100, 0.305083813273404, 0.315196535048174 }, + { 7110, 0.304957283155673, 0.315066945518451 }, + { 7120, 0.304831174522328, 0.314937691733654 }, + { 7130, 0.304705485486314, 0.314808772659583 }, + { 7140, 0.304580214170851, 0.31468018726472 }, + { 7150, 0.304455358709365, 0.314551934520226 }, + { 7160, 0.304330917245426, 0.314424013399953 }, + { 7170, 0.304206887932689, 0.314296422880449 }, + { 7180, 0.304083268934824, 0.314169161940962 }, + { 7190, 0.303960058425462, 0.314042229563446 }, + { 7200, 0.303837254588126, 0.313915624732567 }, + { 7210, 0.303714855616174, 0.313789346435707 }, + { 7220, 0.303592859712737, 0.313663393662969 }, + { 7230, 0.303471265090658, 0.313537765407179 }, + { 7240, 0.303350069972432, 0.313412460663896 }, + { 7250, 0.303229272590146, 0.313287478431408 }, + { 7260, 0.30310887118542, 0.313162817710744 }, + { 7270, 0.302988864009348, 0.313038477505671 }, + { 7280, 0.30286924932244, 0.312914456822699 }, + { 7290, 0.302750025394565, 0.312790754671087 }, + { 7300, 0.302631190504886, 0.31266737006284 }, + { 7310, 0.302512742941815, 0.31254430201272 }, + { 7320, 0.302394681002945, 0.312421549538238 }, + { 7330, 0.302277002994998, 0.312299111659668 }, + { 7340, 0.302159707233771, 0.312176987400037 }, + { 7350, 0.302042792044074, 0.312055175785137 }, + { 7360, 0.30192625575968, 0.31193367584352 }, + { 7370, 0.301810096723269, 0.311812486606503 }, + { 7380, 0.30169431328637, 0.311691607108169 }, + { 7390, 0.301578903809311, 0.311571036385366 }, + { 7400, 0.301463866661161, 0.31145077347771 }, + { 7410, 0.301349200219681, 0.311330817427585 }, + { 7420, 0.301234902871264, 0.311211167280144 }, + { 7430, 0.301120973010891, 0.31109182208331 }, + { 7440, 0.30100740904207, 0.310972780887773 }, + { 7450, 0.300894209376788, 0.310854042746996 }, + { 7460, 0.300781372435461, 0.310735606717209 }, + { 7470, 0.300668896646876, 0.310617471857414 }, + { 7480, 0.300556780448148, 0.31049963722938 }, + { 7490, 0.300445022284661, 0.310382101897646 }, + { 7500, 0.300333620610026, 0.310264864929518 }, + { 7510, 0.300222573886023, 0.310147925395073 }, + { 7520, 0.300111880582555, 0.310031282367149 }, + { 7530, 0.300001539177601, 0.309914934921353 }, + { 7540, 0.299891548157161, 0.309798882136056 }, + { 7550, 0.299781906015211, 0.309683123092391 }, + { 7560, 0.299672611253656, 0.309567656874254 }, + { 7570, 0.299563662382277, 0.3094524825683 }, + { 7580, 0.299455057918686, 0.309337599263943 }, + { 7590, 0.299346796388279, 0.309223006053353 }, + { 7600, 0.299238876324188, 0.309108702031455 }, + { 7610, 0.299131296267236, 0.308994686295927 }, + { 7620, 0.299024054765886, 0.308880957947196 }, + { 7630, 0.298917150376198, 0.30876751608844 }, + { 7640, 0.298810581661782, 0.308654359825579 }, + { 7650, 0.298704347193756, 0.308541488267281 }, + { 7660, 0.298598445550693, 0.30842890052495 }, + { 7670, 0.298492875318583, 0.308316595712732 }, + { 7680, 0.298387635090787, 0.308204572947506 }, + { 7690, 0.298282723467988, 0.308092831348884 }, + { 7700, 0.298178139058152, 0.307981370039207 }, + { 7710, 0.298073880476482, 0.307870188143544 }, + { 7720, 0.297969946345376, 0.307759284789684 }, + { 7730, 0.29786633529438, 0.307648659108138 }, + { 7740, 0.297763045960149, 0.307538310232133 }, + { 7750, 0.297660076986403, 0.307428237297609 }, + { 7760, 0.297557427023885, 0.307318439443216 }, + { 7770, 0.297455094730317, 0.307208915810307 }, + { 7780, 0.29735307877036, 0.307099665542941 }, + { 7790, 0.297251377815571, 0.306990687787871 }, + { 7800, 0.297149990544364, 0.306881981694548 }, + { 7810, 0.297048915641968, 0.306773546415111 }, + { 7820, 0.296948151800384, 0.306665381104387 }, + { 7830, 0.296847697718348, 0.306557484919884 }, + { 7840, 0.296747552101289, 0.306449857021788 }, + { 7850, 0.296647713661287, 0.306342496572958 }, + { 7860, 0.296548181117039, 0.306235402738925 }, + { 7870, 0.296448953193814, 0.306128574687882 }, + { 7880, 0.296350028623417, 0.306022011590684 }, + { 7890, 0.296251406144149, 0.305915712620842 }, + { 7900, 0.296153084500768, 0.305809676954518 }, + { 7910, 0.29605506244445, 0.305703903770521 }, + { 7920, 0.295957338732757, 0.3055983922503 }, + { 7930, 0.295859912129586, 0.305493141577943 }, + { 7940, 0.295762781405147, 0.305388150940171 }, + { 7950, 0.295665945335915, 0.305283419526329 }, + { 7960, 0.295569402704596, 0.305178946528389 }, + { 7970, 0.295473152300089, 0.305074731140935 }, + { 7980, 0.295377192917454, 0.304970772561169 }, + { 7990, 0.295281523357868, 0.304867069988894 }, + { 8000, 0.295186142428596, 0.304763622626521 }, + { 8010, 0.29509104894295, 0.304660429679051 }, + { 8020, 0.294996241720257, 0.304557490354083 }, + { 8030, 0.29490171958582, 0.304454803861798 }, + { 8040, 0.294807481370887, 0.304352369414959 }, + { 8050, 0.294713525912612, 0.304250186228902 }, + { 8060, 0.294619852054023, 0.304148253521536 }, + { 8070, 0.294526458643984, 0.304046570513333 }, + { 8080, 0.294433344537166, 0.303945136427322 }, + { 8090, 0.294340508594008, 0.303843950489089 }, + { 8100, 0.294247949680687, 0.303743011926761 }, + { 8110, 0.294155666669081, 0.303642319971013 }, + { 8120, 0.294063658436738, 0.303541873855053 }, + { 8130, 0.293971923866841, 0.303441672814619 }, + { 8140, 0.293880461848177, 0.303341716087973 }, + { 8150, 0.293789271275103, 0.303242002915899 }, + { 8160, 0.293698351047513, 0.30314253254169 }, + { 8170, 0.293607700070806, 0.303043304211147 }, + { 8180, 0.293517317255857, 0.302944317172572 }, + { 8190, 0.293427201518978, 0.302845570676761 }, + { 8200, 0.293337351781895, 0.302747063977001 }, + { 8210, 0.293247766971707, 0.302648796329059 }, + { 8220, 0.293158446020866, 0.302550766991182 }, + { 8230, 0.293069387867134, 0.302452975224084 }, + { 8240, 0.292980591453561, 0.302355420290948 }, + { 8250, 0.29289205572845, 0.302258101457411 }, + { 8260, 0.292803779645329, 0.302161017991565 }, + { 8270, 0.292715762162918, 0.302064169163948 }, + { 8280, 0.2926280022451, 0.301967554247537 }, + { 8290, 0.292540498860893, 0.301871172517742 }, + { 8300, 0.292453250984416, 0.301775023252403 }, + { 8310, 0.292366257594866, 0.301679105731779 }, + { 8320, 0.292279517676482, 0.301583419238544 }, + { 8330, 0.292193030218519, 0.30148796305778 }, + { 8340, 0.292106794215219, 0.301392736476973 }, + { 8350, 0.292020808665784, 0.301297738786003 }, + { 8360, 0.291935072574342, 0.301202969277141 }, + { 8370, 0.291849584949925, 0.301108427245038 }, + { 8380, 0.291764344806436, 0.301014111986725 }, + { 8390, 0.291679351162625, 0.300920022801602 }, + { 8400, 0.291594603042056, 0.300826158991431 }, + { 8410, 0.291510099473085, 0.300732519860334 }, + { 8420, 0.291425839488828, 0.300639104714781 }, + { 8430, 0.291341822127138, 0.300545912863589 }, + { 8440, 0.291258046430574, 0.300452943617909 }, + { 8450, 0.291174511446374, 0.300360196291229 }, + { 8460, 0.291091216226434, 0.300267670199355 }, + { 8470, 0.291008159827273, 0.300175364660416 }, + { 8480, 0.290925341310012, 0.300083278994851 }, + { 8490, 0.290842759740348, 0.299991412525404 }, + { 8500, 0.290760414188525, 0.299899764577117 }, + { 8510, 0.290678303729309, 0.299808334477325 }, + { 8520, 0.290596427441963, 0.299717121555647 }, + { 8530, 0.290514784410223, 0.299626125143983 }, + { 8540, 0.290433373722268, 0.299535344576503 }, + { 8550, 0.290352194470698, 0.299444779189643 }, + { 8560, 0.29027124575251, 0.299354428322098 }, + { 8570, 0.290190526669069, 0.299264291314815 }, + { 8580, 0.290110036326088, 0.299174367510987 }, + { 8590, 0.290029773833599, 0.299084656256047 }, + { 8600, 0.289949738305931, 0.298995156897657 }, + { 8610, 0.289869928861685, 0.29890586878571 }, + { 8620, 0.28979034462371, 0.298816791272313 }, + { 8630, 0.28971098471908, 0.298727923711788 }, + { 8640, 0.289631848279069, 0.298639265460663 }, + { 8650, 0.289552934439125, 0.298550815877663 }, + { 8660, 0.289474242338851, 0.298462574323709 }, + { 8670, 0.289395771121979, 0.298374540161904 }, + { 8680, 0.289317519936349, 0.298286712757532 }, + { 8690, 0.289239487933881, 0.29819909147805 }, + { 8700, 0.289161674270557, 0.298111675693081 }, + { 8710, 0.289084078106396, 0.298024464774405 }, + { 8720, 0.289006698605431, 0.297937458095957 }, + { 8730, 0.288929534935688, 0.297850655033815 }, + { 8740, 0.288852586269164, 0.2977640549662 }, + { 8750, 0.2887758517818, 0.297677657273462 }, + { 8760, 0.288699330653466, 0.29759146133808 }, + { 8770, 0.288623022067933, 0.29750546654465 }, + { 8780, 0.288546925212856, 0.29741967227988 }, + { 8790, 0.288471039279747, 0.297334077932587 }, + { 8800, 0.28839536346396, 0.297248682893685 }, + { 8810, 0.288319896964663, 0.297163486556181 }, + { 8820, 0.288244638984821, 0.297078488315167 }, + { 8830, 0.288169588731173, 0.296993687567818 }, + { 8840, 0.288094745414214, 0.296909083713378 }, + { 8850, 0.288020108248168, 0.296824676153158 }, + { 8860, 0.287945676450972, 0.29674046429053 }, + { 8870, 0.287871449244258, 0.296656447530918 }, + { 8880, 0.287797425853324, 0.296572625281792 }, + { 8890, 0.287723605507121, 0.296488996952662 }, + { 8900, 0.28764998743823, 0.296405561955071 }, + { 8910, 0.287576570882842, 0.296322319702588 }, + { 8920, 0.287503355080738, 0.296239269610805 }, + { 8930, 0.287430339275271, 0.296156411097322 }, + { 8940, 0.287357522713342, 0.29607374358175 }, + { 8950, 0.287284904645384, 0.2959912664857 }, + { 8960, 0.287212484325343, 0.295908979232774 }, + { 8970, 0.287140261010655, 0.295826881248565 }, + { 8980, 0.287068233962231, 0.295744971960642 }, + { 8990, 0.286996402444435, 0.295663250798553 }, + { 9000, 0.286924765725065, 0.295581717193809 }, + { 9010, 0.286853323075337, 0.295500370579886 }, + { 9020, 0.286782073769861, 0.295419210392211 }, + { 9030, 0.28671101708663, 0.295338236068163 }, + { 9040, 0.286640152306992, 0.295257447047059 }, + { 9050, 0.28656947871564, 0.295176842770153 }, + { 9060, 0.286498995600591, 0.295096422680627 }, + { 9070, 0.286428702253164, 0.295016186223586 }, + { 9080, 0.286358597967967, 0.294936132846049 }, + { 9090, 0.286288682042877, 0.294856261996946 }, + { 9100, 0.286218953779022, 0.29477657312711 }, + { 9110, 0.286149412480764, 0.29469706568927 }, + { 9120, 0.286080057455679, 0.294617739138044 }, + { 9130, 0.286010888014543, 0.294538592929935 }, + { 9140, 0.285941903471314, 0.294459626523322 }, + { 9150, 0.285873103143111, 0.294380839378458 }, + { 9160, 0.285804486350202, 0.294302230957458 }, + { 9170, 0.285736052415981, 0.294223800724294 }, + { 9180, 0.285667800666959, 0.294145548144794 }, + { 9190, 0.285599730432738, 0.294067472686628 }, + { 9200, 0.285531841046001, 0.293989573819307 }, + { 9210, 0.285464131842494, 0.293911851014174 }, + { 9220, 0.285396602161005, 0.293834303744401 }, + { 9230, 0.285329251343354, 0.293756931484977 }, + { 9240, 0.285262078734374, 0.293679733712708 }, + { 9250, 0.28519508368189, 0.293602709906207 }, + { 9260, 0.285128265536713, 0.293525859545888 }, + { 9270, 0.285061623652614, 0.293449182113962 }, + { 9280, 0.284995157386314, 0.293372677094427 }, + { 9290, 0.284928866097465, 0.293296343973068 }, + { 9300, 0.284862749148637, 0.293220182237442 }, + { 9310, 0.284796805905298, 0.293144191376881 }, + { 9320, 0.284731035735806, 0.293068370882479 }, + { 9330, 0.284665438011384, 0.29299272024709 }, + { 9340, 0.284600012106111, 0.292917238965319 }, + { 9350, 0.284534757396907, 0.292841926533518 }, + { 9360, 0.284469673263512, 0.29276678244978 }, + { 9370, 0.284404759088479, 0.29269180621393 }, + { 9380, 0.28434001425715, 0.292616997327523 }, + { 9390, 0.28427543815765, 0.292542355293834 }, + { 9400, 0.284211030180865, 0.292467879617856 }, + { 9410, 0.284146789720432, 0.292393569806291 }, + { 9420, 0.284082716172722, 0.292319425367545 }, + { 9430, 0.284018808936825, 0.29224544581172 }, + { 9440, 0.283955067414537, 0.292171630650613 }, + { 9450, 0.283891491010347, 0.292097979397706 }, + { 9460, 0.283828079131417, 0.292024491568159 }, + { 9470, 0.283764831187574, 0.291951166678808 }, + { 9480, 0.283701746591293, 0.291878004248157 }, + { 9490, 0.283638824757684, 0.291805003796371 }, + { 9500, 0.283576065104475, 0.291732164845274 }, + { 9510, 0.283513467052003, 0.291659486918337 }, + { 9520, 0.283451030023197, 0.291586969540678 }, + { 9530, 0.283388753443564, 0.291514612239054 }, + { 9540, 0.283326636741177, 0.291442414541852 }, + { 9550, 0.283264679346662, 0.291370375979089 }, + { 9560, 0.283202880693181, 0.291298496082403 }, + { 9570, 0.283141240216422, 0.291226774385047 }, + { 9580, 0.283079757354586, 0.291155210421883 }, + { 9590, 0.28301843154837, 0.291083803729378 }, + { 9600, 0.282957262240958, 0.291012553845598 }, + { 9610, 0.282896248878006, 0.290941460310199 }, + { 9620, 0.282835390907627, 0.290870522664427 }, + { 9630, 0.282774687780384, 0.290799740451108 }, + { 9640, 0.282714138949271, 0.290729113214642 }, + { 9650, 0.282653743869704, 0.290658640501001 }, + { 9660, 0.282593501999504, 0.29058832185772 }, + { 9670, 0.282533412798892, 0.290518156833893 }, + { 9680, 0.282473475730468, 0.290448144980167 }, + { 9690, 0.282413690259205, 0.290378285848737 }, + { 9700, 0.282354055852432, 0.290308578993338 }, + { 9710, 0.282294571979826, 0.290239023969243 }, + { 9720, 0.282235238113395, 0.290169620333256 }, + { 9730, 0.282176053727471, 0.290100367643704 }, + { 9740, 0.282117018298692, 0.290031265460436 }, + { 9750, 0.282058131305996, 0.289962313344814 }, + { 9760, 0.281999392230606, 0.289893510859708 }, + { 9770, 0.281940800556016, 0.289824857569495 }, + { 9780, 0.281882355767985, 0.289756353040044 }, + { 9790, 0.281824057354519, 0.289687996838722 }, + { 9800, 0.281765904805865, 0.289619788534379 }, + { 9810, 0.281707897614492, 0.289551727697349 }, + { 9820, 0.28165003527509, 0.28948381389944 }, + { 9830, 0.281592317284549, 0.289416046713933 }, + { 9840, 0.281534743141951, 0.289348425715574 }, + { 9850, 0.28147731234856, 0.289280950480568 }, + { 9860, 0.281420024407811, 0.289213620586576 }, + { 9870, 0.281362878825294, 0.289146435612708 }, + { 9880, 0.281305875108749, 0.289079395139519 }, + { 9890, 0.281249012768051, 0.289012498749002 }, + { 9900, 0.281192291315202, 0.288945746024584 }, + { 9910, 0.281135710264316, 0.28887913655112 }, + { 9920, 0.281079269131611, 0.288812669914892 }, + { 9930, 0.2810229674354, 0.288746345703594 }, + { 9940, 0.280966804696075, 0.288680163506339 }, + { 9950, 0.280910780436102, 0.288614122913642 }, + { 9960, 0.280854894180004, 0.288548223517426 }, + { 9970, 0.280799145454357, 0.288482464911009 }, + { 9980, 0.280743533787776, 0.288416846689099 }, + { 9990, 0.280688058710905, 0.288351368447796 }, + { 10000, 0.280632719756407, 0.288286029784579 } //@formatter:on }; @@ -1199,6 +1645,9 @@ public static double[] kelvinToXY(double kelvin) throws IndexOutOfBoundsExceptio * Convert a point in the CIE XY colour space to a colour temperature in Kelvin. * Uses McCamy's approximation as described here. + *

+ * Note that McCamy's approximation is accurate to better than 1% from 2000 K to 10000 K + * but below 2000 K the approximation error increases rapidly and exponentially. * * @param xy an array with the CIE colour XY values to be converted * @return the colour temperature in K diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/util/ColorUtilTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/util/ColorUtilTest.java index dde2def9f3c..99654ac6294 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/util/ColorUtilTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/util/ColorUtilTest.java @@ -658,20 +658,28 @@ public void rgbwToHsb2hsbToRgbw(double[] rgbw) { } /** - * Test conversion between colour temperature in Kelvin and points on the colour - * temperature locus in the CIE XY colour space + * Test conversion between colour temperature in Kelvin and points on the colour temperature locus in the CIE XY + * colour space. Specifically test the minimum and maximum limits 1000 .. 100 Mirek i.e. 1000 .. 10000 K */ @Test - void testKelvinXyConversion() { - // test minimum and maximum limits 500..153 Mirek i.e. 2000..6536 Kelvin - assertThrows(IndexOutOfBoundsException.class, () -> ColorUtil.kelvinToXY(1000000 / 501)); - assertDoesNotThrow(() -> ColorUtil.kelvinToXY(1000000 / 500)); - assertDoesNotThrow(() -> ColorUtil.kelvinToXY(1000000 / 153)); - assertThrows(IndexOutOfBoundsException.class, () -> ColorUtil.kelvinToXY(1000000 / 152)); - - // test round trips K => XY => K - for (double kelvin = 2000; kelvin <= 6536; kelvin += 5) { - assertEquals(kelvin, ColorUtil.xyToKelvin(ColorUtil.kelvinToXY(kelvin)), 15); + void testKelvinXyConversionLimits() { + assertThrows(IndexOutOfBoundsException.class, () -> ColorUtil.kelvinToXY(1000000 / 1001)); + assertDoesNotThrow(() -> ColorUtil.kelvinToXY(1000000 / 1000)); + assertDoesNotThrow(() -> ColorUtil.kelvinToXY(1000000 / 100)); + assertThrows(IndexOutOfBoundsException.class, () -> ColorUtil.kelvinToXY(1000000 / 99)); + } + + /** + * Test conversion between colour temperature in Kelvin and points on the colour temperature locus in the CIE XY + * colour space. Specifically test round trip conversions K => XY => K + *

+ * Note that McCamy's approximation is accurate to better than 1% from 2000 K to 10000 K but below 2000 K the + * approximation error increases rapidly and exponentially. So we exclude those low values from the tests. + */ + @Test + void testKelvinXyRoundTrip() { + for (double kelvin = 2000; kelvin <= 10000; kelvin += 5) { + assertEquals(kelvin, ColorUtil.xyToKelvin(ColorUtil.kelvinToXY(kelvin)), kelvin / 100); } } } From 2ac5e2f8befa6f9aea438a7f2bf349935068088c Mon Sep 17 00:00:00 2001 From: AndrewFG Date: Mon, 28 Oct 2024 09:28:46 +0000 Subject: [PATCH 2/3] Adopt reviewer suggestion Signed-off-by: AndrewFG --- .../org/openhab/core/util/ColorUtilTest.java | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/util/ColorUtilTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/util/ColorUtilTest.java index 99654ac6294..074a1639ad0 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/util/ColorUtilTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/util/ColorUtilTest.java @@ -389,7 +389,7 @@ public Stream provideArguments(@Nullable ExtensionContext c */ private static Stream allHSB() { List result = new ArrayList<>(); - final double step = 5.0; + final double step = 17.0; for (double h = 0; h < 360; h = h + step) { for (double s = 0; s <= 100; s = s + step) { for (double b = 0; b <= 100; b = b + step) { @@ -435,7 +435,7 @@ private static Stream allXY() { */ private static Stream allRGBW() { List result = new ArrayList<>(); - final double step = 5.0; + final double step = 17.0; for (double r = 0; r <= 100; r = r + step) { for (double g = 0; g <= 100; g = g + step) { for (double b = 0; b <= 100; b = b + step) { @@ -448,6 +448,21 @@ private static Stream allRGBW() { return result.stream(); } + /* + * Return an extended stream of Kelvin color temperature values. + *

+ * Note that McCamy's approximation is accurate to better than 1% from 2000 K to 10000 K but below 2000 K the + * approximation error increases rapidly and exponentially. So we exclude those low values from the tests. + */ + private static Stream allKelvin() { + List result = new ArrayList<>(); + final double step = 5.0; + for (double kelvin = 2000; kelvin <= 10000; kelvin = kelvin + step) { + result.add(Arguments.of(kelvin)); + } + return result.stream(); + } + /* Helper functions */ /** @@ -672,14 +687,10 @@ void testKelvinXyConversionLimits() { /** * Test conversion between colour temperature in Kelvin and points on the colour temperature locus in the CIE XY * colour space. Specifically test round trip conversions K => XY => K - *

- * Note that McCamy's approximation is accurate to better than 1% from 2000 K to 10000 K but below 2000 K the - * approximation error increases rapidly and exponentially. So we exclude those low values from the tests. */ - @Test - void testKelvinXyRoundTrip() { - for (double kelvin = 2000; kelvin <= 10000; kelvin += 5) { - assertEquals(kelvin, ColorUtil.xyToKelvin(ColorUtil.kelvinToXY(kelvin)), kelvin / 100); - } + @ParameterizedTest + @MethodSource("allKelvin") + public void testKelvinXyRoundTrip(double kelvin) { + assertEquals(kelvin, ColorUtil.xyToKelvin(ColorUtil.kelvinToXY(kelvin)), kelvin / 100); } } From aa8a240ba8508e83e0709fb528097cd9c184f3bf Mon Sep 17 00:00:00 2001 From: AndrewFG Date: Mon, 28 Oct 2024 23:46:31 +0000 Subject: [PATCH 3/3] Adopt reviewer suggestions Signed-off-by: AndrewFG --- .../src/test/java/org/openhab/core/util/ColorUtilTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/util/ColorUtilTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/util/ColorUtilTest.java index 074a1639ad0..aba78da5235 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/util/ColorUtilTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/util/ColorUtilTest.java @@ -389,7 +389,7 @@ public Stream provideArguments(@Nullable ExtensionContext c */ private static Stream allHSB() { List result = new ArrayList<>(); - final double step = 17.0; + final double step = 20.0; for (double h = 0; h < 360; h = h + step) { for (double s = 0; s <= 100; s = s + step) { for (double b = 0; b <= 100; b = b + step) { @@ -435,7 +435,7 @@ private static Stream allXY() { */ private static Stream allRGBW() { List result = new ArrayList<>(); - final double step = 17.0; + final double step = 20.0; for (double r = 0; r <= 100; r = r + step) { for (double g = 0; g <= 100; g = g + step) { for (double b = 0; b <= 100; b = b + step) {