Added write support for DataEntryURL box. Closes #154

This commit is contained in:
jevans 2014-02-06 20:45:26 -05:00
commit 1e3556e901
3 changed files with 48 additions and 7 deletions

View file

@ -1,11 +1,12 @@
Feb 03, 2014 - Removed support for Python 2.6. Added write support for Feb 03, 2014 - Removed support for Python 2.6. Added write support for
JP2 Palette and Component Mapping boxes, JPX Association and JP2 DataEntryURL, Palette and Component Mapping boxes, JPX
NumberList boxes. Added read support for JPX free, number list, Association and NumberList boxes. Added read support for JPX
data reference, fragment table, and fragment list boxes. Palette free, number list, data reference, fragment table, and fragment
box now a 2D numpy array instead of a list of 1D arrays. JP2 list boxes. Palette box now a 2D numpy array instead of a list
super box constructors now take optional box list argument. of 1D arrays. JP2 super box constructors now take optional box
Fixed bug where JPX files with more than one codestream but list argument. Fixed bug where JPX files with more than one
advertising jp2 compatibility were not being read. codestream but advertising jp2 compatibility were not being
read.
Jan 28, 2014 - v0.5.10 Fixed bad warning when reader requirements box mask Jan 28, 2014 - v0.5.10 Fixed bad warning when reader requirements box mask
length is unsupported. length is unsupported.

View file

@ -2518,6 +2518,18 @@ class DataEntryURLBox(Jp2kBox):
self.length = length self.length = length
self.offset = offset self.offset = offset
def write(self, fptr):
"""Write a data entry url box to file.
"""
length = 8 + 1 + 3 + len(self.url.encode())
write_buffer = struct.pack('>I4sBBBB',
length, self.box_id.encode(),
self.version,
self.flag[0], self.flag[1], self.flag[2])
fptr.write(write_buffer)
fptr.write(self.url.encode())
def __repr__(self): def __repr__(self):
msg = "glymur.jp2box.DataEntryURLBox({0}, {1}, '{2}')" msg = "glymur.jp2box.DataEntryURLBox({0}, {1}, '{2}')"
msg = msg.format(self.version, self.flag, self.url) msg = msg.format(self.version, self.flag, self.url)

View file

@ -52,6 +52,34 @@ def load_tests(loader, tests, ignore):
tests.addTests(doctest.DocTestSuite('glymur.jp2box')) tests.addTests(doctest.DocTestSuite('glymur.jp2box'))
return tests return tests
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
class TestDataEntryURL(unittest.TestCase):
"""Test suite for DataEntryURL boxes."""
def setUp(self):
self.jp2file = glymur.data.nemo()
def test_basic_url(self):
"""Just your most basic URL box."""
# Wrap our j2k file in a JP2 box along with an interior url box.
jp2 = Jp2k(self.jp2file)
url = 'http://glymur.readthedocs.org'
deurl = glymur.jp2box.DataEntryURLBox(0, (0, 0, 0), url)
boxes = [box for box in jp2.box if box.box_id != 'uuid']
boxes.append(deurl)
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile:
jp22 = jp2.wrap(tfile.name, boxes=boxes)
import shutil
shutil.copyfile(tfile.name, '/Users/jevans/a.jp2')
actdata = [box.box_id for box in jp22.box]
expdata = ['jP ', 'ftyp', 'jp2h', 'jp2c', 'url ']
self.assertEqual(actdata, expdata)
self.assertEqual(jp22.box[4].version, 0)
self.assertEqual(jp22.box[4].flag, (0, 0, 0))
self.assertEqual(jp22.box[4].url, url)
@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] < 2 or @unittest.skipIf(glymur.version.openjpeg_version_tuple[0] < 2 or
OPENJP2_IS_V2_OFFICIAL, OPENJP2_IS_V2_OFFICIAL,
"Not supported until 2.0+.") "Not supported until 2.0+.")