Changeset 69708
- Timestamp:
- Oct 19, 2016, 3:17:34 PM (8 years ago)
- Location:
- grass/trunk/lib/raster
- Files:
-
- 2 added
- 1 edited
-
color_rules.c (modified) (6 diffs)
-
testsuite (added)
-
testsuite/rast_parse_color_rule.py (added)
Legend:
- Unmodified
- Added
- Removed
-
grass/trunk/lib/raster/color_rules.c
r57540 r69708 1 1 /*! 2 \file lib/raster/color_r ead.c2 \file lib/raster/color_rules.c 3 3 4 4 \brief Raster Library - Read and parse color rules file 5 5 6 (C) 2007 by the GRASS Development Team6 (C) 2007-2016 by the GRASS Development Team 7 7 8 8 This program is free software under the GNU General Public … … 16 16 17 17 #include <grass/gis.h> 18 #include <grass/colors.h> 18 19 #include <grass/raster.h> 19 20 #include <grass/glocale.h> … … 29 30 { 30 31 CR_OK = 0, 31 CR_ERROR_SYNTAX, 32 CR_ERROR_RGB, 33 CR_ERROR_COLOR, 32 CR_ERROR_RULE_SYNTAX, 33 CR_ERROR_COLOR_SYNTAX, 34 34 CR_ERROR_PERCENT, 35 35 CR_ERROR_VALUE, … … 39 39 \brief Read color rule 40 40 41 \param min, max min & max values (used only when color rules are in percentage) 42 \param buf 43 \param val value 41 The val output parameter is always an absolute value and is derived 42 from the rule and the min and max values in case the rule is in percents. 43 44 Always only one of the norm, nval, and dflt output parameters is set 45 to non-zero value, the others are set to zero. 46 47 The return code can be translated to an error message using 48 the Rast_parse_color_rule_error() function. 49 50 \param min, max min & max values (used only when color rules are in percentage) 51 \param buf string with the color rule 52 \param[out] val value which the color is assigned to 44 53 \param[out] r,g,b color values 45 \param norm 46 \param nval 47 \param dflt 48 49 \return 0 on failure 50 \return 1 on success 54 \param[out] norm set to non-zero value if the value and color are set 55 \param[out] nval set to non-zero value if rule is for null value 56 \param[out] dflt set to non-zero value if rule specifies the default color 57 58 \returns enum rule_error values (non-zero on failure) 51 59 */ 52 60 int Rast_parse_color_rule(DCELL min, DCELL max, const char *buf, … … 61 69 62 70 if (sscanf(buf, "%s %[^\n]", value, color) != 2) 63 return CR_ERROR_SYNTAX; 64 65 G_chop(color); 66 67 if (sscanf(color, "%d:%d:%d", r, g, b) == 3 || 68 sscanf(color, "%d %d %d", r, g, b) == 3) { 69 if (*r < 0 || *r > 255 || *g < 0 || *g > 255 || *b < 0 || *b > 255) 70 return CR_ERROR_RGB; 71 } 72 else { 73 float fr, fg, fb; 74 75 if (G_color_values(color, &fr, &fg, &fb) < 0) 76 return CR_ERROR_COLOR; 77 78 *r = (int)(fr * 255.99); 79 *g = (int)(fg * 255.99); 80 *b = (int)(fb * 255.99); 81 } 71 return CR_ERROR_RULE_SYNTAX; 72 73 /* we don't allow 'none' color here (ret == 2) */ 74 /* G_str_to_color chops and has only 1 error state */ 75 if (G_str_to_color(color, r, g, b) != 1) 76 return CR_ERROR_COLOR_SYNTAX; 82 77 83 78 G_chop(value); … … 122 117 case CR_OK: 123 118 return ""; 124 case CR_ERROR_SYNTAX: 125 return _("syntax error"); 119 case CR_ERROR_RULE_SYNTAX: 120 return _("syntax error in the color rule"); 121 case CR_ERROR_COLOR_SYNTAX: 122 return _("syntax error in the color format"); 123 /* we no longer distinguish between these two errors 126 124 case CR_ERROR_RGB: 127 125 return _("R/G/B not in range 0-255"); 128 126 case CR_ERROR_COLOR: 129 127 return _("invalid color name"); 128 */ 130 129 case CR_ERROR_PERCENT: 131 130 return _("percentage not in range 0-100");
Note:
See TracChangeset
for help on using the changeset viewer.
