mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Merge pull request #8645 from radarhere/mozjpeg
This commit is contained in:
		
						commit
						6bce9aa461
					
				| 
						 | 
					@ -281,7 +281,10 @@ class TestFileJpeg:
 | 
				
			||||||
        assert not im2.info.get("progressive")
 | 
					        assert not im2.info.get("progressive")
 | 
				
			||||||
        assert im3.info.get("progressive")
 | 
					        assert im3.info.get("progressive")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        assert_image_equal(im1, im3)
 | 
					        if features.check_feature("mozjpeg"):
 | 
				
			||||||
 | 
					            assert_image_similar(im1, im3, 9.39)
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            assert_image_equal(im1, im3)
 | 
				
			||||||
        assert im1_bytes >= im3_bytes
 | 
					        assert im1_bytes >= im3_bytes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_progressive_large_buffer(self, tmp_path: Path) -> None:
 | 
					    def test_progressive_large_buffer(self, tmp_path: Path) -> None:
 | 
				
			||||||
| 
						 | 
					@ -423,8 +426,12 @@ class TestFileJpeg:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        im2 = self.roundtrip(hopper(), progressive=1)
 | 
					        im2 = self.roundtrip(hopper(), progressive=1)
 | 
				
			||||||
        im3 = self.roundtrip(hopper(), progression=1)  # compatibility
 | 
					        im3 = self.roundtrip(hopper(), progression=1)  # compatibility
 | 
				
			||||||
        assert_image_equal(im1, im2)
 | 
					        if features.check_feature("mozjpeg"):
 | 
				
			||||||
        assert_image_equal(im1, im3)
 | 
					            assert_image_similar(im1, im2, 9.39)
 | 
				
			||||||
 | 
					            assert_image_similar(im1, im3, 9.39)
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            assert_image_equal(im1, im2)
 | 
				
			||||||
 | 
					            assert_image_equal(im1, im3)
 | 
				
			||||||
        assert im2.info.get("progressive")
 | 
					        assert im2.info.get("progressive")
 | 
				
			||||||
        assert im2.info.get("progression")
 | 
					        assert im2.info.get("progression")
 | 
				
			||||||
        assert im3.info.get("progressive")
 | 
					        assert im3.info.get("progressive")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -127,6 +127,7 @@ features: dict[str, tuple[str, str | bool, str | None]] = {
 | 
				
			||||||
    "fribidi": ("PIL._imagingft", "HAVE_FRIBIDI", "fribidi_version"),
 | 
					    "fribidi": ("PIL._imagingft", "HAVE_FRIBIDI", "fribidi_version"),
 | 
				
			||||||
    "harfbuzz": ("PIL._imagingft", "HAVE_HARFBUZZ", "harfbuzz_version"),
 | 
					    "harfbuzz": ("PIL._imagingft", "HAVE_HARFBUZZ", "harfbuzz_version"),
 | 
				
			||||||
    "libjpeg_turbo": ("PIL._imaging", "HAVE_LIBJPEGTURBO", "libjpeg_turbo_version"),
 | 
					    "libjpeg_turbo": ("PIL._imaging", "HAVE_LIBJPEGTURBO", "libjpeg_turbo_version"),
 | 
				
			||||||
 | 
					    "mozjpeg": ("PIL._imaging", "HAVE_MOZJPEG", "libjpeg_turbo_version"),
 | 
				
			||||||
    "zlib_ng": ("PIL._imaging", "HAVE_ZLIBNG", "zlib_ng_version"),
 | 
					    "zlib_ng": ("PIL._imaging", "HAVE_ZLIBNG", "zlib_ng_version"),
 | 
				
			||||||
    "libimagequant": ("PIL._imaging", "HAVE_LIBIMAGEQUANT", "imagequant_version"),
 | 
					    "libimagequant": ("PIL._imaging", "HAVE_LIBIMAGEQUANT", "imagequant_version"),
 | 
				
			||||||
    "xcb": ("PIL._imaging", "HAVE_XCB", None),
 | 
					    "xcb": ("PIL._imaging", "HAVE_XCB", None),
 | 
				
			||||||
| 
						 | 
					@ -300,7 +301,8 @@ def pilinfo(out: IO[str] | None = None, supported_formats: bool = True) -> None:
 | 
				
			||||||
            if name == "jpg":
 | 
					            if name == "jpg":
 | 
				
			||||||
                libjpeg_turbo_version = version_feature("libjpeg_turbo")
 | 
					                libjpeg_turbo_version = version_feature("libjpeg_turbo")
 | 
				
			||||||
                if libjpeg_turbo_version is not None:
 | 
					                if libjpeg_turbo_version is not None:
 | 
				
			||||||
                    v = "libjpeg-turbo " + libjpeg_turbo_version
 | 
					                    v = "mozjpeg" if check_feature("mozjpeg") else "libjpeg-turbo"
 | 
				
			||||||
 | 
					                    v += " " + libjpeg_turbo_version
 | 
				
			||||||
            if v is None:
 | 
					            if v is None:
 | 
				
			||||||
                v = version(name)
 | 
					                v = version(name)
 | 
				
			||||||
            if v is not None:
 | 
					            if v is not None:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -76,6 +76,13 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef HAVE_LIBJPEG
 | 
					#ifdef HAVE_LIBJPEG
 | 
				
			||||||
#include "jconfig.h"
 | 
					#include "jconfig.h"
 | 
				
			||||||
 | 
					#ifdef LIBJPEG_TURBO_VERSION
 | 
				
			||||||
 | 
					#define JCONFIG_INCLUDED
 | 
				
			||||||
 | 
					#ifdef __CYGWIN__
 | 
				
			||||||
 | 
					#define _BASETSD_H
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#include "jpeglib.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef HAVE_LIBZ
 | 
					#ifdef HAVE_LIBZ
 | 
				
			||||||
| 
						 | 
					@ -4367,6 +4374,15 @@ setup_module(PyObject *m) {
 | 
				
			||||||
    Py_INCREF(have_libjpegturbo);
 | 
					    Py_INCREF(have_libjpegturbo);
 | 
				
			||||||
    PyModule_AddObject(m, "HAVE_LIBJPEGTURBO", have_libjpegturbo);
 | 
					    PyModule_AddObject(m, "HAVE_LIBJPEGTURBO", have_libjpegturbo);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    PyObject *have_mozjpeg;
 | 
				
			||||||
 | 
					#ifdef JPEG_C_PARAM_SUPPORTED
 | 
				
			||||||
 | 
					    have_mozjpeg = Py_True;
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					    have_mozjpeg = Py_False;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					    Py_INCREF(have_mozjpeg);
 | 
				
			||||||
 | 
					    PyModule_AddObject(m, "HAVE_MOZJPEG", have_mozjpeg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    PyObject *have_libimagequant;
 | 
					    PyObject *have_libimagequant;
 | 
				
			||||||
#ifdef HAVE_LIBIMAGEQUANT
 | 
					#ifdef HAVE_LIBIMAGEQUANT
 | 
				
			||||||
    have_libimagequant = Py_True;
 | 
					    have_libimagequant = Py_True;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -134,7 +134,16 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
 | 
				
			||||||
                    return -1;
 | 
					                    return -1;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /* Compressor configuration */
 | 
					                /* Compressor configuration */
 | 
				
			||||||
 | 
					#ifdef JPEG_C_PARAM_SUPPORTED
 | 
				
			||||||
 | 
					            /* MozJPEG */
 | 
				
			||||||
 | 
					            if (!context->progressive) {
 | 
				
			||||||
 | 
					                /* Do not use MozJPEG progressive default */
 | 
				
			||||||
 | 
					                jpeg_c_set_int_param(
 | 
				
			||||||
 | 
					                    &context->cinfo, JINT_COMPRESS_PROFILE, JCP_FASTEST
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
            jpeg_set_defaults(&context->cinfo);
 | 
					            jpeg_set_defaults(&context->cinfo);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /* Prevent RGB -> YCbCr conversion */
 | 
					            /* Prevent RGB -> YCbCr conversion */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user