Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect documentation for pixmap.tint_with #2179

Closed
arun-mani-j opened this issue Jan 18, 2023 · 4 comments
Closed

Incorrect documentation for pixmap.tint_with #2179

arun-mani-j opened this issue Jan 18, 2023 · 4 comments
Assignees

Comments

@arun-mani-j
Copy link
Contributor

Describe the bug (mandatory)

The documentation of pixmap.tint_with at https://pymupdf.readthedocs.io/en/latest/pixmap.html#Pixmap.tint_with has different parameters. Calling it with the three values, like pixmap.tint_with(100, 100, 100) causes this error:

TypeError: Pixmap.tint_with() takes 3 positional arguments but 4 were given

Using help(pixmap.tint_with) gives a different docstring.

Signature: px.tint_with(black, white)
Docstring: Tint colors with modifiers for black and white.
File:      ~/Projects/web/lib/python3.10/site-packages/fitz/fitz.py
Type:      method

To Reproduce (mandatory)

  1. Obtain a Pixmap for a page.
  2. Call pixmap.tint_with with three integers.
  3. Error occurs.

Expected behavior (optional)

Expected no error to occur.

Your configuration (mandatory)

3.10.9 (main, Dec  7 2022, 13:47:07) [GCC 12.2.0] linux 
PyMuPDF 1.21.1: Python bindings for the MuPDF 1.21.1 library.
Version date: 2022-12-13 00:00:01.
Built for Python 3.10 on linux (64-bit).

Installed via pip install PyMuPDF.

Additional context (optional)

The corresponding documentation file is https://github.com/pymupdf/PyMuPDF/blob/master/docs/pixmap.rst.
I can create a PR for the fix, but I don't know what tint_with does 😅 I found that method while searching for a way to colorize a PDF page like turning background to slight orange for better readability at night time.

@JorjMcKie
Copy link
Collaborator

Thanks for spotting this documentation issue!

@arun-mani-j
Copy link
Contributor Author

You are welcome! If possible, please add an example for this method, so that people like me can know what it does 😅 . Please let me know if I can be of any help :)

@JorjMcKie
Copy link
Collaborator

Here is a first impression of what happens. The meaning as per MuPDF documentation is:

black: Map black to this hexadecimal RGB color.
white: Map white to this hexadecimal RGB color.

So best is to specify the two values as integer in hexa notation 0xrrggbb for each, black or white in pix.tint_with(black, white).
So doing pix.tint_with(0x000000, 0xffffff) is a no-op.

  • pix.tint_with(0x00ff00, 0xffffff) changes black to green, white unchanged
  • pix.tint_with(0xff0000, 0x0000ff) changes black to red, white to blue

Here is an impression of a number of effects on an original:
grafik

@arun-mani-j
Copy link
Contributor Author

Thanks for the elaborate explanation! This is exactly the method I have been looking for ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants