create separate ImagingJpegUseJCSExtensions function

This commit is contained in:
Alexander 2017-08-11 04:07:54 +03:00
parent 83c4d90923
commit 7725d281a5
3 changed files with 31 additions and 24 deletions

View File

@ -809,17 +809,6 @@ PyImaging_ZipDecoderNew(PyObject* self, PyObject* args)
#include "Jpeg.h"
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
// There is no way to compare versions on compile time,
// so we have to do that in runtime.
#ifdef LIBJPEG_TURBO_VERSION
char *libjpeg_turbo_version = TOSTRING(LIBJPEG_TURBO_VERSION);
#else
char *libjpeg_turbo_version = NULL;
#endif
PyObject*
PyImaging_JpegDecoderNew(PyObject* self, PyObject* args)
{
@ -830,7 +819,6 @@ PyImaging_JpegDecoderNew(PyObject* self, PyObject* args)
char* jpegmode; /* what's in the file */
int scale = 1;
int draft = 0;
int use_jcs_extensions = 0;
if (!PyArg_ParseTuple(args, "ssz|ii", &mode, &rawmode, &jpegmode,
&scale, &draft))
@ -843,23 +831,12 @@ PyImaging_JpegDecoderNew(PyObject* self, PyObject* args)
if (decoder == NULL)
return NULL;
#ifdef JCS_EXTENSIONS
#if defined(LIBJPEG_TURBO_VERSION_NUMBER)
#if LIBJPEG_TURBO_VERSION_NUMBER >= 1002010
use_jcs_extensions = 1;
#endif
#else
if (libjpeg_turbo_version) {
use_jcs_extensions = strcmp(libjpeg_turbo_version, "1.2.1") >= 0;
}
#endif
// libjpeg-turbo supports different output formats.
// We are choosing Pillow's native format (3 color bytes + 1 padding)
// to avoid extra conversion in Unpack.c.
if (use_jcs_extensions && strcmp(rawmode, "RGB") == 0) {
if (ImagingJpegUseJCSExtensions() && strcmp(rawmode, "RGB") == 0) {
rawmode = "RGBX";
}
#endif
if (get_unpacker(decoder, mode, rawmode) < 0)
return NULL;

View File

@ -406,6 +406,7 @@ extern int ImagingHexDecode(Imaging im, ImagingCodecState state,
extern int ImagingJpegDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
extern int ImagingJpegDecodeCleanup(ImagingCodecState state);
extern int ImagingJpegUseJCSExtensions(void);
extern int ImagingJpegEncode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);

View File

@ -38,6 +38,35 @@
#include "Jpeg.h"
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
// There is no way to compare versions on compile time,
// so we have to do that in runtime.
#ifdef LIBJPEG_TURBO_VERSION
char *libjpeg_turbo_version = TOSTRING(LIBJPEG_TURBO_VERSION);
#else
char *libjpeg_turbo_version = NULL;
#endif
int
ImagingJpegUseJCSExtensions()
{
int use_jcs_extensions = 0;
#ifdef JCS_EXTENSIONS
#if defined(LIBJPEG_TURBO_VERSION_NUMBER)
#if LIBJPEG_TURBO_VERSION_NUMBER >= 1002010
use_jcs_extensions = 1;
#endif
#else
if (libjpeg_turbo_version) {
use_jcs_extensions = strcmp(libjpeg_turbo_version, "1.2.1") >= 0;
}
#endif
#endif
return use_jcs_extensions;
}
/* -------------------------------------------------------------------- */
/* Suspending input handler */
/* -------------------------------------------------------------------- */