color_free.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*!
  2. * \file lib/raster/color_free.c
  3. *
  4. * \brief Raster Library - Free Colors structure
  5. *
  6. * (C) 2001-2009 by the GRASS Development Team
  7. *
  8. * This program is free software under the GNU General Public License
  9. * (>=v2). Read the file COPYING that comes with GRASS for details.
  10. *
  11. * \author Original author CERL
  12. */
  13. #include <stdlib.h>
  14. #include <grass/gis.h>
  15. #include <grass/raster.h>
  16. /*!
  17. * \brief Free color structure memory
  18. *
  19. * The dynamically allocated memory associated with the <i>colors</i>
  20. * structure is freed.
  21. *
  22. * <b>Note:</b> This routine may be used after Rast_read_colors() as well
  23. * as after Rast_init_colors().
  24. *
  25. * \param colors pointer to Colors structure
  26. */
  27. void Rast_free_colors(struct Colors *colors)
  28. {
  29. Rast__color_reset(colors);
  30. Rast_init_colors(colors);
  31. }
  32. /*!
  33. \brief Free color rules structure
  34. Note: Only for internal use.
  35. \param cp pointer to _Color_Info structure
  36. */
  37. void Rast__color_free_rules(struct _Color_Info_ *cp)
  38. {
  39. struct _Color_Rule_ *rule, *next;
  40. for (rule = cp->rules; rule; rule = next) {
  41. next = rule->next;
  42. G_free(rule);
  43. }
  44. cp->rules = NULL;
  45. }
  46. /*!
  47. \brief Free color rules structure
  48. Note: Only for internal use.
  49. \param cp pointer to _Color_Info structure
  50. */
  51. void Rast__color_free_lookup(struct _Color_Info_ *cp)
  52. {
  53. if (cp->lookup.active) {
  54. G_free(cp->lookup.red);
  55. G_free(cp->lookup.blu);
  56. G_free(cp->lookup.grn);
  57. G_free(cp->lookup.set);
  58. cp->lookup.active = 0;
  59. }
  60. }
  61. /*!
  62. \brief Free color rules structure
  63. Note: Only for internal use.
  64. \param cp pointer to _Color_Info structure
  65. */
  66. void Rast__color_free_fp_lookup(struct _Color_Info_ *cp)
  67. {
  68. if (cp->fp_lookup.active) {
  69. G_free(cp->fp_lookup.vals);
  70. G_free(cp->fp_lookup.rules);
  71. cp->fp_lookup.active = 0;
  72. cp->fp_lookup.nalloc = 0;
  73. }
  74. }
  75. /*!
  76. \brief Reset colors structure
  77. Note: Only for internal use.
  78. This routine should NOT init the colors.
  79. \param colors pointer to Colors structure
  80. */
  81. void Rast__color_reset(struct Colors *colors)
  82. {
  83. Rast__color_free_lookup(&colors->fixed);
  84. Rast__color_free_lookup(&colors->modular);
  85. Rast__color_free_rules(&colors->fixed);
  86. Rast__color_free_rules(&colors->modular);
  87. colors->version = 0;
  88. }