[babl] tools: add a tool for testing icc profile writing



commit 9132f318b1a28fb0daf43808071aa1b07f41a4c1
Author: Øyvind Kolås <pippin gimp org>
Date:   Tue Aug 22 14:00:21 2017 +0200

    tools: add a tool for testing icc profile writing

 tools/babl-icc-rewrite.c |  108 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 108 insertions(+), 0 deletions(-)
---
diff --git a/tools/babl-icc-rewrite.c b/tools/babl-icc-rewrite.c
new file mode 100644
index 0000000..4cce694
--- /dev/null
+++ b/tools/babl-icc-rewrite.c
@@ -0,0 +1,108 @@
+/* babl - dynamically extendable universal pixel conversion library.
+ * Copyright (C) 2005, 2017 Øyvind Kolås.
+ *
+ * This library 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 3 of the License, or (at your option) any later version.
+ *
+ * This library 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 library; if not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include <math.h>
+#include "../babl/babl-internal.h"
+
+static int
+file_get_contents (const char  *path,
+                   char       **contents,
+                   long        *length,
+                   void        *error);
+void file_set_contents (const char *path, const char *data, long length);
+
+int
+main (int    argc,
+      char **argv)
+{
+  const Babl *babl;
+  char *icc = NULL;
+  long  len;
+  int genlen;
+  char *error = NULL;
+  babl_init ();
+
+  if (!argv[1] || !argv[2])
+  {
+    fprintf (stderr, "usage: %s <input.icc> <output.icc>\n", argv[0]);
+    return -1;
+  }
+
+  if (file_get_contents (argv[1], &icc, &len, NULL))
+    return -1;
+
+  babl = babl_space_rgb_icc (icc, len, &error);
+  free (icc);
+
+  icc = (char *)babl_space_rgb_to_icc (babl, &genlen);
+  if (icc)
+  {
+    file_set_contents (argv[2], icc, genlen);
+  }
+
+  babl_exit ();
+  return 0;
+}
+
+static int
+file_get_contents (const char  *path,
+                   char       **contents,
+                   long        *length,
+                   void        *error)
+{
+  FILE *file;
+  long  size;
+  char *buffer;
+
+  file = fopen (path,"rb");
+
+  if (!file)
+    return -1;
+
+  fseek (file, 0, SEEK_END);
+  *length = size = ftell (file);
+  rewind (file);
+  buffer = malloc(size + 8);
+
+  if (!buffer)
+    {
+      fclose(file);
+      return -1;
+    }
+
+  size -= fread (buffer, 1, size, file);
+  if (size)
+    {
+      fclose (file);
+      free (buffer);
+      return -1;
+    }
+  fclose (file);
+  *contents = buffer;
+  return 0;
+}
+
+void file_set_contents (const char *path, const char *data, long length)
+{
+  FILE *fp = fopen (path, "wb");
+  if (length == -1)
+    length = strlen (data);
+  fwrite(data, length, 1, fp);
+  fclose (fp);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]