Merge branch 'issue198' into devel
This commit is contained in:
commit
baba6c9bc5
3 changed files with 22 additions and 12 deletions
|
|
@ -33,6 +33,7 @@ from .core import _COLOR_TYPE_MAP_DISPLAY
|
||||||
from .core import SRGB, GREYSCALE, YCC
|
from .core import SRGB, GREYSCALE, YCC
|
||||||
from .core import ENUMERATED_COLORSPACE, RESTRICTED_ICC_PROFILE
|
from .core import ENUMERATED_COLORSPACE, RESTRICTED_ICC_PROFILE
|
||||||
from .core import ANY_ICC_PROFILE, VENDOR_COLOR_METHOD
|
from .core import ANY_ICC_PROFILE, VENDOR_COLOR_METHOD
|
||||||
|
from .core import _Keydefaultdict
|
||||||
|
|
||||||
from . import _uuid_io
|
from . import _uuid_io
|
||||||
|
|
||||||
|
|
@ -42,14 +43,12 @@ _METHOD_DISPLAY = {
|
||||||
ANY_ICC_PROFILE: 'any ICC profile',
|
ANY_ICC_PROFILE: 'any ICC profile',
|
||||||
VENDOR_COLOR_METHOD: 'vendor color method'}
|
VENDOR_COLOR_METHOD: 'vendor color method'}
|
||||||
|
|
||||||
_APPROX_DISPLAY = {1: 'accurately represents correct colorspace definition',
|
_factory = lambda x: '{0} (invalid)'.format(x)
|
||||||
2: 'approximates correct colorspace definition, '
|
_APPROX_DISPLAY = _Keydefaultdict(_factory,
|
||||||
+ 'exceptional quality',
|
{1: 'accurately represents correct colorspace definition',
|
||||||
3: 'approximates correct colorspace definition, '
|
2: 'approximates correct colorspace definition, exceptional quality',
|
||||||
+ 'reasonable quality',
|
3: 'approximates correct colorspace definition, reasonable quality',
|
||||||
4: 'approximates correct colorspace definition, '
|
4: 'approximates correct colorspace definition, poor quality'})
|
||||||
+ 'poor quality'}
|
|
||||||
|
|
||||||
|
|
||||||
class Jp2kBox(object):
|
class Jp2kBox(object):
|
||||||
"""Superclass for JPEG 2000 boxes.
|
"""Superclass for JPEG 2000 boxes.
|
||||||
|
|
@ -301,13 +300,19 @@ class ColourSpecificationBox(Jp2kBox):
|
||||||
approximation=0, colorspace=None, icc_profile=None,
|
approximation=0, colorspace=None, icc_profile=None,
|
||||||
length=0, offset=-1):
|
length=0, offset=-1):
|
||||||
Jp2kBox.__init__(self, box_id='colr', longname='Colour Specification')
|
Jp2kBox.__init__(self, box_id='colr', longname='Colour Specification')
|
||||||
|
|
||||||
self.method = method
|
self.method = method
|
||||||
self.precedence = precedence
|
self.precedence = precedence
|
||||||
|
|
||||||
|
if approximation not in (0, 1, 2, 3, 4):
|
||||||
|
warnings.warn("Invalid approximation: {0}".format(approximation))
|
||||||
self.approximation = approximation
|
self.approximation = approximation
|
||||||
|
|
||||||
self.colorspace = colorspace
|
self.colorspace = colorspace
|
||||||
self.icc_profile = icc_profile
|
self.icc_profile = icc_profile
|
||||||
self.length = length
|
self.length = length
|
||||||
self.offset = offset
|
self.offset = offset
|
||||||
|
|
||||||
self._validate()
|
self._validate()
|
||||||
|
|
||||||
def _validate(self):
|
def _validate(self):
|
||||||
|
|
@ -316,8 +321,6 @@ class ColourSpecificationBox(Jp2kBox):
|
||||||
raise IOError("colorspace and icc_profile cannot both be set.")
|
raise IOError("colorspace and icc_profile cannot both be set.")
|
||||||
if self.method not in (1, 2, 3, 4):
|
if self.method not in (1, 2, 3, 4):
|
||||||
raise IOError("Invalid method.")
|
raise IOError("Invalid method.")
|
||||||
if self.approximation not in (0, 1, 2, 3, 4):
|
|
||||||
raise IOError("Invalid approximation.")
|
|
||||||
|
|
||||||
def _write_validate(self):
|
def _write_validate(self):
|
||||||
"""In addition to constructor validation steps, run validation steps
|
"""In addition to constructor validation steps, run validation steps
|
||||||
|
|
|
||||||
|
|
@ -455,10 +455,10 @@ class TestColourSpecificationBox(unittest.TestCase):
|
||||||
method=method)
|
method=method)
|
||||||
|
|
||||||
def test_colr_with_bad_approx(self):
|
def test_colr_with_bad_approx(self):
|
||||||
"""colr must have a valid approximation field"""
|
"""colr should have a valid approximation field"""
|
||||||
colorspace = glymur.core.SRGB
|
colorspace = glymur.core.SRGB
|
||||||
approx = -1
|
approx = -1
|
||||||
with self.assertRaises(IOError):
|
with self.assertWarns(UserWarning):
|
||||||
glymur.jp2box.ColourSpecificationBox(colorspace=colorspace,
|
glymur.jp2box.ColourSpecificationBox(colorspace=colorspace,
|
||||||
approximation=approx)
|
approximation=approx)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -758,6 +758,13 @@ class TestJp2k_2_1(unittest.TestCase):
|
||||||
class TestJp2kOpjDataRoot(unittest.TestCase):
|
class TestJp2kOpjDataRoot(unittest.TestCase):
|
||||||
"""These tests should be run by just about all configuration."""
|
"""These tests should be run by just about all configuration."""
|
||||||
|
|
||||||
|
@unittest.skipIf(sys.hexversion < 0x03000000, "Test requires Python 3.3+")
|
||||||
|
def test_invalid_approximation(self):
|
||||||
|
"""Should warn in case of invalid approximation."""
|
||||||
|
filename = opj_data_file('input/nonregression/edf_c2_1015644.jp2')
|
||||||
|
with self.assertWarns(UserWarning):
|
||||||
|
jp2 = Jp2k(filename)
|
||||||
|
|
||||||
@unittest.skipIf(sys.hexversion < 0x03000000, "Test requires Python 3.3+")
|
@unittest.skipIf(sys.hexversion < 0x03000000, "Test requires Python 3.3+")
|
||||||
def test_invalid_colorspace(self):
|
def test_invalid_colorspace(self):
|
||||||
"""Should warn in case of invalid colorspace."""
|
"""Should warn in case of invalid colorspace."""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue