Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ trim_trailing_whitespace = true
[*.yml]
# Two-space indentation
indent_size = 2
indent_style = space

# Tab indentation (no size specified)
[Makefile]
Expand Down
12 changes: 6 additions & 6 deletions Tests/test_color_lut.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ def test_3_to_3_channels(self):
assert tuple(lut.size) == tuple(source.size)
assert len(lut.table) == len(source.table)
assert lut.table != source.table
assert lut.table[0:10] == [0.0, 0.0, 0.0, 0.25, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]
assert lut.table[:10] == [0.0, 0.0, 0.0, 0.25, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]

def test_3_to_4_channels(self):
source = ImageFilter.Color3DLUT.generate((6, 5, 4), lambda r, g, b: (r, g, b))
Expand All @@ -576,7 +576,7 @@ def test_3_to_4_channels(self):
assert len(lut.table) != len(source.table)
assert lut.table != source.table
# fmt: off
assert lut.table[0:16] == [
assert lut.table[:16] == [
0.0, 0.0, 0.0, 1, 0.2**2, 0.0, 0.0, 1,
0.4**2, 0.0, 0.0, 1, 0.6**2, 0.0, 0.0, 1]
# fmt: on
Expand All @@ -592,7 +592,7 @@ def test_4_to_3_channels(self):
assert len(lut.table) != len(source.table)
assert lut.table != source.table
# fmt: off
assert lut.table[0:18] == [
assert lut.table[:18] == [
1.0, 1.0, 1.0, 0.75, 1.0, 1.0, 0.0, 1.0, 1.0,
1.0, 0.96, 1.0, 0.75, 0.96, 1.0, 0.0, 0.96, 1.0]
# fmt: on
Expand All @@ -606,7 +606,7 @@ def test_4_to_4_channels(self):
assert len(lut.table) == len(source.table)
assert lut.table != source.table
# fmt: off
assert lut.table[0:16] == [
assert lut.table[:16] == [
0.0, 0.0, 0.0, 0.5, 0.2**2, 0.0, 0.0, 0.5,
0.4**2, 0.0, 0.0, 0.5, 0.6**2, 0.0, 0.0, 0.5]
# fmt: on
Expand All @@ -622,7 +622,7 @@ def test_with_normals_3_channels(self):
assert len(lut.table) == len(source.table)
assert lut.table != source.table
# fmt: off
assert lut.table[0:18] == [
assert lut.table[:18] == [
0.0, 0.0, 0.0, 0.16, 0.0, 0.0, 0.24, 0.0, 0.0,
0.24, 0.0, 0.0, 0.8 - (0.8**2), 0, 0, 0, 0, 0]
# fmt: on
Expand All @@ -639,7 +639,7 @@ def test_with_normals_4_channels(self):
assert len(lut.table) == len(source.table)
assert lut.table != source.table
# fmt: off
assert lut.table[0:16] == [
assert lut.table[:16] == [
0.0, 0.0, 0.0, 0.5, 0.25, 0.0, 0.0, 0.5,
0.0, 0.0, 0.0, 0.5, 0.0, 0.16, 0.0, 0.5]
# fmt: on
4 changes: 2 additions & 2 deletions Tests/test_decompression_bomb.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ def test_exception_bmp(self):

class TestDecompressionCrop:
@classmethod
def setup_class(self):
def setup_class(cls):
width, height = 128, 128
Image.MAX_IMAGE_PIXELS = height * width * 4 - 1

@classmethod
def teardown_class(self):
def teardown_class(cls):
Image.MAX_IMAGE_PIXELS = ORIGINAL_LIMIT

def testEnlargeCrop(self):
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def test_fp_name(self, tmp_path):
temp_file = str(tmp_path / "temp.jpg")

class FP:
def write(a, b):
def write(self, b):
pass

fp = FP()
Expand Down
14 changes: 7 additions & 7 deletions Tests/test_image_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def convert(im, mode):
"HSV",
)

for mode in modes:
im = hopper(mode)
for mode in modes:
convert(im, mode)
for input_mode in modes:
im = hopper(input_mode)
for output_mode in modes:
convert(im, output_mode)

# Check 0
im = Image.new(mode, (0, 0))
for mode in modes:
convert(im, mode)
im = Image.new(input_mode, (0, 0))
for output_mode in modes:
convert(im, output_mode)


def test_default():
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_image_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def resize_tiled(self, im, dst_size, xtiles, ytiles):
def split_range(size, tiles):
scale = size / tiles
for i in range(tiles):
yield (int(round(scale * i)), int(round(scale * (i + 1))))
yield int(round(scale * i)), int(round(scale * (i + 1)))

tiled = Image.new(im.mode, dst_size)
scale = (im.size[0] / tiled.size[0], im.size[1] / tiled.size[1])
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_imagesequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ def test_consecutive():
def test_palette_mmap():
# Using mmap in ImageFile can require to reload the palette.
with Image.open("Tests/images/multipage-mmap.tiff") as im:
color1 = im.getpalette()[0:3]
color1 = im.getpalette()[:3]
im.seek(0)
color2 = im.getpalette()[0:3]
color2 = im.getpalette()[:3]
assert color1 == color2


Expand Down
14 changes: 14 additions & 0 deletions docs/reference/TiffTags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ metadata tag numbers, names, and type information.
.. method:: lookup(tag)

:param tag: Integer tag number
:param group: Which :py:data:`~PIL.TiffTags.TAGS_V2_GROUPS` to look in

.. versionadded:: 8.3.0

:returns: Taginfo namedtuple, From the :py:data:`~PIL.TiffTags.TAGS_V2` info if possible,
otherwise just populating the value and name from :py:data:`~PIL.TiffTags.TAGS`.
If the tag is not recognized, "unknown" is returned for the name
Expand Down Expand Up @@ -42,6 +46,16 @@ metadata tag numbers, names, and type information.

.. versionadded:: 3.0.0

.. py:data:: PIL.TiffTags.TAGS_V2_GROUPS
:type: dict

:py:data:`~PIL.TiffTags.TAGS_V2` is one dimensional and
doesn't account for the fact that tags actually exist in
`different groups <https://exiftool.org/TagNames/EXIF.html>`_.
This dictionary is used when the tag in question is part of a group.

.. versionadded:: 8.3.0

.. py:data:: PIL.TiffTags.TAGS
:type: dict

Expand Down
2 changes: 1 addition & 1 deletion selftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def testimage():

>>> from PIL import Image, ImageDraw, ImageFilter, ImageMath
>>> im = Image.new("1", (128, 128)) # monochrome
>>> def _info(im): return (im.format, im.mode, im.size)
>>> def _info(im): return im.format, im.mode, im.size
>>> _info(im)
(None, '1', (128, 128))
>>> _info(Image.new("L", (128, 128))) # grayscale (luminance)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def _pkg_config(name):
.strip()
.replace("-I", "")
)
return (libs, cflags)
return libs, cflags
except Exception:
pass

Expand Down
2 changes: 1 addition & 1 deletion src/PIL/BlpImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __getattr__(name):


def unpack_565(i):
return (((i >> 11) & 0x1F) << 3, ((i >> 5) & 0x3F) << 2, (i & 0x1F) << 3)
return ((i >> 11) & 0x1F) << 3, ((i >> 5) & 0x3F) << 2, (i & 0x1F) << 3


def decode_dxt1(data, alpha=False):
Expand Down
4 changes: 1 addition & 3 deletions src/PIL/BmpImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ def _bitmap(self, header=0, offset=0):
read, seek = self.fp.read, self.fp.seek
if header:
seek(header)
file_info = {}
# read bmp header size @offset 14 (this is part of the header size)
file_info["header_size"] = i32(read(4))
file_info["direction"] = -1
file_info = {"header_size": i32(read(4)), "direction": -1}

# -------------------- If requested, read header at a specific position
# read the rest of the bmp header, without its size
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/EpsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def _find_offset(self, fp):
else:
raise SyntaxError("not an EPS file")

return (length, offset)
return length, offset

def load(self, scale=1, transparency=False):
# Load EPS via Ghostscript
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/FpxImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# we map from colour field tuples to (mode, rawmode) descriptors
MODES = {
# opacity
(0x00007FFE): ("A", "L"),
(0x00007FFE,): ("A", "L"),
# monochrome
(0x00010000,): ("L", "L"),
(0x00018000, 0x00017FFE): ("RGBA", "LA"),
Expand Down Expand Up @@ -162,7 +162,7 @@ def _open_subimage(self, index=1, subimage=0):
"raw",
(x, y, x + xtile, y + ytile),
i32(s, i) + 28,
(self.rawmode),
(self.rawmode,),
)
)

Expand Down
2 changes: 1 addition & 1 deletion src/PIL/FtexImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _open(self):

if format == Format.DXT1:
self.mode = "RGBA"
self.tile = [("bcn", (0, 0) + self.size, 0, (1))]
self.tile = [("bcn", (0, 0) + self.size, 0, 1)]
elif format == Format.UNCOMPRESSED:
self.tile = [("raw", (0, 0) + self.size, 0, ("RGB", 0, 1))]
else:
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/GdImageFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def open(fp, mode="r"):
"""
Load texture from a GD image file.

:param filename: GD file name, or an opened file handle.
:param fp: GD file name, or an opened file handle.
:param mode: Optional mode. In this version, if the mode argument
is given, it must be "r".
:returns: An image instance.
Expand Down
11 changes: 6 additions & 5 deletions src/PIL/GifImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,8 +990,6 @@ def getheader(im, palette=None, info=None):
return header, used_palette_colors


# To specify duration, add the time in milliseconds to getdata(),
# e.g. getdata(im_frame, duration=1000)
def getdata(im, offset=(0, 0), **params):
"""
Legacy Method
Expand All @@ -1000,10 +998,13 @@ def getdata(im, offset=(0, 0), **params):
The first string is a local image header, the rest contains
encoded image data.

To specify duration, add the time in milliseconds,
e.g. ``getdata(im_frame, duration=1000)``

:param im: Image object
:param offset: Tuple of (x, y) pixels. Defaults to (0,0)
:param \\**params: E.g. duration or other encoder info parameters
:returns: List of Bytes containing gif encoded frame data
:param offset: Tuple of (x, y) pixels. Defaults to (0, 0)
:param \\**params: e.g. duration or other encoder info parameters
:returns: List of bytes containing GIF encoded frame data

"""

Expand Down
2 changes: 1 addition & 1 deletion src/PIL/GribStubImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def register_handler(handler):


def _accept(prefix):
return prefix[0:4] == b"GRIB" and prefix[7] == 1
return prefix[:4] == b"GRIB" and prefix[7] == 1


class GribStubImageFile(ImageFile.StubImageFile):
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def _open(self):
self.mode = self.info[MODE]

# Skip forward to start of image data
while s and s[0:1] != b"\x1A":
while s and s[:1] != b"\x1A":
s = self.fp.read(1)
if not s:
raise SyntaxError("File truncated")
Expand Down
13 changes: 6 additions & 7 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2582,7 +2582,7 @@ def __transformer(
h = box[3] - box[1]

if method == Transform.AFFINE:
data = data[0:6]
data = data[:6]

elif method == Transform.EXTENT:
# convert extent to an affine transform
Expand All @@ -2593,12 +2593,12 @@ def __transformer(
data = (xs, 0, x0, 0, ys, y0)

elif method == Transform.PERSPECTIVE:
data = data[0:8]
data = data[:8]

elif method == Transform.QUAD:
# quadrilateral warp. data specifies the four corners
# given as NW, SW, SE, and NE.
nw = data[0:2]
nw = data[:2]
sw = data[2:4]
se = data[4:6]
ne = data[6:8]
Expand Down Expand Up @@ -2992,12 +2992,11 @@ def fromqpixmap(im):
((1, 1, 2), "|u1"): ("LA", "LA"),
((1, 1, 3), "|u1"): ("RGB", "RGB"),
((1, 1, 4), "|u1"): ("RGBA", "RGBA"),
# shortcuts:
((1, 1), _ENDIAN + "i4"): ("I", "I"),
((1, 1), _ENDIAN + "f4"): ("F", "F"),
}

# shortcuts
_fromarray_typemap[((1, 1), _ENDIAN + "i4")] = ("I", "I")
_fromarray_typemap[((1, 1), _ENDIAN + "f4")] = ("F", "F")


def _decompression_bomb_check(size):
if MAX_IMAGE_PIXELS is None:
Expand Down
1 change: 1 addition & 0 deletions src/PIL/ImageChops.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ def offset(image, xoffset, yoffset=None):
distances. Data wraps around the edges. If ``yoffset`` is omitted, it
is assumed to be equal to ``xoffset``.

:param image: Input image.
:param xoffset: The horizontal distance.
:param yoffset: The vertical distance. If omitted, both
distances are set to the same value.
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/ImageCms.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def __getattr__(name):
"SOFTPROOFING": 16384, # Do softproofing
"PRESERVEBLACK": 32768, # Black preservation
"NODEFAULTRESOURCEDEF": 16777216, # CRD special
"GRIDPOINTS": lambda n: ((n) & 0xFF) << 16, # Gridpoints
"GRIDPOINTS": lambda n: (n & 0xFF) << 16, # Gridpoints
}

_MAX_FLAG = 0
Expand Down Expand Up @@ -1026,4 +1026,4 @@ def versions():
(pyCMS) Fetches versions.
"""

return (VERSION, core.littlecms_version, sys.version.split()[0], Image.__version__)
return VERSION, core.littlecms_version, sys.version.split()[0], Image.__version__
Loading