mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 09:44:31 +03:00
Real fix for PR #915, keep track of the qtables length
This commit is contained in:
parent
bf22cdebd1
commit
00addab5e4
7
encode.c
7
encode.c
|
@ -535,7 +535,7 @@ PyImaging_ZipEncoderNew(PyObject* self, PyObject* args)
|
||||||
|
|
||||||
#include "Jpeg.h"
|
#include "Jpeg.h"
|
||||||
|
|
||||||
static unsigned int** get_qtables_arrays(PyObject* qtables) {
|
static unsigned int** get_qtables_arrays(PyObject* qtables, int* qtablesLen) {
|
||||||
PyObject* tables;
|
PyObject* tables;
|
||||||
PyObject* table;
|
PyObject* table;
|
||||||
PyObject* table_data;
|
PyObject* table_data;
|
||||||
|
@ -588,6 +588,7 @@ static unsigned int** get_qtables_arrays(PyObject* qtables) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_DECREF(tables);
|
Py_DECREF(tables);
|
||||||
|
*qtablesLen = num_tables;
|
||||||
|
|
||||||
if (PyErr_Occurred()) {
|
if (PyErr_Occurred()) {
|
||||||
PyMem_Free(qarrays);
|
PyMem_Free(qarrays);
|
||||||
|
@ -614,6 +615,7 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args)
|
||||||
int subsampling = -1; /* -1=default, 0=none, 1=medium, 2=high */
|
int subsampling = -1; /* -1=default, 0=none, 1=medium, 2=high */
|
||||||
PyObject* qtables=NULL;
|
PyObject* qtables=NULL;
|
||||||
unsigned int **qarrays = NULL;
|
unsigned int **qarrays = NULL;
|
||||||
|
int qtablesLen = 0;
|
||||||
char* extra = NULL;
|
char* extra = NULL;
|
||||||
int extra_size;
|
int extra_size;
|
||||||
char* rawExif = NULL;
|
char* rawExif = NULL;
|
||||||
|
@ -633,7 +635,7 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args)
|
||||||
if (get_packer(encoder, mode, rawmode) < 0)
|
if (get_packer(encoder, mode, rawmode) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
qarrays = get_qtables_arrays(qtables);
|
qarrays = get_qtables_arrays(qtables, &qtablesLen);
|
||||||
|
|
||||||
if (extra && extra_size > 0) {
|
if (extra && extra_size > 0) {
|
||||||
char* p = malloc(extra_size);
|
char* p = malloc(extra_size);
|
||||||
|
@ -657,6 +659,7 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args)
|
||||||
|
|
||||||
((JPEGENCODERSTATE*)encoder->state.context)->quality = quality;
|
((JPEGENCODERSTATE*)encoder->state.context)->quality = quality;
|
||||||
((JPEGENCODERSTATE*)encoder->state.context)->qtables = qarrays;
|
((JPEGENCODERSTATE*)encoder->state.context)->qtables = qarrays;
|
||||||
|
((JPEGENCODERSTATE*)encoder->state.context)->qtablesLen = qtablesLen;
|
||||||
((JPEGENCODERSTATE*)encoder->state.context)->subsampling = subsampling;
|
((JPEGENCODERSTATE*)encoder->state.context)->subsampling = subsampling;
|
||||||
((JPEGENCODERSTATE*)encoder->state.context)->progressive = progressive;
|
((JPEGENCODERSTATE*)encoder->state.context)->progressive = progressive;
|
||||||
((JPEGENCODERSTATE*)encoder->state.context)->smooth = smooth;
|
((JPEGENCODERSTATE*)encoder->state.context)->smooth = smooth;
|
||||||
|
|
|
@ -90,6 +90,7 @@ typedef struct {
|
||||||
|
|
||||||
/* Custom quantization tables () */
|
/* Custom quantization tables () */
|
||||||
unsigned int **qtables;
|
unsigned int **qtables;
|
||||||
|
int qtablesLen;
|
||||||
|
|
||||||
/* Extra data (to be injected after header) */
|
/* Extra data (to be injected after header) */
|
||||||
char* extra; int extra_size;
|
char* extra; int extra_size;
|
||||||
|
|
|
@ -151,7 +151,7 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
|
||||||
if (context->quality > 0) {
|
if (context->quality > 0) {
|
||||||
quality = context->quality;
|
quality = context->quality;
|
||||||
}
|
}
|
||||||
for (i = 0; i < sizeof(context->qtables)/sizeof(unsigned int *); i++) {
|
for (i = 0; i < context->qtablesLen; i++) {
|
||||||
// TODO: Should add support for none baseline
|
// TODO: Should add support for none baseline
|
||||||
jpeg_add_quant_table(&context->cinfo, i, context->qtables[i],
|
jpeg_add_quant_table(&context->cinfo, i, context->qtables[i],
|
||||||
quality, TRUE);
|
quality, TRUE);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user