mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
improve color cube parser
This commit is contained in:
parent
c1b956e3c8
commit
805dc44707
|
@ -300,7 +300,6 @@ class TestColorLut3DFilter(PillowTestCase):
|
|||
def test_from_cube_file_minimal(self):
|
||||
lut = ImageFilter.Color3DLUT.from_cube_file([
|
||||
"LUT_3D_SIZE 2",
|
||||
"",
|
||||
"0 0 0.031",
|
||||
"0.96 0 0.031",
|
||||
"0 1 0.031",
|
||||
|
@ -321,6 +320,7 @@ class TestColorLut3DFilter(PillowTestCase):
|
|||
'TITLE "LUT name from file"',
|
||||
" LUT_3D_SIZE 2 3 4",
|
||||
" SKIP THIS",
|
||||
"",
|
||||
" # Comment",
|
||||
"CHANNELS 4",
|
||||
"",
|
||||
|
@ -343,25 +343,30 @@ class TestColorLut3DFilter(PillowTestCase):
|
|||
with self.assertRaisesRegexp(ValueError, "No size found"):
|
||||
lut = ImageFilter.Color3DLUT.from_cube_file([
|
||||
'TITLE "LUT name from file"',
|
||||
"",
|
||||
] + [
|
||||
"0 0 0.031",
|
||||
"0.96 0 0.031",
|
||||
] * 3)
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "number of colors on line 4"):
|
||||
with self.assertRaisesRegexp(ValueError, "number of colors on line 3"):
|
||||
lut = ImageFilter.Color3DLUT.from_cube_file([
|
||||
'LUT_3D_SIZE 2',
|
||||
"",
|
||||
] + [
|
||||
"0 0 0.031",
|
||||
"0.96 0 0.031 1",
|
||||
] * 3)
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "Not a number on line 3"):
|
||||
with self.assertRaisesRegexp(ValueError, "1D LUT cube files"):
|
||||
lut = ImageFilter.Color3DLUT.from_cube_file([
|
||||
'LUT_1D_SIZE 2',
|
||||
] + [
|
||||
"0 0 0.031",
|
||||
"0.96 0 0.031 1",
|
||||
])
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "Not a number on line 2"):
|
||||
lut = ImageFilter.Color3DLUT.from_cube_file([
|
||||
'LUT_3D_SIZE 2',
|
||||
"",
|
||||
] + [
|
||||
"0 green 0.031",
|
||||
"0.96 0 0.031",
|
||||
|
@ -371,7 +376,6 @@ class TestColorLut3DFilter(PillowTestCase):
|
|||
with NamedTemporaryFile('w+t', delete=False) as f:
|
||||
f.write(
|
||||
"LUT_3D_SIZE 2\n"
|
||||
"\n"
|
||||
"0 0 0.031\n"
|
||||
"0.96 0 0.031\n"
|
||||
"0 1 0.031\n"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#
|
||||
|
||||
import functools
|
||||
from itertools import chain
|
||||
|
||||
from ._util import isPath
|
||||
|
||||
|
@ -402,8 +403,6 @@ class Color3DLUT(MultibandFilter):
|
|||
|
||||
for i, line in enumerate(iterator, 1):
|
||||
line = line.strip()
|
||||
if not line:
|
||||
break
|
||||
if line.startswith('TITLE "'):
|
||||
name = line.split('"')[1]
|
||||
continue
|
||||
|
@ -414,12 +413,22 @@ class Color3DLUT(MultibandFilter):
|
|||
continue
|
||||
if line.startswith('CHANNELS '):
|
||||
channels = int(line.split()[1])
|
||||
if line.startswith('LUT_1D_SIZE '):
|
||||
raise ValueError("1D LUT cube files aren't supported.")
|
||||
|
||||
try:
|
||||
float(line.partition(' ')[0])
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
# Data starts
|
||||
break
|
||||
|
||||
if size is None:
|
||||
raise ValueError('No size found in the file')
|
||||
|
||||
table = []
|
||||
for i, line in enumerate(iterator, i + 1):
|
||||
for i, line in enumerate(chain([line], iterator), i):
|
||||
line = line.strip()
|
||||
if not line or line.startswith('#'):
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue
Block a user