21 #include <grass/gjson.h>
25 #define COLOR_STRING_LENGTH 30
32 static void close_file(FILE *fp)
55 snprintf(color_string,
sizeof(color_string),
"rgb(%d, %d, %d)",
r,
g,
61 snprintf(color_string,
sizeof(color_string),
"#%02X%02X%02X",
r,
g,
b);
67 snprintf(color_string,
sizeof(color_string),
"hsv(%d, %d, %d)", (
int)h,
73 snprintf(color_string,
sizeof(color_string),
"%d:%d:%d",
r,
g,
b);
100 static int r0 = -1, g0 = -1, b0 = -1;
103 if (v0 == *val && r0 ==
r && g0 ==
g && b0 ==
b)
106 v0 = *val, r0 =
r, g0 =
g, b0 =
b;
109 if (color_value ==
NULL) {
112 G_fatal_error(
_(
"Failed to initialize JSON object. Out of memory?"));
123 set_color(
r,
g,
b, clr_frmt, color_object);
142 if (root_value ==
NULL) {
144 G_fatal_error(
_(
"Failed to initialize JSON array. Out of memory?"));
155 for (
int i = lo; i <= hi; i++) {
156 unsigned char r,
g,
b, set;
161 write_json_rule(&val, &
min, &
max,
r,
g,
b, root_array, perc,
162 clr_frmt, fp, root_value);
169 for (
int i = 0; i <
count; i++) {
171 unsigned char r1, g1, b1, r2, g2, b2;
175 colors,
count - 1 - i);
178 write_json_rule(&val1, &
min, &
max, r1, g1, b1, root_array, perc,
179 clr_frmt, fp, root_value);
180 write_json_rule(&val2, &
min, &
max, r2, g2, b2, root_array, perc,
181 clr_frmt, fp, root_value);
192 if (nv_value ==
NULL) {
196 _(
"Failed to initialize JSON object. Out of memory?"));
200 set_color(
r,
g,
b, clr_frmt, nv_object);
206 if (default_value ==
NULL) {
210 _(
"Failed to initialize JSON object. Out of memory?"));
214 set_color(
r,
g,
b, clr_frmt, default_object);
void G_rgb_to_hsv(int, int, int, float *, float *, float *)
Converts RGB color values to HSV format.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int Rast_colors_count(const struct Colors *)
Get both modular and fixed rules count.
void Rast_get_c_color_range(CELL *, CELL *, const struct Colors *)
Get color range values (CELL)
int Rast_get_fp_color_rule(DCELL *, unsigned char *, unsigned char *, unsigned char *, DCELL *, unsigned char *, unsigned char *, unsigned char *, const struct Colors *, int)
Get color rule from both modular and fixed rules.
void Rast_get_null_value_color(int *, int *, int *, const struct Colors *)
Gets color for null value.
void Rast_lookup_c_colors(const CELL *, unsigned char *, unsigned char *, unsigned char *, unsigned char *, int, struct Colors *)
Lookup an array of colors.
void Rast_get_default_color(int *, int *, int *, const struct Colors *)
Gets default color.
char * G_json_serialize_to_string_pretty(const JSON_Value *value)
void G_json_value_free(JSON_Value *value)
void G_json_free_serialized_string(char *string)
JSON_Status G_json_object_set_number(JSON_Object *object, const char *name, double number)
JSON_Array * G_json_array(const JSON_Value *value)
JSON_Value * G_json_value_init_object(void)
JSON_Value * G_json_value_init_array(void)
JSON_Status G_json_object_set_string(JSON_Object *object, const char *name, const char *string)
JSON_Status G_json_array_append_value(JSON_Array *array, JSON_Value *value)
JSON_Object * G_json_object(const JSON_Value *value)
void Rast_print_json_colors(struct Colors *colors, DCELL min, DCELL max, FILE *fp, int perc, ColorFormat clr_frmt)
Print color table in JSON format.
#define COLOR_STRING_LENGTH
const char * json_string(const JSON_Value *value)
struct json_array_t JSON_Array
struct json_value_t JSON_Value
struct json_object_t JSON_Object
ColorFormat
Color format identifiers (enum)