diff options
author | Richard Hughes <richard@hughsie.com> | 2012-05-09 10:39:01 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2012-05-09 10:39:01 +0100 |
commit | 1f1bffaa596be2f50605c84a760d963e98f5530e (patch) | |
tree | 8145d590cf446863956d6a4313594bf2b8fdfb75 | |
parent | bb1eac7825571ebd1c9481d9eca5a621ba76cb4c (diff) | |
download | colord-1f1bffaa596be2f50605c84a760d963e98f5530e.tar.gz |
Add functionality to colord-convert to sample ti1 -> ti3 files
-rw-r--r-- | client/Makefile.am | 5 | ||||
-rw-r--r-- | client/cd-convert.c | 265 | ||||
-rw-r--r-- | po/POTFILES.in | 1 |
3 files changed, 267 insertions, 4 deletions
diff --git a/client/Makefile.am b/client/Makefile.am index 583fc7e..27ba1f1 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -3,6 +3,7 @@ INCLUDES = \ $(GTK_CFLAGS) \ -I$(top_srcdir) \ -I$(top_srcdir)/libcolord \ + -I$(top_srcdir)/libcolord-gtk \ -DG_LOG_DOMAIN=\"Cd\" \ -DCD_COMPILATION \ -DLIBEXECDIR=\"$(libexecdir)\" \ @@ -11,7 +12,9 @@ INCLUDES = \ -DVERSION="\"$(VERSION)\"" \ -DLOCALEDIR=\""$(localedir)"\" -COLORD_LIBS = $(top_builddir)/libcolord/libcolord.la +COLORD_LIBS = \ + $(top_builddir)/libcolord/libcolord.la \ + $(top_builddir)/libcolord-gtk/libcolord-gtk.la noinst_LIBRARIES = libclientprivate.a libclientprivate_a_SOURCES = \ diff --git a/client/cd-convert.c b/client/cd-convert.c index 64aa440..e7a493b 100644 --- a/client/cd-convert.c +++ b/client/cd-convert.c @@ -23,8 +23,16 @@ #include <glib.h> #include <stdlib.h> +#include <gtk/gtk.h> +#include <glib/gi18n.h> +#include <gio/gio.h> +#include <locale.h> +#include "cd-sensor-sync.h" +#include "cd-device-sync.h" +#include "cd-client-sync.h" #include "cd-it8-utils.h" +#include "cd-sample-window.h" /** * cd_convert_ti3_ti3_to_ccmx: @@ -73,7 +81,7 @@ cd_convert_ti3_ti3_to_ccmx (const gchar *reference_fn, /* save file */ file_ccmx = g_file_new_for_path (device_fn); cd_it8_set_title (it8_ccmx, "Factory Calibration"); - cd_it8_set_originator (it8_ccmx, "cd-calibration"); + cd_it8_set_originator (it8_ccmx, "cd-convert"); cd_it8_add_option (it8_ccmx, "TYPE_FACTORY"); ret = cd_it8_save_to_file (it8_ccmx, file_ccmx, error); if (!ret) @@ -95,16 +103,218 @@ out: } /** + * cd_convert_setup_sensor: + **/ +static CdSensor * +cd_convert_setup_sensor (CdClient *client, + GError **error) +{ + CdSensor *sensor = NULL; + CdSensor *sensor_tmp; + gboolean ret; + GPtrArray *sensors = NULL; + + /* get sensor */ + sensors = cd_client_get_sensors_sync (client, NULL, error); + if (sensors == NULL) { + ret = FALSE; + goto out; + } + if (sensors->len == 0) { + ret = FALSE; + g_set_error_literal (error, 1, 0, + "No native sensors plugged in!"); + goto out; + } + sensor_tmp = g_ptr_array_index (sensors, 0); + ret = cd_sensor_connect_sync (sensor_tmp, NULL, error); + if (!ret) + goto out; + sensor = g_object_ref (sensor_tmp); +out: + if (sensors != NULL) + g_ptr_array_unref (sensors); + return sensor; +} + +/** + * cd_convert_idle_delay_cb: + **/ +static gboolean +cd_convert_idle_delay_cb (gpointer user_data) +{ + GMainLoop *loop = (GMainLoop *) user_data; + g_main_loop_quit (loop); + return FALSE; +} + +/** + * cd_convert_idle_delay: + **/ +static void +cd_convert_idle_delay (guint ms) +{ + GMainLoop *loop; + loop = g_main_loop_new (NULL, FALSE); + g_timeout_add (ms, cd_convert_idle_delay_cb, loop); + g_main_loop_run (loop); + g_main_loop_unref (loop); +} + +/** + * cd_convert_ti1_to_ti3: + **/ +static gboolean +cd_convert_ti1_to_ti3 (const gchar *patches_fn, + const gchar *measured_fn, + CdSensor *sensor, + GError **error) +{ + CdColorRGB rgb; + CdColorXYZ *xyz_tmp; + CdIt8 *it8_measured = NULL; + CdIt8 *it8_patches = NULL; + gboolean ret; + GFile *file_measured = NULL; + GFile *file_patches = NULL; + GtkWindow *sample_window = NULL; + guint i; + guint size; + + /* load patches */ + it8_patches = cd_it8_new (); + file_patches = g_file_new_for_path (patches_fn); + ret = cd_it8_load_from_file (it8_patches, + file_patches, + error); + if (!ret) + goto out; + + /* lock the sensor */ + ret = cd_sensor_lock_sync (sensor, + NULL, + error); + if (!ret) + goto out; + + /* create measurement file */ + sample_window = cd_sample_window_new (); + gtk_window_present (sample_window); + it8_measured = cd_it8_new_with_kind (CD_IT8_KIND_TI3); + size = cd_it8_get_data_size (it8_patches); + for (i = 0; i < size; i++) { + cd_it8_get_data_item (it8_patches, i, &rgb, NULL); + cd_sample_window_set_color (CD_SAMPLE_WINDOW (sample_window), &rgb); + cd_sample_window_set_fraction (CD_SAMPLE_WINDOW (sample_window), + (gdouble) i / (gdouble) size); + cd_convert_idle_delay (200); + + /* get the sample using the default matrix */ + xyz_tmp = cd_sensor_get_sample_sync (sensor, + CD_SENSOR_CAP_LCD, + NULL, + error); + if (xyz_tmp == NULL) { + ret = FALSE; + goto out; + } + + /* add to measured sheet */ + cd_it8_add_data (it8_measured, &rgb, xyz_tmp); + cd_color_xyz_free (xyz_tmp); + } + + /* unlock the sensor */ + ret = cd_sensor_unlock_sync (sensor, + NULL, + error); + if (!ret) + goto out; + + /* save file */ + file_measured = g_file_new_for_path (measured_fn); + cd_it8_set_title (it8_measured, "Calibration"); + cd_it8_set_originator (it8_measured, "cd-convert"); + cd_it8_set_instrument (it8_measured, cd_sensor_get_model (sensor)); + ret = cd_it8_save_to_file (it8_measured, file_measured, error); + if (!ret) + goto out; +out: + if (file_patches != NULL) + g_object_unref (file_patches); + if (file_measured != NULL) + g_object_unref (file_measured); + if (it8_patches != NULL) + g_object_unref (it8_patches); + if (it8_measured != NULL) + g_object_unref (it8_measured); + return ret; +} + +/** * main: **/ int main (int argc, char **argv) { + CdClient *client = NULL; + CdDevice *device = NULL; + CdSensor *sensor = NULL; gboolean ret; + gchar *device_id = NULL; GError *error = NULL; gint retval = EXIT_FAILURE; + GOptionContext *context; + guint xid = 0; + + const GOptionEntry options[] = { + { "device", '\0', 0, G_OPTION_ARG_STRING, &device_id, + /* TRANSLATORS: command line option */ + _("Use this device for profiling"), NULL }, + { "xid", '\0', 0, G_OPTION_ARG_INT, &xid, + /* TRANSLATORS: command line option */ + _("Make the window modal to this XID"), NULL }, + { NULL} + }; + + setlocale (LC_ALL, ""); + + bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); + + gtk_init (&argc, &argv); - g_type_init (); + /* TRANSLATORS: just dumps the EDID to disk */ + context = g_option_context_new (_("gcm-dispread")); + g_option_context_add_main_entries (context, options, NULL); + g_option_context_add_group (context, gtk_get_option_group (TRUE)); + ret = g_option_context_parse (context, &argc, &argv, &error); + if (!ret) + goto out; + + /* get client */ + client = cd_client_new (); + ret = cd_client_connect_sync (client, NULL, &error); + if (!ret) + goto out; + + /* check device */ + if (device_id != NULL) { + device = cd_client_find_device_sync (client, + device_id, + NULL, + &error); + if (device == NULL) { + ret = FALSE; + goto out; + } + ret = cd_device_connect_sync (device, + NULL, + &error); + if (!ret) + goto out; + } /* create a .ccmx from two .ti3 files */ if (argc == 4 && @@ -120,12 +330,61 @@ main (int argc, char **argv) g_error_free (error); goto out; } + } else if (argc == 3 && + g_str_has_suffix (argv[1], ".ti1") && + g_str_has_suffix (argv[2], ".ti3")) { + + /* get sensor */ + sensor = cd_convert_setup_sensor (client, &error); + if (sensor == NULL) { + ret = FALSE; + goto out; + } + + /* mark device to be profiled in colord */ + if (device != NULL) { + ret = cd_device_profiling_inhibit_sync (device, + NULL, + &error); + if (!ret) + goto out; + } + + /* run the samples */ + ret = cd_convert_ti1_to_ti3 (argv[1], + argv[2], + sensor, + &error); + if (!ret) { + g_print ("failed to create ti3: %s", error->message); + g_error_free (error); + goto out; + } } else { - g_print ("Usage: reference.ti3 measured.ti3 device.ccmx\n"); + ret = FALSE; + g_set_error_literal (&error, 1, 0, + "Specify one of:\n" + "patches.ti1 measured.ti3\n" + "reference.ti3 measured.ti3 device.ccmx"); + goto out; } /* success */ retval = EXIT_SUCCESS; out: + if (!ret) { + g_print ("%s: %s\n", + _("Failed to calibrate"), + error->message); + g_error_free (error); + } + g_option_context_free (context); + if (device != NULL) + g_object_unref (device); + if (client != NULL) + g_object_unref (client); + if (sensor != NULL) + g_object_unref (sensor); + g_free (device_id); return retval; } diff --git a/po/POTFILES.in b/po/POTFILES.in index aebed89..34044eb 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,3 +1,4 @@ +client/cd-convert.c client/cd-create-profile.c client/cd-fix-profile.c client/cd-util.c |