lilohuang/PyTurboJPEG

silent crash on wrong array shape

aqc-carlodri opened this issue · 1 comments

If I try to encode an image with missing components, the python interpreter silently exits with no message/exception.

See this example code:

from numpy import uint8, zeros
from turbojpeg import TJPF_RGB, TJSAMP_420, TurboJPEG

jpeg = TurboJPEG()

image = zeros((1024, 4096), dtype=uint8)

print("Entering store...")

with open("test.jpg", "wb") as f:
    jpeg_encoded = jpeg.encode(
        image,
        pixel_format=TJPF_RGB,
        quality=95,
        jpeg_subsample=TJSAMP_420,
    )
    f.write(jpeg_encoded)

print("Exiting store (this never gets printed)...")

Conversely, if I say image = zeros((1024, 4096, 3), dtype=uint8), the script completes normally.

Issue appears with both pyturbojpeg 1.6.3 and 1.6.4, on Windows 10x64.

I would expect to see an exception raised in this case.

Thank you for your work on this great wrapper library, and happy new year!

thank you for the quick solution!