diff options
author | Richard Hughes <richard@hughsie.com> | 2013-04-18 09:07:57 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2013-04-18 09:08:30 +0100 |
commit | 1d43d71c6a4ccc060183a76965016dcbbb97d769 (patch) | |
tree | 082da652458afbd2eab98099d9ee874fd5cb7172 | |
parent | 61c802498fe6decc7729d5a1f8ed7ad9a231d8f2 (diff) | |
download | colord-1d43d71c6a4ccc060183a76965016dcbbb97d769.tar.gz |
Add an example for using CdIcc in applications
-rw-r--r-- | examples/cd-libcolord-icc.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/examples/cd-libcolord-icc.c b/examples/cd-libcolord-icc.c new file mode 100644 index 0000000..5c58e63 --- /dev/null +++ b/examples/cd-libcolord-icc.c @@ -0,0 +1,75 @@ +/* -*- 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> + +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; + } + + 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; +} |