HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/share/slsh/cmaps/mkcmap.sl
define rgb_to_cmap (r, g, b, file)
{
   variable rgb = (r << 16)|(g<<8)|b;
   variable name = path_basename_sans_extname (file);
   if (NULL != stat_file (file))
     throw IOError, sprintf ("File %s exists-- delete it if you want to overwrite", file);

   variable fp = fopen (file, "w");
   () = fputs (`% -*- slang -*-
%

$1 =
[`,
	       fp);
   _for (0, length(rgb)-1, 1)
     {
	variable i = ();
	if ((i mod 8) == 0)
	  () = fputs ("\n  ", fp);
	() = fprintf (fp, "0x%06X,", rgb[i]);
     }
   () = fprintf (fp, `
];

png_add_colormap ("%s", __tmp($1));
`,
		 name);
   () = fclose (fp);
}

#ifnfalse
require ("gslinterp");
require ("readascii");
private define convert_normalized_color (c, n)
{
   variable cx = [0:1:#length(c)];
   variable x = [0:1:#n];
   variable y = interp_linear (x, cx, c);
   return int (y*255.999);
}

define slsh_main ()
{
   variable r, g, b;
   variable file = __argv[1];
   () = readascii (file, &r, &g, &b);
   r = convert_normalized_color (r, 256);
   g = convert_normalized_color (g, 256);
   b = convert_normalized_color (b, 256);
   rgb_to_cmap (r, g, b, path_basename_sans_extname (file) + ".map");
}
#endif