brewery
notashelf /
b6780cc1804075f6863dcf0a370a5bf645082014

chroma

public

Lightweight wallpaper daemon for Wayland

Star0tarball
clone
ssh://git@git.notashelf.dev:33/notashelf/chroma.git
src/config.cC665 lines22.2 KB
1
#include <ctype.h>
2
#include <errno.h>
3
#include <stdio.h>
4
#include <stdlib.h>
5
#include <string.h>
6
7
#include "../include/chroma.h"
8
9
static char *trim_whitespace(char *str) {
10
  char *end;
11
12
  // Trim leading whitespace
13
  while (isspace((unsigned char)*str))
14
    str++;
15
16
  // All spaces?
17
  if (*str == 0)
18
    return str;
19
20
  // Trim trailing whitespace
21
  end = str + strlen(str) - 1;
22
  while (end > str && isspace((unsigned char)*end))
23
    end--;
24
25
  *(end + 1) = '\0';
26
  return str;
27
}
28
29
// Remove quotes from a string
30
static char *remove_quotes(char *str) {
31
  size_t len = strlen(str);
32
  if (len >= 2 && ((str[0] == '"' && str[len - 1] == '"') ||
33
                   (str[0] == '\'' && str[len - 1] == '\''))) {
34
    str[len - 1] = '\0';
35
    return str + 1;
36
  }
37
  return str;
38
}
39
40
// Parse boolean value from string
41
static bool parse_bool(const char *value) {
42
  if (!value)
43
    return false;
44
45
  if (strcasecmp(value, "true") == 0 || strcasecmp(value, "yes") == 0 ||
46
      strcasecmp(value, "1") == 0 || strcasecmp(value, "on") == 0) {
47
    return true;
48
  }
49
50
  return false;
51
}
52
53
// Parse scaling mode from string
54
static chroma_scale_mode_t parse_scale_mode(const char *value) {
55
  if (!value)
56
    return CHROMA_SCALE_FILL; // default
57
58
  if (strcasecmp(value, "fill") == 0) {
59
    return CHROMA_SCALE_FILL;
60
  } else if (strcasecmp(value, "fit") == 0) {
61
    return CHROMA_SCALE_FIT;
62
  } else if (strcasecmp(value, "stretch") == 0) {
63
    return CHROMA_SCALE_STRETCH;
64
  } else if (strcasecmp(value, "center") == 0) {
65
    return CHROMA_SCALE_CENTER;
66
  }
67
68
  chroma_log("WARN", "Unknown scaling mode: %s (using fill)", value);
69
  return CHROMA_SCALE_FILL;
70
}
71
72
// Parse filter quality from string
73
static chroma_filter_quality_t parse_filter_quality(const char *value) {
74
  if (!value)
75
    return CHROMA_FILTER_LINEAR; // default
76
77
  if (strcasecmp(value, "nearest") == 0) {
78
    return CHROMA_FILTER_NEAREST;
79
  } else if (strcasecmp(value, "linear") == 0) {
80
    return CHROMA_FILTER_LINEAR;
81
  } else if (strcasecmp(value, "bilinear") == 0) {
82
    return CHROMA_FILTER_BILINEAR;
83
  } else if (strcasecmp(value, "trilinear") == 0) {
84
    return CHROMA_FILTER_TRILINEAR;
85
  }
86
87
  chroma_log("WARN", "Unknown filter quality: %s (using linear)", value);
88
  return CHROMA_FILTER_LINEAR;
89
}
90
91
// Get string representation of scaling mode
92
static const char *scale_mode_to_string(chroma_scale_mode_t mode) {
93
  switch (mode) {
94
  case CHROMA_SCALE_FILL:
95
    return "fill";
96
  case CHROMA_SCALE_FIT:
97
    return "fit";
98
  case CHROMA_SCALE_STRETCH:
99
    return "stretch";
100
  case CHROMA_SCALE_CENTER:
101
    return "center";
102
  default:
103
    return "unknown";
104
  }
105
}
106
107
// Get string representation of filter quality
108
static const char *filter_quality_to_string(chroma_filter_quality_t quality) {
109
  switch (quality) {
110
  case CHROMA_FILTER_NEAREST:
111
    return "nearest";
112
  case CHROMA_FILTER_LINEAR:
113
    return "linear";
114
  case CHROMA_FILTER_BILINEAR:
115
    return "bilinear";
116
  case CHROMA_FILTER_TRILINEAR:
117
    return "trilinear";
118
  default:
119
    return "unknown";
120
  }
121
}
122
123
// Parse anchor position from string
124
static chroma_anchor_t parse_anchor(const char *value) {
125
  if (!value)
126
    return CHROMA_ANCHOR_CENTER;
127
128
  if (strcasecmp(value, "center") == 0) {
129
    return CHROMA_ANCHOR_CENTER;
130
  } else if (strcasecmp(value, "top") == 0) {
131
    return CHROMA_ANCHOR_TOP;
132
  } else if (strcasecmp(value, "bottom") == 0) {
133
    return CHROMA_ANCHOR_BOTTOM;
134
  } else if (strcasecmp(value, "left") == 0) {
135
    return CHROMA_ANCHOR_LEFT;
136
  } else if (strcasecmp(value, "right") == 0) {
137
    return CHROMA_ANCHOR_RIGHT;
138
  } else if (strcasecmp(value, "top-left") == 0 ||
139
             strcasecmp(value, "topleft") == 0) {
140
    return CHROMA_ANCHOR_TOP_LEFT;
141
  } else if (strcasecmp(value, "top-right") == 0 ||
142
             strcasecmp(value, "topright") == 0) {
143
    return CHROMA_ANCHOR_TOP_RIGHT;
144
  } else if (strcasecmp(value, "bottom-left") == 0 ||
145
             strcasecmp(value, "bottomleft") == 0) {
146
    return CHROMA_ANCHOR_BOTTOM_LEFT;
147
  } else if (strcasecmp(value, "bottom-right") == 0 ||
148
             strcasecmp(value, "bottomright") == 0) {
149
    return CHROMA_ANCHOR_BOTTOM_RIGHT;
150
  }
151
152
  chroma_log("WARN", "Unknown anchor: %s (using center)", value);
153
  return CHROMA_ANCHOR_CENTER;
154
}
155
156
// Get string representation of anchor position
157
static const char *anchor_to_string(chroma_anchor_t anchor) {
158
  switch (anchor) {
159
  case CHROMA_ANCHOR_CENTER:
160
    return "center";
161
  case CHROMA_ANCHOR_TOP:
162
    return "top";
163
  case CHROMA_ANCHOR_BOTTOM:
164
    return "bottom";
165
  case CHROMA_ANCHOR_LEFT:
166
    return "left";
167
  case CHROMA_ANCHOR_RIGHT:
168
    return "right";
169
  case CHROMA_ANCHOR_TOP_LEFT:
170
    return "top-left";
171
  case CHROMA_ANCHOR_TOP_RIGHT:
172
    return "top-right";
173
  case CHROMA_ANCHOR_BOTTOM_LEFT:
174
    return "bottom-left";
175
  case CHROMA_ANCHOR_BOTTOM_RIGHT:
176
    return "bottom-right";
177
  default:
178
    return "unknown";
179
  }
180
}
181
182
// Output-to-image mapping
183
static int add_output_mapping(chroma_config_t *config, const char *output_name,
184
                              const char *image_path,
185
                              chroma_scale_mode_t scale_mode,
186
                              chroma_filter_quality_t filter_quality,
187
                              chroma_anchor_t anchor) {
188
  if (!config || !output_name || !image_path) {
189
    return CHROMA_ERROR_INIT;
190
  }
191
192
  if (config->mapping_count >= MAX_OUTPUTS) {
193
    chroma_log("ERROR", "Maximum number of output mappings reached (%d)",
194
               MAX_OUTPUTS);
195
    return CHROMA_ERROR_MEMORY;
196
  }
197
198
  // Validate string lengths to prevent buffer overflow
199
  size_t output_len = strlen(output_name);
200
  size_t path_len = strlen(image_path);
201
202
  if (output_len >= sizeof(config->mappings[0].output_name)) {
203
    chroma_log("ERROR", "Output name too long: %s (max %zu)", output_name,
204
               sizeof(config->mappings[0].output_name) - 1);
205
    return CHROMA_ERROR_CONFIG;
206
  }
207
208
  if (path_len >= sizeof(config->mappings[0].image_path)) {
209
    chroma_log("ERROR", "Image path too long: %s (max %zu)", image_path,
210
               sizeof(config->mappings[0].image_path) - 1);
211
    return CHROMA_ERROR_CONFIG;
212
  }
213
214
  chroma_config_mapping_t *mapping = &config->mappings[config->mapping_count];
215
216
  strcpy(mapping->output_name, output_name);
217
  strcpy(mapping->image_path, image_path);
218
  mapping->scale_mode = scale_mode;
219
  mapping->filter_quality = filter_quality;
220
  mapping->anchor = anchor;
221
222
  config->mapping_count++;
223
224
  chroma_log(
225
      "DEBUG", "Added mapping: %s -> %s (scale: %s, filter: %s, anchor: %s)",
226
      output_name, image_path, scale_mode_to_string(scale_mode),
227
      filter_quality_to_string(filter_quality), anchor_to_string(anchor));
228
  chroma_log("TRACE", "Output mapping %d: '%s' -> '%s' (path length: %zu)",
229
             config->mapping_count, output_name, image_path, path_len);
230
  return CHROMA_OK;
231
}
232
233
// Initialize configuration with defaults
234
static void init_default_config(chroma_config_t *config) {
235
  if (!config)
236
    return;
237
238
  memset(config, 0, sizeof(chroma_config_t));
239
240
  config->daemon_mode = false;
241
  config->mapping_count = 0;
242
243
  // Set default scaling and filtering
244
  config->default_scale_mode = CHROMA_SCALE_FILL;
245
  config->default_filter_quality = CHROMA_FILTER_LINEAR;
246
  config->default_anchor = CHROMA_ANCHOR_CENTER;
247
248
  // Set default downsampling settings
249
  config->enable_downsampling = true; // enable by default, performance etc.
250
  config->max_output_width = 3840;    // 4K width
251
  config->max_output_height = 2160;   // 4K height
252
  config->min_scale_factor = 0.25f;   // don't scale below 25%
253
254
  // Set default image path (can be overridden)
255
  const char *home = getenv("HOME");
256
  if (home) {
257
    snprintf(config->default_image, sizeof(config->default_image),
258
             "%s/.config/chroma/default.jpg", home);
259
  } else {
260
    strcpy(config->default_image, "/usr/share/pixmaps/chroma-default.jpg");
261
  }
262
}
263
264
// Parse a single configuration line
265
static int parse_config_line(chroma_config_t *config, char *line,
266
                             int line_number) {
267
  if (!config || !line) {
268
    return CHROMA_ERROR_INIT;
269
  }
270
271
  // Skip empty lines and comments
272
  char *trimmed = trim_whitespace(line);
273
  if (*trimmed == '\0' || *trimmed == '#' || *trimmed == ';') {
274
    return CHROMA_OK;
275
  }
276
277
  // Find the equals sign
278
  char *equals = strchr(trimmed, '=');
279
  if (!equals) {
280
    chroma_log("WARN", "Invalid config line %d: no '=' found", line_number);
281
    return CHROMA_OK; // continue parsing
282
  }
283
284
  *equals = '\0';
285
  char *key = trim_whitespace(trimmed);
286
  char *value = trim_whitespace(equals + 1);
287
288
  value = remove_quotes(value);
289
290
  if (*key == '\0' || *value == '\0') {
291
    chroma_log("WARN", "Invalid config line %d: empty key or value",
292
               line_number);
293
    return CHROMA_OK;
294
  }
295
296
  // Parse configuration options
297
  if (strcasecmp(key, "default_image") == 0) {
298
    char *expanded_path = chroma_expand_path(value);
299
    const char *path_to_use = expanded_path ? expanded_path : value;
300
    size_t path_len = strlen(path_to_use);
301
302
    if (path_len >= sizeof(config->default_image)) {
303
      chroma_log("ERROR", "Default image path too long: %s (max %zu)",
304
                 path_to_use, sizeof(config->default_image) - 1);
305
      if (expanded_path) {
306
        free(expanded_path);
307
      }
308
      return CHROMA_ERROR_CONFIG;
309
    }
310
311
    strcpy(config->default_image, path_to_use);
312
313
    if (expanded_path) {
314
      chroma_log("DEBUG", "Set default image: %s -> %s", value, expanded_path);
315
      chroma_log("TRACE", "Default image path set: length=%zu, expanded='%s'",
316
                 path_len, expanded_path);
317
      free(expanded_path);
318
    } else {
319
      chroma_log("WARN", "Failed to expand path, using original: %s", value);
320
    }
321
  } else if (strcasecmp(key, "daemon") == 0 ||
322
             strcasecmp(key, "daemon_mode") == 0) {
323
    config->daemon_mode = parse_bool(value);
324
    chroma_log("DEBUG", "Set daemon mode: %s",
325
               config->daemon_mode ? "true" : "false");
326
    chroma_log("TRACE",
327
               "Daemon mode configuration: key='%s', value='%s', parsed=%s",
328
               key, value, config->daemon_mode ? "true" : "false");
329
  } else if (strcasecmp(key, "scale_mode") == 0 ||
330
             strcasecmp(key, "default_scale_mode") == 0) {
331
    config->default_scale_mode = parse_scale_mode(value);
332
    chroma_log("DEBUG", "Set default scale mode: %s",
333
               scale_mode_to_string(config->default_scale_mode));
334
    chroma_log("TRACE",
335
               "Scale mode configuration: key='%s', value='%s', parsed=%s", key,
336
               value, scale_mode_to_string(config->default_scale_mode));
337
  } else if (strcasecmp(key, "filter_quality") == 0 ||
338
             strcasecmp(key, "default_filter_quality") == 0) {
339
    config->default_filter_quality = parse_filter_quality(value);
340
    chroma_log("DEBUG", "Set default filter quality: %s",
341
               filter_quality_to_string(config->default_filter_quality));
342
    chroma_log("TRACE",
343
               "Filter quality configuration: key='%s', value='%s', parsed=%s",
344
               key, value,
345
               filter_quality_to_string(config->default_filter_quality));
346
  } else if (strcasecmp(key, "enable_downsampling") == 0) {
347
    config->enable_downsampling = parse_bool(value);
348
    chroma_log("DEBUG", "Set downsampling: %s",
349
               config->enable_downsampling ? "enabled" : "disabled");
350
  } else if (strcasecmp(key, "anchor") == 0) {
351
    config->default_anchor = parse_anchor(value);
352
    chroma_log("DEBUG", "Set default anchor: %s",
353
               anchor_to_string(config->default_anchor));
354
  } else if (strcasecmp(key, "max_output_width") == 0) {
355
    int width = atoi(value);
356
    if (width > 0 && width <= 16384) { // Reasonable limits
357
      config->max_output_width = width;
358
      chroma_log("DEBUG", "Set max output width: %d", width);
359
    } else {
360
      chroma_log("WARN", "Invalid max_output_width: %s (using 3840)", value);
361
    }
362
  } else if (strcasecmp(key, "max_output_height") == 0) {
363
    int height = atoi(value);
364
    if (height > 0 && height <= 16384) { // Reasonable limits
365
      config->max_output_height = height;
366
      chroma_log("DEBUG", "Set max output height: %d", height);
367
    } else {
368
      chroma_log("WARN", "Invalid max_output_height: %s (using 2160)", value);
369
    }
370
  } else if (strcasecmp(key, "min_scale_factor") == 0) {
371
    float factor = atof(value);
372
    if (factor > 0.0f && factor <= 1.0f) { // Valid range
373
      config->min_scale_factor = factor;
374
      chroma_log("DEBUG", "Set minimum scale factor: %.2f", factor);
375
    } else {
376
      chroma_log("WARN", "Invalid min_scale_factor: %s (using 0.25)", value);
377
    }
378
  } else if (strncasecmp(key, "output.", 7) == 0) {
379
    // Output-specific mapping: e.g., output.DP-1=/path/to/image.jpg
380
    const char *output_name = key + 7;
381
    if (*output_name == '\0') {
382
      chroma_log("WARN", "Invalid output mapping line %d: no output name",
383
                 line_number);
384
      return CHROMA_OK;
385
    }
386
387
    // Check for extended output configuration with properties
388
    // Format: output.DP-1.scale = fill
389
    // Format: output.DP-1.filter = linear
390
    char *dot = strchr(output_name, '.');
391
    if (dot) {
392
      // This is an output property (scale or filter)
393
      *dot = '\0';
394
      const char *property = dot + 1;
395
396
      // Find existing mapping for this output
397
      chroma_config_mapping_t *mapping = NULL;
398
      for (int i = 0; i < config->mapping_count; i++) {
399
        if (strcmp(config->mappings[i].output_name, output_name) == 0) {
400
          mapping = &config->mappings[i];
401
          break;
402
        }
403
      }
404
405
      if (!mapping) {
406
        chroma_log("WARN", "Output %s not found for property %s (line %d)",
407
                   output_name, property, line_number);
408
        return CHROMA_OK;
409
      }
410
411
      if (strcasecmp(property, "scale") == 0) {
412
        mapping->scale_mode = parse_scale_mode(value);
413
        chroma_log("DEBUG", "Set scale mode for output %s: %s", output_name,
414
                   scale_mode_to_string(mapping->scale_mode));
415
      } else if (strcasecmp(property, "filter") == 0) {
416
        mapping->filter_quality = parse_filter_quality(value);
417
        chroma_log("DEBUG", "Set filter quality for output %s: %s", output_name,
418
                   filter_quality_to_string(mapping->filter_quality));
419
      } else if (strcasecmp(property, "anchor") == 0) {
420
        mapping->anchor = parse_anchor(value);
421
        chroma_log("DEBUG", "Set anchor for output %s: %s", output_name,
422
                   anchor_to_string(mapping->anchor));
423
      } else {
424
        chroma_log("WARN", "Unknown output property: %s (line %d)", property,
425
                   line_number);
426
      }
427
428
      return CHROMA_OK;
429
    }
430
431
    // Expand path before validation and storage
432
    char *expanded_path = chroma_expand_path(value);
433
    const char *path_to_validate = expanded_path ? expanded_path : value;
434
435
    // Validate image path
436
    if (chroma_image_validate(path_to_validate) != CHROMA_OK) {
437
      chroma_log("WARN", "Invalid image path for output %s: %s (expanded: %s)",
438
                 output_name, value, path_to_validate);
439
      if (expanded_path) {
440
        free(expanded_path);
441
      }
442
      return CHROMA_OK;
443
    }
444
445
    if (add_output_mapping(config, output_name, path_to_validate,
446
                           config->default_scale_mode,
447
                           config->default_filter_quality,
448
                           config->default_anchor) != CHROMA_OK) {
449
      chroma_log("ERROR", "Failed to add output mapping: %s -> %s", output_name,
450
                 path_to_validate);
451
      if (expanded_path) {
452
        free(expanded_path);
453
      }
454
      return CHROMA_ERROR_CONFIG;
455
    }
456
457
    if (expanded_path) {
458
      free(expanded_path);
459
    }
460
  } else {
461
    chroma_log("WARN", "Unknown configuration key line %d: %s", line_number,
462
               key);
463
    chroma_log("TRACE", "Unrecognized config line %d: key='%s', value='%s'",
464
               line_number, key, value);
465
  }
466
467
  return CHROMA_OK;
468
}
469
470
// Load configuration from file
471
int chroma_config_load(chroma_config_t *config, const char *config_file) {
472
  if (!config) {
473
    return CHROMA_ERROR_INIT;
474
  }
475
476
  // Initialize with defaults
477
  init_default_config(config);
478
479
  if (!config_file) {
480
    chroma_log("INFO", "No config file specified, using defaults");
481
    return CHROMA_OK;
482
  }
483
484
  FILE *file = fopen(config_file, "r");
485
  if (!file) {
486
    if (errno == ENOENT) {
487
      chroma_log("INFO", "Config file not found: %s (using defaults)",
488
                 config_file);
489
      return CHROMA_OK;
490
    } else {
491
      chroma_log("ERROR", "Failed to open config file %s: %s", config_file,
492
                 strerror(errno));
493
      return CHROMA_ERROR_CONFIG;
494
    }
495
  }
496
497
  chroma_log("INFO", "Loading configuration from: %s", config_file);
498
  chroma_log("TRACE",
499
             "Starting configuration parsing, estimated config size: %ld bytes",
500
             chroma_get_file_size(config_file));
501
502
  char line[1024];
503
  int line_number = 0;
504
  int parse_errors = 0;
505
506
  while (fgets(line, sizeof(line), file)) {
507
    line_number++;
508
509
    char *newline = strchr(line, '\n');
510
    if (newline) {
511
      *newline = '\0';
512
    }
513
514
    if (parse_config_line(config, line, line_number) != CHROMA_OK) {
515
      parse_errors++;
516
    }
517
  }
518
519
  fclose(file);
520
521
  if (parse_errors > 0) {
522
    chroma_log("WARN", "Config file contained %d errors", parse_errors);
523
    // Continue anyway with partial configuration
524
  }
525
526
  chroma_log("INFO",
527
             "Loaded configuration: %d output mappings, default image: %s",
528
             config->mapping_count, config->default_image);
529
530
  // Log configuration memory usage
531
  size_t config_size =
532
      sizeof(chroma_config_t) +
533
      (config->mapping_count * sizeof(chroma_config_mapping_t));
534
  chroma_log_resource_allocation("config_data", config_size,
535
                                 "configuration structure");
536
  chroma_log_memory_stats("post-config-load");
537
538
  return CHROMA_OK;
539
}
540
541
// Free configuration resources
542
void chroma_config_free(chroma_config_t *config) {
543
  if (!config) {
544
    return;
545
  }
546
547
  // Log configuration deallocation
548
  size_t config_size =
549
      sizeof(chroma_config_t) +
550
      (config->mapping_count * sizeof(chroma_config_mapping_t));
551
  chroma_log_resource_deallocation("config_data", config_size,
552
                                   "configuration structure");
553
554
  chroma_log("TRACE", "Clearing %d output mappings from configuration",
555
             config->mapping_count);
556
  memset(config->mappings, 0, sizeof(config->mappings));
557
  config->mapping_count = 0;
558
559
  memset(config->default_image, 0, sizeof(config->default_image));
560
561
  chroma_log("DEBUG", "Freed configuration");
562
}
563
564
// Get image path for specific output
565
const char *chroma_config_get_image_for_output(chroma_config_t *config,
566
                                               const char *output_name) {
567
  if (!config || !output_name) {
568
    return NULL;
569
  }
570
571
  // Look for specific output mapping
572
  for (int i = 0; i < config->mapping_count; i++) {
573
    if (strcmp(config->mappings[i].output_name, output_name) == 0) {
574
      chroma_log("DEBUG", "Found specific mapping for output %s: %s",
575
                 output_name, config->mappings[i].image_path);
576
      return config->mappings[i].image_path;
577
    }
578
  }
579
580
  // Return default image if no specific mapping found
581
  if (strlen(config->default_image) > 0) {
582
    chroma_log("DEBUG", "Using default image for output %s: %s", output_name,
583
               config->default_image);
584
    return config->default_image;
585
  }
586
587
  chroma_log("WARN", "No image configured for output: %s", output_name);
588
  return NULL;
589
}
590
591
// Get configuration mapping for output, including scale mode, filter
592
// quality, and anchor
593
int chroma_config_get_mapping_for_output(
594
    chroma_config_t *config, const char *output_name,
595
    chroma_scale_mode_t *scale_mode, chroma_filter_quality_t *filter_quality,
596
    chroma_anchor_t *anchor) {
597
  if (!config || !output_name || !scale_mode || !filter_quality || !anchor) {
598
    return CHROMA_ERROR_INIT;
599
  }
600
601
  // Look for specific output mapping
602
  for (int i = 0; i < config->mapping_count; i++) {
603
    if (strcmp(config->mappings[i].output_name, output_name) == 0) {
604
      *scale_mode = config->mappings[i].scale_mode;
605
      *filter_quality = config->mappings[i].filter_quality;
606
      *anchor = config->mappings[i].anchor;
607
      chroma_log("DEBUG",
608
                 "Found specific mapping for output %s: scale=%s, filter=%s, "
609
                 "anchor=%s",
610
                 output_name, scale_mode_to_string(*scale_mode),
611
                 filter_quality_to_string(*filter_quality),
612
                 anchor_to_string(*anchor));
613
      return CHROMA_OK;
614
    }
615
  }
616
617
  // Return defaults if no specific mapping found
618
  *scale_mode = config->default_scale_mode;
619
  *filter_quality = config->default_filter_quality;
620
  *anchor = config->default_anchor;
621
  chroma_log(
622
      "DEBUG", "Using defaults for output %s: scale=%s, filter=%s, anchor=%s",
623
      output_name, scale_mode_to_string(*scale_mode),
624
      filter_quality_to_string(*filter_quality), anchor_to_string(*anchor));
625
  return CHROMA_OK;
626
}
627
628
// Print current configuration for debugging
629
void chroma_config_print(const chroma_config_t *config) {
630
  if (!config) {
631
    return;
632
  }
633
634
  chroma_log("INFO", "=== Configuration ===");
635
  chroma_log("INFO", "Default image: %s", config->default_image);
636
  chroma_log("INFO", "Daemon mode: %s", config->daemon_mode ? "true" : "false");
637
  chroma_log("INFO", "Default scale mode: %s",
638
             scale_mode_to_string(config->default_scale_mode));
639
  chroma_log("INFO", "Default filter quality: %s",
640
             filter_quality_to_string(config->default_filter_quality));
641
  chroma_log("INFO", "Downsampling: %s",
642
             config->enable_downsampling ? "enabled" : "disabled");
643
  if (config->enable_downsampling) {
644
    chroma_log("INFO", "Max output size: %dx%d", config->max_output_width,
645
               config->max_output_height);
646
    chroma_log("INFO", "Min scale factor: %.2f", config->min_scale_factor);
647
  }
648
  chroma_log("INFO", "Output mappings: %d", config->mapping_count);
649
650
  for (int i = 0; i < config->mapping_count; i++) {
651
    chroma_log("INFO", "  %s -> %s (scale: %s, filter: %s)",
652
               config->mappings[i].output_name, config->mappings[i].image_path,
653
               scale_mode_to_string(config->mappings[i].scale_mode),
654
               filter_quality_to_string(config->mappings[i].filter_quality));
655
    chroma_log(
656
        "TRACE",
657
        "  Mapping %d: output='%s', image='%s', scale='%s', filter='%s', "
658
        "path_exists=%s",
659
        i, config->mappings[i].output_name, config->mappings[i].image_path,
660
        scale_mode_to_string(config->mappings[i].scale_mode),
661
        filter_quality_to_string(config->mappings[i].filter_quality),
662
        chroma_path_exists(config->mappings[i].image_path) ? "yes" : "no");
663
  }
664
  chroma_log("INFO", "====================");
665
}