summaryrefslogtreecommitdiff
path: root/client/cd-iccdump.c
blob: 8482861cdee74a8ca8e0758685f8f6e5c9d8715d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 *
 * Copyright (C) 2013 Richard Hughes <richard@hughsie.com>
 *
 * Licensed under the GNU General Public License Version 2
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 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 General Public License for more details.
 *
 * You should have received a copy of the GNU 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.
 */

#include "config.h"

#include <glib/gi18n.h>
#include <locale.h>
#include <lcms2.h>
#include <lcms2_plugin.h>
#include <stdlib.h>
#include <math.h>
#include <colord-private.h>

static gint lcms_error_code = 0;

/**
 * cd_fix_profile_error_cb:
 **/
static void
cd_fix_profile_error_cb (cmsContext ContextID,
			 cmsUInt32Number errorcode,
			 const char *text)
{
	g_warning ("LCMS error %" G_GUINT32_FORMAT ": %s", errorcode, text);

	/* copy this sytemwide */
	lcms_error_code = errorcode;
}

/**
 * cd_iccdump_print_file:
 **/
static gboolean
cd_iccdump_print_file (const gchar *filename, GError **error)
{
	g_autofree gchar *str = NULL;
	g_autoptr(CdIcc) icc = NULL;
	g_autoptr(GFile) file = NULL;

	/* load the profile */
	icc = cd_icc_new ();
	file = g_file_new_for_path (filename);
	if (!cd_icc_load_file (icc, file, CD_ICC_LOAD_FLAGS_NONE, NULL, error))
		return FALSE;

	/* dump it to text on the console */
	str = cd_icc_to_string (icc);
	g_print ("%s\n", str);
	return TRUE;
}

/**
 * main:
 **/
int
main (int argc, char **argv)
{
	gboolean ret;
	GOptionContext *context;
	gint i;
	guint retval = EXIT_FAILURE;
	g_autoptr(GError) error = NULL;

	setlocale (LC_ALL, "");

	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	/* setup LCMS */
	cmsSetLogErrorHandler (cd_fix_profile_error_cb);
	context = g_option_context_new (NULL);

	/* TRANSLATORS: program name */
	g_set_application_name (_("ICC profile dump program"));
	ret = g_option_context_parse (context, &argc, &argv, &error);
	if (!ret) {
		/* TRANSLATORS: the user didn't read the man page */
		g_print ("%s: %s\n", _("Failed to parse arguments"),
			 error->message);
		goto out;
	}

	/* dump each option */
	for (i = 1; i < argc; i++) {
		ret = cd_iccdump_print_file (argv[i], &error);
		if (!ret) {
			g_warning ("Failed to dump %s: %s",
				   argv[i], error->message);
			goto out;
		}
	}

	/* success */
	retval = EXIT_SUCCESS;
out:
	g_option_context_free (context);
	return retval;
}