michaelrsweet / pappl

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

When printing an image with "print-scaling=fill" the image is not blown to fully fill the page but printed as with "print-scaling=auto" #62

Closed tillkamppeter closed 3 years ago

tillkamppeter commented 3 years ago

Describe the bug When I set my PostScript Printer Application to print images with PAPPL's built-in image filter using the raster callbacks and I supply the setting "print-scaling=fill", either by setting it as default in the web interface or by supplying the option -o print-scaling=fill on the command line, the setting is ignored and the image printed in standard "auto" mode leaving white borders at two edges. Debug log shows use of "fill" but image comes out as with "auto":

D [2020-11-06T17:27:22.305Z] [Job 62] Created job file "/tmp/pappl248865.d/p00001j000000062-1221-pb237716_jpg.jpg", format "image/jpeg".
D [2020-11-06T17:27:22.316Z] [Printer test] Checking for new jobs to process.
D [2020-11-06T17:27:22.316Z] [Printer test] Starting job 62.
I [2020-11-06T17:27:22.316Z] [Client 4] Print-Job successful-ok
I [2020-11-06T17:27:22.316Z] [Job 62] Starting print job.
I [2020-11-06T17:27:22.316Z] [Client 4] OK application/ipp 223
D [2020-11-06T17:27:22.316Z] [Client 4] Print-Job response: IPP/2.0 request-id=2, status-code=successful-ok
D [2020-11-06T17:27:22.316Z] [Client 4] Print-Job response: operation-attributes-tag
D [2020-11-06T17:27:22.316Z] [Client 4] Print-Job response:   attributes-charset charset utf-8
D [2020-11-06T17:27:22.316Z] [Client 4] Print-Job response:   attributes-natural-language naturalLanguage en-us
D [2020-11-06T17:27:22.316Z] [Client 4] Print-Job response: job-attributes-tag
D [2020-11-06T17:27:22.316Z] [Client 4] Print-Job response:   job-id integer 62
D [2020-11-06T17:27:22.316Z] [Client 4] Print-Job response:   job-uri uri ipp://localhost/ipp/print/test/62
D [2020-11-06T17:27:22.316Z] [Client 4] Print-Job response:   job-state enum processing
D [2020-11-06T17:27:22.316Z] [Client 4] Print-Job response:   job-state-message textWithoutLanguage Job printing.
D [2020-11-06T17:27:22.316Z] [Client 4] Print-Job response:   job-state-reasons keyword job-printing
test-62
I [2020-11-06T17:27:22.316Z] [Client 4] Closing connection from 'localhost'.
till@till-x1yoga:~/printing/openprinting/ps-printer-app/x$ D [2020-11-06T17:27:22.538Z] [Job 62] Getting options for num_pages=1, color=true
D [2020-11-06T17:27:22.538Z] [Job 62] print-color-mode=monochrome
D [2020-11-06T17:27:22.538Z] [Job 62] header.cupsWidth=4960
D [2020-11-06T17:27:22.538Z] [Job 62] header.cupsHeight=7015
D [2020-11-06T17:27:22.538Z] [Job 62] header.cupsBitsPerColor=8
D [2020-11-06T17:27:22.538Z] [Job 62] header.cupsBitsPerPixel=8
D [2020-11-06T17:27:22.538Z] [Job 62] header.cupsBytesPerLine=4960
D [2020-11-06T17:27:22.538Z] [Job 62] header.cupsColorOrder=0
D [2020-11-06T17:27:22.538Z] [Job 62] header.cupsColorSpace=18 (sGray)
D [2020-11-06T17:27:22.538Z] [Job 62] header.cupsNumColors=1
D [2020-11-06T17:27:22.538Z] [Job 62] header.HWResolution=[600 600]
D [2020-11-06T17:27:22.538Z] [Job 62] num_pages=1
D [2020-11-06T17:27:22.538Z] [Job 62] copies=1
D [2020-11-06T17:27:22.538Z] [Job 62] finishings=0x0
D [2020-11-06T17:27:22.538Z] [Job 62] media-col.bottom-margin=0
D [2020-11-06T17:27:22.538Z] [Job 62] media-col.left-margin=0
D [2020-11-06T17:27:22.538Z] [Job 62] media-col.right-margin=0
D [2020-11-06T17:27:22.538Z] [Job 62] media-col.size=21000x29700
D [2020-11-06T17:27:22.538Z] [Job 62] media-col.size-name='iso_a4_210x297mm'
D [2020-11-06T17:27:22.538Z] [Job 62] media-col.source='tray-1'
D [2020-11-06T17:27:22.538Z] [Job 62] media-col.top-margin=0
D [2020-11-06T17:27:22.538Z] [Job 62] media-col.type='stationery'
D [2020-11-06T17:27:22.538Z] [Job 62] orientation-requested=none
D [2020-11-06T17:27:22.538Z] [Job 62] page-ranges=1-1
D [2020-11-06T17:27:22.538Z] [Job 62] print-color-mode='monochrome'
D [2020-11-06T17:27:22.538Z] [Job 62] print-content-optimize='photo'
D [2020-11-06T17:27:22.538Z] [Job 62] print-darkness=0
D [2020-11-06T17:27:22.538Z] [Job 62] print-quality=draft
D [2020-11-06T17:27:22.538Z] [Job 62] print-scaling='fill'
D [2020-11-06T17:27:22.538Z] [Job 62] print-speed=0
D [2020-11-06T17:27:22.538Z] [Job 62] printer-resolution=600x600dpi
I [2020-11-06T17:27:22.538Z] [Job 62] Loading 4608x3456x1 JPEG image.
D [2020-11-06T17:27:22.667Z] [Job 62] ileft=0, itop=0, iwidth=4960, iheight=7015
I [2020-11-06T17:27:22.667Z] [Job 62] Auto-orientation: landscape
D [2020-11-06T17:27:22.667Z] [Job 62] xsize=4960, xstart=0, xend=4960, xdir=4608, xmod=3456, xstep=0
D [2020-11-06T17:27:22.667Z] [Job 62] ysize=6613, ystart=201, yend=6814, ydir=-1
D [2020-11-06T17:27:22.968Z] [Job 62] Adding options for finishings
D [2020-11-06T17:27:22.968Z] [Job 62] Adding option: PageSize
D [2020-11-06T17:27:22.968Z] [Job 62] Adding option: InputSlot
D [2020-11-06T17:27:22.968Z] [Job 62] Adding option: MediaType
D [2020-11-06T17:27:22.968Z] [Job 62] Adding option: orientation-requested
D [2020-11-06T17:27:22.968Z] [Job 62] Adding option presets depending on requested print quality
D [2020-11-06T17:27:22.968Z] [Job 62] Adding option: print-scaling
D [2020-11-06T17:27:22.968Z] [Job 62] Adding option: Resolution
D [2020-11-06T17:27:22.968Z] [Job 62] Adding option: Duplex
D [2020-11-06T17:27:22.968Z] [Job 62] Adding option: OutputBin
D [2020-11-06T17:27:22.968Z] [Job 62] PPD options to be used: Duplex=None InputSlot=Tray1 MediaType=Plain orientation-requested=3 page-ranges=1-1 PageSize=A4.FullBleed print-scaling=fill Resolution=600dpi
I [2020-11-06T17:27:22.969Z] [Job 62] filterPOpen: Filter function (PID 248893) started.
I [2020-11-06T17:27:23.301Z] Saving system state to '/tmp/ps_printer_app.state'.
D [2020-11-06T17:27:49.533Z] [Job 62] filterPOpen: Filter function completed with status 0.
D [2020-11-06T17:27:49.535Z] [Job 62] filterPClose: Filter function (PID 248893) exited with no errors.
I [2020-11-06T17:27:49.536Z] [Job 62] Completed, job-impressions-completed=1.
D [2020-11-06T17:27:49.537Z] [Job 62] Device read metrics: 0 requests, 0 bytes, 0 msecs
D [2020-11-06T17:27:49.537Z] [Job 62] Device write metrics: 0 requests, 0 bytes, 0 msecs

Note that I am using the patch of issue #61 to be able to print the image at all.

To Reproduce Print an image to a Printer Application, with either "print-scaling=fill" set as printer default in the web interface or printing the job with the -o print-scaling=fill command line options. The image comes out with white on two borders (as in "auto" mode) and in the debug log it is also shown that "print-scaling=auto" is used.

System Information:

tillkamppeter commented 3 years ago

It looks like that you are mis-interpreting "print-scaling=fill" here. The difference you make between "auto" and "fill" is only whether to take into account or ignore unprintable margins. Here is the code in the papplJobFilterImage() function:

  if (options->print_scaling == PAPPL_SCALING_FILL)
  {
    // Scale to fill the entire media area...
    ileft   = 0;
    itop    = 0;
    iwidth  = options->header.cupsWidth;
    iheight = options->header.cupsHeight;
  }
  else
  {
    // Scale/center within the margins...
    ileft   = (unsigned)(options->media.left_margin * options->printer_resolution[0] / 2540);
    itop    = (unsigned)(options->media.top_margin * options->printer_resolution[1] / 2540);
    iwidth  = options->header.cupsWidth - (unsigned)((options->media.left_margin + options->media.right_margin) * options->printer_resolution[0] / 2540);
    iheight = options->header.cupsHeight - (unsigned)((options->media.bottom_margin + options->media.top_margin) * options->printer_resolution[1] / 2540);
  }

As I am using "A4.FullBleed" as paper size (zero margins) the effect of "auto" and "fill" got identical and so I assumed that the setting just did not arrive at this point. The actual meaning of "fill" is blowing up the image so much that there are no blank margins any more, allowing for cropping of parts of the image when the aspect ratio of image and media mis-match. My image has 4:3 aspect ratio and A4 paper has 1.41:1. To fill this paper one has to stretch the long edge of the image to the long edge of the paper and the short edge gets too long for the paper so some of the image gets cut off.

tillkamppeter commented 3 years ago

This patch solves the problem, implementing "print-scaling=fill" correctly (note that it also contains the fix of issue #61):

diff --git a/pappl/job-filter.c b/pappl/job-filter.c
index e1524ec..8e7f68f 100644
--- a/pappl/job-filter.c
+++ b/pappl/job-filter.c
@@ -104,22 +104,11 @@ papplJobFilterImage(
   // Images contain a single page/impression...
   papplJobSetImpressions(job, 1);

-  if (options->print_scaling == PAPPL_SCALING_FILL)
-  {
-    // Scale to fill the entire media area...
-    ileft   = 0;
-    itop    = 0;
-    iwidth  = options->header.cupsWidth;
-    iheight = options->header.cupsHeight;
-  }
-  else
-  {
-    // Scale/center within the margins...
-    ileft   = (unsigned)(options->media.left_margin * options->printer_resolution[0] / 2540);
-    itop    = (unsigned)(options->media.top_margin * options->printer_resolution[1] / 2540);
-    iwidth  = options->header.cupsWidth - (unsigned)((options->media.left_margin + options->media.right_margin) * options->printer_resolution[0] / 2540);
-    iheight = options->header.cupsHeight - (unsigned)((options->media.bottom_margin + options->media.top_margin) * options->printer_resolution[1] / 2540);
-  }
+  // Scale/center within the margins...
+  ileft   = (unsigned)(options->media.left_margin * options->printer_resolution[0] / 2540);
+  itop    = (unsigned)(options->media.top_margin * options->printer_resolution[1] / 2540);
+  iwidth  = options->header.cupsWidth - (unsigned)((options->media.left_margin + options->media.right_margin) * options->printer_resolution[0] / 2540);
+  iheight = options->header.cupsHeight - (unsigned)((options->media.bottom_margin + options->media.top_margin) * options->printer_resolution[1] / 2540);

   papplLogJob(job, PAPPL_LOGLEVEL_DEBUG, "ileft=%u, itop=%u, iwidth=%u, iheight=%u", ileft, itop, iwidth, iheight);

@@ -156,7 +145,7 @@ papplJobFilterImage(

    xsize = iwidth;
    ysize = xsize * height / width;
-   if (ysize > iheight)
+   if ((options->print_scaling != PAPPL_SCALING_FILL && ysize > iheight) || (options->print_scaling == PAPPL_SCALING_FILL && ysize < iheight))
    {
      ysize = iheight;
      xsize = ysize * width / height;
@@ -172,7 +161,7 @@ papplJobFilterImage(

    xsize = iwidth;
    ysize = xsize * height / width;
-   if (ysize > iheight)
+   if ((options->print_scaling != PAPPL_SCALING_FILL && ysize > iheight) || (options->print_scaling == PAPPL_SCALING_FILL && ysize < iheight))
    {
      ysize = iheight;
      xsize = ysize * width / height;
@@ -180,7 +169,7 @@ papplJobFilterImage(
    break;

     case IPP_ORIENT_LANDSCAPE : // 90 counter-clockwise
-        pixbase    = pixels + width - depth;
+        pixbase    = pixels + width * depth - depth;
         img_width  = height;
         img_height = width;
         xdir       = (int)depth * (int)width;
@@ -188,7 +177,7 @@ papplJobFilterImage(

    xsize = iwidth;
    ysize = xsize * width / height;
-   if (ysize > iheight)
+   if ((options->print_scaling != PAPPL_SCALING_FILL && ysize > iheight) || (options->print_scaling == PAPPL_SCALING_FILL && ysize < iheight))
    {
      ysize = iheight;
      xsize = ysize * height / width;
@@ -204,7 +193,7 @@ papplJobFilterImage(

    xsize = iwidth;
    ysize = xsize * width / height;
-   if (ysize > iheight)
+   if ((options->print_scaling != PAPPL_SCALING_FILL && ysize > iheight) || (options->print_scaling == PAPPL_SCALING_FILL && ysize < iheight))
    {
      ysize = iheight;
      xsize = ysize * height / width;
@@ -214,10 +203,33 @@ papplJobFilterImage(

   options->orientation_requested = IPP_ORIENT_PORTRAIT; // Don't rotate in the driver

-  xstart = ileft + (iwidth - xsize) / 2;
-  xend   = xstart + xsize;
-  ystart = itop + (iheight - ysize) / 2;
-  yend   = ystart + ysize;
+  if (xsize <= iwidth)
+  {
+    xstart = ileft + (iwidth - xsize) / 2;
+    xend   = xstart + xsize;
+  }
+  else
+  {
+    xstart = ileft;
+    xend   = ileft + iwidth;
+    xsize  = iwidth;
+    pixbase = pixbase + xdir * (int)((img_width - img_height * iwidth / iheight) / 2);
+    img_width = img_height * iwidth / iheight;
+  }
+
+  if (ysize <= iheight)
+  {
+    ystart = itop + (iheight - ysize) / 2;
+    yend   = ystart + ysize;
+  }
+  else
+  {
+    ystart = itop;
+    yend   = itop + iheight;
+    ysize  = iheight;
+    pixbase = pixbase + ydir * (int)((img_height - img_width * iheight / iwidth) / 2);
+    img_height = img_width * iheight / iwidth;
+  }

   xmod   = (int)(img_width % xsize);
   xstep  = (int)(img_width / xsize) * xdir;
tillkamppeter commented 3 years ago

Note that I only tested "print-scaling=fill" and "print-scaling=auto". There are also the "auto-fit", "fit", and "none". They all should do the "right thing", taking into account that an image is only a grid of pixels without having an absolute size.

tillkamppeter commented 3 years ago

Looking at the 5 settings of "print-scaling" as you have described them very well here you implemented only "fit", once taking into account unprintable borders, once not. My fix adds support for "fill", but taking into account unprintable borders and when a borderless paper size/the "borderless" tick mark under "Media" is selected the entire page is filled with the image, otherwise the complete printable area is filled with the image. I do not know whether it makes sense to support "none" as images do not have an absolute size, they are simply a grid of pixels. One could perhaps use the PPI in the images metadata or the resolution of the printer, I do not know what the IPP standard tells here.

tillkamppeter commented 3 years ago

You would need to leave out the first hunk of my patch to get "fill" work exactly as you have described.

tillkamppeter commented 3 years ago

Like this:

diff --git a/pappl/job-filter.c b/pappl/job-filter.c
index e1524ec..8cbe272 100644
--- a/pappl/job-filter.c
+++ b/pappl/job-filter.c
@@ -156,7 +156,7 @@ papplJobFilterImage(

    xsize = iwidth;
    ysize = xsize * height / width;
-   if (ysize > iheight)
+   if ((options->print_scaling != PAPPL_SCALING_FILL && ysize > iheight) || (options->print_scaling == PAPPL_SCALING_FILL && ysize < iheight))
    {
      ysize = iheight;
      xsize = ysize * width / height;
@@ -172,7 +172,7 @@ papplJobFilterImage(

    xsize = iwidth;
    ysize = xsize * height / width;
-   if (ysize > iheight)
+   if ((options->print_scaling != PAPPL_SCALING_FILL && ysize > iheight) || (options->print_scaling == PAPPL_SCALING_FILL && ysize < iheight))
    {
      ysize = iheight;
      xsize = ysize * width / height;
@@ -180,7 +180,7 @@ papplJobFilterImage(
    break;

     case IPP_ORIENT_LANDSCAPE : // 90 counter-clockwise
-        pixbase    = pixels + width - depth;
+        pixbase    = pixels + width * depth - depth;
         img_width  = height;
         img_height = width;
         xdir       = (int)depth * (int)width;
@@ -188,7 +188,7 @@ papplJobFilterImage(

    xsize = iwidth;
    ysize = xsize * width / height;
-   if (ysize > iheight)
+   if ((options->print_scaling != PAPPL_SCALING_FILL && ysize > iheight) || (options->print_scaling == PAPPL_SCALING_FILL && ysize < iheight))
    {
      ysize = iheight;
      xsize = ysize * height / width;
@@ -204,7 +204,7 @@ papplJobFilterImage(

    xsize = iwidth;
    ysize = xsize * width / height;
-   if (ysize > iheight)
+   if ((options->print_scaling != PAPPL_SCALING_FILL && ysize > iheight) || (options->print_scaling == PAPPL_SCALING_FILL && ysize < iheight))
    {
      ysize = iheight;
      xsize = ysize * height / width;
@@ -214,10 +214,33 @@ papplJobFilterImage(

   options->orientation_requested = IPP_ORIENT_PORTRAIT; // Don't rotate in the driver

-  xstart = ileft + (iwidth - xsize) / 2;
-  xend   = xstart + xsize;
-  ystart = itop + (iheight - ysize) / 2;
-  yend   = ystart + ysize;
+  if (xsize <= iwidth)
+  {
+    xstart = ileft + (iwidth - xsize) / 2;
+    xend   = xstart + xsize;
+  }
+  else
+  {
+    xstart = ileft;
+    xend   = ileft + iwidth;
+    xsize  = iwidth;
+    pixbase = pixbase + xdir * (int)((img_width - img_height * iwidth / iheight) / 2);
+    img_width = img_height * iwidth / iheight;
+  }
+
+  if (ysize <= iheight)
+  {
+    ystart = itop + (iheight - ysize) / 2;
+    yend   = ystart + ysize;
+  }
+  else
+  {
+    ystart = itop;
+    yend   = itop + iheight;
+    ysize  = iheight;
+    pixbase = pixbase + ydir * (int)((img_height - img_width * iheight / iwidth) / 2);
+    img_height = img_width * iheight / iwidth;
+  }

   xmod   = (int)(img_width % xsize);
   xstep  = (int)(img_width / xsize) * xdir;
tillkamppeter commented 3 years ago

Updated patch to apply to the current state of the code:

diff --git a/pappl/job-filter.c b/pappl/job-filter.c
index ad72ad4..311aa19 100644
--- a/pappl/job-filter.c
+++ b/pappl/job-filter.c
@@ -156,7 +156,7 @@ papplJobFilterImage(

    xsize = iwidth;
    ysize = xsize * height / width;
-   if (ysize > iheight)
+   if ((options->print_scaling != PAPPL_SCALING_FILL && ysize > iheight) || (options->print_scaling == PAPPL_SCALING_FILL && ysize < iheight))
    {
      ysize = iheight;
      xsize = ysize * width / height;
@@ -172,7 +172,7 @@ papplJobFilterImage(

    xsize = iwidth;
    ysize = xsize * height / width;
-   if (ysize > iheight)
+   if ((options->print_scaling != PAPPL_SCALING_FILL && ysize > iheight) || (options->print_scaling == PAPPL_SCALING_FILL && ysize < iheight))
    {
      ysize = iheight;
      xsize = ysize * width / height;
@@ -188,7 +188,7 @@ papplJobFilterImage(

    xsize = iwidth;
    ysize = xsize * width / height;
-   if (ysize > iheight)
+   if ((options->print_scaling != PAPPL_SCALING_FILL && ysize > iheight) || (options->print_scaling == PAPPL_SCALING_FILL && ysize < iheight))
    {
      ysize = iheight;
      xsize = ysize * height / width;
@@ -204,7 +204,7 @@ papplJobFilterImage(

    xsize = iwidth;
    ysize = xsize * width / height;
-   if (ysize > iheight)
+   if ((options->print_scaling != PAPPL_SCALING_FILL && ysize > iheight) || (options->print_scaling == PAPPL_SCALING_FILL && ysize < iheight))
    {
      ysize = iheight;
      xsize = ysize * height / width;
@@ -218,6 +218,33 @@ papplJobFilterImage(
   xend   = xstart + xsize;
   ystart = itop + (iheight - ysize) / 2;
   yend   = ystart + ysize;
+  if (xsize <= iwidth)
+  {
+    xstart = ileft + (iwidth - xsize) / 2;
+    xend   = xstart + xsize;
+  }
+  else
+  {
+    xstart = ileft;
+    xend   = ileft + iwidth;
+    xsize  = iwidth;
+    pixbase = pixbase + xdir * (int)((img_width - img_height * iwidth / iheight) / 2);
+    img_width = img_height * iwidth / iheight;
+  }
+
+  if (ysize <= iheight)
+  {
+    ystart = itop + (iheight - ysize) / 2;
+    yend   = ystart + ysize;
+  }
+  else
+  {
+    ystart = itop;
+    yend   = itop + iheight;
+    ysize  = iheight;
+    pixbase = pixbase + ydir * (int)((img_height - img_width * iheight / iwidth) / 2);
+    img_height = img_width * iheight / iwidth;
+  }

   xmod   = (int)(img_width % xsize);
   xstep  = (int)(img_width / xsize) * xdir;
michaelrsweet commented 3 years ago

Initial changes are in:

[master 8bafd72] Fix implementation of print-scaling for images, which involved a change to the papplJobFilterImage API to add the image resolution (Issue #62)

@tillkamppeter I wasn't able to use your changes as they didn't cover the full range of scenarios we might see, which required a change to the API (to pass in the image resolution). I will be (shortly) adding some test images that will be used as part of a unit test framework to verify proper scaling, positioning, and orientation.

tillkamppeter commented 3 years ago

I have tested your changes printing photos in "fill" and "fit" mode, both portrait and landscape and it works correctly.

tillkamppeter commented 3 years ago

Sorry, had to repeat the test. The images are correctly calculated and printed, for all 4 cases ("fill"/"fit" and portrait/landscape), but on the printouts with "fill" the Printer Application crashes after printing, with free(): invalid size.

Here is the debug log for a portrait image with "fill":

I [2020-11-10T22:03:30.966Z] [Job 88] Starting print job.
I [2020-11-10T22:03:30.966Z] [Client 1] OK application/ipp 223
D [2020-11-10T22:03:30.966Z] [Client 1] Print-Job response: IPP/2.0 request-id=2, status-code=successful-ok
D [2020-11-10T22:03:30.966Z] [Client 1] Print-Job response: operation-attributes-tag
D [2020-11-10T22:03:30.966Z] [Client 1] Print-Job response:   attributes-charset charset utf-8
D [2020-11-10T22:03:30.966Z] [Client 1] Print-Job response:   attributes-natural-language naturalLanguage en-us
D [2020-11-10T22:03:30.966Z] [Client 1] Print-Job response: job-attributes-tag
D [2020-11-10T22:03:30.966Z] [Client 1] Print-Job response:   job-id integer 88
D [2020-11-10T22:03:30.966Z] [Client 1] Print-Job response:   job-uri uri ipp://localhost/ipp/print/test/88
D [2020-11-10T22:03:30.966Z] [Client 1] Print-Job response:   job-state enum processing
D [2020-11-10T22:03:30.966Z] [Client 1] Print-Job response:   job-state-message textWithoutLanguage Job printing.
D [2020-11-10T22:03:30.966Z] [Client 1] Print-Job response:   job-state-reasons keyword job-printing
test-88
I [2020-11-10T22:03:30.966Z] [Client 1] Closing connection from 'localhost'.
D [2020-11-10T22:03:31.074Z] [Job 88] Getting options for num_pages=1, color=true
D [2020-11-10T22:03:31.075Z] [Job 88] print-color-mode=monochrome
D [2020-11-10T22:03:31.075Z] [Job 88] header.cupsWidth=4960
D [2020-11-10T22:03:31.075Z] [Job 88] header.cupsHeight=7015
D [2020-11-10T22:03:31.075Z] [Job 88] header.cupsBitsPerColor=8
D [2020-11-10T22:03:31.075Z] [Job 88] header.cupsBitsPerPixel=8
D [2020-11-10T22:03:31.075Z] [Job 88] header.cupsBytesPerLine=4960
D [2020-11-10T22:03:31.075Z] [Job 88] header.cupsColorOrder=0
D [2020-11-10T22:03:31.075Z] [Job 88] header.cupsColorSpace=18 (sGray)
D [2020-11-10T22:03:31.075Z] [Job 88] header.cupsNumColors=1
D [2020-11-10T22:03:31.075Z] [Job 88] header.HWResolution=[600 600]
D [2020-11-10T22:03:31.075Z] [Job 88] num_pages=1
D [2020-11-10T22:03:31.075Z] [Job 88] copies=1
D [2020-11-10T22:03:31.075Z] [Job 88] finishings=0x0
D [2020-11-10T22:03:31.075Z] [Job 88] media-col.bottom-margin=0
D [2020-11-10T22:03:31.075Z] [Job 88] media-col.left-margin=0
D [2020-11-10T22:03:31.075Z] [Job 88] media-col.right-margin=0
D [2020-11-10T22:03:31.075Z] [Job 88] media-col.size=21000x29700
D [2020-11-10T22:03:31.075Z] [Job 88] media-col.size-name='iso_a4_210x297mm'
D [2020-11-10T22:03:31.075Z] [Job 88] media-col.source='tray-1'
D [2020-11-10T22:03:31.075Z] [Job 88] media-col.top-margin=0
D [2020-11-10T22:03:31.075Z] [Job 88] media-col.type='stationery'
D [2020-11-10T22:03:31.075Z] [Job 88] orientation-requested=none
D [2020-11-10T22:03:31.075Z] [Job 88] page-ranges=1-1
D [2020-11-10T22:03:31.075Z] [Job 88] print-color-mode='monochrome'
D [2020-11-10T22:03:31.075Z] [Job 88] print-content-optimize='photo'
D [2020-11-10T22:03:31.075Z] [Job 88] print-darkness=0
D [2020-11-10T22:03:31.075Z] [Job 88] print-quality=draft
D [2020-11-10T22:03:31.075Z] [Job 88] print-scaling='fill'
D [2020-11-10T22:03:31.075Z] [Job 88] print-speed=0
D [2020-11-10T22:03:31.075Z] [Job 88] printer-resolution=600x600dpi
I [2020-11-10T22:03:31.075Z] [Job 88] Loading 3888x5184x1 JPEG image.
D [2020-11-10T22:03:31.214Z] [Job 88] ileft=0, itop=0, iwidth=4960, iheight=7015
I [2020-11-10T22:03:31.214Z] [Job 88] Auto-orientation: portrait
D [2020-11-10T22:03:31.214Z] [Job 88] xsize=5261, xstart=-150, xend=5111, xdir=1, xmod=3888, xstep=0
D [2020-11-10T22:03:31.214Z] [Job 88] ysize=7015, ystart=0, yend=7015, ydir=3888
D [2020-11-10T22:03:31.525Z] [Job 88] Adding options for finishings
D [2020-11-10T22:03:31.525Z] [Job 88] Adding option: PageSize
D [2020-11-10T22:03:31.525Z] [Job 88] Adding option: InputSlot
D [2020-11-10T22:03:31.525Z] [Job 88] Adding option: MediaType
D [2020-11-10T22:03:31.525Z] [Job 88] Adding option: orientation-requested
D [2020-11-10T22:03:31.525Z] [Job 88] Adding option presets depending on requested print quality
D [2020-11-10T22:03:31.525Z] [Job 88] Adding option: print-scaling
D [2020-11-10T22:03:31.525Z] [Job 88] Adding option: Resolution
D [2020-11-10T22:03:31.525Z] [Job 88] Adding option: Duplex
D [2020-11-10T22:03:31.525Z] [Job 88] PPD options to be used: ColorModel=Gray Duplex=None InputSlot=Tray1 MediaType=Plain orientation-requested=3 page-ranges=1-1 PageSize=A4.FullBleed print-scaling=fill Resolution=600dpi
I [2020-11-10T22:03:31.525Z] [Job 88] filterPOpen: Filter function (PID 450904) started.
D [2020-11-10T22:03:31.525Z] [Job 88] Monochrome draft quality job -> 1-bit dithering for speed-up
D [2020-11-10T22:03:31.525Z] [Job 88] Photo/Image-optimized dither matrix
D [2020-11-10T22:03:31.526Z] [Job 88] Monochrome draft quality job -> 1-bit dithering for speed-up
D [2020-11-10T22:03:31.526Z] [Job 88] Photo/Image-optimized dither matrix
I [2020-11-10T22:03:31.947Z] Saving system state to '/tmp/ps_printer_app.state'.
D [2020-11-10T22:03:34.522Z] [Job 88] filterPOpen: Filter function completed with status 0.
D [2020-11-10T22:03:34.524Z] [Job 88] filterPClose: Filter function (PID 450904) exited with no errors.
free(): invalid size

[4]+  Done                    PPD_PATHS=/home/till/printing/openprinting/cups-filters/x/ppdfiles ./ps-printer-app -o log-level=debug server 2>&1 | tee z
tillkamppeter commented 3 years ago

"fill" with a landscape image gives double free or corruption (out):

I [2020-11-10T22:20:32.957Z] [Job 89] Starting print job.
D [2020-11-10T22:20:32.957Z] [Client 1] Print-Job response: IPP/2.0 request-id=2, status-code=successful-ok
D [2020-11-10T22:20:32.957Z] [Client 1] Print-Job response: operation-attributes-tag
D [2020-11-10T22:20:32.957Z] [Client 1] Print-Job response:   attributes-charset charset utf-8
D [2020-11-10T22:20:32.957Z] [Client 1] Print-Job response:   attributes-natural-language naturalLanguage en-us
D [2020-11-10T22:20:32.957Z] [Client 1] Print-Job response: job-attributes-tag
D [2020-11-10T22:20:32.957Z] [Client 1] Print-Job response:   job-id integer 89
D [2020-11-10T22:20:32.957Z] [Client 1] Print-Job response:   job-uri uri ipp://localhost/ipp/print/test/89
D [2020-11-10T22:20:32.957Z] [Client 1] Print-Job response:   job-state enum pending
D [2020-11-10T22:20:32.957Z] [Client 1] Print-Job response:   job-state-message textWithoutLanguage Job pending.
D [2020-11-10T22:20:32.957Z] [Client 1] Print-Job response:   job-state-reasons keyword none
test-89
I [2020-11-10T22:20:32.957Z] [Client 1] Closing connection from 'localhost'.
till@till-x1yoga:~/printing/openprinting/ps-printer-app/x$ D [2020-11-10T22:20:33.099Z] [Job 89] Getting options for num_pages=1, color=true
D [2020-11-10T22:20:33.099Z] [Job 89] print-color-mode=monochrome
D [2020-11-10T22:20:33.099Z] [Job 89] header.cupsWidth=4960
D [2020-11-10T22:20:33.099Z] [Job 89] header.cupsHeight=7015
D [2020-11-10T22:20:33.099Z] [Job 89] header.cupsBitsPerColor=8
D [2020-11-10T22:20:33.099Z] [Job 89] header.cupsBitsPerPixel=8
D [2020-11-10T22:20:33.099Z] [Job 89] header.cupsBytesPerLine=4960
D [2020-11-10T22:20:33.099Z] [Job 89] header.cupsColorOrder=0
D [2020-11-10T22:20:33.099Z] [Job 89] header.cupsColorSpace=18 (sGray)
D [2020-11-10T22:20:33.099Z] [Job 89] header.cupsNumColors=1
D [2020-11-10T22:20:33.099Z] [Job 89] header.HWResolution=[600 600]
D [2020-11-10T22:20:33.099Z] [Job 89] num_pages=1
D [2020-11-10T22:20:33.099Z] [Job 89] copies=1
D [2020-11-10T22:20:33.099Z] [Job 89] finishings=0x0
D [2020-11-10T22:20:33.099Z] [Job 89] media-col.bottom-margin=0
D [2020-11-10T22:20:33.099Z] [Job 89] media-col.left-margin=0
D [2020-11-10T22:20:33.099Z] [Job 89] media-col.right-margin=0
D [2020-11-10T22:20:33.099Z] [Job 89] media-col.size=21000x29700
D [2020-11-10T22:20:33.099Z] [Job 89] media-col.size-name='iso_a4_210x297mm'
D [2020-11-10T22:20:33.099Z] [Job 89] media-col.source='tray-1'
D [2020-11-10T22:20:33.099Z] [Job 89] media-col.top-margin=0
D [2020-11-10T22:20:33.099Z] [Job 89] media-col.type='stationery'
D [2020-11-10T22:20:33.099Z] [Job 89] orientation-requested=none
D [2020-11-10T22:20:33.099Z] [Job 89] page-ranges=1-1
D [2020-11-10T22:20:33.099Z] [Job 89] print-color-mode='monochrome'
D [2020-11-10T22:20:33.099Z] [Job 89] print-content-optimize='photo'
D [2020-11-10T22:20:33.099Z] [Job 89] print-darkness=0
D [2020-11-10T22:20:33.099Z] [Job 89] print-quality=draft
D [2020-11-10T22:20:33.099Z] [Job 89] print-scaling='fill'
D [2020-11-10T22:20:33.099Z] [Job 89] print-speed=0
D [2020-11-10T22:20:33.099Z] [Job 89] printer-resolution=600x600dpi
I [2020-11-10T22:20:33.099Z] [Job 89] Loading 4608x3456x1 JPEG image.
D [2020-11-10T22:20:33.228Z] [Job 89] ileft=0, itop=0, iwidth=4960, iheight=7015
I [2020-11-10T22:20:33.228Z] [Job 89] Auto-orientation: landscape
D [2020-11-10T22:20:33.228Z] [Job 89] xsize=5261, xstart=-150, xend=5111, xdir=4608, xmod=3456, xstep=0
D [2020-11-10T22:20:33.228Z] [Job 89] ysize=7015, ystart=0, yend=7015, ydir=-1
D [2020-11-10T22:20:33.536Z] [Job 89] Adding options for finishings
D [2020-11-10T22:20:33.536Z] [Job 89] Adding option: PageSize
D [2020-11-10T22:20:33.536Z] [Job 89] Adding option: InputSlot
D [2020-11-10T22:20:33.536Z] [Job 89] Adding option: MediaType
D [2020-11-10T22:20:33.536Z] [Job 89] Adding option: orientation-requested
D [2020-11-10T22:20:33.536Z] [Job 89] Adding option presets depending on requested print quality
D [2020-11-10T22:20:33.536Z] [Job 89] Adding option: print-scaling
D [2020-11-10T22:20:33.536Z] [Job 89] Adding option: Resolution
D [2020-11-10T22:20:33.536Z] [Job 89] Adding option: Duplex
D [2020-11-10T22:20:33.536Z] [Job 89] PPD options to be used: ColorModel=Gray Duplex=None InputSlot=Tray1 MediaType=Plain orientation-requested=3 page-ranges=1-1 PageSize=A4.FullBleed print-scaling=fill Resolution=600dpi
I [2020-11-10T22:20:33.536Z] [Job 89] filterPOpen: Filter function (PID 451291) started.
D [2020-11-10T22:20:33.536Z] [Job 89] Monochrome draft quality job -> 1-bit dithering for speed-up
D [2020-11-10T22:20:33.536Z] [Job 89] Photo/Image-optimized dither matrix
D [2020-11-10T22:20:33.536Z] [Job 89] Monochrome draft quality job -> 1-bit dithering for speed-up
D [2020-11-10T22:20:33.536Z] [Job 89] Photo/Image-optimized dither matrix
I [2020-11-10T22:20:33.939Z] Saving system state to '/tmp/ps_printer_app.state'.
D [2020-11-10T22:20:38.034Z] [Job 89] filterPOpen: Filter function completed with status 0.
D [2020-11-10T22:20:38.035Z] [Job 89] filterPClose: Filter function (PID 451291) exited with no errors.
double free or corruption (out)
tillkamppeter commented 3 years ago

Thank you very much! I did several tests with "fill", "fit", and "none" printing landscape and portrait photos in draft/gray (which auto-switches to 1-bit dithering in the PS Printer Application) and regular color, all images get printed correctly and the Printer Application keeps running.

michaelrsweet commented 3 years ago

@tillkamppeter Yes, I'm now running a full set of tests and have an unrelated failure (not in this code, but in the find-printer code) that I am tracking down. Since the image stuff seems to be resolved, however, I'll go ahead and close this bug...