GRASS Programmer's Manual
6.4.2(2012)
|
00001 00002 /******************************************************************** 00003 * code in this file is designed to send raster data to the graphics 00004 * driver. It handles raster->color lookup translation, as well as 00005 * loading appropriate colormaps into the driver and the sending of 00006 * raster data to the plotter. The loading of colors is designed to 00007 * never send more colors than the hardware can support - even though 00008 * the GRASS drivers will allocate virtual colormaps to pretend there are more 00009 * This code effectively disables that driver feature/mistake. 00010 * 00011 * To simply plot raster data: 00012 * 00013 * to specify if overlay mode is to be used 00014 * D_set_overlay_mode(flag) 00015 * int flag; /1=yes,0=no/ 00016 * 00017 * to select a raster color for line drawing 00018 * D_color (cat, colors) 00019 * CELL cat 00020 * struct Colors *colors; /color info/ 00021 * 00022 * D_color_of_type(raster, colors, data_type); 00023 * void *raster; 00024 * struct Colors *colors; /color info/ 00025 * RASTER_MAP_TYPE data_type; 00026 * 00027 * Note: the same Colors structure must be passed to all routines. 00028 * 00029 */ 00030 #include <stdlib.h> 00031 #include <grass/gis.h> 00032 #include <grass/display.h> 00033 #include <grass/raster.h> 00034 00035 int D__overlay_mode = 0; /* external for now, but to be fixed later */ 00036 00037 00050 int D_set_overlay_mode(int n) 00051 { 00052 D__overlay_mode = (n != 0); 00053 00054 return 0; 00055 } 00056 00057 00058 /* this routine modifies the hardware colormap 00059 * provided that we are not using fixed mode colors. 00060 * For use by programs such as d.colors 00061 * 00062 * returns: 00063 * 0 error - in fixed mode, 00064 * or cat not in min:max color range 00065 * 1 ok 00066 */ 00067 00068 int D_color(CELL cat, struct Colors *colors) 00069 { 00070 return D_c_color(cat, colors); 00071 } 00072 00073 /* select color for line drawing */ 00074 int D_c_color(CELL cat, struct Colors *colors) 00075 { 00076 return D_color_of_type(&cat, colors, CELL_TYPE); 00077 } 00078 00079 /* select color for line drawing */ 00080 00093 int D_d_color(DCELL val, struct Colors *colors) 00094 { 00095 return D_color_of_type(&val, colors, DCELL_TYPE); 00096 } 00097 00098 /* select color for line drawing */ 00099 00112 int D_f_color(FCELL val, struct Colors *colors) 00113 { 00114 return D_color_of_type(&val, colors, FCELL_TYPE); 00115 } 00116 00117 00134 int D_color_of_type(const void *raster, 00135 struct Colors *colors, RASTER_MAP_TYPE data_type) 00136 { 00137 int r, g, b; 00138 00139 G_get_raster_color(raster, &r, &g, &b, colors, data_type); 00140 R_RGB_color((unsigned char)r, (unsigned char)g, (unsigned char)b); 00141 00142 return 0; 00143 }