mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +03:00
Found edge cases with custom qtables
And there was a lingering bug since the previous qtable unsigned char fix (#1814) since the call to array.array was in another place, the roundtrip was no longer equivalent. That was a minor change, but the revised test wouldn't pass because saving an image with one custom qtable automatically adds a second to it by the call to jpeg_set_defaults. With 1 or >2 custom tables, there is extra work we have to do due to that call.
This commit is contained in:
parent
7872501c5b
commit
8b572ade81
|
@ -195,7 +195,7 @@ def DQT(self, marker):
|
|||
raise SyntaxError("bad quantization table marker")
|
||||
v = i8(s[0])
|
||||
if v//16 == 0:
|
||||
self.quantization[v & 15] = array.array("b", s[1:65])
|
||||
self.quantization[v & 15] = array.array("B", s[1:65])
|
||||
s = s[65:]
|
||||
else:
|
||||
return # FIXME: add code to read 16-bit tables!
|
||||
|
|
|
@ -151,11 +151,22 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
|
|||
if (context->quality > 0) {
|
||||
quality = context->quality;
|
||||
}
|
||||
for (i = 0; i < context->qtablesLen; i++) {
|
||||
// TODO: Should add support for none baseline
|
||||
jpeg_add_quant_table(&context->cinfo, i, &context->qtables[i * DCTSIZE2],
|
||||
quality, TRUE);
|
||||
}
|
||||
int last_q = 0;
|
||||
for (i = 0; i < context->qtablesLen; i++) {
|
||||
// TODO: Should add support for none baseline
|
||||
jpeg_add_quant_table(&context->cinfo, i, &context->qtables[i * DCTSIZE2],
|
||||
quality, TRUE);
|
||||
context->cinfo.comp_info[i].quant_tbl_no = i;
|
||||
last_q = i;
|
||||
}
|
||||
if (context->qtablesLen == 1) {
|
||||
// jpeg_set_defaults created two qtables internally, but we only wanted one.
|
||||
jpeg_add_quant_table(&context->cinfo, 1, &context->qtables[0],
|
||||
quality, TRUE);
|
||||
}
|
||||
for (i = last_q; i < context->cinfo.num_components; i++) {
|
||||
context->cinfo.comp_info[i].quant_tbl_no = last_q;
|
||||
}
|
||||
} else if (context->quality > 0) {
|
||||
jpeg_set_quality(&context->cinfo, context->quality, 1);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user