@@ -800,74 +800,6 @@ PyImaging_ZipDecoderNew(PyObject *self, PyObject *args) {
800800}
801801#endif
802802
803- /* -------------------------------------------------------------------- */
804- /* JPEG */
805- /* -------------------------------------------------------------------- */
806-
807- #ifdef HAVE_LIBJPEG
808-
809- /* We better define this decoder last in this file, so the following
810- undef's won't mess things up for the Imaging library proper. */
811-
812- #undef HAVE_PROTOTYPES
813- #undef HAVE_STDDEF_H
814- #undef HAVE_STDLIB_H
815- #undef UINT8
816- #undef UINT16
817- #undef UINT32
818- #undef INT8
819- #undef INT16
820- #undef INT32
821-
822- #include "libImaging/Jpeg.h"
823-
824- PyObject *
825- PyImaging_JpegDecoderNew (PyObject * self , PyObject * args ) {
826- ImagingDecoderObject * decoder ;
827-
828- char * mode ;
829- char * rawmode ; /* what we want from the decoder */
830- char * jpegmode ; /* what's in the file */
831- int scale = 1 ;
832- int draft = 0 ;
833-
834- if (!PyArg_ParseTuple (args , "ssz|ii" , & mode , & rawmode , & jpegmode , & scale , & draft )) {
835- return NULL ;
836- }
837-
838- if (!jpegmode ) {
839- jpegmode = "" ;
840- }
841-
842- decoder = PyImaging_DecoderNew (sizeof (JPEGSTATE ));
843- if (decoder == NULL ) {
844- return NULL ;
845- }
846-
847- // libjpeg-turbo supports different output formats.
848- // We are choosing Pillow's native format (3 color bytes + 1 padding)
849- // to avoid extra conversion in Unpack.c.
850- if (ImagingJpegUseJCSExtensions () && strcmp (rawmode , "RGB" ) == 0 ) {
851- rawmode = "RGBX" ;
852- }
853-
854- if (get_unpacker (decoder , mode , rawmode ) < 0 ) {
855- return NULL ;
856- }
857-
858- decoder -> decode = ImagingJpegDecode ;
859- decoder -> cleanup = ImagingJpegDecodeCleanup ;
860-
861- strncpy (((JPEGSTATE * )decoder -> state .context )-> rawmode , rawmode , 8 );
862- strncpy (((JPEGSTATE * )decoder -> state .context )-> jpegmode , jpegmode , 8 );
863-
864- ((JPEGSTATE * )decoder -> state .context )-> scale = scale ;
865- ((JPEGSTATE * )decoder -> state .context )-> draft = draft ;
866-
867- return (PyObject * )decoder ;
868- }
869- #endif
870-
871803/* -------------------------------------------------------------------- */
872804/* JPEG 2000 */
873805/* -------------------------------------------------------------------- */
@@ -925,3 +857,61 @@ PyImaging_Jpeg2KDecoderNew(PyObject *self, PyObject *args) {
925857 return (PyObject * )decoder ;
926858}
927859#endif /* HAVE_OPENJPEG */
860+
861+ /* -------------------------------------------------------------------- */
862+ /* JPEG */
863+ /* -------------------------------------------------------------------- */
864+
865+ #ifdef HAVE_LIBJPEG
866+
867+ /* We better define this decoder last in this file, so the undef's
868+ in Jpeg.h won't mess things up for the Imaging library proper. */
869+
870+ #include "libImaging/Jpeg.h"
871+
872+ PyObject *
873+ PyImaging_JpegDecoderNew (PyObject * self , PyObject * args ) {
874+ ImagingDecoderObject * decoder ;
875+
876+ char * mode ;
877+ char * rawmode ; /* what we want from the decoder */
878+ char * jpegmode ; /* what's in the file */
879+ int scale = 1 ;
880+ int draft = 0 ;
881+
882+ if (!PyArg_ParseTuple (args , "ssz|ii" , & mode , & rawmode , & jpegmode , & scale , & draft )) {
883+ return NULL ;
884+ }
885+
886+ if (!jpegmode ) {
887+ jpegmode = "" ;
888+ }
889+
890+ decoder = PyImaging_DecoderNew (sizeof (JPEGSTATE ));
891+ if (decoder == NULL ) {
892+ return NULL ;
893+ }
894+
895+ // libjpeg-turbo supports different output formats.
896+ // We are choosing Pillow's native format (3 color bytes + 1 padding)
897+ // to avoid extra conversion in Unpack.c.
898+ if (ImagingJpegUseJCSExtensions () && strcmp (rawmode , "RGB" ) == 0 ) {
899+ rawmode = "RGBX" ;
900+ }
901+
902+ if (get_unpacker (decoder , mode , rawmode ) < 0 ) {
903+ return NULL ;
904+ }
905+
906+ decoder -> decode = ImagingJpegDecode ;
907+ decoder -> cleanup = ImagingJpegDecodeCleanup ;
908+
909+ strncpy (((JPEGSTATE * )decoder -> state .context )-> rawmode , rawmode , 8 );
910+ strncpy (((JPEGSTATE * )decoder -> state .context )-> jpegmode , jpegmode , 8 );
911+
912+ ((JPEGSTATE * )decoder -> state .context )-> scale = scale ;
913+ ((JPEGSTATE * )decoder -> state .context )-> draft = draft ;
914+
915+ return (PyObject * )decoder ;
916+ }
917+ #endif
0 commit comments