diff --git a/glymur/jp2k.py b/glymur/jp2k.py index 6a10616..1239821 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -695,6 +695,8 @@ 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. verbose : bool, optional Print informational messages produced by the OpenJPEG library. diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index 330f2bf..98173a0 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -95,8 +95,8 @@ class TestJp2k(unittest.TestCase): with self.assertRaises(IOError): Jp2k(filename) - def test_no_cxform(self): - """Indices for jpxfile if no color transform""" + def test_no_cxform_pclr(self): + """Indices for pclr jpxfile if no color transform""" j = Jp2k(self.jpxfile) rgb = j.read() idx = j.read(no_cxform=True) @@ -112,6 +112,21 @@ class TestJp2k(unittest.TestCase): rgb_from_idx[r, c] = palette[idx[r, c]] np.testing.assert_array_equal(rgb, rgb_from_idx) + def test_no_cxform_cmap(self): + """Bands as physically ordered, not as physically intended""" + # This file has the components physically reversed. The cmap box + # tells the decoder how to order them, but this flag prevents that. + filename = opj_data_file('input/conformance/file2.jp2') + j = Jp2k(filename) + ycbcr = j.read() + crcby = j.read(no_cxform=True) + + expected = np.zeros(ycbcr.shape, ycbcr.dtype) + for k in range(crcby.shape[2]): + expected[:,:,crcby.shape[2] - k - 1] = crcby[:,:,k] + + np.testing.assert_array_equal(ycbcr, expected) + def test_file_not_present(self): """Should error out if reading from a file that does not exist""" # Verify that we error out appropriately if not given an existing file