martinbenes1996/jpeglib

Integer QF in jpeglib.from_dct

Closed this issue · 2 comments

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.

Thank you for the bug report. Will take a look at it next week.

Amazing spot! The fix commit 5bf7d01 just pushed to dev.