[net.sources] Graphics source in C: hsalgs/hueload.c

ken@turtleva.UUCP (Ken Turkowski) (12/16/83)

echo x - hsalgs/hueload.c
cat >hsalgs/hueload.c <<'!Funky!Stuff!'
/* load pallette with hue ramps for plyzsort output */

#include <stdio.h>

main()
{   short red[1024],grn[1024],blu[1024],i,j,k,lnth;
    short quad,numhues,divisions,frmnum;
    long pallette[1024];    double hue[256][3];    char instrg[81],dvc[81];
   
    sscanf(gets(instrg),"%s %hd %hd %hd",dvc,&quad,&divisions,&frmnum);

    numhues = 0;
    while (gets(instrg) != NULL)
    {   sscanf(instrg,"%f %f %f",&hue[numhues][0],&hue[numhues][1],
				 &hue[numhues][2]);
	numhues++;
    }

    {   double pow(),exponent;
	lnth = (quad == 0)?  1023/(numhues-1) : 255/(numhues-1);
	exponent = (strcmp(dvc,"bb") == 0)?  1. : .43;  /* gamma correction
							   exponent (none for
							   Marc II "bb") */
	k = 1;
	for (i=1; i<numhues; i++)
	    for (j=0; j<lnth; j++)
	    {   red[k] = pow(hue[i][0] * j / lnth,exponent) * 255.;
	        grn[k] = pow(hue[i][1] * j / lnth,exponent) * 255.;
	        blu[k] = pow(hue[i][2] * j / lnth,exponent) * 255.;
		pallette[k] = blu[k] | (long)(grn[k] <<8) | (long)(red[k] <<16);
		k++;
	    }
	red[0] = pow(hue[0][0] * j / lnth,exponent) * 255.;
	grn[0] = pow(hue[0][1] * j / lnth,exponent) * 255.;
	blu[0] = pow(hue[0][2] * j / lnth,exponent) * 255.;
	pallette[0] = blu[0] | (long)(grn[0] << 8) | (long)(red[0] << 16);
    
    }
    if (strcmp(dvc,"fb") == 0) 
    {   fbquad(quad);
	fbpalw(pallette);
    }
    else if (strcmp(dvc,"bb") == 0)
    {   for (i=0; i<256; i++) {  red[i] *= 16;  grn[i] *= 16;  blu[i] *= 16;  }
	get_bb();
	bbpalw(red,grn,blu,0,256);
    }
    else if (strcmp(dvc,"aed") == 0)
    {   aed_init(0);
	fb_putmap(red,grn,blu);
	aed_done();
    }

}

!Funky!Stuff!