]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
libcupsfilters: Corrected color management API
authorTill Kamppeter <till.kamppeter@gmail.com>
Tue, 22 Mar 2022 21:16:32 +0000 (22:16 +0100)
committerTill Kamppeter <till.kamppeter@gmail.com>
Tue, 22 Mar 2022 21:16:32 +0000 (22:16 +0100)
To the color management functions of cupsfilters/colormanager.c got a
pointer to a filter data record (filter_data_t) added to their
parameter lists to convey a log function to them, so that they log
into the caller's log function and not to stderr any more.

It was not taken into account that the data structure also contains
the print queue name and so the print queue name was continued to be
explicitly supplied as the second parameter.

This is not needed any more and so we have changed the parameter lists
of the functions, not explicitly taking the print queue name any more
and the functions use the print queue name from the data structure.

Also fixed some bugs:

- Do not use getenv("PRINTER") in filter functions. The print queue
  name is part of the filter_data_t data structure.

- In foomatic-rip make sure that the correct print queue name gets
  added to the data structure before the first call of a color
  management function happens. Also make sure that color management
  also works in spooler-less mode.

cupsfilters/colormanager.c
cupsfilters/colormanager.h
cupsfilters/ghostscript.c
cupsfilters/imagetoraster.c
cupsfilters/mupdftoraster.c
cupsfilters/pdftoraster.cxx
cupsfilters/pwgtoraster.c
cupsfilters/rastertopdf.cpp
filter/foomatic-rip/foomaticrip.c
filter/rastertopclx.c

index 12313cc28483c671393ccbaa07c98180baad0fa3..c06c1a39e5786c32efa73aff63c104539ec6c602 100644 (file)
@@ -36,12 +36,9 @@ MIT Open Source License  -  http://www.opensource.org/
 
 
 /* Private function prototypes */
-static int      _get_colord_printer_cm_status   (filter_data_t *data,
-                                                const char *printer_name);
-static char    *_get_colord_printer_id          (filter_data_t *data, 
-                                                const char *printer_name);
-static int      _get_colord_profile             (filter_data_t *data, 
-                                                const char *printer_name, 
+static int      _get_colord_printer_cm_status   (filter_data_t *data);
+static char    *_get_colord_printer_id          (filter_data_t *data);
+static int      _get_colord_profile             (filter_data_t *data,
                                                  char **profile,
                                                  ppd_file_t *ppd);
 static char    *_get_ppd_icc_fallback           (filter_data_t *data, 
@@ -71,8 +68,7 @@ double    blackpoint_default[3] = {0.0, 0.0, 0.0};
 
 /* Get printer color management status from the system's color manager */
 int          
-cmIsPrinterCmDisabled( filter_data_t *data,
-               const char *printer_name)    /* dest name */
+cmIsPrinterCmDisabled(filter_data_t *data)
 {
     filter_logfunc_t log = data->logfunc;
     void *ld = data->logdata;
@@ -80,7 +76,7 @@ cmIsPrinterCmDisabled( filter_data_t *data,
 
 
     /* Request color management status from colord */
-    is_cm_off = _get_colord_printer_cm_status(data, printer_name);
+    is_cm_off = _get_colord_printer_cm_status(data);
 
     if (is_cm_off)
        if(log) log(ld, FILTER_LOGLEVEL_DEBUG,
@@ -94,7 +90,6 @@ cmIsPrinterCmDisabled( filter_data_t *data,
 /* Get printer ICC profile from the system's color manager */
 int 
 cmGetPrinterIccProfile(filter_data_t *data,
-                      const char *printer_name,  /* Printer name (usually "dest" name) */
                        char **icc_profile,        /* ICC Profile Path */
                        ppd_file_t *ppd)           /* Optional PPD file for fallback profile */
 {
@@ -104,7 +99,7 @@ cmGetPrinterIccProfile(filter_data_t *data,
 
 
     /* Request a profile from colord */
-    profile_set = _get_colord_profile(data, printer_name, icc_profile, ppd);
+    profile_set = _get_colord_profile(data, icc_profile, ppd);
     if(log) log(ld, FILTER_LOGLEVEL_DEBUG,
                "Color Manager: ICC Profile: %s", *icc_profile ?
         *icc_profile : "None");
@@ -192,13 +187,12 @@ double *cmBlackPointDefault(void)
 
 
 char * 
-_get_colord_printer_id( filter_data_t *data,
-                       const char *printer_name)         /* Dest name */
+_get_colord_printer_id( filter_data_t *data)
 {
 
     filter_logfunc_t log = data->logfunc;
     void *ld = data->logdata;
-    if (printer_name == NULL) {
+    if (data->printer == NULL) {
       if(log) log(ld, FILTER_LOGLEVEL_DEBUG,
                "Color Manager: Invalid printer name.");
       return 0;
@@ -206,7 +200,7 @@ _get_colord_printer_id( filter_data_t *data,
 
     /* Create printer id string for colord */
     char* printer_id = (char*)malloc(CM_MAX_FILE_LENGTH);
-    snprintf (printer_id, CM_MAX_FILE_LENGTH, "cups-%s", printer_name);
+    snprintf (printer_id, CM_MAX_FILE_LENGTH, "cups-%s", data->printer);
 
     return printer_id;    
 
@@ -214,19 +208,18 @@ _get_colord_printer_id( filter_data_t *data,
 
 
 int 
-_get_colord_printer_cm_status( filter_data_t *data,
-               const char *printer_name)  /* Dest name */
+_get_colord_printer_cm_status( filter_data_t *data)
 {
 
     filter_logfunc_t log = data->logfunc;
     void *ld = data->logdata;
 
     /* If invalid input, we leave color management alone */
-    if (printer_name == NULL) {
+    if (data->printer == NULL) {
       if(log) log(ld, FILTER_LOGLEVEL_DEBUG,
                "Color Manager: Invalid printer name.");
       return 0;
-    } else if (!strcmp(printer_name, "(null)"))
+    } else if (!strcmp(data->printer, "(null)"))
       return 0;
  
     int is_printer_cm_disabled = 0;   /* color management status flag */
@@ -234,7 +227,7 @@ _get_colord_printer_cm_status( filter_data_t *data,
 
 
     /* Check if device is inhibited/disabled in colord  */
-    printer_id = _get_colord_printer_id(data, printer_name);
+    printer_id = _get_colord_printer_id(data);
     is_printer_cm_disabled = colord_get_inhibit_for_device_id (data, printer_id);
 
     if (printer_id != NULL)
@@ -246,7 +239,6 @@ _get_colord_printer_cm_status( filter_data_t *data,
 
 int 
 _get_colord_profile(filter_data_t *data,
-                   const char   *printer_name,     /* Dest name */
                     char         **profile,         /* Requested icc profile path */      
                     ppd_file_t   *ppd)              /* PPD file */
 {
@@ -254,7 +246,7 @@ _get_colord_profile(filter_data_t *data,
     filter_logfunc_t log = data->logfunc;
     void *ld = data->logdata;
 
-    if (printer_name == NULL || profile == 0) {
+    if (data->printer == NULL || profile == 0) {
       if(log) log(ld, FILTER_LOGLEVEL_DEBUG,
                "Color Manager: Invalid input - Unable to find profile."); 
       return -1;
@@ -270,7 +262,7 @@ _get_colord_profile(filter_data_t *data,
     qualifier = colord_get_qualifier_for_ppd(ppd);
 
     if (qualifier != NULL) {
-      printer_id = _get_colord_printer_id(data, printer_name);
+      printer_id = _get_colord_printer_id(data);
       /* Get profile from colord using qualifiers */
       icc_profile = colord_get_profile_for_device_id (data,
                                                      (const char *)printer_id,
index ca796fa4b4c51474eced17817d5e7c523921360c..a43a317f896b0b152b73585a932d5624b5f656f1 100644 (file)
@@ -60,17 +60,15 @@ typedef enum cm_calibration_e
 
 
 extern 
-cm_calibration_t    cmGetCupsColorCalibrateMode       ( filter_data_t *data,
+cm_calibration_t    cmGetCupsColorCalibrateMode       (filter_data_t *data,
                                                       cups_option_t *options,
                                                        int num_options);
 
 extern int          cmGetPrinterIccProfile            (filter_data_t *data,
-                                                      const char *printer_id,
                                                        char **icc_profile,
                                                        ppd_file_t *ppd);
 
-extern int          cmIsPrinterCmDisabled             (filter_data_t *data,
-                                                       const char *printer_id);
+extern int          cmIsPrinterCmDisabled             (filter_data_t *data);
 
 extern double*      cmGammaAdobeRgb                   (void);
 extern double*      cmGammaSGray                      (void);
index f4d58644c66ba56236dc68e81d1811a8560cdaf1..7939ba631da690bed61207de2203afac6f5c0e07 100644 (file)
@@ -680,90 +680,6 @@ out:
   return status;
 }
 
-#if 0
-static char *
-get_ppd_icc_fallback (ppd_file_t *ppd,
-                     char **qualifier,
-                     filter_logfunc_t log,
-                     void *ld)
-{
-  char full_path[1024];
-  char *icc_profile = NULL;
-  char qualifer_tmp[1024];
-  const char *profile_key;
-  ppd_attr_t *attr;
-  char *datadir;
-
-  /* get profile attr, falling back to CUPS */
-  profile_key = "APTiogaProfile";
-  attr = ppdFindAttr(ppd, profile_key, NULL);
-  if (attr == NULL) {
-    profile_key = "cupsICCProfile";
-    attr = ppdFindAttr(ppd, profile_key, NULL);
-  }
-
-  /* create a string for a quick comparion */
-  snprintf(qualifer_tmp, sizeof(qualifer_tmp),
-           "%s.%s.%s",
-           qualifier[0],
-           qualifier[1],
-           qualifier[2]);
-
-  /* neither */
-  if (attr == NULL) {
-    if (log) log(ld, FILTER_LOGLEVEL_INFO,
-                "ghostscript: no profiles specified in PPD");
-    goto out;
-  }
-
-  if ((datadir = getenv("CUPS_DATADIR")) == NULL)
-    datadir = CUPS_DATADIR;
-
-  /* try to find a profile that matches the qualifier exactly */
-  for (;attr != NULL; attr = ppdFindNextAttr(ppd, profile_key, NULL)) {
-    if (log) log(ld, FILTER_LOGLEVEL_INFO,
-                "ghostscript: found profile %s in PPD with qualifier '%s'",
-                attr->value, attr->spec);
-
-    /* invalid entry */
-    if (attr->spec == NULL || attr->value == NULL)
-      continue;
-
-    /* expand to a full path if not already specified */
-    if (attr->value[0] != '/')
-      snprintf(full_path, sizeof(full_path),
-               "%s/profiles/%s", datadir, attr->value);
-    else
-      strncpy(full_path, attr->value, sizeof(full_path));
-
-    /* check the file exists */
-    if (access(full_path, 0)) {
-      if (log) log(ld, FILTER_LOGLEVEL_INFO,
-                  "ghostscript: found profile %s in PPD that does not exist",
-                  full_path);
-      continue;
-    }
-
-    /* matches the qualifier */
-    if (strcmp(qualifer_tmp, attr->spec) == 0) {
-      icc_profile = strdup(full_path);
-      goto out;
-    }
-  }
-
-  /* no match */
-  if (attr == NULL) {
-    if (log) log(ld, FILTER_LOGLEVEL_INFO,
-                "ghostscript: no profiles in PPD for qualifier '%s'",
-                qualifer_tmp);
-    goto out;
-  }
-
-out:
-  return icc_profile;
-}
-#endif /* 0 */
-
 /*
  * 'ghostscript()' - Filter function to use Ghostscript for print
  *                   data conversions
@@ -1071,10 +987,10 @@ ghostscript(int inputfd,         /* I - File descriptor input stream */
   if (cm_calibrate == CM_CALIBRATION_ENABLED)
     cm_disabled = 1;
   else 
-    cm_disabled = cmIsPrinterCmDisabled(data, data->printer);
+    cm_disabled = cmIsPrinterCmDisabled(data);
 
   if (!cm_disabled)
-    cmGetPrinterIccProfile(data, data->printer, &icc_profile, ppd);
+    cmGetPrinterIccProfile(data, &icc_profile, ppd);
 
   /* Ghostscript parameters */
   gs_args = cupsArrayNew(NULL, NULL);
index 3d6709765ef3cacb6d6aad86864ee129b17e1424..84fa7d6ac1ddbb12c60b7e28d0ea03bd8d0549ef 100644 (file)
@@ -674,7 +674,7 @@ imagetoraster(int inputfd,         /* I - File descriptor input stream */
   if (cm_calibrate == CM_CALIBRATION_ENABLED)
     cm_disabled = 1;
   else
-    cm_disabled = cmIsPrinterCmDisabled(data, data->printer);
+    cm_disabled = cmIsPrinterCmDisabled(data);
 
  /*
   * Choose the appropriate colorspace...
index 58d83935d0c6bb71db128bcf6c54a1c0512bc0e7..0022f98cdbbf4a1fa00990a0709d86d5dfdbf0f2 100644 (file)
@@ -506,10 +506,10 @@ mupdftoraster (int inputfd,         /* I - File descriptor input stream */
   if (cm_calibrate == CM_CALIBRATION_ENABLED)
     cm_disabled = 1;
   else 
-    cm_disabled = cmIsPrinterCmDisabled(data, getenv("PRINTER"));
+    cm_disabled = cmIsPrinterCmDisabled(data);
 
   if (!cm_disabled)
-    cmGetPrinterIccProfile(data, getenv("PRINTER"), &icc_profile, ppd);
+    cmGetPrinterIccProfile(data, &icc_profile, ppd);
 
 /*  Find print-rendering-intent */
 
index d33877ed781bbfb8008bff2b7d395d72c2574d77..e3040cdac53d786095c104faa7876856379a9f39 100644 (file)
@@ -430,10 +430,10 @@ static int parseOpts(filter_data_t *data,
     if (doc->colour_profile.cm_calibrate == CM_CALIBRATION_ENABLED)
       doc->colour_profile.cm_disabled = 1;
     else
-      doc->colour_profile.cm_disabled = cmIsPrinterCmDisabled(data, data->printer);
+      doc->colour_profile.cm_disabled = cmIsPrinterCmDisabled(data);
 
     if (!doc->colour_profile.cm_disabled)
-      cmGetPrinterIccProfile(data, data->printer, &profile, doc->ppd);
+      cmGetPrinterIccProfile(data, &profile, doc->ppd);
 
     if (profile != NULL) {
       doc->colour_profile.colorProfile = cmsOpenProfileFromFile(profile,"r");
@@ -512,10 +512,10 @@ static int parseOpts(filter_data_t *data,
     if (doc->colour_profile.cm_calibrate == CM_CALIBRATION_ENABLED)
       doc->colour_profile.cm_disabled = 1;
     else
-      doc->colour_profile.cm_disabled = cmIsPrinterCmDisabled(data, data->printer);
+      doc->colour_profile.cm_disabled = cmIsPrinterCmDisabled(data);
 
     if (!doc->colour_profile.cm_disabled)
-      cmGetPrinterIccProfile(data, data->printer, &profile, doc->ppd);
+      cmGetPrinterIccProfile(data, &profile, doc->ppd);
 
     if (profile != NULL) {
       doc->colour_profile.colorProfile = cmsOpenProfileFromFile(profile,"r");
index 759f862070eae003be30e05d2efe07ceb0c2005e..bcaf26cfcf52382dba4e085fcf06c1473bde449a 100644 (file)
@@ -388,10 +388,10 @@ static int parseOpts(filter_data_t *data,
     if (doc->color_profile.cm_calibrate == CM_CALIBRATION_ENABLED)
       doc->color_profile.cm_disabled = 1;
     else
-      doc->color_profile.cm_disabled = cmIsPrinterCmDisabled(data, data->printer);
+      doc->color_profile.cm_disabled = cmIsPrinterCmDisabled(data);
 
     if (!doc->color_profile.cm_disabled)
-      cmGetPrinterIccProfile(data, data->printer, &profile, doc->ppd);
+      cmGetPrinterIccProfile(data, &profile, doc->ppd);
 
     if (profile != NULL) {
       doc->color_profile.colorProfile = cmsOpenProfileFromFile(profile,"r");
index c3eb6ef9d416e055cf2fcf8a7ef2b235363d4930..7326e8ff41f770750372ffecf44a839525e7c735 100644 (file)
@@ -1448,7 +1448,7 @@ rastertopdf(int inputfd,    /* I - File descriptor input stream */
       cm_calibrate == CM_CALIBRATION_ENABLED)
     doc.cm_disabled = 1;
   else
-    doc.cm_disabled = cmIsPrinterCmDisabled(data, getenv("PRINTER"));
+    doc.cm_disabled = cmIsPrinterCmDisabled(data);
 
   if (outformat == OUTPUT_FORMAT_PCLM && data->ppd == NULL
         && printer_attrs == NULL )
index fda6872002fea894f7eb1c3d4585b89353856750..a03c83726c856199df7999b463abf71597daa96a 100644 (file)
@@ -852,17 +852,15 @@ int main(int argc, char** argv)
         if (strlen(getenv("PPD")) > 2047)
           job->ppdfile[2047] = '\0';
         spooler = SPOOLER_CUPS;
-    if (getenv("CUPS_SERVERBIN")) {
-        strncpy(cupsfilterpath, getenv("CUPS_SERVERBIN"),
-               sizeof(cupsfilterpath) - 1);
-        if (strlen(getenv("CUPS_SERVERBIN")) > PATH_MAX-1)
-          cupsfilterpath[PATH_MAX-1] = '\0';
+       strncpy_omit(job->printer, getenv("PRINTER"), 256, omit_shellescapes);
+       if (getenv("CUPS_SERVERBIN")) {
+            strncpy(cupsfilterpath, getenv("CUPS_SERVERBIN"),
+                    sizeof(cupsfilterpath) - 1);
+            if (strlen(getenv("CUPS_SERVERBIN")) > PATH_MAX-1)
+              cupsfilterpath[PATH_MAX-1] = '\0';
         }
     }
 
-    /* Check status of printer color management from the color manager */
-    cm_disabled = cmIsPrinterCmDisabled(data, getenv("PRINTER"));
-
     /* CUPS calls foomatic-rip only with 5 or 6 positional parameters,
        not with named options, like for example "-p <string>". */
     if (spooler != SPOOLER_CUPS) {
@@ -916,6 +914,10 @@ int main(int argc, char** argv)
 
     }
 
+    /* Check status of printer color management from the color manager */
+    data->printer = job->printer;
+    cm_disabled = cmIsPrinterCmDisabled(data);
+
     _log("'CM Color Calibration' Mode in SPOOLER-LESS: %s\n", cm_calibrate ? 
          "Activated" : "Off");
 
@@ -1040,8 +1042,7 @@ int main(int argc, char** argv)
                   _log("INFO: Using qualifer: '%s.%s.%s'\n",
                         qualifier[0], qualifier[1], qualifier[2]);
 
-                  cmGetPrinterIccProfile(data, getenv("PRINTER"),
-                                        (char **)&icc_profile, 0);
+                  cmGetPrinterIccProfile(data, (char **)&icc_profile, 0);
 
                   /* fall back to PPD */
                   if (icc_profile == NULL) {
index 4a7b75cb1d449178167a3175f5e715dec40b32b2..8dbab3ec80892a5afeb6734da4f304a6105cd1f4 100644 (file)
@@ -107,7 +107,7 @@ int ReadLine(cups_raster_t *ras, cups_page_header2_t *header);
  */
 
 void
-StartPage(filter_data_t *data,         /* I - filter data */
+StartPage(filter_data_t      *data,    /* I - filter data */
          ppd_file_t         *ppd,      /* I - PPD file */
           cups_page_header2_t *header, /* I - Page header */
          int                job_id,    /* I - Job ID */
@@ -352,7 +352,7 @@ StartPage(filter_data_t *data,              /* I - filter data */
     if (cm_calibrate == CM_CALIBRATION_ENABLED)
       cm_disabled = 1;
     else
-      cm_disabled = cmIsPrinterCmDisabled(data, getenv("PRINTER"));
+      cm_disabled = cmIsPrinterCmDisabled(data);
 
     if (ppd && !cm_disabled)
     {
@@ -1831,6 +1831,7 @@ main(int  argc,                           /* I - Number of command-line arguments */
   */
   filter_data_t temp;
   filter_data_t *data = &temp;
+  data->printer = getenv("PRINTER");
   data->logdata = NULL;
   data->logfunc = cups_logfunc;
   if (argc < 6 || argc > 7)