Main Page   Compound List   File List   Compound Members   File Members  

FireExportImg.c

Go to the documentation of this file.
00001 
00025 #include "FireExportImg.h"
00026 
00027 int FireExportFireIDPng(ChHashTable * proptbl, FireYear * fyr, FireTimer * ft)  {
00028     KeyVal * png_dir, * icm_fname, * img_w, * img_h, * titl_txt, * titl_fnt, * titl_pos;    /* key/val props */
00029     GridData * gd                                       = NULL;                             /* fire year wrapper */
00030     gdFontPtr tfont                                     = gdFontTiny;                       /* title font */    
00031     EnumPosition tpos                                   = EnumURPosition;                   /* title position */
00032     char png_fname[FIRE_EXPORT_IMG_DEFAULT_FILENAME_SIZE]   = {'\0'};
00033     char title[FIRE_EXPORT_IMG_DEFAULT_TITLE_SIZE]          = {'\0'};
00034     int * red                                           = NULL;
00035     int * green                                         = NULL;
00036     int * blue                                          = NULL;
00037     int icm_size, mt = 0;   
00038         
00039     /* check args */
00040     if ( proptbl == NULL  || ChHashTableRetrieve(proptbl, GetFireProp(PROP_EXPFPDIR), (void *)&png_dir) )   {
00041         ERR_ERROR("Unable to retrieve EXPORT_FIRE_ID_PNG_DIRECTORY property. \n", ERR_EINVAL);
00042         }
00043 
00044     /* return if no export options specified */
00045     if  ( strcmp(png_dir->val, GetFireVal(VAL_NULL)) == 0)  {
00046         return ERR_SUCCESS;
00047         }
00048         
00049     /* retrieve remaining export args */
00050     if ( ChHashTableRetrieve(proptbl, GetFireProp(PROP_EXPFPICMF), (void *)&icm_fname)  
00051         ||  ChHashTableRetrieve(proptbl, GetFireProp(PROP_EXPFPWID), (void *)&img_w)
00052         ||  ChHashTableRetrieve(proptbl, GetFireProp(PROP_EXPFPHGT), (void *)&img_h)
00053         ||  ChHashTableRetrieve(proptbl, GetFireProp(PROP_EXPFPTTXT), (void *)&titl_txt)
00054         ||  ChHashTableRetrieve(proptbl, GetFireProp(PROP_EXPFPTF), (void *)&titl_fnt)
00055         ||  ChHashTableRetrieve(proptbl, GetFireProp(PROP_EXPFPTP), (void *)&titl_pos) )    {
00056         ERR_ERROR("All EXPORT_FIRE_ID_PNG* properties must be specified when exporting. \n", ERR_EINVAL);
00057         }
00058         
00059     /* generate name for output png file of format fidYYYYMMDDHHHH.png */
00060     FIRE_TIMER_GET_MILITARY_TIME(ft, mt);
00061     sprintf(png_fname, "%s\\fid%d%02d%02d%04d.png", png_dir->val, ft->sim_cur_yr, ft->sim_cur_mo, ft->sim_cur_dy, mt);          
00062     
00063     /* wrap FireYear as GridData to export */
00064     if ( (gd = InitGridDataFromIntTwoDArray(fyr->id, fyr->xllcorner, fyr->yllcorner,
00065                                                 fyr->cellsize, FIRE_YEAR_ID_UNBURNABLE)) == NULL )  {
00066         ERR_ERROR("Unable to load FireYear as GridData. \n", ERR_EINVAL);
00067         }
00068         
00069     /* retrieve index color model */
00070     if ( GridDataImgGetIndexColorModelFromFile((char *) icm_fname->val, &red, &green, &blue, &icm_size) )   {
00071         ERR_ERROR("Unable to load index color model from file. \n", ERR_EINVAL);
00072         }
00073     
00074     /* retrieve title text */
00075     if ( strcmp(titl_txt->val, GetFireVal(VAL_NULL)) == 0 ) {
00076         sprintf(title, "%d%02d%02d%04d", ft->sim_cur_yr, ft->sim_cur_mo, ft->sim_cur_dy, mt);
00077         }
00078     else    {
00079         strcpy(title, titl_txt->val);
00080         }
00081             
00082     /* retrieve title font */
00083     if ( strcmp(titl_fnt->val, GetFireVal(VAL_GIANT)) == 0 )    {
00084         tfont = gdFontGiant;
00085         }
00086     else if ( strcmp(titl_fnt->val, GetFireVal(VAL_LARGE)) == 0 )   {
00087         tfont = gdFontLarge;
00088         }
00089     else if ( strcmp(titl_fnt->val, GetFireVal(VAL_MEDBOLD)) == 0 ) {
00090         tfont = gdFontMediumBold;
00091         }
00092     else if ( strcmp(titl_fnt->val, GetFireVal(VAL_SMALL)) == 0 )   {
00093         tfont = gdFontSmall;
00094         }   
00095     else    {       /* default */
00096         tfont = gdFontTiny;
00097         }
00098 
00099     /* retrieve title position */
00100     if ( strcmp(titl_pos->val, GetFireVal(VAL_UL)) == 0 )   {
00101         tpos = EnumULPosition;
00102         }
00103     else if ( strcmp(titl_pos->val, GetFireVal(VAL_LL)) == 0 )  {
00104         tpos = EnumLLPosition;
00105         }
00106     else if ( strcmp(titl_pos->val, GetFireVal(VAL_LR)) == 0 )  {   
00107         tpos = EnumLRPosition;
00108         }
00109     else    {       /* default */
00110         tpos = EnumURPosition;
00111         }
00112     
00113     /* export png file  (default title color and no data colors) */
00114     if ( GridDataImgExportIndexColorModelPng(gd, png_fname, atoi(img_w->val), atoi(img_h->val),
00115             title, tfont, tpos,             
00116             RGBColorsGetBasicColorRed(FIRE_EXPORT_IMG_DEFAULT_TITLE_COLOR),
00117             RGBColorsGetBasicColorGreen(FIRE_EXPORT_IMG_DEFAULT_TITLE_COLOR), 
00118             RGBColorsGetBasicColorBlue(FIRE_EXPORT_IMG_DEFAULT_TITLE_COLOR),
00119             RGBColorsGetBasicColorRed(FIRE_EXPORT_IMG_DEFAULT_NODATA_COLOR),
00120             RGBColorsGetBasicColorGreen(FIRE_EXPORT_IMG_DEFAULT_NODATA_COLOR), 
00121             RGBColorsGetBasicColorBlue(FIRE_EXPORT_IMG_DEFAULT_NODATA_COLOR),                                
00122             red, green, blue, icm_size) )   {
00123         FreeGridData(gd);
00124         free(red);
00125         free(green);
00126         free(blue);         
00127         ERR_ERROR("Unable to export PNG file of Fire IDs in function FireExportFireIDPng. \n", ERR_EBADFUNC);
00128         }
00129                     
00130     /* free memory */
00131     FreeGridData(gd);
00132     free(red);
00133     free(green);
00134     free(blue);
00135         
00136     return ERR_SUCCESS;
00137     }
00138  
00139 /* end of FireExportImg.c */

Generated at Fri Jun 22 00:46:51 2001 for HFire by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000