"graph" action: Print the "X-Generator" header on generated graphs, too.
[collection4.git] / src / common.c
index 2b6b5eb..3cd40d5 100644 (file)
@@ -1,8 +1,32 @@
+/**
+ * collection4 - common.c
+ * Copyright (C) 2010  Florian octo Forster
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301  USA
+ *
+ * Authors:
+ *   Florian octo Forster <ff at octo.it>
+ **/
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <inttypes.h>
 #include <string.h>
+#include <ctype.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -158,6 +182,23 @@ static uint32_t rgb_to_uint32 (double *rgb) /* {{{ */
       | ((uint32_t) b));
 } /* }}} uint32_t rgb_to_uint32 */
 
+static int uint32_to_rgb (uint32_t color, double *rgb)
+{
+  uint8_t r;
+  uint8_t g;
+  uint8_t b;
+
+  r = (uint8_t) ((color >> 16) & 0x00ff);
+  g = (uint8_t) ((color >>  8) & 0x00ff);
+  b = (uint8_t) ((color >>  0) & 0x00ff);
+
+  rgb[0] = ((double) r) / 255.0;
+  rgb[1] = ((double) g) / 255.0;
+  rgb[2] = ((double) b) / 255.0;
+
+  return (0);
+} /* }}} int uint32_to_rgb */
+
 uint32_t get_random_color (void) /* {{{ */
 {
   double hsv[3] = { 0.0, 1.0, 1.0 };
@@ -170,6 +211,18 @@ uint32_t get_random_color (void) /* {{{ */
   return (rgb_to_uint32 (rgb));
 } /* }}} uint32_t get_random_color */
 
+uint32_t fade_color (uint32_t color) /* {{{ */
+{
+  double rgb[3];
+
+  uint32_to_rgb (color, rgb);
+  rgb[0] = 1.0 - ((1.0 - rgb[0]) * 0.1);
+  rgb[1] = 1.0 - ((1.0 - rgb[1]) * 0.1);
+  rgb[2] = 1.0 - ((1.0 - rgb[2]) * 0.1);
+
+  return (rgb_to_uint32 (rgb));
+} /* }}} uint32_t fade_color */
+
 int print_debug (const char *format, ...) /* {{{ */
 {
   static _Bool have_header = 0;
@@ -190,4 +243,25 @@ int print_debug (const char *format, ...) /* {{{ */
   return (status);
 } /* }}} int print_debug */
 
+char *strtolower (char *str) /* {{{ */
+{
+  unsigned int i;
+
+  if (str == NULL)
+    return (NULL);
+
+  for (i = 0; str[i] != 0; i++)
+    str[i] = (char) tolower ((int) str[i]);
+
+  return (str);
+} /* }}} char *strtolower */
+
+char *strtolower_copy (const char *str)
+{
+  if (str == NULL)
+    return (NULL);
+
+  return (strtolower (strdup (str)));
+}
+
 /* vim: set sw=2 sts=2 et fdm=marker : */