Boomaga / boomaga

Boomaga provides a virtual printer for CUPS. This can be used for print preview or for print booklets.
Other
181 stars 34 forks source link

Add grayscale printing option #39

Closed carsonip closed 7 years ago

carsonip commented 7 years ago

Add grayscale option by converting input file to grayscale using ghostscript right before feeding into boomagamerger. It seem to work well for most cases.

Possible problems:

Side note: I tried to put the conversion at the constructor of TmpPdfFile but it does not work. Diffing the outputs shows the wrong references in XObject e.g. Im0. This is due to TmpPdfFile::writeSheets() called by TmpPdfFile::updateSheets() inside Project::update().

This commit may cause problems. Codes for the new feature may not be added at the best places. Please advise.

Resolves: #36

carsonip commented 7 years ago

The conversion is still pretty slow though. Is it possible to move the grayscale conversion step to the last (after merging and writeSheets)? If not, maybe we'll have to add some optimization in the input step (e.g. caching grayscale input instead of generating every time a tmp pdf is generated). Please advise.

SokoloffA commented 7 years ago

Good solution!

Translation files

No problem. I'll update the translation files before the release.

"Converted input file does not take care of endPos of InputFile"

This problem can be solved so: gs is able to read from STDIN, followed command works fine

cat color.pdf | gs -sDEVICE=pdfwrite -sProcessColorModel=DeviceGray -sColorConversionStrategy=Gray -o gray.pdf -f - So boomags can read part of file from startPos to endPos and send data to the gs via STDIN.

A few more comments.

  1. I found a bug, see my comment in the code.
  2. Checkbox "GrayScale" will be better to move from "Layout" group to "Printer" group. Or another option add it to printer settings.
  3. The conversion to grayscale may take a long time. We can speed up if run gs processes for every file in the parallel.
SokoloffA commented 7 years ago

I created "grayscale" branch. I wrote a multithreaded converter, but it's slow an ugly. I'll work on it.

carsonip commented 7 years ago

Sorry I was too busy in the last few weeks and forgot to reply. For comment 2, I am a FinePrint user, I feel like the placement of "Grayscale" checkbox is reasonable in their UI. Look at this screenshot.

I can continue to work on the branch after a week. Many thanks!

SokoloffA commented 7 years ago

This solution is too slow. The following command is run more than three minutes for the PDF specification file (1310 pages).

time gs -sDEVICE=pdfwrite -sProcessColorModel=DeviceGray -sColorConversionStrategy=Gray  -o PDF_gray.pdf -f PDF_Spec-1.7.pdf 

Maybe we should use fake grayscale? The temporary file is color, but we convert image to grayscale on preview. Et and we run gs when the user presses the print button.

These solution have pros and cons:

What you think?

carsonip commented 7 years ago

Sounds good to me. Fake it during preview is the way to go, considering the UX. The time required for conversion is reasonable given that it is a 1300-page document.

SokoloffA commented 7 years ago

I found another solution, for my "HP Color LaserJet Pro MFP M476" following line print as grayscale:

lpr -P ASU -o HPColorAsGray=True color.pdf 

We can add options when sending job to real printer.

What printer you are use? Is it has "Prian as grayscale" or something like in the GUI configuration? If yes try following:

  1. Copy ppd file for your hardware printer from /etc/cups/ppd directory to somewhere as color.ppd.
  2. In the GUI config change settings to grayscale and test that printer really priny in the grayscale.
  3. Copy ppd as gray.ppd
  4. Compare these ppd-files with diff and send them to me.
carsonip commented 7 years ago

This is also a neat way. I use Brother MFC-J615W at home. It has the grayscale option in the printing GUI. The diff is as follows:

197c197
< *DefaultBRMonoColor: Color
---
> *DefaultBRMonoColor: Mono

The original ppd file is here.

SokoloffA commented 7 years ago

Please try

lpr -P ASU -o BRMonoColor=Mono color.pdf

Please note, you must use the parameter without the Default prefix.

P.S. I have New Year vacation, so I can continue to work after 8 january.

carsonip commented 7 years ago

Yes it works well.

carsonip commented 7 years ago

In PWG PPD mapping API implementation for CUPS, I find this code. Hopefully this makes it easier for us to develop our version of mono color printing.

   /*
    * Try adding some common color options to create grayscale presets.  These
    * are listed in order of popularity...
    */

    const char    *color_option = NULL,    /* Color control option */
        *gray_choice = NULL;    /* Choice to select grayscale */

    if ((color_model = ppdFindOption(ppd, "ColorModel")) != NULL &&
        ppdFindChoice(color_model, "Gray"))
    {
      color_option = "ColorModel";
      gray_choice  = "Gray";
    }
    else if ((color_model = ppdFindOption(ppd, "HPColorMode")) != NULL &&
             ppdFindChoice(color_model, "grayscale"))
    {
      color_option = "HPColorMode";
      gray_choice  = "grayscale";
    }
    else if ((color_model = ppdFindOption(ppd, "BRMonoColor")) != NULL &&
             ppdFindChoice(color_model, "Mono"))
    {
      color_option = "BRMonoColor";
      gray_choice  = "Mono";
    }
    else if ((color_model = ppdFindOption(ppd, "CNIJSGrayScale")) != NULL &&
             ppdFindChoice(color_model, "1"))
    {
      color_option = "CNIJSGrayScale";
      gray_choice  = "1";
    }
    else if ((color_model = ppdFindOption(ppd, "HPColorAsGray")) != NULL &&
             ppdFindChoice(color_model, "True"))
    {
      color_option = "HPColorAsGray";
      gray_choice  = "True";
    }
SokoloffA commented 7 years ago

I did support printing in grayscale. Please test it from grayscale branch.

It bothers me that the function ppdFindOption is deprecated. Apple suggest using cupsCopyDestInfo, but I didn't understand how to use it.

carsonip commented 7 years ago

Sorry for the late reply. From what I see, the ppdFindOption is deprecated while the cupsCopyDestInfo is new in CUPS 1.6. Do we have to bump up the required version of CUPS or what?

SokoloffA commented 7 years ago

I don't understand how to use cupsCopyDestInfo. What is http_t *http? Where can I get it? So now I use ppdFindOption.

SokoloffA commented 7 years ago

Because I want to have the maximum space for jobs/booklets lists, and there was a issue to add forced color printing, I removed the checkbox "print in grayscale", and added the "color mode" option to printer profile. You'll can create two profiles and quickly switch between them.

Commit - https://github.com/Boomaga/boomaga/commit/ce9dc7aa808ee5e1bcd5e75e9c8fd5a1d1ed8913