From adddb134f8f07916e5cee424a4bb84fbc9e4b6a2 Mon Sep 17 00:00:00 2001 From: jevans Date: Sat, 8 Jun 2013 22:21:08 -0400 Subject: [PATCH] Handling first 36 bytes of header. --- glymur/jp2box.py | 71 ++++++++++++++++++++++++++++++++++++++++- glymur/test/__init__.py | 1 + 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/glymur/jp2box.py b/glymur/jp2box.py index 789c803..1854707 100644 --- a/glymur/jp2box.py +++ b/glymur/jp2box.py @@ -12,6 +12,7 @@ References """ import copy +import datetime import math import os import pprint @@ -221,12 +222,80 @@ class ColourSpecificationBox(Jp2kBox): # ICC profile kwargs['colorspace'] = None n = offset + length - f.tell() - kwargs['icc_profile'] = f.read(n) + icc_profile = ICCProfile(f.read(n)) + kwargs['icc_profile'] = icc_profile box = ColourSpecificationBox(**kwargs) return box +class ICCProfile: + """ + """ + profile_class = {b'scnr': 'input device profile', + b'mntr': 'display device profile', + b'prtr': 'output device profile', + b'link': 'devicelink profile', + b'spac': 'colorspace conversion profile', + b'abst': 'abstract profile', + b'nmcl': 'name colour profile'} + + colour_space_dict = {b'XYZ ': 'XYZ', + b'Lab ': 'Lab', + b'Luv ': 'Luv', + b'YCbr': 'YCbCr', + b'Yxy ': 'Yxy', + b'RGB ': 'RGB', + b'GRAY': 'gray', + b'HSV ': 'hsv', + b'HLS ': 'hls', + b'CMYK': 'CMYK', + b'CMY ': 'cmy', + b'2CLR': '2colour', + b'3CLR': '3colour', + b'4CLR': '4colour', + b'5CLR': '5colour', + b'6CLR': '6colour', + b'7CLR': '7colour', + b'8CLR': '8colour', + b'9CLR': '9colour', + b'ACLR': '10colour', + b'BCLR': '11colour', + b'CCLR': '12colour', + b'DCLR': '13colour', + b'ECLR': '14colour', + b'FCLR': '15colour'} + + def __init__(self, buffer): + self._raw_buffer = buffer + self.parse_header() + + def parse_header(self): + """See section 7.2""" + self.size, = struct.unpack('>I', self._raw_buffer[0:4]) + self.preferred_cmm_type, = struct.unpack('>I', self._raw_buffer[4:8]) + + data = struct.unpack('>BB', self._raw_buffer[8:10]) + major = data[0] + minor = (data[1] & 0xf0) >> 4 + bugfix = (data[1] & 0x0f) + self.version = '{0}.{1}.{2}'.format(major, minor, bugfix) + + self.device_class = self.profile_class[self._raw_buffer[12:16]] + self.colour_space = self.colour_space_dict[self._raw_buffer[16:20]] + self.connection_space = self.colour_space_dict[self._raw_buffer[20:24]] + + data = struct.unpack('>HHHHHH', self._raw_buffer[24:36]) + self.datetime = datetime.datetime(*data) + + print(self._raw_buffer[24:36]) + + def __str__(self): + msg = "Profile size: {0}" + msg = "Preferred CMM type: {1}" + msg = msg.format(self.size, + self.preferred_cmm_type) + class ComponentDefinitionBox(Jp2kBox): """Container for component definition box information. diff --git a/glymur/test/__init__.py b/glymur/test/__init__.py index 9677af5..1e19d88 100644 --- a/glymur/test/__init__.py +++ b/glymur/test/__init__.py @@ -1,6 +1,7 @@ from .test_callbacks import TestCallbacks as callbacks from .test_codestream import TestCodestream as codestream from .test_jp2k import TestJp2k as jp2k +from .test_icc import TestICC as icc from .test_printing import TestPrinting as printing from .test_opj_suite import TestSuite as suite from .test_opj_suite_write import TestSuiteWrite as suitew