Plan 9 from Bell Labs’s /usr/web/sources/contrib/pdt/sky/cmd/skywatch/util.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <thread.h>
#include <bio.h>
#include <draw.h>

#include "debug.h"
#include "lex.h"
#include "sky.h"
#include "gfx.h"

#include "dat.h"
#include "fns.h"

double gamma(double);
double igamma(double);

double
runeatof(Rune *s)
{
	char cs[Ltoksize+1], *c;
	int i;

	for(i=0, c=cs; i<Ltoksize && *s; i++)
		*c++ = *s++;
	*c = '\0';

	return atof(cs);
}

Rune*
runestrtok(Rune *s, Rune *b)
{
	static Rune *saved;
	Rune *sc, *bc;

	if(s == 0) s = saved;

	sc = s;
	while(*sc){
		for(bc=b; *bc; bc++) if(*sc == *bc){
			*sc++ = L'\0';
			saved = sc;
			return s;
		}
		sc++;
	}
	saved = L"";
	return s;
}

int
utf8enc(Rune *s, char *b, int n)
{
	int l;

	while(n && *s){
		l = runelen(*s);
		if(l > n) return -1;
		runetochar(b, s);
		b += l;
		n -= l;
	}
	if(n) *b='\0';
	return n;
}

void
bvmag2rgbsz(double bv, double vmag, uchar *r, uchar *g, uchar *b, int *size)
{
	double t, v, fx;

	/* Ballesteros's black body temperature formula */
	t = 4600*(1.0/(0.92*bv+1.7) + 1.0/(0.92*bv+0.62));

	/* Planckian locus -- cubic spline approximation */
/*
	t = t < 1667 ? 1667 : t > 25000 ? 25000 : t;
	xc = t < 4000
		? 0.179910 + (8.776956e2 + (-2.343589e5 + (-2.661239e8)/t)/t)/t	
		: 0.240390 + (2.226347e2 + (2.1070379e6 + (-3.0258469e9)/t)/t)/t;

	yc = t < 2222
		? -0.20219683 + (2.18555832 + (-1.34811020 + (-1.1063814)*xc)*xc)*xc
		: t < 4000
		? -0.16748867 + (2.09137015 + (-1.37418593 + (-0.9549476)*xc)*xc)*xc
		: -0.37001483 + (3.75112997 + (-5.87338670 + (3.0817580)*xc)*xc)*xc;
*/

	/* from Mitchell Charity <http://www.vendian.org/mncharity/dir3/blackbody/> */
	t = t < 1000 ? 1000 : t > 40000 ? 40000 : t;
	switch((int)(t/100)){
	case 10: *r=255; *g=56; *b=0; break;
	case 11: *r=255; *g=71; *b=0; break;
	case 12: *r=255; *g=83; *b=0; break;
	case 13: *r=255; *g=93; *b=0; break;
	case 14: *r=255; *g=101; *b=0; break;
	case 15: *r=255; *g=109; *b=0; break;
	case 16: *r=255; *g=115; *b=0; break;
	case 17: *r=255; *g=121; *b=0; break;
	case 18: *r=255; *g=126; *b=0; break;
	case 19: *r=255; *g=131; *b=0; break;
	case 20: *r=255; *g=137; *b=18; break;
	case 21: *r=255; *g=142; *b=33; break;
	case 22: *r=255; *g=147; *b=44; break;
	case 23: *r=255; *g=152; *b=54; break;
	case 24: *r=255; *g=157; *b=63; break;
	case 25: *r=255; *g=161; *b=72; break;
	case 26: *r=255; *g=165; *b=79; break;
	case 27: *r=255; *g=169; *b=87; break;
	case 28: *r=255; *g=173; *b=94; break;
	case 29: *r=255; *g=177; *b=101; break;
	case 30: *r=255; *g=180; *b=107; break;
	case 31: *r=255; *g=184; *b=114; break;
	case 32: *r=255; *g=187; *b=120; break;
	case 33: *r=255; *g=190; *b=126; break;
	case 34: *r=255; *g=193; *b=132; break;
	case 35: *r=255; *g=196; *b=137; break;
	case 36: *r=255; *g=199; *b=143; break;
	case 37: *r=255; *g=201; *b=148; break;
	case 38: *r=255; *g=204; *b=153; break;
	case 39: *r=255; *g=206; *b=159; break;
	case 40: *r=255; *g=209; *b=163; break;
	case 41: *r=255; *g=211; *b=168; break;
	case 42: *r=255; *g=213; *b=173; break;
	case 43: *r=255; *g=215; *b=177; break;
	case 44: *r=255; *g=217; *b=182; break;
	case 45: *r=255; *g=219; *b=186; break;
	case 46: *r=255; *g=221; *b=190; break;
	case 47: *r=255; *g=223; *b=194; break;
	case 48: *r=255; *g=225; *b=198; break;
	case 49: *r=255; *g=227; *b=202; break;
	case 50: *r=255; *g=228; *b=206; break;
	case 51: *r=255; *g=230; *b=210; break;
	case 52: *r=255; *g=232; *b=213; break;
	case 53: *r=255; *g=233; *b=217; break;
	case 54: *r=255; *g=235; *b=220; break;
	case 55: *r=255; *g=236; *b=224; break;
	case 56: *r=255; *g=238; *b=227; break;
	case 57: *r=255; *g=239; *b=230; break;
	case 58: *r=255; *g=240; *b=233; break;
	case 59: *r=255; *g=242; *b=236; break;
	case 60: *r=255; *g=243; *b=239; break;
	case 61: *r=255; *g=244; *b=242; break;
	case 62: *r=255; *g=245; *b=245; break;
	case 63: *r=255; *g=246; *b=248; break;
	case 64: *r=255; *g=248; *b=251; break;
	case 65: *r=255; *g=249; *b=253; break;
	case 66: *r=254; *g=249; *b=255; break;
	case 67: *r=252; *g=247; *b=255; break;
	case 68: *r=249; *g=246; *b=255; break;
	case 69: *r=247; *g=245; *b=255; break;
	case 70: *r=245; *g=243; *b=255; break;
	case 71: *r=243; *g=242; *b=255; break;
	case 72: *r=240; *g=241; *b=255; break;
	case 73: *r=239; *g=240; *b=255; break;
	case 74: *r=237; *g=239; *b=255; break;
	case 75: *r=235; *g=238; *b=255; break;
	case 76: *r=233; *g=237; *b=255; break;
	case 77: *r=231; *g=236; *b=255; break;
	case 78: *r=230; *g=235; *b=255; break;
	case 79: *r=228; *g=234; *b=255; break;
	case 80: *r=227; *g=233; *b=255; break;
	case 81: *r=225; *g=232; *b=255; break;
	case 82: *r=224; *g=231; *b=255; break;
	case 83: *r=222; *g=230; *b=255; break;
	case 84: *r=221; *g=230; *b=255; break;
	case 85: *r=220; *g=229; *b=255; break;
	case 86: *r=218; *g=228; *b=255; break;
	case 87: *r=217; *g=227; *b=255; break;
	case 88: *r=216; *g=227; *b=255; break;
	case 89: *r=215; *g=226; *b=255; break;
	case 90: *r=214; *g=225; *b=255; break;
	case 91: *r=212; *g=225; *b=255; break;
	case 92: *r=211; *g=224; *b=255; break;
	case 93: *r=210; *g=223; *b=255; break;
	case 94: *r=209; *g=223; *b=255; break;
	case 95: *r=208; *g=222; *b=255; break;
	case 96: *r=207; *g=221; *b=255; break;
	case 97: *r=207; *g=221; *b=255; break;
	case 98: *r=206; *g=220; *b=255; break;
	case 99: *r=205; *g=220; *b=255; break;
	case 100: *r=204; *g=219; *b=255; break;
	case 101: *r=203; *g=219; *b=255; break;
	case 102: *r=202; *g=218; *b=255; break;
	case 103: *r=201; *g=218; *b=255; break;
	case 104: *r=201; *g=217; *b=255; break;
	case 105: *r=200; *g=217; *b=255; break;
	case 106: *r=199; *g=216; *b=255; break;
	case 107: *r=199; *g=216; *b=255; break;
	case 108: *r=198; *g=216; *b=255; break;
	case 109: *r=197; *g=215; *b=255; break;
	case 110: *r=196; *g=215; *b=255; break;
	case 111: *r=196; *g=214; *b=255; break;
	case 112: *r=195; *g=214; *b=255; break;
	case 113: *r=195; *g=214; *b=255; break;
	case 114: *r=194; *g=213; *b=255; break;
	case 115: *r=193; *g=213; *b=255; break;
	case 116: *r=193; *g=212; *b=255; break;
	case 117: *r=192; *g=212; *b=255; break;
	case 118: *r=192; *g=212; *b=255; break;
	case 119: *r=191; *g=211; *b=255; break;
	case 120: *r=191; *g=211; *b=255; break;
	case 121: *r=190; *g=211; *b=255; break;
	case 122: *r=190; *g=210; *b=255; break;
	case 123: *r=189; *g=210; *b=255; break;
	case 124: *r=189; *g=210; *b=255; break;
	case 125: *r=188; *g=210; *b=255; break;
	case 126: *r=188; *g=209; *b=255; break;
	case 127: *r=187; *g=209; *b=255; break;
	case 128: *r=187; *g=209; *b=255; break;
	case 129: *r=186; *g=208; *b=255; break;
	case 130: *r=186; *g=208; *b=255; break;
	case 131: *r=185; *g=208; *b=255; break;
	case 132: *r=185; *g=208; *b=255; break;
	case 133: *r=185; *g=207; *b=255; break;
	case 134: *r=184; *g=207; *b=255; break;
	case 135: *r=184; *g=207; *b=255; break;
	case 136: *r=183; *g=207; *b=255; break;
	case 137: *r=183; *g=206; *b=255; break;
	case 138: *r=183; *g=206; *b=255; break;
	case 139: *r=182; *g=206; *b=255; break;
	case 140: *r=182; *g=206; *b=255; break;
	case 141: *r=182; *g=205; *b=255; break;
	case 142: *r=181; *g=205; *b=255; break;
	case 143: *r=181; *g=205; *b=255; break;
	case 144: *r=181; *g=205; *b=255; break;
	case 145: *r=180; *g=205; *b=255; break;
	case 146: *r=180; *g=204; *b=255; break;
	case 147: *r=180; *g=204; *b=255; break;
	case 148: *r=179; *g=204; *b=255; break;
	case 149: *r=179; *g=204; *b=255; break;
	case 150: *r=179; *g=204; *b=255; break;
	case 151: *r=178; *g=203; *b=255; break;
	case 152: *r=178; *g=203; *b=255; break;
	case 153: *r=178; *g=203; *b=255; break;
	case 154: *r=178; *g=203; *b=255; break;
	case 155: *r=177; *g=203; *b=255; break;
	case 156: *r=177; *g=202; *b=255; break;
	case 157: *r=177; *g=202; *b=255; break;
	case 158: *r=177; *g=202; *b=255; break;
	case 159: *r=176; *g=202; *b=255; break;
	case 160: *r=176; *g=202; *b=255; break;
	case 161: *r=176; *g=202; *b=255; break;
	case 162: *r=175; *g=201; *b=255; break;
	case 163: *r=175; *g=201; *b=255; break;
	case 164: *r=175; *g=201; *b=255; break;
	case 165: *r=175; *g=201; *b=255; break;
	case 166: *r=175; *g=201; *b=255; break;
	case 167: *r=174; *g=201; *b=255; break;
	case 168: *r=174; *g=201; *b=255; break;
	case 169: *r=174; *g=200; *b=255; break;
	case 170: *r=174; *g=200; *b=255; break;
	case 171: *r=173; *g=200; *b=255; break;
	case 172: *r=173; *g=200; *b=255; break;
	case 173: *r=173; *g=200; *b=255; break;
	case 174: *r=173; *g=200; *b=255; break;
	case 175: *r=173; *g=200; *b=255; break;
	case 176: *r=172; *g=199; *b=255; break;
	case 177: *r=172; *g=199; *b=255; break;
	case 178: *r=172; *g=199; *b=255; break;
	case 179: *r=172; *g=199; *b=255; break;
	case 180: *r=172; *g=199; *b=255; break;
	case 181: *r=171; *g=199; *b=255; break;
	case 182: *r=171; *g=199; *b=255; break;
	case 183: *r=171; *g=199; *b=255; break;
	case 184: *r=171; *g=198; *b=255; break;
	case 185: *r=171; *g=198; *b=255; break;
	case 186: *r=170; *g=198; *b=255; break;
	case 187: *r=170; *g=198; *b=255; break;
	case 188: *r=170; *g=198; *b=255; break;
	case 189: *r=170; *g=198; *b=255; break;
	case 190: *r=170; *g=198; *b=255; break;
	case 191: *r=170; *g=198; *b=255; break;
	case 192: *r=169; *g=198; *b=255; break;
	case 193: *r=169; *g=197; *b=255; break;
	case 194: *r=169; *g=197; *b=255; break;
	case 195: *r=169; *g=197; *b=255; break;
	case 196: *r=169; *g=197; *b=255; break;
	case 197: *r=169; *g=197; *b=255; break;
	case 198: *r=169; *g=197; *b=255; break;
	case 199: *r=168; *g=197; *b=255; break;
	case 200: *r=168; *g=197; *b=255; break;
	case 201: *r=168; *g=197; *b=255; break;
	case 202: *r=168; *g=197; *b=255; break;
	case 203: *r=168; *g=196; *b=255; break;
	case 204: *r=168; *g=196; *b=255; break;
	case 205: *r=168; *g=196; *b=255; break;
	case 206: *r=167; *g=196; *b=255; break;
	case 207: *r=167; *g=196; *b=255; break;
	case 208: *r=167; *g=196; *b=255; break;
	case 209: *r=167; *g=196; *b=255; break;
	case 210: *r=167; *g=196; *b=255; break;
	case 211: *r=167; *g=196; *b=255; break;
	case 212: *r=167; *g=196; *b=255; break;
	case 213: *r=166; *g=196; *b=255; break;
	case 214: *r=166; *g=195; *b=255; break;
	case 215: *r=166; *g=195; *b=255; break;
	case 216: *r=166; *g=195; *b=255; break;
	case 217: *r=166; *g=195; *b=255; break;
	case 218: *r=166; *g=195; *b=255; break;
	case 219: *r=166; *g=195; *b=255; break;
	case 220: *r=166; *g=195; *b=255; break;
	case 221: *r=165; *g=195; *b=255; break;
	case 222: *r=165; *g=195; *b=255; break;
	case 223: *r=165; *g=195; *b=255; break;
	case 224: *r=165; *g=195; *b=255; break;
	case 225: *r=165; *g=195; *b=255; break;
	case 226: *r=165; *g=195; *b=255; break;
	case 227: *r=165; *g=194; *b=255; break;
	case 228: *r=165; *g=194; *b=255; break;
	case 229: *r=165; *g=194; *b=255; break;
	case 230: *r=164; *g=194; *b=255; break;
	case 231: *r=164; *g=194; *b=255; break;
	case 232: *r=164; *g=194; *b=255; break;
	case 233: *r=164; *g=194; *b=255; break;
	case 234: *r=164; *g=194; *b=255; break;
	case 235: *r=164; *g=194; *b=255; break;
	case 236: *r=164; *g=194; *b=255; break;
	case 237: *r=164; *g=194; *b=255; break;
	case 238: *r=164; *g=194; *b=255; break;
	case 239: *r=164; *g=194; *b=255; break;
	case 240: *r=163; *g=194; *b=255; break;
	case 241: *r=163; *g=194; *b=255; break;
	case 242: *r=163; *g=193; *b=255; break;
	case 243: *r=163; *g=193; *b=255; break;
	case 244: *r=163; *g=193; *b=255; break;
	case 245: *r=163; *g=193; *b=255; break;
	case 246: *r=163; *g=193; *b=255; break;
	case 247: *r=163; *g=193; *b=255; break;
	case 248: *r=163; *g=193; *b=255; break;
	case 249: *r=163; *g=193; *b=255; break;
	case 250: *r=163; *g=193; *b=255; break;
	case 251: *r=162; *g=193; *b=255; break;
	case 252: *r=162; *g=193; *b=255; break;
	case 253: *r=162; *g=193; *b=255; break;
	case 254: *r=162; *g=193; *b=255; break;
	case 255: *r=162; *g=193; *b=255; break;
	case 256: *r=162; *g=193; *b=255; break;
	case 257: *r=162; *g=193; *b=255; break;
	case 258: *r=162; *g=193; *b=255; break;
	case 259: *r=162; *g=192; *b=255; break;
	case 260: *r=162; *g=192; *b=255; break;
	case 261: *r=162; *g=192; *b=255; break;
	case 262: *r=162; *g=192; *b=255; break;
	case 263: *r=162; *g=192; *b=255; break;
	case 264: *r=161; *g=192; *b=255; break;
	case 265: *r=161; *g=192; *b=255; break;
	case 266: *r=161; *g=192; *b=255; break;
	case 267: *r=161; *g=192; *b=255; break;
	case 268: *r=161; *g=192; *b=255; break;
	case 269: *r=161; *g=192; *b=255; break;
	case 270: *r=161; *g=192; *b=255; break;
	case 271: *r=161; *g=192; *b=255; break;
	case 272: *r=161; *g=192; *b=255; break;
	case 273: *r=161; *g=192; *b=255; break;
	case 274: *r=161; *g=192; *b=255; break;
	case 275: *r=161; *g=192; *b=255; break;
	case 276: *r=161; *g=192; *b=255; break;
	case 277: *r=161; *g=192; *b=255; break;
	case 278: *r=160; *g=192; *b=255; break;
	case 279: *r=160; *g=192; *b=255; break;
	case 280: *r=160; *g=191; *b=255; break;
	case 281: *r=160; *g=191; *b=255; break;
	case 282: *r=160; *g=191; *b=255; break;
	case 283: *r=160; *g=191; *b=255; break;
	case 284: *r=160; *g=191; *b=255; break;
	case 285: *r=160; *g=191; *b=255; break;
	case 286: *r=160; *g=191; *b=255; break;
	case 287: *r=160; *g=191; *b=255; break;
	case 288: *r=160; *g=191; *b=255; break;
	case 289: *r=160; *g=191; *b=255; break;
	case 290: *r=160; *g=191; *b=255; break;
	case 291: *r=160; *g=191; *b=255; break;
	case 292: *r=160; *g=191; *b=255; break;
	case 293: *r=159; *g=191; *b=255; break;
	case 294: *r=159; *g=191; *b=255; break;
	case 295: *r=159; *g=191; *b=255; break;
	case 296: *r=159; *g=191; *b=255; break;
	case 297: *r=159; *g=191; *b=255; break;
	case 298: *r=159; *g=191; *b=255; break;
	case 299: *r=159; *g=191; *b=255; break;
	case 300: *r=159; *g=191; *b=255; break;
	case 301: *r=159; *g=191; *b=255; break;
	case 302: *r=159; *g=191; *b=255; break;
	case 303: *r=159; *g=191; *b=255; break;
	case 304: *r=159; *g=190; *b=255; break;
	case 305: *r=159; *g=190; *b=255; break;
	case 306: *r=159; *g=190; *b=255; break;
	case 307: *r=159; *g=190; *b=255; break;
	case 308: *r=159; *g=190; *b=255; break;
	case 309: *r=159; *g=190; *b=255; break;
	case 310: *r=159; *g=190; *b=255; break;
	case 311: *r=158; *g=190; *b=255; break;
	case 312: *r=158; *g=190; *b=255; break;
	case 313: *r=158; *g=190; *b=255; break;
	case 314: *r=158; *g=190; *b=255; break;
	case 315: *r=158; *g=190; *b=255; break;
	case 316: *r=158; *g=190; *b=255; break;
	case 317: *r=158; *g=190; *b=255; break;
	case 318: *r=158; *g=190; *b=255; break;
	case 319: *r=158; *g=190; *b=255; break;
	case 320: *r=158; *g=190; *b=255; break;
	case 321: *r=158; *g=190; *b=255; break;
	case 322: *r=158; *g=190; *b=255; break;
	case 323: *r=158; *g=190; *b=255; break;
	case 324: *r=158; *g=190; *b=255; break;
	case 325: *r=158; *g=190; *b=255; break;
	case 326: *r=158; *g=190; *b=255; break;
	case 327: *r=158; *g=190; *b=255; break;
	case 328: *r=158; *g=190; *b=255; break;
	case 329: *r=158; *g=190; *b=255; break;
	case 330: *r=158; *g=190; *b=255; break;
	case 331: *r=158; *g=190; *b=255; break;
	case 332: *r=157; *g=190; *b=255; break;
	case 333: *r=157; *g=190; *b=255; break;
	case 334: *r=157; *g=189; *b=255; break;
	case 335: *r=157; *g=189; *b=255; break;
	case 336: *r=157; *g=189; *b=255; break;
	case 337: *r=157; *g=189; *b=255; break;
	case 338: *r=157; *g=189; *b=255; break;
	case 339: *r=157; *g=189; *b=255; break;
	case 340: *r=157; *g=189; *b=255; break;
	case 341: *r=157; *g=189; *b=255; break;
	case 342: *r=157; *g=189; *b=255; break;
	case 343: *r=157; *g=189; *b=255; break;
	case 344: *r=157; *g=189; *b=255; break;
	case 345: *r=157; *g=189; *b=255; break;
	case 346: *r=157; *g=189; *b=255; break;
	case 347: *r=157; *g=189; *b=255; break;
	case 348: *r=157; *g=189; *b=255; break;
	case 349: *r=157; *g=189; *b=255; break;
	case 350: *r=157; *g=189; *b=255; break;
	case 351: *r=157; *g=189; *b=255; break;
	case 352: *r=157; *g=189; *b=255; break;
	case 353: *r=157; *g=189; *b=255; break;
	case 354: *r=157; *g=189; *b=255; break;
	case 355: *r=157; *g=189; *b=255; break;
	case 356: *r=156; *g=189; *b=255; break;
	case 357: *r=156; *g=189; *b=255; break;
	case 358: *r=156; *g=189; *b=255; break;
	case 359: *r=156; *g=189; *b=255; break;
	case 360: *r=156; *g=189; *b=255; break;
	case 361: *r=156; *g=189; *b=255; break;
	case 362: *r=156; *g=189; *b=255; break;
	case 363: *r=156; *g=189; *b=255; break;
	case 364: *r=156; *g=189; *b=255; break;
	case 365: *r=156; *g=189; *b=255; break;
	case 366: *r=156; *g=189; *b=255; break;
	case 367: *r=156; *g=189; *b=255; break;
	case 368: *r=156; *g=189; *b=255; break;
	case 369: *r=156; *g=189; *b=255; break;
	case 370: *r=156; *g=189; *b=255; break;
	case 371: *r=156; *g=189; *b=255; break;
	case 372: *r=156; *g=188; *b=255; break;
	case 373: *r=156; *g=188; *b=255; break;
	case 374: *r=156; *g=188; *b=255; break;
	case 375: *r=156; *g=188; *b=255; break;
	case 376: *r=156; *g=188; *b=255; break;
	case 377: *r=156; *g=188; *b=255; break;
	case 378: *r=156; *g=188; *b=255; break;
	case 379: *r=156; *g=188; *b=255; break;
	case 380: *r=156; *g=188; *b=255; break;
	case 381: *r=156; *g=188; *b=255; break;
	case 382: *r=156; *g=188; *b=255; break;
	case 383: *r=156; *g=188; *b=255; break;
	case 384: *r=155; *g=188; *b=255; break;
	case 385: *r=155; *g=188; *b=255; break;
	case 386: *r=155; *g=188; *b=255; break;
	case 387: *r=155; *g=188; *b=255; break;
	case 388: *r=155; *g=188; *b=255; break;
	case 389: *r=155; *g=188; *b=255; break;
	case 390: *r=155; *g=188; *b=255; break;
	case 391: *r=155; *g=188; *b=255; break;
	case 392: *r=155; *g=188; *b=255; break;
	case 393: *r=155; *g=188; *b=255; break;
	case 394: *r=155; *g=188; *b=255; break;
	case 395: *r=155; *g=188; *b=255; break;
	case 396: *r=155; *g=188; *b=255; break;
	case 397: *r=155; *g=188; *b=255; break;
	case 398: *r=155; *g=188; *b=255; break;
	case 399: *r=155; *g=188; *b=255; break;
	case 400: *r=155; *g=188; *b=255; break;
	}

	/* vmag range is -1.46..7.96 => fx in 3.837...0.00065 */
	fx = pow(10, -vmag/2.5);
	*size = fx > 1 ? sqrt(fx)-0.5 : 0;
	fx = fx>1 ? 1 : fx;
	*r = 255.0*gamma(igamma((double)(*r)/255.0) * fx);
	*g = 255.0*gamma(igamma((double)(*g)/255.0) * fx);
	*b = 255.0*gamma(igamma((double)(*b)/255.0) * fx);
}

double
gamma(double u)
{
	return u <= 0.0031308 ? 323.0*u/25.0 : (211.0*pow(u, 5.0/12.0)-11.0) / 200.0;
}

double
igamma(double u)
{
	return u <= 0.04045 ? 25.0*u/323.0 : pow((200.0*u+11.0)/211.0, 2.4);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].