color_rain.c

Go to the documentation of this file.
00001 #include "gis.h"
00002 
00003 static struct
00004 {
00005     int red, grn, blu;
00006 } rules[] =
00007 {
00008   {255, 255,   0},       /* yellow */
00009     {0, 255,   0},       /* green */
00010     {0, 255, 255},       /* cyan */
00011     {0,   0, 255},       /* blue */
00012   {255,   0, 255},       /* magenta */
00013   {255,   0,   0}        /* red */
00014 };
00015 
00016 static int add_rainbow_colors (struct Colors *, DCELL, DCELL);
00017 
00018 
00034 int 
00035 G_make_rainbow_colors (struct Colors *colors, CELL min, CELL max)
00036 {
00037     G_init_colors (colors);
00038     return add_rainbow_colors (colors, (DCELL) min, (DCELL) max);
00039 }
00040 
00041 int 
00042 G_make_rainbow_fp_colors (struct Colors *colors, DCELL min, DCELL max)
00043 {
00044     G_init_colors (colors);
00045     G_mark_colors_as_fp(colors);
00046     return add_rainbow_colors (colors, min, max);
00047 }
00048 
00049 int 
00050 G_add_rainbow_colors (struct Colors *colors, CELL min, CELL max)
00051 {
00052     return add_rainbow_colors(colors, (DCELL) min, (DCELL) max);
00053 }
00054 
00055 static int add_rainbow_colors (struct Colors *colors, DCELL min, DCELL max)
00056 {
00057     double incr;
00058     int i,n;
00059     DCELL val1, val2;
00060 
00061     if (min > max) return -1;
00062 
00063 
00064 /* to generate the rainbow start with yellow (R & G)
00065  * decrease red (G)
00066  * then increase blue (G & B)
00067  * then decrease green (B)
00068  * then increase red (R & B)
00069  */
00070     n = sizeof(rules)/sizeof(*rules);
00071     incr = (max-min)/(double)(n-1);
00072 
00073     val1 = min;
00074     for (i = 1; i < n; i++)
00075     {
00076         if (i == n-1)
00077             val2 = max;
00078         else
00079             val2 = min + incr*i;
00080 
00081         G_add_d_raster_color_rule (
00082                 &val1, rules[i-1].red, rules[i-1].grn, rules[i-1].blu,
00083                 &val2, rules[i].red, rules[i].grn, rules[i].blu,
00084                 colors);
00085         val1 = val2;
00086     }
00087     return 1;
00088 }

Generated on Mon Jan 1 19:49:25 2007 for GRASS by  doxygen 1.5.1