Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/bitsy/gamma.c

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


## diffname bitsy/gamma.c 2000/1231
## diff -e /dev/null /n/emeliedump/2000/1231/sys/src/9/bitsy/gamma.c
0a
#include <u.h>
#include <libc.h>
#include <stdio.h>

double	gamma = 1.6;

int
remap5(int i)
{
	double v;

	v = (double)i/31.0;
	return 31.0*pow(v, gamma);
}

int
remap6(int i)
{
	double v;

	v = (double)i/63.0;
	return 63.0*pow(v, gamma);
}

int
remap(int i)
{
	int r, g, b;

	b = i & 0x1F;
	g = (i>>5) & 0x3F;
	r = (i>>11) & 0x1F;
	return (remap5(r)<<11) | (remap6(g)<<5) | (remap5(b)<<0);
}

void
main(void)
{
	int i;

	printf("/* gamma = %.2f */\n", gamma);
	printf("ushort gamma[65536] = {\n");
	for(i=0; i<65536; i++){
		if((i%8) == 0)
			printf("\t");
		printf("0x%.4x, ", remap(i));
		if((i%8) == 7)
			printf("\n");
	}
	printf("};\n");
}
.

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].