nut-tree/libnut-core

Region based screenshots are broken on macOS

s1hofmann opened this issue · 1 comments

Version
2.1.0

Short overview
When taking screenshots of a region on macOS Catalina, resulting images are mostly broken.

Detailed error description
On macOS Catalina, region based screenshots who's width is not a multiple of 4 are broken.
CGDisplayCreateImageForRect seems to allocate memory in 16 byte chunks, not caring about the actual image size.

Example:

Width: 3360
Height: 2100

3360px * 4 channels = 13440 bytes

When taking a screenshot of e.g. 3358px width, CGDisplayCreateImageForRect would still allocate 13440 bytes.
This results in a black margin on the right side of the image, where all pixels are zeroed due to initialisation.

When writing the image to a file, these additional pixels cause an image tilt.

After I updated my machine to Big Sur, this issue seems to be fixed.
Switching to the macOS Big Sur GitHub Actions runner to check.