From 148729c4b42e66767076549952b3810822abb1cb Mon Sep 17 00:00:00 2001 From: jevans Date: Mon, 10 Jun 2013 19:46:07 -0400 Subject: [PATCH] Have figured out that we need a LOT of ICC standard documents. --- glymur/jp2box.py | 22 +++++++++++-- glymur/test/test_icc.py | 68 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 glymur/test/test_icc.py diff --git a/glymur/jp2box.py b/glymur/jp2box.py index 850c300..6086038 100644 --- a/glymur/jp2box.py +++ b/glymur/jp2box.py @@ -282,9 +282,12 @@ class ICCProfile: offset = data[1::3] size = data[2::3] for j in range(num_tags): - print("{0} at {1} of length {2}".format(signature[j], - offset[j], - size[j])) + sig = buffer[132 + j * 4:132 + (j + 1) * 4] + print(sig) + import pdb; pdb.set_trace() + tag_buffer = buffer[offset[j]:offset[j] + size[j]] + if sig == b'desc': + table['desc'] = _MultiLocalizedUnicodeType(tag_buffer) def parse_header(self, buffer): """See section 7.2""" @@ -333,6 +336,19 @@ class ICCProfile: msg = msg.format(self.size, self.preferred_cmm_type) +class _MultiLocalizedUnicodeType: + def __init__(self, buffer): + import pdb; pdb.set_trace() + self.id = buffer[0:4].decode('utf-8') + data = struct.unpack('>II', buffer[8:16]) + num_names = data[0] + self.record_size = data[1] + + data = struct.unpack('>' + 'HHII' * num_names, + buffer[16:16 + 12 * num_names]) + for j in range(num_names): + print(j) + class ComponentDefinitionBox(Jp2kBox): """Container for component definition box information. diff --git a/glymur/test/test_icc.py b/glymur/test/test_icc.py new file mode 100644 index 0000000..30d41fc --- /dev/null +++ b/glymur/test/test_icc.py @@ -0,0 +1,68 @@ +import datetime +import os +import struct +import sys +import tempfile +import unittest +import warnings +from xml.etree import cElementTree as ET + +import numpy as np +import pkg_resources + +from glymur import Jp2k +import glymur + +try: + data_root = os.environ['OPJ_DATA_ROOT'] +except KeyError: + data_root = None +except: + raise + + +class TestICC(unittest.TestCase): + + def setUp(self): + self.jp2file = pkg_resources.resource_filename(glymur.__name__, + "data/nemo.jp2") + + def tearDown(self): + pass + + @unittest.skipIf(data_root is None, + "OPJ_DATA_ROOT environment variable not set") + def test_file5(self): + filename = os.path.join(data_root, 'input/conformance/file5.jp2') + j = Jp2k(filename) + profile = j.box[3].box[1].icc_profile + self.assertEqual(profile.size, 546) + self.assertEqual(profile.preferred_cmm_type, 0) + self.assertEqual(profile.version, '2.2.0') + self.assertEqual(profile.device_class, 'input device profile') + self.assertEqual(profile.colour_space, 'RGB') + self.assertEqual(profile.datetime, + datetime.datetime(2001,8,30,13,32,37)) + self.assertEqual(profile.file_signature, 'acsp') + self.assertEqual(profile.platform, 'unrecognized') + self.assertTrue(profile.flags & 0x01) # embedded + self.assertFalse(profile.flags & 0x02) # use anywhere + + self.assertEqual(profile.device_manufacturer, 'KODA') + self.assertEqual(profile.device_model, 'ROMM') + + self.assertFalse(profile.device_attributes & 0x01) # reflective + self.assertFalse(profile.device_attributes & 0x02) # glossy + self.assertFalse(profile.device_attributes & 0x04) # positive + self.assertFalse(profile.device_attributes & 0x08) # colour + self.assertEqual(profile.rendering_intent & 0x00ff, 0) # perceptual + + np.testing.assert_almost_equal(profile.illuminant, + (0.964203, 1.000000, 0.824905), + decimal=6) + + self.assertEqual(profile.creator, 'JPEG') + +if __name__ == "__main__": + unittest.main() +