From 1be7c4ec50eba5caf32ec52df3198ce9e7298914 Mon Sep 17 00:00:00 2001 From: John Evans Date: Tue, 18 Mar 2014 11:00:35 -0400 Subject: [PATCH] Changing name to "ignore_pclr_cmap_cdef". #179 --- glymur/jp2k.py | 37 ++++++++++++++++------------- glymur/test/test_jp2k.py | 4 ++-- glymur/test/test_opj_suite_write.py | 2 +- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/glymur/jp2k.py b/glymur/jp2k.py index 1239821..f76163f 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -695,8 +695,9 @@ class Jp2k(Jp2kBox): (first_row, first_col, last_row, last_col) tile : int, optional Number of tile to decode. - no_cxform : bool - Whether or not to apply intended color transforms. + ignore_pclr_cmap_cdef : bool + Whether or not to ignore the pclr, cmap, or cdef boxes during any + color transformation. Defaults to False. verbose : bool, optional Print informational messages produced by the OpenJPEG library. @@ -751,7 +752,7 @@ class Jp2k(Jp2kBox): msg += "the read_bands method instead." raise RuntimeError(msg) - def _read_openjpeg(self, rlevel=0, no_cxform=False, verbose=False): + def _read_openjpeg(self, rlevel=0, ignore_pclr_cmap_cdef=False, verbose=False): """Read a JPEG 2000 image using libopenjpeg. Parameters @@ -759,8 +760,9 @@ class Jp2k(Jp2kBox): rlevel : int, optional Factor by which to rlevel output resolution. Use -1 to get the lowest resolution thumbnail. - no_cxform : bool - Whether or not to apply intended color transforms. + ignore_pclr_cmap_cdef : bool + Whether or not to ignore the pclr, cmap, or cdef boxes during any + color transformation. Defaults to False. verbose : bool, optional Print informational messages produced by the OpenJPEG library. @@ -796,7 +798,7 @@ class Jp2k(Jp2kBox): dparameters = opj.DecompressionParametersType() opj.set_default_decoder_parameters(ctypes.byref(dparameters)) - if no_cxform is True: + if ignore_pclr_cmap_cdef is True: # Return raw codestream components. dparameters.flags |= 1 @@ -844,7 +846,7 @@ class Jp2k(Jp2kBox): return data def _read_openjp2(self, rlevel=0, layer=0, area=None, tile=None, - verbose=False, no_cxform=False): + verbose=False, ignore_pclr_cmap_cdef=False): """Read a JPEG 2000 image using libopenjp2. Parameters @@ -874,7 +876,8 @@ class Jp2k(Jp2kBox): """ self._subsampling_sanity_check() - dparam = self._populate_dparam(layer, rlevel, area, tile, no_cxform) + dparam = self._populate_dparam(layer, rlevel, area, tile, + ignore_pclr_cmap_cdef) with ExitStack() as stack: if hasattr(opj2.OPENJP2, @@ -918,7 +921,7 @@ class Jp2k(Jp2kBox): return img_array - def _populate_dparam(self, layer, rlevel, area, tile, no_cxform): + def _populate_dparam(self, layer, rlevel, area, tile, ignore_pclr_cmap_cdef): """Populate decompression structure with appropriate input parameters. Parameters @@ -932,8 +935,9 @@ class Jp2k(Jp2kBox): (first_row, first_col, last_row, last_col) tile : int Number of tile to decode. - no_cxform : bool - Whether or not to apply intended color transforms. + ignore_pclr_cmap_cdef : bool + Whether or not to ignore the pclr, cmap, or cdef boxes during any + color transformation. Defaults to False. Returns ------- @@ -971,14 +975,14 @@ class Jp2k(Jp2kBox): dparam.tile_index = tile dparam.nb_tile_to_decode = 1 - if no_cxform is True: + if ignore_pclr_cmap_cdef is True: # Return raw codestream components. dparam.flags |= 1 return dparam def read_bands(self, rlevel=0, layer=0, area=None, tile=None, - verbose=False, no_cxform=False): + verbose=False, ignore_pclr_cmap_cdef=False): """Read a JPEG 2000 image. The only time you should use this method is when the image has @@ -996,8 +1000,9 @@ class Jp2k(Jp2kBox): (first_row, first_col, last_row, last_col) tile : int, optional Number of tile to decode. - no_cxform : bool - Whether or not to apply intended color transforms. + ignore_pclr_cmap_cdef : bool + Whether or not to ignore the pclr, cmap, or cdef boxes during any + color transformation. Defaults to False. verbose : bool, optional Print informational messages produced by the OpenJPEG library. @@ -1027,7 +1032,7 @@ class Jp2k(Jp2kBox): "of OpenJP2 installed before using " "this functionality.") - dparam = self._populate_dparam(layer, rlevel, area, tile, no_cxform) + dparam = self._populate_dparam(layer, rlevel, area, tile, ignore_pclr_cmap_cdef) with ExitStack() as stack: if hasattr(opj2.OPENJP2, diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index 98173a0..6a456f8 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -99,7 +99,7 @@ class TestJp2k(unittest.TestCase): """Indices for pclr jpxfile if no color transform""" j = Jp2k(self.jpxfile) rgb = j.read() - idx = j.read(no_cxform=True) + idx = j.read(ignore_pclr_cmap_cdef=True) self.assertEqual(rgb.shape, (1024, 1024, 3)) self.assertEqual(idx.shape, (1024, 1024)) @@ -119,7 +119,7 @@ class TestJp2k(unittest.TestCase): filename = opj_data_file('input/conformance/file2.jp2') j = Jp2k(filename) ycbcr = j.read() - crcby = j.read(no_cxform=True) + crcby = j.read(ignore_pclr_cmap_cdef=True) expected = np.zeros(ycbcr.shape, ycbcr.dtype) for k in range(crcby.shape[2]): diff --git a/glymur/test/test_opj_suite_write.py b/glymur/test/test_opj_suite_write.py index 1db11c4..3475906 100644 --- a/glymur/test/test_opj_suite_write.py +++ b/glymur/test/test_opj_suite_write.py @@ -224,7 +224,7 @@ class TestSuiteWriteCinema(unittest.TestCase): @unittest.skipIf(os.name == "nt", "Temporary file issue on window.") -@unittest.skipIf(re.match(r"""2\.0""", glymur.version.openjpeg_version), +@unittest.skipIf(not re.match(r"""(1.5|2.0)""", glymur.version.openjpeg_version), "Functionality implemented for 2.1") @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_OPJ_DATA_ROOT environment variable not set")