mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
flake8
This commit is contained in:
parent
6b5871a484
commit
08499d3547
|
@ -24,6 +24,7 @@ from PIL._binary import o8
|
||||||
|
|
||||||
EPSILON = 1e-10
|
EPSILON = 1e-10
|
||||||
|
|
||||||
|
|
||||||
def linear(middle, pos):
|
def linear(middle, pos):
|
||||||
if pos <= middle:
|
if pos <= middle:
|
||||||
if middle < EPSILON:
|
if middle < EPSILON:
|
||||||
|
@ -38,25 +39,30 @@ def linear(middle, pos):
|
||||||
else:
|
else:
|
||||||
return 0.5 + 0.5 * pos / middle
|
return 0.5 + 0.5 * pos / middle
|
||||||
|
|
||||||
|
|
||||||
def curved(middle, pos):
|
def curved(middle, pos):
|
||||||
return pos ** (log(0.5) / log(max(middle, EPSILON)))
|
return pos ** (log(0.5) / log(max(middle, EPSILON)))
|
||||||
|
|
||||||
|
|
||||||
def sine(middle, pos):
|
def sine(middle, pos):
|
||||||
return (sin((-pi / 2.0) + pi * linear(middle, pos)) + 1.0) / 2.0
|
return (sin((-pi / 2.0) + pi * linear(middle, pos)) + 1.0) / 2.0
|
||||||
|
|
||||||
|
|
||||||
def sphere_increasing(middle, pos):
|
def sphere_increasing(middle, pos):
|
||||||
return sqrt(1.0 - (linear(middle, pos) - 1.0) ** 2)
|
return sqrt(1.0 - (linear(middle, pos) - 1.0) ** 2)
|
||||||
|
|
||||||
|
|
||||||
def sphere_decreasing(middle, pos):
|
def sphere_decreasing(middle, pos):
|
||||||
return 1.0 - sqrt(1.0 - linear(middle, pos) ** 2)
|
return 1.0 - sqrt(1.0 - linear(middle, pos) ** 2)
|
||||||
|
|
||||||
SEGMENTS = [ linear, curved, sine, sphere_increasing, sphere_decreasing ]
|
SEGMENTS = [linear, curved, sine, sphere_increasing, sphere_decreasing]
|
||||||
|
|
||||||
|
|
||||||
class GradientFile:
|
class GradientFile:
|
||||||
|
|
||||||
gradient = None
|
gradient = None
|
||||||
|
|
||||||
def getpalette(self, entries = 256):
|
def getpalette(self, entries=256):
|
||||||
|
|
||||||
palette = []
|
palette = []
|
||||||
|
|
||||||
|
@ -89,6 +95,7 @@ class GradientFile:
|
||||||
|
|
||||||
return b"".join(palette), "RGBA"
|
return b"".join(palette), "RGBA"
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# File handler for GIMP's gradient format.
|
# File handler for GIMP's gradient format.
|
||||||
|
|
||||||
|
@ -114,13 +121,13 @@ class GimpGradientFile(GradientFile):
|
||||||
s = fp.readline().split()
|
s = fp.readline().split()
|
||||||
w = [float(x) for x in s[:11]]
|
w = [float(x) for x in s[:11]]
|
||||||
|
|
||||||
x0, x1 = w[0], w[2]
|
x0, x1 = w[0], w[2]
|
||||||
xm = w[1]
|
xm = w[1]
|
||||||
rgb0 = w[3:7]
|
rgb0 = w[3:7]
|
||||||
rgb1 = w[7:11]
|
rgb1 = w[7:11]
|
||||||
|
|
||||||
segment = SEGMENTS[int(s[11])]
|
segment = SEGMENTS[int(s[11])]
|
||||||
cspace = int(s[12])
|
cspace = int(s[12])
|
||||||
|
|
||||||
if cspace != 0:
|
if cspace != 0:
|
||||||
raise IOError("cannot handle HSV colour space")
|
raise IOError("cannot handle HSV colour space")
|
||||||
|
|
|
@ -95,7 +95,6 @@ class TestImage(PillowTestCase):
|
||||||
self.assertEqual(len(palette[0]), 1024)
|
self.assertEqual(len(palette[0]), 1024)
|
||||||
self.assertEqual(palette[1], "RGBA")
|
self.assertEqual(palette[1], "RGBA")
|
||||||
|
|
||||||
|
|
||||||
def test_load_1_3_via_imagepalette(self):
|
def test_load_1_3_via_imagepalette(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
from PIL import ImagePalette
|
from PIL import ImagePalette
|
||||||
|
|
Loading…
Reference in New Issue
Block a user