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:
Stephen Arthur 2016-05-22 17:43:57 -07:00
parent 7872501c5b
commit 8b572ade81
2 changed files with 17 additions and 6 deletions

View File

@ -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!

View File

@ -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);
}