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

Bad multiple screen grab #14

Closed
Archarachne opened this issue Dec 12, 2016 · 22 comments
Closed

Bad multiple screen grab #14

Archarachne opened this issue Dec 12, 2016 · 22 comments

Comments

@Archarachne
Copy link

I'm working on 10.12.1 MacOS Sierra with 2.0.18 mss version and python 3.5. When today I tried to create multiple screenshots using mss according to documentation.
And with two different screens with resolutions
{'height': 1200, 'left': 0, 'top': 0, 'width': 1920}, {'height': 768, 'left': -1366, 'top': 0, 'width': 1366}. The bigger screenshot looks fine but the smaller gives a very bad result: http://imgur.com/a/hKrHw. What is the cause of it?

@BoboTiG BoboTiG added the bug label Dec 12, 2016
@BoboTiG
Copy link
Owner

BoboTiG commented Dec 13, 2016

Woops, weird. Few questions to try to understand, following examples:

  1. If you take the screenshot of all monitors, what is the result?
  2. What is the result if you take one screenshot per monitor?
  3. What is the result if you specify which monitor to capture?

@Archarachne
Copy link
Author

So following the examples:

  1. If both monitors are get a screenshot together the picture looks like the one attached only mixed together.
  2. 3 - the screenshot of the bigger, primary screen is always perfect; the other-smaller gets mixed.

@BoboTiG
Copy link
Owner

BoboTiG commented Dec 15, 2016

If you set the little screen as primary one, same results? How is connected the second screen (nothing special on the set-up part, or something helpful?) ?

@Archarachne
Copy link
Author

It's connected via HDMI and thunderbolt adapter. I'm checking the primary screen right now.

@Archarachne
Copy link
Author

After switching primary setting between the screens the small one (I own 11 inch MacBook Air with 10.12.1 Sierra) always gives a bad picture while the big one is ok (with bigger resolution).

@BoboTiG
Copy link
Owner

BoboTiG commented Dec 20, 2016

OK, you are using a Thunderbolt adaptater, good to know. I will have testing hardware in january, but for now I cannot try something for you :/

@Archarachne
Copy link
Author

Thanks, will be waiting for an update. 👍

The funny thing is that the MacBook air screen has got a problem, not the attached monitor. I would expect otherwise. :)

@BoboTiG
Copy link
Owner

BoboTiG commented Mar 21, 2017

Hello,

Finally, I could get a machine and a Thunderbolt adaptater. But all screenshots are good :/
Do you have a clue, something special in your configuration that could interfer? The monitor state i "normal"?

@vvarp
Copy link

vvarp commented Apr 10, 2017

Got hit by the same issue running on MacBook Air 11" - a machine with fairly uncommon native resolution (1366x768)

Resulting PNG is at correct resolution, however at closer inspection it looks like there's 10 black pixels inserted at the end of each scanline - clearly that's since 1366 is not divisible by 16 (and 1376 is).

I know close to nothing about CoreGraphics internals, so I am really unable to debug it further - any clues would be appreciated!

@BoboTiG
Copy link
Owner

BoboTiG commented Apr 10, 2017

Hello,

That is a good clue, thanks. I will investigate soon.

@DavideBecker
Copy link

DavideBecker commented Apr 16, 2017

I've encountered a similar issue. Most likely related. Using a MacBook Air 13" with a resolution of 1440x900 and no 2nd screen.

sct.get_pixels({'left': 0, 'top': 0, 'width': 1440, 'height': 900})
Works just fine, but when I change it to

sct.get_pixels({'left': 0, 'top': 0, 'width': 1400, 'height': 900})
(Changing the width) I get a very distorted image

http://i.imgur.com/wh85Cbl.png

So after some more experimentation it looks like some sort of rounding issue.

sct.get_pixels({'left': 0, 'top': 0, 'width': 720, 'height': 900})
(Half the width of the full resolution) Also looks totally normal.

sct.get_pixels({'left': 0, 'top': 0, 'width': 360, 'height': 900})
(Fourth of the width) Is distorted again.

Edit: Looks like the problem always occurs when the width is not a multiple of 16

Kudos though, it's still a pretty awesome package

@BoboTiG
Copy link
Owner

BoboTiG commented Apr 20, 2017

@Archarachne, @vvarp and @DavideBecker: Could you try the PIL example? It will help locate the issue.

@DavideBecker
Copy link

Works fine for me, but if I change sct.get_pixels(monitor) to sct.get_pixels({ "top": 200, "left": 200, "width": 200, "height": 200 }) in order to only get part of the screen, the image gets distorted again.

http://i.imgur.com/T58VPKG.png

However, it looks like if the width is a multiple of 16 (e.g. sct.get_pixels(monitor) to sct.get_pixels({ "top": 160, "left": 160, "width": 160, "height": 160 })) everything works like it should.

http://i.imgur.com/hFzWEni.png

@BoboTiG
Copy link
Owner

BoboTiG commented Apr 20, 2017

OK, I added an example to capture a part of the screen. It works well on GNU/Linux, whatever the width.
Can I ask you to try out this code?

@DavideBecker
Copy link

Running exactly that code gives me this image:

http://i.imgur.com/Omvl3QD.png

It looks like this is some odd OSX bug. Really seems like some pixels move to a row where they shouldn't. Either too many or too few.

@BoboTiG
Copy link
Owner

BoboTiG commented Apr 20, 2017

Can you print the detected dimensions to check they are not changed by the OS:

from mss import mss

with mss() as sct:
    mon = {'top': 160, 'left': 160, 'width': 222, 'height': 42}

    # Create the picture
    output = 'sct-{top}x{left}_{width}x{height}.png'.format(**mon)
    sct.to_png(sct.get_pixels(mon), output)
    print(output)

    print('{}x{}'.format(sct.width, sct.height))

@DavideBecker
Copy link

That gives me the expected 222x42

@BoboTiG
Copy link
Owner

BoboTiG commented Apr 20, 2017

Hm, it is a good thing. I will be able to try on a Mac soon. I have in mind an mistake with the bits per pixel value, but I cannot say anything right now.

@DavideBecker
Copy link

DavideBecker commented Apr 20, 2017

I've been playing with various print statements and a buddy of mine stumbled upon this Stackoverflow answer which looks very promising.

The width stays correct the whole time, so the issue is most likely in the last few lines of darwin.py

@BoboTiG
Copy link
Owner

BoboTiG commented Apr 20, 2017

I have time to work on it now. Could you save the content of sct.image to a file and share it with me?

@DavideBecker
Copy link

We've been tinkering a bit and I think we're pretty close to a good solution. I'll polish up the code and submit a pull request.

BoboTiG pushed a commit that referenced this issue Apr 22, 2017
…ot divisible by 16 (fixes #14)



* Fixed image size issue and added PEP8 compliancy
- Images used the rounded up width, which resulted in them being slightly wider. Whoops
- Removed parameters for crop_width and used the self equivalent to be PEP8 compliant
@BoboTiG
Copy link
Owner

BoboTiG commented Apr 22, 2017

The fix has been pushed to the dev branch. I will wait for your responses before merging to master and uploading to PyPi. Thanks @DavideBecker for the fix :)

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

4 participants