Merge branch 'issue68' into release-0.2.0
Conflicts: release.txt
This commit is contained in:
commit
bfdebf5b48
16 changed files with 151 additions and 72 deletions
|
|
@ -17,8 +17,8 @@ def nemo():
|
|||
file : str
|
||||
Platform-independent path to nemo.jp2.
|
||||
"""
|
||||
file = pkg_resources.resource_filename(__name__, "nemo.jp2")
|
||||
return file
|
||||
filename = pkg_resources.resource_filename(__name__, "nemo.jp2")
|
||||
return filename
|
||||
|
||||
|
||||
def goodstuff():
|
||||
|
|
@ -29,5 +29,5 @@ def goodstuff():
|
|||
file : str
|
||||
Platform-independent path to goodstuff.j2k.
|
||||
"""
|
||||
file = pkg_resources.resource_filename(__name__, "goodstuff.j2k")
|
||||
return file
|
||||
filename = pkg_resources.resource_filename(__name__, "goodstuff.j2k")
|
||||
return filename
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ def read_config_file():
|
|||
that we currently care about is still in the svn trunk at openjpeg.org.
|
||||
We must use a configuration file that the user must write.
|
||||
"""
|
||||
lib = {}
|
||||
lib = {'openjp2': None, 'openjpeg': None}
|
||||
filename = glymurrc_fname()
|
||||
if filename is not None:
|
||||
# Read the configuration file for the library location.
|
||||
|
|
@ -92,11 +92,11 @@ def read_config_file():
|
|||
try:
|
||||
lib['openjp2'] = parser.get('library', 'openjp2')
|
||||
except NoOptionError:
|
||||
lib['openjp2'] = None
|
||||
pass
|
||||
try:
|
||||
lib['openjpeg'] = parser.get('library', 'openjpeg')
|
||||
except NoOptionError:
|
||||
lib['openjpeg'] = None
|
||||
pass
|
||||
|
||||
return lib
|
||||
|
||||
|
|
@ -113,7 +113,7 @@ def load_openjp2(libopenjp2_path):
|
|||
openjp2_lib = ctypes.windll.LoadLibrary(libopenjp2_path)
|
||||
else:
|
||||
openjp2_lib = ctypes.CDLL(libopenjp2_path)
|
||||
except OSError:
|
||||
except (TypeError, OSError):
|
||||
msg = '"Library {0}" could not be loaded. Operating in degraded mode.'
|
||||
msg = msg.format(libopenjp2_path)
|
||||
warnings.warn(msg, UserWarning)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#pylint: disable-all
|
||||
import doctest
|
||||
import os
|
||||
import pkg_resources
|
||||
|
|
@ -12,6 +13,7 @@ import numpy as np
|
|||
import glymur
|
||||
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
@unittest.skipIf(glymur.lib._openjp2.OPENJP2 is None,
|
||||
"Missing openjp2 library.")
|
||||
class TestOpenJP2(unittest.TestCase):
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#pylint: disable-all
|
||||
import ctypes
|
||||
import unittest
|
||||
|
||||
|
|
|
|||
|
|
@ -3,19 +3,18 @@ import sys
|
|||
|
||||
import numpy as np
|
||||
|
||||
def mse(A, B):
|
||||
def mse(amat, bmat):
|
||||
"""Mean Square Error"""
|
||||
diff = A.astype(np.double) - B.astype(np.double)
|
||||
#e = np.sqrt(np.mean(diff**2))
|
||||
e = np.mean(diff**2)
|
||||
return e
|
||||
diff = amat.astype(np.double) - bmat.astype(np.double)
|
||||
err = np.mean(diff**2)
|
||||
return err
|
||||
|
||||
|
||||
def peak_tolerance(A, B):
|
||||
def peak_tolerance(amat, bmat):
|
||||
"""Peak Tolerance"""
|
||||
diff = np.abs(A.astype(np.double) - B.astype(np.double))
|
||||
p = diff.max()
|
||||
return p
|
||||
diff = np.abs(amat.astype(np.double) - bmat.astype(np.double))
|
||||
ptol = diff.max()
|
||||
return ptol
|
||||
|
||||
|
||||
def read_pgx(pgx_file):
|
||||
|
|
@ -28,42 +27,42 @@ def read_pgx(pgx_file):
|
|||
PG%[ \t]%c%c%[ \t+-]%d%[ \t]%d%[ \t]%d"
|
||||
"""
|
||||
header = ''
|
||||
with open(pgx_file, 'rb') as fp:
|
||||
with open(pgx_file, 'rb') as fptr:
|
||||
while True:
|
||||
x = fp.read(1)
|
||||
if x[0] == 10 or x == '\n':
|
||||
pos = fp.tell()
|
||||
char = fptr.read(1)
|
||||
if char[0] == 10 or char == '\n':
|
||||
pos = fptr.tell()
|
||||
break
|
||||
else:
|
||||
if sys.hexversion < 0x03000000:
|
||||
header += x
|
||||
header += char
|
||||
else:
|
||||
header += chr(x[0])
|
||||
header += chr(char[0])
|
||||
|
||||
header = header.rstrip()
|
||||
n = re.split('\s', header)
|
||||
tokens = re.split('\s', header)
|
||||
|
||||
if (n[1][0] == 'M') and (sys.byteorder == 'little'):
|
||||
if (tokens[1][0] == 'M') and (sys.byteorder == 'little'):
|
||||
swapbytes = True
|
||||
elif (n[1][0] == 'L') and (sys.byteorder == 'big'):
|
||||
elif (tokens[1][0] == 'L') and (sys.byteorder == 'big'):
|
||||
swapbytes = True
|
||||
else:
|
||||
swapbytes = False
|
||||
|
||||
if (len(n) == 6):
|
||||
bitdepth = int(n[3])
|
||||
if (len(tokens) == 6):
|
||||
bitdepth = int(tokens[3])
|
||||
signed = bitdepth < 0
|
||||
if signed:
|
||||
bitdepth = -1 * bitdepth
|
||||
nrows = int(n[5])
|
||||
ncols = int(n[4])
|
||||
nrows = int(tokens[5])
|
||||
ncols = int(tokens[4])
|
||||
else:
|
||||
bitdepth = int(n[2])
|
||||
bitdepth = int(tokens[2])
|
||||
signed = bitdepth < 0
|
||||
if signed:
|
||||
bitdepth = -1 * bitdepth
|
||||
nrows = int(n[4])
|
||||
ncols = int(n[3])
|
||||
nrows = int(tokens[4])
|
||||
ncols = int(tokens[3])
|
||||
|
||||
if signed:
|
||||
if bitdepth <= 8:
|
||||
|
|
@ -84,9 +83,9 @@ def read_pgx(pgx_file):
|
|||
|
||||
# Reopen the file in binary mode and seek to the start of the binary
|
||||
# data
|
||||
with open(pgx_file, 'rb') as fp:
|
||||
fp.seek(pos)
|
||||
data = np.fromfile(file=fp, dtype=dtype).reshape(shape)
|
||||
with open(pgx_file, 'rb') as fptr:
|
||||
fptr.seek(pos)
|
||||
data = np.fromfile(file=fptr, dtype=dtype).reshape(shape)
|
||||
|
||||
return(data.byteswap(swapbytes))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#pylint: disable-all
|
||||
import os
|
||||
import pkg_resources
|
||||
import re
|
||||
|
|
@ -29,6 +30,7 @@ class TestCallbacks(unittest.TestCase):
|
|||
# Restore stdout.
|
||||
sys.stdout = self.stdout
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
def test_info_callback_on_write(self):
|
||||
# Verify the messages printed when writing an image in verbose mode.
|
||||
j = glymur.Jp2k(self.jp2file)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#pylint: disable-all
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
|
|
@ -29,6 +30,7 @@ class TestCodestream(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
pass
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
def test_reserved_marker_segment(self):
|
||||
# Some marker segments were reserved in FCD15444-1. Since that
|
||||
# standard is old, some of them may have come into use.
|
||||
|
|
@ -58,6 +60,7 @@ class TestCodestream(unittest.TestCase):
|
|||
self.assertEqual(c.segment[2].length, 3)
|
||||
self.assertEqual(c.segment[2]._data, b'\x00')
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
@unittest.skipIf(sys.hexversion < 0x03020000,
|
||||
"Uses features introduced in 3.2.")
|
||||
def test_unknown_marker_segment(self):
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
"""These tests are for edge cases where OPENJPEG does not exist, but
|
||||
OPENJP2 may be present in some form or other.
|
||||
"""
|
||||
#pylint: disable-all
|
||||
|
||||
import imp
|
||||
import os
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#pylint: disable-all
|
||||
import datetime
|
||||
import os
|
||||
import struct
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#pylint: disable-all
|
||||
import doctest
|
||||
import os
|
||||
import tempfile
|
||||
|
|
@ -14,10 +15,14 @@ from glymur.jp2box import *
|
|||
|
||||
# Doc tests should be run as well.
|
||||
def load_tests(loader, tests, ignore):
|
||||
if os.name == "nt":
|
||||
# Can't do it on windows, temporary file issue.
|
||||
return tests
|
||||
tests.addTests(doctest.DocTestSuite('glymur.jp2box'))
|
||||
return tests
|
||||
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||
"Missing openjp2 library.")
|
||||
class TestChannelDefinition(unittest.TestCase):
|
||||
|
|
@ -232,6 +237,7 @@ class TestChannelDefinition(unittest.TestCase):
|
|||
association=[1, 2, 3])
|
||||
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
class TestXML(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
|
@ -370,6 +376,7 @@ class TestColourSpecificationBox(unittest.TestCase):
|
|||
with self.assertRaises(NotImplementedError):
|
||||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
def test_missing_colr_box(self):
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
boxes = [self.jP, self.ftyp, self.jp2h, self.jp2c]
|
||||
|
|
@ -501,12 +508,14 @@ class TestJp2Boxes(unittest.TestCase):
|
|||
self.assertEqual(jp2.box[2].box[1].colorspace, glymur.core.SRGB)
|
||||
self.assertIsNone(jp2.box[2].box[1].icc_profile)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
def test_wrap(self):
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile:
|
||||
j2k.wrap(tfile.name)
|
||||
self.verify_wrapped_raw(tfile.name)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
def test_wrap_jp2(self):
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile:
|
||||
|
|
@ -514,6 +523,7 @@ class TestJp2Boxes(unittest.TestCase):
|
|||
boxes = [box.box_id for box in jp2.box]
|
||||
self.assertEqual(boxes, ['jP ', 'ftyp', 'jp2h', 'jp2c'])
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
def test_default_layout_but_with_specified_boxes(self):
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
boxes = [JPEG2000SignatureBox(),
|
||||
|
|
@ -532,6 +542,7 @@ class TestJp2Boxes(unittest.TestCase):
|
|||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
self.verify_wrapped_raw(tfile.name)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
def test_image_header_box_not_first_in_jp2_header(self):
|
||||
# The specification says that ihdr must be the first box in jp2h.
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
|
|
@ -551,6 +562,7 @@ class TestJp2Boxes(unittest.TestCase):
|
|||
with self.assertRaises(IOError):
|
||||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
def test_first_2_boxes_not_jP_and_ftyp(self):
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
c = j2k.get_codestream()
|
||||
|
|
@ -571,6 +583,7 @@ class TestJp2Boxes(unittest.TestCase):
|
|||
with self.assertRaises(IOError):
|
||||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
def test_jp2h_not_preceeding_jp2c(self):
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
c = j2k.get_codestream()
|
||||
|
|
@ -591,6 +604,7 @@ class TestJp2Boxes(unittest.TestCase):
|
|||
with self.assertRaises(IOError):
|
||||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
def test_missing_codestream(self):
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
c = j2k.get_codestream()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
import contextlib
|
||||
import ctypes
|
||||
# pylint: disable-all
|
||||
import doctest
|
||||
import imp
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
|
|
@ -33,14 +31,18 @@ except:
|
|||
|
||||
# Doc tests should be run as well.
|
||||
def load_tests(loader, tests, ignore):
|
||||
if os.name == "nt":
|
||||
# Can't do it on windows, temporary file issue.
|
||||
return tests
|
||||
if glymur.lib.openjp2.OPENJP2 is not None:
|
||||
tests.addTests(doctest.DocTestSuite('glymur.jp2k'))
|
||||
return tests
|
||||
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||
"Missing openjp2 library.")
|
||||
class TestJp2k(unittest.TestCase):
|
||||
class TestJp2kBadXmlFile(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
|
@ -88,14 +90,6 @@ class TestJp2k(unittest.TestCase):
|
|||
with self.assertWarns(UserWarning) as cw:
|
||||
jp2k = Jp2k(self._bad_xml_file)
|
||||
|
||||
def test_rlevel_max(self):
|
||||
# Verify that rlevel=-1 gets us the lowest resolution image
|
||||
j = Jp2k(self.j2kfile)
|
||||
thumbnail1 = j.read(rlevel=-1)
|
||||
thumbnail2 = j.read(rlevel=5)
|
||||
np.testing.assert_array_equal(thumbnail1, thumbnail2)
|
||||
self.assertEqual(thumbnail1.shape, (25, 15, 3))
|
||||
|
||||
def test_invalid_xml_box(self):
|
||||
# Should be able to recover from xml box with bad xml.
|
||||
with warnings.catch_warnings():
|
||||
|
|
@ -107,6 +101,27 @@ class TestJp2k(unittest.TestCase):
|
|||
self.assertEqual(jp2k.box[3].length, 28)
|
||||
self.assertIsNone(jp2k.box[3].xml)
|
||||
|
||||
|
||||
|
||||
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||
"Missing openjp2 library.")
|
||||
class TestJp2k(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.jp2file = glymur.data.nemo()
|
||||
self.j2kfile = glymur.data.goodstuff()
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_rlevel_max(self):
|
||||
# Verify that rlevel=-1 gets us the lowest resolution image
|
||||
j = Jp2k(self.j2kfile)
|
||||
thumbnail1 = j.read(rlevel=-1)
|
||||
thumbnail2 = j.read(rlevel=5)
|
||||
np.testing.assert_array_equal(thumbnail1, thumbnail2)
|
||||
self.assertEqual(thumbnail1.shape, (25, 15, 3))
|
||||
|
||||
def test_bad_area_parameter(self):
|
||||
# Verify that we error out appropriately if given a bad area parameter.
|
||||
j = Jp2k(self.jp2file)
|
||||
|
|
@ -143,6 +158,7 @@ class TestJp2k(unittest.TestCase):
|
|||
filename = 'this file does not actually exist on the file system.'
|
||||
jp2k = Jp2k(filename)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_write_srgb_without_mct(self):
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
expdata = j2k.read()
|
||||
|
|
@ -155,6 +171,7 @@ class TestJp2k(unittest.TestCase):
|
|||
c = ofile.get_codestream()
|
||||
self.assertEqual(c.segment[2].spcod[3], 0) # no mct
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_write_grayscale_with_mct(self):
|
||||
# MCT usage makes no sense for grayscale images.
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
|
|
@ -164,6 +181,7 @@ class TestJp2k(unittest.TestCase):
|
|||
with self.assertRaises(IOError):
|
||||
ofile.write(expdata[:, :, 0], mct=True)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_write_cprl(self):
|
||||
# Issue 17
|
||||
j = Jp2k(self.jp2file)
|
||||
|
|
@ -244,6 +262,7 @@ class TestJp2k(unittest.TestCase):
|
|||
jp2k = Jp2k(filename)
|
||||
self.assertEqual(len(jp2k.box), 0)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_64bit_XL_field(self):
|
||||
# Verify that boxes with the XL field are properly read.
|
||||
# Don't have such a file on hand, so we create one. Copy our example
|
||||
|
|
@ -276,6 +295,7 @@ class TestJp2k(unittest.TestCase):
|
|||
self.assertEqual(jp2k.box[5].offset, 3127)
|
||||
self.assertEqual(jp2k.box[5].length, 1133427 + 8)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_L_is_zero(self):
|
||||
# Verify that boxes with the L field as zero are correctly read.
|
||||
# This should only happen in the last box of a JPEG 2000 file.
|
||||
|
|
@ -331,6 +351,7 @@ class TestJp2k(unittest.TestCase):
|
|||
j = Jp2k(filename)
|
||||
self.assertEqual(j.box, [])
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_code_block_height_different_than_width(self):
|
||||
# Verify that we can set a code block size where height does not equal
|
||||
# width.
|
||||
|
|
@ -346,6 +367,7 @@ class TestJp2k(unittest.TestCase):
|
|||
# Code block size is reported as XY in the codestream.
|
||||
self.assertEqual(tuple(c.segment[2].spcod[5:7]), (3, 2))
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_negative_too_many_dimensions(self):
|
||||
# OpenJP2 only allows 2D or 3D images.
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
|
|
@ -354,6 +376,7 @@ class TestJp2k(unittest.TestCase):
|
|||
data = np.zeros((128, 128, 2, 2), dtype=np.uint8)
|
||||
j.write(data)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_unrecognized_jp2_colorspace(self):
|
||||
# We only allow RGB and GRAYSCALE.
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
||||
|
|
@ -362,6 +385,7 @@ class TestJp2k(unittest.TestCase):
|
|||
data = np.zeros((128, 128, 3), dtype=np.uint8)
|
||||
j.write(data, colorspace='cmyk')
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_2D_rgb(self):
|
||||
# RGB must have at least 3 components.
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
||||
|
|
@ -370,6 +394,7 @@ class TestJp2k(unittest.TestCase):
|
|||
data = np.zeros((128, 128, 2), dtype=np.uint8)
|
||||
j.write(data, colorspace='rgb')
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_colorspace_with_j2k(self):
|
||||
# Specifying a colorspace with J2K does not make sense.
|
||||
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
|
||||
|
|
@ -378,6 +403,7 @@ class TestJp2k(unittest.TestCase):
|
|||
data = np.zeros((128, 128, 3), dtype=np.uint8)
|
||||
j.write(data, colorspace='rgb')
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_specify_rgb(self):
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
|
|
@ -385,6 +411,7 @@ class TestJp2k(unittest.TestCase):
|
|||
j.write(data, colorspace='rgb')
|
||||
self.assertEqual(j.box[2].box[1].colorspace, glymur.core.SRGB)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_specify_gray(self):
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
|
|
@ -393,6 +420,7 @@ class TestJp2k(unittest.TestCase):
|
|||
self.assertEqual(j.box[2].box[1].colorspace,
|
||||
glymur.core.GREYSCALE)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_specify_grey(self):
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
|
|
@ -401,6 +429,7 @@ class TestJp2k(unittest.TestCase):
|
|||
self.assertEqual(j.box[2].box[1].colorspace,
|
||||
glymur.core.GREYSCALE)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_grey_with_extra_component(self):
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
|
|
@ -412,6 +441,7 @@ class TestJp2k(unittest.TestCase):
|
|||
self.assertEqual(j.box[2].box[1].colorspace,
|
||||
glymur.core.GREYSCALE)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_grey_with_two_extra_components(self):
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
|
|
@ -423,6 +453,7 @@ class TestJp2k(unittest.TestCase):
|
|||
self.assertEqual(j.box[2].box[1].colorspace,
|
||||
glymur.core.GREYSCALE)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_rgb_with_extra_component(self):
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
||||
j = Jp2k(tfile.name, 'wb')
|
||||
|
|
@ -441,6 +472,7 @@ class TestJp2k(unittest.TestCase):
|
|||
data = np.zeros((128, 128, 3), dtype=np.uint8)
|
||||
j.write(data, colorspace='ycc')
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_uinf_ulst_url_boxes(self):
|
||||
# Verify that we can read UINF, ULST, and URL boxes. I don't have
|
||||
# easy access to such a file, and there's no such file in the
|
||||
|
|
@ -497,6 +529,7 @@ class TestJp2k(unittest.TestCase):
|
|||
self.assertEqual(jp2k.box[3].box[1].flag, (0, 0, 0))
|
||||
self.assertEqual(jp2k.box[3].box[1].url, 'abcd')
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_xml_box_with_trailing_nulls(self):
|
||||
# ElementTree does not like trailing null chars after valid XML
|
||||
# text.
|
||||
|
|
@ -526,6 +559,7 @@ class TestJp2k(unittest.TestCase):
|
|||
self.assertEqual(jp2k.box[3].offset, 77)
|
||||
self.assertEqual(jp2k.box[3].length, 36)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
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.
|
||||
|
|
@ -572,6 +606,7 @@ class TestJp2k(unittest.TestCase):
|
|||
self.assertEqual(jasoc.box[3].box[0].label, 'label')
|
||||
self.assertEqual(jasoc.box[3].box[1].box_id, 'xml ')
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_openjpeg_library_message(self):
|
||||
# Verify the error message produced by the openjpeg library.
|
||||
# This will confirm that the error callback mechanism is working.
|
||||
|
|
@ -616,6 +651,7 @@ class TestJp2k(unittest.TestCase):
|
|||
attr_value = elt.attrib['{0}CreatorTool'.format(ns1)]
|
||||
self.assertEqual(attr_value, 'glymur')
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
|
||||
def test_unrecognized_exif_tag(self):
|
||||
# An unrecognized exif tag should be handled gracefully.
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
||||
|
|
@ -671,42 +707,48 @@ class TestJp2k15(unittest.TestCase):
|
|||
pass
|
||||
|
||||
def test_bands(self):
|
||||
# Reading individual bands is an advanced maneuver.
|
||||
"""Reading individual bands is an advanced maneuver.
|
||||
"""
|
||||
jp2k = Jp2k(self.j2kfile)
|
||||
with self.assertRaises(NotImplementedError) as ce:
|
||||
jpdata = jp2k.read_bands()
|
||||
with self.assertRaises(NotImplementedError):
|
||||
jp2k.read_bands()
|
||||
|
||||
def test_area(self):
|
||||
# Area option not allowed for 1.5.1.
|
||||
"""Area option not allowed for 1.5.1.
|
||||
"""
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
with self.assertRaises(TypeError) as ce:
|
||||
d = j2k.read(area=(0, 0, 100, 100))
|
||||
with self.assertRaises(TypeError):
|
||||
j2k.read(area=(0, 0, 100, 100))
|
||||
|
||||
def test_tile(self):
|
||||
# tile option not allowed for 1.5.1.
|
||||
"""tile option not allowed for 1.5.1.
|
||||
"""
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
with self.assertRaises(TypeError) as ce:
|
||||
d = j2k.read(tile=0)
|
||||
with self.assertRaises(TypeError):
|
||||
j2k.read(tile=0)
|
||||
|
||||
def test_layer(self):
|
||||
# layer option not allowed for 1.5.1.
|
||||
"""layer option not allowed for 1.5.1.
|
||||
"""
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
with self.assertRaises(TypeError) as ce:
|
||||
d = j2k.read(layer=1)
|
||||
with self.assertRaises(TypeError):
|
||||
j2k.read(layer=1)
|
||||
|
||||
def test_basic_jp2(self):
|
||||
# This test is only useful when openjp2 is not available
|
||||
# and OPJ_DATA_ROOT is not set. We need at least one
|
||||
# working JP2 test.
|
||||
"""This test is only useful when openjp2 is not available
|
||||
and OPJ_DATA_ROOT is not set. We need at least one
|
||||
working JP2 test.
|
||||
"""
|
||||
j2k = Jp2k(self.jp2file)
|
||||
d = j2k.read(rlevel=1)
|
||||
j2k.read(rlevel=1)
|
||||
|
||||
def test_basic_j2k(self):
|
||||
# This test is only useful when openjp2 is not available
|
||||
# and OPJ_DATA_ROOT is not set. We need at least one
|
||||
# working J2K test.
|
||||
"""This test is only useful when openjp2 is not available
|
||||
and OPJ_DATA_ROOT is not set. We need at least one
|
||||
working J2K test.
|
||||
"""
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
d = j2k.read()
|
||||
j2k.read()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
The tests defined here roughly correspond to what is in the OpenJPEG test
|
||||
suite.
|
||||
"""
|
||||
#pylint: disable-all
|
||||
|
||||
from contextlib import contextmanager
|
||||
import os
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
The tests here do not correspond directly to the OpenJPEG test suite, but
|
||||
seem like logical negative tests to add.
|
||||
"""
|
||||
#pylint: disable-all
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
|
|
@ -71,6 +72,7 @@ class TestSuiteNegative(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
pass
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
def test_negative_psnr_with_cratios(self):
|
||||
# Using psnr with cratios options is not allowed.
|
||||
# Not an OpenJPEG test, but close.
|
||||
|
|
@ -126,6 +128,7 @@ class TestSuiteNegative(unittest.TestCase):
|
|||
# the end of SOT.
|
||||
self.assertEqual(c.segment[-1].marker_id, 'SOD')
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
def test_code_block_dimensions(self):
|
||||
# opj_compress doesn't allow the dimensions of a codeblock
|
||||
# to be too small or too big, so neither will we.
|
||||
|
|
@ -154,6 +157,7 @@ class TestSuiteNegative(unittest.TestCase):
|
|||
with self.assertWarns(UserWarning) as cw:
|
||||
j = Jp2k(infile)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
def test_precinct_size_not_multiple_of_two(self):
|
||||
# Seems like precinct sizes should be powers of two.
|
||||
ifile = Jp2k(self.j2kfile)
|
||||
|
|
@ -163,6 +167,7 @@ class TestSuiteNegative(unittest.TestCase):
|
|||
with self.assertRaises(IOError) as ce:
|
||||
ofile.write(data, psizes=[(13, 13)])
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
def test_codeblock_size_not_multiple_of_two(self):
|
||||
# Seems like code block sizes should be powers of two.
|
||||
ifile = Jp2k(self.j2kfile)
|
||||
|
|
@ -172,6 +177,7 @@ class TestSuiteNegative(unittest.TestCase):
|
|||
with self.assertRaises(IOError) as ce:
|
||||
ofile.write(data, cbsize=(13, 12))
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
def test_codeblock_size_with_precinct_size(self):
|
||||
# Seems like code block sizes should never exceed half that of
|
||||
# precinct size.
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
The tests defined here roughly correspond to what is in the OpenJPEG test
|
||||
suite.
|
||||
"""
|
||||
#pylint: disable-all
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
|
|
@ -57,6 +58,7 @@ def read_image(infile):
|
|||
return data
|
||||
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "no write support on windows, period")
|
||||
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||
"Missing openjp2 library.")
|
||||
@unittest.skipIf(no_read_backend, no_read_backend_msg)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#pylint: disable-all
|
||||
import os
|
||||
import pkg_resources
|
||||
import struct
|
||||
|
|
@ -21,6 +22,7 @@ except:
|
|||
raise
|
||||
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||
"Missing openjp2 library.")
|
||||
class TestPrintingNeedsLib(unittest.TestCase):
|
||||
|
|
@ -782,8 +784,7 @@ class TestPrinting(unittest.TestCase):
|
|||
expected = '\n'.join(lines)
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
@unittest.skipIf(os.name == "nt",
|
||||
"Problems using NamedTemporaryFile on windows.")
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
def test_less_common_boxes(self):
|
||||
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
|
||||
with open(self.jp2file, 'rb') as ifile:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
| OS | Python 2.7 | Python 3.3 | Notes |
|
||||
+------------+------------+------------+--------------------------------------+
|
||||
| Windows | X | | Python(xy) with OpenJPEG 1.5.1. |
|
||||
| | | | At least 25 tests should pass |
|
||||
| Windows | X | | Python(xy) with OpenJPEG 1.5.1. At |
|
||||
| | | | least 155 of 444 tests should pass. |
|
||||
+------------+------------+------------+--------------------------------------+
|
||||
| Windows | X | | Python(xy) with OpenJPEG 1.5.1 and |
|
||||
| | | | OpenJPEG svn. At least 282 of 444 |
|
||||
| | | | tests should pass. |
|
||||
+------------+------------+------------+--------------------------------------+
|
||||
| Mac | X | | MacPorts with both OpenJPEG 1.5.1 |
|
||||
| | | | and OpenJPEG svn. 370 of 450 tests |
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue