michaelrsweet / pappl

PAPPL - Printer Application Framework
https://www.msweet.org/pappl
Apache License 2.0
309 stars 49 forks source link

When printing colored PNG image in gray the image does not get correctly converted #63

Closed tillkamppeter closed 3 years ago

tillkamppeter commented 3 years ago

Describe the bug When printing JPEG or PNG images with PAPPL's built-in image filters the images being color but printing being done in gray (monochrome printer or user request), the images are supposed to be converted when loading with libjpeg or libpng. This is doe correctly for JPEG images bug not for PNG. The patch below fixes this:

--- a/pappl/job-filter.c
+++ b/pappl/job-filter.c
@@ -535,7 +556,7 @@ _papplJobFilterPNG(
   // Prepare options...
   options = papplJobCreatePrintOptions(job, 1, (png.format & PNG_FORMAT_FLAG_CO
LOR) != 0);

-  if (png.format & PNG_FORMAT_FLAG_COLOR)
+  if (options->header.cupsNumColors > 1)
   {
     png.format = PNG_FORMAT_RGB;
     png_bpp    = 3;

Without the patch the function papplJobFilterImage() receives the 3-byte color pixels and only copies the first of the three bytes into the destination image, meaning that only the red components of the original image are used. On most photos one sees only a slight difference, but on drawings for example important parts can miss in the printout.

To Reproduce Print PNG images with a PAPPL-based Printer Application, preferably a drawing with pure red, grren, and blue graphical elements.

System Information:

michaelrsweet commented 3 years ago

[master ec80129] Fix PNG grayscale printing (Issue #63)