00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "gis.h"
00025 #include <math.h>
00026
00027
00041 int G_make_histogram_eq_colors (
00042 struct Colors *colors,
00043 struct Cell_stats *statf)
00044 {
00045 long count, total;
00046 CELL prev=0,cat;
00047 double span, sum;
00048 int first;
00049 int x, grey;
00050
00051 G_init_colors (colors);
00052 G_set_null_value_color (0, 0, 0, colors);
00053
00054 total = 0;
00055
00056 G_rewind_cell_stats (statf);
00057 while (G_next_cell_stat (&cat, &count, statf))
00058 if (count > 0)
00059 total += count;
00060 if (total <= 0)
00061 return 0;
00062
00063 span = total/256.0;
00064 first = 1;
00065 grey = 0;
00066 sum = 0.0;
00067
00068 G_rewind_cell_stats (statf);
00069 while (G_next_cell_stat (&cat, &count, statf))
00070 {
00071 if (count <= 0)
00072 continue;
00073 x = (sum + (count/2.0))/span;
00074 if (x < 0) x = 0;
00075 else if (x > 255) x = 255;
00076 sum += count;
00077 if (first)
00078 {
00079 prev = cat;
00080 grey = x;
00081 first = 0;
00082 }
00083 else if (grey != x)
00084 {
00085 G_add_color_rule (prev, grey, grey, grey, cat-1, grey, grey, grey, colors);
00086 grey = x;
00087 prev = cat;
00088 }
00089 }
00090 if (!first)
00091 {
00092 G_add_color_rule (prev, grey, grey, grey, cat, grey, grey, grey, colors);
00093 }
00094
00095 return 0;
00096 }
00097
00098
00099 int G_make_histogram_log_colors (
00100 struct Colors *colors,
00101 struct Cell_stats *statf,
00102 int min, int max)
00103 {
00104 long count, total;
00105 CELL prev=0,cat;
00106 int first;
00107 int x, grey;
00108
00109 G_init_colors (colors);
00110 G_set_null_value_color (0, 0, 0, colors);
00111
00112 total = 0;
00113
00114 G_rewind_cell_stats (statf);
00115 while (G_next_cell_stat (&cat, &count, statf))
00116 if (count > 0)
00117 total += count;
00118 if (total <= 0)
00119 return 0;
00120
00121 first = 1;
00122 grey = 0;
00123
00124 G_rewind_cell_stats (statf);
00125 while (G_next_cell_stat (&cat, &count, statf))
00126 {
00127 if (count <= 0)
00128 continue;
00129
00130
00131 x = (int) ( log(cat)* 255. / log(max) );
00132
00133 if (x < 0) x = 0;
00134 else if (x > 255) x = 255;
00135 if (first)
00136 {
00137 prev = cat;
00138 grey = x;
00139 first = 0;
00140 }
00141 else if (grey != x)
00142 {
00143 G_add_color_rule (prev, grey, grey, grey, cat-1, grey, grey, grey, colors);
00144 grey = x;
00145 prev = cat;
00146 }
00147 }
00148 if (!first)
00149 {
00150 G_add_color_rule (prev, grey, grey, grey, cat, grey, grey, grey, colors);
00151 }
00152
00153 return 0;
00154 }
00155