RHEL-26148 - fix grayscale/color raster printing via AirPrint

Resolves: RHEL-26148
This commit is contained in:
Zdenek Dohnal 2024-03-20 12:48:04 +01:00
parent a9b9734d1d
commit 8bc4532aef
2 changed files with 214 additions and 1 deletions

View File

@ -0,0 +1,208 @@
diff --git a/cupsfilters/raster.c b/cupsfilters/raster.c
index 67a20bd..58a5135 100644
--- a/cupsfilters/raster.c
+++ b/cupsfilters/raster.c
@@ -28,6 +28,7 @@
#include <ctype.h>
#include <cupsfilters/ipp.h>
#include <cups/pwg.h>
+#include <stdbool.h>
//
// Local functions
@@ -1419,41 +1420,46 @@ raster_base_header(cups_page_header2_t *h, // O - Raster header
// TODO - Support for MediaType number
h->cupsMediaType = 0;
- // Only for CUPS Raster, if we do not have a sample header from a PPD file
- if (pwg_raster == 0 &&
- ((val = cupsGetOption("pwg-raster-document-type", num_options,
- options)) != NULL ||
- (val = cupsGetOption("PwgRasterDocumentType", num_options,
- options)) != NULL ||
- (val = cupsGetOption("color-space", num_options, options)) != NULL ||
- (val = cupsGetOption("ColorSpace", num_options, options)) != NULL ||
- (val = cupsGetOption("color-model", num_options, options)) != NULL ||
- (val = cupsGetOption("ColorModel", num_options, options)) != NULL ||
- (val = cupsGetOption("print-color-mode", num_options, options)) !=
- NULL ||
- (val = cupsGetOption("output-mode", num_options, options)) != NULL ||
- (val = cupsGetOption("OutputMode", num_options, options)) != NULL ||
- (val = cfIPPAttrEnumValForPrinter(data->printer_attrs,
- data->job_attrs,
- "print-color-mode")) != NULL))
+
+ // Do we have a color printer?
+ bool is_color =
+ ((attr = ippFindAttribute(data->printer_attrs, "color-supported",
+ IPP_TAG_BOOLEAN)) != NULL &&
+ ippGetBoolean(attr, 0));
+
+ // Color modes
+ int numcolors = 0; // Number of colorants
+ if ((val = cupsGetOption("pwg-raster-document-type", num_options,
+ options)) != NULL ||
+ (val = cupsGetOption("PwgRasterDocumentType", num_options,
+ options)) != NULL ||
+ (val = cupsGetOption("color-space", num_options, options)) != NULL ||
+ (val = cupsGetOption("ColorSpace", num_options, options)) != NULL ||
+ (val = cupsGetOption("color-model", num_options, options)) != NULL ||
+ (val = cupsGetOption("ColorModel", num_options, options)) != NULL ||
+ (val = cupsGetOption("print-color-mode", num_options, options)) !=
+ NULL ||
+ (val = cupsGetOption("output-mode", num_options, options)) != NULL ||
+ (val = cupsGetOption("OutputMode", num_options, options)) != NULL ||
+ (val = cfIPPAttrEnumValForPrinter(data->printer_attrs,
+ data->job_attrs,
+ "print-color-mode")) != NULL)
{
int bitspercolor, // Bits per color
bitsperpixel, // Bits per pixel
- colorspace, // CUPS/PWG raster color space
- numcolors; // Number of colorants
+ colorspace; // CUPS/PWG raster color space;
const char *ptr; // Pointer into value
ptr = NULL;
- numcolors = 0;
bitspercolor = 8;
- if (!strncasecmp(val, "AdobeRgb", 8))
+ if (is_color && !strncasecmp(val, "AdobeRgb", 8))
{
if (*(val + 8) == '_' || *(val + 8) == '-')
ptr = val + 9;
colorspace = 20;
numcolors = 3;
}
- else if (!strncasecmp(val, "adobe-rgb", 9))
+ else if (is_color && !strncasecmp(val, "adobe-rgb", 9))
{
if (*(val + 9) == '_' || *(val + 9) == '-')
ptr = val + 10;
@@ -1499,19 +1505,19 @@ raster_base_header(cups_page_header2_t *h, // O - Raster header
colorspace = 18;
numcolors = 1;
}
- else if (!strcasecmp(val, "color"))
+ else if (is_color && !strcasecmp(val, "color"))
{
colorspace = 19;
numcolors = 3;
}
- else if (!strncasecmp(val, "Cmyk", 4))
+ else if (is_color && !strncasecmp(val, "Cmyk", 4))
{
if (*(val + 4) == '_' || *(val + 4) == '-')
ptr = val + 5;
colorspace = 6;
numcolors = 4;
}
- else if (!strncasecmp(val, "Cmy", 3))
+ else if (!pwg_raster && is_color && !strncasecmp(val, "Cmy", 3))
{
if (*(val + 3) == '_' || *(val + 3) == '-')
ptr = val + 4;
@@ -1523,10 +1529,9 @@ raster_base_header(cups_page_header2_t *h, // O - Raster header
ptr = val + 6;
numcolors = strtol(ptr, (char **)&ptr, 10);
if (*ptr == '_' || *ptr == '-')
- {
ptr ++;
+ if (numcolors > 0 && numcolors < 16)
colorspace = 47 + numcolors;
- }
else
{
numcolors = 0;
@@ -1544,39 +1549,49 @@ raster_base_header(cups_page_header2_t *h, // O - Raster header
{
if (*(val + 4) == '_' || *(val + 4) == '-')
ptr = val + 5;
- colorspace = 18;
+ colorspace = pwg_raster ? 18 : 3;
numcolors = 1;
}
- else if (!strncasecmp(val, "Srgb", 4))
+ else if (is_color && !strncasecmp(val, "Srgb", 4))
{
if (*(val + 4) == '_' || *(val + 4) == '-')
ptr = val + 5;
colorspace = 19;
numcolors = 3;
}
- else if (!strncasecmp(val, "Rgbw", 4))
+ else if (!pwg_raster && is_color && !strncasecmp(val, "Rgbw", 4))
{
if (*(val + 4) == '_' || *(val + 4) == '-')
ptr = val + 5;
colorspace = 17;
numcolors = 4;
}
- else if (!strncasecmp(val, "Rgb", 3))
+ else if (is_color && !strncasecmp(val, "Rgb", 3))
{
if (*(val + 3) == '_' || *(val + 3) == '-')
ptr = val + 4;
- colorspace = 1;
+ colorspace = pwg_raster ? 19 : 1;
numcolors = 3;
}
else if (!strcasecmp(val, "auto"))
{
// Let "auto" not look like an error
- colorspace = 19;
- numcolors = 3;
+ if (is_color)
+ {
+ colorspace = 19;
+ numcolors = 3;
+ }
+ else
+ {
+ colorspace = 18;
+ numcolors = 1;
+ }
}
+
+ // Color mode found
if (numcolors > 0)
{
- if (ptr)
+ if (ptr && *ptr)
bitspercolor = strtol(ptr, (char **)&ptr, 10);
bitsperpixel = bitspercolor * numcolors;
// In 1-bit-per-color RGB modes we add a forth bit to each pixel
@@ -1589,20 +1604,25 @@ raster_base_header(cups_page_header2_t *h, // O - Raster header
h->cupsColorSpace = colorspace;
h->cupsNumColors = numcolors;
}
- else
+ }
+
+ // No color mode found
+ if (numcolors == 0)
+ {
+ if (is_color)
{
h->cupsBitsPerColor = 8;
h->cupsBitsPerPixel = 24;
h->cupsColorSpace = 19;
h->cupsNumColors = 3;
}
- }
- else
- {
- h->cupsBitsPerColor = 8;
- h->cupsBitsPerPixel = 24;
- h->cupsColorSpace = 19;
- h->cupsNumColors = 3;
+ else
+ {
+ h->cupsBitsPerColor = 8;
+ h->cupsBitsPerPixel = 8;
+ h->cupsColorSpace = 18;
+ h->cupsNumColors = 1;
+ }
}
// TODO - Support for color orders 1 (banded) and 2 (planar)

View File

@ -4,7 +4,7 @@
Name: libcupsfilters
Epoch: 1
Version: 2.0.0
Release: 5%{?dist}
Release: 6%{?dist}
Summary: Library for developing printing filters
# the CUPS exception text is the same as LLVM exception, so using that name with
# agreement from legal team
@ -15,6 +15,8 @@ Source0: %{URL}/releases/download/%{version}/%{name}-%{version}.tar.gz
# Patches
# RHEL-26148 - fix grayscale/color raster printing via AirPrint
Patch001: libcf-color-raster-printing.patch
# for generating configure and Makefile scripts in autogen.h
@ -192,6 +194,9 @@ rm -f %{buildroot}%{_pkgdocdir}/{LICENSE,COPYING,NOTICE}
%changelog
* Wed Mar 20 2024 Zdenek Dohnal <zdohnal@redhat.com> - 1:2.0.0-6
- RHEL-26148 - fix grayscale/color raster printing via AirPrint
* Mon Jan 29 2024 Fedora Release Engineering <releng@fedoraproject.org> - 1:2.0.0-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild