color_free.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <stdlib.h>
  2. #include <grass/gis.h>
  3. /*!
  4. * \brief free color structure memory
  5. *
  6. * The dynamically allocated memory associated with the <b>colors</b>
  7. * structure is freed.
  8. * <b>Note.</b> This routine may be used after <i>G_read_colors</i> as
  9. * well as after <i>G_init_colors.</i>
  10. *
  11. * \param colors
  12. * \return
  13. */
  14. void G_free_colors(struct Colors *colors)
  15. {
  16. G__color_reset(colors);
  17. G_init_colors(colors);
  18. }
  19. /*******************************************
  20. * G__color* routines only to be used by other routines in this
  21. * library
  22. *******************************************/
  23. void G__color_free_rules(struct _Color_Info_ *cp)
  24. {
  25. struct _Color_Rule_ *rule, *next;
  26. for (rule = cp->rules; rule; rule = next) {
  27. next = rule->next;
  28. G_free(rule);
  29. }
  30. cp->rules = NULL;
  31. }
  32. void G__color_free_lookup(struct _Color_Info_ *cp)
  33. {
  34. if (cp->lookup.active) {
  35. G_free(cp->lookup.red);
  36. G_free(cp->lookup.blu);
  37. G_free(cp->lookup.grn);
  38. G_free(cp->lookup.set);
  39. cp->lookup.active = 0;
  40. }
  41. }
  42. void G__color_free_fp_lookup(struct _Color_Info_ *cp)
  43. {
  44. if (cp->fp_lookup.active) {
  45. G_free(cp->fp_lookup.vals);
  46. G_free(cp->fp_lookup.rules);
  47. cp->fp_lookup.active = 0;
  48. cp->fp_lookup.nalloc = 0;
  49. }
  50. }
  51. void G__color_reset(struct Colors *colors)
  52. {
  53. G__color_free_lookup(&colors->fixed);
  54. G__color_free_lookup(&colors->modular);
  55. G__color_free_rules(&colors->fixed);
  56. G__color_free_rules(&colors->modular);
  57. colors->version = 0;
  58. /* this routine should NOT init the colors */
  59. }