home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Raytrace & Morphing / SOS-RAYTRACE.ISO / programm / source / radsrc22 / src / px / colorsca.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-19  |  1.7 KB  |  97 lines

  1. /* Copyright (c) 1987 Regents of the University of California */
  2.  
  3. #ifndef lint
  4. static char SCCSid[] = "@(#)colorscale.c 2.2 12/19/91 LBL";
  5. #endif
  6.  
  7. /*
  8.  *  colorscale.c - program to produce color pallets
  9.  *
  10.  *     9/9/87
  11.  */
  12.  
  13. #include  <stdio.h>
  14.  
  15. #include  "color.h"
  16.  
  17. int  primary = -1;
  18. double  prival = 0.0;
  19.  
  20.  
  21. main(argc, argv)
  22. int  argc;
  23. char  *argv[];
  24. {
  25.     int  i;
  26.  
  27.     for (i = 1; i < argc && argv[i][0] == '-'; i++)
  28.         switch (argv[i][1]) {
  29.         case 'r':
  30.             primary = RED;
  31.             prival = atof(argv[++i]);
  32.             break;
  33.         case 'g':
  34.             primary = GRN;
  35.             prival = atof(argv[++i]);
  36.             break;
  37.         case 'b':
  38.             primary = BLU;
  39.             prival = atof(argv[++i]);
  40.             break;
  41.         default:
  42.             goto userr;
  43.         }
  44.     if (primary < 0 || i < argc)
  45.         goto userr;
  46.     printargs(argc, argv, stdout);
  47.     printf("\n");
  48.     printf("-Y 256 +X 256\n");
  49.     colorscale();
  50.     exit(0);
  51. userr:
  52.     fprintf(stderr, "Usage: %s -r|-g|-b value\n", argv[0]);
  53.     exit(1);
  54. }
  55.  
  56.  
  57. colorscale()            /* output our color scale */
  58. {
  59.     COLOR  scanline[256];
  60.     int  j;
  61.     register int  i;
  62.  
  63.     for (j = 256-1; j >= 0; j--) {
  64.         for (i = 0; i < 256; i++)
  65.             switch (primary) {
  66.             case RED:
  67.                 setcolor(scanline[i],prival,i/256.0,j/256.0);
  68.                 break;
  69.             case GRN:
  70.                 setcolor(scanline[i],i/256.0,prival,j/256.0);
  71.                 break;
  72.             case BLU:
  73.                 setcolor(scanline[i],i/256.0,j/256.0,prival);
  74.                 break;
  75.             }
  76.         if (fwritescan(scanline, 256, stdout) < 0)
  77.             goto writerr;
  78.     }
  79.     return;
  80. writerr:
  81.     fprintf(stderr, "write error in colorscale\n");
  82.     exit(1);
  83. }
  84.  
  85.  
  86. printargs(ac, av, fp)        /* print arguments to a file */
  87. int  ac;
  88. char  **av;
  89. FILE  *fp;
  90. {
  91.     while (ac-- > 0) {
  92.         fputs(*av++, fp);
  93.         putc(' ', fp);
  94.     }
  95.     putc('\n', fp);
  96. }
  97.