summaryrefslogtreecommitdiff
path: root/examples/cd-libcolord-icc.c
blob: d0a07854c4d73d6166f8db1a628bf4b9a6a87867 (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
/* -*- 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.
 */

//gcc -o cd-libcolord-icc cd-libcolord-icc.c `pkg-config --cflags --libs colord` -Wall

#include <stdlib.h>
#include <colord.h>
#include <locale.h>

int
main (int argc, char *argv[])
{
	CdIcc *icc = NULL;
	const gchar *locale;
	gboolean ret;
	GError *error = NULL;
	GFile *file = NULL;
	gint retval = EXIT_FAILURE;

	if (argc != 2) {
		g_warning ("usage: cd-libcolord-icc.c filename, e.g. /usr/share/color/icc/colord/sRGB.icc");
		goto out;
	}

	setlocale (LC_ALL, "");

	g_type_init ();

	icc = cd_icc_new ();
	file = g_file_new_for_path (argv[1]);
	ret = cd_icc_load_file (icc,
				file,
				CD_ICC_LOAD_FLAGS_METADATA,
				NULL, /* GCancellable */
				&error);
	if (!ret) {
		g_warning ("failed to parse %s: %s", argv[1], error->message);
		g_error_free (error);
		goto out;
	}

	/* get details about the profile */
	g_print ("Filename:\t%s\n", cd_icc_get_filename (icc));
	g_print ("License:\t%s\n", cd_icc_get_metadata_item (icc, "License"));
	g_print ("LCMS hProfile:\t%p\n", cd_icc_get_handle (icc));

	/* get translated UTF-8 strings where available */
	locale = g_getenv ("LANG");
	g_print ("Description:\t%s\n", cd_icc_get_description (icc, locale, NULL));
	g_print ("Model:\t\t%s\n", cd_icc_get_model (icc, locale, NULL));
	g_print ("Copyright:\t%s\n", cd_icc_get_copyright (icc, locale, NULL));

	retval = EXIT_SUCCESS;
out:
	if (file != NULL)
		g_object_unref (file);
	if (icc != NULL)
		g_object_unref (icc);
	return retval;
}