diff --git a/CHANGES.txt b/CHANGES.txt index 5e62c1c..d50310c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,6 @@ +Jan 28, 2014 - v0.5.10 Fixed bad warning when reader requirements box mask + length is unsupported. + Oct 29, 2013 - v0.5.9 Fixed bad library load on linux as a result of 0.5.8 Oct 29, 2013 - v0.5.8 Fixed unnecessary warnings when default locations for diff --git a/docs/source/conf.py b/docs/source/conf.py index b14af27..4b0eb14 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -78,7 +78,7 @@ copyright = u'2013, John Evans' # The short X.Y version. version = '0.5' # The full version, including alpha/beta/rc tags. -release = '0.5.9' +release = '0.5.10' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/source/roadmap.rst b/docs/source/roadmap.rst index f9216a3..1e336f1 100644 --- a/docs/source/roadmap.rst +++ b/docs/source/roadmap.rst @@ -9,3 +9,4 @@ Here's an incomplete list of what I'd like to focus on in the future. * investigate adding write support for UUID/XMP boxes (potentially a big project) * investigate JPIP (likely to be an even bigger project) +Support for Python 2.6 will be dropped with the 0.6.0 release. diff --git a/glymur/jp2box.py b/glymur/jp2box.py index bf88e4d..2b40630 100644 --- a/glymur/jp2box.py +++ b/glymur/jp2box.py @@ -1465,13 +1465,24 @@ class ReaderRequirementsBox(Jp2kBox): # Decodes Completely Mask read_buffer = fptr.read(2 * mask_length) + fuam = dcm = standard_flag = standard_mask = [] + vendor_feature = vendor_mask = [] + # The mask length tells us the format string to use when unpacking # from the buffer read from file. - mask_format = {1: 'B', 2: 'H', 4: 'I'}[mask_length] - fuam, dcm = struct.unpack('>' + mask_format * 2, read_buffer) + try: + mask_format = {1: 'B', 2: 'H', 4: 'I', 8: 'Q'}[mask_length] + fuam, dcm = struct.unpack('>' + mask_format * 2, read_buffer) + standard_flag, standard_mask = _parse_standard_flag(fptr, + mask_length) + vendor_feature, vendor_mask = _parse_vendor_features(fptr, + mask_length) - standard_flag, standard_mask = _parse_standard_flag(fptr, mask_length) - vendor_feature, vendor_mask = _parse_vendor_features(fptr, mask_length) + except KeyError: + msg = 'The ReaderRequirements box (rreq) has a mask length of {0} ' + msg += 'bytes, but only values of 1, 2, 4, or 8 are supported. ' + msg += 'The box contents will not be interpreted.' + warnings.warn(msg.format(mask_length), UserWarning) box = ReaderRequirementsBox(fuam, dcm, standard_flag, standard_mask, vendor_feature, vendor_mask, diff --git a/glymur/test/test_jp2box_jpx.py b/glymur/test/test_jp2box_jpx.py new file mode 100644 index 0000000..344a3cd --- /dev/null +++ b/glymur/test/test_jp2box_jpx.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +""" +Test suite specifically targeting JPX box layout. +""" + +import os +import struct +import sys +import tempfile +import warnings +import xml.etree.cElementTree as ET + +if sys.hexversion < 0x02070000: + import unittest2 as unittest +else: + import unittest + +import glymur +from glymur import Jp2k +from glymur.jp2box import ReaderRequirementsBox + + +@unittest.skipIf(sys.hexversion < 0x03000000, "Warning assert on 2.x.") +@unittest.skipIf(os.name == "nt", "Temporary file issue on window.") +class TestReaderRequirements(unittest.TestCase): + """Test suite for XML boxes.""" + + def setUp(self): + self.jp2file = glymur.data.nemo() + pass + + def tearDown(self): + pass + + def test_mask_length_is_3(self): + """The standard says that the mask length should be 1, 2, 4, or 8.""" + # Rewrite nemo to include this kind of rreq box. + with tempfile.NamedTemporaryFile(suffix=".jpx") as tfile: + with open(self.jp2file, 'rb') as nemof: + # Read the jP and ftyp boxes as-is. + write_buffer = nemof.read(32) + tfile.write(write_buffer) + + # Fake a rreq box with ML = 3. + write_buffer = struct.pack('>I4sB', 74, b'rreq', 3) + tfile.write(write_buffer) + + # pad the rest with zeros + write_buffer = struct.pack('>65s', b'\x00' * 65) + tfile.write(write_buffer) + + # Write the rest of nemo. + tfile.write(nemof.read()) + tfile.flush() + + with self.assertWarns(UserWarning): + j = Jp2k(tfile.name) + self.assertEqual(j.box[2].box_id, 'rreq') + self.assertEqual(type(j.box[2]), + glymur.jp2box.ReaderRequirementsBox) + diff --git a/glymur/version.py b/glymur/version.py index 6116920..d3d87db 100644 --- a/glymur/version.py +++ b/glymur/version.py @@ -15,7 +15,7 @@ from .lib import openjp2 as opj2 # Do not change the format of this next line! Doing so risks breaking # setup.py -version = "0.5.9" +version = "0.5.10" _sv = LooseVersion(version) version_tuple = _sv.version diff --git a/setup.py b/setup.py index 89e69f7..e2f72f0 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ kwargs = {'name': 'Glymur', 'description': 'Tools for accessing JPEG2000 files', 'long_description': open('README.md').read(), 'author': 'John Evans', - 'author_email': 'john.g.evans.ne at gmail dot com', + 'author_email': 'john.g.evans.ne@gmail.com', 'url': 'https://github.com/quintusdias/glymur', 'packages': ['glymur', 'glymur.data', 'glymur.test', 'glymur.lib', 'glymur.lib.test'],