Fixes masked JPEG image

Fixes #4890