BoboTiG / python-mss

An ultra fast cross-platform multiple screenshots module in pure Python using ctypes.
https://pypi.org/project/mss/
MIT License
987 stars 88 forks source link

How to turn scaling off? Screen grab always has scaling with factor 2 applied #257

Open orange-puff opened 1 year ago

orange-puff commented 1 year ago

General information:

Description

When I run the following code:

import pyautogui
import mss

w, h = pyautogui.size()
with mss.mss() as sct:
    monitor = {"top": 0, "left": 0, "width": w, "height": h}
    mss_image = sct.grab(monitor)
    print(f'({w}, {h}) ({mss_image.width}, {mss_image.height})')

it results in (1440, 900) (2880, 1800)

This interferes with my ability to then use pyautogui to find certain pixels with a given color and click them. Is there a way to turn scaling off in mss, or is this perhaps a macOS issue?

Upvote & Fund

Fund with Polar

BoboTiG commented 1 year ago

It's funny, I was thinking about that exact behavior. I think I will make the auto-scaling an optional feature rather than the default behavior. It will also fix several issues I saw here, and there, like:

I will try something and rely on the CI (and maybe you) for the testing, since I don't own a Mac machine yet.

orange-puff commented 1 year ago

I would be happy to test this. Also, sorry for the off topic question. Is there a link to any documentation of why mss is so fast compared to pillow or pyautogui? It's performing much better on my computer than either of them.

orange-puff commented 1 year ago

I was hoping to test this locally, but the docs look outdated, https://python-mss.readthedocs.io/developers.html python -m pip install -r tests-requirements.txt but this file doesn't seem to exist.

Is there an updated guide for getting things running locally? I am also getting

    from . import __version__
ImportError: attempted relative import with no known parent package

when attempting to run main.py. I've researched this error extensively in other contexts and I cannot find a working solution for it

BoboTiG commented 1 year ago

Thanks for pointing the documentation issue, it's broken since my last commit, and I'll fix it.

To run main:

cd src
python -m mss

You should remove any older MSS installation first:

python -m pip uninstall -y mss

And here is the correct installation command:

python -m pip install -e '.[test]'
orange-puff commented 1 year ago

So I did this, then added

import pyautogui
if __name__ == "__main__":  # pragma: nocover
    w, h = pyautogui.size()
    print(w,h)
    with mss() as sct:
        monitor = {"top": 0, "left": 0, "width": w, "height": h}
        mss_image = sct.grab(monitor)
        print(f'({w}, {h}) ({mss_image.width}, {mss_image.height})')

to src/mss/__main__.py and I get

1440 900
zsh: segmentation fault  python3 -m mss
orange-puff commented 1 year ago

The line that is throwing the exception is; https://github.com/BoboTiG/python-mss/blob/main/src/mss/darwin.py#L181 If I rerun I also get zsh: bus error python3 -m mss zsh: illegal hardware instruction python3 -m mss

Without knowing what the underlying dll looks like, it's not easy to go deeper. But I will try to look at the arg and how the PR might have contributed

BoboTiG commented 1 year ago

Actually the PR isn't working. I quickly tried something, but without a Mac machine it's complex. I will receive a Mac machine by the next week, and will be able to work on it then.