Validated through 2686. #139

This commit is contained in:
John Evans 2014-03-10 19:54:01 -04:00
commit de6984e204
4 changed files with 78 additions and 34 deletions

View file

@ -166,6 +166,11 @@ class Jp2k(Jp2kBox):
fps : int fps : int
Frames per second, should be either 24 or 48. Frames per second, should be either 24 or 48.
""" """
if version.openjpeg_version_tuple[0] == 1:
msg = "Writing Cinema2K or Cinema4K files is not supported with "
msg += 'openjpeg library versions less than 2.0.1.'
raise IOError(msg)
if cinema_mode == 'cinema2k': if cinema_mode == 'cinema2k':
if fps == 24: if fps == 24:
cparams.cp_cinema = CINEMA_MODE['cinema2k_24'] cparams.cp_cinema = CINEMA_MODE['cinema2k_24']
@ -331,8 +336,8 @@ class Jp2k(Jp2kBox):
colorspace : int colorspace : int
Either CLRSPC_SRGB or CLRSPC_GRAY Either CLRSPC_SRGB or CLRSPC_GRAY
""" """
if (('cinema2k' in kwargs or 'cinema4k' in kwargs) and
if ('cinema2k' in kwargs or 'cinema4k' in kwargs) and len(set(kwargs)) > 1: (len(set(kwargs)) > 1)):
msg = "Cannot specify cinema2k/cinema4k along with other options." msg = "Cannot specify cinema2k/cinema4k along with other options."
raise IOError(msg) raise IOError(msg)

View file

@ -35,6 +35,7 @@ if HAS_PYTHON_XMP_TOOLKIT:
from libxmp import XMPMeta from libxmp import XMPMeta
from .fixtures import OPJ_DATA_ROOT, opj_data_file from .fixtures import OPJ_DATA_ROOT, opj_data_file
from . import fixtures
# Doc tests should be run as well. # Doc tests should be run as well.
@ -376,6 +377,10 @@ class TestJp2k(unittest.TestCase):
creator_tool = xmp.get_property(libxmp.consts.XMP_NS_XMP, 'CreatorTool') creator_tool = xmp.get_property(libxmp.consts.XMP_NS_XMP, 'CreatorTool')
self.assertEqual(creator_tool, 'Google') self.assertEqual(creator_tool, 'Google')
@unittest.skipIf(fixtures.OPENJP2_IS_V2_OFFICIAL,
"Feature not supported in 2.0.0 official")
@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] == 1,
"Feature not supported in 1.5")
def test_jpx_mult_codestreams_jp2_brand(self): def test_jpx_mult_codestreams_jp2_brand(self):
"""Read JPX codestream when jp2-compatible.""" """Read JPX codestream when jp2-compatible."""
# The file in question has multiple codestreams. # The file in question has multiple codestreams.

View file

@ -23,6 +23,31 @@ from glymur import Jp2k
import glymur import glymur
@unittest.skipIf(re.match(r"""1\.[01234]""", glymur.version.openjpeg_version),
"Functionality not implemented for 1.3, 1.4")
@unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_OPJ_DATA_ROOT environment variable not set")
class TestSuiteNegative2pointzero(unittest.TestCase):
"""Feature set not supported for versions less than 2.0"""
def setUp(self):
self.jp2file = glymur.data.nemo()
self.j2kfile = glymur.data.goodstuff()
def tearDown(self):
pass
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
def test_cinema_mode(self):
"""Cinema mode not supported for less than 2.0.1."""
infile = opj_data_file('input/nonregression/Bretagne1.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
with self.assertRaises(IOError):
j.write(data, psnr=[30, 35, 40], cratios=[2, 3, 4])
@unittest.skipIf(re.match(r"""1\.[01234]""", glymur.version.openjpeg_version), @unittest.skipIf(re.match(r"""1\.[01234]""", glymur.version.openjpeg_version),
"Functionality not implemented for 1.3, 1.4") "Functionality not implemented for 1.3, 1.4")
@unittest.skipIf(OPJ_DATA_ROOT is None, @unittest.skipIf(OPJ_DATA_ROOT is None,

View file

@ -21,18 +21,21 @@ except ((ImportError, RuntimeError)):
from .fixtures import read_image, NO_READ_BACKEND, NO_READ_BACKEND_MSG from .fixtures import read_image, NO_READ_BACKEND, NO_READ_BACKEND_MSG
from .fixtures import OPJ_DATA_ROOT, opj_data_file from .fixtures import OPJ_DATA_ROOT, opj_data_file
from . import fixtures
from glymur import Jp2k from glymur import Jp2k
import glymur import glymur
@unittest.skipIf(not _HAS_SKIMAGE_FREEIMAGE_SUPPORT,
"Cannot read input image without scikit-image/freeimage")
@unittest.skipIf(os.name == "nt", "no write support on windows, period") @unittest.skipIf(os.name == "nt", "no write support on windows, period")
@unittest.skipIf(re.match(r"""1\.[01234]\.\d""", @unittest.skipIf(fixtures.OPENJP2_IS_V2_OFFICIAL,
glymur.version.openjpeg_version) is not None, "Feature not supported in 2.0.0 official")
"Writing only supported with openjpeg version 1.5+.") @unittest.skipIf(glymur.version.openjpeg_version_tuple[0] == 1,
@unittest.skipIf(NO_READ_BACKEND, NO_READ_BACKEND_MSG) "Feature not supported in 1.5")
@unittest.skipIf(OPJ_DATA_ROOT is None, @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set") "OPJ_DATA_ROOT environment variable not set")
class TestSuiteWrite(unittest.TestCase): class TestSuiteWriteCinema(unittest.TestCase):
"""Tests for writing with openjp2 backend. """Tests for writing with openjp2 backend.
These tests either roughly correspond with those tests with similar names These tests either roughly correspond with those tests with similar names
@ -148,8 +151,6 @@ class TestSuiteWrite(unittest.TestCase):
@unittest.skipIf(not _HAS_SKIMAGE_FREEIMAGE_SUPPORT,
"Cannot read input image without scikit-image/freeimage")
def test_NR_ENC_ElephantDream_4K_tif_21_encode(self): def test_NR_ENC_ElephantDream_4K_tif_21_encode(self):
relfile = 'input/nonregression/ElephantDream_4K.tif' relfile = 'input/nonregression/ElephantDream_4K.tif'
infile = opj_data_file(relfile) infile = opj_data_file(relfile)
@ -162,8 +163,6 @@ class TestSuiteWrite(unittest.TestCase):
self.check_cinema4k_codestream(codestream, (4096, 2160)) self.check_cinema4k_codestream(codestream, (4096, 2160))
@unittest.skipIf(not _HAS_SKIMAGE_FREEIMAGE_SUPPORT,
"Cannot read input image without scikit-image/freeimage")
def test_NR_ENC_X_5_2K_24_235_CBR_STEM24_000_tif_19_encode(self): def test_NR_ENC_X_5_2K_24_235_CBR_STEM24_000_tif_19_encode(self):
relfile = 'input/nonregression/X_5_2K_24_235_CBR_STEM24_000.tif' relfile = 'input/nonregression/X_5_2K_24_235_CBR_STEM24_000.tif'
infile = opj_data_file(relfile) infile = opj_data_file(relfile)
@ -176,8 +175,6 @@ class TestSuiteWrite(unittest.TestCase):
self.check_cinema2k_codestream(codestream, (2048, 857)) self.check_cinema2k_codestream(codestream, (2048, 857))
@unittest.skipIf(not _HAS_SKIMAGE_FREEIMAGE_SUPPORT,
"Cannot read input image without scikit-image/freeimage")
def test_NR_ENC_X_6_2K_24_FULL_CBR_CIRCLE_000_tif_20_encode(self): def test_NR_ENC_X_6_2K_24_FULL_CBR_CIRCLE_000_tif_20_encode(self):
relfile = 'input/nonregression/X_6_2K_24_FULL_CBR_CIRCLE_000.tif' relfile = 'input/nonregression/X_6_2K_24_FULL_CBR_CIRCLE_000.tif'
infile = opj_data_file(relfile) infile = opj_data_file(relfile)
@ -190,8 +187,6 @@ class TestSuiteWrite(unittest.TestCase):
self.check_cinema2k_codestream(codestream, (2048, 1080)) self.check_cinema2k_codestream(codestream, (2048, 1080))
@unittest.skipIf(not _HAS_SKIMAGE_FREEIMAGE_SUPPORT,
"Cannot read input image without scikit-image/freeimage")
def test_NR_ENC_X_6_2K_24_FULL_CBR_CIRCLE_000_tif_17_encode(self): def test_NR_ENC_X_6_2K_24_FULL_CBR_CIRCLE_000_tif_17_encode(self):
relfile = 'input/nonregression/X_6_2K_24_FULL_CBR_CIRCLE_000.tif' relfile = 'input/nonregression/X_6_2K_24_FULL_CBR_CIRCLE_000.tif'
infile = opj_data_file(relfile) infile = opj_data_file(relfile)
@ -204,8 +199,6 @@ class TestSuiteWrite(unittest.TestCase):
self.check_cinema2k_codestream(codestream, (2048, 1080)) self.check_cinema2k_codestream(codestream, (2048, 1080))
@unittest.skipIf(not _HAS_SKIMAGE_FREEIMAGE_SUPPORT,
"Cannot read input image without scikit-image/freeimage")
def test_NR_ENC_X_5_2K_24_235_CBR_STEM24_000_tif_16_encode(self): def test_NR_ENC_X_5_2K_24_235_CBR_STEM24_000_tif_16_encode(self):
relfile = 'input/nonregression/X_5_2K_24_235_CBR_STEM24_000.tif' relfile = 'input/nonregression/X_5_2K_24_235_CBR_STEM24_000.tif'
infile = opj_data_file(relfile) infile = opj_data_file(relfile)
@ -218,8 +211,6 @@ class TestSuiteWrite(unittest.TestCase):
self.check_cinema2k_codestream(codestream, (2048, 857)) self.check_cinema2k_codestream(codestream, (2048, 857))
@unittest.skipIf(not _HAS_SKIMAGE_FREEIMAGE_SUPPORT,
"Cannot read input image without scikit-image/freeimage")
def test_NR_ENC_X_4_2K_24_185_CBR_WB_000_tif_18_encode(self): def test_NR_ENC_X_4_2K_24_185_CBR_WB_000_tif_18_encode(self):
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)
@ -232,32 +223,50 @@ class TestSuiteWrite(unittest.TestCase):
self.check_cinema2k_codestream(codestream, (1998, 1080)) self.check_cinema2k_codestream(codestream, (1998, 1080))
@unittest.skipIf(not _HAS_SKIMAGE_FREEIMAGE_SUPPORT, @unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
"Cannot read input image without scikit-image/freeimage") @unittest.skipIf(re.match(r"""2\.0""", glymur.version.openjpeg_version),
def test_NR_ENC_X_4_2K_24_185_CBR_WB_000_tif_15_encode(self): "Functionality implemented for 2.1")
relfile = 'input/nonregression/X_4_2K_24_185_CBR_WB_000.tif' @unittest.skipIf(OPJ_DATA_ROOT is None,
infile = opj_data_file(relfile) "OPJ_OPJ_DATA_ROOT environment variable not set")
data = skimage.io.imread(infile) class TestSuiteNegative2pointzero(unittest.TestCase):
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: """Feature set not supported for versions less than 2.0"""
j = Jp2k(tfile.name, 'wb')
j.write(data, cinema2k=24)
codestream = j.get_codestream() def setUp(self):
self.check_cinema2k_codestream(codestream, (1998, 1080)) self.jp2file = glymur.data.nemo()
self.j2kfile = glymur.data.goodstuff()
def tearDown(self):
pass
@unittest.skipIf(not _HAS_SKIMAGE_FREEIMAGE_SUPPORT, def test_cinema_mode(self):
"Cannot read input image without scikit-image/freeimage")
def test_cinema2k_bad_frame_rate(self):
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: with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb') j = Jp2k(tfile.name, 'wb')
with self.assertRaises(IOError): with self.assertRaises(IOError):
j.write(data, cinema2k=36) j.write(data, cinema2k=48)
@unittest.skipIf(os.name == "nt", "no write support on windows, period")
@unittest.skipIf(re.match(r"""1\.[01234]\.\d""",
glymur.version.openjpeg_version) is not None,
"Writing only supported with openjpeg version 1.5+.")
@unittest.skipIf(NO_READ_BACKEND, NO_READ_BACKEND_MSG)
@unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
class TestSuiteWrite(unittest.TestCase):
"""Tests for writing with openjp2 backend.
These tests either roughly correspond with those tests with similar names
in the OpenJPEG test suite or are closely associated.
"""
def setUp(self):
pass
def tearDown(self):
pass
def test_NR_ENC_Bretagne1_ppm_1_encode(self): def test_NR_ENC_Bretagne1_ppm_1_encode(self):
"""NR-ENC-Bretagne1.ppm-1-encode""" """NR-ENC-Bretagne1.ppm-1-encode"""
infile = opj_data_file('input/nonregression/Bretagne1.ppm') infile = opj_data_file('input/nonregression/Bretagne1.ppm')