GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71746
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
color_free.c
Go to the documentation of this file.
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 
14 #include <stdlib.h>
15 
16 #include <grass/gis.h>
17 #include <grass/raster.h>
18 
19 /*!
20  * \brief Free color structure memory
21  *
22  * The dynamically allocated memory associated with the <i>colors</i>
23  * structure is freed.
24  *
25  * <b>Note:</b> This routine may be used after Rast_read_colors() as well
26  * as after Rast_init_colors().
27  *
28  * \param colors pointer to Colors structure
29  */
30 void Rast_free_colors(struct Colors *colors)
31 {
32  Rast__color_reset(colors);
33  Rast_init_colors(colors);
34 }
35 
36 /*!
37  \brief Free color rules structure
38 
39  Note: Only for internal use.
40 
41  \param cp pointer to _Color_Info structure
42  */
44 {
45  struct _Color_Rule_ *rule, *next;
46 
47  for (rule = cp->rules; rule; rule = next) {
48  next = rule->next;
49  G_free(rule);
50  }
51  cp->rules = NULL;
52 }
53 
54 /*!
55  \brief Free color rules structure
56 
57  Note: Only for internal use.
58 
59  \param cp pointer to _Color_Info structure
60  */
62 {
63  if (cp->lookup.active) {
64  G_free(cp->lookup.red);
65  G_free(cp->lookup.blu);
66  G_free(cp->lookup.grn);
67  G_free(cp->lookup.set);
68  cp->lookup.active = 0;
69  }
70 }
71 
72 /*!
73  \brief Free color rules structure
74 
75  Note: Only for internal use.
76 
77  \param cp pointer to _Color_Info structure
78  */
80 {
81  if (cp->fp_lookup.active) {
82  G_free(cp->fp_lookup.vals);
83  G_free(cp->fp_lookup.rules);
84  cp->fp_lookup.active = 0;
85  cp->fp_lookup.nalloc = 0;
86  }
87 }
88 
89 /*!
90  \brief Reset colors structure
91 
92  Note: Only for internal use.
93 
94  This routine should NOT init the colors.
95 
96  \param colors pointer to Colors structure
97  */
98 void Rast__color_reset(struct Colors *colors)
99 {
100  Rast__color_free_lookup(&colors->fixed);
102  Rast__color_free_rules(&colors->fixed);
104  colors->version = 0;
105 }
void Rast__color_free_fp_lookup(struct _Color_Info_ *cp)
Free color rules structure.
Definition: color_free.c:79
struct _Color_Info_ fixed
Definition: gis.h:640
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:149
unsigned char * blu
Definition: gis.h:608
unsigned char * red
Definition: gis.h:606
int version
Definition: gis.h:628
struct _Color_Rule_ * next
Definition: gis.h:595
unsigned char * grn
Definition: gis.h:607
int nalloc
Definition: gis.h:610
#define NULL
Definition: ccmath.h:32
void Rast_init_colors(struct Colors *colors)
Initialize color structure.
Definition: color_init.c:25
unsigned char * set
Definition: gis.h:609
DCELL * vals
Definition: gis.h:616
void Rast__color_free_lookup(struct _Color_Info_ *cp)
Free color rules structure.
Definition: color_free.c:61
void Rast_free_colors(struct Colors *colors)
Free color structure memory.
Definition: color_free.c:30
Definition: gis.h:626
int active
Definition: gis.h:611
struct _Color_Info_::@3 lookup
struct _Color_Info_ modular
Definition: gis.h:641
struct _Color_Info_::@4 fp_lookup
void Rast__color_reset(struct Colors *colors)
Reset colors structure.
Definition: color_free.c:98
void Rast__color_free_rules(struct _Color_Info_ *cp)
Free color rules structure.
Definition: color_free.c:43
struct _Color_Rule_ * rules
Definition: gis.h:601