diff options
-rw-r--r-- | redshift | 242 | ||||
-rw-r--r-- | redshift_old | 91 | ||||
-rw-r--r-- | src/curve.py | 57 |
3 files changed, 387 insertions, 3 deletions
diff --git a/redshift b/redshift new file mode 100644 index 0000000..3f18fec --- /dev/null +++ b/redshift @@ -0,0 +1,242 @@ +1.00000000 0.18172716 0.00000000 +1.00000000 0.25503671 0.00000000 +1.00000000 0.30942099 0.00000000 +1.00000000 0.35357379 0.00000000 +1.00000000 0.39091524 0.00000000 +1.00000000 0.42322816 0.00000000 +1.00000000 0.45159884 0.00000000 +1.00000000 0.47675916 0.00000000 +1.00000000 0.49923747 0.00000000 +1.00000000 0.51943421 0.00000000 +1.00000000 0.54360078 0.08679949 +1.00000000 0.56618736 0.14065513 +1.00000000 0.58734976 0.18362641 +1.00000000 0.60724493 0.22137978 +1.00000000 0.62600248 0.25591950 +1.00000000 0.64373109 0.28819679 +1.00000000 0.66052319 0.31873863 +1.00000000 0.67645822 0.34786758 +1.00000000 0.69160518 0.37579588 +1.00000000 0.70602449 0.40267128 +1.00000000 0.71976951 0.42860152 +1.00000000 0.73288760 0.45366838 +1.00000000 0.74542112 0.47793608 +1.00000000 0.75740814 0.50145662 +1.00000000 0.76888303 0.52427322 +1.00000000 0.77987699 0.54642268 +1.00000000 0.79041843 0.56793692 +1.00000000 0.80053332 0.58884417 +1.00000000 0.81024551 0.60916971 +1.00000000 0.81957693 0.62893653 +1.00000000 0.82854786 0.64816570 +1.00000000 0.83717703 0.66687674 +1.00000000 0.84548188 0.68508786 +1.00000000 0.85347859 0.70281616 +1.00000000 0.86118227 0.72007777 +1.00000000 0.86860704 0.73688797 +1.00000000 0.87576611 0.75326132 +1.00000000 0.88267187 0.76921169 +1.00000000 0.88933596 0.78475236 +1.00000000 0.89576933 0.79989606 +1.00000000 0.90198230 0.81465502 +1.00000000 0.90963069 0.82838210 +1.00000000 0.91710889 0.84190889 +1.00000000 0.92441842 0.85523742 +1.00000000 0.93156127 0.86836903 +1.00000000 0.93853986 0.88130458 +1.00000000 0.94535695 0.89404470 +1.00000000 0.95201559 0.90658983 +1.00000000 0.95851906 0.91894041 +1.00000000 0.96487079 0.93109690 +1.00000000 0.97107439 0.94305985 +1.00000000 0.97713351 0.95482993 +1.00000000 0.98305189 0.96640795 +1.00000000 0.98883326 0.97779486 +1.00000000 0.99448139 0.98899179 +1.00000000 1.00000000 1.00000000 +0.98947904 0.99348723 1.00000000 +0.97940448 0.98722715 1.00000000 +0.96975025 0.98120637 1.00000000 +0.96049223 0.97541240 1.00000000 +0.95160805 0.96983355 1.00000000 +0.94303638 0.96443333 1.00000000 +0.93480451 0.95923080 1.00000000 +0.92689056 0.95421394 1.00000000 +0.91927697 0.94937330 1.00000000 +0.91194747 0.94470005 1.00000000 +0.90488690 0.94018594 1.00000000 +0.89808115 0.93582323 1.00000000 +0.89151710 0.93160469 1.00000000 +0.88518247 0.92752354 1.00000000 +0.87906581 0.92357340 1.00000000 +0.87315640 0.91974827 1.00000000 +0.86744421 0.91604254 1.00000000 +0.86191983 0.91245088 1.00000000 +0.85657444 0.90896831 1.00000000 +0.85139976 0.90559011 1.00000000 +0.84638799 0.90231183 1.00000000 +0.84153180 0.89912926 1.00000000 +0.83682430 0.89603843 1.00000000 +0.83225897 0.89303558 1.00000000 +0.82782969 0.89011714 1.00000000 +0.82353066 0.88727974 1.00000000 +0.81935641 0.88452017 1.00000000 +0.81530175 0.88183541 1.00000000 +0.81136180 0.87922257 1.00000000 +0.80753191 0.87667891 1.00000000 +0.80380769 0.87420182 1.00000000 +0.80018497 0.87178882 1.00000000 +0.79665980 0.86943756 1.00000000 +0.79322843 0.86714579 1.00000000 +0.78988728 0.86491137 1.00000000 +0.78663296 0.86273225 1.00000000 +0.78346225 0.86060650 1.00000000 +0.78037207 0.85853224 1.00000000 +0.77735950 0.85650771 1.00000000 +0.77442176 0.85453121 1.00000000 +0.77155617 0.85260112 1.00000000 +0.76876022 0.85071588 1.00000000 +0.76603147 0.84887402 1.00000000 +0.76336762 0.84707411 1.00000000 +0.76076645 0.84531479 1.00000000 +0.75822586 0.84359476 1.00000000 +0.75574383 0.84191277 1.00000000 +0.75331843 0.84026762 1.00000000 +0.75094780 0.83865816 1.00000000 +0.74863017 0.83708329 1.00000000 +0.74636386 0.83554194 1.00000000 +0.74414722 0.83403311 1.00000000 +0.74197871 0.83255582 1.00000000 +0.73985682 0.83110912 1.00000000 +0.73778012 0.82969211 1.00000000 +0.73574723 0.82830393 1.00000000 +0.73375683 0.82694373 1.00000000 +0.73180765 0.82561071 1.00000000 +0.72989845 0.82430410 1.00000000 +0.72802807 0.82302316 1.00000000 +0.72619537 0.82176715 1.00000000 +0.72439927 0.82053539 1.00000000 +0.72263872 0.81932722 1.00000000 +0.72091270 0.81814197 1.00000000 +0.71922025 0.81697905 1.00000000 +0.71756043 0.81583783 1.00000000 +0.71593234 0.81471775 1.00000000 +0.71433510 0.81361825 1.00000000 +0.71276788 0.81253878 1.00000000 +0.71122987 0.81147883 1.00000000 +0.70972029 0.81043789 1.00000000 +0.70823838 0.80941546 1.00000000 +0.70678342 0.80841109 1.00000000 +0.70535469 0.80742432 1.00000000 +0.70395153 0.80645469 1.00000000 +0.70257327 0.80550180 1.00000000 +0.70121928 0.80456522 1.00000000 +0.69988894 0.80364455 1.00000000 +0.69858167 0.80273941 1.00000000 +0.69729688 0.80184943 1.00000000 +0.69603402 0.80097423 1.00000000 +0.69479255 0.80011347 1.00000000 +0.69357196 0.79926681 1.00000000 +0.69237173 0.79843391 1.00000000 +0.69119138 0.79761446 1.00000000 +0.69003044 0.79680814 1.00000000 +0.68888844 0.79601466 1.00000000 +0.68776494 0.79523371 1.00000000 +0.68665951 0.79446502 1.00000000 +0.68557173 0.79370830 1.00000000 +0.68450119 0.79296330 1.00000000 +0.68344751 0.79222975 1.00000000 +0.68241029 0.79150740 1.00000000 +0.68138918 0.79079600 1.00000000 +0.68038380 0.79009531 1.00000000 +0.67939381 0.78940511 1.00000000 +0.67841888 0.78872517 1.00000000 +0.67745866 0.78805526 1.00000000 +0.67651284 0.78739518 1.00000000 +0.67558112 0.78674472 1.00000000 +0.67466317 0.78610368 1.00000000 +0.67375872 0.78547186 1.00000000 +0.67286748 0.78484907 1.00000000 +0.67198916 0.78423512 1.00000000 +0.67112350 0.78362984 1.00000000 +0.67027024 0.78303305 1.00000000 +0.66942911 0.78244457 1.00000000 +0.66859988 0.78186425 1.00000000 +0.66778228 0.78129191 1.00000000 +0.66697610 0.78072740 1.00000000 +0.66618110 0.78017057 1.00000000 +0.66539706 0.77962127 1.00000000 +0.66462376 0.77907934 1.00000000 +0.66386098 0.77854465 1.00000000 +0.66310852 0.77801705 1.00000000 +0.66236618 0.77749642 1.00000000 +0.66163375 0.77698261 1.00000000 +0.66091106 0.77647551 1.00000000 +0.66019791 0.77597498 1.00000000 +0.65949412 0.77548090 1.00000000 +0.65879952 0.77499315 1.00000000 +0.65811392 0.77451161 1.00000000 +0.65743716 0.77403618 1.00000000 +0.65676908 0.77356673 1.00000000 +0.65610952 0.77310316 1.00000000 +0.65545831 0.77264537 1.00000000 +0.65481530 0.77219324 1.00000000 +0.65418036 0.77174669 1.00000000 +0.65355332 0.77130560 1.00000000 +0.65293404 0.77086988 1.00000000 +0.65232240 0.77043944 1.00000000 +0.65171824 0.77001419 1.00000000 +0.65112144 0.76959404 1.00000000 +0.65053187 0.76917889 1.00000000 +0.64994941 0.76876866 1.00000000 +0.64937392 0.76836326 1.00000000 +0.64880528 0.76796263 1.00000000 +0.64824339 0.76756666 1.00000000 +0.64768812 0.76717529 1.00000000 +0.64713935 0.76678844 1.00000000 +0.64659699 0.76640603 1.00000000 +0.64606092 0.76602798 1.00000000 +0.64553103 0.76565424 1.00000000 +0.64500722 0.76528472 1.00000000 +0.64448939 0.76491935 1.00000000 +0.64397745 0.76455808 1.00000000 +0.64347129 0.76420082 1.00000000 +0.64297081 0.76384753 1.00000000 +0.64247594 0.76349813 1.00000000 +0.64198657 0.76315256 1.00000000 +0.64150261 0.76281076 1.00000000 +0.64102399 0.76247267 1.00000000 +0.64055061 0.76213824 1.00000000 +0.64008239 0.76180740 1.00000000 +0.63961926 0.76148010 1.00000000 +0.63916112 0.76115628 1.00000000 +0.63870790 0.76083590 1.00000000 +0.63825953 0.76051890 1.00000000 +0.63781592 0.76020522 1.00000000 +0.63737701 0.75989482 1.00000000 +0.63694273 0.75958764 1.00000000 +0.63651299 0.75928365 1.00000000 +0.63608774 0.75898278 1.00000000 +0.63566691 0.75868499 1.00000000 +0.63525042 0.75839025 1.00000000 +0.63483822 0.75809849 1.00000000 +0.63443023 0.75780969 1.00000000 +0.63402641 0.75752379 1.00000000 +0.63362667 0.75724075 1.00000000 +0.63323097 0.75696053 1.00000000 +0.63283925 0.75668310 1.00000000 +0.63245144 0.75640840 1.00000000 +0.63206749 0.75613641 1.00000000 +0.63168735 0.75586707 1.00000000 +0.63131096 0.75560036 1.00000000 +0.63093826 0.75533624 1.00000000 +0.63056920 0.75507467 1.00000000 +0.63020374 0.75481562 1.00000000 +0.62984181 0.75455904 1.00000000 +0.62948337 0.75430491 1.00000000 +0.62912838 0.75405319 1.00000000 +0.62877678 0.75380385 1.00000000 +0.62842852 0.75355685 1.00000000 +0.62808356 0.75331217 1.00000000 +0.62774186 0.75306977 1.00000000 +0.62740336 0.75282962 1.00000000 diff --git a/redshift_old b/redshift_old new file mode 100644 index 0000000..9b7a236 --- /dev/null +++ b/redshift_old @@ -0,0 +1,91 @@ +1.0000 0.0425 0.0000 +1.0000 0.0668 0.0000 +1.0000 0.0911 0.0000 +1.0000 0.1149 0.0000 +1.0000 0.1380 0.0000 +1.0000 0.1604 0.0000 +1.0000 0.1819 0.0000 +1.0000 0.2024 0.0000 +1.0000 0.2220 0.0000 +1.0000 0.2406 0.0000 +1.0000 0.2630 0.0062 +1.0000 0.2868 0.0155 +1.0000 0.3102 0.0261 +1.0000 0.3334 0.0379 +1.0000 0.3562 0.0508 +1.0000 0.3787 0.0650 +1.0000 0.4008 0.0802 +1.0000 0.4227 0.0964 +1.0000 0.4442 0.1136 +1.0000 0.4652 0.1316 +1.0000 0.4859 0.1505 +1.0000 0.5062 0.1702 +1.0000 0.5262 0.1907 +1.0000 0.5458 0.2118 +1.0000 0.5650 0.2335 +1.0000 0.5839 0.2558 +1.0000 0.6023 0.2786 +1.0000 0.6204 0.3018 +1.0000 0.6382 0.3255 +1.0000 0.6557 0.3495 +1.0000 0.6727 0.3739 +1.0000 0.6894 0.3986 +1.0000 0.7058 0.4234 +1.0000 0.7218 0.4485 +1.0000 0.7375 0.4738 +1.0000 0.7529 0.4992 +1.0000 0.7679 0.5247 +1.0000 0.7826 0.5503 +1.0000 0.7970 0.5760 +1.0000 0.8111 0.6016 +1.0000 0.8250 0.6272 +1.0000 0.8384 0.6529 +1.0000 0.8517 0.6785 +1.0000 0.8647 0.7040 +1.0000 0.8773 0.7294 +1.0000 0.8897 0.7548 +1.0000 0.9019 0.7801 +1.0000 0.9137 0.8051 +1.0000 0.9254 0.8301 +1.0000 0.9367 0.8550 +1.0000 0.9478 0.8795 +1.0000 0.9587 0.9040 +1.0000 0.9694 0.9283 +1.0000 0.9798 0.9524 +1.0000 0.9900 0.9763 +1.0000 1.0000 1.0000 +0.9771 0.9867 1.0000 +0.9554 0.9740 1.0000 +0.9349 0.9618 1.0000 +0.9154 0.9500 1.0000 +0.8968 0.9389 1.0000 +0.8792 0.9282 1.0000 +0.8624 0.9179 1.0000 +0.8465 0.9080 1.0000 +0.8313 0.8986 1.0000 +0.8167 0.8895 1.0000 +0.8029 0.8808 1.0000 +0.7896 0.8724 1.0000 +0.7769 0.8643 1.0000 +0.7648 0.8565 1.0000 +0.7532 0.8490 1.0000 +0.7420 0.8418 1.0000 +0.7314 0.8348 1.0000 +0.7212 0.8281 1.0000 +0.7113 0.8216 1.0000 +0.7018 0.8153 1.0000 +0.6927 0.8092 1.0000 +0.6839 0.8032 1.0000 +0.6755 0.7975 1.0000 +0.6674 0.7921 1.0000 +0.6595 0.7867 1.0000 +0.6520 0.7816 1.0000 +0.6447 0.7765 1.0000 +0.6376 0.7717 1.0000 +0.6308 0.7670 1.0000 +0.6242 0.7623 1.0000 +0.6179 0.7579 1.0000 +0.6117 0.7536 1.0000 +0.6058 0.7493 1.0000 +0.6000 0.7453 1.0000 +0.5944 0.7414 1.0000 diff --git a/src/curve.py b/src/curve.py index 74beb41..4c05822 100644 --- a/src/curve.py +++ b/src/curve.py @@ -58,6 +58,8 @@ def series_d(temperature): ''' Calculate the colour for a blackbody temperature + Using `lambda t : divide_by_maximum(series_d(t))` as the algorithm is better than just `series_d` + @param temperature:float The blackbody temperature in kelvins, must be inside [4000, 7000] @return :(float, float, float) The red, green and blue components of the white point ''' @@ -68,7 +70,7 @@ def series_d(temperature): for (k, d) in ks: x += k * 10 ** (d * 3) / temperature ** d y = 2.870 * x - 3.000 * x ** 2 - 0.275 - return ciexy_to_srgb(x, y, 1.0) + return ciexyy_to_srgb(x, y, 1.0) def simple_whitepoint(temperature): @@ -98,7 +100,7 @@ def cmf_2deg(temperature): ''' Calculate the colour for a blackbody temperature using raw CIE 1931 2 degree CMF data with interpolation - Using `lambda t : divide_by_maximum(cmf_2deg(t))` as the colour algorithm is better than just `cmf_2deg` + Using `lambda t : divide_by_maximum(cmf_2deg(t))` as the algorithm is better than just `cmf_2deg` @param temperature:float The blackbody temperature in kelvins, clipped to [1000, 40000] @return :(float, float, float) The red, green and blue components of the white point @@ -129,7 +131,7 @@ def cmf_10deg(temperature): ''' Calculate the colour for a blackbody temperature using raw CIE 1964 10 degree CMF data with interpolation - Using `lambda t : divide_by_maximum(cmf_10deg(t))` as the colour algorithm is better than just `cmf_10deg` + Using `lambda t : divide_by_maximum(cmf_10deg(t))` as the algorithm is better than just `cmf_10deg` @param temperature:float The blackbody temperature in kelvins, clipped to [1000, 40000] @return :(float, float, float) The red, green and blue components of the white point @@ -155,6 +157,54 @@ def cmf_10deg(temperature): return ciexyy_to_srgb(x, y, 1) +redshift_cache, redshift_old_cache = None, None +def redshift(temperature, old_version = False, linear_interpolation = False): + ''' + Calculate the colour for a blackbody temperature using same data as in the program redshift + + @param temperature:float The blackbody temperature in kelvins, clipped to [1000, 25100] (100 more kelvins than in redshift) + @param old_version:bool Whether to the method used in redshift<=1.8, in which case + `temperature` is clipped to [1000, 10000] (1 more kelvin than in redshift) + @param linear_interpolation:bool Whether to interpolate one linear RGB instead of sRGB + @return :(float, float, float) The red, green and blue components of the white point + ''' + global redshift_cache, redshift_old_cache + cache = None + if not old_version: + if redshift_cache is None: + with open(DATADIR + '/redshift', 'rb') as file: + redshift_cache = file.read() + redshift_cache = redshift_cache.decode('utf-8', 'error').split('\n') + redshift_cache = filter(lambda x : not x == '', redshift_cache) + redshift_cache = [[float(x) for x in r_g_b.split(' ')] for r_g_b in redshift_cache] + cache = redshift_cache + else: + if redshift_old_cache is None: + with open(DATADIR + '/redshift_old', 'rb') as file: + redshift_old_cache = file.read() + redshift_old_cache = redshift_old_cache.decode('utf-8', 'error').split('\n') + redshift_old_cache = filter(lambda x : not x == '', redshift_old_cache) + redshift_old_cache = [[float(x) for x in r_g_b.split(' ')] for r_g_b in redshift_old_cache] + cache = redshift_old_cache + temp = min(max(1000, temperature), 10000 if old_version else 25100) + r, g, b = 1, 1, 1 + if (temp % 100) == 0: + (r, g, b) = cache[(temp - 1000) // 100] + else: + temp -= 1000 + (r1, g1, b1) = cache[temp // 100] + (r2, g2, b2) = cache[temp // 100 + 1] + temp = (temp % 100) / 100 + if linear_interpolation: + (r, g, b) = standard_to_linear(r, g, b) + r = r1 * temp + r2 * (1 - temp) + g = g1 * temp + g2 * (1 - temp) + b = b1 * temp + b2 * (1 - temp) + if linear_interpolation: + (r, g, b) = linear_to_standard(r, g, b) + return (r, g, b) + + def temperature(temperature, algorithm): ''' @@ -166,6 +216,7 @@ def temperature(temperature, algorithm): if temperature == 6500: return (r, g, b) = algorithm(temperature) + print(r, g, b) rgb_brightness(r, g, b) |