pylint work, #99
This commit is contained in:
parent
bf24e9b280
commit
0eb58e4ae4
4 changed files with 47 additions and 61 deletions
|
|
@ -187,8 +187,6 @@ class Jp2k(Jp2kBox):
|
|||
msg += "profile if the file type box brand is 'jp2 '."
|
||||
warnings.warn(msg)
|
||||
|
||||
#def _populate_cparams(self, cbsize, cratios, eph, grid_offset, modesw,
|
||||
# numres, prog, psnr, psizes, sop, subsam, tilesize):
|
||||
def _populate_cparams(self, **kwargs):
|
||||
"""Populate compression parameters structure from input arguments.
|
||||
|
||||
|
|
@ -374,36 +372,6 @@ class Jp2k(Jp2kBox):
|
|||
msg = "Only uint8 and uint16 images are currently supported."
|
||||
raise RuntimeError(msg)
|
||||
|
||||
def _set_multi_component_transform(self, colorspace, cparams, mct=None):
|
||||
"""Set multi component transform usage.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
colorspace : int
|
||||
Either CLRSPC_SRGB or CLRSPC_GRAY
|
||||
cparams : CompressionParametersType(ctypes.Structure)
|
||||
Corresponds to cparameters_t type in openjp2 headers.
|
||||
mct : bool, optional
|
||||
Specifies usage of the multi component transform. If not
|
||||
specified, defaults to True if the colorspace is RGB.
|
||||
"""
|
||||
if mct is None:
|
||||
# If the multi component transform was not specified, we infer
|
||||
# that it should be used if the color space is RGB.
|
||||
if colorspace == _opj2.CLRSPC_SRGB:
|
||||
cparams.tcp_mct = 1
|
||||
else:
|
||||
cparams.tcp_mct = 0
|
||||
else:
|
||||
# MCT was specified. Does it make sense?
|
||||
if mct and colorspace == _opj2.CLRSPC_GRAY:
|
||||
# Cannot check for this in the validate routine, as we need
|
||||
# to know what the target colorspace has been determined to be.
|
||||
msg = "Cannot specify usage of the multi component transform "
|
||||
msg += "if the colorspace is gray."
|
||||
raise IOError(msg)
|
||||
cparams.tcp_mct = 1 if mct else 0
|
||||
|
||||
def _process_write_inputs(self, img_array, colorspace=None, **kwargs):
|
||||
"""Directs processing of write method arguments.
|
||||
|
||||
|
|
@ -414,6 +382,10 @@ class Jp2k(Jp2kBox):
|
|||
|
||||
Parameters
|
||||
----------
|
||||
img_array : ndarray
|
||||
Image data to be written to file.
|
||||
colorspace : str, optional
|
||||
Either 'rgb' or 'gray'.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -421,6 +393,9 @@ class Jp2k(Jp2kBox):
|
|||
Corresponds to cparameters_t type in openjp2 headers.
|
||||
colorspace : int
|
||||
Either CLRSPC_SRGB or CLRSPC_GRAY
|
||||
mct : bool, optional
|
||||
Specifies usage of the multi component transform. If not
|
||||
specified, defaults to True if the colorspace is RGB.
|
||||
"""
|
||||
|
||||
if 'cratios' in kwargs and 'psnr' in kwargs:
|
||||
|
|
@ -434,9 +409,20 @@ class Jp2k(Jp2kBox):
|
|||
|
||||
try:
|
||||
mct = kwargs['mct']
|
||||
if mct and colorspace == _opj2.CLRSPC_GRAY:
|
||||
# Cannot check for this in the validate routine, as we need
|
||||
# to know what the target colorspace has been determined to be.
|
||||
msg = "Cannot specify usage of the multi component transform "
|
||||
msg += "if the colorspace is gray."
|
||||
raise IOError(msg)
|
||||
cparams.tcp_mct = 1 if mct else 0
|
||||
except KeyError:
|
||||
mct = None
|
||||
self._set_multi_component_transform(colorspace, cparams, mct)
|
||||
# If the multi component transform was not specified, we infer
|
||||
# that it should be used if the color space is RGB.
|
||||
if colorspace == _opj2.CLRSPC_SRGB:
|
||||
cparams.tcp_mct = 1
|
||||
else:
|
||||
cparams.tcp_mct = 0
|
||||
|
||||
return cparams, colorspace
|
||||
|
||||
|
|
|
|||
|
|
@ -1381,7 +1381,6 @@ def write_tile(codec, tile_index, data, data_size, stream):
|
|||
|
||||
def set_error_message(msg):
|
||||
"""The openjpeg error handler has recorded an error message."""
|
||||
global ERROR_MSG_LST
|
||||
ERROR_MSG_LST.append(msg)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1,3 @@
|
|||
#from .test_openjp2 import TestOpenJP2 as openjp2
|
||||
"""
|
||||
Test suite for openjp2, openjpeg low-level functionality.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
#pylint: disable-all
|
||||
"""
|
||||
Tests for OpenJPEG module.
|
||||
"""
|
||||
import ctypes
|
||||
import re
|
||||
import sys
|
||||
|
|
@ -10,43 +12,40 @@ else:
|
|||
|
||||
import glymur
|
||||
|
||||
# pylint: disable=E1101,R0904
|
||||
|
||||
@unittest.skipIf(glymur.lib._openjpeg.OPENJPEG is None,
|
||||
@unittest.skipIf(glymur.lib.openjpeg.OPENJPEG is None,
|
||||
"Missing openjpeg library.")
|
||||
class TestOpenJPEG(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
"""Test suite for openjpeg functions we choose to expose."""
|
||||
|
||||
def test_version(self):
|
||||
version = glymur.lib._openjpeg.version()
|
||||
"""Only versions 1.3, 1.4, and 1.5 are supported."""
|
||||
version = glymur.lib.openjpeg.version()
|
||||
regex = re.compile('1.[345].[0-9]')
|
||||
if sys.hexversion <= 0x03020000:
|
||||
self.assertRegexpMatches(version, regex)
|
||||
else:
|
||||
self.assertRegex(version, regex)
|
||||
|
||||
def test_set_default_decoder_parameters(self):
|
||||
# Verify that we properly set the default decode parameters.
|
||||
version = glymur.lib._openjpeg.version()
|
||||
def test_default_decoder_parameters(self):
|
||||
"""Verify that we properly set the default decode parameters."""
|
||||
version = glymur.lib.openjpeg.version()
|
||||
minor = int(version.split('.')[1])
|
||||
|
||||
dp = glymur.lib._openjpeg.DecompressionParametersType()
|
||||
glymur.lib._openjpeg.set_default_decoder_parameters(ctypes.byref(dp))
|
||||
dcp = glymur.lib.openjpeg.DecompressionParametersType()
|
||||
glymur.lib.openjpeg.set_default_decoder_parameters(ctypes.byref(dcp))
|
||||
|
||||
self.assertEqual(dp.cp_reduce, 0)
|
||||
self.assertEqual(dp.cp_layer, 0)
|
||||
self.assertEqual(dp.infile, b'')
|
||||
self.assertEqual(dp.outfile, b'')
|
||||
self.assertEqual(dp.decod_format, -1)
|
||||
self.assertEqual(dp.cod_format, -1)
|
||||
self.assertEqual(dp.jpwl_correct, 0)
|
||||
self.assertEqual(dp.jpwl_exp_comps, 0)
|
||||
self.assertEqual(dp.jpwl_max_tiles, 0)
|
||||
self.assertEqual(dp.cp_limit_decoding, 0)
|
||||
self.assertEqual(dcp.cp_reduce, 0)
|
||||
self.assertEqual(dcp.cp_layer, 0)
|
||||
self.assertEqual(dcp.infile, b'')
|
||||
self.assertEqual(dcp.outfile, b'')
|
||||
self.assertEqual(dcp.decod_format, -1)
|
||||
self.assertEqual(dcp.cod_format, -1)
|
||||
self.assertEqual(dcp.jpwl_correct, 0)
|
||||
self.assertEqual(dcp.jpwl_exp_comps, 0)
|
||||
self.assertEqual(dcp.jpwl_max_tiles, 0)
|
||||
self.assertEqual(dcp.cp_limit_decoding, 0)
|
||||
if minor > 4:
|
||||
# Introduced in 1.5.x
|
||||
self.assertEqual(dp.flags, 0)
|
||||
self.assertEqual(dcp.flags, 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue