Subject: Re: [stella] tia hue luminance From: Adam Wozniak <adam@xxxxxxxxxxxxxxxx> Date: Mon, 8 Dec 2003 18:57:12 -0800 (PST) |
On Mon, 8 Dec 2003, Eric Ball wrote: > The colors in Adam's files aren't correct by my calculations. I'll see how > quickly I can put together a revised page. Please point out the error in my code: #include <stdio.h> #include <math.h> #define PI 3.141592653587 double clip(double arg) { if (arg < 0.0) return 0.0; if (arg > 1.0) return 1.0; return arg; } double transform (double arg) { if (arg <= 0.081) return arg / 4.5; return pow ((arg + .099) / 1.099, 1.0 / .45); } int map[128]; void fillmap (void) { int i; int colu; double yp, up, vp, hue, sat; double rp, gp, bp; double r, g, b; for (i = 0; i < 128; i++) { colu = i << 1; yp = 0.09 * (double) (colu & 0x0F); hue = 180.0 - ((double) (colu / 16 - 1)) * 24.0; hue = hue * PI / 180.0; if (colu / 16 == 0) { sat = 0.0; } else { sat = 20.0 / 92.5; } up = sat * cos (hue); vp = sat * sin (hue); rp = 1.14 * vp + yp; gp = yp - .3947 * up - .5808 * vp; bp = 2.033 * up + yp; rp = clip (rp); gp = clip (gp); bp = clip (bp); r = transform (rp); g = transform (gp); b = transform (bp); map[colu >> 1] = (int) (r * 255.0); map[colu >> 1] <<= 8; map[colu >> 1] |= (int) (g * 255.0); map[colu >> 1] <<= 8; map[colu >> 1] |= (int) (b * 255.0); } } int print (int map[128], char *title) { int i, j; printf ("<B>%s<B><BR>\n", title); printf ("<TABLE>\n"); printf ("<TR><TD></TD>"); for (j = 0; j < 7; j++) { printf ("<TD>lu=%X</TD>", j); } printf ("</TR>"); for (i = 0; i < 16; i++) { printf ("<TR>\n"); printf ("<TD>col=%X</TD>", i); for (j = 0; j < 7; j++) { printf ("<TD bgcolor=#%06X align=center title=\"#%06X\">", map[i << 3 | j], map[i << 3 | j]); printf (" "); printf ("</TD>"); } printf ("</TR>\n"); } printf ("</TABLE>\n"); return 0; } int main (void) { fillmap (); printf ("<HTML><BODY>\n"); print (map, "Eric Ball"); printf ("</BODY></HTML>\n"); } -- adam@xxxxxxxxxxxxxxxx http://cuddlepuddle.org/~adam/pgp.html Will code for food. http://cuddlepuddle.org/~adam/resume.html "The dinosaurs are not around today because they did not have a space program." -- Arthur C. Clarke ---------------------------------------------------------------------------------------------- Archives (includes files) at http://www.biglist.com/lists/stella/archives/ Unsub & more at http://www.biglist.com/lists/stella/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [stella] tia hue luminance, Eric Ball | Thread | Re: [stella] tia hue luminance, Andrew Davie |
Re: [stella] tia hue luminance, Eric Ball | Date | Re: [stella] tia hue luminance, Eric Ball |
Month |