layer is now a property
This commit is contained in:
parent
373afb692e
commit
9025bb3ec3
2 changed files with 28 additions and 11 deletions
|
|
@ -68,6 +68,8 @@ class Jp2k(Jp2kBox):
|
||||||
ignore_pclr_cmap_cdef : bool
|
ignore_pclr_cmap_cdef : bool
|
||||||
whether or not to ignore the pclr, cmap, or cdef boxes during any
|
whether or not to ignore the pclr, cmap, or cdef boxes during any
|
||||||
color transformation, defaults to False.
|
color transformation, defaults to False.
|
||||||
|
layer : int
|
||||||
|
zero-based number of quality layer to decode
|
||||||
verbose : bool
|
verbose : bool
|
||||||
whether or not to print informational messages produced by the
|
whether or not to print informational messages produced by the
|
||||||
OpenJPEG library, defaults to false
|
OpenJPEG library, defaults to false
|
||||||
|
|
@ -106,6 +108,7 @@ class Jp2k(Jp2kBox):
|
||||||
self._codec_format = None
|
self._codec_format = None
|
||||||
self._colorspace = None
|
self._colorspace = None
|
||||||
self._shape = None
|
self._shape = None
|
||||||
|
self._layer = 0
|
||||||
|
|
||||||
self._ignore_pclr_cmap_cdef = False
|
self._ignore_pclr_cmap_cdef = False
|
||||||
self._verbose = False
|
self._verbose = False
|
||||||
|
|
@ -122,6 +125,18 @@ class Jp2k(Jp2kBox):
|
||||||
def ignore_pclr_cmap_cdef(self, ignore_pclr_cmap_cdef):
|
def ignore_pclr_cmap_cdef(self, ignore_pclr_cmap_cdef):
|
||||||
self._ignore_pclr_cmap_cdef = ignore_pclr_cmap_cdef
|
self._ignore_pclr_cmap_cdef = ignore_pclr_cmap_cdef
|
||||||
|
|
||||||
|
@property
|
||||||
|
def layer(self):
|
||||||
|
return self._layer
|
||||||
|
|
||||||
|
@layer.setter
|
||||||
|
def layer(self, layer):
|
||||||
|
if version.openjpeg_version_tuple[0] < 2:
|
||||||
|
msg = "Layer property not supported unless the version of OpenJPEG "
|
||||||
|
msg += "is 2.0 or higher."
|
||||||
|
raise RuntimeError(msg)
|
||||||
|
self._layer = layer
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def verbose(self):
|
def verbose(self):
|
||||||
return self._verbose
|
return self._verbose
|
||||||
|
|
@ -1156,7 +1171,7 @@ class Jp2k(Jp2kBox):
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def _read_openjp2(self, rlevel=0, layer=0, area=None, tile=None, verbose=False):
|
def _read_openjp2(self, rlevel=0, layer=None, area=None, tile=None, verbose=False):
|
||||||
"""Read a JPEG 2000 image using libopenjp2.
|
"""Read a JPEG 2000 image using libopenjp2.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -1184,9 +1199,12 @@ class Jp2k(Jp2kBox):
|
||||||
RuntimeError
|
RuntimeError
|
||||||
If the image has differing subsample factors.
|
If the image has differing subsample factors.
|
||||||
"""
|
"""
|
||||||
|
if layer is not None:
|
||||||
|
self._layer = layer
|
||||||
|
|
||||||
self._subsampling_sanity_check()
|
self._subsampling_sanity_check()
|
||||||
|
|
||||||
self._populate_dparams(rlevel, layer=layer, tile=tile, area=area)
|
self._populate_dparams(rlevel, tile=tile, area=area)
|
||||||
|
|
||||||
with ExitStack() as stack:
|
with ExitStack() as stack:
|
||||||
if re.match("2.1", version.openjpeg_version):
|
if re.match("2.1", version.openjpeg_version):
|
||||||
|
|
@ -1231,13 +1249,11 @@ class Jp2k(Jp2kBox):
|
||||||
|
|
||||||
return img_array
|
return img_array
|
||||||
|
|
||||||
def _populate_dparams(self, rlevel, tile=None, layer=None, area=None):
|
def _populate_dparams(self, rlevel, tile=None, area=None):
|
||||||
"""Populate decompression structure with appropriate input parameters.
|
"""Populate decompression structure with appropriate input parameters.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
layer : int
|
|
||||||
Number of quality layer to decode.
|
|
||||||
rlevel : int
|
rlevel : int
|
||||||
Factor by which to rlevel output resolution.
|
Factor by which to rlevel output resolution.
|
||||||
area : tuple
|
area : tuple
|
||||||
|
|
@ -1263,8 +1279,7 @@ class Jp2k(Jp2kBox):
|
||||||
|
|
||||||
dparam.decod_format = self._codec_format
|
dparam.decod_format = self._codec_format
|
||||||
|
|
||||||
if layer is not None:
|
dparam.cp_layer = self._layer
|
||||||
dparam.cp_layer = layer
|
|
||||||
|
|
||||||
# Must check the specified rlevel against the maximum.
|
# Must check the specified rlevel against the maximum.
|
||||||
if rlevel != 0:
|
if rlevel != 0:
|
||||||
|
|
@ -1301,7 +1316,7 @@ class Jp2k(Jp2kBox):
|
||||||
|
|
||||||
self._dparams = dparam
|
self._dparams = dparam
|
||||||
|
|
||||||
def read_bands(self, rlevel=0, layer=0, area=None, tile=None,
|
def read_bands(self, rlevel=0, layer=None, area=None, tile=None,
|
||||||
verbose=False, ignore_pclr_cmap_cdef=False):
|
verbose=False, ignore_pclr_cmap_cdef=False):
|
||||||
"""Read a JPEG 2000 image.
|
"""Read a JPEG 2000 image.
|
||||||
|
|
||||||
|
|
@ -1348,7 +1363,9 @@ class Jp2k(Jp2kBox):
|
||||||
"functionality.")
|
"functionality.")
|
||||||
|
|
||||||
self.ignore_pclr_cmap_cdef = ignore_pclr_cmap_cdef
|
self.ignore_pclr_cmap_cdef = ignore_pclr_cmap_cdef
|
||||||
self._populate_dparams(rlevel, layer=layer, tile=tile, area=area)
|
if layer is not None:
|
||||||
|
self._layer = layer
|
||||||
|
self._populate_dparams(rlevel, tile=tile, area=area)
|
||||||
|
|
||||||
with ExitStack() as stack:
|
with ExitStack() as stack:
|
||||||
if re.match("2.1", version.openjpeg_version):
|
if re.match("2.1", version.openjpeg_version):
|
||||||
|
|
|
||||||
|
|
@ -1094,8 +1094,8 @@ class TestJp2k_1_x(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
with patch('glymur.version.openjpeg_version_tuple', new=(1, 5, 0)):
|
with patch('glymur.version.openjpeg_version_tuple', new=(1, 5, 0)):
|
||||||
j2k = Jp2k(self.j2kfile)
|
j2k = Jp2k(self.j2kfile)
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(RuntimeError):
|
||||||
j2k.read(layer=1)
|
j2k.layer = 1
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG)
|
@unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue