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)
|
||||
|
||||
|
||||
def open(fp, mode="r"):
|
||||
def open(fp, mode="r", format_args=None):
|
||||
"""
|
||||
Opens and identifies the given image file.
|
||||
|
||||
|
@ -2601,13 +2601,13 @@ def open(fp, mode="r"):
|
|||
|
||||
preinit()
|
||||
|
||||
def _open_core(fp, filename, prefix):
|
||||
def _open_core(fp, filename, prefix, format_args):
|
||||
for i in ID:
|
||||
try:
|
||||
factory, accept = OPEN[i]
|
||||
if not accept or accept(prefix):
|
||||
fp.seek(0)
|
||||
im = factory(fp, filename)
|
||||
im = factory(fp, filename, format_args)
|
||||
_decompression_bomb_check(im.size)
|
||||
return im
|
||||
except (SyntaxError, IndexError, TypeError, struct.error):
|
||||
|
@ -2617,11 +2617,11 @@ def open(fp, mode="r"):
|
|||
continue
|
||||
return None
|
||||
|
||||
im = _open_core(fp, filename, prefix)
|
||||
im = _open_core(fp, filename, prefix, format_args)
|
||||
|
||||
if im is None:
|
||||
if init():
|
||||
im = _open_core(fp, filename, prefix)
|
||||
im = _open_core(fp, filename, prefix, format_args)
|
||||
|
||||
if im:
|
||||
im._exclusive_fp = exclusive_fp
|
||||
|
|
|
@ -75,7 +75,7 @@ def _tilesort(t):
|
|||
class ImageFile(Image.Image):
|
||||
"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)
|
||||
|
||||
self._min_frame = 0
|
||||
|
@ -86,6 +86,10 @@ class ImageFile(Image.Image):
|
|||
self.decoderconfig = ()
|
||||
self.decodermaxblock = MAXBLOCK
|
||||
|
||||
if format_args is None:
|
||||
format_args = {}
|
||||
self.formats_args = format_args
|
||||
|
||||
if isPath(fp):
|
||||
# filename
|
||||
self.fp = open(fp, "rb")
|
||||
|
|
|
@ -776,14 +776,14 @@ def _save_cjpeg(im, fp, filename):
|
|||
|
||||
##
|
||||
# Factory for making JPEG and MPO instances
|
||||
def jpeg_factory(fp=None, filename=None):
|
||||
im = JpegImageFile(fp, filename)
|
||||
def jpeg_factory(fp=None, filename=None, format_args=None):
|
||||
im = JpegImageFile(fp, filename, format_args)
|
||||
try:
|
||||
mpheader = im._getmp()
|
||||
if mpheader[45057] > 1:
|
||||
# It's actually an MPO
|
||||
from .MpoImagePlugin import MpoImageFile
|
||||
im = MpoImageFile(fp, filename)
|
||||
im = MpoImageFile(fp, filename, format_args)
|
||||
except (TypeError, IndexError):
|
||||
# It is really a JPEG
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue
Block a user