color_wave.c

Go to the documentation of this file.
00001 /**********************************************************************
00002  *
00003  *  G_make_wave_colors (colors, min, max)
00004  *
00005  *   struct Colors *colors   struct to hold colors
00006  *   CELL min,max            min,max color numbers
00007  *
00008  *  Generates color wave that is stored in the colors structure. 
00009  *
00010  **********************************************************************/
00011 
00012 #include <grass/gis.h>
00013 
00014 static int add_wave_colors (struct Colors *, DCELL, DCELL);
00015 
00016 
00030 int 
00031 G_make_wave_colors (struct Colors *colors, CELL min, CELL max)
00032 {
00033     G_init_colors (colors);
00034     return add_wave_colors  (colors,min,max) ;
00035 }
00036 
00037 int 
00038 G_make_wave_fp_colors (struct Colors *colors, DCELL min, DCELL max)
00039 {
00040     G_init_colors (colors);
00041     return add_wave_colors  (colors,min,max) ;
00042 }
00043 
00044 int 
00045 G_make_color_wave ( /* for 3.0 compatibility */
00046     struct Colors *colors,
00047     CELL min,
00048     CELL max
00049 )
00050 {
00051     return G_make_wave_colors(colors,min,max);
00052 }
00053 
00054 int 
00055 G_add_wave_colors (struct Colors *colors, CELL min, CELL max)
00056 {
00057     return add_wave_colors  (colors,(DCELL) min,(DCELL) max) ;
00058 }
00059 
00060 static int add_wave_colors (struct Colors *colors, DCELL min, DCELL max)
00061 {
00062     DCELL x1,x2,x3,x4,x5;
00063 
00064     if (max < min)
00065         return -1;
00066 
00067     if (min == 1) min = 0;
00068     if (max == -1) max = 0;
00069 
00070     x1 = (5.0*min + 1.0*max)/6.0;
00071     x2 = (4.0*min + 2.0*max)/6.0;
00072     x3 = (3.0*min + 3.0*max)/6.0;
00073     x4 = (2.0*min + 4.0*max)/6.0;
00074     x5 = (1.0*min + 5.0*max)/6.0;
00075 
00076     if (min <= x1)
00077         G_add_d_raster_color_rule (&min, 255, 85, 85, &x1, 170, 170, 0, colors);
00078     if (x1 <= x2)
00079         G_add_d_raster_color_rule (&x1, 170, 170, 0, &x2, 85, 255, 85, colors);
00080     if (x2 <= x3)
00081         G_add_d_raster_color_rule (&x2, 85, 255, 85, &x3, 0, 170, 170, colors);
00082     if (x3 <= x4)
00083         G_add_d_raster_color_rule (&x3, 0, 170, 170, &x4, 85, 85, 255, colors);
00084     if (x4 <= x5)
00085         G_add_d_raster_color_rule (&x4, 85, 85, 255, &x5, 170, 0, 170, colors);
00086     if (x5 <= max)
00087         G_add_d_raster_color_rule (&x5, 170, 0, 170, &max, 255, 85, 85, colors);
00088 
00089     return 1;
00090 }

Generated on Wed Dec 19 14:59:05 2007 for GRASS by  doxygen 1.5.4