summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTill Kamppeter <till.kamppeter@gmail.com>2013-05-30 14:41:07 +0200
committerTill Kamppeter <till.kamppeter@gmail.com>2013-05-30 14:41:07 +0200
commitc374882e38fdac7ef766c9ac1ec8674e02bd56bc (patch)
tree0832c02fd2c388fc4c9da275650f7d7df7b6aa7d
parent89c224b029357002c48660dae98de2d1e560d4e0 (diff)
downloadghostpdl-c374882e38fdac7ef766c9ac1ec8674e02bd56bc.tar.gz
Added support for printer calibration to the gstoraster CUPS filter
For doing calibration printouts the color management in the print filter chain needs to get turned off. This is done by calling Ghostscript with the "-dUseFastColor" command line option. Inhibiting color management can be done via colord, with a command like colormgr device-inhibit /org/freedesktop/ColorManager/devices/<printer> 0 or by sending the calibration print job with the option "color-management=off". Thanks to Richard Hughes for the patch.
-rw-r--r--gs/cups/colord.c126
-rw-r--r--gs/cups/colord.h3
-rw-r--r--gs/cups/gstoraster.c12
3 files changed, 129 insertions, 12 deletions
diff --git a/gs/cups/colord.c b/gs/cups/colord.c
index 88dbc9740..8783874b6 100644
--- a/gs/cups/colord.c
+++ b/gs/cups/colord.c
@@ -1,6 +1,6 @@
/*
Copyright (c) 2011, Tim Waugh
-Copyright (c) 2011, Richard Hughes
+Copyright (c) 2011-2013, Richard Hughes
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -262,11 +262,10 @@ out:
}
static char *
-get_profile_for_device_id (DBusConnection *con,
- const char *device_id,
- const char **qualifier_tuple)
+get_device_path_for_device_id (DBusConnection *con,
+ const char *device_id)
{
- char *profile = NULL;
+ char *device_path = NULL;
const char *device_path_tmp;
DBusError error;
DBusMessageIter args;
@@ -302,20 +301,21 @@ get_profile_for_device_id (DBusConnection *con,
}
dbus_message_iter_get_basic(&args, &device_path_tmp);
fprintf(stderr, "DEBUG: Found device %s\n", device_path_tmp);
- profile = get_profile_for_device_path(con, device_path_tmp, qualifier_tuple);
+ device_path = strdup(device_path_tmp);
out:
if (message != NULL)
dbus_message_unref(message);
if (reply != NULL)
dbus_message_unref(reply);
- return profile;
+ return device_path;
}
char *
colord_get_profile_for_device_id (const char *device_id,
- const char **qualifier_tuple)
+ const char **qualifier_tuple)
{
DBusConnection *con = NULL;
+ char *device_path = NULL;
char *filename = NULL;
if (device_id == NULL) {
@@ -330,19 +330,118 @@ colord_get_profile_for_device_id (const char *device_id,
goto out;
}
+ /* find the device */
+ device_path = get_device_path_for_device_id (con, device_id);
+ if (device_path == NULL) {
+ fprintf(stderr, "DEBUG: Failed to get find device %s\n", device_id);
+ goto out;
+ }
+
/* get the best profile for the device */
- filename = get_profile_for_device_id (con, device_id, qualifier_tuple);
+ filename = get_profile_for_device_path(con, device_path, qualifier_tuple);
if (filename == NULL) {
- fprintf(stderr, "DEBUG: Failed to get profile filename!\n");
+ fprintf(stderr, "DEBUG: Failed to get profile filename for %s\n", device_id);
goto out;
}
fprintf(stderr, "DEBUG: Use profile filename: '%s'\n", filename);
out:
+ free(device_path);
if (con != NULL)
dbus_connection_unref(con);
return filename;
}
+int
+get_profile_inhibitors (DBusConnection *con, const char *object_path)
+{
+ char *tmp;
+ const char *interface = "org.freedesktop.ColorManager.Device";
+ const char *property = "ProfilingInhibitors";
+ DBusError error;
+ DBusMessageIter args;
+ DBusMessageIter sub;
+ DBusMessageIter sub2;
+ DBusMessage *message = NULL;
+ DBusMessage *reply = NULL;
+ int inhibitors = 0;
+
+ message = dbus_message_new_method_call("org.freedesktop.ColorManager",
+ object_path,
+ "org.freedesktop.DBus.Properties",
+ "Get");
+
+ dbus_message_iter_init_append(message, &args);
+ dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &interface);
+ dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &property);
+
+ /* send syncronous */
+ dbus_error_init(&error);
+ fprintf(stderr, "DEBUG: Calling %s.Get(%s)\n", interface, property);
+ reply = dbus_connection_send_with_reply_and_block(con,
+ message,
+ -1,
+ &error);
+ if (reply == NULL) {
+ fprintf(stderr, "DEBUG: Failed to send: %s:%s\n",
+ error.name, error.message);
+ dbus_error_free(&error);
+ goto out;
+ }
+
+ /* get reply data */
+ dbus_message_iter_init(reply, &args);
+ if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_VARIANT) {
+ fprintf(stderr, "DEBUG: Incorrect reply type\n");
+ goto out;
+ }
+
+ /* count the size of the array */
+ dbus_message_iter_recurse(&args, &sub2);
+ dbus_message_iter_recurse(&sub2, &sub);
+ while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
+ dbus_message_iter_get_basic(&sub, &tmp);
+ fprintf(stderr, "DEBUG: Inhibitor %s exists\n", tmp);
+ dbus_message_iter_next(&sub);
+ inhibitors++;
+ }
+out:
+ if (message != NULL)
+ dbus_message_unref(message);
+ if (reply != NULL)
+ dbus_message_unref(reply);
+ return inhibitors;
+}
+
+int
+colord_get_inhibit_for_device_id (const char *device_id)
+{
+ DBusConnection *con;
+ char *device_path = NULL;
+ int has_inhibitors = FALSE;
+
+ /* connect to system bus */
+ con = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+ if (con == NULL) {
+ fprintf(stderr, "ERROR: Failed to connect to system bus\n");
+ goto out;
+ }
+
+ /* find the device */
+ device_path = get_device_path_for_device_id (con, device_id);
+ if (device_path == NULL) {
+ fprintf(stderr, "DEBUG: Failed to get find device %s\n", device_id);
+ goto out;
+ }
+
+ /* get the best profile for the device */
+ has_inhibitors = get_profile_inhibitors(con, device_path);
+out:
+ free(device_path);
+ if (con != NULL)
+ dbus_connection_unref(con);
+ return has_inhibitors;
+}
+
#else
char *
@@ -353,4 +452,11 @@ colord_get_profile_for_device_id (const char *device_id,
return NULL;
}
+int
+colord_get_inhibit_for_device_id (const char *device_id)
+{
+ fprintf(stderr, "WARN: not compiled with DBus support\n");
+ return 0;
+}
+
#endif
diff --git a/gs/cups/colord.h b/gs/cups/colord.h
index ceb54f49d..8f5c1423f 100644
--- a/gs/cups/colord.h
+++ b/gs/cups/colord.h
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2011, Richard Hughes
+Copyright (c) 2011-2013, Richard Hughes
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -32,3 +32,4 @@ MIT Open Source License - http://www.opensource.org/
char **colord_get_qualifier_for_ppd (ppd_file_t *ppd);
char *colord_get_profile_for_device_id (const char *device_id,
const char **qualifier_tuple);
+int colord_get_inhibit_for_device_id (const char *device_id);
diff --git a/gs/cups/gstoraster.c b/gs/cups/gstoraster.c
index eda6fc083..53945699f 100644
--- a/gs/cups/gstoraster.c
+++ b/gs/cups/gstoraster.c
@@ -2,7 +2,7 @@
Copyright (c) 2008, Till Kamppeter
Copyright (c) 2011, Tim Waugh
-Copyright (c) 2011, Richard Hughes
+Copyright (c) 2011-2013, Richard Hughes
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -525,6 +525,7 @@ main (int argc, char **argv, char *envp[])
GsDocType doc_type;
gs_page_header h;
int fd;
+ int device_inhibited;
int i;
int n;
int num_options;
@@ -594,6 +595,13 @@ main (int argc, char **argv, char *envp[])
goto out;
}
+ /* support colord and the "color-management=off" option */
+ device_inhibited = colord_get_inhibit_for_device_id (getenv("PRINTER"));
+ t = cupsGetOption("color-management", num_options, options);
+ if (t != NULL && strcmp(t, "off") == 0)
+ device_inhibited = TRUE;
+ if (device_inhibited)
+ fprintf(stderr, "DEBUG: Device is inhibited, no CM performed\n");
qualifier = colord_get_qualifier_for_ppd (ppd);
if (qualifier != NULL) {
@@ -630,6 +638,8 @@ main (int argc, char **argv, char *envp[])
cupsArrayAdd(gs_args, strdup("-dNOINTERPOLATE"));
if (doc_type == GS_DOC_TYPE_PS)
cupsArrayAdd(gs_args, strdup("-dNOMEDIAATTRS"));
+ if (device_inhibited)
+ cupsArrayAdd(gs_args, strdup("-dUseFastColor"));
cupsArrayAdd(gs_args, strdup("-sDEVICE=cups"));
cupsArrayAdd(gs_args, strdup("-sstdout=%stderr"));
cupsArrayAdd(gs_args, strdup("-sOutputFile=%stdout"));