From 0eb58e4ae48a44edbea4954e18b868dcbb412bf3 Mon Sep 17 00:00:00 2001 From: John Evans Date: Sat, 10 Aug 2013 07:12:31 -0400 Subject: [PATCH] pylint work, #99 --- glymur/jp2k.py | 54 ++++++++++++-------------------- glymur/lib/openjp2.py | 1 - glymur/lib/test/__init__.py | 4 ++- glymur/lib/test/test_openjpeg.py | 49 ++++++++++++++--------------- 4 files changed, 47 insertions(+), 61 deletions(-) diff --git a/glymur/jp2k.py b/glymur/jp2k.py index 0785178..75eca03 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -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 diff --git a/glymur/lib/openjp2.py b/glymur/lib/openjp2.py index 66a3cba..468bb51 100644 --- a/glymur/lib/openjp2.py +++ b/glymur/lib/openjp2.py @@ -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) diff --git a/glymur/lib/test/__init__.py b/glymur/lib/test/__init__.py index 5aea3ab..47a3d86 100644 --- a/glymur/lib/test/__init__.py +++ b/glymur/lib/test/__init__.py @@ -1 +1,3 @@ -#from .test_openjp2 import TestOpenJP2 as openjp2 +""" +Test suite for openjp2, openjpeg low-level functionality. +""" diff --git a/glymur/lib/test/test_openjpeg.py b/glymur/lib/test/test_openjpeg.py index 3dc7628..5363a1f 100644 --- a/glymur/lib/test/test_openjpeg.py +++ b/glymur/lib/test/test_openjpeg.py @@ -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)