Check-in Differences
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Difference From caa41a260e3342c1 To 294601b232f6563c

2010-03-15
16:23
fixing png_checj_sig / png_sig_cmp check-in: 25c2d2d92f user: a.furieri@lqt.it tags: trunk
2010-01-13
15:15
implementing bsearch for rasterlite_grid tool check-in: caa41a260e user: a.furieri@lqt.it tags: trunk
2010-01-09
11:16
implementing Shaded Relief for Grids check-in: d4879cedec user: a.furieri@lqt.it tags: trunk
2009-12-07
15:41
supporting RGBA, ARGB, BGR and BGRA raw images check-in: 294601b232 user: a.furieri@lqt.it tags: trunk
2009-11-19
11:03
fixing makefile and warnings for MSVC check-in: bf94dc55e3 user: a.furieri@lqt.it tags: trunk

Changes to src/rasterlite_grid.c.

    53     53   #define ARG_GRID_PATH		1
    54     54   #define ARG_COLOR_PATH		2
    55     55   #define ARG_TIFF_PATH		3
    56     56   #define ARG_GRID_TYPE		4
    57     57   #define ARG_EPSG_CODE		5
    58     58   #define ARG_NODATA_COLOR	6
    59     59   #define ARG_PROJ4TEXT		7
    60         -#define ARG_MONO_COLOR		9
    61         -#define ARG_Z_FACTOR		10
    62         -#define ARG_SCALE			11
    63         -#define ARG_AZIMUTH			12
    64         -#define ARG_ALTITUDE		13
    65     60   
    66     61   #define ASCII_GRID	100
    67     62   #define FLOAT_GRID	101
    68     63   
    69     64   #define BYTE_ORDER_NONE	0
    70     65   #define BYTE_ORDER_BIG	1
    71     66   #define BYTE_ORDER_LITTLE	2
    72     67   
    73     68   struct colorTable
    74     69   {
    75         -/* a color table value range */
    76     70       double min;
    77     71       double max;
    78     72       unsigned char red;
    79     73       unsigned char green;
    80     74       unsigned char blue;
    81     75   };
    82     76   
    83         -struct triple_scan
    84         -{
    85         -/* the 3-scanlines object for Shaded Relief */
    86         -    int ncols;
    87         -    double z_factor;
    88         -    double scale_factor;
    89         -    double altitude;
    90         -    double azimuth;
    91         -    int mono_color;
    92         -    unsigned char mono_red;
    93         -    unsigned char mono_green;
    94         -    unsigned char mono_blue;
    95         -    float no_data_value;
    96         -    unsigned char no_red;
    97         -    unsigned char no_green;
    98         -    unsigned char no_blue;
    99         -    float *row1;
   100         -    float *row2;
   101         -    float *row3;
   102         -    float *current_row;
   103         -};
   104         -
   105         -static int
   106         -cmp_color_qsort (const void *p1, const void *p2)
   107         -{
   108         -/* compares two colorTable entries [for QSORT] */
   109         -    struct colorTable *pc1 = (struct colorTable *) p1;
   110         -    struct colorTable *pc2 = (struct colorTable *) p2;
   111         -    if (pc1->min > pc2->min)
   112         -	return 1;
   113         -    if (pc1->min < pc2->min)
   114         -	return -1;
   115         -    if (pc1->max > pc2->max)
   116         -	return 1;
   117         -    if (pc1->max < pc2->max)
   118         -	return -1;
   119         -    return 0;
   120         -}
   121         -
   122         -static int
   123         -cmp_color_bsearch (const void *p1, const void *p2)
   124         -{
   125         -/* compares two colorTable entries [for BSEARCH] */
   126         -    struct colorTable *pc1 = (struct colorTable *) p1;
   127         -    struct colorTable *pc2 = (struct colorTable *) p2;
   128         -    if (pc1->min >= pc2->min && pc1->min <= pc2->max)
   129         -	return 0;
   130         -    if (pc1->min > pc2->min)
   131         -	return 1;
   132         -    if (pc1->min < pc2->min)
   133         -	return -1;
   134         -    if (pc1->min > pc2->max)
   135         -	return 1;
   136         -    if (pc1->min < pc2->max)
   137         -	return -1;
   138         -}
   139         -
   140         -static int
   141         -match_color (struct colorTable *color_table, int colors, double value,
   142         -	     unsigned char *red, unsigned char *green, unsigned char *blue)
   143         -{
   144         -/* mapping a value into the corresponding color */
   145         -    struct colorTable *ret;
   146         -    struct colorTable src;
   147         -    src.min = value;
   148         -    ret =
   149         -	bsearch (&src, color_table, colors, sizeof (struct colorTable),
   150         -		 cmp_color_bsearch);
   151         -    if (ret)
   152         -      {
   153         -	  *red = ret->red;
   154         -	  *green = ret->green;
   155         -	  *blue = ret->blue;
   156         -	  return 1;
   157         -      }
   158         -    return 0;
   159         -}
   160         -
   161         -static struct triple_scan *
   162         -triple_alloc (int ncols)
   163         -{
   164         -/* allocating the 3-scanlines object */
   165         -    struct triple_scan *p = malloc (sizeof (struct triple_scan));
   166         -    p->ncols = ncols;
   167         -    p->row1 = malloc (sizeof (float) * ncols);
   168         -    p->row2 = malloc (sizeof (float) * ncols);
   169         -    p->row3 = malloc (sizeof (float) * ncols);
   170         -    p->current_row = p->row1;
   171         -    p->mono_color = 0;
   172         -    p->mono_red = 0;
   173         -    p->mono_green = 0;
   174         -    p->mono_blue = 0;
   175         -    p->no_data_value = 0.0;
   176         -    p->no_red = 0;
   177         -    p->no_green = 0;
   178         -    p->no_blue = 0;
   179         -    p->z_factor = 1.0;
   180         -    p->scale_factor = 1.0;
   181         -    p->altitude = 45.0;
   182         -    p->azimuth = 315.0;
   183         -    return p;
   184         -}
   185         -
   186         -static void
   187         -triple_free (struct triple_scan *p)
   188         -{
   189         -/* freeing the 3-scanlines object */
   190         -    free (p->row1);
   191         -    free (p->row2);
   192         -    free (p->row3);
   193         -    free (p);
   194         -}
   195         -
   196         -static void
   197         -triple_set_no_data (struct triple_scan *p, float no_data_value,
   198         -		    unsigned char no_red, unsigned char no_green,
   199         -		    unsigned char no_blue)
   200         -{
   201         -/* setting NODATA params */
   202         -    p->no_data_value = no_data_value;
   203         -    p->no_red = no_red;
   204         -    p->no_green = no_green;
   205         -    p->no_blue = no_blue;
   206         -}
   207         -
   208         -static void
   209         -triple_set_monochrome_params (struct triple_scan *p, int mono_color,
   210         -			      unsigned char mono_red, unsigned char mono_green,
   211         -			      unsigned char mono_blue)
   212         -{
   213         -/* setting ShadedRelief params */
   214         -    p->mono_color = mono_color;
   215         -    p->mono_red = mono_red;
   216         -    p->mono_green = mono_green;
   217         -    p->mono_blue = mono_blue;
   218         -}
   219         -
   220         -static void
   221         -triple_set_shaded_relief_params (struct triple_scan *p, double z, double scale,
   222         -				 double alt, double az)
   223         -{
   224         -/* setting ShadedRelief params */
   225         -    p->z_factor = z;
   226         -    p->scale_factor = scale;
   227         -    p->altitude = alt;
   228         -    p->azimuth = az;
   229         -}
   230         -
   231         -static void
   232         -triple_rotate (struct triple_scan *p)
   233         -{
   234         -/* rotating the 3-scanlines */
   235         -    if (p->current_row == p->row1)
   236         -      {
   237         -	  p->current_row = p->row2;
   238         -	  goto zero_init;
   239         -      }
   240         -    if (p->current_row == p->row2)
   241         -      {
   242         -	  p->current_row = p->row3;
   243         -	  goto zero_init;
   244         -      }
   245         -    p->current_row = p->row1;
   246         -    p->row1 = p->row2;
   247         -    p->row2 = p->row3;
   248         -    p->row3 = p->current_row;
   249         -  zero_init:
   250         -    memset (p->current_row, 0, sizeof (float) * p->ncols);
   251         -}
   252         -
   253         -static void
   254         -triple_store_cell (struct triple_scan *p, int icol, float value)
   255         -{
   256         -/* storing a cell value into 3-scanlines */
   257         -    if (icol < 0 || icol >= p->ncols)
   258         -	return;
   259         -    *(p->current_row + icol) = value;
   260         -}
   261         -
   262         -static int
   263         -triple_is_valid (struct triple_scan *p)
   264         -{
   265         -/* checking for validitity */
   266         -    if (p->current_row == p->row3)
   267         -	return 1;
   268         -    return 0;
   269         -}
   270         -
   271         -static void
   272         -triple_shaded_relief (struct triple_scan *p, unsigned char *raster)
   273         -{
   274         -/* creating a shaded relief scanline */
   275         -    int j;
   276         -    int n;
   277         -    double x;
   278         -    double y;
   279         -    double aspect;
   280         -    double slope;
   281         -    double cang;
   282         -    int gray;
   283         -    float afWin[9];
   284         -    const double degreesToRadians = M_PI / 180.0;
   285         -    const double altRadians = p->altitude * degreesToRadians;
   286         -    const double azRadians = p->azimuth * degreesToRadians;
   287         -    double red;
   288         -    double green;
   289         -    double blue;
   290         -    double alpha;
   291         -    int bContainsNull;
   292         -    unsigned char *p_raster = raster;
   293         -    unsigned char r;
   294         -    unsigned char g;
   295         -    unsigned char b;
   296         -
   297         -/*
   298         -/ Move a 3x3 pafWindow over each cell 
   299         -/ (where the cell in question is #4)
   300         -/ 
   301         -/      0 1 2
   302         -/      3 4 5
   303         -/      6 7 8
   304         -*/
   305         -    for (j = 0; j < p->ncols; j++)
   306         -      {
   307         -	  /* Exclude the edges */
   308         -	  if (j == 0 || j == p->ncols - 1)
   309         -	      continue;
   310         -
   311         -	  bContainsNull = 0;
   312         -
   313         -	  afWin[0] = p->row1[j - 1];
   314         -	  afWin[1] = p->row1[j];
   315         -	  afWin[2] = p->row1[j + 1];
   316         -	  afWin[3] = p->row2[j - 1];
   317         -	  afWin[4] = p->row2[j];
   318         -	  afWin[5] = p->row2[j + 1];
   319         -	  afWin[6] = p->row3[j - 1];
   320         -	  afWin[7] = p->row3[j];
   321         -	  afWin[8] = p->row3[j + 1];
   322         -
   323         -	  for (n = 0; n <= 8; n++)
   324         -	    {
   325         -		if (afWin[n] == p->no_data_value)
   326         -		  {
   327         -		      bContainsNull = 1;
   328         -		      break;
   329         -		  }
   330         -	    }
   331         -
   332         -	  if (bContainsNull)
   333         -	    {
   334         -		/* We have nulls so write nullValue and move on */
   335         -		r = p->no_red;
   336         -		g = p->no_green;
   337         -		b = p->no_blue;
   338         -	    }
   339         -	  else
   340         -	    {
   341         -		/* We have a valid 3x3 window. */
   342         -
   343         -		/* ---------------------------------------
   344         -		 * Compute Hillshade
   345         -		 */
   346         -
   347         -		/* First Slope ... */
   348         -		x = p->z_factor * ((afWin[0] + afWin[3] + afWin[3] + afWin[6]) -
   349         -				   (afWin[2] + afWin[5] + afWin[5] +
   350         -				    afWin[8])) / (8.0 * p->scale_factor);
   351         -
   352         -		y = p->z_factor * ((afWin[6] + afWin[7] + afWin[7] + afWin[8]) -
   353         -				   (afWin[0] + afWin[1] + afWin[1] +
   354         -				    afWin[2])) / (8.0 * p->scale_factor);
   355         -
   356         -		slope = M_PI / 2 - atan (sqrt (x * x + y * y));
   357         -
   358         -		/* ... then aspect... */
   359         -		aspect = atan2 (x, y);
   360         -
   361         -		/* ... then the shade value */
   362         -		cang = sin (altRadians) * sin (slope) +
   363         -		    cos (altRadians) * cos (slope) *
   364         -		    cos (azRadians - M_PI / 2 - aspect);
   365         -
   366         -		if (cang <= 0.0)
   367         -		    cang = 1.0;
   368         -		else
   369         -		    cang = 1.0 + (254.0 * cang);
   370         -
   371         -		if (p->mono_color)
   372         -		  {
   373         -		      /* using the monochrome base color + ALPHA */
   374         -		      alpha = cang / 255.0;
   375         -		      red = (double) (p->mono_red) * alpha;
   376         -		      green = (double) (p->mono_green) * alpha;
   377         -		      blue = (double) (p->mono_blue) * alpha;
   378         -		      if (red < 0.0)
   379         -			  red = 0.0;
   380         -		      if (green < 0.0)
   381         -			  green = 0.0;
   382         -		      if (blue < 0.0)
   383         -			  blue = 0.0;
   384         -		      if (red > 255.0)
   385         -			  red = 255.0;
   386         -		      if (green > 255.0)
   387         -			  green = 255.0;
   388         -		      if (blue > 255.0)
   389         -			  blue = 255.0;
   390         -		      r = (unsigned char) red;
   391         -		      g = (unsigned char) green;
   392         -		      b = (unsigned) blue;
   393         -		  }
   394         -		else
   395         -		  {
   396         -		      /* plain gray-scale */
   397         -		      gray = (int) cang;
   398         -		      r = (unsigned char) gray;
   399         -		      g = (unsigned char) gray;
   400         -		      b = (unsigned) gray;
   401         -		  }
   402         -	    }
   403         -	  *p_raster++ = r;
   404         -	  *p_raster++ = g;
   405         -	  *p_raster++ = b;
   406         -      }
   407         -}
   408         -
   409         -static int
   410         -triple_shaded_relief_color (struct colorTable *color_table, int colors,
   411         -			    struct triple_scan *p, unsigned char *raster,
   412         -			    int row)
   413         -{
   414         -/* creating a shaded relief color scanline */
   415         -    int color;
   416         -    int j;
   417         -    int n;
   418         -    double x;
   419         -    double y;
   420         -    double aspect;
   421         -    double slope;
   422         -    double cang;
   423         -    float afWin[9];
   424         -    const double degreesToRadians = M_PI / 180.0;
   425         -    const double altRadians = p->altitude * degreesToRadians;
   426         -    const double azRadians = p->azimuth * degreesToRadians;
   427         -    double red;
   428         -    double green;
   429         -    double blue;
   430         -    double alpha;
   431         -    double thisValue;
   432         -    int bContainsNull;
   433         -    unsigned char *p_raster = raster;
   434         -    unsigned char r;
   435         -    unsigned char g;
   436         -    unsigned char b;
   437         -
   438         -/*
   439         -/ Move a 3x3 pafWindow over each cell 
   440         -/ (where the cell in question is #4)
   441         -/ 
   442         -/      0 1 2
   443         -/      3 4 5
   444         -/      6 7 8
   445         -*/
   446         -    for (j = 0; j < p->ncols; j++)
   447         -      {
   448         -	  /* Exclude the edges */
   449         -	  if (j == 0 || j == p->ncols - 1)
   450         -	      continue;
   451         -
   452         -	  bContainsNull = 0;
   453         -
   454         -	  afWin[0] = p->row1[j - 1];
   455         -	  afWin[1] = p->row1[j];
   456         -	  afWin[2] = p->row1[j + 1];
   457         -	  afWin[3] = p->row2[j - 1];
   458         -	  afWin[4] = p->row2[j];
   459         -	  afWin[5] = p->row2[j + 1];
   460         -	  afWin[6] = p->row3[j - 1];
   461         -	  afWin[7] = p->row3[j];
   462         -	  afWin[8] = p->row3[j + 1];
   463         -
   464         -	  thisValue = afWin[4];
   465         -
   466         -	  for (n = 0; n <= 8; n++)
   467         -	    {
   468         -		if (afWin[n] == p->no_data_value)
   469         -		  {
   470         -		      bContainsNull = 1;
   471         -		      break;
   472         -		  }
   473         -	    }
   474         -
   475         -	  if (bContainsNull)
   476         -	    {
   477         -		/* We have nulls so write nullValue and move on */
   478         -		r = p->no_red;
   479         -		g = p->no_green;
   480         -		b = p->no_blue;
   481         -	    }
   482         -	  else
   483         -	    {
   484         -		/* We have a valid 3x3 window. */
   485         -
   486         -		/* ---------------------------------------
   487         -		 * Compute Hillshade
   488         -		 */
   489         -
   490         -		/* First Slope ... */
   491         -		x = p->z_factor * ((afWin[0] + afWin[3] + afWin[3] + afWin[6]) -
   492         -				   (afWin[2] + afWin[5] + afWin[5] +
   493         -				    afWin[8])) / (8.0 * p->scale_factor);
   494         -
   495         -		y = p->z_factor * ((afWin[6] + afWin[7] + afWin[7] + afWin[8]) -
   496         -				   (afWin[0] + afWin[1] + afWin[1] +
   497         -				    afWin[2])) / (8.0 * p->scale_factor);
   498         -
   499         -		slope = M_PI / 2 - atan (sqrt (x * x + y * y));
   500         -
   501         -		/* ... then aspect... */
   502         -		aspect = atan2 (x, y);
   503         -
   504         -		/* ... then the shade value */
   505         -		cang = sin (altRadians) * sin (slope) +
   506         -		    cos (altRadians) * cos (slope) *
   507         -		    cos (azRadians - M_PI / 2 - aspect);
   508         -
   509         -		if (cang <= 0.0)
   510         -		    cang = 1.0;
   511         -		else
   512         -		    cang = 1.0 + (254.0 * cang);
   513         -
   514         -		/* merging the color + ALPHA */
   515         -		if (!match_color (color_table, colors, thisValue, &r, &g, &b))
   516         -		  {
   517         -		      printf
   518         -			  ("Grid row %d: unmatched value %1.8f; color not found\n",
   519         -			   row, thisValue);
   520         -		      return 0;
   521         -		  }
   522         -		alpha = cang / 255.0;
   523         -		red = (double) r *alpha;
   524         -		green = (double) g *alpha;
   525         -		blue = (double) b *alpha;
   526         -		if (red < 0.0)
   527         -		    red = 0.0;
   528         -		if (green < 0.0)
   529         -		    green = 0.0;
   530         -		if (blue < 0.0)
   531         -		    blue = 0.0;
   532         -		if (red > 255.0)
   533         -		    red = 255.0;
   534         -		if (green > 255.0)
   535         -		    green = 255.0;
   536         -		if (blue > 255.0)
   537         -		    blue = 255.0;
   538         -		r = (unsigned char) red;
   539         -		g = (unsigned char) green;
   540         -		b = (unsigned) blue;
   541         -	    }
   542         -	  *p_raster++ = r;
   543         -	  *p_raster++ = g;
   544         -	  *p_raster++ = b;
   545         -      }
   546         -    return 1;
   547         -}
   548         -
   549     77   static int
   550     78   parse_hex (const char hi, const char lo)
   551     79   {
   552     80   /* parsing an hexedecimal value XX */
   553     81       int hex;
   554     82       switch (hi)
   555     83         {
................................................................................
   822    350   	    }
   823    351   	  return 1;
   824    352         }
   825    353       return 0;
   826    354   }
   827    355   
   828    356   static struct colorTable *
   829         -parse_color_table (const char *path, int *count)
          357  +parse_color_table (const char *path)
   830    358   {
   831    359   /* parsing the Color Table */
   832    360       double min;
   833    361       double max;
   834    362       unsigned char red;
   835    363       unsigned char green;
   836    364       unsigned char blue;
................................................................................
   872    400   		ptr = buf;
   873    401   		continue;
   874    402   	    }
   875    403   	  *ptr++ = c;
   876    404         }
   877    405       if (lines == 0 || error > 0)
   878    406   	return NULL;
   879         -    table = malloc (sizeof (struct colorTable) * (lines));
          407  +    table = malloc (sizeof (struct colorTable) * (lines + 1));
          408  +/* marking the last (stop) table item */
          409  +    (table + lines)->min = DBL_MAX;
          410  +    (table + lines)->max = DBL_MAX;
          411  +    (table + lines)->red = 0;
          412  +    (table + lines)->green = 0;
          413  +    (table + lines)->blue = 0;
   880    414   /* closing and reopening the Color Table file */
   881    415       fclose (in);
   882    416       in = fopen (path, "rb");
   883    417       if (!in)
   884    418         {
   885    419   	  printf ("Re-Open error: %s\n", path);
   886    420   	  return NULL;
................................................................................
   923    457         {
   924    458   	  /* unexected error */
   925    459   	  fprintf (stderr, "ColorTable: unexpected read error\n");
   926    460   	  free (table);
   927    461   	  table = NULL;
   928    462         }
   929    463       fclose (in);
   930         -/* sorting the color table */
   931         -    *count = lines;
   932         -    qsort (table, lines, sizeof (struct colorTable), cmp_color_qsort);
   933    464       return table;
   934    465   }
   935    466   
   936    467   static int
   937    468   parseIntHeader (const char *row, const char *tag, int *value)
   938    469   {
   939    470   /* parsing an Integer value Header */
................................................................................
   973    504   	  *value = BYTE_ORDER_BIG;
   974    505   	  return 1;
   975    506         }
   976    507       return 0;
   977    508   }
   978    509   
   979    510   static int
   980         -fetch_scanline (int row, struct colorTable *color_table, int colors, FILE * asc,
          511  +match_color (struct colorTable *color_table, double value, unsigned char *red,
          512  +	     unsigned char *green, unsigned char *blue)
          513  +{
          514  +/* mapping a value into the corresponding color */
          515  +    struct colorTable *p = color_table;
          516  +    while (p)
          517  +      {
          518  +	  if (p->min == DBL_MAX)
          519  +	      return 0;
          520  +	  if (value >= p->min && value <= p->max)
          521  +	    {
          522  +		*red = p->red;
          523  +		*green = p->green;
          524  +		*blue = p->blue;
          525  +		return 1;
          526  +	    }
          527  +	  p++;
          528  +      }
          529  +    return 0;
          530  +}
          531  +
          532  +static int
          533  +fetch_scanline (int row, struct colorTable *color_table, FILE * asc,
   981    534   		unsigned char *raster, int columns, double nodata,
   982    535   		unsigned char no_red, unsigned char no_green,
   983    536   		unsigned char no_blue)
   984    537   {
   985    538   /* feeding a TIFF scanline from an ASCII Grid */
   986    539       int c;
   987    540       int cell = 0;
................................................................................
  1012    565   		  {
  1013    566   		      *p_raster++ = no_red;
  1014    567   		      *p_raster++ = no_green;
  1015    568   		      *p_raster++ = no_blue;
  1016    569   		  }
  1017    570   		else
  1018    571   		  {
  1019         -		      if (match_color
  1020         -			  (color_table, colors, value, &red, &green, &blue))
          572  +		      if (match_color (color_table, value, &red, &green, &blue))
  1021    573   			{
  1022    574   			    *p_raster++ = red;
  1023    575   			    *p_raster++ = green;
  1024    576   			    *p_raster++ = blue;
  1025    577   			}
  1026    578   		      else
  1027    579   			{
................................................................................
  1101    653       convert.int_value = 1;
  1102    654       if (convert.byte[0] == 0)
  1103    655   	return 0;
  1104    656       return 1;
  1105    657   }
  1106    658   
  1107    659   static int
  1108         -fetch_float_scanline (int row, struct colorTable *color_table, int colors,
          660  +fetch_float_scanline (int row, struct colorTable *color_table,
  1109    661   		      unsigned char *floats, unsigned char *raster, int columns,
  1110    662   		      double nodata, unsigned char no_red,
  1111    663   		      unsigned char no_green, unsigned char no_blue,
  1112    664   		      int byteorder)
  1113    665   {
  1114    666   /* feeding a TIFF scanline from a FLOAT Grid */
  1115    667       int cell = 0;
................................................................................
  1127    679   	    {
  1128    680   		*p_raster++ = no_red;
  1129    681   		*p_raster++ = no_green;
  1130    682   		*p_raster++ = no_blue;
  1131    683   	    }
  1132    684   	  else
  1133    685   	    {
  1134         -		if (match_color
  1135         -		    (color_table, colors, value, &red, &green, &blue))
          686  +		if (match_color (color_table, value, &red, &green, &blue))
  1136    687   		  {
  1137    688   		      *p_raster++ = red;
  1138    689   		      *p_raster++ = green;
  1139    690   		      *p_raster++ = blue;
  1140    691   		  }
  1141    692   		else
  1142    693   		  {
................................................................................
  1148    699   	    }
  1149    700   	  ptr += sizeof (float);
  1150    701         }
  1151    702       return 1;
  1152    703   }
  1153    704   
  1154    705   static void
  1155         -export_geoTiff_float (struct colorTable *color_table, int colors,
  1156         -		      const char *proj4text, const char *grid_path,
  1157         -		      const char *tiff_path, unsigned char no_red,
  1158         -		      unsigned char no_green, unsigned char no_blue,
  1159         -		      int verbose)
          706  +export_geoTiff_float (struct colorTable *color_table, const char *proj4text,
          707  +		      const char *grid_path, const char *tiff_path,
          708  +		      unsigned char no_red, unsigned char no_green,
          709  +		      unsigned char no_blue, int verbose)
  1160    710   {
  1161    711   /* exporting a FLOAT GRID as GeoTIFF */
  1162    712       TIFF *tiff = NULL;
  1163    713       GTIF *gtif = NULL;
  1164    714       int byteorder = BYTE_ORDER_NONE;
  1165    715       int c;
  1166    716       int row = 0;
................................................................................
  1306    856   	  if (rd != (sizeof (float) * ncols))
  1307    857   	    {
  1308    858   		printf ("*** Grid read error ***\n");
  1309    859   		printf ("An invalid GeoTIFF was generated ... aborting ...\n");
  1310    860   		goto stop;
  1311    861   	    }
  1312    862   	  if (fetch_float_scanline
  1313         -	      (row + 1, color_table, colors, flt_buf, raster, ncols, nodata,
  1314         -	       no_red, no_green, no_blue, byteorder))
          863  +	      (row + 1, color_table, flt_buf, raster, ncols, nodata, no_red,
          864  +	       no_green, no_blue, byteorder))
  1315    865   	    {
  1316    866   		if (TIFFWriteScanline (tiff, raster, row, 0) < 0)
  1317    867   		  {
  1318    868   		      printf ("\tTIFF write error @ row=%d\n", row);
  1319    869   		      printf
  1320    870   			  ("An invalid GeoTIFF was generated ... aborting ...\n");
  1321    871   		      goto stop;
................................................................................
  1338    888   	free (raster);
  1339    889       if (flt_buf)
  1340    890   	free (flt_buf);
  1341    891       fclose (grid);
  1342    892   }
  1343    893   
  1344    894   static void
  1345         -export_geoTiff_ascii (struct colorTable *color_table, int colors,
  1346         -		      const char *proj4text, const char *grid_path,
  1347         -		      const char *tiff_path, unsigned char no_red,
  1348         -		      unsigned char no_green, unsigned char no_blue,
  1349         -		      int verbose)
          895  +export_geoTiff_ascii (struct colorTable *color_table, const char *proj4text,
          896  +		      const char *grid_path, const char *tiff_path,
          897  +		      unsigned char no_red, unsigned char no_green,
          898  +		      unsigned char no_blue, int verbose)
  1350    899   {
  1351    900   /* exporting an ASCII GRID as GeoTIFF */
  1352    901       TIFF *tiff = NULL;
  1353    902       GTIF *gtif = NULL;
  1354    903       int c;
  1355    904       int row = 0;
  1356    905       char buf[1024];
................................................................................
  1466   1015         {
  1467   1016   	  if (verbose)
  1468   1017   	    {
  1469   1018   		fprintf (stderr, "writing scanline %d of %d\n", row + 1, nrows);
  1470   1019   		fflush (stderr);
  1471   1020   	    }
  1472   1021   	  if (fetch_scanline
  1473         -	      (row + 1, color_table, colors, asc, raster, ncols, nodata, no_red,
         1022  +	      (row + 1, color_table, asc, raster, ncols, nodata, no_red,
  1474   1023   	       no_green, no_blue))
  1475   1024   	    {
  1476   1025   		if (TIFFWriteScanline (tiff, raster, row, 0) < 0)
  1477   1026   		  {
  1478   1027   		      printf ("\tTIFF write error @ row=%d\n", row);
  1479   1028   		      printf
  1480   1029   			  ("An invalid GeoTIFF was generated ... aborting ...\n");
................................................................................
  1495   1044       if (tiff)
  1496   1045   	XTIFFClose (tiff);
  1497   1046       if (raster)
  1498   1047   	free (raster);
  1499   1048       fclose (asc);
  1500   1049   }
  1501   1050   
  1502         -static int
  1503         -fetch_float_scanline_shaded (int row, unsigned char *floats, int columns,
  1504         -			     int byteorder, struct triple_scan *triplet)
  1505         -{
  1506         -/* feeding a TIFF scanline from a FLOAT Grid */
  1507         -    int cell = 0;
  1508         -    double value;
  1509         -    unsigned char *ptr = floats;
  1510         -    int endian_arch = check_endian_arch ();
  1511         -    for (cell = 0; cell < columns; cell++)
  1512         -      {
  1513         -	  value = fetch_float (ptr, byteorder, endian_arch);
  1514         -	  triple_store_cell (triplet, cell, value);
  1515         -	  ptr += sizeof (float);
  1516         -      }
  1517         -    return 1;
  1518         -}
  1519         -
  1520         -static void
  1521         -export_geoTiff_shaded_float (struct colorTable *color_table, int colors,
  1522         -			     const char *proj4text, const char *grid_path,
  1523         -			     const char *tiff_path, unsigned char no_red,
  1524         -			     unsigned char no_green, unsigned char no_blue,
  1525         -			     int mono_color, unsigned char mono_red,
  1526         -			     unsigned char mono_green, unsigned char mono_blue,
  1527         -			     double z_factor, double scale_factor,
  1528         -			     double azimuth, double altitude, int verbose)
  1529         -{
  1530         -/* exporting a FLOAT GRID as GeoTIFF */
  1531         -    TIFF *tiff = NULL;
  1532         -    GTIF *gtif = NULL;
  1533         -    int byteorder = BYTE_ORDER_NONE;
  1534         -    int c;
  1535         -    int row = 0;
  1536         -    char buf[1024];
  1537         -    char path[1024];
  1538         -    char *ptr = buf;
  1539         -    int err = 0;
  1540         -    int ncols = -1;
  1541         -    int nrows = -1;
  1542         -    double xllcorner = 0.0;
  1543         -    double yllcorner = 0.0;
  1544         -    double cellsize = 0.0;
  1545         -    double nodata = 0.0;
  1546         -    double tiepoint[6];
  1547         -    double pixsize[3];
  1548         -    struct triple_scan *triplet = NULL;
  1549         -    unsigned char *raster = NULL;
  1550         -    unsigned char *flt_buf = NULL;
  1551         -    size_t rd;
  1552         -    FILE *grid;
  1553         -
  1554         -/* parsing the Grid Header .hdr */
  1555         -    sprintf (path, "%s.hdr", grid_path);
  1556         -    grid = fopen (path, "rb");
  1557         -    if (!grid)
  1558         -      {
  1559         -	  printf ("Open error: %s\n", path);
  1560         -	  return;
  1561         -      }
  1562         -    while ((c = getc (grid)) != EOF)
  1563         -      {
  1564         -	  if (c == '\r')
  1565         -	    {
  1566         -		/* ignoring Return chars */
  1567         -		continue;
  1568         -	    }
  1569         -	  if (c == '\n')
  1570         -	    {
  1571         -		*ptr = '\0';
  1572         -		switch (row)
  1573         -		  {
  1574         -		  case 0:
  1575         -		      if (!parseIntHeader (buf, "ncols ", &ncols))
  1576         -			  err = 1;
  1577         -		      break;
  1578         -		  case 1:
  1579         -		      if (!parseIntHeader (buf, "nrows ", &nrows))
  1580         -			  err = 1;
  1581         -		      break;
  1582         -		  case 2:
  1583         -		      if (!parseDblHeader (buf, "xllcorner ", &xllcorner))
  1584         -			  err = 1;
  1585         -		      break;
  1586         -		  case 3:
  1587         -		      if (!parseDblHeader (buf, "yllcorner ", &yllcorner))
  1588         -			  err = 1;
  1589         -		      break;
  1590         -		  case 4:
  1591         -		      if (!parseDblHeader (buf, "cellsize ", &cellsize))
  1592         -			  err = 1;
  1593         -		      break;
  1594         -		  case 5:
  1595         -		      if (!parseDblHeader (buf, "NODATA_value ", &nodata))
  1596         -			  err = 1;
  1597         -		      break;
  1598         -		  case 6:
  1599         -		      if (!parseOrderHeader (buf, "byteorder ", &byteorder))
  1600         -			  err = 1;
  1601         -		      break;
  1602         -		  };
  1603         -		ptr = buf;
  1604         -		row++;
  1605         -		if (row == 7)
  1606         -		    break;
  1607         -		continue;
  1608         -	    }
  1609         -	  *ptr++ = c;
  1610         -      }
  1611         -    if (err)
  1612         -      {
  1613         -	  /* there was some error */
  1614         -	  printf ("Invalid FLOAT Grid Header format in: %s\n", path);
  1615         -	  goto stop;
  1616         -      }
  1617         -    fclose (grid);
  1618         -
  1619         -/* resizing CellSize */
  1620         -    cellsize = (cellsize * (double) ncols) / (double) (ncols - 2);
  1621         -
  1622         -/* parsing the Grid Cells .flt */
  1623         -    sprintf (path, "%s.flt", grid_path);
  1624         -    grid = fopen (path, "rb");
  1625         -    if (!grid)
  1626         -      {
  1627         -	  printf ("Open error: %s\n", path);
  1628         -	  return;
  1629         -      }
  1630         -/* creating the GeoTIFF file */
  1631         -    tiff = XTIFFOpen (tiff_path, "w");
  1632         -    if (!tiff)
  1633         -      {
  1634         -	  printf ("\tCould not open TIFF image '%s'\n", tiff_path);
  1635         -	  goto stop;
  1636         -      }
  1637         -    gtif = GTIFNew (tiff);
  1638         -    if (!gtif)
  1639         -      {
  1640         -	  printf ("\tCould not open GeoTIFF image '%s'\n", tiff_path);
  1641         -	  goto stop;
  1642         -      }
  1643         -
  1644         -/* writing the TIFF Tags */
  1645         -    TIFFSetField (tiff, TIFFTAG_IMAGEWIDTH, ncols - 2);
  1646         -    TIFFSetField (tiff, TIFFTAG_IMAGELENGTH, nrows - 2);
  1647         -    TIFFSetField (tiff, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
  1648         -    TIFFSetField (tiff, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT);
  1649         -    TIFFSetField (tiff, TIFFTAG_ROWSPERSTRIP, 1);
  1650         -    TIFFSetField (tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
  1651         -    TIFFSetField (tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
  1652         -    TIFFSetField (tiff, TIFFTAG_BITSPERSAMPLE, 8);
  1653         -    TIFFSetField (tiff, TIFFTAG_SAMPLESPERPIXEL, 3);
  1654         -
  1655         -/* writing the GeoTIFF Tags */
  1656         -    pixsize[0] = cellsize;
  1657         -    pixsize[1] = cellsize;
  1658         -    pixsize[2] = 0.0;
  1659         -    TIFFSetField (tiff, GTIFF_PIXELSCALE, 3, pixsize);
  1660         -    tiepoint[0] = 0.0;
  1661         -    tiepoint[1] = 0.0;
  1662         -    tiepoint[2] = 0.0;
  1663         -    tiepoint[3] = xllcorner;
  1664         -    tiepoint[4] = yllcorner + (cellsize * nrows);
  1665         -    tiepoint[5] = 0.0;
  1666         -    TIFFSetField (tiff, GTIFF_TIEPOINTS, 6, tiepoint);
  1667         -    GTIFSetFromProj4 (gtif, proj4text);
  1668         -    GTIFWriteKeys (gtif);
  1669         -    raster = malloc (ncols * 3);
  1670         -    flt_buf = malloc (sizeof (float) * ncols);
  1671         -
  1672         -/* initializing the TripleRow object */
  1673         -    triplet = triple_alloc (ncols);
  1674         -    triple_set_shaded_relief_params (triplet, z_factor, scale_factor, altitude,
  1675         -				     azimuth);
  1676         -    triple_set_monochrome_params (triplet, mono_color, mono_red, mono_green,
  1677         -				  mono_blue);
  1678         -    triple_set_no_data (triplet, nodata, no_red, no_green, no_blue);
  1679         -
  1680         -    for (row = 0; row < nrows; row++)
  1681         -      {
  1682         -	  if (verbose)
  1683         -	    {
  1684         -		fprintf (stderr, "writing scanline %d of %d\n", row + 1, nrows);
  1685         -		fflush (stderr);
  1686         -	    }
  1687         -	  rd = fread (flt_buf, 1, ncols * sizeof (float), grid);
  1688         -	  if (rd != (sizeof (float) * ncols))
  1689         -	    {
  1690         -		printf ("*** Grid read error ***\n");
  1691         -		printf ("An invalid GeoTIFF was generated ... aborting ...\n");
  1692         -		goto stop;
  1693         -	    }
  1694         -	  if (fetch_float_scanline_shaded
  1695         -	      (row + 1, flt_buf, ncols, byteorder, triplet))
  1696         -	    {
  1697         -		if (triple_is_valid (triplet))
  1698         -		  {
  1699         -		      int ret = 1;
  1700         -		      if (!color_table)
  1701         -			  triple_shaded_relief (triplet, raster);
  1702         -		      else
  1703         -			  ret =
  1704         -			      triple_shaded_relief_color (color_table, colors,
  1705         -							  triplet, raster,
  1706         -							  row + 1);
  1707         -		      if (!ret)
  1708         -			  goto stop;
  1709         -		      if (TIFFWriteScanline (tiff, raster, row - 2, 0) < 0)
  1710         -			{
  1711         -			    printf ("\tTIFF write error @ row=%d\n", row);
  1712         -			    printf
  1713         -				("An invalid GeoTIFF was generated ... aborting ...\n");
  1714         -			    goto stop;
  1715         -			}
  1716         -		  }
  1717         -		triple_rotate (triplet);
  1718         -	    }
  1719         -	  else
  1720         -	    {
  1721         -		printf ("*** Grid read error ***\n");
  1722         -		printf ("An invalid GeoTIFF was generated ... aborting ...\n");
  1723         -		goto stop;
  1724         -	    }
  1725         -      }
  1726         -
  1727         -  stop:
  1728         -    if (gtif)
  1729         -	GTIFFree (gtif);
  1730         -    if (tiff)
  1731         -	XTIFFClose (tiff);
  1732         -    if (raster)
  1733         -	free (raster);
  1734         -    if (flt_buf)
  1735         -	free (flt_buf);
  1736         -    fclose (grid);
  1737         -    if (triplet)
  1738         -	triple_free (triplet);
  1739         -}
  1740         -
  1741         -static int
  1742         -fetch_scanline_shaded (int row, FILE * asc, int columns,
  1743         -		       struct triple_scan *triplet)
  1744         -{
  1745         -/* feeding a TIFF scanline from an ASCII Grid */
  1746         -    int c;
  1747         -    int cell = 0;
  1748         -    char buf[1024];
  1749         -    char *ptr = buf;
  1750         -    double value;
  1751         -    while ((c = getc (asc)) != EOF)
  1752         -      {
  1753         -	  if (c == '\n')
  1754         -	      break;
  1755         -	  *ptr++ = c;
  1756         -	  if (c == ' ')
  1757         -	    {
  1758         -		/* value delimiter */
  1759         -		*ptr = '\0';
  1760         -		cell++;
  1761         -		if (cell > columns)
  1762         -		  {
  1763         -		      printf ("Grid row %d: exceding column\n", row);
  1764         -		      return 0;
  1765         -		  }
  1766         -		value = atof (buf);
  1767         -		triple_store_cell (triplet, cell, (float) value);
  1768         -		ptr = buf;
  1769         -	    }
  1770         -      }
  1771         -    return 1;
  1772         -}
  1773         -
  1774         -static void
  1775         -export_geoTiff_shaded_ascii (struct colorTable *color_table, int colors,
  1776         -			     const char *proj4text, const char *grid_path,
  1777         -			     const char *tiff_path, unsigned char no_red,
  1778         -			     unsigned char no_green, unsigned char no_blue,
  1779         -			     int mono_color, unsigned char mono_red,
  1780         -			     unsigned char mono_green, unsigned char mono_blue,
  1781         -			     double z_factor, double scale_factor,
  1782         -			     double azimuth, double altitude, int verbose)
  1783         -{
  1784         -/* exporting an ASCII GRID as GeoTIFF */
  1785         -    TIFF *tiff = NULL;
  1786         -    GTIF *gtif = NULL;
  1787         -    int c;
  1788         -    int row = 0;
  1789         -    char buf[1024];
  1790         -    char *ptr = buf;
  1791         -    int err = 0;
  1792         -    int ncols = -1;
  1793         -    int nrows = -1;
  1794         -    double xllcorner = 0.0;
  1795         -    double yllcorner = 0.0;
  1796         -    double cellsize = 0.0;
  1797         -    double nodata = 0.0;
  1798         -    double tiepoint[6];
  1799         -    double pixsize[3];
  1800         -    unsigned char *raster = NULL;
  1801         -    struct triple_scan *triplet = NULL;
  1802         -    FILE *asc = fopen (grid_path, "rb");
  1803         -    if (!asc)
  1804         -      {
  1805         -	  printf ("Open error: %s\n", grid_path);
  1806         -	  return;
  1807         -      }
  1808         -    while ((c = getc (asc)) != EOF)
  1809         -      {
  1810         -	  if (c == '\r')
  1811         -	    {
  1812         -		/* ignoring Return chars */
  1813         -		continue;
  1814         -	    }
  1815         -	  if (c == '\n')
  1816         -	    {
  1817         -		*ptr = '\0';
  1818         -		switch (row)
  1819         -		  {
  1820         -		  case 0:
  1821         -		      if (!parseIntHeader (buf, "ncols ", &ncols))
  1822         -			  err = 1;
  1823         -		      break;
  1824         -		  case 1:
  1825         -		      if (!parseIntHeader (buf, "nrows ", &nrows))
  1826         -			  err = 1;
  1827         -		      break;
  1828         -		  case 2:
  1829         -		      if (!parseDblHeader (buf, "xllcorner ", &xllcorner))
  1830         -			  err = 1;
  1831         -		      break;
  1832         -		  case 3:
  1833         -		      if (!parseDblHeader (buf, "yllcorner ", &yllcorner))
  1834         -			  err = 1;
  1835         -		      break;
  1836         -		  case 4:
  1837         -		      if (!parseDblHeader (buf, "cellsize ", &cellsize))
  1838         -			  err = 1;
  1839         -		      break;
  1840         -		  case 5:
  1841         -		      if (!parseDblHeader (buf, "NODATA_value ", &nodata))
  1842         -			  err = 1;
  1843         -		      break;
  1844         -		  };
  1845         -		ptr = buf;
  1846         -		row++;
  1847         -		if (row == 6)
  1848         -		    break;
  1849         -		continue;
  1850         -	    }
  1851         -	  *ptr++ = c;
  1852         -      }
  1853         -    if (err)
  1854         -      {
  1855         -	  /* there was some error */
  1856         -	  printf ("Invalid ASCII Grid format in: %s\n", grid_path);
  1857         -	  goto stop;
  1858         -      }
  1859         -
  1860         -/* resizing CellSize */
  1861         -    cellsize = (cellsize * (double) ncols) / (double) (ncols - 2);
  1862         -
  1863         -/* creating the GeoTIFF file */
  1864         -    tiff = XTIFFOpen (tiff_path, "w");
  1865         -    if (!tiff)
  1866         -      {
  1867         -	  printf ("\tCould not open TIFF image '%s'\n", tiff_path);
  1868         -	  goto stop;
  1869         -      }
  1870         -    gtif = GTIFNew (tiff);
  1871         -    if (!gtif)
  1872         -      {
  1873         -	  printf ("\tCould not open GeoTIFF image '%s'\n", tiff_path);
  1874         -	  goto stop;
  1875         -      }
  1876         -
  1877         -/* writing the TIFF Tags */
  1878         -    TIFFSetField (tiff, TIFFTAG_IMAGEWIDTH, ncols - 2);
  1879         -    TIFFSetField (tiff, TIFFTAG_IMAGELENGTH, nrows - 2);
  1880         -    TIFFSetField (tiff, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
  1881         -    TIFFSetField (tiff, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT);
  1882         -    TIFFSetField (tiff, TIFFTAG_ROWSPERSTRIP, 1);
  1883         -    TIFFSetField (tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
  1884         -    TIFFSetField (tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
  1885         -    TIFFSetField (tiff, TIFFTAG_BITSPERSAMPLE, 8);
  1886         -    TIFFSetField (tiff, TIFFTAG_SAMPLESPERPIXEL, 3);
  1887         -
  1888         -/* writing the GeoTIFF Tags */
  1889         -    pixsize[0] = cellsize;
  1890         -    pixsize[1] = cellsize;
  1891         -    pixsize[2] = 0.0;
  1892         -    TIFFSetField (tiff, GTIFF_PIXELSCALE, 3, pixsize);
  1893         -    tiepoint[0] = 0.0;
  1894         -    tiepoint[1] = 0.0;
  1895         -    tiepoint[2] = 0.0;
  1896         -    tiepoint[3] = xllcorner;
  1897         -    tiepoint[4] = yllcorner + (cellsize * nrows);
  1898         -    tiepoint[5] = 0.0;
  1899         -    TIFFSetField (tiff, GTIFF_TIEPOINTS, 6, tiepoint);
  1900         -    GTIFSetFromProj4 (gtif, proj4text);
  1901         -    GTIFWriteKeys (gtif);
  1902         -    raster = malloc (ncols * 3);
  1903         -
  1904         -/* initializing the TripleRow object */
  1905         -    triplet = triple_alloc (ncols);
  1906         -    triple_set_shaded_relief_params (triplet, z_factor, scale_factor, altitude,
  1907         -				     azimuth);
  1908         -    triple_set_monochrome_params (triplet, mono_color, mono_red, mono_green,
  1909         -				  mono_blue);
  1910         -    triple_set_no_data (triplet, nodata, no_red, no_green, no_blue);
  1911         -
  1912         -    for (row = 0; row < nrows; row++)
  1913         -      {
  1914         -	  if (verbose)
  1915         -	    {
  1916         -		fprintf (stderr, "writing scanline %d of %d\n", row + 1, nrows);
  1917         -		fflush (stderr);
  1918         -	    }
  1919         -	  if (fetch_scanline_shaded (row + 1, asc, ncols, triplet))
  1920         -	    {
  1921         -		if (triple_is_valid (triplet))
  1922         -		  {
  1923         -		      int ret = 1;
  1924         -		      if (!color_table)
  1925         -			  triple_shaded_relief (triplet, raster);
  1926         -		      else
  1927         -			  ret =
  1928         -			      triple_shaded_relief_color (color_table, colors,
  1929         -							  triplet, raster,
  1930         -							  row + 1);
  1931         -		      if (!ret)
  1932         -			  goto stop;
  1933         -		      if (TIFFWriteScanline (tiff, raster, row - 2, 0) < 0)
  1934         -			{
  1935         -			    printf ("\tTIFF write error @ row=%d\n", row);
  1936         -			    printf
  1937         -				("An invalid GeoTIFF was generated ... aborting ...\n");
  1938         -			    goto stop;
  1939         -			}
  1940         -		  }
  1941         -		triple_rotate (triplet);
  1942         -	    }
  1943         -	  else
  1944         -	    {
  1945         -		printf ("*** Grid read error ***\n");
  1946         -		printf ("An invalid GeoTIFF was generated ... aborting ...\n");
  1947         -		goto stop;
  1948         -	    }
  1949         -      }
  1950         -
  1951         -  stop:
  1952         -    if (gtif)
  1953         -	GTIFFree (gtif);
  1954         -    if (tiff)
  1955         -	XTIFFClose (tiff);
  1956         -    if (raster)
  1957         -	free (raster);
  1958         -    fclose (asc);
  1959         -    if (triplet)
  1960         -	triple_free (triplet);
  1961         -}
  1962         -
  1963   1051   static void
  1964   1052   do_help ()
  1965   1053   {
  1966   1054   /* printing the argument list */
  1967   1055       fprintf (stderr, "\n\nusage: rasterlite_grid ARGLIST\n");
  1968   1056       fprintf (stderr,
  1969   1057   	     "==============================================================\n");
................................................................................
  1976   1064       fprintf (stderr,
  1977   1065   	     "-t or --tiff-path     pathname    the GeoTIFF path (output)\n");
  1978   1066       fprintf (stderr,
  1979   1067   	     "-p or --proj4text     proj4text   the PROJ.4 parameters\n");
  1980   1068       fprintf (stderr, "-f or --grid-format   grid-type   [ASCII | FLOAT]\n");
  1981   1069       fprintf (stderr,
  1982   1070   	     "-n or --nodata-color  0xRRGGBB    [default = 0x000000]\n");
  1983         -    fprintf (stderr, "-v or --verbose                   verbose output\n\n");
  1984         -    fprintf (stderr, "Shaded Relief specific arguments:\n");
  1985         -    fprintf (stderr, "---------------------------------\n");
  1986         -    fprintf (stderr,
  1987         -	     "-sr or --shaded-relief            *disabled by default*\n");
  1988         -    fprintf (stderr, "-m or --monochrome    0xRRGGBB    [default = none]\n");
  1989         -    fprintf (stderr, "-z or --z-factor      numeric     [default = 1.0]\n");
  1990         -    fprintf (stderr, "-s or --scale-factor  numeric     [default = 1.0]\n");
  1991         -    fprintf (stderr, "-az or --azimuth      numeric     [default = 315.0]\n");
  1992         -    fprintf (stderr, "-al or --altitude     numeric     [default = 45.0]\n\n");
  1993         -    fprintf (stderr, "Please note: --monochrome and --color-path are\n");
  1994         -    fprintf (stderr, "mutually exclusive options\n");
         1071  +    fprintf (stderr, "-v or --verbose                   verbose output\n");
  1995   1072   }
  1996   1073   
  1997   1074   int
  1998   1075   main (int argc, char *argv[])
  1999   1076   {
  2000   1077   /* the MAIN function simply perform arguments checking */
  2001   1078       int i;
................................................................................
  2008   1085       int verbose = 0;
  2009   1086       int error = 0;
  2010   1087       struct colorTable *color_table = NULL;
  2011   1088       unsigned char no_red = 0;
  2012   1089       unsigned char no_green = 0;
  2013   1090       unsigned char no_blue = 0;
  2014   1091       char error_nodata_color[1024];
  2015         -    int shaded_relief = 0;
  2016         -    int mono_color = 0;
  2017         -    unsigned char mono_red = 0;
  2018         -    unsigned char mono_green = 0;
  2019         -    unsigned char mono_blue = 0;
  2020         -    char error_mono_color[1024];
  2021         -    double z_factor = 1.0;
  2022         -    double scale_factor = 1.0;
  2023         -    double azimuth = 315.0;
  2024         -    double altitude = 45.0;
  2025         -    int colors;
  2026   1092       *error_nodata_color = '\0';
  2027         -    *error_mono_color = '\0';
  2028   1093       for (i = 1; i < argc; i++)
  2029   1094         {
  2030   1095   	  /* parsing the invocation arguments */
  2031   1096   	  if (next_arg != ARG_NONE)
  2032   1097   	    {
  2033   1098   		switch (next_arg)
  2034   1099   		  {
................................................................................
  2050   1115   		      if (strcasecmp (argv[i], "FLOAT") == 0)
  2051   1116   			  grid_type = FLOAT_GRID;
  2052   1117   		      break;
  2053   1118   		  case ARG_NODATA_COLOR:
  2054   1119   		      if (!parse_rgb (argv[i], &no_red, &no_green, &no_blue))
  2055   1120   			  strcpy (error_nodata_color, argv[i]);
  2056   1121   		      break;
  2057         -		  case ARG_MONO_COLOR:
  2058         -		      if (!parse_rgb
  2059         -			  (argv[i], &mono_red, &mono_green, &mono_blue))
  2060         -			  strcpy (error_mono_color, argv[i]);
  2061         -		      else
  2062         -			  mono_color = 1;
  2063         -		      break;
  2064         -		  case ARG_Z_FACTOR:
  2065         -		      z_factor = atof (argv[i]);
  2066         -		      break;
  2067         -		  case ARG_SCALE:
  2068         -		      scale_factor = atof (argv[i]);
  2069         -		      break;
  2070         -		  case ARG_AZIMUTH:
  2071         -		      azimuth = atof (argv[i]);
  2072         -		      break;
  2073         -		  case ARG_ALTITUDE:
  2074         -		      altitude = atof (argv[i]);
  2075         -		      break;
  2076   1122   		  };
  2077   1123   		next_arg = ARG_NONE;
  2078   1124   		continue;
  2079   1125   	    }
  2080   1126   	  if (strcasecmp (argv[i], "--help") == 0
  2081   1127   	      || strcmp (argv[i], "-?") == 0)
  2082   1128   	    {
................................................................................
  2149   1195   		continue;
  2150   1196   	    }
  2151   1197   	  if (strcmp (argv[i], "-v") == 0)
  2152   1198   	    {
  2153   1199   		verbose = 1;
  2154   1200   		continue;
  2155   1201   	    }
  2156         -	  if (strcasecmp (argv[i], "--shared-relief") == 0)
  2157         -	    {
  2158         -		shaded_relief = 1;
  2159         -		continue;
  2160         -	    }
  2161         -	  if (strcmp (argv[i], "-sr") == 0)
  2162         -	    {
  2163         -		shaded_relief = 1;
  2164         -		continue;
  2165         -	    }
  2166         -	  if (strcmp (argv[i], "-m") == 0)
  2167         -	    {
  2168         -		next_arg = ARG_MONO_COLOR;
  2169         -		continue;
  2170         -	    }
  2171         -	  if (strcasecmp (argv[i], "--monochrome") == 0)
  2172         -	    {
  2173         -		next_arg = ARG_MONO_COLOR;
  2174         -		continue;
  2175         -	    }
  2176         -	  if (strcmp (argv[i], "-z") == 0)
  2177         -	    {
  2178         -		next_arg = ARG_Z_FACTOR;
  2179         -		continue;
  2180         -	    }
  2181         -	  if (strcasecmp (argv[i], "--z-factor") == 0)
  2182         -	    {
  2183         -		next_arg = ARG_Z_FACTOR;
  2184         -		continue;
  2185         -	    }
  2186         -	  if (strcmp (argv[i], "-s") == 0)
  2187         -	    {
  2188         -		next_arg = ARG_SCALE;
  2189         -		continue;
  2190         -	    }
  2191         -	  if (strcasecmp (argv[i], "--scale-factor") == 0)
  2192         -	    {
  2193         -		next_arg = ARG_SCALE;
  2194         -		continue;
  2195         -	    }
  2196         -	  if (strcmp (argv[i], "-az") == 0)
  2197         -	    {
  2198         -		next_arg = ARG_AZIMUTH;
  2199         -		continue;
  2200         -	    }
  2201         -	  if (strcasecmp (argv[i], "--azimuth") == 0)
  2202         -	    {
  2203         -		next_arg = ARG_AZIMUTH;
  2204         -		continue;
  2205         -	    }
  2206         -	  if (strcmp (argv[i], "-al") == 0)
  2207         -	    {
  2208         -		next_arg = ARG_ALTITUDE;
  2209         -		continue;
  2210         -	    }
  2211         -	  if (strcasecmp (argv[i], "--altitude") == 0)
  2212         -	    {
  2213         -		next_arg = ARG_ALTITUDE;
  2214         -		continue;
  2215         -	    }
  2216   1202   	  fprintf (stderr, "unknown argument: %s\n", argv[i]);
  2217   1203   	  error = 1;
  2218   1204         }
  2219   1205       if (error)
  2220   1206         {
  2221   1207   	  do_help ();
  2222   1208   	  return -1;
................................................................................
  2224   1210   /* checking the arguments */
  2225   1211       if (!grid_path)
  2226   1212         {
  2227   1213   	  fprintf (stderr,
  2228   1214   		   "did you forget setting the --grid-path argument ?\n");
  2229   1215   	  error = 1;
  2230   1216         }
  2231         -    if (!shaded_relief)
         1217  +    if (!color_path)
  2232   1218         {
  2233         -	  if (!color_path)
  2234         -	    {
  2235         -		fprintf (stderr,
  2236         -			 "did you forget setting the --color-path argument ?\n");
  2237         -		error = 1;
  2238         -	    }
         1219  +	  fprintf (stderr,
         1220  +		   "did you forget setting the --color-path argument ?\n");
         1221  +	  error = 1;
  2239   1222         }
  2240   1223       if (!tiff_path)
  2241   1224         {
  2242   1225   	  fprintf (stderr,
  2243   1226   		   "did you forget setting the --tiff-path argument ?\n");
  2244   1227   	  error = 1;
  2245   1228         }
................................................................................
  2256   1239   	  error = 1;
  2257   1240         }
  2258   1241       if (strlen (error_nodata_color))
  2259   1242         {
  2260   1243   	  printf ("invalid NODATA color '%s'\n", error_nodata_color);
  2261   1244   	  error = 1;
  2262   1245         }
  2263         -    if (strlen (error_mono_color))
  2264         -      {
  2265         -	  printf ("invalid Shaded Relief Monochrome color '%s'\n",
  2266         -		  error_mono_color);
  2267         -	  error = 1;
  2268         -      }
  2269         -    if (color_path && mono_color)
  2270         -      {
  2271         -	  printf ("--monochrome and --color-path are mutually exclusive\n");
  2272         -	  error = 1;
  2273         -      }
  2274   1246       if (error)
  2275   1247         {
  2276   1248   	  do_help ();
  2277   1249   	  return -1;
  2278   1250         }
  2279   1251       printf ("=====================================================\n");
  2280   1252       printf ("             Arguments Summary\n");
  2281   1253       printf ("=====================================================\n");
  2282   1254       printf ("Grid       pathname: '%s'\n", grid_path);
  2283         -    if (color_path)
  2284         -	printf ("ColorTable pathname: '%s'\n", color_path);
         1255  +    printf ("ColorTable pathname: '%s'\n", color_path);
  2285   1256       printf ("GeoTIFF    pathname: '%s'\n", tiff_path);
  2286   1257       printf ("PROJ.4       string: '%s'\n", proj4text);
  2287         -    printf ("NoData        color: 0x%02x%02x%02x\n", no_red, no_green, no_blue);
  2288   1258       switch (grid_type)
  2289   1259         {
  2290   1260         case ASCII_GRID:
  2291   1261   	  printf ("Grid Format: ASCII\n");
  2292   1262   	  break;
  2293   1263         case FLOAT_GRID:
  2294   1264   	  printf ("Grid Format: FLOAT\n");
  2295   1265   	  break;
  2296   1266         default:
  2297   1267   	  printf ("Grid Format: UNKNOWN\n");
  2298   1268   	  break;
  2299   1269         }
  2300         -    if (shaded_relief)
         1270  +    printf ("=====================================================\n\n");
         1271  +    color_table = parse_color_table (color_path);
         1272  +    if (!color_table)
  2301   1273         {
  2302         -	  printf ("\n           Shaded Relief arguments:\n");
  2303         -	  printf ("-----------------------------------------------------\n");
  2304         -	  printf ("Z-factor     : %1.4f\n", z_factor);
  2305         -	  printf ("Scale-factor : %1.4f\n", scale_factor);
  2306         -	  printf ("Azimuth      : %1.4f\n", azimuth);
  2307         -	  printf ("Altitude     : %1.4f\n", altitude);
  2308         -	  if (mono_color)
  2309         -	      printf ("Monochrome   : 0x%02x%02x%02x\n", mono_red, mono_green,
  2310         -		      mono_blue);
         1274  +	  fprintf (stderr, "\n*********** Invalid Color Table\n");
         1275  +	  return -1;
  2311   1276         }
  2312         -    printf ("=====================================================\n\n");
  2313         -    if (color_path)
  2314         -      {
  2315         -	  color_table = parse_color_table (color_path, &colors);
  2316         -	  if (!color_table)
  2317         -	    {
  2318         -		fprintf (stderr, "\n*********** Invalid Color Table\n");
  2319         -		return -1;
  2320         -	    }
  2321         -      }
  2322         -    if (shaded_relief)
  2323         -      {
  2324         -	  if (grid_type == FLOAT_GRID)
  2325         -	      export_geoTiff_shaded_float (color_table, colors, proj4text,
  2326         -					   grid_path, tiff_path, no_red,
  2327         -					   no_green, no_blue, mono_color,
  2328         -					   mono_red, mono_green, mono_blue,
  2329         -					   z_factor, scale_factor, azimuth,
  2330         -					   altitude, verbose);
  2331         -	  else
  2332         -	      export_geoTiff_shaded_ascii (color_table, colors, proj4text,
  2333         -					   grid_path, tiff_path, no_red,
  2334         -					   no_green, no_blue, mono_color,
  2335         -					   mono_red, mono_green, mono_blue,
  2336         -					   z_factor, scale_factor, azimuth,
  2337         -					   altitude, verbose);
  2338         -      }
         1277  +    if (grid_type == FLOAT_GRID)
         1278  +	export_geoTiff_float (color_table, proj4text, grid_path, tiff_path,
         1279  +			      no_red, no_green, no_blue, verbose);
  2339   1280       else
  2340         -      {
  2341         -	  if (grid_type == FLOAT_GRID)
  2342         -	      export_geoTiff_float (color_table, colors, proj4text, grid_path,
  2343         -				    tiff_path, no_red, no_green, no_blue,
  2344         -				    verbose);
  2345         -	  else
  2346         -	      export_geoTiff_ascii (color_table, colors, proj4text, grid_path,
  2347         -				    tiff_path, no_red, no_green, no_blue,
  2348         -				    verbose);
  2349         -      }
  2350         -    if (color_table)
  2351         -	free (color_table);
         1281  +	export_geoTiff_ascii (color_table, proj4text, grid_path, tiff_path,
         1282  +			      no_red, no_green, no_blue, verbose);
         1283  +    free (color_table);
  2352   1284       return 0;
  2353   1285   }

Changes to src/rasterlite_load.c.

  1203   1203       if (ret != SQLITE_OK)
  1204   1204         {
  1205   1205   	  printf ("COMMIT TRANSACTION error: %s\n", sql_err);
  1206   1206   	  sqlite3_free (sql_err);
  1207   1207   	  goto stop;
  1208   1208         }
  1209   1209   
  1210         -    if (tif)
  1211         -	XTIFFClose (tif);
  1212         -    if (gtif)
  1213         -	GTIFFree (gtif);
  1214   1210       for (i = 0; i < NTILES; i++)
  1215   1211         {
  1216   1212   	  tile = &(infos.tiles[i]);
  1217   1213   	  if (tile->geometry)
  1218   1214   	      gaiaFreeGeomColl (tile->geometry);
  1219   1215         }
  1220   1216