Debian Codegraph @

examples/cd-libcolord-icc.c

raw
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2013 Richard Hughes <[email protected]>
4 *
5 * Licensed under the GNU General Public License Version 2
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 //gcc -o cd-libcolord-icc cd-libcolord-icc.c `pkg-config --cflags --libs colord` -Wall
23
24 #include <stdlib.h>
25 #include <colord.h>
26 #include <locale.h>
27
28 int
29 main (int argc, char *argv[])
30 {
31 CdIcc *icc = NULL;
32 const gchar *locale;
33 gboolean ret;
34 GError *error = NULL;
35 GFile *file = NULL;
36 gint retval = EXIT_FAILURE;
37
38 if (argc != 2) {
39 g_warning ("usage: cd-libcolord-icc.c filename, e.g. /usr/share/color/icc/colord/sRGB.icc");
40 goto out;
41 }
42
43 setlocale (LC_ALL, "");
44
45 g_type_init ();
46
47 icc = cd_icc_new ();
48 file = g_file_new_for_path (argv[1]);
49 ret = cd_icc_load_file (icc,
50 file,
51 CD_ICC_LOAD_FLAGS_METADATA,
52 NULL, /* GCancellable */
53 &error);
54 if (!ret) {
55 g_warning ("failed to parse %s: %s", argv[1], error->message);
56 g_error_free (error);
57 goto out;
58 }
59
60 /* get details about the profile */
61 g_print ("Filename:\t%s\n", cd_icc_get_filename (icc));
62 g_print ("License:\t%s\n", cd_icc_get_metadata_item (icc, "License"));
63 g_print ("LCMS hProfile:\t%p\n", cd_icc_get_handle (icc));
64
65 /* get translated UTF-8 strings where available */
66 locale = g_getenv ("LANG");
67 g_print ("Description:\t%s\n", cd_icc_get_description (icc, locale, NULL));
68 g_print ("Model:\t\t%s\n", cd_icc_get_model (icc, locale, NULL));
69 g_print ("Copyright:\t%s\n", cd_icc_get_copyright (icc, locale, NULL));
70
71 retval = EXIT_SUCCESS;
72 out:
73 if (file != NULL)
74 g_object_unref (file);
75 if (icc != NULL)
76 g_object_unref (icc);
77 return retval;
78 }