diff --git a/glymur/data/nemo.jp2 b/glymur/data/nemo.jp2 index 2bb8638..55d199c 100644 Binary files a/glymur/data/nemo.jp2 and b/glymur/data/nemo.jp2 differ diff --git a/glymur/jp2k.py b/glymur/jp2k.py index 4a62021..2fd3dea 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -203,7 +203,7 @@ class Jp2k(Jp2kBox): >>> import glymur >>> jfile = glymur.data.nemo() >>> jp2 = glymur.Jp2k(jfile) - >>> data = jp2.read(reduce=3) + >>> data = jp2.read(reduce=1) >>> from tempfile import NamedTemporaryFile >>> tfile = NamedTemporaryFile(suffix='.jp2', delete=False) >>> j = Jp2k(tfile.name, mode='wb') @@ -587,7 +587,7 @@ class Jp2k(Jp2kBox): >>> thumbnail = jp.read(reduce=-1) >>> thumbnail.shape - (46, 81, 3) + (728, 1296, 3) """ if opj2._OPENJP2 is not None: img_array = self._read_openjp2(**kwargs) @@ -930,14 +930,14 @@ class Jp2k(Jp2kBox): -------- >>> import glymur >>> jfile = glymur.data.nemo() - >>> jp = glymur.Jp2k(jfile) - >>> codestream = jp.get_codestream() + >>> jp2 = glymur.Jp2k(jfile) + >>> codestream = jp2.get_codestream() >>> print(codestream.segment[1]) SIZ marker segment @ (3137, 47) Profile: 2 Reference Grid Height, Width: (1456 x 2592) Vertical, Horizontal Reference Grid Offset: (0 x 0) - Reference Tile Height, Width: (512 x 512) + Reference Tile Height, Width: (1456 x 2592) Vertical, Horizontal Reference Tile Offset: (0 x 0) Bitdepth: (8, 8, 8) Signed: (False, False, False) diff --git a/glymur/test/test_callbacks.py b/glymur/test/test_callbacks.py index 9a1250b..331e20e 100644 --- a/glymur/test/test_callbacks.py +++ b/glymur/test/test_callbacks.py @@ -21,8 +21,8 @@ class TestCallbacks(unittest.TestCase): # Save sys.stdout. self.stdout = sys.stdout sys.stdout = StringIO() - self.jp2file = pkg_resources.resource_filename(glymur.__name__, - "data/nemo.jp2") + self.jp2file = glymur.data.nemo() + self.j2kfile = glymur.data.goodstuff() def tearDown(self): # Restore stdout. @@ -44,20 +44,16 @@ class TestCallbacks(unittest.TestCase): def test_info_warning_callbacks_on_read(self): # Verify that we get the expected stdio output when our internal info # callback handler is enabled. - j = glymur.Jp2k(self.jp2file) - d = j.read(reduce=3, verbose=True, area=(0, 0, 512, 1024)) + j = glymur.Jp2k(self.j2kfile) + d = j.read(reduce=1, verbose=True, area=(0, 0, 200, 150)) actual = sys.stdout.getvalue().strip() - lines = ['[INFO] Start to read j2k main header (3135).', + lines = ['[INFO] Start to read j2k main header (0).', '[INFO] Main header has been correctly decoded.', - '[INFO] Setting decoding area to 0,0,1024,512', - '[INFO] Header of tile 0 / 17 has been read.', - '[INFO] Tile 1/18 has been decoded.', - '[INFO] Image data has been updated with tile 1.', - '[INFO] Header of tile 1 / 17 has been read.', - '[INFO] Tile 2/18 has been decoded.', - '[INFO] Image data has been updated with tile 2.', - '[INFO] Stream reached its end !'] + '[INFO] Setting decoding area to 0,0,150,200', + '[INFO] Header of tile 0 / 0 has been read.', + '[INFO] Tile 1/1 has been decoded.', + '[INFO] Image data has been updated with tile 1.'] expected = '\n'.join(lines) self.assertEqual(actual, expected) diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index d9549c5..f2da55f 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -74,10 +74,8 @@ class TestJp2k(unittest.TestCase): os.unlink(cls._bad_xml_file) def setUp(self): - self.jp2file = pkg_resources.resource_filename(glymur.__name__, - "data/nemo.jp2") - self.j2kfile = pkg_resources.resource_filename(glymur.__name__, - "data/goodstuff.j2k") + self.jp2file = glymur.data.nemo() + self.j2kfile = glymur.data.goodstuff() def tearDown(self): pass @@ -92,11 +90,11 @@ class TestJp2k(unittest.TestCase): def test_reduce_max(self): # Verify that reduce=-1 gets us the lowest resolution image - j = Jp2k(self.jp2file) + j = Jp2k(self.j2kfile) thumbnail1 = j.read(reduce=-1) thumbnail2 = j.read(reduce=5) np.testing.assert_array_equal(thumbnail1, thumbnail2) - self.assertEqual(thumbnail1.shape, (46, 81, 3)) + self.assertEqual(thumbnail1.shape, (25, 15, 3)) def test_invalid_xml_box(self): # Should be able to recover from xml box with bad xml. @@ -145,15 +143,6 @@ class TestJp2k(unittest.TestCase): filename = 'this file does not actually exist on the file system.' jp2k = Jp2k(filename) - def test_nemo_tile(self): - # Issue 134, trouble reading first nemo tile. - j = Jp2k(self.jp2file) - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - tiledata = j.read(tile=0) - subsetdata = j.read(area=(0, 0, 512, 512)) - np.testing.assert_array_equal(tiledata, subsetdata) - def test_write_srgb_without_mct(self): j2k = Jp2k(self.j2kfile) expdata = j2k.read() @@ -178,7 +167,7 @@ class TestJp2k(unittest.TestCase): def test_write_cprl(self): # Issue 17 j = Jp2k(self.jp2file) - expdata = j.read(reduce=2) + expdata = j.read(reduce=1) with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: ofile = Jp2k(tfile.name, 'wb') ofile.write(expdata, prog='CPRL') @@ -220,7 +209,7 @@ class TestJp2k(unittest.TestCase): self.assertEqual(jp2k.box[5].id, 'jp2c') self.assertEqual(jp2k.box[5].offset, 3127) - self.assertEqual(jp2k.box[5].length, 1133427) + self.assertEqual(jp2k.box[5].length, 1132296) # jp2h super box self.assertEqual(len(jp2k.box[2].box), 2) @@ -540,7 +529,7 @@ class TestJp2k(unittest.TestCase): def test_asoc_label_box(self): # Construct a fake file with an asoc and a label box, as # OpenJPEG doesn't have such a file. - data = Jp2k(self.jp2file).read(reduce=3) + data = Jp2k(self.jp2file).read(reduce=1) with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: j = Jp2k(tfile.name, 'wb') j.write(data) diff --git a/glymur/test/test_opj_suite_neg.py b/glymur/test/test_opj_suite_neg.py index 5754e16..78d6154 100644 --- a/glymur/test/test_opj_suite_neg.py +++ b/glymur/test/test_opj_suite_neg.py @@ -65,8 +65,8 @@ def read_image(infile): class TestSuiteNegative(unittest.TestCase): def setUp(self): - self.jp2file = pkg_resources.resource_filename(glymur.__name__, - "data/nemo.jp2") + self.jp2file = glymur.data.nemo() + self.j2kfile = glymur.data.goodstuff() def tearDown(self): pass @@ -156,8 +156,8 @@ class TestSuiteNegative(unittest.TestCase): def test_precinct_size_not_multiple_of_two(self): # Seems like precinct sizes should be powers of two. - ifile = Jp2k(self.jp2file) - data = ifile.read(reduce=3) + ifile = Jp2k(self.j2kfile) + data = ifile.read(reduce=2) with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: ofile = Jp2k(tfile.name, 'wb') with self.assertRaises(IOError) as ce: @@ -165,8 +165,8 @@ class TestSuiteNegative(unittest.TestCase): def test_codeblock_size_not_multiple_of_two(self): # Seems like code block sizes should be powers of two. - ifile = Jp2k(self.jp2file) - data = ifile.read(reduce=3) + ifile = Jp2k(self.j2kfile) + data = ifile.read(reduce=2) with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: ofile = Jp2k(tfile.name, 'wb') with self.assertRaises(IOError) as ce: @@ -175,8 +175,8 @@ class TestSuiteNegative(unittest.TestCase): def test_codeblock_size_with_precinct_size(self): # Seems like code block sizes should never exceed half that of # precinct size. - ifile = Jp2k(self.jp2file) - data = ifile.read(reduce=3) + ifile = Jp2k(self.j2kfile) + data = ifile.read(reduce=2) with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: ofile = Jp2k(tfile.name, 'wb') with self.assertRaises(IOError) as ce: diff --git a/glymur/test/test_printing.py b/glymur/test/test_printing.py index 4090a2d..5b93e09 100644 --- a/glymur/test/test_printing.py +++ b/glymur/test/test_printing.py @@ -34,7 +34,7 @@ class TestPrintingNeedsLib(unittest.TestCase): with tempfile.NamedTemporaryFile(suffix='.jp2', delete=False) as tfile: cls._plain_nemo_file = tfile.name ijfile = Jp2k(jp2file) - data = ijfile.read(reduce=3) + data = ijfile.read(reduce=1) ojfile = Jp2k(cls._plain_nemo_file, 'wb') ojfile.write(data) @@ -43,8 +43,9 @@ class TestPrintingNeedsLib(unittest.TestCase): os.unlink(cls._plain_nemo_file) def setUp(self): - self.jp2file = pkg_resources.resource_filename(glymur.__name__, - "data/nemo.jp2") + self.jp2file = glymur.data.nemo() + self.j2kfile = glymur.data.goodstuff() + # Save sys.stdout. self.stdout = sys.stdout sys.stdout = StringIO() @@ -57,7 +58,7 @@ class TestPrintingNeedsLib(unittest.TestCase): " Compatibility: ['jp2 ']", 'JP2 Header Box (jp2h) @ (32, 45)', ' Image Header Box (ihdr) @ (40, 22)', - ' Size: [182 324 3]', + ' Size: [728 1296 3]', ' Bitdepth: 8', ' Signed: False', ' Compression: wavelet', @@ -66,15 +67,15 @@ class TestPrintingNeedsLib(unittest.TestCase): ' Method: enumerated colorspace', ' Precedence: 0', ' Colorspace: sRGB', - 'Contiguous Codestream Box (jp2c) @ (77, 112814)', + 'Contiguous Codestream Box (jp2c) @ (77, 1632355)', ' Main header:', ' SOC marker segment @ (85, 0)', ' SIZ marker segment @ (87, 47)', ' Profile: 2', - ' Reference Grid Height, Width: (182 x 324)', + ' Reference Grid Height, Width: (728 x 1296)', ' Vertical, Horizontal Reference Grid Offset: ' + '(0 x 0)', - ' Reference Tile Height, Width: (182 x 324)', + ' Reference Tile Height, Width: (728 x 1296)', ' Vertical, Horizontal Reference Tile Offset: ' + '(0 x 0)', ' Bitdepth: (8, 8, 8)', @@ -121,7 +122,7 @@ class TestPrintingNeedsLib(unittest.TestCase): def test_asoc_label_box(self): # Construct a fake file with an asoc and a label box, as # OpenJPEG doesn't have such a file. - data = glymur.Jp2k(self.jp2file).read(reduce=3) + data = glymur.Jp2k(self.jp2file).read(reduce=1) with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: j = glymur.Jp2k(tfile.name, 'wb') j.write(data) @@ -177,7 +178,7 @@ class TestPrintingNeedsLib(unittest.TestCase): lst = actual.split('\n') lst = lst[1:] actual = '\n'.join(lst) - + self.maxDiff = None self.assertEqual(actual, self.expectedPlain) def test_entire_file(self): @@ -209,15 +210,15 @@ class TestPrinting(unittest.TestCase): def test_COC_segment(self): j = glymur.Jp2k(self.jp2file) codestream = j.get_codestream(header_only=False) - print(codestream.segment[5]) + print(codestream.segment[6]) actual = sys.stdout.getvalue().strip() - lines = ['COC marker segment @ (3233, 9)', + lines = ['COC marker segment @ (3260, 9)', ' Associated component: 1', ' Coding style for this component: ' + 'Entropy coder, PARTITION = 0', ' Coding style parameters:', - ' Number of resolutions: 6', + ' Number of resolutions: 2', ' Code block height, width: (64 x 64)', ' Wavelet transform: 5-3 reversible', ' Code block context:', @@ -230,6 +231,7 @@ class TestPrinting(unittest.TestCase): ' Segmentation symbols: False'] expected = '\n'.join(lines) + self.maxDiff = None self.assertEqual(actual, expected) def test_COD_segment(self): @@ -245,10 +247,10 @@ class TestPrinting(unittest.TestCase): ' EPH marker segments: False', ' Coding style parameters:', ' Progression order: LRCP', - ' Number of layers: 3', + ' Number of layers: 2', ' Multiple component transformation usage: ' + 'reversible', - ' Number of resolutions: 6', + ' Number of resolutions: 2', ' Code block height, width: (64 x 64)', ' Wavelet transform: 5-3 reversible', ' Precinct size: default, 2^15 x 2^15', @@ -392,7 +394,7 @@ class TestPrinting(unittest.TestCase): print(codestream.segment[-1]) actual = sys.stdout.getvalue().strip() - lines = ['EOC marker segment @ (1136552, 0)'] + lines = ['EOC marker segment @ (1135421, 0)'] expected = '\n'.join(lines) self.assertEqual(actual, expected) @@ -476,15 +478,13 @@ class TestPrinting(unittest.TestCase): def test_QCC_segment(self): j = glymur.Jp2k(self.jp2file) codestream = j.get_codestream(header_only=False) - print(codestream.segment[6]) + print(codestream.segment[7]) actual = sys.stdout.getvalue().strip() - lines = ['QCC marker segment @ (3244, 20)', + lines = ['QCC marker segment @ (3271, 8)', ' Associated Component: 1', ' Quantization style: no quantization, 2 guard bits', - ' Step size: [(0, 8), (0, 9), (0, 9), (0, 10), (0, 9), ' - + '(0, 9), (0, 10), (0, 9), (0, 9), (0, 10), (0, 9), (0, 9), ' - + '(0, 10), (0, 9), (0, 9), (0, 10)]'] + ' Step size: [(0, 8), (0, 9), (0, 9), (0, 10)]'] expected = '\n'.join(lines) self.assertEqual(actual, expected) @@ -495,11 +495,9 @@ class TestPrinting(unittest.TestCase): print(codestream.segment[3]) actual = sys.stdout.getvalue().strip() - lines = ['QCD marker segment @ (3200, 19)', + lines = ['QCD marker segment @ (3200, 7)', ' Quantization style: no quantization, 2 guard bits', - ' Step size: [(0, 8), (0, 9), (0, 9), (0, 10), (0, 9), ' - + '(0, 9), (0, 10), (0, 9), (0, 9), (0, 10), (0, 9), ' - + '(0, 9), (0, 10), (0, 9), (0, 9), (0, 10)]'] + ' Step size: [(0, 8), (0, 9), (0, 9), (0, 10)]'] expected = '\n'.join(lines) self.assertEqual(actual, expected) @@ -514,7 +512,7 @@ class TestPrinting(unittest.TestCase): ' Profile: 2', ' Reference Grid Height, Width: (1456 x 2592)', ' Vertical, Horizontal Reference Grid Offset: (0 x 0)', - ' Reference Tile Height, Width: (512 x 512)', + ' Reference Tile Height, Width: (1456 x 2592)', ' Vertical, Horizontal Reference Tile Offset: (0 x 0)', ' Bitdepth: (8, 8, 8)', ' Signed: (False, False, False)', @@ -537,26 +535,27 @@ class TestPrinting(unittest.TestCase): def test_SOD_segment(self): j = glymur.Jp2k(self.jp2file) codestream = j.get_codestream(header_only=False) - print(codestream.segment[9]) + print(codestream.segment[10]) actual = sys.stdout.getvalue().strip() - lines = ['SOD marker segment @ (3299, 0)'] + lines = ['SOD marker segment @ (3302, 0)'] expected = '\n'.join(lines) self.assertEqual(actual, expected) def test_SOT_segment(self): j = glymur.Jp2k(self.jp2file) codestream = j.get_codestream(header_only=False) - print(codestream.segment[4]) + print(codestream.segment[5]) actual = sys.stdout.getvalue().strip() - lines = ['SOT marker segment @ (3221, 10)', + lines = ['SOT marker segment @ (3248, 10)', ' Tile part index: 0', - ' Tile part length: 78629', + ' Tile part length: 1132173', ' Tile part instance: 0', ' Number of tile parts: 1'] expected = '\n'.join(lines) + self.maxDiff = None self.assertEqual(actual, expected) @unittest.skipIf(data_root is None, @@ -606,7 +605,7 @@ class TestPrinting(unittest.TestCase): ' Profile: 2', ' Reference Grid Height, Width: (1456 x 2592)', ' Vertical, Horizontal Reference Grid Offset: (0 x 0)', - ' Reference Tile Height, Width: (512 x 512)', + ' Reference Tile Height, Width: (1456 x 2592)', ' Vertical, Horizontal Reference Tile Offset: (0 x 0)', ' Bitdepth: (8, 8, 8)', ' Signed: (False, False, False)', @@ -619,10 +618,10 @@ class TestPrinting(unittest.TestCase): ' EPH marker segments: False', ' Coding style parameters:', ' Progression order: LRCP', - ' Number of layers: 3', + ' Number of layers: 2', ' Multiple component transformation usage: ' + 'reversible', - ' Number of resolutions: 6', + ' Number of resolutions: 2', ' Code block height, width: (64 x 64)', ' Wavelet transform: 5-3 reversible', ' Precinct size: default, 2^15 x 2^15', @@ -634,13 +633,12 @@ class TestPrinting(unittest.TestCase): ' Vertically stripe causal context: False', ' Predictable termination: False', ' Segmentation symbols: False', - ' QCD marker segment @ (3200, 19)', + ' QCD marker segment @ (3200, 7)', ' Quantization style: no quantization, ' + '2 guard bits', - ' Step size: [(0, 8), (0, 9), (0, 9), ' - + '(0, 10), (0, 9), (0, 9), (0, 10), (0, 9), (0, 9), ' - + '(0, 10), (0, 9), (0, 9), (0, 10), (0, 9), (0, 9), ' - + '(0, 10)]'] + ' Step size: [(0, 8), (0, 9), (0, 9), (0, 10)]', + ' CME marker segment @ (3209, 37)', + ' "Created by OpenJPEG version 2.0.0"'] expected = '\n'.join(lst) self.assertEqual(actual, expected)