From: Zdenek Dohnal Date: Mon, 22 May 2023 15:52:43 +0000 (+0200) Subject: backend/ipp.c: Adjust color job options X-Git-Tag: v2.4.3~12^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F461%2Fhead;p=thirdparty%2Fcups.git backend/ipp.c: Adjust color job options In case the client doesn't do it, we have to consolidate color options in the job to prevent opposite options being set at the same time. --- diff --git a/backend/ipp.c b/backend/ipp.c index c8172792fe..be1f2c0481 100644 --- a/backend/ipp.c +++ b/backend/ipp.c @@ -146,6 +146,7 @@ static char mandatory_attrs[1024] = ""; * Local functions... */ +static void adjust_options(int num_options, cups_option_t *options); static void cancel_job(http_t *http, const char *uri, int id, const char *resource, const char *user, int version); @@ -2286,6 +2287,59 @@ main(int argc, /* I - Number of command-line args */ } +/* + * 'adjust_options()' - Adjust options which have the same meaning. + * + * In case the backend gets PPD option and IPP attribute of the same meaning + * among options array, adjust their values to reflect the same choices, + * if the values differ (preferring PPD option values). + * + * Support for each PPD x IPP option pair is added adhoc, based on demand. + */ + +static void +adjust_options(int num_options, /* I - Number of options */ + cups_option_t *options) /* I - Array of job options */ +{ + const char *ppd_option_value = NULL; /* PPD option value */ + const char *ipp_attr_value = NULL; /* IPP attribute value */ + + + fprintf(stderr, "DEBUG: adjust_options()\n"); + + if (options == NULL || num_options < 2) + { + fprintf(stderr, "DEBUG: adjust_options(): Invalid values.\n"); + return; + } + + /* + * PPD option ColorModel and IPP attribute print-color-mode + */ + + ppd_option_value = cupsGetOption("ColorModel", num_options, options); + ipp_attr_value = cupsGetOption("print-color-mode", num_options, options); + + if (!ppd_option_value || !ipp_attr_value) + return; + + if (strcmp(ipp_attr_value, "monochrome") && (!strcmp(ppd_option_value, "Gray") + || !strcmp(ppd_option_value, "FastGray") + || !strcmp(ppd_option_value, "DeviceGray"))) + { + fprintf(stderr, "DEBUG: adjust_options(): Adjusting print-color-mode to monochrome.\n"); + num_options = cupsAddOption("print-color-mode", "monochrome", num_options, &options); + } + else if (strcmp(ipp_attr_value, "color") && (!strcmp(ppd_option_value, "CMY") + || !strcmp(ppd_option_value, "CMYK") + || !strcmp(ppd_option_value, "RGB"))) + { + fprintf(stderr, "DEBUG: adjust_options(): Adjusting print-color-mode to color.\n"); + num_options = cupsAddOption("print-color-mode", "color", num_options, &options); + } +} + + /* * 'cancel_job()' - Cancel a print job. */ @@ -2897,6 +2951,7 @@ new_request( */ fputs("DEBUG: Adding all operation/job attributes.\n", stderr); + adjust_options(num_options, options); cupsEncodeOptions2(request, num_options, options, IPP_TAG_OPERATION); cupsEncodeOptions2(request, num_options, options, IPP_TAG_JOB); }