color_obj.c

来自「CA仿真模型中SLEUTH模型」· C语言 代码 · 共 434 行 · 第 1/2 页

C
434
字号
/***************************************************************************************************************************************************************                           MODULE PROLOG                                   *********************************************************************************This object encapsulates the colortable structures.*************************************************************************************************************************************************************/#include <stdlib.h>#include <string.h>#include <errno.h>#include "scenario_obj.h"#include "color_obj.h"#include "landclass_obj.h"#include "memory_obj.h"#include "ugm_defines.h"#include "ugm_macros.h"#include "gdif_obj.h"char color_obj_c_sccs_id[] = "@(#)color_obj.c	1.84	12/4/00";/*****************************************************************************\*********************************************************************************                                                                           ****                      STATIC MEMORY FOR THIS OBJECT                        ****                                                                           *********************************************************************************\*****************************************************************************/static struct colortable *color_table_landuse_ptr;static struct colortable *color_table_probability_ptr;static struct colortable *color_table_growth_ptr;static struct colortable *color_table_deltatron_ptr;static struct colortable *color_table_grayscale_ptr;static int initialized = FALSE;/*****************************************************************************\*********************************************************************************                                                                           ****                        STATIC FUNCTION PROTOTYPES                         ****                                                                           *********************************************************************************\*****************************************************************************/static void color_fill ();/*************************************************************************************************************************************************************** FUNCTION NAME: color_GetColortable** PURPOSE:       returns pointer to a selected colortable** AUTHOR:        Keith Clarke** PROGRAMMER:    Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/struct colortable *  color_GetColortable (int i){  char func[] = "color_GetColortable";  struct colortable *return_ptr;  if (i == LANDUSE_COLORTABLE)  {    return_ptr = color_table_landuse_ptr;  }  else if (i == PROBABILITY_COLORTABLE)  {    return_ptr = color_table_probability_ptr;  }  else if (i == GROWTH_COLORTABLE)  {    return_ptr = color_table_growth_ptr;  }  else if (i == DELTATRON_COLORTABLE)  {    return_ptr = color_table_deltatron_ptr;  }  else if (i == GRAYSCALE_COLORTABLE)  {    return_ptr = color_table_grayscale_ptr;  }  else  {    sprintf (msg_buf, "Unknown colortable");    LOG_ERROR (msg_buf);    EXIT (1);  }  return return_ptr;}/*************************************************************************************************************************************************************** FUNCTION NAME: color_Init** PURPOSE:       main driver for initializing the colortables** AUTHOR:        Keith Clarke** PROGRAMMER:    Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/void  color_Init (){  char filename[MAX_FILENAME_LEN];  /*   *   * ALLOCATE SPACE FOR EACH COLORTABLE   *   */  color_table_landuse_ptr = (struct colortable *)    malloc (sizeof (struct colortable));  color_table_probability_ptr = (struct colortable *)    malloc (sizeof (struct colortable));  color_table_growth_ptr = (struct colortable *)    malloc (sizeof (struct colortable));  color_table_deltatron_ptr = (struct colortable *)    malloc (sizeof (struct colortable));  color_table_grayscale_ptr = (struct colortable *)    malloc (sizeof (struct colortable));  /*   *   * FILL IN COLOR VALUES   *   */  color_fill ();  /*   *   * WRITE OUT A COLOR KEY FOR EACH COLORTABLE   *   */  if (scen_GetWriteColorKeyFlag ())  {    sprintf (filename, "%skey_%s.gif",             scen_GetOutputDir (), color_table_landuse_ptr->name);    gdif_WriteColorKey (                         color_table_landuse_ptr,                         filename);    sprintf (filename, "%skey_%s.gif",             scen_GetOutputDir (), color_table_probability_ptr->name);    gdif_WriteColorKey (                         color_table_probability_ptr,                         filename);    sprintf (filename, "%skey_%s.gif",             scen_GetOutputDir (), color_table_growth_ptr->name);    gdif_WriteColorKey (                         color_table_growth_ptr,                         filename);    sprintf (filename, "%skey_%s.gif",             scen_GetOutputDir (), color_table_deltatron_ptr->name);    gdif_WriteColorKey (                         color_table_deltatron_ptr,                         filename);  }  initialized = TRUE;}/*************************************************************************************************************************************************************** FUNCTION NAME: color_fill** PURPOSE:       initializes RGB values for each colortable** AUTHOR:        Keith Clarke** PROGRAMMER:    Tommy E. Cathey of NESC (919)541-1500** CREATION DATE: 11/11/1999** DESCRIPTION:*****/static void  color_fill (){  int i;  int index;  int color_val;  strcpy (color_table_grayscale_ptr->name, "GRAYSCALE_COLORMAP");  color_table_grayscale_ptr->size = MAX_COLORS;  for (i = 0; i < MAX_COLORS; i++)  {    color_table_grayscale_ptr->color[i].red = i;    color_table_grayscale_ptr->color[i].green = i;    color_table_grayscale_ptr->color[i].blue = i;  }  strcpy (color_table_landuse_ptr->name, "LANDUSE_COLORMAP");  color_table_landuse_ptr->size = MAX_COLORS;  for (i = 0; i < MAX_COLORS; i++)  {    color_table_landuse_ptr->color[i].red = i;    color_table_landuse_ptr->color[i].green = i;    color_table_landuse_ptr->color[i].blue = i;  }  for (i = 0; i < landclass_GetNumLandclasses (); i++)  {    color_val = landclass_GetClassColor (i);    color_table_landuse_ptr->color[i].red = (color_val & RED_MASK) >> 16;    color_table_landuse_ptr->color[i].green = (color_val & GREEN_MASK) >> 8;    color_table_landuse_ptr->color[i].blue = color_val & BLUE_MASK;  }  strcpy (color_table_probability_ptr->name, "PROBABILITY_COLORMAP");  color_table_probability_ptr->size = MAX_COLORS;  for (i = 0; i < MAX_COLORS; i++)  {    color_table_probability_ptr->color[i].red = i;    color_table_probability_ptr->color[i].green = i;    color_table_probability_ptr->color[i].blue = i;  }  strcpy (color_table_deltatron_ptr->name, "DELTATRON_COLORMAP");

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?