-/*
- * Copyright 2012 Canonical Ltd.
- * Copyright 2013 ALT Linux, Andrew V. Stepanov <stanv@altlinux.com>
- * Copyright 2018 Sahil Arora <sahilarora.535@gmail.com>
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 3, as published
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>.
- */
+//
+// Copyright 2012 Canonical Ltd.
+// Copyright 2013 ALT Linux, Andrew V. Stepanov <stanv@altlinux.com>
+// Copyright 2018 Sahil Arora <sahilarora.535@gmail.com>
+//
+// This program is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License version 3, as published
+// by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranties of
+// MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>.
+//
#include <config.h>
#include <ctype.h>
typedef enum banner_info_e
{
- INFO_IMAGEABLE_AREA = 1,
- INFO_JOB_BILLING = 1 << 1,
- INFO_JOB_ID = 1 << 2,
- INFO_JOB_NAME = 1 << 3,
- INFO_JOB_ORIGINATING_HOST_NAME = 1 << 4,
- INFO_JOB_ORIGINATING_USER_NAME = 1 << 5,
- INFO_JOB_UUID = 1 << 6,
- INFO_OPTIONS = 1 << 7,
- INFO_PAPER_NAME = 1 << 8,
- INFO_PAPER_SIZE = 1 << 9,
- INFO_PRINTER_DRIVER_NAME = 1 << 10,
- INFO_PRINTER_DRIVER_VERSION = 1 << 11,
- INFO_PRINTER_INFO = 1 << 12,
- INFO_PRINTER_LOCATION = 1 << 13,
- INFO_PRINTER_MAKE_AND_MODEL = 1 << 14,
- INFO_PRINTER_NAME = 1 << 15,
- INFO_TIME_AT_CREATION = 1 << 16,
- INFO_TIME_AT_PROCESSING = 1 << 17
+ INFO_IMAGEABLE_AREA = 1,
+ INFO_JOB_BILLING = 1 << 1,
+ INFO_JOB_ID = 1 << 2,
+ INFO_JOB_NAME = 1 << 3,
+ INFO_JOB_ORIGINATING_HOST_NAME = 1 << 4,
+ INFO_JOB_ORIGINATING_USER_NAME = 1 << 5,
+ INFO_JOB_UUID = 1 << 6,
+ INFO_OPTIONS = 1 << 7,
+ INFO_PAPER_NAME = 1 << 8,
+ INFO_PAPER_SIZE = 1 << 9,
+ INFO_PRINTER_DRIVER_NAME = 1 << 10,
+ INFO_PRINTER_DRIVER_VERSION = 1 << 11,
+ INFO_PRINTER_INFO = 1 << 12,
+ INFO_PRINTER_LOCATION = 1 << 13,
+ INFO_PRINTER_MAKE_AND_MODEL = 1 << 14,
+ INFO_PRINTER_NAME = 1 << 15,
+ INFO_TIME_AT_CREATION = 1 << 16,
+ INFO_TIME_AT_PROCESSING = 1 << 17
} banner_info_t;
typedef struct banner_s
{
- char *template_file;
- char *header, *footer;
- unsigned infos;
+ char *template_file;
+ char *header, *footer;
+ unsigned infos;
} banner_t;
-static void banner_free(banner_t *banner)
+static void
+banner_free(banner_t *banner)
{
- if (banner)
- {
- free(banner->template_file);
- free(banner->header);
- free(banner->footer);
- free(banner);
- }
+ if (banner)
+ {
+ free(banner->template_file);
+ free(banner->header);
+ free(banner->footer);
+ free(banner);
+ }
}
-static int parse_line(char *line, char **key, char **value)
+static int
+parse_line(char *line,
+ char **key,
+ char **value)
{
- char *p = line;
+ char *p = line;
- *key = *value = NULL;
+ *key = *value = NULL;
- while (isspace(*p))
- p++;
- if (!*p || *p == '#')
- return 0;
+ while (isspace(*p))
+ p++;
+ if (!*p || *p == '#')
+ return (0);
- *key = p;
- while (*p && !isspace(*p))
- p++;
- if (!*p)
- return 1;
+ *key = p;
+ while (*p && !isspace(*p))
+ p++;
+ if (!*p)
+ return (1);
- *p++ = '\0';
+ *p++ = '\0';
- while (isspace(*p))
- p++;
- if (!*p)
- return 1;
+ while (isspace(*p))
+ p++;
+ if (!*p)
+ return (1);
- *value = p;
+ *value = p;
- /* remove trailing space */
- while (*p)
- p++;
- while (isspace(*--p))
- *p = '\0';
+ // remove trailing space
+ while (*p)
+ p++;
+ while (isspace(*--p))
+ *p = '\0';
- return 1;
+ return (1);
}
-static unsigned parse_show(char *s, cf_logfunc_t log, void *ld)
+static unsigned
+parse_show(char *s,
+ cf_logfunc_t log,
+ void *ld)
{
- unsigned info = 0;
- char *tok;
-
- for (tok = strtok(s, " \t"); tok; tok = strtok(NULL, " \t"))
- {
- if (!strcasecmp(tok, "imageable-area"))
- info |= INFO_IMAGEABLE_AREA;
- else if (!strcasecmp(tok, "job-billing"))
- info |= INFO_JOB_BILLING;
- else if (!strcasecmp(tok, "job-id"))
- info |= INFO_JOB_ID;
- else if (!strcasecmp(tok, "job-name"))
- info |= INFO_JOB_NAME;
- else if (!strcasecmp(tok, "job-originating-host-name"))
- info |= INFO_JOB_ORIGINATING_HOST_NAME;
- else if (!strcasecmp(tok, "job-originating-user-name"))
- info |= INFO_JOB_ORIGINATING_USER_NAME;
- else if (!strcasecmp(tok, "job-uuid"))
- info |= INFO_JOB_UUID;
- else if (!strcasecmp(tok, "options"))
- info |= INFO_OPTIONS;
- else if (!strcasecmp(tok, "paper-name"))
- info |= INFO_PAPER_NAME;
- else if (!strcasecmp(tok, "paper-size"))
- info |= INFO_PAPER_SIZE;
- else if (!strcasecmp(tok, "printer-driver-name"))
- info |= INFO_PRINTER_DRIVER_NAME;
- else if (!strcasecmp(tok, "printer-driver-version"))
- info |= INFO_PRINTER_DRIVER_VERSION;
- else if (!strcasecmp(tok, "printer-info"))
- info |= INFO_PRINTER_INFO;
- else if (!strcasecmp(tok, "printer-location"))
- info |= INFO_PRINTER_LOCATION;
- else if (!strcasecmp(tok, "printer-make-and-model"))
- info |= INFO_PRINTER_MAKE_AND_MODEL;
- else if (!strcasecmp(tok, "printer-name"))
- info |= INFO_PRINTER_NAME;
- else if (!strcasecmp(tok, "time-at-creation"))
- info |= INFO_TIME_AT_CREATION;
- else if (!strcasecmp(tok, "time-at-processing"))
- info |= INFO_TIME_AT_PROCESSING;
- else if (log)
- log(ld, CF_LOGLEVEL_ERROR, "cfFilterBannerToPDF: error: unknown value for 'Show': %s\n", tok);
- }
- return info;
+ unsigned info = 0;
+ char *tok;
+
+ for (tok = strtok(s, " \t"); tok; tok = strtok(NULL, " \t"))
+ {
+ if (!strcasecmp(tok, "imageable-area"))
+ info |= INFO_IMAGEABLE_AREA;
+ else if (!strcasecmp(tok, "job-billing"))
+ info |= INFO_JOB_BILLING;
+ else if (!strcasecmp(tok, "job-id"))
+ info |= INFO_JOB_ID;
+ else if (!strcasecmp(tok, "job-name"))
+ info |= INFO_JOB_NAME;
+ else if (!strcasecmp(tok, "job-originating-host-name"))
+ info |= INFO_JOB_ORIGINATING_HOST_NAME;
+ else if (!strcasecmp(tok, "job-originating-user-name"))
+ info |= INFO_JOB_ORIGINATING_USER_NAME;
+ else if (!strcasecmp(tok, "job-uuid"))
+ info |= INFO_JOB_UUID;
+ else if (!strcasecmp(tok, "options"))
+ info |= INFO_OPTIONS;
+ else if (!strcasecmp(tok, "paper-name"))
+ info |= INFO_PAPER_NAME;
+ else if (!strcasecmp(tok, "paper-size"))
+ info |= INFO_PAPER_SIZE;
+ else if (!strcasecmp(tok, "printer-driver-name"))
+ info |= INFO_PRINTER_DRIVER_NAME;
+ else if (!strcasecmp(tok, "printer-driver-version"))
+ info |= INFO_PRINTER_DRIVER_VERSION;
+ else if (!strcasecmp(tok, "printer-info"))
+ info |= INFO_PRINTER_INFO;
+ else if (!strcasecmp(tok, "printer-location"))
+ info |= INFO_PRINTER_LOCATION;
+ else if (!strcasecmp(tok, "printer-make-and-model"))
+ info |= INFO_PRINTER_MAKE_AND_MODEL;
+ else if (!strcasecmp(tok, "printer-name"))
+ info |= INFO_PRINTER_NAME;
+ else if (!strcasecmp(tok, "time-at-creation"))
+ info |= INFO_TIME_AT_CREATION;
+ else if (!strcasecmp(tok, "time-at-processing"))
+ info |= INFO_TIME_AT_PROCESSING;
+ else if (log)
+ log(ld, CF_LOGLEVEL_ERROR, "cfFilterBannerToPDF: error: unknown value for 'Show': %s\n", tok);
+ }
+
+ return (info);
}
-static char *template_path(const char *name, const char *datadir)
+static char *
+template_path(const char *name,
+ const char *datadir)
{
- char *result;
+ char *result;
- if (name[0] == '/')
- return strdup(name);
+ if (name[0] == '/')
+ return (strdup(name));
- result = malloc(strlen(datadir) + strlen(name) + 2);
- sprintf(result, "%s/%s", datadir, name);
+ result = malloc(strlen(datadir) + strlen(name) + 2);
+ sprintf(result, "%s/%s", datadir, name);
- return result;
+ return (result);
}
-static banner_t *banner_new_from_file(const char *filename, int *num_options,
- cups_option_t **options, const char *datadir,
- cf_logfunc_t log, void *ld)
+static banner_t *
+banner_new_from_file(const char *filename,
+ int *num_options,
+ cups_option_t **options,
+ const char *datadir,
+ cf_logfunc_t log,
+ void *ld)
{
- FILE *f;
- char *line = NULL;
- size_t len = 0, bytes_read;
- int linenr = 0;
- int ispdf = 0;
- int gotinfos = 0;
- banner_t *banner = NULL;
-
- if (!(f = fopen(filename, "r")))
+ FILE *f;
+ char *line = NULL;
+ size_t len = 0, bytes_read;
+ int linenr = 0;
+ int ispdf = 0;
+ int gotinfos = 0;
+ banner_t *banner = NULL;
+
+ if (!(f = fopen(filename, "r")))
+ {
+ if (log)
+ log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterBannerToPDF: Error opening temporary file with input stream");
+ goto out;
+ }
+
+ while ((bytes_read = getline(&line, &len, f)) != -1)
+ {
+ char *start = line;
+
+ linenr ++;
+
+ if (bytes_read == -1)
{
if (log)
log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterBannerToPDF: Error opening temporary file with input stream");
+ "cfFilterBannerToPDF: No banner instructions found in input stream");
goto out;
}
- while ((bytes_read = getline(&line, &len, f)) != -1)
- {
- char *start = line;
+ if (strncmp(line, "%PDF-", 5) == 0)
+ ispdf = 1;
+ while(start < line + len &&
+ ((ispdf && *start == '%') || isspace(*start)))
+ start ++;
+ if (strncasecmp(start, "#PDF-BANNER", 11) == 0 ||
+ strncasecmp(start, "PDF-BANNER", 10) == 0)
+ break;
+ }
- linenr ++;
+ banner = calloc(1, sizeof *banner);
- if (bytes_read == -1)
- {
- if (log)
- log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterBannerToPDF: No banner instructions found in input stream");
- goto out;
- }
+ while (getline(&line, &len, f) != -1)
+ {
+ char *key, *value;
- if (strncmp(line, "%PDF-", 5) == 0)
- ispdf = 1;
- while(start < line + len &&
- ((ispdf && *start == '%') || isspace(*start)))
- start ++;
- if (strncasecmp(start, "#PDF-BANNER", 11) == 0 ||
- strncasecmp(start, "PDF-BANNER", 10) == 0)
- break;
- }
+ linenr++;
+ if (!parse_line(line, &key, &value))
+ continue;
-
- banner = calloc(1, sizeof *banner);
-
- while (getline(&line, &len, f) != -1)
+ if (!value)
{
- char *key, *value;
-
- linenr++;
- if (!parse_line(line, &key, &value))
- continue;
-
- if (!value)
- {
- if (ispdf)
- break;
- if (log)
- log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterBannerToPDF: Line %d is missing a value", linenr);
- continue;
- }
-
- if (ispdf)
- while (*key == '%')
- key ++;
-
- if (!strcasecmp(key, "template"))
- banner->template_file = template_path(value, datadir);
- else if (!strcasecmp(key, "header"))
- banner->header = strdup(value);
- else if (!strcasecmp(key, "footer"))
- banner->header = strdup(value);
- else if (!strcasecmp(key, "font"))
- {
- *num_options = cupsAddOption("banner-font",
- strdup(value), *num_options, options);
- }
- else if (!strcasecmp(key, "font-size"))
- {
- *num_options = cupsAddOption("banner-font-size",
- strdup(value), *num_options, options);
- }
- else if (!strcasecmp(key, "show"))
- {
- banner->infos = parse_show(value, log, ld);
- gotinfos = 1;
- }
- else if (!strcasecmp(key, "image") ||
- !strcasecmp(key, "notice"))
- {
- if (log)
- log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterBannerToPDF: Note: %d: bannertopdf does not support '%s'",
- linenr, key);
- }
- else
- {
- if (ispdf)
- break;
- if (log)
- log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterBannerToPDF: Error: %d: unknown keyword '%s'",
- linenr, key);
- }
+ if (ispdf)
+ break;
+ if (log)
+ log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterBannerToPDF: Line %d is missing a value", linenr);
+ continue;
+ }
+
+ if (ispdf)
+ while (*key == '%')
+ key ++;
+
+ if (!strcasecmp(key, "template"))
+ banner->template_file = template_path(value, datadir);
+ else if (!strcasecmp(key, "header"))
+ banner->header = strdup(value);
+ else if (!strcasecmp(key, "footer"))
+ banner->header = strdup(value);
+ else if (!strcasecmp(key, "font"))
+ *num_options = cupsAddOption("banner-font",
+ strdup(value), *num_options, options);
+ else if (!strcasecmp(key, "font-size"))
+ *num_options = cupsAddOption("banner-font-size",
+ strdup(value), *num_options, options);
+ else if (!strcasecmp(key, "show"))
+ {
+ banner->infos = parse_show(value, log, ld);
+ gotinfos = 1;
}
-
- /* load default template if none was specified */
- if (!banner->template_file)
+ else if (!strcasecmp(key, "image") ||
+ !strcasecmp(key, "notice"))
{
- if (ispdf)
- banner->template_file = strdup(filename);
- else
- banner->template_file = template_path("default.pdf", datadir);
+ if (log)
+ log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterBannerToPDF: Note: %d: bannertopdf does not support '%s'",
+ linenr, key);
}
- if (!gotinfos)
+ else
{
- char *value = strdup("printer-name printer-info printer-location printer-make-and-model printer-driver-name printer-driver-version paper-size imageable-area job-id options time-at-creation time-at-processing");
- banner->infos = parse_show(value, log, ld);
- free(value);
+ if (ispdf)
+ break;
+ if (log)
+ log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterBannerToPDF: Error: %d: unknown keyword '%s'",
+ linenr, key);
}
+ }
-out:
- free(line);
- if (f)
- fclose(f);
- return banner;
+ // load default template if none was specified
+ if (!banner->template_file)
+ {
+ if (ispdf)
+ banner->template_file = strdup(filename);
+ else
+ banner->template_file = template_path("default.pdf", datadir);
+ }
+ if (!gotinfos)
+ {
+ char *value = strdup("printer-name printer-info printer-location printer-make-and-model printer-driver-name printer-driver-version paper-size imageable-area job-id options time-at-creation time-at-processing");
+ banner->infos = parse_show(value, log, ld);
+ free(value);
+ }
+
+ out:
+ free(line);
+ if (f)
+ fclose(f);
+
+ return (banner);
}
-static int get_int_option(const char *name,
- int num_options,
- cups_option_t *options,
- int def)
+static int
+get_int_option(const char *name,
+ int num_options,
+ cups_option_t *options,
+ int def)
{
- const char *value = cupsGetOption(name, num_options, options);
- return value ? atoi(value) : def;
+ const char *value = cupsGetOption(name, num_options, options);
+ return (value ? atoi(value) : def);
}
-static int duplex_marked(cf_filter_data_t *data)
+static int
+duplex_marked(cf_filter_data_t *data)
{
- const char *val; /* Pointer into value */
+ const char *val; // Pointer into value
if ((val = cupsGetOption("Duplex",
data->num_options, data->options)) != NULL)
return (strncasecmp(val, "Duplex", 6) == 0);
return (0);
}
-static void info_linef(FILE *s,
- const char *key,
- const char *valuefmt, ...)
+static void
+info_linef(FILE *s,
+ const char *key,
+ const char *valuefmt, ...)
{
- va_list ap;
+ va_list ap;
- va_start(ap, valuefmt);
- fprintf(s, "(%s: ", key);
- vfprintf(s, valuefmt, ap);
- fprintf(s, ") Tj T*\n");
- va_end(ap);
+ va_start(ap, valuefmt);
+ fprintf(s, "(%s: ", key);
+ vfprintf(s, valuefmt, ap);
+ fprintf(s, ") Tj T*\n");
+ va_end(ap);
}
-static void info_line(FILE *s,
- const char *key,
- const char *value)
+static void
+info_line(FILE *s,
+ const char *key,
+ const char *value)
{
- info_linef(s, key, "%s", value);
+ info_linef(s, key, "%s", value);
}
-static void info_line_time(FILE *s,
- const char *key,
- const char *timestamp)
+static void
+info_line_time(FILE *s,
+ const char *key,
+ const char *timestamp)
{
- char buf[40];
- time_t time;
-
- if (timestamp)
- {
- time = (time_t)atoll(timestamp);
- strftime(buf, sizeof buf, "%c", localtime(&time));
- info_line(s, key, buf);
- }
- else
- info_line(s, key, "unknown");
+ char buf[40];
+ time_t time;
+
+ if (timestamp)
+ {
+ time = (time_t)atoll(timestamp);
+ strftime(buf, sizeof buf, "%c", localtime(&time));
+ info_line(s, key, buf);
+ }
+ else
+ info_line(s, key, "unknown");
}
-static const char *human_time(const char *timestamp)
+static const char *
+human_time(const char *timestamp)
{
- time_t time;
- int size = sizeof(char) * 40;
- char *buf = malloc(size);
- strcpy(buf, "unknown");
-
- if (timestamp)
- {
- time = (time_t)atoll(timestamp);
- strftime(buf, size, "%c", localtime(&time));
- }
-
- return buf;
+ time_t time;
+ int size = sizeof(char) * 40;
+ char *buf = malloc(size);
+ strcpy(buf, "unknown");
+
+ if (timestamp)
+ {
+ time = (time_t)atoll(timestamp);
+ strftime(buf, size, "%c", localtime(&time));
+ }
+
+ return (buf);
}
-/*
- * Add new key & value.
- */
-static cf_opt_t *add_opt(cf_opt_t *in_opt, const char *key, const char *val)
+//
+// Add new key & value.
+//
+
+static cf_opt_t *
+add_opt(cf_opt_t *in_opt,
+ const char *key,
+ const char *val)
{
- if (!key || !val)
- {
- return in_opt;
- }
+ if (!key || !val)
+ return (in_opt);
- if (!strlen(key) || !strlen(val))
- {
- return in_opt;
- }
+ if (!strlen(key) || !strlen(val))
+ return (in_opt);
- cf_opt_t *entry = malloc(sizeof(cf_opt_t));
- if (!entry)
- {
- return in_opt;
- }
+ cf_opt_t *entry = malloc(sizeof(cf_opt_t));
+ if (!entry)
+ return (in_opt);
- entry->key = key;
- entry->val = val;
- entry->next = in_opt;
+ entry->key = key;
+ entry->val = val;
+ entry->next = in_opt;
- return entry;
+ return (entry);
}
-/*
- * Collect all known info about current task.
- * Bond PDF form field name with collected info.
- *
- * Create PDF form's field names according above.
- */
-static cf_opt_t *get_known_opts(
- cf_filter_data_t *data,
- const char *jobid,
- const char *user,
- const char *jobtitle,
- int num_options,
-
- cups_option_t *options)
+//
+// Collect all known info about current task.
+// Bond PDF form field name with collected info.
+//
+// Create PDF form's field names according above.
+//
+
+static
+cf_opt_t *get_known_opts(cf_filter_data_t *data,
+ const char *jobid,
+ const char *user,
+ const char *jobtitle,
+ int num_options,
+ cups_option_t *options)
{
- cf_opt_t *opt = NULL;
- ipp_t *printer_attrs = data->printer_attrs;
- ipp_attribute_t *ipp_attr;
- char buf[1024];
- const char *value = NULL;
-
- /* Job ID */
- opt = add_opt(opt, "job-id", jobid);
-
- /* Job title */
- opt = add_opt(opt, "job-title", jobtitle);
-
- /* Printed by */
- opt = add_opt(opt, "user", user);
-
- /* Printer name */
- opt = add_opt(opt, "printer-name", data->printer);
-
- /* Printer info */
- if ((value = cupsGetOption("printer-info",
- num_options, options)) == NULL || !value[0])
- value = getenv("PRINTER_INFO");
- opt = add_opt(opt, "printer-info", value);
-
- /* Time at creation */
- opt = add_opt(opt, "time-at-creation",
- human_time(cupsGetOption("time-at-creation", num_options, options)));
-
- /* Processing time */
- opt = add_opt(opt, "time-at-processing",
- human_time(cupsGetOption("time-at-processing", num_options, options)));
-
- /* Billing information */
- opt = add_opt(opt, "job-billing",
- cupsGetOption("job-billing", num_options, options));
-
- /* Source hostname */
- opt = add_opt(opt, "job-originating-host-name",
- cupsGetOption("job-originating-host-name", num_options, options));
-
- /* Banner font */
- opt = add_opt(opt, "banner-font",
- cupsGetOption("banner-font", num_options, options));
-
- /* Banner font size */
- opt = add_opt(opt, "banner-font-size",
- cupsGetOption("banner-font-size", num_options, options));
+ cf_opt_t *opt = NULL;
+ ipp_t *printer_attrs = data->printer_attrs;
+ ipp_attribute_t *ipp_attr;
+ char buf[1024];
+ const char *value = NULL;
+
+ // Job ID
+ opt = add_opt(opt, "job-id", jobid);
+
+ // Job title
+ opt = add_opt(opt, "job-title", jobtitle);
+
+ // Printed by
+ opt = add_opt(opt, "user", user);
+
+ // Printer name
+ opt = add_opt(opt, "printer-name", data->printer);
+
+ // Printer info
+ if ((value = cupsGetOption("printer-info",
+ num_options, options)) == NULL || !value[0])
+ value = getenv("PRINTER_INFO");
+ opt = add_opt(opt, "printer-info", value);
+
+ // Time at creation
+ opt = add_opt(opt, "time-at-creation",
+ human_time(cupsGetOption("time-at-creation", num_options,
+ options)));
+
+ // Processing time
+ opt = add_opt(opt, "time-at-processing",
+ human_time(cupsGetOption("time-at-processing", num_options,
+ options)));
+
+ // Billing information
+ opt = add_opt(opt, "job-billing",
+ cupsGetOption("job-billing", num_options, options));
+
+ // Source hostname
+ opt = add_opt(opt, "job-originating-host-name",
+ cupsGetOption("job-originating-host-name", num_options,
+ options));
+
+ // Banner font
+ opt = add_opt(opt, "banner-font",
+ cupsGetOption("banner-font", num_options, options));
+
+ // Banner font size
+ opt = add_opt(opt, "banner-font-size",
+ cupsGetOption("banner-font-size", num_options, options));
+
+ // Job UUID
+ opt = add_opt(opt, "job-uuid",
+ cupsGetOption("job-uuid", num_options, options));
+
+ // Security context
+ opt = add_opt(opt, "security-context",
+ cupsGetOption("security-context", num_options, options));
+
+ // Security context range part
+ opt = add_opt(opt, "security-context-range",
+ cupsGetOption("security-context-range", num_options, options));
+
+ // Security context current range part
+ const char *full_range = cupsGetOption("security-context-range", num_options,
+ options);
+ if (full_range)
+ {
+ size_t cur_size = strcspn(full_range, "-");
+ char *cur_range = strndup(full_range, cur_size);
+ opt = add_opt(opt, "security-context-range-cur", cur_range);
+ }
+
+ // Security context type part
+ opt = add_opt(opt, "security-context-type",
+ cupsGetOption("security-context-type", num_options, options));
+
+ // Security context role part
+ opt = add_opt(opt, "security-context-role",
+ cupsGetOption("security-context-role", num_options, options));
+
+ // Security context user part
+ opt = add_opt(opt, "security-context-user",
+ cupsGetOption("security-context-user", num_options, options));
- /* Job UUID */
- opt = add_opt(opt, "job-uuid",
- cupsGetOption("job-uuid", num_options, options));
-
- /* Security context */
- opt = add_opt(opt, "security-context",
- cupsGetOption("security-context", num_options, options));
-
- /* Security context range part */
- opt = add_opt(opt, "security-context-range",
- cupsGetOption("security-context-range", num_options, options));
+#if 0
+ // Driver
+ opt = add_opt(opt, "driver", "driverless");
- /* Security context current range part */
- const char *full_range = cupsGetOption("security-context-range", num_options, options);
- if (full_range)
- {
- size_t cur_size = strcspn(full_range, "-");
- char *cur_range = strndup(full_range, cur_size);
- opt = add_opt(opt, "security-context-range-cur", cur_range);
- }
+ // Driver version
+ opt = add_opt(opt, "driver-version", VERSION);
+#endif
- /* Security context type part */
- opt = add_opt(opt, "security-context-type",
- cupsGetOption("security-context-type", num_options, options));
+ // Make and model
+ int is_fax = 0;
+ char make[256];
+ char *model;
+ if ((ipp_attr = ippFindAttribute(printer_attrs, "ipp-features-supported",
+ IPP_TAG_ZERO)) != NULL &&
+ ippContainsString(ipp_attr, "faxout"))
+ {
+ ipp_attr = ippFindAttribute(printer_attrs, "printer-uri-supported",
+ IPP_TAG_ZERO);
+ if (ipp_attr)
+ {
+ ippAttributeString(ipp_attr, buf, sizeof(buf));
+ if (strcasestr(buf, "faxout"))
+ is_fax = 1;
+ }
+ }
+
+ if ((ipp_attr = ippFindAttribute(printer_attrs, "printer-info",
+ IPP_TAG_ZERO)) != NULL ||
+ (ipp_attr = ippFindAttribute(printer_attrs, "printer-make-and-model",
+ IPP_TAG_ZERO)) != NULL)
+ snprintf(make, sizeof(make), "%s", ippGetString(ipp_attr, 0, NULL));
+ else
+ snprintf(make, sizeof(make), "%s", "Unknown Printer");
+ if (!strncasecmp(make, "Hewlett Packard ", 16) ||
+ !strncasecmp(make, "Hewlett-Packard ", 16))
+ {
+ model = make + 16;
+ snprintf(make, sizeof(make), "%s", "HP");
+ }
+ else if ((model = strchr(make, ' ')) != NULL)
+ *model++ = '\0';
+ else
+ model = make;
+ snprintf(buf, sizeof(buf), "%s %s%s",
+ make, model, (is_fax ? ", Fax" : ""));
+ char *nickname = buf;
+ opt = add_opt(opt, "make-and-model", nickname);
+
+ return (opt);
+}
- /* Security context role part */
- opt = add_opt(opt, "security-context-role",
- cupsGetOption("security-context-role", num_options, options));
+static int
+generate_banner_pdf(banner_t *banner,
+ cf_filter_data_t *data,
+ const char *jobid,
+ const char *user,
+ const char *jobtitle,
+ int num_options,
+ cups_option_t *options,
+ cf_logfunc_t log,
+ void *ld,
+ FILE *outputfp)
+{
+ char *buf;
+ size_t len;
+ FILE *s;
+ cf_pdf_t *doc;
+ float page_width = 0.0, page_length = 0.0;
+ float media_limits[4];
+ float page_scale;
+ unsigned copies;
+ ipp_t *printer_attrs = data->printer_attrs;
+ ipp_attribute_t *ipp_attr;
+ char buf2[1024];
+ const char *value;
+#ifndef HAVE_OPEN_MEMSTREAM
+ struct stat st;
+#endif
- /* Security context user part */
- opt = add_opt(opt, "security-context-user",
- cupsGetOption("security-context-user", num_options, options));
+ if (!(doc = cfPDFLoadTemplate(banner->template_file)))
+ {
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "PDF template must exist and contain exactly 1 page: %s",
+ banner->template_file);
+ return (1);
+ }
+
+ memset(media_limits, 0, sizeof(media_limits));
+ if (data != NULL && (data->printer_attrs) != NULL)
+ {
+ cfGetPageDimensions(data->printer_attrs, data->job_attrs,
+ num_options, options,
+ data->header, 0,
+ &(page_width), &(page_length),
+ &(media_limits[0]), &(media_limits[1]),
+ &(media_limits[2]), &(media_limits[3]),
+ NULL, NULL);
+ media_limits[2] = page_width - media_limits[2];
+ media_limits[3] = page_length - media_limits[3];
+ }
+
+ if (cfPDFResizePage(doc, 1, page_width, page_length, &page_scale) != 0)
+ {
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "Unable to resize requested PDF page");
+ cfPDFFree(doc);
+ return (1);
+ }
-#if 0
- /* Driver */
- opt = add_opt(opt, "driver", "driverless");
+ if (cfPDFAddType1Font(doc, 1, "Courier") != 0)
+ {
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "Unable to add type1 font to requested PDF page");
+ cfPDFFree(doc);
+ return (1);
+ }
- /* Driver version */
- opt = add_opt(opt, "driver-version", VERSION);
+#ifdef HAVE_OPEN_MEMSTREAM
+ s = open_memstream(&buf, &len);
+#else
+ if ((s = tmpfile()) == NULL)
+ {
+ if (log)
+ log(ld, CF_LOGLEVEL_ERROR, "cfFilterBannerToPDF: Cannot create temp file: %s\n", strerror(errno));
+ cfPDFFree(doc);
+ return (1);
+ }
#endif
- /* Make and model */
+ if (banner->infos & INFO_IMAGEABLE_AREA)
+ {
+ fprintf(s, "q\n");
+ fprintf(s, "0 0 0 RG\n");
+ fprintf(s, "%f %f %f %f re S\n", media_limits[0] + 1.0,
+ media_limits[1] + 1.0,
+ media_limits[2] - media_limits[0] - 2.0,
+ media_limits[3] - media_limits[1] - 2.0);
+ fprintf(s, "Q\n");
+ }
+
+ fprintf(s, "%f 0 0 %f 0 0 cm\n", page_scale, page_scale);
+
+ fprintf(s, "0 0 0 rg\n");
+ fprintf(s, "BT\n");
+ fprintf(s, "/bannertopdf-font 14 Tf\n");
+ fprintf(s, "83.662 335.0 Td\n");
+ fprintf(s, "17 TL\n");
+
+ if ((banner->infos & INFO_PRINTER_NAME) &&
+ data->printer && data->printer[0] && data->printer[0] != '/')
+ info_line(s, "Printer", data->printer);
+
+ if ((banner->infos & INFO_PRINTER_INFO) &&
+ (((value = cupsGetOption("printer-info",
+ num_options, options)) != NULL && value[0]) ||
+ ((value = getenv("PRINTER_INFO")) != NULL && value[0])))
+ info_line(s, "Description", value);
+
+ if ((banner->infos & INFO_PRINTER_LOCATION) &&
+ (((value = cupsGetOption("printer-location",
+ num_options, options)) != NULL && value[0]) ||
+ ((value = getenv("PRINTER_LOCATION")) != NULL && value[0])))
+ info_line(s, "Location", value);
+
+ if ((banner->infos & INFO_JOB_ID) &&
+ data->printer && data->printer[0] && data->printer[0] != '/' &&
+ jobid && jobid[0])
+ info_linef(s, "Job ID", "%s-%s", data->printer, jobid);
+
+ if ((banner->infos & INFO_JOB_NAME) && jobtitle && jobtitle[0])
+ info_line(s, "Job Title", jobtitle);
+
+ if ((banner->infos & INFO_JOB_ORIGINATING_HOST_NAME) &&
+ (value = cupsGetOption("job-originating-host-name",
+ num_options, options)) != NULL && value[0])
+ info_line(s, "Printed from", value);
+
+ if ((banner->infos & INFO_JOB_ORIGINATING_USER_NAME) && user && user[0])
+ info_line(s, "Printed by", user);
+
+ if ((banner->infos & INFO_TIME_AT_CREATION) &&
+ (value =
+ cupsGetOption("time-at-creation", num_options, options)) != NULL &&
+ value[0])
+ info_line_time(s, "Created at", value);
+
+ if ((banner->infos & INFO_TIME_AT_PROCESSING) &&
+ (value =
+ cupsGetOption("time-at-processing", num_options, options)) != NULL &&
+ value[0])
+ info_line_time(s, "Printed at", value);
+
+ if ((banner->infos & INFO_JOB_BILLING) &&
+ (value = cupsGetOption("job-billing", num_options, options)) != NULL &&
+ value[0])
+ info_line(s, "Billing Information\n", value);
+
+ if ((banner->infos & INFO_JOB_UUID) &&
+ (value = cupsGetOption("job-uuid", num_options, options)) != NULL &&
+ value[0])
+ info_line(s, "Job UUID", value);
+
+ if ((banner->infos & INFO_PRINTER_DRIVER_NAME) ||
+ (banner->infos & INFO_PRINTER_MAKE_AND_MODEL))
+ {
int is_fax = 0;
char make[256];
char *model;
- if ((ipp_attr = ippFindAttribute(printer_attrs, "ipp-features-supported",
+ if ((ipp_attr = ippFindAttribute(printer_attrs,
+ "ipp-features-supported",
IPP_TAG_ZERO)) != NULL &&
ippContainsString(ipp_attr, "faxout"))
{
IPP_TAG_ZERO);
if (ipp_attr)
{
- ippAttributeString(ipp_attr, buf, sizeof(buf));
- if (strcasestr(buf, "faxout"))
+ ippAttributeString(ipp_attr, buf2, sizeof(buf2));
+ if (strcasestr(buf2, "faxout"))
is_fax = 1;
}
}
- if ((ipp_attr = ippFindAttribute(printer_attrs, "printer-info",
- IPP_TAG_ZERO)) != NULL ||
- (ipp_attr = ippFindAttribute(printer_attrs, "printer-make-and-model",
+ if ((ipp_attr = ippFindAttribute(printer_attrs,
+ "printer-info",
+ IPP_TAG_ZERO)) != NULL ||
+ (ipp_attr = ippFindAttribute(printer_attrs,
+ "printer-make-and-model",
IPP_TAG_ZERO)) != NULL)
+ {
snprintf(make, sizeof(make), "%s", ippGetString(ipp_attr, 0, NULL));
- else
- snprintf(make, sizeof(make), "%s", "Unknown Printer");
- if (!strncasecmp(make, "Hewlett Packard ", 16) ||
- !strncasecmp(make, "Hewlett-Packard ", 16)) {
- model = make + 16;
- snprintf(make, sizeof(make), "%s", "HP");
- }
- else if ((model = strchr(make, ' ')) != NULL)
- *model++ = '\0';
- else
- model = make;
- snprintf(buf, sizeof(buf), "%s %s%s",
- make, model, (is_fax ? ", Fax" : ""));
- char *nickname = buf;
- opt = add_opt(opt, "make-and-model", nickname);
- return opt;
-}
-
-static int generate_banner_pdf(banner_t *banner,
- cf_filter_data_t *data,
- const char *jobid,
- const char *user,
- const char *jobtitle,
- int num_options,
- cups_option_t *options,
- cf_logfunc_t log,
- void *ld,
- FILE *outputfp)
-{
- char *buf;
- size_t len;
- FILE *s;
- cf_pdf_t *doc;
- float page_width = 0.0, page_length = 0.0;
- float media_limits[4];
- float page_scale;
- unsigned copies;
- ipp_t *printer_attrs = data->printer_attrs;
- ipp_attribute_t *ipp_attr;
- char buf2[1024];
- const char *value;
+ if (!strncasecmp(make, "Hewlett Packard ", 16) ||
+ !strncasecmp(make, "Hewlett-Packard ", 16))
+ {
+ model = make + 16;
+ snprintf(make, sizeof(make), "%s", "HP");
+ }
+ else if ((model = strchr(make, ' ')) != NULL)
+ *model++ = '\0';
+ else
+ model = make;
+ snprintf(buf2, sizeof(buf2), "%s %s%s",
+ make, model, (is_fax ? " (Fax)" : ""));
+ char *nickname = buf2;
+ info_line(s, "Make and Model", nickname);
+ }
+ }
+
+ if (banner->infos & INFO_IMAGEABLE_AREA)
+ {
+ info_linef(s, "Media Limits", "%.2f x %.2f to %.2f x %.2f inches",
+ media_limits[0] / 72.0,
+ media_limits[1] / 72.0,
+ media_limits[2] / 72.0,
+ media_limits[3] / 72.0);
+ info_linef(s, "Media Limits", "%.2f x %.2f to %.2f x %.2f cm",
+ media_limits[0] / 72.0 * 2.54,
+ media_limits[1] / 72.0 * 2.54,
+ media_limits[2] / 72.0 * 2.54,
+ media_limits[3] / 72.0 * 2.54);
+ }
+
+ fprintf(s, "ET\n");
#ifndef HAVE_OPEN_MEMSTREAM
- struct stat st;
-#endif
-
- if (!(doc = cfPDFLoadTemplate(banner->template_file)))
+ fflush(s);
+ if (fstat(fileno(s), &st) < 0)
+ {
+ if (log)
+ log(ld, CF_LOGLEVEL_ERROR, "cfFilterBannerToPDF: Cannot fstat(): %s\n", , strerror(errno));
+ return (1);
+ }
+ fseek(s, 0L, SEEK_SET);
+ if ((buf = malloc(st.st_size + 1)) == NULL)
+ {
+ if (log)
+ log(ld, CF_LOGLEVEL_ERROR, "cfFilterBannerToPDF: Cannot malloc(): %s\n", , strerror(errno));
+ return (1);
+ }
+ size_t nbytes = fread(buf, 1, st.st_size, s);
+ buf[st.st_size] = '\0';
+ len = strlen(buf);
+#endif // !HAVE_OPEN_MEMSTREAM
+ fclose(s);
+
+ cf_opt_t *known_opts = get_known_opts(data,
+ jobid,
+ user,
+ jobtitle,
+ num_options,
+ options);
+
+ //
+ // Try to find a PDF form in PDF template and fill it.
+ //
+
+ if (cfPDFFillForm(doc, known_opts) != 0)
+ {
+ //
+ // Could we fill a PDF form? If no, just add PDF stream.
+ //
+
+ if (cfPDFPrependStream(doc, 1, buf, len) != 0)
{
if (log) log(ld, CF_LOGLEVEL_ERROR,
- "PDF template must exist and contain exactly 1 page: %s",
- banner->template_file);
- return (1);
+ "Unable to prepend stream to requested PDF page");
}
+ }
- memset(media_limits, 0, sizeof(media_limits));
- if (data != NULL && (data->printer_attrs) != NULL)
- {
- cfGetPageDimensions(data->printer_attrs, data->job_attrs,
- num_options, options,
- data->header, 0,
- &(page_width), &(page_length),
- &(media_limits[0]), &(media_limits[1]),
- &(media_limits[2]), &(media_limits[3]),
- NULL, NULL);
- media_limits[2] = page_width - media_limits[2];
- media_limits[3] = page_length - media_limits[3];
- }
+ copies = get_int_option("number-up", num_options, options, 1);
- if (cfPDFResizePage(doc, 1, page_width, page_length, &page_scale) != 0)
- {
- if (log) log(ld, CF_LOGLEVEL_ERROR,
- "Unable to resize requested PDF page");
- cfPDFFree(doc);
- return (1);
- }
+ if (duplex_marked(data))
+ copies *= 2;
- if (cfPDFAddType1Font(doc, 1, "Courier") != 0)
+ if (copies > 1)
+ {
+ if (cfPDFDuplicatePage(doc, 1, copies - 1) != 0)
{
if (log) log(ld, CF_LOGLEVEL_ERROR,
- "Unable to add type1 font to requested PDF page");
- cfPDFFree(doc);
- return (1);
- }
-
-#ifdef HAVE_OPEN_MEMSTREAM
- s = open_memstream(&buf, &len);
-#else
- if ((s = tmpfile()) == NULL)
- {
- if (log)
- log(ld, CF_LOGLEVEL_ERROR, "cfFilterBannerToPDF: Cannot create temp file: %s\n", strerror(errno));
- cfPDFFree(doc);
- return 1;
- }
-#endif
-
- if (banner->infos & INFO_IMAGEABLE_AREA)
- {
- fprintf(s, "q\n");
- fprintf(s, "0 0 0 RG\n");
- fprintf(s, "%f %f %f %f re S\n", media_limits[0] + 1.0,
- media_limits[1] + 1.0,
- media_limits[2] - media_limits[0] - 2.0,
- media_limits[3] - media_limits[1] - 2.0);
- fprintf(s, "Q\n");
- }
-
- fprintf(s, "%f 0 0 %f 0 0 cm\n", page_scale, page_scale);
-
- fprintf(s, "0 0 0 rg\n");
- fprintf(s, "BT\n");
- fprintf(s, "/bannertopdf-font 14 Tf\n");
- fprintf(s, "83.662 335.0 Td\n");
- fprintf(s, "17 TL\n");
-
- if ((banner->infos & INFO_PRINTER_NAME) &&
- data->printer && data->printer[0] && data->printer[0] != '/')
- info_line(s, "Printer", data->printer);
-
- if ((banner->infos & INFO_PRINTER_INFO) &&
- (((value = cupsGetOption("printer-info",
- num_options, options)) != NULL && value[0]) ||
- ((value = getenv("PRINTER_INFO")) != NULL && value[0])))
- info_line(s, "Description", value);
-
- if ((banner->infos & INFO_PRINTER_LOCATION) &&
- (((value = cupsGetOption("printer-location",
- num_options, options)) != NULL && value[0]) ||
- ((value = getenv("PRINTER_LOCATION")) != NULL && value[0])))
- info_line(s, "Location", value);
-
- if ((banner->infos & INFO_JOB_ID) &&
- data->printer && data->printer[0] && data->printer[0] != '/' &&
- jobid && jobid[0])
- info_linef(s, "Job ID", "%s-%s", data->printer, jobid);
-
- if ((banner->infos & INFO_JOB_NAME) && jobtitle && jobtitle[0])
- info_line(s, "Job Title", jobtitle);
-
- if ((banner->infos & INFO_JOB_ORIGINATING_HOST_NAME) &&
- (value = cupsGetOption("job-originating-host-name",
- num_options, options)) != NULL && value[0])
- info_line(s, "Printed from", value);
-
- if ((banner->infos & INFO_JOB_ORIGINATING_USER_NAME) && user && user[0])
- info_line(s, "Printed by", user);
-
- if ((banner->infos & INFO_TIME_AT_CREATION) &&
- (value =
- cupsGetOption("time-at-creation", num_options, options)) != NULL &&
- value[0])
- info_line_time(s, "Created at", value);
-
- if ((banner->infos & INFO_TIME_AT_PROCESSING) &&
- (value =
- cupsGetOption("time-at-processing", num_options, options)) != NULL &&
- value[0])
- info_line_time(s, "Printed at", value);
-
- if ((banner->infos & INFO_JOB_BILLING) &&
- (value = cupsGetOption("job-billing", num_options, options)) != NULL &&
- value[0])
- info_line(s, "Billing Information\n", value);
-
- if ((banner->infos & INFO_JOB_UUID) &&
- (value = cupsGetOption("job-uuid", num_options, options)) != NULL &&
- value[0])
- info_line(s, "Job UUID", value);
-
- if ((banner->infos & INFO_PRINTER_DRIVER_NAME) ||
- (banner->infos & INFO_PRINTER_MAKE_AND_MODEL))
-
- {
- int is_fax = 0;
- char make[256];
- char *model;
- if ((ipp_attr = ippFindAttribute(printer_attrs,
- "ipp-features-supported",
- IPP_TAG_ZERO)) != NULL &&
- ippContainsString(ipp_attr, "faxout"))
- {
- ipp_attr = ippFindAttribute(printer_attrs, "printer-uri-supported",
- IPP_TAG_ZERO);
- if (ipp_attr)
- {
- ippAttributeString(ipp_attr, buf2, sizeof(buf2));
- if (strcasestr(buf2, "faxout"))
- is_fax = 1;
- }
- }
-
- if ((ipp_attr = ippFindAttribute(printer_attrs,
- "printer-info",
- IPP_TAG_ZERO)) != NULL ||
- (ipp_attr = ippFindAttribute(printer_attrs,
- "printer-make-and-model",
- IPP_TAG_ZERO)) != NULL)
- {
- snprintf(make, sizeof(make), "%s", ippGetString(ipp_attr, 0, NULL));
-
- if (!strncasecmp(make, "Hewlett Packard ", 16) ||
- !strncasecmp(make, "Hewlett-Packard ", 16))
- {
- model = make + 16;
- snprintf(make, sizeof(make), "%s", "HP");
- }
- else if ((model = strchr(make, ' ')) != NULL)
- *model++ = '\0';
- else
- model = make;
- snprintf(buf2, sizeof(buf2), "%s %s%s",
- make, model, (is_fax ? " (Fax)" : ""));
- char *nickname = buf2;
- info_line(s, "Make and Model", nickname);
- }
- }
-
- if (banner->infos & INFO_IMAGEABLE_AREA)
- {
- info_linef(s, "Media Limits", "%.2f x %.2f to %.2f x %.2f inches",
- media_limits[0] / 72.0,
- media_limits[1] / 72.0,
- media_limits[2] / 72.0,
- media_limits[3] / 72.0);
- info_linef(s, "Media Limits", "%.2f x %.2f to %.2f x %.2f cm",
- media_limits[0] / 72.0 * 2.54,
- media_limits[1] / 72.0 * 2.54,
- media_limits[2] / 72.0 * 2.54,
- media_limits[3] / 72.0 * 2.54);
- }
-
- fprintf(s, "ET\n");
-#ifndef HAVE_OPEN_MEMSTREAM
- fflush(s);
- if (fstat(fileno(s), &st) < 0)
- {
- if (log)
- log(ld, CF_LOGLEVEL_ERROR, "cfFilterBannerToPDF: Cannot fstat(): %s\n", , strerror(errno));
- return 1;
- }
- fseek(s, 0L, SEEK_SET);
- if ((buf = malloc(st.st_size + 1)) == NULL)
- {
- if (log)
- log(ld, CF_LOGLEVEL_ERROR, "cfFilterBannerToPDF: Cannot malloc(): %s\n", , strerror(errno));
- return 1;
- }
- size_t nbytes = fread(buf, 1, st.st_size, s);
- buf[st.st_size] = '\0';
- len = strlen(buf);
-#endif /* !HAVE_OPEN_MEMSTREAM */
- fclose(s);
-
- cf_opt_t *known_opts = get_known_opts(data,
- jobid,
- user,
- jobtitle,
- num_options,
- options);
-
- /*
- * Try to find a PDF form in PDF template and fill it.
- */
-
- if (cfPDFFillForm(doc, known_opts) != 0)
- {
- /*
- * Could we fill a PDF form? If no, just add PDF stream.
- */
-
- if (cfPDFPrependStream(doc, 1, buf, len) != 0)
- {
- if (log) log(ld, CF_LOGLEVEL_ERROR,
- "Unable to prepend stream to requested PDF page");
- }
+ "Unable to duplicate requested PDF page");
}
+ }
- copies = get_int_option("number-up", num_options, options, 1);
+ cfPDFWrite(doc, outputfp);
- if (duplex_marked(data))
- copies *= 2;
-
- if (copies > 1)
- {
- if (cfPDFDuplicatePage(doc, 1, copies - 1) != 0)
- {
- if (log) log(ld, CF_LOGLEVEL_ERROR,
- "Unable to duplicate requested PDF page");
- }
- }
+ cf_opt_t *opt_current = known_opts;
+ cf_opt_t *opt_next = NULL;
+ while (opt_current != NULL)
+ {
+ opt_next = opt_current->next;
+ free(opt_current);
+ opt_current = opt_next;
+ }
- cfPDFWrite(doc, outputfp);
-
- cf_opt_t *opt_current = known_opts;
- cf_opt_t *opt_next = NULL;
- while (opt_current != NULL)
- {
- opt_next = opt_current->next;
- free(opt_current);
- opt_current = opt_next;
- }
-
- free(buf);
- cfPDFFree(doc);
- return 0;
+ free(buf);
+ cfPDFFree(doc);
+ return (0);
}
-int cfFilterBannerToPDF(int inputfd, /* I - File descriptor input stream */
- int outputfd, /* I - File descriptor output stream */
- int inputseekable, /* I - Is input stream seekable? (unused)*/
- cf_filter_data_t *data, /* I - Job and printer data */
- void *parameters) /* I - Filter-specific parameters -
- Template/Banner data directory */
+int
+cfFilterBannerToPDF(int inputfd, // I - File descriptor input stream
+ int outputfd, // I - File descriptor output stream
+ int inputseekable, // I - Is input stream seekable?
+ // (unused)
+ cf_filter_data_t *data, // I - Job and printer data
+ void *parameters) // I - Filter-specific parameters -
+ // Template/Banner data directory
{
- banner_t *banner;
- int num_options = 0;
- int ret;
- FILE *inputfp;
- FILE *outputfp;
- int tempfd;
- cups_option_t *options = NULL;
- char tempfile[1024], buffer[1024];
- size_t bytes;
- const char *datadir = (const char *)parameters;
-
- cf_logfunc_t log = data->logfunc;
- void *ld = data->logdata;
- cf_filter_iscanceledfunc_t iscanceled = data->iscanceledfunc;
- void *icd = data->iscanceleddata;
- char jobid[50];
-
- num_options = cfJoinJobOptionsAndAttrs(data, num_options, &options);
-
- /*
- * Open the input data stream specified by the inputfd...
- */
-
- if ((inputfp = fdopen(inputfd, "rb")) == NULL)
+ banner_t *banner;
+ int num_options = 0;
+ int ret;
+ FILE *inputfp;
+ FILE *outputfp;
+ int tempfd;
+ cups_option_t *options = NULL;
+ char tempfile[1024], buffer[1024];
+ size_t bytes;
+ const char *datadir = (const char *)parameters;
+
+ cf_logfunc_t log = data->logfunc;
+ void *ld = data->logdata;
+ cf_filter_iscanceledfunc_t iscanceled = data->iscanceledfunc;
+ void *icd = data->iscanceleddata;
+ char jobid[50];
+
+ num_options = cfJoinJobOptionsAndAttrs(data, num_options, &options);
+
+ //
+ // Open the input data stream specified by the inputfd...
+ //
+
+ if ((inputfp = fdopen(inputfd, "rb")) == NULL)
+ {
+ if (!iscanceled || !iscanceled(icd))
{
- if (!iscanceled || !iscanceled(icd))
- {
- if (log)
- log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterBannerToPDF: Unable to open input data stream.");
- }
- return (1);
- }
-
- /*
- * Copy the input data stream into a temporary file...
- */
-
- if ((tempfd = cupsTempFd(tempfile, sizeof(tempfile))) < 0)
- {
- if (log) log(ld, CF_LOGLEVEL_ERROR,
- "cfFilterBannerToPDF: Unable to copy input file: %s",
- strerror(errno));
- return (1);
- }
-
- if (log) log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterBannerToPDF: Copying input to temp file \"%s\"",
- tempfile);
-
- while ((bytes = fread(buffer, 1, sizeof(buffer), inputfp)) > 0)
- bytes = write(tempfd, buffer, bytes);
-
- if (inputfd)
- {
- fclose(inputfp);
- close(inputfd);
- }
- close(tempfd);
-
- /*
- * Open the output data stream specified by the outputfd...
- */
-
- if ((outputfp = fdopen(outputfd, "w")) == NULL)
- {
- if (!iscanceled || !iscanceled(icd))
- {
- if (log)
- log(ld, CF_LOGLEVEL_DEBUG,
- "cfFilterBannerToPDF: Unable to open output data stream.");
- }
-
- fclose(inputfp);
- return (1);
- }
-
- /*
- * Parse the instructions...
- */
- banner = banner_new_from_file(tempfile, &num_options, &options, datadir,
- log, ld);
-
- if (!banner)
+ if (log)
+ log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterBannerToPDF: Unable to open input data stream.");
+ }
+ return (1);
+ }
+
+ //
+ // Copy the input data stream into a temporary file...
+ //
+
+ if ((tempfd = cupsTempFd(tempfile, sizeof(tempfile))) < 0)
+ {
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "cfFilterBannerToPDF: Unable to copy input file: %s",
+ strerror(errno));
+ return (1);
+ }
+
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterBannerToPDF: Copying input to temp file \"%s\"",
+ tempfile);
+
+ while ((bytes = fread(buffer, 1, sizeof(buffer), inputfp)) > 0)
+ bytes = write(tempfd, buffer, bytes);
+
+ if (inputfd)
+ {
+ fclose(inputfp);
+ close(inputfd);
+ }
+ close(tempfd);
+
+ //
+ // Open the output data stream specified by the outputfd...
+ //
+
+ if ((outputfp = fdopen(outputfd, "w")) == NULL)
+ {
+ if (!iscanceled || !iscanceled(icd))
{
- if (log)
- log(ld, CF_LOGLEVEL_ERROR, "cfFilterBannerToPDF: Could not read banner file");
- return 1;
- }
-
- sprintf(jobid, "%d", data->job_id);
-
- /*
- * Create the banner/test page
- */
- ret = generate_banner_pdf(banner,
- data,
- jobid,
- data->job_user,
- data->job_title,
- num_options,
- options,
- log,
- ld,
- outputfp);
-
- /*
- * Clean up...
- */
- banner_free(banner);
- if (options) cupsFreeOptions(num_options, options);
- unlink(tempfile);
-
- return ret;
+ if (log)
+ log(ld, CF_LOGLEVEL_DEBUG,
+ "cfFilterBannerToPDF: Unable to open output data stream.");
+ }
+
+ fclose(inputfp);
+ return (1);
+ }
+
+ //
+ // Parse the instructions...
+ //
+
+ banner = banner_new_from_file(tempfile, &num_options, &options, datadir,
+ log, ld);
+
+ if (!banner)
+ {
+ if (log)
+ log(ld, CF_LOGLEVEL_ERROR, "cfFilterBannerToPDF: Could not read banner file");
+ return (1);
+ }
+
+ sprintf(jobid, "%d", data->job_id);
+
+ //
+ // Create the banner/test page
+ //
+
+ ret = generate_banner_pdf(banner,
+ data,
+ jobid,
+ data->job_user,
+ data->job_title,
+ num_options,
+ options,
+ log,
+ ld,
+ outputfp);
+
+ //
+ // Clean up...
+ //
+
+ banner_free(banner);
+ if (options) cupsFreeOptions(num_options, options);
+ unlink(tempfile);
+
+ return (ret);
}
-/*
-Copyright (c) 2020, Vikrant Malik
+//
+// Copyright (c) 2020, Vikrant Malik
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// MIT Open Source License - http://www.opensource.org/
+//
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-MIT Open Source License - http://www.opensource.org/
-
-*/
#include "image.h"
#include <stdio.h>
#include <cups/raster.h>
unsigned int dither1[16][16] = {
- {0,128,32,160,8,136,40,168,2,130,34,162,10,138,42,170},
- {192,64,224,96,200,72,232,104,194,66,226,98,202,74,234,106},
- {48,176,16,144,56,184,24,152,50,178,18,146,58,186,26,154},
- {240,112,208,80,248,120,216,88,242,114,210,82,250,122,218,90},
- {12,140,44,172,4,132,36,164,14,142,46,174,6,134,38,166},
- {204,76,236,108,196,68,228,100,206,78,238,110,198,70,230,102},
- {60,188,28,156,52,180,20,148,62,190,30,158,54,182,22,150},
- {252,124,220,92,244,116,212,84,254,126,222,94,246,118,214,86},
- {3,131,35,163,11,139,43,171,1,129,33,161,9,137,41,169},
- {195,67,227,99,203,75,235,107,193,65,225,97,201,73,233,105},
- {51,179,19,147,59,187,27,155,49,177,17,145,57,185,25,153},
- {243,115,211,83,251,123,219,91,241,113,209,81,249,121,217,89},
- {15,143,47,175,7,135,39,167,13,141,45,173,5,133,37,165},
- {207,79,239,111,199,71,231,103,205,77,237,109,197,69,229,101},
- {63,191,31,159,55,183,23,151,61,189,29,157,53,181,21,149},
- {255,127,223,95,247,119,215,87,253,125,221,93,245,117,213,85}
+ { 0, 128, 32, 160, 8, 136, 40, 168, 2, 130, 34, 162, 10, 138, 42, 170},
+ {192, 64, 224, 96, 200, 72, 232, 104, 194, 66, 226, 98, 202, 74, 234, 106},
+ { 48, 176, 16, 144, 56, 184, 24, 152, 50, 178, 18, 146, 58, 186, 26, 154},
+ {240, 112, 208, 80, 248, 120, 216, 88, 242, 114, 210, 82, 250, 122, 218, 90},
+ { 12, 140, 44, 172, 4, 132, 36, 164, 14, 142, 46, 174, 6, 134, 38, 166},
+ {204, 76, 236, 108, 196, 68, 228, 100, 206, 78, 238, 110, 198, 70, 230, 102},
+ { 60, 188, 28, 156, 52, 180, 20, 148, 62, 190, 30, 158, 54, 182, 22, 150},
+ {252, 124, 220, 92, 244, 116, 212, 84, 254, 126, 222, 94, 246, 118, 214, 86},
+ { 3, 131, 35, 163, 11, 139, 43, 171, 1, 129, 33, 161, 9, 137, 41, 169},
+ {195, 67, 227, 99, 203, 75, 235, 107, 193, 65, 225, 97, 201, 73, 233, 105},
+ { 51, 179, 19, 147, 59, 187, 27, 155, 49, 177, 17, 145, 57, 185, 25, 153},
+ {243, 115, 211, 83, 251, 123, 219, 91, 241, 113, 209, 81, 249, 121, 217, 89},
+ { 15, 143, 47, 175, 7, 135, 39, 167, 13, 141, 45, 173, 5, 133, 37, 165},
+ {207, 79, 239, 111, 199, 71, 231, 103, 205, 77, 237, 109, 197, 69, 229, 101},
+ { 63, 191, 31, 159, 55, 183, 23, 151, 61, 189, 29, 157, 53, 181, 21, 149},
+ {255, 127, 223, 95, 247, 119, 215, 87, 253, 125, 221, 93, 245, 117, 213, 85}
};
+
unsigned int dither2[8][8] = {
- {0,32,8,40,2,34,10,42},
- {48,16,56,24,50,18,58,26},
- {12,44,4,36,14,46,6,38},
- {60,28,52,20,62,30,54,22},
- {3,35,11,43,1,33,9,41},
- {51,19,59,27,49,17,57,25},
- {15,47,7,39,13,45,5,37},
- {63,31,55,23,61,29,53,21}
+ { 0, 32, 8, 40, 2, 34, 10, 42},
+ {48, 16, 56, 24, 50, 18, 58, 26},
+ {12, 44, 4, 36, 14, 46, 6, 38},
+ {60, 28, 52, 20, 62, 30, 54, 22},
+ { 3, 35, 11, 43, 1, 33, 9, 41},
+ {51, 19, 59, 27, 49, 17, 57, 25},
+ {15, 47, 7, 39, 13, 45, 5, 37},
+ {63, 31, 55, 23, 61, 29, 53, 21}
};
+
unsigned int dither4[4][4] = {
- {0,8,2,10},
- {12,4,14,6},
- {3,11,1,9},
- {15,7,13,5}
+ { 0, 8, 2, 10},
+ {12, 4, 14, 6},
+ { 3, 11, 1, 9},
+ {15, 7, 13, 5}
};
+
unsigned char revTable[256] = {
0x00,0x80,0x40,0xc0,0x20,0xa0,0x60,0xe0,0x10,0x90,0x50,0xd0,0x30,0xb0,0x70,0xf0,
0x08,0x88,0x48,0xc8,0x28,0xa8,0x68,0xe8,0x18,0x98,0x58,0xd8,0x38,0xb8,0x78,0xf8,
0x0f,0x8f,0x4f,0xcf,0x2f,0xaf,0x6f,0xef,0x1f,0x9f,0x5f,0xdf,0x3f,0xbf,0x7f,0xff
};
-/*
- * 'cfConvertBits()' - Convert 8 bit raster data to bitspercolor raster data using
- * ordered dithering.
- */
-
-unsigned char * /* O - Output string */
-cfConvertBits(unsigned char *src, /* I - Input string */
- unsigned char *dst, /* I - Destination string */
- unsigned int x, /* I - Column */
- unsigned int y, /* I - Row */
- unsigned int cupsNumColors,/* I - Number of color components of output data */
- unsigned int bitspercolor) /* I - Bitspercolor of output data */
+
+//
+// 'cfConvertBits()' - Convert 8 bit raster data to bitspercolor
+// raster data using ordered dithering.
+//
+
+unsigned char * // O - Output string
+cfConvertBits(unsigned char *src, // I - Input string
+ unsigned char *dst, // I - Destination string
+ unsigned int x, // I - Column
+ unsigned int y, // I - Row
+ unsigned int cupsNumColors,// I - Number of color components of
+ // output data
+ unsigned int bitspercolor) // I - Bitspercolor of output data
{
- /* assumed that max number of colors is 4 */
+ // assumed that max number of colors is 4
unsigned char c = 0;
unsigned short s = 0;
- switch (bitspercolor) {
- case 1:
- if (cupsNumColors != 1) {
- for (unsigned int i = 0;i < cupsNumColors; i++) {
- c <<= 1;
- /* ordered dithering */
- if (src[i] > dither1[y & 0xf][x & 0xf]) {
- c |= 0x1;
- }
- }
- *dst = c;
- }
- else {
- return src; /*Do not convert bits if both bitspercolor and numcolors are 1*/
- }
- break;
- case 2:
- for (unsigned int i = 0;i < cupsNumColors;i++) {
- unsigned int d;
- c <<= 2;
- /* ordered dithering */
- d = src[i] + dither2[y & 0x7][x & 0x7];
- if (d > 255) d = 255;
- c |= d >> 6;
- }
- *dst = c;
- break;
- case 4:
- for (unsigned int i = 0;i < cupsNumColors;i++) {
- unsigned int d;
- s <<= 4;
- /* ordered dithering */
- d = src[i] + dither4[y & 0x3][x & 0x3];
- if (d > 255) d = 255;
- s |= d >> 4;
- }
- if (cupsNumColors < 3) {
- dst[0] = s;
- } else {
- dst[0] = s >> 8;
- dst[1] = s;
- }
- break;
- case 16:
- for (unsigned int i = 0;i < cupsNumColors;i++) {
- dst[i*2] = src[i];
- dst[i*2+1] = src[i];
- }
- break;
- case 8:
- case 0:
- default:
- return src;
- break;
+ switch (bitspercolor)
+ {
+ case 1:
+ if (cupsNumColors != 1)
+ {
+ for (unsigned int i = 0; i < cupsNumColors; i++)
+ {
+ c <<= 1;
+ // ordered dithering
+ if (src[i] > dither1[y & 0xf][x & 0xf])
+ c |= 0x1;
+ }
+ *dst = c;
+ }
+ else
+ return (src); // Do not convert bits if both bitspercolor and
+ // numcolors are 1
+ break;
+ case 2:
+ for (unsigned int i = 0; i < cupsNumColors; i++)
+ {
+ unsigned int d;
+ c <<= 2;
+ // ordered dithering
+ d = src[i] + dither2[y & 0x7][x & 0x7];
+ if (d > 255)
+ d = 255;
+ c |= d >> 6;
+ }
+ *dst = c;
+ break;
+ case 4:
+ for (unsigned int i = 0; i < cupsNumColors; i++)
+ {
+ unsigned int d;
+ s <<= 4;
+ // ordered dithering
+ d = src[i] + dither4[y & 0x3][x & 0x3];
+ if (d > 255)
+ d = 255;
+ s |= d >> 4;
+ }
+ if (cupsNumColors < 3)
+ dst[0] = s;
+ else
+ {
+ dst[0] = s >> 8;
+ dst[1] = s;
+ }
+ break;
+ case 16:
+ for (unsigned int i = 0; i < cupsNumColors; i++)
+ {
+ dst[i * 2] = src[i];
+ dst[i * 2 + 1] = src[i];
+ }
+ break;
+ case 8:
+ case 0:
+ default:
+ return (src);
+ break;
}
- return dst;
+
+ return (dst);
}
-/*
- * 'cfWritePixel()' - Write a pixel from pixelBuf to dst based on color order.
- */
-
-void /* O - Exit status */
-cfWritePixel(unsigned char *dst, /* I - Destination string */
- unsigned int plane, /* I - Plane/Band */
- unsigned int pixeli, /* I - Pixel */
- unsigned char *pixelBuf, /* I - Input string */
- unsigned int cupsNumColors,/* I - Number of color components of output data */
- unsigned int bitspercolor, /* I - Bitspercolor of output data */
- cups_order_t colororder) /* I - Color Order of output data */
+
+//
+// 'cfWritePixel()' - Write a pixel from pixelBuf to dst based on
+// color order.
+//
+
+void // O - Exit status
+cfWritePixel(unsigned char *dst, // I - Destination string
+ unsigned int plane, // I - Plane/Band
+ unsigned int pixeli, // I - Pixel
+ unsigned char *pixelBuf, // I - Input string
+ unsigned int cupsNumColors,// I - Number of color components of
+ // output data
+ unsigned int bitspercolor, // I - Bitspercolor of output data
+ cups_order_t colororder) // I - Color Order of output data
{
unsigned int bo;
unsigned char so;
- switch (colororder) {
- case CUPS_ORDER_PLANAR:
- case CUPS_ORDER_BANDED:
- if (cupsNumColors != 1) {
- switch (bitspercolor) {
- case 1:
- bo = pixeli & 0x7;
- so = cupsNumColors - plane - 1;
- if ((pixeli & 7) == 0) dst[pixeli/8] = 0;
- dst[pixeli/8] |= ((*pixelBuf >> so) & 1) << (7-bo);
- break;
- case 2:
- bo = (pixeli & 0x3)*2;
- so = (cupsNumColors - plane - 1)*2;
- if ((pixeli & 3) == 0) dst[pixeli/4] = 0;
- dst[pixeli/4] |= ((*pixelBuf >> so) & 3) << (6-bo);
- break;
- case 4:
- {
- unsigned short c = (pixelBuf[0] << 8) | pixelBuf[1];
- bo = (pixeli & 0x1)*4;
- so = (cupsNumColors - plane - 1)*4;
- if ((pixeli & 1) == 0) dst[pixeli/2] = 0;
- dst[pixeli/2] |= ((c >> so) & 0xf) << (4-bo);
- }
- break;
- case 8:
- dst[pixeli] = pixelBuf[plane];
- break;
- case 16:
- default:
- dst[pixeli*2] = pixelBuf[plane*2];
- dst[pixeli*2+1] = pixelBuf[plane*2+1];
- break;
- }
- break;
- }
- case CUPS_ORDER_CHUNKED:
- default:
- switch (bitspercolor)
- {
- case 1:
- switch (cupsNumColors) {
- case 1:
- {
- unsigned int bo = pixeli & 0x7;
- if ((pixeli & 7) == 0) dst[pixeli/8] = 0;
- dst[pixeli/8] |= *pixelBuf << (7-bo);
- }
- break;
- case 6:
- dst[pixeli] = *pixelBuf;
- break;
- case 3:
- case 4:
- default:
- {
- unsigned int qo = (pixeli & 0x1)*4;
- if ((pixeli & 1) == 0) dst[pixeli/2] = 0;
- dst[pixeli/2] |= *pixelBuf << (4-qo);
- }
- break;
- }
- break;
- case 2:
- switch (cupsNumColors) {
- case 1:
- {
- unsigned int bo = (pixeli & 0x3)*2;
- if ((pixeli & 3) == 0) dst[pixeli/4] = 0;
- dst[pixeli/4] |= *pixelBuf << (6-bo);
- }
- break;
- case 3:
- case 4:
- default:
- dst[pixeli] = *pixelBuf;
- break;
- }
- break;
- case 4:
- switch (cupsNumColors) {
- case 1:
- {
- unsigned int bo = (pixeli & 0x1)*4;
- if ((pixeli & 1) == 0) dst[pixeli/2] = 0;
- dst[pixeli/2] |= *pixelBuf << (4-bo);
- }
- break;
- case 3:
- case 4:
- default:
- dst[pixeli*2] = pixelBuf[0];
- dst[pixeli*2+1] = pixelBuf[1];
- break;
- }
- break;
- case 8:
- {
- unsigned char *dp = dst + pixeli*cupsNumColors;
- for (unsigned int i = 0;i < cupsNumColors;i++) {
- dp[i] = pixelBuf[i];
- }
- }
- break;
- case 16:
+ switch (colororder)
+ {
+ case CUPS_ORDER_PLANAR:
+ case CUPS_ORDER_BANDED:
+ if (cupsNumColors != 1)
+ {
+ switch (bitspercolor)
+ {
+ case 1:
+ bo = pixeli & 0x7;
+ so = cupsNumColors - plane - 1;
+ if ((pixeli & 7) == 0)
+ dst[pixeli / 8] = 0;
+ dst[pixeli / 8] |= ((*pixelBuf >> so) & 1) << (7 - bo);
+ break;
+ case 2:
+ bo = (pixeli & 0x3) * 2;
+ so = (cupsNumColors - plane - 1) * 2;
+ if ((pixeli & 3) == 0)
+ dst[pixeli / 4] = 0;
+ dst[pixeli / 4] |= ((*pixelBuf >> so) & 3) << (6 - bo);
+ break;
+ case 4:
+ {
+ unsigned short c = (pixelBuf[0] << 8) | pixelBuf[1];
+ bo = (pixeli & 0x1) * 4;
+ so = (cupsNumColors - plane - 1) * 4;
+ if ((pixeli & 1) == 0)
+ dst[pixeli / 2] = 0;
+ dst[pixeli / 2] |= ((c >> so) & 0xf) << (4 - bo);
+ }
+ break;
+ case 8:
+ dst[pixeli] = pixelBuf[plane];
+ break;
+ case 16:
+ default:
+ dst[pixeli * 2] = pixelBuf[plane * 2];
+ dst[pixeli * 2 +1] = pixelBuf[plane * 2 + 1];
+ break;
+ }
+ break;
+ }
+ case CUPS_ORDER_CHUNKED:
default:
- {
- unsigned char *dp = dst + pixeli*cupsNumColors*2;
- for (unsigned int i = 0;i < cupsNumColors*2;i++) {
- dp[i] = pixelBuf[i];
- }
- }
- break;
- }
- break;
+ switch (bitspercolor)
+ {
+ case 1:
+ switch (cupsNumColors)
+ {
+ case 1:
+ {
+ unsigned int bo = pixeli & 0x7;
+ if ((pixeli & 7) == 0)
+ dst[pixeli / 8] = 0;
+ dst[pixeli / 8] |= *pixelBuf << (7 - bo);
+ }
+ break;
+ case 6:
+ dst[pixeli] = *pixelBuf;
+ break;
+ case 3:
+ case 4:
+ default:
+ {
+ unsigned int qo = (pixeli & 0x1) * 4;
+ if ((pixeli & 1) == 0)
+ dst[pixeli / 2] = 0;
+ dst[pixeli / 2] |= *pixelBuf << (4 - qo);
+ }
+ break;
+ }
+ break;
+ case 2:
+ switch (cupsNumColors)
+ {
+ case 1:
+ {
+ unsigned int bo = (pixeli & 0x3) * 2;
+ if ((pixeli & 3) == 0)
+ dst[pixeli / 4] = 0;
+ dst[pixeli / 4] |= *pixelBuf << (6 - bo);
+ }
+ break;
+ case 3:
+ case 4:
+ default:
+ dst[pixeli] = *pixelBuf;
+ break;
+ }
+ break;
+ case 4:
+ switch (cupsNumColors)
+ {
+ case 1:
+ {
+ unsigned int bo = (pixeli & 0x1) * 4;
+ if ((pixeli & 1) == 0)
+ dst[pixeli / 2] = 0;
+ dst[pixeli / 2] |= *pixelBuf << (4 - bo);
+ }
+ break;
+ case 3:
+ case 4:
+ default:
+ dst[pixeli * 2] = pixelBuf[0];
+ dst[pixeli * 2 + 1] = pixelBuf[1];
+ break;
+ }
+ break;
+ case 8:
+ {
+ unsigned char *dp = dst + pixeli * cupsNumColors;
+ for (unsigned int i = 0; i < cupsNumColors; i++)
+ dp[i] = pixelBuf[i];
+ }
+ break;
+ case 16:
+ default:
+ {
+ unsigned char *dp = dst + pixeli * cupsNumColors * 2;
+ for (unsigned int i = 0; i < cupsNumColors * 2; i++)
+ dp[i] = pixelBuf[i];
+ }
+ break;
+ }
+ break;
}
}
-/*
- * 'cfReverseOneBitLine()' - Reverse the order of pixels in one line of 1-bit raster data.
- */
-unsigned char * /* O - Output string */
-cfReverseOneBitLine(unsigned char *src, /* I - Input line */
- unsigned char *dst, /* I - Destination string */
- unsigned int pixels,/* I - Number of pixels */
- unsigned int size) /* I - Bytesperline */
+//
+// 'cfReverseOneBitLine()' - Reverse the order of pixels in one line
+// of 1-bit raster data.
+//
+
+unsigned char * // O - Output string
+cfReverseOneBitLine(unsigned char *src, // I - Input line
+ unsigned char *dst, // I - Destination string
+ unsigned int pixels,// I - Number of pixels
+ unsigned int size) // I - Bytesperline
{
unsigned char *bp;
unsigned char *dp;
- unsigned int npadbits = (size*8)-pixels;
+ unsigned int npadbits = (size * 8) - pixels;
- if (npadbits == 0) {
- bp = src+size-1;
+ if (npadbits == 0)
+ {
+ bp = src + size - 1;
dp = dst;
- for (unsigned int j = 0;j < size;j++,bp--,dp++) {
+ for (unsigned int j = 0; j < size; j++, bp--, dp++)
*dp = revTable[*bp];
- }
- } else {
- unsigned int pd,d;
+ }
+ else
+ {
+ unsigned int pd, d;
unsigned int sw;
- size = (pixels+7)/8;
- sw = (size*8)-pixels;
- bp = src+size-1;
+ size = (pixels + 7) / 8;
+ sw = (size * 8) - pixels;
+ bp = src + size - 1;
dp = dst;
pd = *bp--;
- for (unsigned int j = 1;j < size;j++,bp--,dp++) {
+ for (unsigned int j = 1; j < size; j++, bp--, dp++)
+ {
d = *bp;
*dp = revTable[(((d << 8) | pd) >> sw) & 0xff];
pd = d;
}
*dp = revTable[(pd >> sw) & 0xff];
}
- return dst;
+ return (dst);
}
-/*
- * 'cfReverseOneBitLineSwap()' - Reverse the order of pixels in one line of 1-bit raster data
- * and invert the colors.
- */
+//
+// 'cfReverseOneBitLineSwap()' - Reverse the order of pixels in one
+// line of 1-bit raster data and invert
+// the colors.
+//
-unsigned char * /* O - Output string */
-cfReverseOneBitLineSwap(unsigned char *src, /* I - Input line */
- unsigned char *dst, /* I - Destination string */
- unsigned int pixels,/* I - Number of pixels */
- unsigned int size) /* I - Bytesperline */
+unsigned char * // O - Output string
+cfReverseOneBitLineSwap(unsigned char *src, // I - Input line
+ unsigned char *dst, // I - Destination string
+ unsigned int pixels,// I - Number of pixels
+ unsigned int size) // I - Bytesperline
{
unsigned char *bp;
unsigned char *dp;
- unsigned int npadbits = (size*8)-pixels;
+ unsigned int npadbits = (size * 8) - pixels;
- if (npadbits == 0) {
- bp = src+size-1;
+ if (npadbits == 0)
+ {
+ bp = src + size - 1;
dp = dst;
- for (unsigned int j = 0;j < size;j++,bp--,dp++) {
+ for (unsigned int j = 0; j < size; j++, bp--, dp++)
*dp = revTable[(unsigned char)(~*bp)];
- }
- } else {
- unsigned int pd,d;
+ }
+ else
+ {
+ unsigned int pd, d;
unsigned int sw;
- size = (pixels+7)/8;
- sw = (size*8)-pixels;
- bp = src+size-1;
+ size = (pixels + 7) / 8;
+ sw = (size * 8) - pixels;
+ bp = src + size - 1;
dp = dst;
pd = *bp--;
- for (unsigned int j = 1;j < size;j++,bp--,dp++) {
+ for (unsigned int j = 1; j < size; j++, bp--, dp++)
+ {
d = *bp;
*dp = ~revTable[(((d << 8) | pd) >> sw) & 0xff];
pd = d;
}
*dp = ~revTable[(pd >> sw) & 0xff];
}
- return dst;
+ return (dst);
}
-/*
- * 'cfOneBitLine()' - Convert one line of 8-bit raster data to 1-bit raster data using ordered dithering.
- */
-void /* O - Output line */
-cfOneBitLine(unsigned char *src, /* I - Input line */
- unsigned char *dst, /* O - Destination line */
- unsigned int width, /* I - Width of raster image in pixels */
- unsigned int row, /* I - Current Row */
- int bi_level) /* I - Bi-level option */
+//
+// 'cfOneBitLine()' - Convert one line of 8-bit raster data to 1-bit
+// raster data using ordered dithering.
+//
+
+void // O - Output line
+cfOneBitLine(unsigned char *src, // I - Input line
+ unsigned char *dst, // O - Destination line
+ unsigned int width, // I - Width of raster image in pixels
+ unsigned int row, // I - Current Row
+ int bi_level) // I - Bi-level option
{
- // If bi_level is true, do threshold dithering to produce black and white output
- // else, do ordered dithering.
+ // If bi_level is true, do threshold dithering to produce black and
+ // white output else, do ordered dithering.
unsigned char t = 0;
unsigned int threshold = 0;
- for(unsigned int w = 0; w < width; w+=8){
+ for (unsigned int w = 0; w < width; w += 8)
+ {
t = 0;
- for (int k = 0; k < 8; k++) {
+ for (int k = 0; k < 8; k++)
+ {
t <<= 1;
if (w + k < width) {
if (bi_level)
}
}
-/*
- * 'cfOneBitToGrayLine()' - Convert one line of 1-bit raster data to 8-bit
- * raster data.
- */
-void /* O - Output line */
-cfOneBitToGrayLine(unsigned char *src, /* I - Input line */
- unsigned char *dst, /* O - Destination line */
- unsigned int width) /* I - Width of raster image in pixels */
+//
+// 'cfOneBitToGrayLine()' - Convert one line of 1-bit raster data to
+// 8-bit raster data.
+//
+
+void // O - Output line
+cfOneBitToGrayLine(unsigned char *src, // I - Input line
+ unsigned char *dst, // O - Destination line
+ unsigned int width) // I - Width of raster image in
+ // pixels
{
unsigned char mask = 0x80;
- for (unsigned int w = 0; w < width; w += 1) {
- if (mask == 0) {
+ for (unsigned int w = 0; w < width; w += 1)
+ {
+ if (mask == 0)
+ {
mask = 0x80;
src ++;
}
}
}
-/*
- * 'cfRGB8toKCMYcm()' - Convert one pixel of 8-bit RGB data to KCMYcm raster data.
- */
-unsigned char *cfRGB8toKCMYcm(unsigned char *src,
- unsigned char *dst,
- unsigned int x,
- unsigned int y)
+//
+// 'cfRGB8toKCMYcm()' - Convert one pixel of 8-bit RGB data to KCMYcm
+// raster data.
+//
+
+unsigned char
+*cfRGB8toKCMYcm(unsigned char *src,
+ unsigned char *dst,
+ unsigned int x,
+ unsigned int y)
{
unsigned char cmyk[4];
unsigned char c;
unsigned char d;
- cfImageRGBToCMYK(src,cmyk,1);
+ cfImageRGBToCMYK(src, cmyk, 1);
c = 0;
d = dither1[y & 0xf][x & 0xf];
- /* K */
- if (cmyk[3] > d) {
+ // K
+ if (cmyk[3] > d)
c |= 0x20;
- }
- /* C */
- if (cmyk[0] > d) {
+ // C
+ if (cmyk[0] > d)
c |= 0x10;
- }
- /* M */
- if (cmyk[1] > d) {
+ // M
+ if (cmyk[1] > d)
c |= 0x08;
- }
- /* Y */
- if (cmyk[2] > d) {
+ // Y
+ if (cmyk[2] > d)
c |= 0x04;
- }
- if (c == 0x18) { /* Blue */
- c = 0x11; /* cyan + light magenta */
- } else if (c == 0x14) { /* Green */
- c = 0x06; /* light cyan + yellow */
- }
+ if (c == 0x18) // Blue
+ c = 0x11; // cyan + light magenta
+ else if (c == 0x14) // Green
+ c = 0x06; // light cyan + yellow
*dst = c;
- return dst;
+ return (dst);
}
-/*
-Copyright (c) 2020, Vikrant Malik
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-MIT Open Source License - http://www.opensource.org/
-
-*/
-
-
+//
+// Copyright (c) 2020, Vikrant Malik
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// MIT Open Source License - http://www.opensource.org/
+//
+
+#ifndef _CUPS_FILTERS_BITMAP_H_
+# define _CUPS_FILTERS_BITMAP_H_
# ifdef __cplusplus
extern "C" {
-# endif /* __cplusplus */
+# endif // __cplusplus
#include <cups/raster.h>
# ifdef __cplusplus
}
-# endif /* __cplusplus */
+# endif // __cplusplus
+#endif // !_CUPS_FILTERS_BITMAP_H_
- /***
- This file is part of cups-filters.
-
- This file is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- This file 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 Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
- USA.
-***/
-
-/*
- * Include necessary headers.
- */
+//
+// This file is part of cups-filters.
+//
+// This file is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License as
+// published by the Free Software Foundation; either version 2.1 of the
+// License, or (at your option) any later version.
+//
+// This file 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 Lesser General
+// Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with avahi; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+// USA.
+//
+
+//
+// Include necessary headers.
+//
#include <config.h>
#include <cupsfilters/catalog.h>
-int /* O - 1 on success, 0 on failure */
-cfGetURI(const char *url, /* I - URL to get */
- char *name, /* I - Temporary filename */
- size_t namesize) /* I - Size of temporary filename
- buffer */
+int // O - 1 on success, 0 on failure
+cfGetURI(const char *url, // I - URL to get
+ char *name, // I - Temporary filename
+ size_t namesize) // I - Size of temporary filename
+ // buffer
{
http_t *http = NULL;
- char scheme[32], /* URL scheme */
- userpass[256], /* URL username:password */
- host[256], /* URL host */
- resource[256]; /* URL resource */
- int port; /* URL port */
- http_encryption_t encryption; /* Type of encryption to use */
- http_status_t status; /* Status of GET request */
- int fd; /* Temporary file */
+ char scheme[32], // URL scheme
+ userpass[256], // URL username:password
+ host[256], // URL host
+ resource[256]; // URL resource
+ int port; // URL port
+ http_encryption_t encryption; // Type of encryption to use
+ http_status_t status; // Status of GET request
+ int fd; // Temporary file
if (httpSeparateURI(HTTP_URI_CODING_ALL, url, scheme, sizeof(scheme),
close(fd);
httpClose(http);
- if (status != HTTP_STATUS_OK) {
+ if (status != HTTP_STATUS_OK)
+ {
unlink(name);
*name = '\0';
return (0);
}
-/*
- * 'cfCatalogFind()' - Find a CUPS message catalog file containing
- * human-readable standard option and choice names
- * for IPP printers
- */
+//
+// 'cfCatalogFind()' - Find a CUPS message catalog file containing
+// human-readable standard option and choice names
+// for IPP printers
+//
const char *
cfCatalogSearchDir(const char *dirname)
int i;
if (dirname == NULL)
- return NULL;
+ return (NULL);
- /* Check first whether we have an English file and prefer this */
+ // Check first whether we have an English file and prefer this
snprintf(catalogpath, sizeof(catalogpath), "%s/en/cups_en.po", dirname);
- if (access(catalogpath, R_OK) == 0) {
- /* Found */
+ if (access(catalogpath, R_OK) == 0)
+ {
+ // Found
catalog = strdup(catalogpath);
- return catalog;
+ return (catalog);
}
if ((dir = cupsDirOpen(dirname)) == NULL)
- return NULL;
+ return (NULL);
- while ((subdirentry = cupsDirRead(dir)) != NULL) {
- /* Do we actually have a subdir? */
+ while ((subdirentry = cupsDirRead(dir)) != NULL)
+ {
+ // Do we actually have a subdir?
if (!S_ISDIR(subdirentry->fileinfo.st_mode))
continue;
- /* Check format of subdir name */
+ // Check format of subdir name
c1 = subdirentry->filename;
if (c1[0] < 'a' || c1[0] > 'z' || c1[1] < 'a' || c1[1] > 'z')
continue;
strncpy(lang, c1, i);
lang[i] = '\0';
snprintf(subdirpath, sizeof(subdirpath), "%s/%s", dirname, c1);
- if ((subdir = cupsDirOpen(subdirpath)) != NULL) {
- while ((catalogentry = cupsDirRead(subdir)) != NULL) {
- /* Do we actually have a regular file? */
+ if ((subdir = cupsDirOpen(subdirpath)) != NULL)
+ {
+ while ((catalogentry = cupsDirRead(subdir)) != NULL)
+ {
+ // Do we actually have a regular file?
if (!S_ISREG(catalogentry->fileinfo.st_mode))
continue;
- /* Check format of catalog name */
+ // Check format of catalog name
c2 = catalogentry->filename;
if (strlen(c2) < 10 || strncmp(c2, "cups_", 5) != 0 ||
strncmp(c2 + 5, lang, i) != 0 ||
strcmp(c2 + strlen(c2) - 3, ".po"))
continue;
- /* Is catalog readable ? */
+ // Is catalog readable ?
snprintf(catalogpath, sizeof(catalogpath), "%s/%s", subdirpath, c2);
if (access(catalogpath, R_OK) != 0)
continue;
- /* Found */
+ // Found
catalog = strdup(catalogpath);
break;
}
}
cupsDirClose(dir);
- return catalog;
+ return (catalog);
}
const char *catalog = NULL, *c;
char buf[1024];
- /* Directory supplied by calling program, from config file,
- environment variable, ... */
+ // Directory supplied by calling program, from config file,
+ // environment variable, ...
if ((catalog = cfCatalogSearchDir(preferreddir)) != NULL)
goto found;
- /* Directory supplied by environment variable CUPS_LOCALEDIR */
+ // Directory supplied by environment variable CUPS_LOCALEDIR
if ((catalog = cfCatalogSearchDir(getenv("CUPS_LOCALEDIR"))) != NULL)
goto found;
- /* Determine CUPS datadir (usually /usr/share/cups) */
+ // Determine CUPS datadir (usually /usr/share/cups)
if ((c = getenv("CUPS_DATADIR")) == NULL)
c = CUPS_DATADIR;
- /* Search /usr/share/cups/locale/ (location which
- Debian/Ubuntu package of CUPS is using) */
+ // Search /usr/share/cups/locale/ (location which
+ // Debian/Ubuntu package of CUPS is using)
snprintf(buf, sizeof(buf), "%s/locale", c);
if ((catalog = cfCatalogSearchDir(buf)) != NULL)
goto found;
- /* Search /usr/(local/)share/locale/ (standard location
- which CUPS is using on Linux) */
+ // Search /usr/(local/)share/locale/ (standard location
+ // which CUPS is using on Linux)
snprintf(buf, sizeof(buf), "%s/../locale", c);
if ((catalog = cfCatalogSearchDir(buf)) != NULL)
goto found;
- /* Search /usr/(local/)lib/locale/ (standard location
- which CUPS is using on many non-Linux systems) */
+ // Search /usr/(local/)lib/locale/ (standard location
+ // which CUPS is using on many non-Linux systems)
snprintf(buf, sizeof(buf), "%s/../../lib/locale", c);
if ((catalog = cfCatalogSearchDir(buf)) != NULL)
goto found;
found:
- return catalog;
+ return (catalog);
}
void *b,
void *user_data)
{
- return strcasecmp(((catalog_choice_strings_t *)a)->name,
- ((catalog_choice_strings_t *)b)->name);
+ return (strcasecmp(((catalog_choice_strings_t *)a)->name,
+ ((catalog_choice_strings_t *)b)->name));
}
void *b,
void *user_data)
{
- return strcasecmp(((catalog_opt_strings_t *)a)->name,
- ((catalog_opt_strings_t *)b)->name);
+ return (strcasecmp(((catalog_opt_strings_t *)a)->name,
+ ((catalog_opt_strings_t *)b)->name));
}
{
catalog_choice_strings_t *entry_rec = (catalog_choice_strings_t *)entry;
- if (entry_rec) {
+ if (entry_rec)
+ {
if (entry_rec->name) free(entry_rec->name);
if (entry_rec->human_readable) free(entry_rec->human_readable);
free(entry_rec);
{
catalog_opt_strings_t *entry_rec = (catalog_opt_strings_t *)entry;
- if (entry_rec) {
+ if (entry_rec)
+ {
if (entry_rec->name) free(entry_rec->name);
if (entry_rec->human_readable) free(entry_rec->human_readable);
if (entry_rec->choices) cupsArrayDelete(entry_rec->choices);
cups_array_t *
cfCatalogOptionArrayNew()
{
- return cupsArrayNew3(compare_options, NULL, NULL, 0,
- NULL, cfCatalogFreeOptionStrings);
+ return (cupsArrayNew3(compare_options, NULL, NULL, 0,
+ NULL, cfCatalogFreeOptionStrings));
}
catalog_opt_strings_t opt;
if (!name || !options)
- return NULL;
+ return (NULL);
opt.name = name;
- return cupsArrayFind(options, &opt);
+ return (cupsArrayFind(options, &opt));
}
catalog_choice_strings_t choice;
if (!name || !choices)
- return NULL;
+ return (NULL);
choice.name = name;
- return cupsArrayFind(choices, &choice);
+ return (cupsArrayFind(choices, &choice));
}
catalog_opt_strings_t *opt = NULL;
if (!name || !options)
- return NULL;
+ return (NULL);
- if ((opt = cfCatalogFindOption(options, name)) == NULL) {
+ if ((opt = cfCatalogFindOption(options, name)) == NULL)
+ {
opt = calloc(1, sizeof(catalog_opt_strings_t));
- if (!opt) return NULL;
+ if (!opt)
+ return (NULL);
opt->human_readable = NULL;
opt->choices = cupsArrayNew3(compare_choices, NULL, NULL, 0,
NULL, cfCatalogFreeChoiceStrings);
- if (!opt->choices) {
+ if (!opt->choices)
+ {
free(opt);
- return NULL;
+ return (NULL);
}
opt->name = strdup(name);
- if (!cupsArrayAdd(options, opt)) {
+ if (!cupsArrayAdd(options, opt))
+ {
cfCatalogFreeOptionStrings(opt, NULL);
- return NULL;
+ return (NULL);
}
}
if (human_readable)
opt->human_readable = strdup(human_readable);
- return opt;
+ return (opt);
}
catalog_opt_strings_t *opt;
if (!name || !human_readable || !opt_name || !options)
- return NULL;
+ return (NULL);
opt = cfCatalogAddOption(opt_name, NULL, options);
- if (!opt) return NULL;
+ if (!opt)
+ return (NULL);
- if ((choice = cfCatalogFindChoice(opt->choices, name)) == NULL) {
+ if ((choice = cfCatalogFindChoice(opt->choices, name)) == NULL)
+ {
choice = calloc(1, sizeof(catalog_choice_strings_t));
- if (!choice) return NULL;
+ if (!choice)
+ return (NULL);
choice->human_readable = NULL;
choice->name = strdup(name);
- if (!cupsArrayAdd(opt->choices, choice)) {
+ if (!cupsArrayAdd(opt->choices, choice))
+ {
cfCatalogFreeChoiceStrings(choice, NULL);
- return NULL;
+ return (NULL);
}
}
if (human_readable)
choice->human_readable = strdup(human_readable);
- return choice;
+ return (choice);
}
catalog_opt_strings_t *opt = NULL;
if (!name || !options)
- return NULL;
+ return (NULL);
if (printer_options &&
(opt = cfCatalogFindOption(printer_options, name)) != NULL)
- return opt->human_readable;
+ return (opt->human_readable);
if ((opt = cfCatalogFindOption(options, name)) != NULL)
- return opt->human_readable;
+ return (opt->human_readable);
else
- return NULL;
+ return (NULL);
}
catalog_choice_strings_t *choice = NULL;
if (!name || !opt_name || !options)
- return NULL;
+ return (NULL);
if (printer_options &&
(opt = cfCatalogFindOption(printer_options, opt_name)) != NULL &&
(choice = cfCatalogFindChoice(opt->choices, name)) != NULL)
- return choice->human_readable;
+ return (choice->human_readable);
else if ((opt = cfCatalogFindOption(options, opt_name)) != NULL &&
(choice = cfCatalogFindChoice(opt->choices, name)) != NULL)
- return choice->human_readable;
+ return (choice->human_readable);
else
- return NULL;
+ return (NULL);
}
char *ptr, *start, *start2, *end, *end2, *sep;
char *opt_name = NULL, *choice_name = NULL,
*human_readable = NULL;
- int part = -1; /* -1: before first "msgid" or invalid
- line
- 0: "msgid"
- 1: "msgstr"
- 2: "..." = "..."
- 10: EOF, save last entry */
+ int part = -1; // -1: before first "msgid" or invalid
+ // line
+ // 0: "msgid"
+ // 1: "msgstr"
+ // 2: "..." = "..."
+ // 10: EOF, save last entry
int digit;
int found_in_catalog = 0;
if (location == NULL || (strncasecmp(location, "http:", 5) &&
- strncasecmp(location, "https:", 6))) {
+ strncasecmp(location, "https:", 6)))
+ {
if (location == NULL ||
(stat(location, &statbuf) == 0 &&
- S_ISDIR(statbuf.st_mode))) /* directory? */
+ S_ISDIR(statbuf.st_mode))) // directory?
{
filename = cfCatalogFind(location);
if (filename)
return;
}
- while (cupsFileGets(fp, line, sizeof(line)) || (part = 10)) {
- /* Find a pair of quotes delimiting a string in each line
- and optional "msgid" or "msgstr" keywords, or a
- "..." = "..." pair. Skip comments ('#') and empty lines. */
- if (part < 10) {
+ while (cupsFileGets(fp, line, sizeof(line)) || (part = 10))
+ {
+ // Find a pair of quotes delimiting a string in each line
+ // and optional "msgid" or "msgstr" keywords, or a
+ // "..." = "..." pair. Skip comments ('#') and empty lines.
+ if (part < 10)
+ {
ptr = line;
while (isspace(*ptr)) ptr ++;
if (*ptr == '#' || *ptr == '\0') continue;
if (*(end - 1) == '\\') continue;
start2 = NULL;
end2 = NULL;
- if (start > ptr) {
+ if (start > ptr)
+ {
if (*(start - 1) == '\\') continue;
if (strncasecmp(ptr, "msgid", 5) == 0) part = 0;
if (strncasecmp(ptr, "msgstr", 6) == 0) part = 1;
- } else {
+ }
+ else
+ {
start2 = ptr;
while ((start2 = strchr(start2 + 1, '\"')) < end &&
*(start2 - 1) == '\\');
- if (start2 < end) {
- /* Line with "..." = "..." of text/strings format */
+ if (start2 < end)
+ {
+ // Line with "..." = "..." of text/strings format
end2 = end;
end = start2;
start2 ++;
start2 ++;
*end2 = '\0';
part = 2;
- } else
- /* Continuation line in message catalog file */
+ }
+ else
+ // Continuation line in message catalog file
start2 = NULL;
}
start ++;
*end = '\0';
}
- /* Read out the strings between the quotes and save entries */
- if (part == 0 || part == 2 || part == 10) {
- /* Save previous attribute */
- if (human_readable) {
- if (opt_name) {
- if (choice_name) {
+ // Read out the strings between the quotes and save entries
+ if (part == 0 || part == 2 || part == 10)
+ {
+ // Save previous attribute
+ if (human_readable)
+ {
+ if (opt_name)
+ {
+ if (choice_name)
+ {
cfCatalogAddChoice(choice_name, human_readable,
opt_name, options);
free(choice_name);
- } else
+ }
+ else
cfCatalogAddOption(opt_name, human_readable, options);
free(opt_name);
}
choice_name = NULL;
human_readable = NULL;
}
- /* Stop the loop after saving the last entry */
+ // Stop the loop after saving the last entry
if (part == 10)
break;
- /* IPP attribute has to be defined with a single msgid line,
- no continuation lines */
- if (opt_name) {
+ // IPP attribute has to be defined with a single msgid line,
+ // no continuation lines
+ if (opt_name)
+ {
free (opt_name);
opt_name = NULL;
- if (choice_name) {
+ if (choice_name)
+ {
free (choice_name);
choice_name = NULL;
}
part = -1;
continue;
}
- /* No continuation line in text/strings format */
- if (part == 2 && (start2 == NULL || end2 == NULL)) {
+ // No continuation line in text/strings format
+ if (part == 2 && (start2 == NULL || end2 == NULL))
+ {
part = -1;
continue;
}
- /* Check line if it is a valid IPP attribute:
- No spaces, only lowercase letters, digits, '-', '_',
- "option" or "option.choice" */
+ // Check line if it is a valid IPP attribute:
+ // No spaces, only lowercase letters, digits, '-', '_',
+ // "option" or "option.choice"
for (ptr = start, sep = NULL; ptr < end; ptr ++)
- if (*ptr == '.') { /* Separator between option and choice */
- if (!sep) { /* Only the first '.' counts */
+ if (*ptr == '.') // Separator between option and choice
+ {
+ if (!sep) // Only the first '.' counts
+ {
sep = ptr + 1;
*ptr = '\0';
}
- } else if (!((*ptr >= 'a' && *ptr <= 'z') ||
- (*ptr >= '0' && *ptr <= '9') ||
- *ptr == '-' || *ptr == '_'))
+ }
+ else if (!((*ptr >= 'a' && *ptr <= 'z') ||
+ (*ptr >= '0' && *ptr <= '9') ||
+ *ptr == '-' || *ptr == '_'))
break;
- if (ptr < end) { /* Illegal character found */
+ if (ptr < end) // Illegal character found
+ {
part = -1;
continue;
}
- if (strlen(start) > 0) /* Option name found */
+ if (strlen(start) > 0) // Option name found
opt_name = strdup(start);
- else { /* Empty option name */
+ else // Empty option name
+ {
part = -1;
continue;
}
- if (sep && strlen(sep) > 0) /* Choice name found */
+ if (sep && strlen(sep) > 0) // Choice name found
choice_name = strdup(sep);
- else /* Empty choice name */
+ else // Empty choice name
choice_name = NULL;
- if (part == 2) { /* Human-readable string in the same line */
+ if (part == 2) // Human-readable string in the same line
+ {
start = start2;
end = end2;
}
}
- if (part == 1 || part == 2) {
- /* msgid was not for an IPP attribute, ignore this msgstr */
+ if (part == 1 || part == 2)
+ {
+ // msgid was not for an IPP attribute, ignore this msgstr
if (!opt_name) continue;
- /* Empty string */
+ // Empty string
if (start == end) continue;
- /* Unquote string */
+ // Unquote string
ptr = start;
end = start;
- while (*ptr) {
- if (*ptr == '\\') {
+ while (*ptr)
+ {
+ if (*ptr == '\\')
+ {
ptr ++;
- if (isdigit(*ptr)) {
+ if (isdigit(*ptr))
+ {
digit = 0;
*end = 0;
- while (isdigit(*ptr) && digit < 3) {
+ while (isdigit(*ptr) && digit < 3)
+ {
*end = *end * 8 + *ptr - '0';
digit ++;
ptr ++;
}
end ++;
- } else {
+ }
+ else
+ {
if (*ptr == 'n')
*end ++ = '\n';
else if (*ptr == 'r')
*end ++ = *ptr ++;
}
*end = '\0';
- /* Did the unquoting make the string empty? */
+ // Did the unquoting make the string empty?
if (strlen(start) == 0) continue;
- /* Add the string to our human-readable string */
- if (human_readable) { /* Continuation line */
+ // Add the string to our human-readable string
+ if (human_readable) // Continuation line
+ {
human_readable = realloc(human_readable,
sizeof(char) *
(strlen(human_readable) +
*ptr = ' ';
strncpy(ptr + 1, start,
sizeof(human_readable) - (ptr - human_readable) - 1);
- } else /* First line */
+ }
+ else // First line
human_readable = strdup(start);
}
}
- /***
- This file is part of cups-filters.
-
- This file is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- This file 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 Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
- USA.
-***/
+//
+// This file is part of cups-filters.
+//
+// This file is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License as
+// published by the Free Software Foundation; either version 2.1 of the
+// License, or (at your option) any later version.
+//
+// This file 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 Lesser General
+// Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with avahi; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+// USA.
+//
#ifndef _CUPS_FILTERS_CATALOG_H_
# define _CUPS_FILTERS_CATALOG_H_
# ifdef __cplusplus
extern "C" {
-# endif /* __cplusplus */
+# endif // __cplusplus
-/*
- * Include necessary headers...
- */
+//
+// Include necessary headers...
+//
#include <config.h>
#else
# include <unistd.h>
# include <fcntl.h>
-#endif /* WIN32 || __EMX__ */
+#endif // WIN32 || __EMX__
#include <cups/cups.h>
#include <cups/backend.h>
#include <cups/raster.h>
-/* Data structure for IPP choice name and human-readable string */
+// Data structure for IPP choice name and human-readable string
typedef struct catalog_choice_strings_s {
- char *name, *human_readable;
+ char *name,
+ *human_readable;
} catalog_choice_strings_t;
-/* Data structure for IPP option name, human-readable string, and choice list */
+// Data structure for IPP option name, human-readable string, and choice list
typedef struct catalog_opt_strings_s {
- char *name, *human_readable;
+ char *name,
+ *human_readable;
cups_array_t *choices;
} catalog_opt_strings_t;
-/*
- * Prototypes...
- */
+//
+// Prototypes...
+//
int cfGetURI(const char *url, char *name, size_t namesize);
const char *cfCatalogSearchDir(const char *dirname);
# ifdef __cplusplus
}
-# endif /* __cplusplus */
+# endif // __cplusplus
-#endif /* !_CUPS_FILTERS_CATALOG_H_ */
+#endif // !_CUPS_FILTERS_CATALOG_H_
-/*
- * Byte checking routines for CUPS.
- *
- * Copyright 2007 by Apple Inc.
- * Copyright 1993-2005 by Easy Software Products.
- *
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law. Distribution and use rights are outlined in the file "COPYING"
- * which should have been included with this file.
- *
- * Contents:
- *
- * cfCheckBytes() - Check to see if all bytes are zero.
- * cfCheckValue() - Check to see if all bytes match the given value.
- */
+//
+// Byte checking routines for cups-filters.
+//
+// Copyright 2007 by Apple Inc.
+// Copyright 1993-2005 by Easy Software Products.
+//
+// These coded instructions, statements, and computer programs are the
+// property of Apple Inc. and are protected by Federal copyright
+// law. Distribution and use rights are outlined in the file "COPYING"
+// which should have been included with this file.
+//
+// Contents:
+//
+// cfCheckBytes() - Check to see if all bytes are zero.
+// cfCheckValue() - Check to see if all bytes match the given value.
-/*
- * Include necessary headers.
- */
+
+//
+// Include necessary headers.
+//
#include "driver.h"
-/*
- * 'cfCheckBytes()' - Check to see if all bytes are zero.
- */
+//
+// 'cfCheckBytes()' - Check to see if all bytes are zero.
+//
-int /* O - 1 if they match */
-cfCheckBytes(const unsigned char *bytes, /* I - Bytes to check */
- int length) /* I - Number of bytes to check */
+int // O - 1 if they match
+cfCheckBytes(const unsigned char *bytes, // I - Bytes to check
+ int length) // I - Number of bytes to check
{
while (length > 7)
{
}
-/*
- * 'cfCheckValue()' - Check to see if all bytes match the given value.
- */
+//
+// 'cfCheckValue()' - Check to see if all bytes match the given value.
+//
-int /* O - 1 if they match */
-cfCheckValue(const unsigned char *bytes, /* I - Bytes to check */
- int length, /* I - Number of bytes to check */
- const unsigned char value) /* I - Value to check */
+int // O - 1 if they match
+cfCheckValue(const unsigned char *bytes, // I - Bytes to check
+ int length, // I - Number of bytes to check
+ const unsigned char value) // I - Value to check
{
while (length > 7)
{
return (1);
}
-
-/*
- * CMYK color separation code for CUPS.
- *
- * Copyright 2007-2011 by Apple Inc.
- * Copyright 1993-2005 by Easy Software Products.
- *
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law. Distribution and use rights are outlined in the file "COPYING"
- * which should have been included with this file.
- *
- * Contents:
- *
- * cfCMYKDelete() - Delete a color separation.
- * cfCMYKDoBlack() - Do a black separation...
- * cfCMYKDoCMYK() - Do a CMYK separation...
- * cfCMYKDoGray() - Do a grayscale separation...
- * cfCMYKDoRGB() - Do an sRGB separation...
- * cfCMYKNew() - Create a new CMYK color separation.
- * cfCMYKSetBlack() - Set the transition range for CMY to black.
- * cfCMYKSetCurve() - Set a color transform curve using points.
- * cfCMYKSetGamma() - Set a color transform curve using gamma and
- * density.
- * cfCMYKSetInkLimit() - Set the limit on the amount of ink.
- * cfCMYKSetLtDk() - Set light/dark ink transforms.
- */
-
-/*
- * Include necessary headers.
- */
+//
+// CMYK color separation code for cups-filters.
+//
+// Copyright 2007-2011 by Apple Inc.
+// Copyright 1993-2005 by Easy Software Products.
+//
+// These coded instructions, statements, and computer programs are the
+// property of Apple Inc. and are protected by Federal copyright
+// law. Distribution and use rights are outlined in the file "COPYING"
+// which should have been included with this file.
+//
+// Contents:
+//
+// cfCMYKDelete() - Delete a color separation.
+// cfCMYKDoBlack() - Do a black separation...
+// cfCMYKDoCMYK() - Do a CMYK separation...
+// cfCMYKDoGray() - Do a grayscale separation...
+// cfCMYKDoRGB() - Do an sRGB separation...
+// cfCMYKNew() - Create a new CMYK color separation.
+// cfCMYKSetBlack() - Set the transition range for CMY to black.
+// cfCMYKSetCurve() - Set a color transform curve using points.
+// cfCMYKSetGamma() - Set a color transform curve using gamma and
+// density.
+// cfCMYKSetInkLimit() - Set the limit on the amount of ink.
+// cfCMYKSetLtDk() - Set light/dark ink transforms.
+//
+
+//
+// Include necessary headers.
+//
#include <config.h>
#include "driver.h"
#include <ctype.h>
-/*
- * 'cfCMYKDelete()' - Delete a color separation.
- */
+//
+// 'cfCMYKDelete()' - Delete a color separation.
+//
void
-cfCMYKDelete(cf_cmyk_t *cmyk) /* I - Color separation */
+cfCMYKDelete(cf_cmyk_t *cmyk) // I - Color separation
{
- /*
- * Range check input...
- */
+ //
+ // Range check input...
+ //
if (cmyk == NULL)
return;
- /*
- * Free memory used...
- */
+ //
+ // Free memory used...
+ //
free(cmyk->channels[0]);
free(cmyk);
}
-/*
- * 'cfCMYKDoBlack()' - Do a black separation...
- */
+//
+// 'cfCMYKDoBlack()' - Do a black separation...
+//
void
-cfCMYKDoBlack(const cf_cmyk_t *cmyk,
- /* I - Color separation */
- const unsigned char *input,
- /* I - Input grayscale pixels */
- short *output,
- /* O - Output Device-N pixels */
- int num_pixels)
- /* I - Number of pixels */
+cfCMYKDoBlack(const cf_cmyk_t *cmyk,
+ // I - Color separation
+ const unsigned char *input,
+ // I - Input grayscale pixels
+ short *output,
+ // O - Output Device-N pixels
+ int num_pixels)
+ // I - Number of pixels
{
- int k; /* Current black value */
- const short **channels; /* Copy of channel LUTs */
- int ink, /* Amount of ink */
- ink_limit; /* Ink limit from separation */
+ int k; // Current black value
+ const short **channels; // Copy of channel LUTs
+ int ink, // Amount of ink
+ ink_limit; // Ink limit from separation
- /*
- * Range check input...
- */
+ //
+ // Range check input...
+ //
if (cmyk == NULL || input == NULL || output == NULL || num_pixels <= 0)
return;
- /*
- * Loop through it all...
- */
+ //
+ // Loop through it all...
+ //
channels = (const short **)cmyk->channels;
ink_limit = cmyk->ink_limit;
switch (cmyk->num_channels)
{
- case 1 : /* Black */
+ case 1 : // Black
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
k = *input++;
*output++ = channels[0][k];
}
break;
- case 2 : /* Black, light black */
+ case 2 : // Black, light black
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
k = *input++;
output[0] = channels[0][k];
}
break;
- case 3 : /* CMY */
+ case 3 : // CMY
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
k = *input++;
output[0] = channels[0][k];
}
break;
- case 4 : /* CMYK */
+ case 4 : // CMYK
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
k = *input++;
*output++ = 0;
}
break;
- case 6 : /* CcMmYK */
+ case 6 : // CcMmYK
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
k = *input++;
*output++ = 0;
}
break;
- case 7 : /* CcMmYKk */
+ case 7 : // CcMmYKk
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
k = *input++;
output[0] = 0;
}
-/*
- * 'cfCMYKDoCMYK()' - Do a CMYK separation...
- */
+//
+// 'cfCMYKDoCMYK()' - Do a CMYK separation...
+//
void
-cfCMYKDoCMYK(const cf_cmyk_t *cmyk,
- /* I - Color separation */
- const unsigned char *input,
- /* I - Input grayscale pixels */
- short *output,
- /* O - Output Device-N pixels */
- int num_pixels)
- /* I - Number of pixels */
+cfCMYKDoCMYK(const cf_cmyk_t *cmyk,
+ // I - Color separation
+ const unsigned char *input,
+ // I - Input grayscale pixels
+ short *output,
+ // O - Output Device-N pixels
+ int num_pixels)
+ // I - Number of pixels
{
- int c, /* Current cyan value */
- m, /* Current magenta value */
- y, /* Current yellow value */
- k; /* Current black value */
- const short **channels; /* Copy of channel LUTs */
- int ink, /* Amount of ink */
- ink_limit; /* Ink limit from separation */
+ int c, // Current cyan value
+ m, // Current magenta value
+ y, // Current yellow value
+ k; // Current black value
+ const short **channels; // Copy of channel LUTs
+ int ink, // Amount of ink
+ ink_limit; // Ink limit from separation
- /*
- * Range check input...
- */
+ //
+ // Range check input...
+ //
if (cmyk == NULL || input == NULL || output == NULL || num_pixels <= 0)
return;
- /*
- * Loop through it all...
- */
+ //
+ // Loop through it all...
+ //
channels = (const short **)cmyk->channels;
ink_limit = cmyk->ink_limit;
switch (cmyk->num_channels)
{
- case 1 : /* Black */
+ case 1 : // Black
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
c = *input++;
m = *input++;
}
break;
- case 2 : /* Black, light black */
+ case 2 : // Black, light black
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
c = *input++;
m = *input++;
}
break;
- case 3 : /* CMY */
+ case 3 : // CMY
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
c = *input++;
m = *input++;
}
break;
- case 4 : /* CMYK */
+ case 4 : // CMYK
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
c = *input++;
m = *input++;
}
break;
- case 6 : /* CcMmYK */
+ case 6 : // CcMmYK
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
c = *input++;
m = *input++;
}
break;
- case 7 : /* CcMmYKk */
+ case 7 : // CcMmYKk
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
c = *input++;
m = *input++;
}
-/*
- * 'cfCMYKDoGray()' - Do a grayscale separation...
- */
+//
+// 'cfCMYKDoGray()' - Do a grayscale separation...
+//
void
-cfCMYKDoGray(const cf_cmyk_t *cmyk,
- /* I - Color separation */
- const unsigned char *input,
- /* I - Input grayscale pixels */
- short *output,
- /* O - Output Device-N pixels */
- int num_pixels)
- /* I - Number of pixels */
+cfCMYKDoGray(const cf_cmyk_t *cmyk,
+ // I - Color separation
+ const unsigned char *input,
+ // I - Input grayscale pixels
+ short *output,
+ // O - Output Device-N pixels
+ int num_pixels)
+ // I - Number of pixels
{
- int k, /* Current black value */
- kc; /* Current black color value */
- const short **channels; /* Copy of channel LUTs */
- int ink, /* Amount of ink */
- ink_limit; /* Ink limit from separation */
+ int k, // Current black value
+ kc; // Current black color value
+ const short **channels; // Copy of channel LUTs
+ int ink, // Amount of ink
+ ink_limit; // Ink limit from separation
- /*
- * Range check input...
- */
+ //
+ // Range check input...
+ //
if (cmyk == NULL || input == NULL || output == NULL || num_pixels <= 0)
return;
- /*
- * Loop through it all...
- */
+ //
+ // Loop through it all...
+ //
channels = (const short **)cmyk->channels;
ink_limit = cmyk->ink_limit;
switch (cmyk->num_channels)
{
- case 1 : /* Black */
+ case 1 : // Black
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
k = cf_scmy_lut[*input++];
*output++ = channels[0][k];
}
break;
- case 2 : /* Black, light black */
+ case 2 : // Black, light black
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
k = cf_scmy_lut[*input++];
output[0] = channels[0][k];
}
break;
- case 3 : /* CMY */
+ case 3 : // CMY
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
k = cf_scmy_lut[*input++];
output[0] = channels[0][k];
}
break;
- case 4 : /* CMYK */
+ case 4 : // CMYK
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
k = cf_scmy_lut[*input++];
kc = cmyk->color_lut[k];
}
break;
- case 6 : /* CcMmYK */
+ case 6 : // CcMmYK
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
k = cf_scmy_lut[*input++];
kc = cmyk->color_lut[k];
}
break;
- case 7 : /* CcMmYKk */
+ case 7 : // CcMmYKk
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
k = cf_scmy_lut[*input++];
kc = cmyk->color_lut[k];
}
-/*
- * 'cfCMYKDoRGB()' - Do an sRGB separation...
- */
+//
+// 'cfCMYKDoRGB()' - Do an sRGB separation...
+//
void
-cfCMYKDoRGB(const cf_cmyk_t *cmyk,
- /* I - Color separation */
- const unsigned char *input,
- /* I - Input grayscale pixels */
- short *output,
- /* O - Output Device-N pixels */
- int num_pixels)
- /* I - Number of pixels */
+cfCMYKDoRGB(const cf_cmyk_t *cmyk,
+ // I - Color separation
+ const unsigned char *input,
+ // I - Input grayscale pixels
+ short *output,
+ // O - Output Device-N pixels
+ int num_pixels)
+ // I - Number of pixels
{
- int c, /* Current cyan value */
- m, /* Current magenta value */
- y, /* Current yellow value */
- k, /* Current black value */
- kc, /* Current black color value */
- km; /* Maximum black value */
- const short **channels; /* Copy of channel LUTs */
- int ink, /* Amount of ink */
- ink_limit; /* Ink limit from separation */
+ int c, // Current cyan value
+ m, // Current magenta value
+ y, // Current yellow value
+ k, // Current black value
+ kc, // Current black color value
+ km; // Maximum black value
+ const short **channels; // Copy of channel LUTs
+ int ink, // Amount of ink
+ ink_limit; // Ink limit from separation
- /*
- * Range check input...
- */
+ //
+ // Range check input...
+ //
if (cmyk == NULL || input == NULL || output == NULL || num_pixels <= 0)
return;
- /*
- * Loop through it all...
- */
+ //
+ // Loop through it all...
+ //
channels = (const short **)cmyk->channels;
ink_limit = cmyk->ink_limit;
switch (cmyk->num_channels)
{
- case 1 : /* Black */
+ case 1 : // Black
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
c = cf_scmy_lut[*input++];
m = cf_scmy_lut[*input++];
}
break;
- case 2 : /* Black, light black */
+ case 2 : // Black, light black
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
c = cf_scmy_lut[*input++];
m = cf_scmy_lut[*input++];
}
break;
- case 3 : /* CMY */
+ case 3 : // CMY
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
c = cf_scmy_lut[*input++];
m = cf_scmy_lut[*input++];
}
break;
- case 4 : /* CMYK */
+ case 4 : // CMYK
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
c = cf_scmy_lut[*input++];
m = cf_scmy_lut[*input++];
}
break;
- case 6 : /* CcMmYK */
+ case 6 : // CcMmYK
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
c = cf_scmy_lut[*input++];
m = cf_scmy_lut[*input++];
}
break;
- case 7 : /* CcMmYKk */
+ case 7 : // CcMmYKk
while (num_pixels > 0)
{
- /*
- * Get the input black value and then set the corresponding color
- * channel values...
- */
+ //
+ // Get the input black value and then set the corresponding color
+ // channel values...
+ //
c = cf_scmy_lut[*input++];
m = cf_scmy_lut[*input++];
}
-/*
- * 'cfCMYKNew()' - Create a new CMYK color separation.
- */
+//
+// 'cfCMYKNew()' - Create a new CMYK color separation.
+//
-cf_cmyk_t * /* O - New CMYK separation or NULL */
-cfCMYKNew(int num_channels) /* I - Number of color components */
+cf_cmyk_t * // O - New CMYK separation or NULL
+cfCMYKNew(int num_channels) // I - Number of color components
{
- cf_cmyk_t *cmyk; /* New color separation */
- int i; /* Looping var */
+ cf_cmyk_t *cmyk; // New color separation
+ int i; // Looping var
- /*
- * Range-check the input...
- */
+ //
+ // Range-check the input...
+ //
if (num_channels < 1)
return (NULL);
- /*
- * Allocate memory for the separation...
- */
+ //
+ // Allocate memory for the separation...
+ //
if ((cmyk = calloc(1, sizeof(cf_cmyk_t))) == NULL)
return (NULL);
- /*
- * Allocate memory for the LUTs...
- */
+ //
+ // Allocate memory for the LUTs...
+ //
cmyk->num_channels = num_channels;
for (i = 1; i < num_channels; i ++)
cmyk->channels[i] = cmyk->channels[0] + i * 256;
- /*
- * Fill in the LUTs with unity transitions...
- */
+ //
+ // Fill in the LUTs with unity transitions...
+ //
for (i = 0; i < 256; i ++)
cmyk->black_lut[i] = i;
switch (num_channels)
{
- case 1 : /* K */
- case 2 : /* Kk */
+ case 1 : // K
+ case 2 : // Kk
for (i = 0; i < 256; i ++)
{
cmyk->channels[0][i] = CF_MAX_LUT * i / 255;
}
break;
- case 3 : /* CMY */
+ case 3 : // CMY
for (i = 0; i < 256; i ++)
{
cmyk->channels[0][i] = CF_MAX_LUT * i / 255;
cmyk->channels[2][i] = CF_MAX_LUT * i / 255;
}
break;
- case 4 : /* CMYK */
+ case 4 : // CMYK
for (i = 0; i < 256; i ++)
{
cmyk->channels[0][i] = CF_MAX_LUT * i / 255;
cmyk->channels[3][i] = CF_MAX_LUT * i / 255;
}
break;
- case 6 : /* CcMmYK */
- case 7 : /* CcMmYKk */
+ case 6 : // CcMmYK
+ case 7 : // CcMmYKk
for (i = 0; i < 256; i ++)
{
cmyk->channels[0][i] = CF_MAX_LUT * i / 255;
break;
}
- /*
- * Return the separation...
- */
+ //
+ // Return the separation...
+ //
return (cmyk);
}
-/*
- * 'cfCMYKSetBlack()' - Set the transition range for CMY to black.
- */
+//
+// 'cfCMYKSetBlack()' - Set the transition range for CMY to black.
+//
void
-cfCMYKSetBlack(cf_cmyk_t *cmyk, /* I - CMYK color separation */
- float lower, /* I - No black ink */
- float upper, /* I - Only black ink */
- cf_logfunc_t log, /* I - Log function */
- void *ld) /* I - Log function data */
+cfCMYKSetBlack(cf_cmyk_t *cmyk, // I - CMYK color separation
+ float lower, // I - No black ink
+ float upper, // I - Only black ink
+ cf_logfunc_t log, // I - Log function
+ void *ld) // I - Log function data
{
- int i, /* Looping var */
- delta, /* Difference between lower and upper */
- ilower, /* Lower level from 0 to 255 */
- iupper; /* Upper level from 0 to 255 */
+ int i, // Looping var
+ delta, // Difference between lower and upper
+ ilower, // Lower level from 0 to 255
+ iupper; // Upper level from 0 to 255
- /*
- * Range check input...
- */
+ //
+ // Range check input...
+ //
if (cmyk == NULL || lower < 0.0 || lower > 1.0 || upper < 0.0 || upper > 1.0 ||
lower > upper)
return;
- /*
- * Convert lower and upper to integers from 0 to 255...
- */
+ //
+ // Convert lower and upper to integers from 0 to 255...
+ //
ilower = (int)(255.0 * lower + 0.5);
iupper = (int)(255.0 * upper + 0.5);
delta = iupper - ilower;
- /*
- * Generate the CMY-only data...
- */
+ //
+ // Generate the CMY-only data...
+ //
for (i = 0; i < ilower; i ++)
{
cmyk->color_lut[i] = i;
}
- /*
- * Then the transition data...
- */
+ //
+ // Then the transition data...
+ //
for (; i < iupper; i ++)
{
cmyk->color_lut[i] = ilower - ilower * (i - ilower) / delta;
}
- /*
- * Then the K-only data...
- */
+ //
+ // Then the K-only data...
+ //
for (; i < 256; i ++)
{
}
-/*
- * 'cfCMYKSetCurve()' - Set a color transform curve using points.
- */
+//
+// 'cfCMYKSetCurve()' - Set a color transform curve using points.
+//
void
-cfCMYKSetCurve(cf_cmyk_t *cmyk, /* I - CMYK color separation */
- int channel, /* I - Color channel */
- int num_xypoints,
- /* I - Number of X,Y points */
- const float *xypoints, /* I - X,Y points */
- cf_logfunc_t log, /* I - Log function */
- void *ld) /* I - Log function data */
+cfCMYKSetCurve(cf_cmyk_t *cmyk, // I - CMYK color separation
+ int channel, // I - Color channel
+ int num_xypoints,
+ // I - Number of X,Y points
+ const float *xypoints, // I - X,Y points
+ cf_logfunc_t log, // I - Log function
+ void *ld) // I - Log function data
{
- int i; /* Looping var */
- int xstart; /* Start position */
- int xend; /* End position */
- int xdelta; /* Difference in position */
- int ystart; /* Start value */
- int yend; /* End value */
- int ydelta; /* Difference in value */
+ int i; // Looping var
+ int xstart; // Start position
+ int xend; // End position
+ int xdelta; // Difference in position
+ int ystart; // Start value
+ int yend; // End value
+ int ydelta; // Difference in value
- /*
- * Range check input...
- */
+ //
+ // Range check input...
+ //
if (cmyk == NULL || channel < 0 || channel >= cmyk->num_channels ||
num_xypoints < 1 || xypoints == NULL)
return;
- /*
- * Initialize the lookup table for the specified channel...
- */
+ //
+ // Initialize the lookup table for the specified channel...
+ //
for (xstart = xend = 0, ystart = yend = 0;
num_xypoints > 0;
cmyk->channels[channel][i] = ystart + ydelta * (i - xstart) / xdelta;
}
- /*
- * Initialize any trailing values to the maximum of the last data point...
- */
+ //
+ // Initialize any trailing values to the maximum of the last data point...
+ //
for (i = xend; i < 256; i ++)
cmyk->channels[channel][i] = yend;
}
-/*
- * 'cfCMYKSetGamma()' - Set a color transform curve using gamma and density.
- */
+//
+// 'cfCMYKSetGamma()' - Set a color transform curve using gamma and density.
+//
void
-cfCMYKSetGamma(cf_cmyk_t *cmyk, /* I - CMYK color separation */
- int channel, /* I - Ink channel */
- float gamval, /* I - Gamma correction */
- float density, /* I - Maximum density */
- cf_logfunc_t log, /* I - Log function */
- void *ld) /* I - Log function data */
+cfCMYKSetGamma(cf_cmyk_t *cmyk, // I - CMYK color separation
+ int channel, // I - Ink channel
+ float gamval, // I - Gamma correction
+ float density, // I - Maximum density
+ cf_logfunc_t log, // I - Log function
+ void *ld) // I - Log function data
{
- int i; /* Looping var */
+ int i; // Looping var
- /*
- * Range check input...
- */
+ //
+ // Range check input...
+ //
if (cmyk == NULL || channel < 0 || channel >= cmyk->num_channels ||
gamval <= 0.0 || density <= 0.0 || density > 1.0)
return;
- /*
- * Initialize the lookup table for the specified channel...
- */
+ //
+ // Initialize the lookup table for the specified channel...
+ //
for (i = 0; i < 256; i ++)
cmyk->channels[channel][i] = (int)(density * CF_MAX_LUT *
}
-/*
- * 'cfCMYKSetInkLimit()' - Set the limit on the amount of ink.
- */
+//
+// 'cfCMYKSetInkLimit()' - Set the limit on the amount of ink.
+//
void
-cfCMYKSetInkLimit(cf_cmyk_t *cmyk, /* I - CMYK color separation */
- float limit) /* I - Limit of ink */
+cfCMYKSetInkLimit(cf_cmyk_t *cmyk, // I - CMYK color separation
+ float limit) // I - Limit of ink
{
if (!cmyk || limit < 0.0)
return;
}
-/*
- * 'cfCMYKSetLtDk()' - Set light/dark ink transforms.
- */
+//
+// 'cfCMYKSetLtDk()' - Set light/dark ink transforms.
+//
void
-cfCMYKSetLtDk(cf_cmyk_t *cmyk, /* I - CMYK color separation */
- int channel, /* I - Dark ink channel (+1 for light) */
- float light, /* I - Light ink only level */
- float dark, /* I - Dark ink only level */
- cf_logfunc_t log, /* I - Log function */
- void *ld) /* I - Log function data */
+cfCMYKSetLtDk(cf_cmyk_t *cmyk, // I - CMYK color separation
+ int channel, // I - Dark ink channel (+1 for light)
+ float light, // I - Light ink only level
+ float dark, // I - Dark ink only level
+ cf_logfunc_t log, // I - Log function
+ void *ld) // I - Log function data
{
- int i, /* Looping var */
- delta, /* Difference between lower and upper */
- ilight, /* Light level from 0 to 255 */
- idark; /* Dark level from 0 to 255 */
- short lut[256]; /* Original LUT data */
+ int i, // Looping var
+ delta, // Difference between lower and upper
+ ilight, // Light level from 0 to 255
+ idark; // Dark level from 0 to 255
+ short lut[256]; // Original LUT data
- /*
- * Range check input...
- */
+ //
+ // Range check input...
+ //
if (cmyk == NULL || light < 0.0 || light > 1.0 || dark < 0.0 || dark > 1.0 ||
light > dark || channel < 0 || channel > (cmyk->num_channels - 2))
return;
- /*
- * Convert lower and upper to integers from 0 to 255...
- */
+ //
+ // Convert lower and upper to integers from 0 to 255...
+ //
ilight = (int)(255.0 * light + 0.5);
idark = (int)(255.0 * dark + 0.5);
delta = idark - ilight;
- /*
- * Copy the dark ink LUT...
- */
+ //
+ // Copy the dark ink LUT...
+ //
memcpy(lut, cmyk->channels[channel], sizeof(lut));
- /*
- * Generate the light-only data...
- */
+ //
+ // Generate the light-only data...
+ //
for (i = 0; i < ilight; i ++)
{
cmyk->channels[channel + 1][i] = CF_MAX_LUT * i / ilight;
}
- /*
- * Then the transition data...
- */
+ //
+ // Then the transition data...
+ //
for (; i < idark; i ++)
{
(i - ilight) / delta;
}
- /*
- * Then the K-only data...
- */
+ //
+ // Then the K-only data...
+ //
for (; i < 256; i ++)
{
" %3d = %4dlt + %4ddk", i,
cmyk->channels[channel + 0][i], cmyk->channels[channel + 1][i]);
}
-
-/*
-Copyright (c) 2011, Tim Waugh
-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
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-MIT Open Source License - http://www.opensource.org/
-
-*/
-
-
-/* Common routines for accessing the colord CMS framework */
+//
+// Copyright (c) 2011, Tim Waugh
+// 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
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// MIT Open Source License - http://www.opensource.org/
+//
+
+
+// Common routines for accessing the colord CMS framework
#include <cups/raster.h>
#include <stdio.h>
num_options = cfJoinJobOptionsAndAttrs(data, num_options, &options);
- /* Get data from "cm-profile-qualifier" option */
+ // Get data from "cm-profile-qualifier" option
if ((val =
cupsGetOption("cm-profile-qualifier",
data->num_options, data->options)) != NULL &&
}
else
{
- /* String for resolution */
+ // String for resolution
if (x_res <= 0)
buf[0] = '\0';
else if (y_res <= 0 || y_res == x_res)
else
snprintf(buf, sizeof(buf), "%dx%ddpi", x_res, y_res);
- /* return a NULL terminated array so we don't have to break it up later */
+ // return a NULL terminated array so we don't have to break it up later
tuple = calloc(QUAL_SIZE + 1, sizeof(char*));
tuple[QUAL_COLORSPACE] = strdup(color_space ? color_space : "");
tuple[QUAL_MEDIA] = strdup(media_type ? media_type : "");
cupsFreeOptions(num_options, options);
- return tuple;
+ return (tuple);
}
#ifdef HAVE_DBUS
static char *
-get_filename_for_profile_path (cf_filter_data_t *data,
- DBusConnection *con,
- const char *object_path)
+get_filename_for_profile_path(cf_filter_data_t *data,
+ DBusConnection *con,
+ const char *object_path)
{
cf_logfunc_t log = data->logfunc;
void *ld = data->logdata;
DBusMessageIter sub;
message = dbus_message_new_method_call("org.freedesktop.ColorManager",
- object_path,
- "org.freedesktop.DBus.Properties",
- "Get");
+ 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 */
+ // send syncronous
dbus_error_init(&error);
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "Calling %s.Get(%s)", interface, property);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG, "Calling %s.Get(%s)", interface, property);
reply = dbus_connection_send_with_reply_and_block(con,
- message,
- -1,
- &error);
- if (reply == NULL) {
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "DEBUG: Failed to send: %s:%s",
- error.name, error.message);
+ message,
+ -1,
+ &error);
+ if (reply == NULL)
+ {
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "DEBUG: Failed to send: %s:%s",
+ error.name, error.message);
dbus_error_free(&error);
goto out;
}
- /* get reply data */
+ // get reply data
dbus_message_iter_init(reply, &args);
- if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_VARIANT) {
- if(log) log(ld, CF_LOGLEVEL_DEBUG,"Incorrect reply type");
-
+ if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_VARIANT)
+ {
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Incorrect reply type");
goto out;
}
dbus_message_iter_recurse(&args, &sub);
dbus_message_iter_get_basic(&sub, &tmp);
filename = strdup(tmp);
-out:
+ out:
if (message != NULL)
dbus_message_unref(message);
if (reply != NULL)
dbus_message_unref(reply);
- return filename;
+ return (filename);
}
static char *
-get_profile_for_device_path ( cf_filter_data_t *data,
- DBusConnection *con,
- const char *object_path,
- const char **split)
+get_profile_for_device_path(cf_filter_data_t *data,
+ DBusConnection *con,
+ const char *object_path,
+ const char **split)
{
cf_logfunc_t log = data->logfunc;
void *ld = data->logdata;
"GetProfileForQualifiers");
dbus_message_iter_init_append(message, &args);
- /* create the fallbacks */
+ // create the fallbacks
key = calloc(max_keys + 1, sizeof(char*));
- /* exact match */
+ // exact match
i = 0;
snprintf(str, sizeof(str), "%s.%s.%s",
split[QUAL_COLORSPACE],
DBUS_TYPE_ARRAY,
"s",
&entry);
- for (i=0; key[i] != NULL; i++) {
+ for (i=0; key[i] != NULL; i++)
+ {
dbus_message_iter_append_basic(&entry,
DBUS_TYPE_STRING,
&key[i]);
}
dbus_message_iter_close_container(&args, &entry);
- /* send syncronous */
+ // send syncronous
dbus_error_init(&error);
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "Calling GetProfileForQualifiers(%s...)", key[0]);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Calling GetProfileForQualifiers(%s...)", key[0]);
reply = dbus_connection_send_with_reply_and_block(con,
message,
-1,
&error);
- if (reply == NULL) {
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "Failed to send: %s:%s",
- error.name, error.message);
+ if (reply == NULL)
+ {
+ if (log) log(ld, CF_LOGLEVEL_DEBUG, "Failed to send: %s:%s",
+ error.name, error.message);
dbus_error_free(&error);
goto out;
}
- /* get reply data */
+ // get reply data
dbus_message_iter_init(reply, &args);
- if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_OBJECT_PATH) {
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "Incorrect reply type");
+ if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_OBJECT_PATH)
+ {
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Incorrect reply type");
goto out;
}
dbus_message_iter_get_basic(&args, &tmp);
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "Found profile %s", tmp);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG, "Found profile %s", tmp);
- /* get filename */
+ // get filename
profile = get_filename_for_profile_path(data, con, tmp);
-out:
+ out:
if (message != NULL)
dbus_message_unref(message);
if (reply != NULL)
free(key[i]);
free(key);
}
- return profile;
+ return (profile);
}
static char *
-get_device_path_for_device_id ( cf_filter_data_t *data,
- DBusConnection *con,
- const char *device_id)
+get_device_path_for_device_id(cf_filter_data_t *data,
+ DBusConnection *con,
+ const char *device_id)
{
cf_logfunc_t log = data->logfunc;
void *ld = data->logdata;
dbus_message_iter_init_append(message, &args);
dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &device_id);
- /* send syncronous */
+ // send syncronous
dbus_error_init(&error);
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "Calling FindDeviceById(%s)", device_id);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Calling FindDeviceById(%s)", device_id);
reply = dbus_connection_send_with_reply_and_block(con,
- message,
- -1,
- &error);
- if (reply == NULL) {
- if(log) log(ld, CF_LOGLEVEL_DEBUG, "Failed to send: %s:%s",
- error.name, error.message);
+ message,
+ -1,
+ &error);
+ if (reply == NULL)
+ {
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Failed to send: %s:%s",
+ error.name, error.message);
dbus_error_free(&error);
goto out;
}
- /* get reply data */
+ // get reply data
dbus_message_iter_init(reply, &args);
- if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_OBJECT_PATH) {
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "Incorrect reply type");
+ if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_OBJECT_PATH)
+ {
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Incorrect reply type");
goto out;
}
dbus_message_iter_get_basic(&args, &device_path_tmp);
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "Found device %s", device_path_tmp);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Found device %s", device_path_tmp);
device_path = strdup(device_path_tmp);
-out:
+ out:
if (message != NULL)
dbus_message_unref(message);
if (reply != NULL)
dbus_message_unref(reply);
- return device_path;
+ return (device_path);
}
char *
-cfColordGetProfileForDeviceID (cf_filter_data_t *data,
- const char *device_id,
- const char **qualifier_tuple)
+cfColordGetProfileForDeviceID(cf_filter_data_t *data,
+ const char *device_id,
+ const char **qualifier_tuple)
{
cf_logfunc_t log = data->logfunc;
void *ld = data->logdata;
char *device_path = NULL;
char *filename = NULL;
- if (device_id == NULL) {
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "No colord device ID available");
+ if (device_id == NULL)
+ {
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "No colord device ID available");
goto out;
}
- /* connect to system bus */
+ // connect to system bus
con = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (con == NULL) {
+ if (con == NULL)
+ {
// If D-Bus is not reachable, gracefully leave and ignore error
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "Failed to connect to system bus");
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Failed to connect to system bus");
goto out;
}
- /* find the device */
+ // find the device
device_path = get_device_path_for_device_id (data, con, device_id);
- if (device_path == NULL) {
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "Failed to get device %s", device_id);
+ if (device_path == NULL)
+ {
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Failed to get device %s", device_id);
goto out;
}
- /* get the best profile for the device */
- filename = get_profile_for_device_path(data, con, device_path, qualifier_tuple);
- if (filename == NULL || !filename[0]) {
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "Failed to get profile filename for %s", device_id);
+ // get the best profile for the device
+ filename = get_profile_for_device_path(data, con, device_path,
+ qualifier_tuple);
+ if (filename == NULL || !filename[0])
+ {
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Failed to get profile filename for %s", device_id);
goto out;
}
- if(log) log(ld, CF_LOGLEVEL_ERROR,
- "Use profile filename: '%s'", filename);
-out:
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "Use profile filename: '%s'", filename);
+ out:
free(device_path);
if (con != NULL)
dbus_connection_unref(con);
- return filename;
+ return (filename);
}
static int
-get_profile_inhibitors ( cf_filter_data_t *data,
- DBusConnection *con, const char *object_path)
+get_profile_inhibitors(cf_filter_data_t *data,
+ DBusConnection *con,
+ const char *object_path)
{
cf_logfunc_t log = data->logfunc;
void *ld = data->logdata;
dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &interface);
dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &property);
- /* send syncronous */
+ // send syncronous
dbus_error_init(&error);
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "Calling %s.Get(%s)", interface, property);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Calling %s.Get(%s)", interface, property);
reply = dbus_connection_send_with_reply_and_block(con,
message,
-1,
&error);
- if (reply == NULL) {
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "Failed to send: %s:%s",
- error.name, error.message);
+ if (reply == NULL)
+ {
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Failed to send: %s:%s",
+ error.name, error.message);
dbus_error_free(&error);
goto out;
}
- /* get reply data */
+ // get reply data
dbus_message_iter_init(reply, &args);
- if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_VARIANT) {
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "Incorrect reply type");
+ if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_VARIANT)
+ {
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Incorrect reply type");
goto out;
}
- /* count the size of the array */
+ // 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) {
+ while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID)
+ {
dbus_message_iter_get_basic(&sub, &tmp);
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "Inhibitor %s exists", tmp);
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Inhibitor %s exists", tmp);
dbus_message_iter_next(&sub);
inhibitors++;
}
-out:
+ out:
if (message != NULL)
dbus_message_unref(message);
if (reply != NULL)
dbus_message_unref(reply);
- return inhibitors;
+ return (inhibitors);
}
int
-cfColordGetInhibitForDeviceID (cf_filter_data_t *data,
- const char *device_id)
+cfColordGetInhibitForDeviceID(cf_filter_data_t *data,
+ const char *device_id)
{
cf_logfunc_t log = data->logfunc;
void* ld = data->logdata;
char *device_path = NULL;
int has_inhibitors = FALSE;
- /* connect to system bus */
+ // connect to system bus
con = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (con == NULL) {
+ if (con == NULL)
+ {
// If D-Bus is not reachable, gracefully leave and ignore error
- if(log) log(ld, CF_LOGLEVEL_ERROR,
- "Failed to connect to system bus");
+ if (log) log(ld, CF_LOGLEVEL_ERROR,
+ "Failed to connect to system bus");
goto out;
}
- /* find the device */
+ // find the device
device_path = get_device_path_for_device_id (data, con, device_id);
- if (device_path == NULL) {
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "Failed to get find device %s", device_id);
+ if (device_path == NULL)
+ {
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Failed to get find device %s", device_id);
goto out;
}
- /* get the best profile for the device */
+ // get the best profile for the device
has_inhibitors = get_profile_inhibitors(data, con, device_path);
-out:
+ out:
free(device_path);
if (con != NULL)
dbus_connection_unref(con);
- return has_inhibitors;
+ return (has_inhibitors);
}
#else
char *
-cfColordGetProfileForDeviceID (cf_filter_data_t *data,
- const char *device_id,
- const char **qualifier_tuple)
+cfColordGetProfileForDeviceID(cf_filter_data_t *data,
+ const char *device_id,
+ const char **qualifier_tuple)
{
cf_logfunc_t log = data->logfunc;
void *ld = data->logdata;
- if(log) log(ld, CF_LOGLEVEL_WARN,
- "not compiled with DBus support");
- return NULL;
+ if (log) log(ld, CF_LOGLEVEL_WARN,
+ "not compiled with DBus support");
+ return (NULL);
}
int
-cfColordGetInhibitForDeviceID (cf_filter_data_t *data,
- const char *device_id)
+cfColordGetInhibitForDeviceID(cf_filter_data_t *data,
+ const char *device_id)
{
cf_logfunc_t log = data->logfunc;
void *ld = data->logdata;
- if(log) log(ld, CF_LOGLEVEL_WARN,
- "not compiled with DBus support");
-
- return 0;
+ if (log) log(ld, CF_LOGLEVEL_WARN,
+ "not compiled with DBus support");
+ return (0);
}
#endif
-/*
-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
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-MIT Open Source License - http://www.opensource.org/
-
-*/
+//
+// 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
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// MIT Open Source License - http://www.opensource.org/
+//
#ifndef _CUPS_FILTERS_COLORD_H_
# ifdef __cplusplus
extern "C" {
-# endif /* __cplusplus */
+# endif // __cplusplus
-/* Common routines for accessing the colord CMS framework */
+// Common routines for accessing the colord CMS framework
#include <cups/raster.h>
#include <cupsfilters/filter.h>
# ifdef __cplusplus
}
-# endif /* __cplusplus */
+# endif // __cplusplus
-#endif /* !_CUPS_FILTERS_COLORD_H_ */
+#endif // !_CUPS_FILTERS_COLORD_H_
-/*
-Copyright (c) 2011-2013, Richard Hughes
-Copyright (c) 2014, Joseph Simon
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-MIT Open Source License - http://www.opensource.org/
-
-*/
+//
+// Copyright (c) 2011-2013, Richard Hughes
+// Copyright (c) 2014, Joseph Simon
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// MIT Open Source License - http://www.opensource.org/
+//
#include "colormanager.h"
#define CM_MAX_FILE_LENGTH 1024
-/* Commonly-used calibration numbers */
+//
+// Commonly-used calibration numbers
+//
double adobergb_wp[3] = {0.95045471, 1.0, 1.08905029};
double sgray_wp[3] = {0.9505, 1, 1.0890};
double blackpoint_default[3] = {0.0, 0.0, 0.0};
+//
+// Public functions
+//
+//
+// Get printer color management status from the system's color manager
+//
-/*
- * Public functions
- */
-
-
-/* Get printer color management status from the system's color manager */
int
cfCmIsPrinterCmDisabled(cf_filter_data_t *data)
{
- cf_logfunc_t log = data->logfunc;
- void *ld = data->logdata;
- int is_printer_cm_disabled = 0; /* color management status flag */
- char printer_id[CM_MAX_FILE_LENGTH] = ""; /* colord printer id */
+ cf_logfunc_t log = data->logfunc;
+ void *ld = data->logdata;
+ int is_printer_cm_disabled = 0; // color management status flag
+ char printer_id[CM_MAX_FILE_LENGTH] = ""; // colord printer id
- /* If invalid input, we leave color management alone */
- if (data->printer == NULL) {
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "Color Manager: Invalid printer name.");
- return 0;
- }
+ // If invalid input, we leave color management alone
+ if (data->printer == NULL)
+ {
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Color Manager: Invalid printer name.");
+ return (0);
+ }
- /* Create printer id string for colord */
- snprintf(printer_id, CM_MAX_FILE_LENGTH, "cups-%s", data->printer);
+ // Create printer id string for colord
+ snprintf(printer_id, CM_MAX_FILE_LENGTH, "cups-%s", data->printer);
- /* Check if device is inhibited/disabled in colord */
- is_printer_cm_disabled = cfColordGetInhibitForDeviceID (data, printer_id);
+ // Check if device is inhibited/disabled in colord
+ is_printer_cm_disabled = cfColordGetInhibitForDeviceID (data, printer_id);
- if (is_printer_cm_disabled)
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "Color Manager: Color management disabled by OS.");
+ if (is_printer_cm_disabled)
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Color Manager: Color management disabled by OS.");
- return is_printer_cm_disabled;
+ return (is_printer_cm_disabled);
}
-/* Get printer ICC profile from the system's color manager */
+//
+// Get printer ICC profile from the system's color manager
+//
+
int
cfCmGetPrinterIccProfile(cf_filter_data_t *data,
const char *color_space,
const char *media_type,
int x_res,
int y_res,
- char **profile) /* ICC Profile Path */
+ char **profile) // ICC Profile Path
{
- cf_logfunc_t log = data->logfunc;
- void *ld = data->logdata;
- const char *val;
- int is_profile_set = 0; /* profile-is-found flag */
- char **qualifier = NULL; /* color qualifier strings */
- char *icc_profile = NULL; /* icc profile path */
- char printer_id[CM_MAX_FILE_LENGTH] = ""; /* colord printer id */
-
- if (data->printer == NULL || profile == NULL) {
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "Color Manager: Invalid input - Unable to find profile.");
- return -1;
- }
-
- /* Get color qualifier triple */
- qualifier = cfColordGetQualifier(data, color_space, media_type,
- x_res, y_res);
-
- if (qualifier != NULL) {
- /* Create printer id string for colord */
- snprintf(printer_id, CM_MAX_FILE_LENGTH, "cups-%s", data->printer);
-
- /* Get profile from colord using qualifiers */
- icc_profile = cfColordGetProfileForDeviceID(data,
- (const char *)printer_id,
- (const char **)qualifier);
- }
-
- /* Do we have a profile? */
- if (icc_profile)
- is_profile_set = 1;
- /* If not, get fallback profile from option */
- else if ((val = cupsGetOption("cm-fallback-profile",
- data->num_options, data->options)) != NULL &&
- val[0] != '\0')
- {
- is_profile_set = 1;
- icc_profile = strdup(val);
- }
- else
- icc_profile = NULL;
-
- /* If a profile is found, we give it to the caller */
- if (is_profile_set)
- *profile = strdup(icc_profile);
- else
- *profile = NULL;
-
- if (qualifier != NULL) {
- for (int i=0; qualifier[i] != NULL; i++)
- free(qualifier[i]);
- free(qualifier);
- }
-
- if (icc_profile != NULL)
- free(icc_profile);
-
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "Color Manager: ICC Profile: %s",
- *profile ? *profile : "None");
-
- return is_profile_set;
+ cf_logfunc_t log = data->logfunc;
+ void *ld = data->logdata;
+ const char *val;
+ int is_profile_set = 0; // profile-is-found flag
+ char **qualifier = NULL; // color qualifier strings
+ char *icc_profile = NULL; // icc profile path
+ char printer_id[CM_MAX_FILE_LENGTH] = ""; // colord printer id
+
+ if (data->printer == NULL || profile == NULL)
+ {
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Color Manager: Invalid input - Unable to find profile.");
+ return (-1);
+ }
+
+ // Get color qualifier triple
+ qualifier = cfColordGetQualifier(data, color_space, media_type,
+ x_res, y_res);
+
+ if (qualifier != NULL)
+ {
+ // Create printer id string for colord
+ snprintf(printer_id, CM_MAX_FILE_LENGTH, "cups-%s", data->printer);
+
+ // Get profile from colord using qualifiers
+ icc_profile = cfColordGetProfileForDeviceID(data,
+ (const char *)printer_id,
+ (const char **)qualifier);
+ }
+
+ // Do we have a profile?
+ if (icc_profile)
+ is_profile_set = 1;
+ // If not, get fallback profile from option
+ else if ((val = cupsGetOption("cm-fallback-profile",
+ data->num_options, data->options)) != NULL &&
+ val[0] != '\0')
+ {
+ is_profile_set = 1;
+ icc_profile = strdup(val);
+ }
+ else
+ icc_profile = NULL;
+
+ // If a profile is found, we give it to the caller
+ if (is_profile_set)
+ *profile = strdup(icc_profile);
+ else
+ *profile = NULL;
+
+ if (qualifier != NULL)
+ {
+ for (int i= 0; qualifier[i] != NULL; i++)
+ free(qualifier[i]);
+ free(qualifier);
+ }
+
+ if (icc_profile != NULL)
+ free(icc_profile);
+
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Color Manager: ICC Profile: %s",
+ *profile ? *profile : "None");
+
+ return (is_profile_set);
}
-/* Find the "cm-calibration" CUPS option */
+//
+// Find the "cm-calibration" CUPS option
+//
+
cf_cm_calibration_t
cfCmGetCupsColorCalibrateMode(cf_filter_data_t *data)
{
- int num_options = 0;
- cups_option_t *options = NULL;
- cf_logfunc_t log = data->logfunc;
- void *ld = data->logdata;
- cf_cm_calibration_t status; /* color management status */
+ int num_options = 0;
+ cups_option_t *options = NULL;
+ cf_logfunc_t log = data->logfunc;
+ void *ld = data->logdata;
+ cf_cm_calibration_t status; // color management status
- num_options = cfJoinJobOptionsAndAttrs(data, num_options, &options);
+ num_options = cfJoinJobOptionsAndAttrs(data, num_options, &options);
- /* Find the string in CUPS options and */
- if (cupsGetOption(CF_CM_CALIBRATION_STRING, num_options, options) != NULL)
- status = CF_CM_CALIBRATION_ENABLED;
- else
- status = CF_CM_CALIBRATION_DISABLED;
+ // Find the string in CUPS options and
+ if (cupsGetOption(CF_CM_CALIBRATION_STRING, num_options, options) != NULL)
+ status = CF_CM_CALIBRATION_ENABLED;
+ else
+ status = CF_CM_CALIBRATION_DISABLED;
- if(log) log(ld, CF_LOGLEVEL_DEBUG,
- "Color Manager: %s", status ?
- "Calibration Mode/Enabled" : "Calibration Mode/Off");
+ if (log) log(ld, CF_LOGLEVEL_DEBUG,
+ "Color Manager: %s", status ?
+ "Calibration Mode/Enabled" : "Calibration Mode/Off");
- cupsFreeOptions(num_options, options);
+ cupsFreeOptions(num_options, options);
- return status;
+ return (status);
}
-/* Functions to return specific calibration data */
+//
+// Accessor functions to return specific calibration data
+//
-
-/* Gamma values */
+// Gamma values
double *cfCmGammaAdobeRGB(void)
{
- return adobergb_gamma;
+ return (adobergb_gamma);
}
+
double *cfCmGammaSGray(void)
{
- return sgray_gamma;
+ return (sgray_gamma);
}
-/* Whitepoint values */
+// Whitepoint values
double *cfCmWhitePointAdobeRGB(void)
{
- return adobergb_wp;
+ return (adobergb_wp);
}
+
double *cfCmWhitePointSGray(void)
{
- return sgray_wp;
+ return (sgray_wp);
}
-/* Adapted primaries matrix */
+// Adapted primaries matrix
double *cfCmMatrixAdobeRGB(void)
{
- return adobergb_matrix;
+ return (adobergb_matrix);
}
-/* Blackpoint value */
+// Blackpoint value
double *cfCmBlackPointDefault(void)
{
- return blackpoint_default;
+ return (blackpoint_default);
}
-/*
-Copyright (c) 2014, Joseph Simon
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-MIT Open Source License - http://www.opensource.org/
-
-*/
+//
+// Copyright (c) 2014, Joseph Simon
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// MIT Open Source License - http://www.opensource.org/
+//
#ifndef _CUPS_FILTERS_COLORMANAGER_H_
# define _CUPS_FILTERS_COLORMANAGER_H_
-/* "Color Manager" -- Color management interface for cups-filters */
+// "Color Manager" -- Color management interface for cups-filters
# ifdef __cplusplus
extern "C" {
-# endif /* __cplusplus */
+# endif // __cplusplus
#include <cups/raster.h>
#include <cupsfilters/filter.h>
-#define CF_CM_CALIBRATION_STRING "cm-calibration" /* String for "Color
- Calibration Mode" */
+#define CF_CM_CALIBRATION_STRING "cm-calibration" // String for "Color
+ // Calibration Mode"
-/* Enum for status of CUPS color calibration */
+// Enum for status of CUPS color calibration
typedef enum cf_cm_calibration_e
{
- CF_CM_CALIBRATION_DISABLED = 0, /* "cm-calibration" option
- not found */
- CF_CM_CALIBRATION_ENABLED = 1 /* "cm-calibration" found */
+ CF_CM_CALIBRATION_DISABLED = 0, // "cm-calibration" option
+ // not found
+ CF_CM_CALIBRATION_ENABLED = 1 // "cm-calibration" found
} cf_cm_calibration_t;
-
-/*
- * Prototypes
- */
-
+//
+// Prototypes
+//
extern
cf_cm_calibration_t cfCmGetCupsColorCalibrateMode(cf_filter_data_t *data);
# ifdef __cplusplus
}
-# endif /* __cplusplus */
+# endif // __cplusplus
-#endif /* !_CUPS_FILTERS_COLORMANAGER_H_ */
+#endif // !_CUPS_FILTERS_COLORMANAGER_H_
-/*
- * Internal debugging macros for libcupsfilters.
- *
- * Copyright © 2007-2018 by Apple Inc.
- * Copyright © 1997-2005 by Easy Software Products.
- *
- * Licensed under Apache License v2.0. See the file "LICENSE" for more
- * information.
- */
+//
+// Internal debugging macros for libcupsfilters.
+//
+// Copyright © 2007-2018 by Apple Inc.
+// Copyright © 1997-2005 by Easy Software Products.
+//
+// Licensed under Apache License v2.0. See the file "LICENSE" for more
+// information.
+//
#ifndef _CUPS_FILTERS_DEBUG_INTERNAL_H_
# define _CUPS_FILTERS_DEBUG_INTERNAL_H_
-/*
- * C++ magic...
- */
+//
+// C++ magic...
+//
# ifdef __cplusplus
extern "C" {
-# endif /* __cplusplus */
+# endif // __cplusplus
-/*
- * The debug macros are used if you compile with DEBUG defined.
- *
- * Usage:
- *
- * DEBUG_puts("string");
- * DEBUG_printf(("format string", arg, arg, ...));
- * DEBUG_assert(boolean expression);
- *
- * Note the extra parenthesis around the DEBUG_printf macro...
- */
+//
+// The debug macros are used if you compile with DEBUG defined.
+//
+// Usage:
+//
+// DEBUG_puts("string");
+// DEBUG_printf(("format string", arg, arg, ...));
+// DEBUG_assert(boolean expression);
+//
+// Note the extra parenthesis around the DEBUG_printf macro...
+//
# ifdef DEBUG
# include <assert.h>
# define DEBUG_puts(x)
# define DEBUG_printf(x)
# define DEBUG_assert(x)
-# endif /* DEBUG */
+# endif // DEBUG
# ifdef DEBUG
extern void _cf_debug_printf(const char *format, ...);
extern void _cf_debug_puts(const char *s);
-# endif /* DEBUG */
+# endif // DEBUG
# ifdef __cplusplus
}
-# endif /* __cplusplus */
+# endif // __cplusplus
-#endif /* !_CUPS_FILTERS_DEBUG_INTERNAL_H_ */
+#endif // !_CUPS_FILTERS_DEBUG_INTERNAL_H_
-/*
- * Debugging functions for cupsfilters.
- *
- * Copyright © 2008-2018 by Apple Inc.
- *
- * Licensed under Apache License v2.0. See the file "LICENSE" for more
- * information.
- */
+//
+// Debugging functions for cupsfilters.
+//
+// Copyright © 2008-2018 by Apple Inc.
+//
+// Licensed under Apache License v2.0. See the file "LICENSE" for more
+// information.
+//
-/*
- * Include necessary headers...
- */
+//
+// Include necessary headers...
+//
#include <stdio.h>
#include <stdarg.h>
-/*
- * '_cf_debug_printf()' - Write a formatted line to the log.
- */
+//
+// '_cf_debug_printf()' - Write a formatted line to the log.
+//
void
-_cf_debug_printf(const char *format, /* I - Printf-style format string */
- ...) /* I - Additional arguments as needed */
+_cf_debug_printf(const char *format, // I - Printf-style format string
+ ...) // I - Additional arguments as needed
{
- va_list ap; /* Pointer to arguments */
+ va_list ap; // Pointer to arguments
va_start(ap, format);
vfprintf(stderr, format, ap);
}
-/*
- * '_cf_debug_puts()' - Write a single line to the log.
- */
+//
+// '_cf_debug_puts()' - Write a single line to the log.
+//
void
-_cf_debug_puts(const char *s) /* I - String to output */
+_cf_debug_puts(const char *s) // I - String to output
{
fputs(s, stderr);
fflush(stderr);
-/*
- * Dithering routines for CUPS.
- *
- * Copyright 2007 by Apple Inc.
- * Copyright 1993-2005 by Easy Software Products.
- *
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law. Distribution and use rights are outlined in the file "COPYING"
- * which should have been included with this file.
- *
- * Contents:
- *
- * cfDitherDelete() - Free a dithering buffer.
- * cfDitherLine() - Dither a line of pixels...
- * cfDitherNew() - Create a dithering buffer.
- */
-
-/*
- * Include necessary headers.
- */
+//
+// Dithering routines for CUPS.
+//
+// Copyright 2007 by Apple Inc.
+// Copyright 1993-2005 by Easy Software Products.
+//
+// These coded instructions, statements, and computer programs are the
+// property of Apple Inc. and are protected by Federal copyright
+// law. Distribution and use rights are outlined in the file "COPYING"
+// which should have been included with this file.
+//
+// Contents:
+//
+// cfDitherDelete() - Free a dithering buffer.
+// cfDitherLine() - Dither a line of pixels...
+// cfDitherNew() - Create a dithering buffer.
+//
+
+//
+// Include necessary headers.
+//
#include <config.h>
#include "driver.h"
-/*
- * 'cfDitherDelete()' - Free a dithering buffer.
- *
- * Returns 0 on success, -1 on failure.
- */
+//
+// 'cfDitherDelete()' - Free a dithering buffer.
+//
+// Returns 0 on success, -1 on failure.
+//
void
-cfDitherDelete(cf_dither_t *d) /* I - Dithering buffer */
+cfDitherDelete(cf_dither_t *d) // I - Dithering buffer
{
if (d != NULL)
free(d);
}
-/*
- * 'cfDitherLine()' - Dither a line of pixels...
- */
+//
+// 'cfDitherLine()' - Dither a line of pixels...
+//
void
-cfDitherLine(cf_dither_t *d, /* I - Dither data */
- const cf_lut_t *lut, /* I - Lookup table */
- const short *data, /* I - Separation data */
- int num_channels,
- /* I - Number of components */
- unsigned char *p) /* O - Pixels */
+cfDitherLine(cf_dither_t *d, // I - Dither data
+ const cf_lut_t *lut, // I - Lookup table
+ const short *data, // I - Separation data
+ int num_channels,
+ // I - Number of components
+ unsigned char *p) // O - Pixels
{
- register int x, /* Horizontal position in line... */
- pixel, /* Current adjusted pixel... */
- e, /* Current error */
- e0,e1,e2; /* Error values */
- register int errval0, /* First half of error value */
- errval1, /* Second half of error value */
- errbase, /* Base multiplier */
- errbase0, /* Base multiplier for large values */
- errbase1, /* Base multiplier for small values */
- errrange; /* Range of random multiplier */
- register int *p0, /* Error buffer pointers... */
+ register int x, // Horizontal position in line...
+ pixel, // Current adjusted pixel...
+ e, // Current error
+ e0, e1, e2; // Error values
+ register int errval0, // First half of error value
+ errval1, // Second half of error value
+ errbase, // Base multiplier
+ errbase0, // Base multiplier for large values
+ errbase1, // Base multiplier for small values
+ errrange; // Range of random multiplier
+ register int *p0, // Error buffer pointers...
*p1;
- static char logtable[16384]; /* Error magnitude for randomness */
- static char loginit = 0; /* Has the table been initialized? */
+ static char logtable[16384]; // Error magnitude for randomness
+ static char loginit = 0; // Has the table been initialized?
if (!loginit)
{
- /*
- * Initialize a logarithmic table for the magnitude of randomness
- * that is introduced.
- */
+ //
+ // Initialize a logarithmic table for the magnitude of randomness
+ // that is introduced.
+ //
loginit = 1;
if (d->row == 0)
{
- /*
- * Dither from left to right:
- *
- * e0 == p0[0]
- * e1 e2 == p1[-1] p1[0]
- */
+ //
+ // Dither from left to right:
+ //
+ // e0 == p0[0]
+ // e1 e2 == p1[-1] p1[0]
+ //
p0 = d->errors + 2;
p1 = d->errors + 2 + d->width + 4;
e1 = 0;
e2 = 0;
- /*
- * Error diffuse each output pixel...
- */
+ //
+ // Error diffuse each output pixel...
+ //
for (x = d->width;
x > 0;
x --, p0 ++, p1 ++, p ++, data += num_channels)
{
- /*
- * Skip blank pixels...
- */
+ //
+ // Skip blank pixels...
+ //
if (*data == 0)
{
continue;
}
- /*
- * Compute the net pixel brightness and brightness error. Set a dot
- * if necessary...
- */
+ //
+ // Compute the net pixel brightness and brightness error. Set a dot
+ // if necessary...
+ //
pixel = lut[*data].intensity + e0 / 128;
*p = lut[pixel].pixel;
e = lut[pixel].error;
- /*
- * Set the randomness factor...
- */
+ //
+ // Set the randomness factor...
+ //
if (e > 0)
errrange = logtable[e];
errbase = 8 - errrange;
errrange = errrange * 2 + 1;
- /*
- * Randomize the error value.
- */
+ //
+ // Randomize the error value.
+ //
if (errrange > 1)
{
else
errbase0 = errbase1 = errbase;
- /*
- * X 7/16 = X e0
- * 3/16 5/16 1/16 = e1 e2
- */
+ //
+ // X 7/16 = X e0
+ // 3/16 5/16 1/16 = e1 e2
+ //
errval0 = errbase0 * e;
errval1 = (16 - errbase0) * e;
}
else
{
- /*
- * Dither from right to left:
- *
- * e0 == p0[0]
- * e2 e1 == p1[0] p1[1]
- */
+ //
+ // Dither from right to left:
+ //
+ // e0 == p0[0]
+ // e2 e1 == p1[0] p1[1]
+ //
p0 = d->errors + d->width + 1 + d->width + 4;
p1 = d->errors + d->width + 1;
e1 = 0;
e2 = 0;
- /*
- * Error diffuse each output pixel...
- */
+ //
+ // Error diffuse each output pixel...
+ //
for (x = d->width;
x > 0;
x --, p0 --, p1 --, p --, data -= num_channels)
{
- /*
- * Skip blank pixels...
- */
+ //
+ // Skip blank pixels...
+ //
if (*data == 0)
{
continue;
}
- /*
- * Compute the net pixel brightness and brightness error. Set a dot
- * if necessary...
- */
+ //
+ // Compute the net pixel brightness and brightness error. Set a dot
+ // if necessary...
+ //
pixel = lut[*data].intensity + e0 / 128;
*p = lut[pixel].pixel;
e = lut[pixel].error;
- /*
- * Set the randomness factor...
- */
+ //
+ // Set the randomness factor...
+ //
if (e > 0)
errrange = logtable[e];
errbase = 8 - errrange;
errrange = errrange * 2 + 1;
- /*
- * Randomize the error value.
- */
+ //
+ // Randomize the error value.
+ //
if (errrange > 1)
{
else
errbase0 = errbase1 = errbase;
- /*
- * X 7/16 = X e0
- * 3/16 5/16 1/16 = e1 e2
- */
+ //
+ // X 7/16 = X e0
+ // 3/16 5/16 1/16 = e1 e2
+ //
errval0 = errbase0 * e;
errval1 = (16 - errbase0) * e;
}
}
- /*
- * Update to the next row...
- */
+ //
+ // Update to the next row...
+ //
d->row = 1 - d->row;
}
-/*
- * 'cfDitherNew()' - Create an error-diffusion dithering buffer.
- */
+//
+// 'cfDitherNew()' - Create an error-diffusion dithering buffer.
+//
-cf_dither_t * /* O - New state array */
-cfDitherNew(int width) /* I - Width of output in pixels */
+cf_dither_t * // O - New state array
+cfDitherNew(int width) // I - Width of output in pixels
{
- cf_dither_t *d; /* New dithering buffer */
+ cf_dither_t *d; // New dithering buffer
if ((d = (cf_dither_t *)calloc(1, sizeof(cf_dither_t) +
- 2 * (width + 4) *
- sizeof(int))) == NULL)
+ 2 * (width + 4) *
+ sizeof(int))) == NULL)
return (NULL);
d->width = width;
return (d);
}
-
-/*
- * Printer driver utilities header file for CUPS.
- *
- * Copyright 2007 by Apple Inc.
- * Copyright 1993-2005 by Easy Software Products.
- *
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law. Distribution and use rights are outlined in the file "COPYING"
- * which should have been included with this file.
- */
+//
+// Printer driver utilities header file for CUPS.
+//
+// Copyright 2007 by Apple Inc.
+// Copyright 1993-2005 by Easy Software Products.
+//
+// These coded instructions, statements, and computer programs are the
+// property of Apple Inc. and are protected by Federal copyright
+// law. Distribution and use rights are outlined in the file "COPYING"
+// which should have been included with this file.
+//
+
#ifndef _CUPS_FILTERS_DRIVER_H_
# define _CUPS_FILTERS_DRIVER_H_
# ifdef __cplusplus
extern "C" {
-# endif /* __cplusplus */
+# endif // __cplusplus
+
-/*
- * Include necessary headers...
- */
+//
+// Include necessary headers...
+//
# include <stdio.h>
# include <stdlib.h>
# else
# include <unistd.h>
# include <fcntl.h>
-# endif /* WIN32 || __EMX__ */
+# endif // WIN32 || __EMX__
# include <cups/cups.h>
# include <cups/raster.h>
-/*
- * Common macros...
- */
+//
+// Common macros...
+//
# ifndef min
# define min(a,b) ((a) < (b) ? (a) : (b))
# define max(a,b) ((a) > (b) ? (a) : (b))
-# endif /* !min */
+# endif // !min
-/*
- * Constants...
- */
+//
+// Constants...
+//
-#define CF_MAX_CHAN 15 /* Maximum number of color components */
-#define CF_MAX_LUT 4095 /* Maximum LUT value */
-#define CF_MAX_RGB 4 /* Maximum number of sRGB components */
+#define CF_MAX_CHAN 15 // Maximum number of color components
+#define CF_MAX_LUT 4095 // Maximum LUT value
+#define CF_MAX_RGB 4 // Maximum number of sRGB components
-/*
- * Types/structures for the various routines.
- */
+//
+// Types/structures for the various routines.
+//
-typedef struct cf_lut_s /**** Lookup Table for Dithering ****/
+typedef struct cf_lut_s // *** Lookup Table for Dithering ***
{
- short intensity; /* Adjusted intensity */
- short pixel; /* Output pixel value */
- int error; /* Error from desired value */
+ short intensity; // Adjusted intensity
+ short pixel; // Output pixel value
+ int error; // Error from desired value
} cf_lut_t;
-typedef struct cf_dither_s /**** Dithering State ****/
+typedef struct cf_dither_s // *** Dithering State ***
{
- int width; /* Width of buffer */
- int row; /* Current row */
- int errors[96]; /* Error values */
+ int width; // Width of buffer
+ int row; // Current row
+ int errors[96]; // Error values
} cf_dither_t;
-typedef struct cf_sample_s /**** Color sample point ****/
+typedef struct cf_sample_s // *** Color sample point ***
{
- unsigned char rgb[3]; /* sRGB values */
- unsigned char colors[CF_MAX_RGB]; /* Color values */
+ unsigned char rgb[3]; // sRGB values
+ unsigned char colors[CF_MAX_RGB]; // Color values
} cf_sample_t;
-typedef struct cf_rgb_s /*** Color separation lookup table ***/
+typedef struct cf_rgb_s // *** Color separation lookup table ***
{
- int cube_size; /* Size of color cube (2-N) on a side */
- int num_channels; /* Number of colors per sample */
- unsigned char ****colors; /* 4-D array of sample values */
- int cube_index[256]; /* Index into cube for a given sRGB value */
- int cube_mult[256]; /* Multiplier value for a given sRGB value */
- int cache_init; /* Are cached values initialized? */
- unsigned char black[CF_MAX_RGB]; /* Cached black (sRGB = 0,0,0) */
- unsigned char white[CF_MAX_RGB]; /* Cached white (sRGB = 255,255,255) */
+ int cube_size; // Size of color cube (2-N) on a side
+ int num_channels; // Number of colors per sample
+ unsigned char ****colors; // 4-D array of sample values
+ int cube_index[256]; // Index into cube for a given sRGB
+ // value
+ int cube_mult[256]; // Multiplier value for a given sRGB
+ // value
+ int cache_init; // Are cached values initialized?
+ unsigned char black[CF_MAX_RGB]; // Cached black (sRGB = 0,0,0)
+ unsigned char white[CF_MAX_RGB]; // Cached white (sRGB = 255,255,255)
} cf_rgb_t;
-typedef struct cf_cmyk_s /**** Simple CMYK lookup table ****/
+typedef struct cf_cmyk_s // *** Simple CMYK lookup table ***
{
- unsigned char black_lut[256]; /* Black generation LUT */
- unsigned char color_lut[256]; /* Color removal LUT */
- int ink_limit; /* Ink limit */
- int num_channels; /* Number of components */
+ unsigned char black_lut[256]; // Black generation LUT
+ unsigned char color_lut[256]; // Color removal LUT
+ int ink_limit; // Ink limit
+ int num_channels; // Number of components
short *channels[CF_MAX_CHAN];
- /* Lookup tables */
+ // Lookup tables
} cf_cmyk_t;
-/*
- * Globals...
- */
+//
+// Globals...
+//
extern const unsigned char
cf_srgb_lut[256];
- /* sRGB gamma lookup table */
+ // sRGB gamma lookup table
extern const unsigned char
cf_scmy_lut[256];
- /* sRGB gamma lookup table (inverted) */
+ // sRGB gamma lookup table (inverted)
-/*
- * Prototypes...
- */
+//
+// Prototypes...
+//
-/*
- * Byte checking functions...
- */
+//
+// Byte checking functions...
+//
extern int cfCheckBytes(const unsigned char *, int);
extern int cfCheckValue(const unsigned char *, int,
const unsigned char);
-/*
- * Dithering functions...
- */
+//
+// Dithering functions...
+//
extern void cfDitherLine(cf_dither_t *d, const cf_lut_t *lut,
const short *data, int num_channels,
extern cf_dither_t *cfDitherNew(int width);
extern void cfDitherDelete(cf_dither_t *);
-/*
- * Lookup table functions for dithering...
- */
+//
+// Lookup table functions for dithering...
+//
extern cf_lut_t *cfLutNew(int num_vals, const float *vals,
cf_logfunc_t log, void *ld);
extern void cfLutDelete(cf_lut_t *lut);
-/*
- * Bit packing functions...
- */
+//
+// Bit packing functions...
+//
extern void cfPackHorizontal(const unsigned char *,
unsigned char *, int,
const unsigned char, const int);
- extern void cfPackHorizontal2(const unsigned char *,
+extern void cfPackHorizontal2(const unsigned char *,
unsigned char *, int, const int);
extern void cfPackHorizontalBit(const unsigned char *,
unsigned char *, int,
extern void cfPackVertical(const unsigned char *, unsigned char *,
int, const unsigned char, const int);
-/*
- * Color separation functions...
- */
+//
+// Color separation functions...
+//
extern void cfRGBDelete(cf_rgb_t *rgb);
extern void cfRGBDoGray(cf_rgb_t *rgb,
extern cf_rgb_t *cfRGBNew(int num_samples, cf_sample_t *samples,
int cube_size, int num_channels);
-/*
- * CMYK separation functions...
- */
+//
+// CMYK separation functions...
+//
extern cf_cmyk_t *cfCMYKNew(int num_channels);
extern void cfCMYKDelete(cf_cmyk_t *cmyk);
cf_logfunc_t log, void *ld);
-/*
- * Convenience macro for writing print data...
- */
+//
+// Convenience macro for writing print data...
+//
# define cfWritePrintData(s,n) fwrite((s), 1, (n), stdout)
+
# ifdef __cplusplus
}
-# endif /* __cplusplus */
+# endif // __cplusplus
-#endif /* !_CUPS_FILTERS_DRIVER_H_ */
+#endif // !_CUPS_FILTERS_DRIVER_H_
-/*
- * Filter functions support for cups-filters.
- *
- * Copyright © 2020 by Till Kamppeter.
- *
- * Licensed under Apache License v2.0. See the file "LICENSE" for more
- * information.
- */
-
-/*
- * Include necessary headers...
- */
+//
+// Filter functions support for cups-filters.
+//
+// Copyright © 2020 by Till Kamppeter.
+//
+// Licensed under Apache License v2.0. See the file "LICENSE" for more
+// information.
+//
+
+
+//
+// Include necessary headers...
+//
#include "config.h"
#include "filter.h"
extern char **environ;
-/*
- * Type definitions
- */
-typedef struct filter_function_pid_s /* Filter in filter chain */
+//
+// Type definitions
+//
+
+typedef struct filter_function_pid_s // Filter in filter chain
{
- char *name; /* Filter executable name */
- int pid; /* PID of filter process */
+ char *name; // Filter executable name
+ int pid; // PID of filter process
} filter_function_pid_t;
-/*
- * 'fcntl_add_cloexec()' - Add FD_CLOEXEC flag to the flags
- * of a given file descriptor.
- */
+//
+// 'fcntl_add_cloexec()' - Add FD_CLOEXEC flag to the flags
+// of a given file descriptor.
+//
-static int /* Return value of fcntl() */
-fcntl_add_cloexec(int fd) /* File descriptor to add FD_CLOEXEC to */
+static int // Return value of fcntl()
+fcntl_add_cloexec(int fd) // File descriptor to add FD_CLOEXEC to
{
- return fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+ return (fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC));
}
-/*
- * 'fcntl_add_nodelay()' - Add O_NODELAY flag to the flags
- * of a given file descriptor.
- */
+//
+// 'fcntl_add_nodelay()' - Add O_NODELAY flag to the flags
+// of a given file descriptor.
+//
-static int /* Return value of fcntl() */
-fcntl_add_nonblock(int fd) /* File descriptor to add O_NONBLOCK to */
+static int // Return value of fcntl()
+fcntl_add_nonblock(int fd) // File descriptor to add O_NONBLOCK to
{
- return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
+ return (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK));
}
-/*
- * 'cfCUPSLogFunc()' - Output log messages on stderr, compatible to CUPS,
- * meaning that the debug level is represented by a
- * prefix like "DEBUG: ", "INFO: ", ...
- */
+//
+// 'cfCUPSLogFunc()' - Output log messages on stderr, compatible to
+// CUPS, meaning that the debug level is
+// represented by a prefix like "DEBUG: ", "INFO:
+// ", ...
+//
void
cfCUPSLogFunc(void *data,
va_list arglist;
- (void)data; /* No extra data needed */
+ (void)data; // No extra data needed
switch(level)
{
}
-/*
- * 'cfCUPSIsCanceledFunc()' - Return 1 if the job is canceled, which is
- * the case when the integer pointed at by data
- * is not zero.
- */
+//
+// 'cfCUPSIsCanceledFunc()' - Return 1 if the job is canceled, which
+// is the case when the integer pointed at
+// by data is not zero.
+//
int
cfCUPSIsCanceledFunc(void *data)
}
-void * /* O - Extension record which got
- replaced, NULL if there was
- no record under this name,
- the added record is the one
- there, or no record was
- added. If not NULL the
- returned record should usually
- be deleted or freed. */
-cfFilterDataAddExt(cf_filter_data_t *data, /* I - Filter data record */
- const char *name, /* I - Name of extension */
- void *ext) /* I - Extension record to be added*/
+void * // O - Extension record which got
+ // replaced, NULL if there was
+ // no record under this name,
+ // the added record is the one
+ // there, or no record was
+ // added. If not NULL the
+ // returned record should usually
+ // be deleted or freed.
+cfFilterDataAddExt(cf_filter_data_t *data, // I - Filter data record
+ const char *name, // I - Name of extension
+ void *ext) // I - Extension record to be added
{
cf_filter_data_ext_t *entry;
void *old_ext = NULL;
if ((entry = get_filter_data_ext_entry(data->extension, name)) != NULL)
return (entry->ext);
else
- return NULL;
+ return (NULL);
}
return (ext);
}
else
- return NULL;
+ return (NULL);
}
-/*
- * 'cfFilterTee()' - This filter function is mainly for debugging. it
- * resembles the "tee" utility, passing through the
- * data unfiltered and copying it to a file. The file
- * name is simply given as parameter. This makes using
- * the function easy (add it as item of a filter chain
- * called via cfFilterChain()) and can even be used more
- * than once in the same filter chain (using different
- * file names). In case of write error to the copy
- * file, copying is stopped but the rest of the job is
- * passed on to the next filter. If NULL is supplied
- * as file name, the data is simply passed through
- * without getting copied.
- */
-
-int /* O - Error status */
-cfFilterTee(int inputfd, /* I - File descriptor input stream */
- int outputfd, /* I - File descriptor output stream */
- int inputseekable, /* I - Is input stream seekable? (unused) */
- cf_filter_data_t *data, /* I - Job and printer data */
- void *parameters) /* I - Filter-specific parameters (File name) */
+//
+// 'cfFilterTee()' - This filter function is mainly for debugging. it
+// resembles the "tee" utility, passing through the
+// data unfiltered and copying it to a file. The
+// file name is simply given as parameter. This
+// makes using the function easy (add it as item of
+// a filter chain called via cfFilterChain()) and
+// can even be used more than once in the same
+// filter chain (using different file names). In
+// case of write error to the copy file, copying is
+// stopped but the rest of the job is passed on to
+// the next filter. If NULL is supplied as file
+// name, the data is simply passed through without
+// getting copied.
+//
+
+int // O - Error status
+cfFilterTee(int inputfd, // I - File descriptor input stream
+ int outputfd, // I - File descriptor output stream
+ int inputseekable, // I - Is input stream seekable? (unused)
+ cf_filter_data_t *data, // I - Job and printer data
+ void *parameters) // I - Filter-specific parameters (File
+ // name)
{
const char *filename = (const char *)parameters;
- ssize_t bytes, total = 0; /* Bytes read/written */
- char buffer[65536]; /* Read/write buffer */
- cf_logfunc_t log = data->logfunc; /* Log function */
- void *ld = data->logdata; /* log function data */
- int teefd = -1; /* File descriptor for "tee"ed
- copy */
+ ssize_t bytes, total = 0; // Bytes read/written
+ char buffer[65536]; // Read/write buffer
+ cf_logfunc_t log = data->logfunc; // Log function
+ void *ld = data->logdata; // log function data
+ int teefd = -1; // File descriptor for "tee"ed
+ // copy
(void)inputseekable;
- /* Open the "tee"ed copy file */
+ // Open the "tee"ed copy file
if (filename)
teefd = open(filename, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
}
-/*
- * 'cfFilterPOpen()' - Pipe a stream to or from a filter function
- * Can be the input to or the output from the
- * filter function.
- */
-
-int /* O - File decriptor */
-cfFilterPOpen(cf_filter_function_t filter_func, /* I - Filter function */
- int inputfd, /* I - File descriptor input stream or -1 */
- int outputfd, /* I - File descriptor output stream or -1 */
- int inputseekable, /* I - Is input stream seekable? */
- cf_filter_data_t *data, /* I - Job and printer data */
- void *parameters, /* I - Filter-specific parameters */
- int *filter_pid) /* O - PID of forked filter process */
+//
+// 'cfFilterPOpen()' - Pipe a stream to or from a filter function Can
+// be the input to or the output from the filter
+// function.
+//
+
+int // O - File decriptor
+cfFilterPOpen(cf_filter_function_t filter_func,
+ // I - Filter function
+ int inputfd, // I - File descriptor input stream or -1
+ int outputfd, // I - File descriptor output stream or -1
+ int inputseekable, // I - Is input stream seekable?
+ cf_filter_data_t *data, // I - Job and printer data
+ void *parameters, // I - Filter-specific parameters
+ int *filter_pid) // O - PID of forked filter process
{
- int pipefds[2], /* Pipes for filters */
- pid, /* Process ID of filter */
+ int pipefds[2], // Pipes for filters
+ pid, // Process ID of filter
ret,
- infd, outfd; /* Temporary file descriptors */
+ infd, outfd; // Temporary file descriptors
cf_logfunc_t log = data->logfunc;
void *ld = data->logdata;
- /*
- * Check file descriptors...
- */
+ //
+ // Check file descriptors...
+ //
if (inputfd < 0 && outputfd < 0)
{
return (-1);
}
- /*
- * Ignore broken pipe signals...
- */
+ //
+ // Ignore broken pipe signals...
+ //
signal(SIGPIPE, SIG_IGN);
- /*
- * Open a pipe ...
- */
+ //
+ // Open a pipe ...
+ //
if (pipe(pipefds) < 0) {
if (log) log(ld, CF_LOGLEVEL_ERROR,
}
if ((pid = fork()) == 0) {
- /*
- * Child process goes here...
- *
- * Update input and output FDs as needed...
- */
+ //
+ // Child process goes here...
+ //
+ // Update input and output FDs as needed...
+ //
if (inputfd < 0) {
inputseekable = 0;
close(pipefds[0]);
}
- /*
- * Execute filter function...
- */
+ //
+ // Execute filter function...
+ //
ret = (filter_func)(infd, outfd, inputseekable, data, parameters);
- /*
- * Close file descriptor and terminate the sub-process...
- */
+ //
+ // Close file descriptor and terminate the sub-process...
+ //
close(infd);
close(outfd);
if (log) log(ld, CF_LOGLEVEL_INFO,
"cfFilterPOpen: Filter function (PID %d) started.", pid);
- /*
- * Save PID for waiting for or terminating the sub-process
- */
+ //
+ // Save PID for waiting for or terminating the sub-process
+ //
*filter_pid = pid;
- /*
- * Return file descriptor to stream to or from
- */
+ //
+ // Return file descriptor to stream to or from
+ //
if (inputfd < 0) {
close(pipefds[0]);
} else {
- /*
- * fork() error
- */
+ //
+ // fork() error
+ //
if (log) log(ld, CF_LOGLEVEL_ERROR,
"cfFilterPOpen: Could not fork to start filter function: %s",
}
-/*
- * 'cfFilterPClose()' - Close a piped stream created with
- * cfFilterPOpen().
- */
+//
+// 'cfFilterPClose()' - Close a piped stream created with
+// cfFilterPOpen().
+//
-int /* O - Error status */
-cfFilterPClose(int fd, /* I - Pipe file descriptor */
- int filter_pid, /* I - PID of forked filter process */
- cf_filter_data_t *data)
+int // O - Error status
+cfFilterPClose(int fd, // I - Pipe file descriptor
+ int filter_pid, // I - PID of forked filter process
+ cf_filter_data_t *data)
{
- int status, /* Exit status */
- retval; /* Return value */
+ int status, // Exit status
+ retval; // Return value
cf_logfunc_t log = data->logfunc;
void *ld = data->logdata;
- /*
- * close the stream...
- */
+ //
+ // close the stream...
+ //
close(fd);
- /*
- * Wait for the child process to exit...
- */
+ //
+ // Wait for the child process to exit...
+ //
retval = 0;
"cfFilterPClose: Filter function (PID %d) exited with no errors.",
filter_pid);
- /* How did the filter function terminate */
+ // How did the filter function terminate
if (WIFEXITED(status))
- /* Via exit() anywhere or return() in the main() function */
+ // Via exit() anywhere or return() in the main() function
retval = WEXITSTATUS(status);
else if (WIFSIGNALED(status))
- /* Via signal */
+ // Via signal
retval = 256 * WTERMSIG(status);
out:
- return(retval);
+ return (retval);
}
-/*
- * 'compare_filter_pids()' - Compare two filter PIDs...
- */
+//
+// 'compare_filter_pids()' - Compare two filter PIDs...
+//
-static int /* O - Result of comparison */
-compare_filter_pids(filter_function_pid_t *a, /* I - First filter */
- filter_function_pid_t *b) /* I - Second filter */
+static int // O - Result of comparison
+compare_filter_pids(filter_function_pid_t *a, // I - First filter
+ filter_function_pid_t *b) // I - Second filter
{
return (a->pid - b->pid);
}
-/*
- * 'cfFilterChain()' - Call filter functions in a chain to do a data
- * format conversion which non of the individual
- * filter functions does
- */
+//
+// 'cfFilterChain()' - Call filter functions in a chain to do a data
+// format conversion which non of the individual
+// filter functions does
+//
-int /* O - Error status */
-cfFilterChain(int inputfd, /* I - File descriptor input stream */
- int outputfd, /* I - File descriptor output stream */
- int inputseekable, /* I - Is input stream seekable? */
- cf_filter_data_t *data, /* I - Job and printer data */
- void *parameters) /* I - Filter-specific parameters */
+int // O - Error status
+cfFilterChain(int inputfd, // I - File descriptor input stream
+ int outputfd, // I - File descriptor output stream
+ int inputseekable, // I - Is input stream seekable?
+ cf_filter_data_t *data,
+ // I - Job and printer data
+ void *parameters) // I - Filter-specific parameters
{
cups_array_t *filter_chain = (cups_array_t *)parameters;
- cf_filter_filter_in_chain_t *filter, /* Current filter */
- *next; /* Next filter */
- int current, /* Current filter */
- filterfds[2][2], /* Pipes for filters */
- pid, /* Process ID of filter */
- status, /* Exit status */
- retval, /* Return value */
+ cf_filter_filter_in_chain_t *filter, // Current filter
+ *next; // Next filter
+ int current, // Current filter
+ filterfds[2][2], // Pipes for filters
+ pid, // Process ID of filter
+ status, // Exit status
+ retval, // Return value
ret;
- int infd, outfd; /* Temporary file descriptors */
+ int infd, outfd; // Temporary file descriptors
char buf[4096];
ssize_t bytes;
- cups_array_t *pids; /* Executed filters array */
- filter_function_pid_t *pid_entry, /* Entry in executed filters array */
- key; /* Search key for filters */
+ cups_array_t *pids; // Executed filters array
+ filter_function_pid_t *pid_entry, // Entry in executed filters array
+ key; // Search key for filters
cf_logfunc_t log = data->logfunc;
void *ld = data->logdata;
cf_filter_iscanceledfunc_t iscanceled = data->iscanceledfunc;
void *icd = data->iscanceleddata;
- /*
- * Ignore broken pipe signals...
- */
+ //
+ // Ignore broken pipe signals...
+ //
signal(SIGPIPE, SIG_IGN);
- /*
- * Remove NULL filters...
- */
+ //
+ // Remove NULL filters...
+ //
for (filter = (cf_filter_filter_in_chain_t *)cupsArrayFirst(filter_chain);
filter;
filter->name ? filter->name : "Unspecified");
}
- /*
- * Empty filter chain -> Pass through the data unchanged
- */
+ //
+ // Empty filter chain -> Pass through the data unchanged
+ //
if (cupsArrayCount(filter_chain) == 0)
{
return (retval);
}
- /*
- * Execute all of the filters...
- */
+ //
+ // Execute all of the filters...
+ //
pids = cupsArrayNew((cups_array_func_t)compare_filter_pids, NULL);
current = 0;
filterfds[1 - current][1] = outputfd;
if ((pid = fork()) == 0) {
- /*
- * Child process goes here...
- *
- * Update input and output FDs as needed...
- */
+ //
+ // Child process goes here...
+ //
+ // Update input and output FDs as needed...
+ //
infd = filterfds[current][0];
outfd = filterfds[1 - current][1];
if (outfd < 0)
outfd = open("/dev/null", O_WRONLY);
- /*
- * Execute filter function...
- */
+ //
+ // Execute filter function...
+ //
ret = (filter->function)(infd, outfd, inputseekable, data,
filter->parameters);
inputseekable = 0;
}
- /*
- * Close remaining pipes...
- */
+ //
+ // Close remaining pipes...
+ //
if (filterfds[0][0] > 1)
close(filterfds[0][0]);
if (filterfds[1][1] > 1)
close(filterfds[1][1]);
- /*
- * Wait for the children to exit...
- */
+ //
+ // Wait for the children to exit...
+ //
retval = 0;
}
-/*
- * 'cfFilterOpenBackAndSidePipes()' - Open the pipes for the back
- * channel and the side channel, so
- * that the filter functions can
- * communicate with a backend. Only
- * needed if a CUPS backend (either
- * implemented as filter function or
- * called via cfFilterExternalCUPS())
- * is called with the same
- * filter_data record as the
- * filters. Usually to be called when
- * populating the filter_data record.
- */
-
-int /* O - 0 on success, -1 on error */
-cfFilterOpenBackAndSidePipes(
- cf_filter_data_t *data) /* O - FDs in filter_data record */
+//
+// 'cfFilterOpenBackAndSidePipes()' - Open the pipes for the back
+// channel and the side channel, so
+// that the filter functions can
+// communicate with a backend. Only
+// needed if a CUPS backend (either
+// implemented as filter function
+// or called via
+// cfFilterExternalCUPS()) is
+// called with the same filter_data
+// record as the filters. Usually
+// to be called when populating the
+// filter_data record.
+//
+
+int // O - 0 on success,
+ // -1 on error
+cfFilterOpenBackAndSidePipes(cf_filter_data_t *data) // O - FDs in filter_data
+ // record
{
cf_logfunc_t log = data->logfunc;
- void *ld = data->logdata;
+ void *ld = data->logdata;
- /*
- * Initialize FDs...
- */
+ //
+ // Initialize FDs...
+ //
data->back_pipe[0] = -1;
data->back_pipe[1] = -1;
data->side_pipe[0] = -1;
data->side_pipe[1] = -1;
- /*
- * Create the back channel pipe...
- */
+ //
+ // Create the back channel pipe...
+ //
if (pipe(data->back_pipe))
goto out;
- /*
- * Set the "close on exec" flag on each end of the pipe...
- */
+ //
+ // Set the "close on exec" flag on each end of the pipe...
+ //
if (fcntl_add_cloexec(data->back_pipe[0]))
goto out;
if (fcntl_add_cloexec(data->back_pipe[1]))
goto out;
- /*
- * Create a socket pair as bi-directional pipe for the side channel...
- */
+ //
+ // Create a socket pair as bi-directional pipe for the side channel...
+ //
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, data->side_pipe))
goto out;
- /*
- * Make the side channel FDs non-blocking...
- */
+ //
+ // Make the side channel FDs non-blocking...
+ //
if (fcntl_add_nonblock(data->side_pipe[0]))
goto out;
if (log) log(ld, CF_LOGLEVEL_DEBUG,
"Pipes for back and side channels opened");
- /*
- * Return 0 indicating success...
- */
+ //
+ // Return 0 indicating success...
+ //
return (0);
out:
- /*
- * Clean up after failure...
- */
+ //
+ // Clean up after failure...
+ //
if (log) log(ld, CF_LOGLEVEL_ERROR,
"Unable to open pipes for back and side channels");
}
-/*
- * 'cfFilterCloseBackAndSidePipes()' - Close the pipes for the back
- * hannel and the side channel.
- * sually to be called when done
- * with the filter chain .
- */
+//
+// 'cfFilterCloseBackAndSidePipes()' - Close the pipes for the back
+// hannel and the side channel.
+// sually to be called when done
+// with the filter chain .
+//
void
-cfFilterCloseBackAndSidePipes(
- cf_filter_data_t *data) /* O - FDs in filter_data record */
+cfFilterCloseBackAndSidePipes(cf_filter_data_t *data) // I - FDs in filter_data
+ // record
{
cf_logfunc_t log = data->logfunc;
- void *ld = data->logdata;
+ void *ld = data->logdata;
- /*
- * close all valid FDs...
- */
+ //
+ // close all valid FDs...
+ //
if (data->back_pipe[0] >= 0)
close(data->back_pipe[0]);
if (data->side_pipe[1] >= 0)
close(data->side_pipe[1]);
- /*
- * ... and invalidate them
- */
+ //
+ // ... and invalidate them
+ //
data->back_pipe[0] = -1;
data->back_pipe[1] = -1;
-/*
- * Filter functions header file for cups-filters.
- *
- * Copyright 2020 by Till Kamppeter.
- *
- * Distribution and use rights are outlined in the file "COPYING"
- * which should have been included with this file.
- */
+//
+// Filter functions header file for cups-filters.
+//
+// Copyright 2020 by Till Kamppeter.
+//
+// Distribution and use rights are outlined in the file "COPYING"
+// which should have been included with this file.
+//
#ifndef _CUPS_FILTERS_FILTER_H_
# define _CUPS_FILTERS_FILTER_H_
# ifdef __cplusplus
extern "C" {
-# endif /* __cplusplus */
+# endif // __cplusplus
-/*
- * Include necessary headers...
- */
+//
+// Include necessary headers...
+//
# include "log.h"
# else
# include <unistd.h>
# include <fcntl.h>
-# endif /* WIN32 || __EMX__ */
+# endif // WIN32 || __EMX__
# include <cups/cups.h>
# include <cups/raster.h>
-/*
- * Types and structures...
- */
+//
+// Types and structures...
+//
typedef int (*cf_filter_iscanceledfunc_t)(void *data);
typedef struct cf_filter_data_s {
- char *printer; /* Print queue name or NULL */
- int job_id; /* Job ID or 0 */
- char *job_user; /* Job user or NULL */
- char *job_title; /* Job title or NULL */
- int copies; /* Number of copies
- (1 if filter(s) should not treat it) */
- char *content_type; /* Input MIME type (CUPS env variable
- CONTENT_TYPE) or NULL */
- char *final_content_type; /* Output MIME type (CUPS env variable
- FINAL_CONTENT_TYPE) or NULL */
- ipp_t *job_attrs; /* IPP attributes passed along with the job */
- ipp_t *printer_attrs; /* Printer capabilities in IPP format
- (what is answered to get-printer-attributes */
- cups_page_header2_t *header; /* CUPS/PWG Raster header (optional) */
+ char *printer; // Print queue name or NULL
+ int job_id; // Job ID or 0
+ char *job_user; // Job user or NULL
+ char *job_title; // Job title or NULL
+ int copies; // Number of copies
+ // (1 if filter(s) should not treat it)
+ char *content_type; // Input MIME type (CUPS env variable
+ // CONTENT_TYPE) or NULL
+ char *final_content_type; // Output MIME type (CUPS env variable
+ // FINAL_CONTENT_TYPE) or NULL
+ ipp_t *job_attrs; // IPP attributes passed along with the job
+ ipp_t *printer_attrs; // Printer capabilities in IPP format
+ // (what is answered to get-printer-attributes
+ cups_page_header2_t *header;
+ // CUPS/PWG Raster header (optional)
int num_options;
- cups_option_t *options; /* Job options as key/value pairs */
- int back_pipe[2]; /* File descriptors of backchannel pipe */
- int side_pipe[2]; /* File descriptors of sidechannel pipe */
- cups_array_t *extension; /* Extension data */
- cf_logfunc_t logfunc; /* Logging function, NULL for no logging */
- void *logdata; /* User data for logging function, can be NULL */
- cf_filter_iscanceledfunc_t iscanceledfunc; /* Function returning 1 when
- job is canceled, NULL for not
- supporting stop on cancel */
- void *iscanceleddata; /* User data for is-canceled function, can be
- NULL */
+ cups_option_t *options; // Job options as key/value pairs
+ int back_pipe[2]; // File descriptors of backchannel pipe
+ int side_pipe[2]; // File descriptors of sidechannel pipe
+ cups_array_t *extension; // Extension data
+ cf_logfunc_t logfunc; // Logging function, NULL for no logging
+ void *logdata; // User data for logging function, can be NULL
+ cf_filter_iscanceledfunc_t iscanceledfunc;
+ // Function returning 1 when job is
+ // canceled, NULL for not supporting stop
+ // on cancel
+ void *iscanceleddata; // User data for is-canceled function, can be
+ // NULL
} cf_filter_data_t;
typedef struct cf_filter_data_ext_s {
- char* name;
+ char *name;
void *ext;
} cf_filter_data_ext_t;
int inputseekable, cf_filter_data_t *data,
void *parameters);
-typedef enum cf_filter_out_format_e { /* Possible output formats for filter
- functions */
- CF_FILTER_OUT_FORMAT_PDF, /* PDF */
- CF_FILTER_OUT_FORMAT_PDF_IMAGE, /* Raster-only PDF */
- CF_FILTER_OUT_FORMAT_PCLM, /* PCLM */
- CF_FILTER_OUT_FORMAT_CUPS_RASTER, /* CUPS Raster */
- CF_FILTER_OUT_FORMAT_PWG_RASTER, /* PWG Raster */
- CF_FILTER_OUT_FORMAT_APPLE_RASTER, /* Apple Raster */
- CF_FILTER_OUT_FORMAT_PXL /* PCL-XL */
+typedef enum cf_filter_out_format_e { // Possible output formats for filter
+ // functions
+ CF_FILTER_OUT_FORMAT_PDF, // PDF
+ CF_FILTER_OUT_FORMAT_PDF_IMAGE, // Raster-only PDF
+ CF_FILTER_OUT_FORMAT_PCLM, // PCLM
+ CF_FILTER_OUT_FORMAT_CUPS_RASTER, // CUPS Raster
+ CF_FILTER_OUT_FORMAT_PWG_RASTER, // PWG Raster
+ CF_FILTER_OUT_FORMAT_APPLE_RASTER, // Apple Raster
+ CF_FILTER_OUT_FORMAT_PXL // PCL-XL
} cf_filter_out_format_t;
-typedef struct cf_filter_filter_in_chain_s { /* filter entry for CUPS array to
- be supplied to cfFilterChain()
- filter function */
- cf_filter_function_t function; /* Filter function to be called */
- void *parameters; /* Parameters for this filter function call */
- char *name; /* Name/comment, only for logging */
+typedef struct cf_filter_filter_in_chain_s { // filter entry for CUPS array to
+ // be supplied to cfFilterChain()
+ // filter function
+ cf_filter_function_t function; // Filter function to be called
+ void *parameters; // Parameters for this filter function call
+ char *name; // Name/comment, only for logging
} cf_filter_filter_in_chain_t;
-typedef struct cf_filter_texttopdf_parameter_s { /* parameters container of
- environemnt variables needed
- by texttopdf filter
- function */
+typedef struct cf_filter_texttopdf_parameter_s { // parameters container of
+ // environemnt variables needed
+ // by texttopdf filter
+ // function
char *data_dir;
char *char_set;
char *content_type;
char *classification;
} cf_filter_texttopdf_parameter_t;
-typedef struct cf_filter_universal_parameter_s { /* Contains input and output
- type to be supplied to the
- universal function, and also
- parameters for
- cfFilterTextToPDF() */
+typedef struct cf_filter_universal_parameter_s { // Contains input and output
+ // type to be supplied to the
+ // universal function, and also
+ // parameters for
+ // cfFilterTextToPDF()
char *actual_output_type;
cf_filter_texttopdf_parameter_t texttopdf_params;
const char *bannertopdf_template_dir;
} cf_filter_universal_parameter_t;
-/*
- * Prototypes...
- */
+//
+// Prototypes...
+//
extern void cfCUPSLogFunc(void *data,
cf_loglevel_t level,
cf_filter_data_t *data,
void *parameters);
-/* Parameters: Filename/path (const char *) to copy the data to */
+// Parameters: Filename/path (const char *) to copy the data to
-extern int cfFilterPOpen(cf_filter_function_t filter_func, /* I - Filter
- function */
+extern int cfFilterPOpen(cf_filter_function_t filter_func, // I - Filter
+ // function
int inputfd,
int outputfd,
int inputseekable,
cf_filter_data_t *data,
void *parameters);
-/* Parameters: Unsorted (!) CUPS array of cf_filter_filter_in_chain_t*
- List of filters to execute in a chain, next filter takes output of
- previous filter as input, all get the same filter data, parameters
- are supplied individually in the array */
+// Parameters: Unsorted (!) CUPS array of cf_filter_filter_in_chain_t*
+// List of filters to execute in a chain, next filter takes output of
+// previous filter as input, all get the same filter data, parameters
+// are supplied individually in the array
extern int cfFilterOpenBackAndSidePipes(cf_filter_data_t *data);
cf_filter_data_t *data,
void *parameters);
-/* Requires specification of output format via data->final_content_type
- or alternatively as parameter of type cf_filter_out_format_t.
-
- Output formats: PDF, raster-only PDF, PCLm, PostScript, CUPS Raster,
- PWG Raster, Apple Raster, PCL-XL
-
- Note: With the Apple Raster selection and a Ghostscript version
- without "appleraster" output device (9.55.x and older) the output
- is actually CUPS Raster but information about available color
- spaces and depths is taken from the urf-supported printer IPP
- attribute. This mode is for further processing with
- rastertopwg. With Ghostscript supporting Apple Raster output
- (9.56.0 and newer), we actually produce Apple Raster and no further
- filter is required. */
+// Requires specification of output format via data->final_content_type
+// or alternatively as parameter of type cf_filter_out_format_t.
+//
+// Output formats: PDF, raster-only PDF, PCLm, PostScript, CUPS Raster,
+// PWG Raster, Apple Raster, PCL-XL
+//
+// Note: With the Apple Raster selection and a Ghostscript version
+// without "appleraster" output device (9.55.x and older) the output
+// is actually CUPS Raster but information about available color
+// spaces and depths is taken from the urf-supported printer IPP
+// attribute. This mode is for further processing with
+// rastertopwg. With Ghostscript supporting Apple Raster output
+// (9.56.0 and newer), we actually produce Apple Raster and no further
+// filter is required.
extern int cfFilterBannerToPDF(int inputfd,
cf_filter_data_t *data,
void *parameters);
-/* Parameters: const char*
- Template directory: In this directory there are the PDF template files
- for the banners and test pages. CUPS uses /usr/share/cups/data/ for that.
- If you submit a PDF file with added banner instructions as input file
- the template directory is not needed as the PDF input file itself is used
- as template. */
+// Parameters: const char*
+// Template directory: In this directory there are the PDF template files
+// for the banners and test pages. CUPS uses /usr/share/cups/data/ for that.
+// If you submit a PDF file with added banner instructions as input file
+// the template directory is not needed as the PDF input file itself is used
+// as template.
extern int cfFilterImageToPDF(int inputfd,
cf_filter_data_t *data,
void *parameters);
-/* Requires specification of output format via data->final_content_type
-
- Output formats: CUPS Raster, PWG Raster, Apple Raster, PCLM
-
- Note: On the Apple Raster, PWG Raster, and PCLm selection the
- output is actually CUPS Raster but information about available
- color spaces and depths is taken from the urf-supported or
- pwg-raster-document-type-supported printer IPP attributes or from a
- supplied CUPS Raster sample header. This mode is for further
- processing with rastertopwg or pwgtopclm. This can change in the
- future when we add Apple Raster and PWG Raster output support to
- this filter function. */
+// Requires specification of output format via data->final_content_type
+//
+// Output formats: CUPS Raster, PWG Raster, Apple Raster, PCLM
+//
+// Note: On the Apple Raster, PWG Raster, and PCLm selection the
+// output is actually CUPS Raster but information about available
+// color spaces and depths is taken from the urf-supported or
+// pwg-raster-document-type-supported printer IPP attributes or from a
+// supplied CUPS Raster sample header. This mode is for further
+// processing with rastertopwg and/or pwgtopclm. This can change in the
+// future when we add Apple Raster and PWG Raster output support to
+// this filter function.
extern int cfFilterMuPDFToPWG(int inputfd,
cf_filter_data_t *data,
void *parameters);
-/* Requires specification of output format via data->final_content_type
-
- Output formats: CUPS Raster, PWG Raster, Apple Raster, PCLm
-
- Note: With CUPS Raster, Apple Raster, or PCLm selections the output
- is actually PWG Raster but information about available color spaces
- and depths is taken from the urf-supported printer IPP attribute,
- the pclm- attributes, or from a supplied CUPS Raster sample header
- (PCLM is always sGray/sRGB 8-bit). These modes are for further
- processing with pwgtoraster or pwgtopclm. This can change in the
- future when MuPDF adds further output formats. */
+// Requires specification of output format via data->final_content_type
+//
+// Output formats: CUPS Raster, PWG Raster, Apple Raster, PCLm
+//
+// Note: With CUPS Raster, Apple Raster, or PCLm selections the output
+// is actually PWG Raster but information about available color spaces
+// and depths is taken from the urf-supported printer IPP attribute,
+// the pclm- attributes, or from a supplied CUPS Raster sample header
+// (PCLM is always sGray/sRGB 8-bit). These modes are for further
+// processing with pwgtoraster or pwgtopclm. This can change in the
+// future when MuPDF adds further output formats.
extern int cfFilterPCLmToRaster(int inputfd,
cf_filter_data_t *data,
void *parameters);
-/* Requires specification of output format via data->final_content_type
-
- Output formats: CUPS Raster, Apple Raster, or PWG Raster */
+// Requires specification of output format via data->final_content_type
+//
+// Output formats: CUPS Raster, Apple Raster, or PWG Raster
extern int cfFilterPDFToPDF(int inputfd,
cf_filter_data_t *data,
void *parameters);
-/* (Optional) Specification of output format via
- data->final_content_type is used for determining whether this
- filter function does page logging for CUPS (output of "PAGE: XX YY"
- log messages) or not and also to determine whether the printer or
- driver generates copies or whether we have to send the pages
- repeatedly.
-
- Alternatively, the options "pdf-filter-page-logging",
- "hardware-copies", and "hardware-collate" can be used to manually
- do these selections. */
+// (Optional) Specification of output format via
+// data->final_content_type is used for determining whether this
+// filter function does page logging for CUPS (output of "PAGE: XX YY"
+// log messages) or not and also to determine whether the printer or
+// driver generates copies or whether we have to send the pages
+// repeatedly.
+//
+// Alternatively, the options "pdf-filter-page-logging",
+// "hardware-copies", and "hardware-collate" can be used to manually
+// do these selections.
extern int cfFilterPDFToRaster(int inputfd,
cf_filter_data_t *data,
void* parameters);
-/* Requires specification of output format via data->final_content_type
-
- Output formats: CUPS Raster, PWG Raster, Apple Raster, PCLm
-
- Note: With PCLm selection the output is actually CUPS Raster but
- color space and depth will be 8-bit sRGB or SGray, the only color
- spaces supported by PCLm. This mode is for further processing with
- pwgtopclm. */
+// Requires specification of output format via data->final_content_type
+//
+// Output formats: CUPS Raster, PWG Raster, Apple Raster, PCLm
+//
+// Note: With PCLm selection the output is actually PWG Raster but
+// color space and depth will be 8-bit sRGB or SGray, the only color
+// spaces supported by PCLm. This mode is for further processing with
+// pwgtopclm.
extern int cfFilterPWGToRaster(int inputfd,
cf_filter_data_t *data,
void *parameters);
-/* Requires specification of output format via data->final_content_type
-
- Output formats: CUPS Raster, PWG Raster, Apple Raster */
+// Requires specification of output format via data->final_content_type
+//
+// Output formats: CUPS Raster, PWG Raster, Apple Raster
extern int cfFilterPWGToPDF(int inputfd,
cf_filter_data_t *data,
void *parameters);
-/* Requires specification of output format via data->final_content_type
- or alternatively as parameter of type cf_filter_out_format_t.
-
- Output formats: PDF, PCLm */
+// Requires specification of output format via data->final_content_type
+// or alternatively as parameter of type cf_filter_out_format_t.
+//
+// Output formats: PDF, PCLm
extern int cfFilterRasterToPWG(int inputfd,
cf_filter_data_t *data,
void *parameters);
-/* Requires specification of output format via data->final_content_type
-
- Output formats: Apple Raster or PWG Raster, if PCLM is specified
- PWG Raster is produced to feed into the cfFilterPWGToPDF() filter
- function. */
+// Requires specification of output format via data->final_content_type
+//
+// Output formats: Apple Raster or PWG Raster, if PCLM is specified
+// PWG Raster is produced to feed into the cfFilterPWGToPDF() filter
+// function.
extern int cfFilterTextToPDF(int inputfd,
cf_filter_data_t *data,
void *parameters);
-/* Parameters: cf_filter_texttopdf_parameter_t*
-
- Data directory (fonts, charsets), charset, content type (for prettyprint),
- classification (for overprint/watermark) */
+// Parameters: cf_filter_texttopdf_parameter_t*
+//
+// Data directory (fonts, charsets), charset, content type (for prettyprint),
+// classification (for overprint/watermark)
extern int cfFilterTextToText(int inputfd,
cf_filter_data_t *data,
void *parameters);
+
extern int cfFilterUniversal(int inputfd,
int outputfd,
int inputseekable,
cf_filter_data_t *data,
void *parameters);
-/* Requires specification of input format via data->content_type and
- job's final output format via data->final_content_type
-
- Parameters: cf_filter_universal_parameter_t
-
- Contains: actual_output_type: Format which the filter should
- actually produce if different from job's final output
- format, otherwise NULL to produce the job's final output
- format
- texttopdf_params: parameters for texttopdf */
+// Requires specification of input format via data->content_type and
+// job's final output format via data->final_content_type
+//
+// Parameters: cf_filter_universal_parameter_t
+//
+// Contains: actual_output_type: Format which the filter should
+// actually produce if different from job's final output
+// format, otherwise NULL to produce the job's final output
+// format
+// texttopdf_params: parameters for texttopdf
# ifdef __cplusplus
}
-# endif /* __cplusplus */
-
-#endif /* !_CUPS_FILTERS_FILTER_H_ */
+# endif // __cplusplus
-/*
- * End
- */
+#endif // !_CUPS_FILTERS_FILTER_H_
void dump(pdftopdf_doc_t *doc) const;
};
-/*
- This class does the number-up calculation. Example:
-
- _cfPDFToPDFNupParameters param;
- param.xyz = ...; // fill it with your data!
-
- _cfPDFToPDFNupState nup(param);
- _cfPDFToPDFNupPageEdit edit;
- for (auto page : your_pages)
- {
- bool newPage = nup.mext_page(page.w, page.h, edit); // w, h from input page
- // create newPage, if required; then place current page as specified in edit
- }
-*/
+//
+// This class does the number-up calculation. Example:
+//
+// _cfPDFToPDFNupParameters param;
+// param.xyz = ...; // fill it with your data!
+//
+// _cfPDFToPDFNupState nup(param);
+// _cfPDFToPDFNupPageEdit edit;
+// for (auto page : your_pages)
+// {
+// bool newPage = nup.mext_page(page.w, page.h, edit); // w, h from input
+// // page
+// // create newPage, if required; then place current page as specified
+// // in edit
+// }
+//
class _cfPDFToPDFNupState
{
#include <cupsfilters/filter.h>
-typedef struct /***** Document information *****/
+typedef struct // **** Document information ****
{
- cf_logfunc_t logfunc; /* Log function */
- void *logdata; /* Log data */
- cf_filter_iscanceledfunc_t iscanceledfunc; /* Function returning 1 when
- job is canceled, NULL for not
- supporting stop on cancel */
- void *iscanceleddata; /* User data for is-canceled
- function, can be NULL */
+ cf_logfunc_t logfunc; // Log function
+ void *logdata; // Log data
+ cf_filter_iscanceledfunc_t iscanceledfunc; // Function returning 1 when
+ // job is canceled, NULL for not
+ // supporting stop on cancel
+ void *iscanceleddata; // User data for is-canceled
+ // function, can be NULL
} pdftopdf_doc_t;
#endif // !_CUPS_FILTERS_PDFTOPDF_PDFTOPDF_H
}
else if (optGetInt("orientation-requested", num_options, options, &ipprot))
{
- /* IPP orientation values are:
- * 3: 0 degrees, 4: 90 degrees, 5: -90 degrees, 6: 180 degrees
- */
+ // IPP orientation values are:
+ // 3: 0 degrees, 4: 90 degrees, 5: -90 degrees, 6: 180 degrees
+
if ((ipprot < 3) || (ipprot > 6))
{
if (ipprot && doc->logfunc)
void *parameters) // I - Filter-specific parameters
// (unused)
{
- pdftopdf_doc_t doc; /* Document information */
+ pdftopdf_doc_t doc; // Document information
char *final_content_type = data->final_content_type;
FILE *inputfp,
*outputfp;
}
// }}}
-/*
- * This crop function is written for print-scaling=fill option.
- * Trim Box is used for trimming the page in required size.
- * scale tells if we need to scale input file.
- */
+
+//
+// This crop function is written for print-scaling=fill option.
+// Trim Box is used for trimming the page in required size.
+// scale tells if we need to scale input file.
+//
+
pdftopdf_rotation_e
_cfPDFToPDFQPDFPageHandle::crop(const _cfPDFToPDFPageRect &cropRect,
pdftopdf_rotation_e orientation,