00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <grass/gis.h>
00013
00014 static int add_ramp_colors (struct Colors *, DCELL, DCELL);
00015
00016
00030 int
00031 G_make_ramp_colors (struct Colors *colors, CELL min, CELL max)
00032 {
00033 G_init_colors (colors);
00034 return add_ramp_colors (colors, (DCELL) min, (DCELL) max) ;
00035 }
00036
00037 int
00038 G_make_ramp_fp_colors (struct Colors *colors, DCELL min, DCELL max)
00039 {
00040 G_init_colors (colors);
00041 return add_ramp_colors (colors,min,max) ;
00042 }
00043
00044 int
00045 G_make_color_ramp (
00046 struct Colors *colors,
00047 CELL min,
00048 CELL max
00049 )
00050 {
00051 return G_make_ramp_colors(colors,min,max);
00052 }
00053
00054 int
00055 G_add_ramp_colors (struct Colors *colors, CELL min, CELL max)
00056 {
00057 return add_ramp_colors (colors, (DCELL) min, (DCELL) max) ;
00058 }
00059
00060 static int add_ramp_colors (struct Colors *colors, DCELL min, DCELL max)
00061 {
00062 DCELL blu1, blu2, grn1, grn2, red1, red2;
00063 double delta;
00064
00065 if (max < min)
00066 return -1;
00067
00068 if (min == 1) min = 0;
00069 if (max == -1) max = 0;
00070 delta = max - min;
00071
00072 red1 = min;
00073 red2 = min + delta/3.;
00074 grn1 = red2 + 1;
00075 grn2 = min + 2.*delta/3.;
00076 blu1 = grn2 + 1;
00077 blu2 = max;
00078
00079 if (red1 <= red2)
00080 G_add_d_raster_color_rule (&red1, 0, 0, 0, &red2, 0, 0, 255, colors);
00081 if (grn1 <= grn2)
00082 G_add_d_raster_color_rule (&grn1, 0, 0, 0, &grn2, 0, 255, 0, colors);
00083 if (blu1 <= blu2)
00084 G_add_d_raster_color_rule (&blu1, 0, 0, 0, &blu2, 255, 0, 0, colors);
00085
00086 return 1;
00087 }