]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
libcupsfilters: Added RGBW support to cfFilterPCLmToRaster()
authorTill Kamppeter <till.kamppeter@gmail.com>
Fri, 7 Oct 2022 12:03:22 +0000 (14:03 +0200)
committerTill Kamppeter <till.kamppeter@gmail.com>
Fri, 7 Oct 2022 12:03:22 +0000 (14:03 +0200)
Requesting RGBW as destination color space (to test, use pclmtoraster
CUPS filter wrapper and PPD for HP inkjet with hpcups driver of HPLIP)
leads to wrong color output on some input files and even to a crash on
others.

This is cause by missing support for RGBW and this, instead RGB being
output into the destination file with RGBW declared as the color space
in its header.

This commit adds explicit support for RGBW output and this way solves
the problem.

cupsfilters/pclmtoraster.cxx

index c201b51aad64df071d69a5643e2604a9ec650341..763b94996eb39999b4660561b2305c1ce249c895 100644 (file)
@@ -356,6 +356,20 @@ rotate_bitmap(unsigned char *src,    // I - Input string
 }
 
 
+static unsigned char *
+rgb_to_rgbw_line(unsigned char *src,
+                unsigned char *dst,
+                unsigned int row,
+                unsigned int pixels,
+                pclmtoraster_data_t *data)
+{
+  cfImageRGBToCMYK(src, dst, pixels);
+  for (unsigned int i = 0; i < 4 * pixels; i ++)
+    dst[i] = ~dst[i];
+  return (dst);
+}
+
+
 static unsigned char *
 rgb_to_cmyk_line(unsigned char *src,
                 unsigned char *dst,
@@ -428,6 +442,19 @@ cmyk_to_rgb_line(unsigned char *src,
 }
 
 
+static unsigned char *
+cmyk_to_rgbw_line(unsigned char *src,
+                 unsigned char *dst,
+                 unsigned int row,
+                 unsigned int pixels,
+                 pclmtoraster_data_t *data)
+{
+  for (unsigned int i = 0; i < 4 * pixels; i ++)
+    dst[i] = ~src[i];
+  return (dst);
+}
+
+
 static unsigned char *
 cmyk_to_cmy_line(unsigned char *src,
                 unsigned char *dst,
@@ -490,6 +517,20 @@ gray_to_rgb_line(unsigned char *src,
 }
 
 
+static unsigned char *
+gray_to_rgbw_line(unsigned char *src,
+                 unsigned char *dst,
+                 unsigned int row,
+                 unsigned int pixels,
+                 pclmtoraster_data_t *data)
+{
+  cfImageWhiteToCMYK(src, dst, pixels);
+  for (unsigned int i = 0; i < 4 * pixels; i ++)
+    dst[i] = ~dst[i];
+  return (dst);
+}
+
+
 static unsigned char *
 gray_to_cmyk_line(unsigned char *src,
                  unsigned char *dst,
@@ -720,6 +761,14 @@ select_convert_func(int                    pgno,    // I - Page number
        else if (colorspace == "/DeviceGray")
          convert->convertcspace = gray_to_cmyk_line;
        break;
+    case CUPS_CSPACE_RGBW:
+        if (colorspace == "/DeviceRGB")
+         convert->convertcspace = rgb_to_rgbw_line;
+       else if (colorspace == "/DeviceCMYK")
+         convert->convertcspace = cmyk_to_rgbw_line;
+       else if (colorspace == "/DeviceGray")
+         convert->convertcspace = gray_to_rgbw_line;
+       break;
     case CUPS_CSPACE_RGB:
     case CUPS_CSPACE_ADOBERGB:
     case CUPS_CSPACE_SRGB:
@@ -814,7 +863,7 @@ out_page(cups_raster_t*      raster,        // I - Raster stream
                        &(paperdimensions[0]), &(paperdimensions[1]),
                        &(margins[0]), &(margins[1]),
                        &(margins[2]), &(margins[3]), NULL, NULL);
-    if (data->outformat == CF_FILTER_OUT_FORMAT_PWG_RASTER)
+    if (data->outformat != CF_FILTER_OUT_FORMAT_CUPS_RASTER)
       memset(margins, 0, sizeof(margins));
   }
   else