Integer QF in jpeglib.from_dct
Closed this issue · 2 comments
btlorch commented
According to the docstring, jpeglib.from_dct
assumes the quantization table to be either None or to be an ndarray. The example from the documentation suggests that integer quality factors are also possible, but the example leads to an error.
Y = np.random.randint(-127, 127,(2,2,8,8),dtype=np.int16)
Cb = np.random.randint(-127, 127,(1,1,8,8),dtype=np.int16)
Cr = np.random.randint(-127, 127,(1,1,8,8),dtype=np.int16)
im = jpeglib.from_dct(Y, Cb, Cr, qt=75) # chrominance -> YCbCr infered
When only the luminance channel is given, then the jpeglib object is created successfully, but writing to a file fails.
Y = np.random.randint(-127, 127, (2, 2, 8, 8), dtype=np.int16)
im = jpeglib.from_dct(Y, qt=75)
im.write_dct("/tmp/tmp.jpg")
A simple solution would be to disallow integer quality factors. Another solution would be to retrieve the quantization tables for the given quality factor.
martinbenes1996 commented
Thank you for the bug report. Will take a look at it next week.
martinbenes1996 commented
Amazing spot! The fix commit 5bf7d01 just pushed to dev.