mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-26 07:04:45 +03:00
Added format_args argument
This commit is contained in:
parent
1e56ed8c00
commit
eab6618159
|
@ -2557,7 +2557,7 @@ def _decompression_bomb_check(size):
|
||||||
DecompressionBombWarning)
|
DecompressionBombWarning)
|
||||||
|
|
||||||
|
|
||||||
def open(fp, mode="r"):
|
def open(fp, mode="r", format_args=None):
|
||||||
"""
|
"""
|
||||||
Opens and identifies the given image file.
|
Opens and identifies the given image file.
|
||||||
|
|
||||||
|
@ -2601,13 +2601,13 @@ def open(fp, mode="r"):
|
||||||
|
|
||||||
preinit()
|
preinit()
|
||||||
|
|
||||||
def _open_core(fp, filename, prefix):
|
def _open_core(fp, filename, prefix, format_args):
|
||||||
for i in ID:
|
for i in ID:
|
||||||
try:
|
try:
|
||||||
factory, accept = OPEN[i]
|
factory, accept = OPEN[i]
|
||||||
if not accept or accept(prefix):
|
if not accept or accept(prefix):
|
||||||
fp.seek(0)
|
fp.seek(0)
|
||||||
im = factory(fp, filename)
|
im = factory(fp, filename, format_args)
|
||||||
_decompression_bomb_check(im.size)
|
_decompression_bomb_check(im.size)
|
||||||
return im
|
return im
|
||||||
except (SyntaxError, IndexError, TypeError, struct.error):
|
except (SyntaxError, IndexError, TypeError, struct.error):
|
||||||
|
@ -2617,11 +2617,11 @@ def open(fp, mode="r"):
|
||||||
continue
|
continue
|
||||||
return None
|
return None
|
||||||
|
|
||||||
im = _open_core(fp, filename, prefix)
|
im = _open_core(fp, filename, prefix, format_args)
|
||||||
|
|
||||||
if im is None:
|
if im is None:
|
||||||
if init():
|
if init():
|
||||||
im = _open_core(fp, filename, prefix)
|
im = _open_core(fp, filename, prefix, format_args)
|
||||||
|
|
||||||
if im:
|
if im:
|
||||||
im._exclusive_fp = exclusive_fp
|
im._exclusive_fp = exclusive_fp
|
||||||
|
|
|
@ -75,7 +75,7 @@ def _tilesort(t):
|
||||||
class ImageFile(Image.Image):
|
class ImageFile(Image.Image):
|
||||||
"Base class for image file format handlers."
|
"Base class for image file format handlers."
|
||||||
|
|
||||||
def __init__(self, fp=None, filename=None):
|
def __init__(self, fp=None, filename=None, format_args=None):
|
||||||
Image.Image.__init__(self)
|
Image.Image.__init__(self)
|
||||||
|
|
||||||
self._min_frame = 0
|
self._min_frame = 0
|
||||||
|
@ -86,6 +86,10 @@ class ImageFile(Image.Image):
|
||||||
self.decoderconfig = ()
|
self.decoderconfig = ()
|
||||||
self.decodermaxblock = MAXBLOCK
|
self.decodermaxblock = MAXBLOCK
|
||||||
|
|
||||||
|
if format_args is None:
|
||||||
|
format_args = {}
|
||||||
|
self.formats_args = format_args
|
||||||
|
|
||||||
if isPath(fp):
|
if isPath(fp):
|
||||||
# filename
|
# filename
|
||||||
self.fp = open(fp, "rb")
|
self.fp = open(fp, "rb")
|
||||||
|
|
|
@ -776,14 +776,14 @@ def _save_cjpeg(im, fp, filename):
|
||||||
|
|
||||||
##
|
##
|
||||||
# Factory for making JPEG and MPO instances
|
# Factory for making JPEG and MPO instances
|
||||||
def jpeg_factory(fp=None, filename=None):
|
def jpeg_factory(fp=None, filename=None, format_args=None):
|
||||||
im = JpegImageFile(fp, filename)
|
im = JpegImageFile(fp, filename, format_args)
|
||||||
try:
|
try:
|
||||||
mpheader = im._getmp()
|
mpheader = im._getmp()
|
||||||
if mpheader[45057] > 1:
|
if mpheader[45057] > 1:
|
||||||
# It's actually an MPO
|
# It's actually an MPO
|
||||||
from .MpoImagePlugin import MpoImageFile
|
from .MpoImagePlugin import MpoImageFile
|
||||||
im = MpoImageFile(fp, filename)
|
im = MpoImageFile(fp, filename, format_args)
|
||||||
except (TypeError, IndexError):
|
except (TypeError, IndexError):
|
||||||
# It is really a JPEG
|
# It is really a JPEG
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue
Block a user