merge branch 'issue287' into devel

This commit is contained in:
jevans 2014-10-21 19:44:08 -04:00
commit 689cedfa78
4 changed files with 48 additions and 73 deletions

View file

@ -967,10 +967,10 @@ class Jp2k(Jp2kBox):
>>> thumbnail.shape >>> thumbnail.shape
(728, 1296, 3) (728, 1296, 3)
""" """
if opj2.OPENJP2 is not None: if version.openjpeg_version_tuple[0] < 2:
img = self._read_openjp2(**kwargs)
else:
img = self._read_openjpeg(**kwargs) img = self._read_openjpeg(**kwargs)
else:
img = self._read_openjp2(**kwargs)
return img return img
def _subsampling_sanity_check(self): def _subsampling_sanity_check(self):

View file

@ -25,8 +25,6 @@ import glymur
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
"Missing openjp2 library.")
class TestCallbacks(unittest.TestCase): class TestCallbacks(unittest.TestCase):
"""Test suite for callbacks.""" """Test suite for callbacks."""
@ -37,6 +35,8 @@ class TestCallbacks(unittest.TestCase):
def tearDown(self): def tearDown(self):
pass pass
@unittest.skipIf(glymur.version.openjpeg_version[0] != '2',
"Missing openjp2 library.")
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG) @unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.") @unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
def test_info_callback_on_write(self): def test_info_callback_on_write(self):
@ -59,46 +59,20 @@ class TestCallbacks(unittest.TestCase):
# callback handler is enabled. # callback handler is enabled.
j = glymur.Jp2k(self.j2kfile) j = glymur.Jp2k(self.j2kfile)
with patch('sys.stdout', new=StringIO()) as fake_out: with patch('sys.stdout', new=StringIO()) as fake_out:
j.read(rlevel=1, verbose=True, area=(0, 0, 200, 150)) j.read(rlevel=1, verbose=True)
actual = fake_out.getvalue().strip() actual = fake_out.getvalue().strip()
lines = ['[INFO] Start to read j2k main header (0).', if glymur.version.openjpeg_version[0] == '2':
'[INFO] Main header has been correctly decoded.', lines = ['[INFO] Start to read j2k main header (0).',
'[INFO] Setting decoding area to 0,0,150,200', '[INFO] Main header has been correctly decoded.',
'[INFO] Header of tile 0 / 0 has been read.', '[INFO] No decoded area parameters, set the decoded area to the whole image',
'[INFO] Tile 1/1 has been decoded.', '[INFO] Header of tile 0 / 0 has been read.',
'[INFO] Image data has been updated with tile 1.'] '[INFO] Tile 1/1 has been decoded.',
'[INFO] Image data has been updated with tile 1.']
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
@unittest.skipIf(glymur.lib.openjpeg.OPENJPEG is None,
"Missing openjpeg library.")
class TestCallbacks15(unittest.TestCase):
"""This test suite is for OpenJPEG 1.5.1 properties.
"""
def setUp(self):
self.jp2file = glymur.data.nemo()
self.j2kfile = glymur.data.goodstuff()
def tearDown(self):
pass
def test_info_callbacks_on_read(self):
"""Verify stdout when reading.
Verify that we get the expected stdio output when our internal info
callback handler is enabled.
"""
with patch('glymur.lib.openjp2.OPENJP2', new=None):
# Force to use OPENJPEG instead of OPENJP2.
j = glymur.Jp2k(self.j2kfile)
with patch('sys.stdout', new=StringIO()) as fake_out:
j.read(rlevel=1, verbose=True)
actual = fake_out.getvalue().strip()
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
else:
regex = re.compile(r"""\[INFO\]\stile\s1\sof\s1\s+ regex = re.compile(r"""\[INFO\]\stile\s1\sof\s1\s+
\[INFO\]\s-\stiers-1\stook\s \[INFO\]\s-\stiers-1\stook\s
[0-9]+\.[0-9]+\ss\s+ [0-9]+\.[0-9]+\ss\s+
@ -114,7 +88,3 @@ class TestCallbacks15(unittest.TestCase):
self.assertRegexpMatches(actual, regex) self.assertRegexpMatches(actual, regex)
else: else:
self.assertRegex(actual, regex) self.assertRegex(actual, regex)
if __name__ == "__main__":
unittest.main()

View file

@ -987,8 +987,6 @@ class TestJp2k_write(unittest.TestCase):
self.assertEqual(codestream.segment[2].spcod[0], glymur.core.CPRL) self.assertEqual(codestream.segment[2].spcod[0], glymur.core.CPRL)
@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] >= 2,
"Negative tests only for version 1.x")
class TestJp2k_1_x(unittest.TestCase): class TestJp2k_1_x(unittest.TestCase):
"""Test suite for openjpeg 1.x, not appropriate for 2.x""" """Test suite for openjpeg 1.x, not appropriate for 2.x"""
@ -1002,32 +1000,32 @@ class TestJp2k_1_x(unittest.TestCase):
def test_tile(self): def test_tile(self):
"""tile option not allowed for 1.x. """tile option not allowed for 1.x.
""" """
j2k = Jp2k(self.j2kfile) with patch('glymur.version.openjpeg_version_tuple', new=(1, 5, 0)):
with self.assertRaises(TypeError): j2k = Jp2k(self.j2kfile)
j2k.read(tile=0) with self.assertRaises(TypeError):
j2k.read(tile=0)
def test_layer(self): def test_layer(self):
"""layer option not allowed for 1.x. """layer option not allowed for 1.x.
""" """
j2k = Jp2k(self.j2kfile) with patch('glymur.version.openjpeg_version_tuple', new=(1, 5, 0)):
with self.assertRaises(TypeError): j2k = Jp2k(self.j2kfile)
j2k.read(layer=1) with self.assertRaises(TypeError):
j2k.read(layer=1)
@unittest.skipIf(re.match(r'''2.0.0''', @unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG)
glymur.version.openjpeg_version) is None, class Test_2p0_official(unittest.TestCase):
"Tests only to be run on 2.0 official.") """Tests specific to v2.0.0"""
class TestJp2k_2_0_official(unittest.TestCase):
"""Test suite to only be run on v2.0 official."""
@unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG)
def test_extra_components_on_v2(self): def test_extra_components_on_v2(self):
"""Can only write 4 components on 2.0+, should error out otherwise.""" """Can only write 4 components on 2.0+, should error out otherwise."""
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: with patch('glymur.version.openjpeg_version', new="2.0.0"):
j = Jp2k(tfile.name, 'wb') with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
data = np.zeros((128, 128, 4), dtype=np.uint8) j = Jp2k(tfile.name, 'wb')
with self.assertRaises(IOError): data = np.zeros((128, 128, 4), dtype=np.uint8)
j.write(data) with self.assertRaises(IOError):
j.write(data)
@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] < 2, @unittest.skipIf(glymur.version.openjpeg_version_tuple[0] < 2,

View file

@ -12,6 +12,11 @@ import sys
import tempfile import tempfile
import unittest import unittest
if sys.hexversion <= 0x03030000:
from mock import patch
else:
from unittest.mock import patch
import numpy as np import numpy as np
try: try:
import skimage.io import skimage.io
@ -195,12 +200,10 @@ class WriteCinemaWarns(CinemaBase):
@unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT, @unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT,
"Cannot read input image without scikit-image/freeimage") "Cannot read input image without scikit-image/freeimage")
@unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG) @unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG)
@unittest.skipIf(not re.match("(1.5|2.0.0)", glymur.version.openjpeg_version),
"Functionality implemented for 2.0.1")
@unittest.skipIf(OPJ_DATA_ROOT is None, @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_OPJ_DATA_ROOT environment variable not set") "OPJ_OPJ_DATA_ROOT environment variable not set")
class TestSuiteNegative2pointzero(unittest.TestCase): class TestNegative2pointzero(unittest.TestCase):
"""Feature set not supported for versions less than 2.0""" """Feature set not supported for versions less than 2.0.1"""
def setUp(self): def setUp(self):
self.jp2file = glymur.data.nemo() self.jp2file = glymur.data.nemo()
@ -210,13 +213,17 @@ class TestSuiteNegative2pointzero(unittest.TestCase):
pass pass
def test_cinema_mode(self): def test_cinema_mode(self):
"""Cinema mode not allowed for anything less than 2.0.1"""
relfile = 'input/nonregression/X_4_2K_24_185_CBR_WB_000.tif' relfile = 'input/nonregression/X_4_2K_24_185_CBR_WB_000.tif'
infile = opj_data_file(relfile) infile = opj_data_file(relfile)
data = skimage.io.imread(infile) data = skimage.io.imread(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: versions = ["1.5.0", "2.0.0"]
j = Jp2k(tfile.name, 'wb') for version in versions:
with self.assertRaises(IOError): with patch('glymur.version.openjpeg_version', new=version):
j.write(data, cinema2k=48) with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
with self.assertRaises(IOError):
j.write(data, cinema2k=48)
@unittest.skipIf(re.match(r'''1.[0-4]''', openjpeg_version) is not None, @unittest.skipIf(re.match(r'''1.[0-4]''', openjpeg_version) is not None,