diff --git a/CHANGES.txt b/CHANGES.txt index efc70fc..d4b0eba 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,5 @@ +Jul 11, 2013 - v0.2.0 Support for Python 2.7 on windows, OpenJPEG 1.5.1. + Jun 27, 2013 - v0.1.10 Can wrap codestreams in custom JP2 jackets. Exposing parameter to specify multi component transform. Added a raw codestream file. diff --git a/MANIFEST.in b/MANIFEST.in index 86279d7..1390b67 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,4 @@ include *.txt *.md prune build exclude readthedocs-pip-requirements.txt +exclude release.txt diff --git a/docs/source/conf.py b/docs/source/conf.py index 6ddfcfb..47985ed 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.1' # The full version, including alpha/beta/rc tags. -release = '0.1.10' +release = '0.2.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/source/detailed_installation.rst b/docs/source/detailed_installation.rst index 5090cdc..d05dae4 100644 --- a/docs/source/detailed_installation.rst +++ b/docs/source/detailed_installation.rst @@ -1,16 +1,57 @@ ------------------------------------------------------ -Detailed Instructions for Package Management, Testing ------------------------------------------------------ +---------------------------------- +Detailed Installation Instructions +---------------------------------- -You only need to read this page if you want detailed +'''''''''''''''''''''' +Glymur Configuration +'''''''''''''''''''''' + +The default glymur installation process relies upon OpenJPEG version +1.5.1 being properly installed on your system. This will, however, only +give you you basic read capabilities, so if you wish to take advantage +of more of glymur's features, you should compile OpenJPEG as a shared +library (named *openjp2* instead of *openjpeg*) from the developmental +source that you can retrieve via subversion. As of this time of writing, +svn revision 2345 works. You should also download the test data for +the purpose of configuring and running OpenJPEG's test suite, check +their instructions for all this. You should set the **OPJ_DATA_ROOT** +environment variable for the purpose of running Glymur's test suite. :: + + $ svn co http://openjpeg.googlecode.com/svn/data + $ export OPJ_DATA_ROOT=`pwd`/data + +Glymur uses ctypes (for the moment) to access the openjp2 library, and +because ctypes access libraries in a platform-dependent manner, it is +recommended that you create a configuration file to help Glymur properly find +the openjp2 library. You may create the configuration file as follows:: + + $ mkdir -p ~/.config/glymur + $ cd ~/.config/glymur + $ cat > glymurrc << EOF + > [library] + > openjp2: /opt/openjp2-svn/lib/libopenjp2.so + > EOF + +This assumes, of course, that you've installed OpenJPEG into +/opt/openjp2-svn on a linux system. You may also substitute +**$XDG_CONFIG_HOME** for **$HOME/.config**. + +You may also include a line for the version 1.5.1 library if you have it installed +in a non-standard place, i.e. :: + + [library] + openjp2: /opt/openjp2-svn/lib/libopenjp2.so + openjpeg: /not/the/usual/location/lib/libopenjpeg.so + +''''''''''''''''''''''''''''''''''''''''''' +Package Management Suggestions for Testing +''''''''''''''''''''''''''''''''''''''''''' + +You only need to read this section if you want detailed platform-specific instructions on running as many tests as possible or wish to use your system's package manager to install as many required -packages/RPMs/ports/whatever without going through pip. Otherwise go on to -the next page. +packages/RPMs/ports/whatever without going through pip. -'''''''' -Platform -'''''''' Mac OS X -------- @@ -27,13 +68,29 @@ additionally be installed: * py33-scikit-image and either py33-Pillow or freeimage * py33-matplotlib and py33-Pillow +MacPorts supplies both OpenJPEG 1.5.0 and OpenJPEG 2.0.0. As previously +mentioned, the 2.0.0 official release is not supported (although the 2.0+ +development version via SVN *is* supported). + Linux ----- +Fedora 19 +''''''''' +Fedora 18 ships with Python 3.3 and all the necessary RPMs are available to +run the maximum number of tests. + + * python3 + * python3-numpy + * python3-setuptools + * python3-matplotlib (for running tests) + * python3-matplotlib-tk (or whichever matplotlib backend you prefer) + * python3-pillow (for running tests) + Fedora 18 ''''''''' -Fedora 18 ships with Python 3.3, so all the necessary RPMs are available to -meet the minimal set of requirements. +Fedora 18 ships with Python 3.3 and the following RPMs are available to +meet the minimal set of requirements for running glymur. * python3 * python3-numpy @@ -56,31 +113,10 @@ repositories:: $ pip-python3 install Pillow --user $ export PYTHONPATH=$HOME/.local/lib/python3.3/site-packages:$PYTHONPATH -Raspbian -'''''''' -Yeah, this was the first thing I tried after getting my new Raspberry Pi hooked -up (couldn't help myself :-) Raspbian ships with Python 3.2 and 2.7, so these steps detail working with 2.7. - -Additional required OS packages include:: - - * python-pip - * python-pkg-resources - * python-mock - -You must install contextlib2 via pip, and then you can run at least -a minimal number of tests. To attempt to run more of the tests, -install the following debs:: - - * python-dev - * python-matplotlib - -and then install Pillow via pip. The tests take about 30 minutes to run, with -one unexpected failure as of the time of writing. - Fedora 17 ''''''''' -Fedora 17 ships with Python 3.2 and 2.7, so these steps detail working with -2.7. +Fedora 17 ships with Python 3.2 and 2.7, but OpenJPEG is only at version 1.4, +so these steps detail working with Python 2.7 and the svn version of OpenJPEG. Required RPMs include:: @@ -111,19 +147,23 @@ it was installable via pip:: Windows ------- -Not currently supported. +The only configuration I've tested is Python(xy), which uses Python 2.7. +Python(xy) already comes with numpy, but you will have to install pip and then +contextlib2 and mock as well. Both 1.5.1 and the svn development versions of +openjpeg work. + ''''''' Testing ''''''' -If you wish to run the tests (strongly suggested :-), you can either run them +If you wish to run the tests (strongly recommended :-), you can either run them from within python as follows ... :: >>> import glymur >>> glymur.runtests() -or from the unix command line. :: +or from the command line. :: $ cd /to/where/you/unpacked/glymur $ python -m unittest discover diff --git a/docs/source/how_do_i.rst b/docs/source/how_do_i.rst index a15b865..5fcee3a 100644 --- a/docs/source/how_do_i.rst +++ b/docs/source/how_do_i.rst @@ -6,13 +6,13 @@ How do I...? Read the lowest resolution thumbnail? ===================================== Printing the Jp2k object should reveal the number of resolutions (look in the -COD segment section), but you can take a shortcut by supplying -1 as the reduce -level. :: +COD segment section), but you can take a shortcut by supplying -1 as the +resolution level. :: >>> import glymur >>> file = glymur.data.nemo() >>> j = glymur.Jp2k(file) - >>> thumbnail = j.read(reduce=-1) + >>> thumbnail = j.read(rlevel=-1) Display metadata? ================= diff --git a/docs/source/introduction.rst b/docs/source/introduction.rst index f8d4c65..3fbbb84 100644 --- a/docs/source/introduction.rst +++ b/docs/source/introduction.rst @@ -2,14 +2,9 @@ Glymur: a Python interface for JPEG 2000 ---------------------------------------- -**Glymur** contains a Python interface to the OpenJPEG library -which allows linux and mac users to read and write JPEG 2000 files. For more -information about OpenJPEG, please consult http://www.openjpeg.org. Glymur -currently relies upon a development version of the OpenJPEG library, and so, -while useable, it is totally at the mercy of any upstream changes -made to the development version of OpenJPEG. - -Glymur supports both reading and writing of JPEG 2000 images (part 1). Writing +**Glymur** is an interface to the OpenJPEG library +which allows one to read and write JPEG 2000 files from within Python. +Glymur supports both reading and writing of JPEG 2000 images. Writing JPEG 2000 images is currently limited to images that can fit in memory, however. @@ -23,34 +18,18 @@ Glymur works on Python 2.7 and 3.3. Python 3.3 is strongly recommended. OpenJPEG Installation ===================== -OpenJPEG must be built as a shared library. In addition, you -currently must compile OpenJPEG from the developmental source that -you can retrieve via subversion. As of this time of writing, svn -revision 2345 works. You should download the test data for the purpose -of configuring and running OpenJPEG's test suite, check their instructions for -all this. You should set the **OPJ_DATA_ROOT** environment variable for the -purpose of running Glymur's test suite. :: +The OpenJPEG library version must be either 1.5.1 or the trunk/development +version of OpenJPEG. Version 2.0.0 or versions earlier than 1.5.0 +are not supported. Furthermore, the 1.5.x version of OpenJPEG is +currently only utilized for read-only purposes. For more information +about OpenJPEG, please consult http://www.openjpeg.org. - $ svn co http://openjpeg.googlecode.com/svn/data - $ export OPJ_DATA_ROOT=`pwd`/data - -Earlier versions of OpenJPEG through the 2.0 official release will **NOT** -work and are not supported. - -Glymur uses ctypes (for the moment) to access the openjp2 library, and -because ctypes access libraries in a platform-dependent manner, it is -recommended that you create a configuration file to help Glymur properly find -the openjp2 library. You may create the configuration file as follows:: - - $ mkdir -p ~/.config/glymur - $ cd ~/.config/glymur - $ cat > glymurrc << EOF - > [library] - > openjp2: /opt/openjp2-svn/lib/libopenjp2.so - > EOF - -That assumes, of course, that you've installed OpenJPEG into /opt/openjp2-svn. -You may also substitute **$XDG_CONFIG_HOME** for **$HOME/.config**. +If you use MacPorts on the mac or if you have a sufficiently recent version of +Linux, your package manager should already provide you with at least version +1.5.1 of OpenJPEG, which means that glymur can be installed ready to read JPEG +2000 images. If you use windows, I suggest using the 1.5.1 windows installer +provided to you by the OpenJPEG folks at +https://code.google.com/p/openjpeg/downloads/list . Glymur Installation =================== @@ -76,5 +55,6 @@ You can run the tests from within python as follows:: >>> import glymur >>> glymur.runtests() -Many tests are currently skipped; the important thing is whether or not any -tests fail. +Many tests are currently skipped; in fact most of them are skipped if you +are relying on OpenJPEG 1.5.1. But the important thing, though, is whether or +not any tests fail. diff --git a/glymur/codestream.py b/glymur/codestream.py index 327dd19..ce11e9d 100644 --- a/glymur/codestream.py +++ b/glymur/codestream.py @@ -3,6 +3,7 @@ The module contains classes used to store information parsed from JPEG 2000 codestreams. """ +# pylint: disable=C0302,R0902,R0903,R0913 import math import struct @@ -11,22 +12,44 @@ import warnings import numpy as np -from .core import _progression_order_display -from .core import _wavelet_transform_display -from .core import _capabilities_display +from .core import LRCP, RLCP, RPCL, PCRL, CPRL +from .core import WAVELET_XFORM_9X7_IRREVERSIBLE +from .core import WAVELET_XFORM_5X3_REVERSIBLE +from .core import _CAPABILITIES_DISPLAY from .lib import openjp2 as opj2 +_PROGRESSION_ORDER_DISPLAY = { + LRCP: 'LRCP', + RLCP: 'RLCP', + RPCL: 'RPCL', + PCRL: 'PCRL', + CPRL: 'CPRL'} + +_WAVELET_TRANSFORM_DISPLAY = { + WAVELET_XFORM_9X7_IRREVERSIBLE: '9-7 irreversible', + WAVELET_XFORM_5X3_REVERSIBLE: '5-3 reversible'} + # Need a catch-all list of valid markers. # See table A-1 in ISO/IEC FCD15444-1. -_valid_markers = [0xff00, 0xff01, 0xfffe] +_VALID_MARKERS = [0xff00, 0xff01, 0xfffe] for _marker in range(0xffc0, 0xffe0): - _valid_markers.append(_marker) + _VALID_MARKERS.append(_marker) for _marker in range(0xfff0, 0xfff9): - _valid_markers.append(_marker) + _VALID_MARKERS.append(_marker) for _marker in range(0xff4f, 0xff70): - _valid_markers.append(_marker) + _VALID_MARKERS.append(_marker) for _marker in range(0xff90, 0xff94): - _valid_markers.append(_marker) + _VALID_MARKERS.append(_marker) + + +class InconsistentStartOfTileError(IOError): + """To be raised if bad SOT segment encountered. + + SOT segment offsets are recorded as encountered. The offsets should all be + different. + """ + def __init__(self, msg): + IOError.__init__(self, msg) class Codestream(object): @@ -47,178 +70,205 @@ class Codestream(object): 15444-1:2004 - Information technology -- JPEG 2000 image coding system: Core coding system """ - def __init__(self, f, header_only=True): + def __init__(self, fptr, header_only=True): """ Parameters ---------- - f : file + fptr : file Open file object. header_only : bool, optional If True, only marker segments in the main header are parsed. Supplying False may impose a large performance penalty. """ - self._parse_tile_part_bit_stream_flag = False + # Number of components. Must be kept track of for the processing of + # many segments. + self._csiz = -1 + + # Do we parse the tile part bit stream or not? + self._parse_tpart_flag = False self.segment = [] # First two bytes are the SOC marker - buffer = f.read(2) - marker_id, = struct.unpack('>H', buffer) - segment = SOCsegment(offset=f.tell() - 2, length=0) + read_buffer = fptr.read(2) + marker_id, = struct.unpack('>H', read_buffer) + segment = SOCsegment(offset=fptr.tell() - 2, length=0) self.segment.append(segment) - tile_offset = [] - tile_length = [] + self._tile_offset = [] + self._tile_length = [] while True: - offset = f.tell() - buffer = f.read(2) - marker_id, = struct.unpack('>H', buffer) - if marker_id >= 0xff30 and marker_id <= 0xff3f: - the_id = '0x{0:x}'.format(marker_id) - segment = Segment(id=the_id, offset=offset, length=0) + read_buffer = fptr.read(2) + marker_id, = struct.unpack('>H', read_buffer) - elif marker_id == 0xff51: - # Need to keep track of the number of components from SIZ for - # other markers - segment = self._parseSIZsegment(f) - self._Csiz = len(segment.Ssiz) - - elif marker_id == 0xff52: - segment = self._parseCODsegment(f) - - elif marker_id == 0xff53: - segment = self._parseCOCsegment(f) - - elif marker_id == 0xff55: - segment = self._parseTLMsegment(f) - - elif marker_id == 0xff58: - segment = self._parsePLTsegment(f) - - elif marker_id == 0xff5c: - segment = self._parseQCDsegment(f) - - elif marker_id == 0xff5d: - segment = self._parseQCCsegment(f) - - elif marker_id == 0xff5e: - segment = self._parseRGNsegment(f) - - elif marker_id == 0xff5f: - segment = self._parsePODsegment(f) - - elif marker_id == 0xff60: - segment = self._parsePPMsegment(f) - - elif marker_id == 0xff61: - segment = self._parsePPTsegment(f) - - elif marker_id == 0xff63: - segment = self._parseCRGsegment(f) - - elif marker_id == 0xff64: - segment = self._parseCMEsegment(f) - - elif marker_id == 0xff90: - # Need to keep easy access to tile offsets and lengths for when - # we encounter start-of-data marker segments. - if header_only: - # Stop parsing as soon as we hit the first Start Of Tile. - return - - segment = self._parseSOTsegment(f) - if segment.offset not in tile_offset: - tile_offset.append(segment.offset) - tile_length.append(segment.Psot) - else: - msg = "Inconsistent start-of-tile (SOT) marker segment " - msg += "encountered in tile with index {0}. " - msg += "Codestream parsing terminated." - msg = msg.format(segment.Isot) - warnings.warn(msg) - return - - elif marker_id == 0xff93: - # start of data. Need to seek past the current tile part. - # The last SOT marker segment has the info that we need. - segment = self._parseSODsegment(f) - - elif marker_id == 0xffd9: - # end of codestream - segment = self._parseEOCsegment(f) - self.segment.append(segment) + if marker_id == 0xff90 and header_only: + # start-of-tile (SOT) means we are out of the main header. + # No need to go any further. break - elif marker_id in _valid_markers: - # It's a reserved marker that I don't know anything about. - # See table A-1 in ISO/IEC FCD15444-1. - segment = self._parseGenericSegment(f, marker_id) - - elif ((marker_id & 0xff00) >> 8) == 255: - # Peek ahead to see if the next two bytes are a marker or not. - # Then seek back. - msg = "Unrecognized marker id: 0x{0:x}".format(marker_id) + try: + segment = self._process_marker_segment(fptr, marker_id) + except InconsistentStartOfTileError as isote: + # Treat this as a warning. + msg = str(isote) warnings.warn(msg) - cpos = f.tell() - buffer = f.read(2) - next_item, = struct.unpack('>H', buffer) - f.seek(cpos) - if ((next_item & 0xff00) >> 8) == 255: - # No segment associated with this marker, so reset - # to two bytes after it. - segment = Segment(id='0x{0:x}'.format(marker_id), - offset=offset, length=0) - else: - segment = self._parseGenericSegment(f, marker_id) - - else: - msg = 'Invalid marker id encountered at byte {0:d} ' - msg += 'in codestream: "0x{1:x}"' - msg = msg.format(offset, marker_id) - raise IOError(msg) + break self.segment.append(segment) + if marker_id == 0xffd9: + # end of codestream, should break. + break + if marker_id == 0xff93: # If SOD, then we need to seek past the tile part bit stream. - x = f.tell() - if self._parse_tile_part_bit_stream_flag: + if self._parse_tpart_flag: # But first parse the tile part bit stream for SOP and # EPH segments. - self._parse_tile_part_bit_stream(f, segment, - tile_length[-1]) + self._parse_tile_part_bit_stream(fptr, segment, + self._tile_length[-1]) - f.seek(tile_offset[-1] + tile_length[-1]) + fptr.seek(self._tile_offset[-1] + self._tile_length[-1]) - def _parse_tile_part_bit_stream(self, f, sod_marker, tile_length): + def _process_marker_segment(self, fptr, marker_id): + """Process and return a segment from the codestream. + """ + offset = fptr.tell() - 2 + + if marker_id >= 0xff30 and marker_id <= 0xff3f: + the_id = '0x{0:x}'.format(marker_id) + segment = Segment(marker_id=the_id, offset=offset, length=0) + + elif marker_id == 0xff51: + # Need to keep track of the number of components from SIZ for + # other markers + segment = _parse_siz_segment(fptr) + self._csiz = len(segment.ssiz) + + elif marker_id == 0xff52: + segment = _parse_cod_segment(fptr) + + sop = (segment.scod & 2) > 0 + eph = (segment.scod & 4) > 0 + + if sop or eph: + self._parse_tpart_flag = True + else: + self._parse_tpart_flag = False + + elif marker_id == 0xff53: + segment = self._parse_coc_segment(fptr) + + elif marker_id == 0xff55: + segment = _parse_tlm_segment(fptr) + + elif marker_id == 0xff58: + segment = _parse_plt_segment(fptr) + + elif marker_id == 0xff5c: + segment = _parse_qcd_segment(fptr) + + elif marker_id == 0xff5d: + segment = self._parse_qcc_segment(fptr) + + elif marker_id == 0xff5e: + segment = self._parse_rgn_segment(fptr) + + elif marker_id == 0xff5f: + segment = self._parse_pod_segment(fptr) + + elif marker_id == 0xff60: + segment = _parse_ppm_segment(fptr) + + elif marker_id == 0xff61: + segment = _parse_ppt_segment(fptr) + + elif marker_id == 0xff63: + segment = _parse_crg_segment(fptr, self._csiz) + + elif marker_id == 0xff64: + segment = _parse_cme_segment(fptr) + + elif marker_id == 0xff90: + # Need to keep easy access to tile offsets and lengths for when + # we encounter start-of-data marker segments. + + segment = _parse_sot_segment(fptr) + if segment.offset not in self._tile_offset: + self._tile_offset.append(segment.offset) + self._tile_length.append(segment.psot) + else: + msg = "Inconsistent start-of-tile (SOT) marker segment " + msg += "encountered in tile with index {0}. " + msg += "Codestream parsing terminated." + msg = msg.format(segment.isot) + raise InconsistentStartOfTileError(msg) + + elif marker_id == 0xff93: + # start of data. Need to seek past the current tile part. + # The last SOT marker segment has the info that we need. + segment = _parse_sod_segment(fptr) + + elif marker_id == 0xffd9: + # end of codestream + segment = _parse_eoc_segment(fptr) + + elif marker_id in _VALID_MARKERS: + # It's a reserved marker that I don't know anything about. + # See table A-1 in ISO/IEC FCD15444-1. + segment = _parse_generic_segment(fptr, marker_id) + + elif ((marker_id & 0xff00) >> 8) == 255: + # Peek ahead to see if the next two bytes are a marker or not. + # Then seek back. + msg = "Unrecognized marker id: 0x{0:x}".format(marker_id) + warnings.warn(msg) + cpos = fptr.tell() + read_buffer = fptr.read(2) + next_item, = struct.unpack('>H', read_buffer) + fptr.seek(cpos) + if ((next_item & 0xff00) >> 8) == 255: + # No segment associated with this marker, so reset + # to two bytes after it. + segment = Segment(id='0x{0:x}'.format(marker_id), + offset=offset, length=0) + else: + segment = _parse_generic_segment(fptr, marker_id) + + else: + msg = 'Invalid marker id encountered at byte {0:d} ' + msg += 'in codestream: "0x{1:x}"' + msg = msg.format(offset, marker_id) + raise IOError(msg) + + return segment + + def _parse_tile_part_bit_stream(self, fptr, sod_marker, tile_length): """Parse the tile part bit stream for SOP, EPH marker segments.""" - buffer = f.read(tile_length) + read_buffer = fptr.read(tile_length) # The tile length could possibly be too large and extend past # the end of file. We need to be a bit resilient. - count = min(tile_length, len(buffer)) - packet = np.frombuffer(buffer, dtype=np.uint8, count=count) + count = min(tile_length, len(read_buffer)) + packet = np.frombuffer(read_buffer, dtype=np.uint8, count=count) indices = np.where(packet == 0xff) for idx in indices[0]: try: if packet[idx+1] == 0x91 and (idx < (len(packet) - 5)): - kwargs = {} - kwargs['offset'] = sod_marker.offset + 2 + idx - kwargs['length'] = 4 + offset = sod_marker.offset + 2 + idx + length = 4 nsop = packet[(idx + 4):(idx+6)].view('uint16')[0] if sys.byteorder == 'little': nsop = nsop.byteswap() - kwargs['Nsop'] = nsop - segment = SOPsegment(**kwargs) + segment = SOPsegment(nsop, length, offset) self.segment.append(segment) elif packet[idx + 1] == 0x92: - kwargs = {} - kwargs['offset'] = sod_marker.offset + 2 + idx - kwargs['length'] = 0 - segment = EPHsegment(**kwargs) + offset = sod_marker.offset + 2 + idx + length = 0 + segment = EPHsegment(length, offset) self.segment.append(segment) except IndexError: continue @@ -233,170 +283,12 @@ class Codestream(object): msg += ''.join(strs) return msg - def _parseSIZsegment(self, f): - """Parse the SIZ segment. - - Parameters - ---------- - f : file - Open file object. - - Returns - ------- - SIZsegment instance. - """ - kwargs = {} - kwargs['offset'] = f.tell() - 2 - - buffer = f.read(38) - data = struct.unpack('>HHIIIIIIIIH', buffer) - - kwargs['length'] = data[0] - kwargs['Rsiz'] = data[1] - - Xsiz = data[2] - Ysiz = data[3] - XOsiz = data[4] - YOsiz = data[5] - XTsiz = data[6] - YTsiz = data[7] - XTOsiz = data[8] - YTOsiz = data[9] - - num_tiles_x = (Xsiz - XOsiz) / (XTsiz - XTOsiz) - num_tiles_y = (Ysiz - YOsiz) / (YTsiz - YTOsiz) - numtiles = math.ceil(num_tiles_x) * math.ceil(num_tiles_y) - if numtiles > 65535: - msg = "Invalid number of tiles ({0}).".format(numtiles) - warnings.warn(msg) - - kwargs['Xsiz'] = Xsiz - kwargs['Ysiz'] = Ysiz - kwargs['XOsiz'] = XOsiz - kwargs['YOsiz'] = YOsiz - kwargs['XTsiz'] = XTsiz - kwargs['YTsiz'] = YTsiz - kwargs['XTOsiz'] = XTOsiz - kwargs['YTOsiz'] = YTOsiz - - num_components = data[10] - buffer = f.read(num_components * 3) - data = struct.unpack('>' + 'B' * num_components * 3, buffer) - - Ssiz = data[0::3] - kwargs['Ssiz'] = Ssiz - kwargs['_bitdepth'] = tuple(((x & 0x7f) + 1) for x in Ssiz) - kwargs['_signed'] = tuple(((x & 0xb0) > 0) for x in Ssiz) - - ssf = [] - for j, subsampling in enumerate(list(zip(data[1::3], data[2::3]))): - if 0 in subsampling: - msg = "Invalid subsampling value for component {0}: " - msg += "dx={1}, dy={2}." - msg = msg.format(j, subsampling[0], subsampling[1]) - warnings.warn(msg) - kwargs['XRsiz'] = data[1::3] - kwargs['YRsiz'] = data[2::3] - - return SIZsegment(**kwargs) - - def _parseGenericSegment(self, f, marker_id): - """Parse a generic marker segment. - - Parameters - ---------- - f : file - Open file object. - - Returns - ------- - Segment instance. - """ - kwargs = {} - offset = f.tell() - 2 - - buffer = f.read(2) - length, = struct.unpack('>H', buffer) - data = f.read(length-2) - - segment = Segment(id='0x{0:x}'.format(marker_id), - offset=offset, length=length) - segment.data = data - return segment - - def _parseCMEsegment(self, f): - """Parse the CME marker segment. - - Parameters - ---------- - f : file - Open file object. - - Returns - ------- - CME segment instance. - """ - kwargs = {} - kwargs['offset'] = f.tell() - 2 - - buffer = f.read(4) - data = struct.unpack('>HH', buffer) - kwargs['length'] = data[0] - kwargs['Rcme'] = data[1] - kwargs['Ccme'] = f.read(kwargs['length'] - 4) - - return CMEsegment(**kwargs) - - def _parseCRGsegment(self, f): - """Parse the CRG marker segment. - - Parameters - ---------- - f : file - Open file object. - - Returns - ------- - CRG segment instance. - """ - kwargs = {} - kwargs['offset'] = f.tell() - 2 - - buffer = f.read(2) - length, = struct.unpack('>H', buffer) - kwargs['length'] = length - - buffer = f.read(4 * self._Csiz) - data = struct.unpack('>' + 'HH' * self._Csiz, buffer) - kwargs['Xcrg'] = data[0::2] - kwargs['Ycrg'] = data[1::2] - - return CRGsegment(**kwargs) - - def _parseEOCsegment(self, f): - """Parse the EOC marker segment. - - Parameters - ---------- - f : file - Open file object. - - Returns - ------- - EOC Segment instance. - """ - kwargs = {} - kwargs['offset'] = f.tell() - 2 - kwargs['length'] = 0 - - return EOCsegment(**kwargs) - - def _parseCOCsegment(self, f): + def _parse_coc_segment(self, fptr): """Parse the COC marker segment. Parameters ---------- - f : file + fptr : file Open file object. Returns @@ -404,469 +296,127 @@ class Codestream(object): COC segment instance. """ kwargs = {} - offset = f.tell() - 2 + offset = fptr.tell() - 2 kwargs['offset'] = offset - buffer = f.read(2) - length, = struct.unpack('>H', buffer) + read_buffer = fptr.read(2) + length, = struct.unpack('>H', read_buffer) kwargs['length'] = length - if self._Csiz <= 255: - buffer = f.read(1) - component, = struct.unpack('>B', buffer) + if self._csiz <= 255: + read_buffer = fptr.read(1) + component, = struct.unpack('>B', read_buffer) else: - buffer = f.read(2) - component, = struct.unpack('>H', buffer) - kwargs['Ccoc'] = component + read_buffer = fptr.read(2) + component, = struct.unpack('>H', read_buffer) + ccoc = component - buffer = f.read(1) - kwargs['Scoc'], = struct.unpack('>B', buffer) + read_buffer = fptr.read(1) + scoc, = struct.unpack('>B', read_buffer) - n = offset + 2 + length - f.tell() - buffer = f.read(n) - SPcoc = np.frombuffer(buffer, dtype=np.uint8) - kwargs['SPcoc'] = SPcoc + numbytes = offset + 2 + length - fptr.tell() + read_buffer = fptr.read(numbytes) + spcoc = np.frombuffer(read_buffer, dtype=np.uint8) + spcoc = spcoc - e1 = SPcoc[1] - e2 = SPcoc[2] - _code_block_size = (4 * math.pow(2, e2), 4 * math.pow(2, e1)) - kwargs['_code_block_size'] = _code_block_size + return COCsegment(ccoc, scoc, spcoc, length, offset) - if len(SPcoc) > 5: - kwargs['_precinct_size'] = _parse_precinct_size(SPcoc[5:]) - else: - kwargs['_precinct_size'] = None - - return COCsegment(**kwargs) - - def _parseCODsegment(self, f): - """Parse the COD segment. - - Parameters - ---------- - f : file - Open file object. - - Returns - ------- - COD segment instance. - """ - kwargs = {} - offset = f.tell() - 2 - kwargs['offset'] = f.tell() - 2 - - buffer = f.read(3) - length, Scod = struct.unpack('>HB', buffer) - kwargs['length'] = length - kwargs['Scod'] = Scod - - sop = (Scod & 2) > 0 - eph = (Scod & 4) > 0 - - if sop or eph: - self._parse_tile_part_bit_stream_flag = True - else: - self._parse_tile_part_bit_stream_flag = False - - n = offset + 2 + length - f.tell() - SPcod = f.read(n) - kwargs['SPcod'] = np.frombuffer(SPcod, dtype=np.uint8) - - params = struct.unpack('>BHBBBBBB', SPcod[0:9]) - kwargs['_layers'] = params[1] - kwargs['_numresolutions'] = params[3] - - if params[3] > opj2._J2K_MAXRLVLS: - msg = "Invalid number of resolutions ({0})." - msg = msg.format(params[3] + 1) - warnings.warn(msg) - - cblk_width = 4 * math.pow(2, params[4]) - cblk_height = 4 * math.pow(2, params[5]) - code_block_size = (cblk_height, cblk_width) - kwargs['_code_block_size'] = code_block_size - - if len(SPcod) > 9: - kwargs['_precinct_size'] = _parse_precinct_size(SPcod[9:]) - else: - kwargs['_precinct_size'] = None - - return CODsegment(**kwargs) - - def _parsePODsegment(self, f): + def _parse_pod_segment(self, fptr): """Parse the POD segment. Parameters ---------- - f : file + fptr : file Open file object. Returns ------- POD segment instance. """ - kwargs = {} - kwargs['offset'] = f.tell() - 2 + offset = fptr.tell() - 2 - buffer = f.read(2) - length, = struct.unpack('>H', buffer) + read_buffer = fptr.read(2) + length, = struct.unpack('>H', read_buffer) - if self._Csiz < 257: - n = int((length - 2) / 7) - buffer = f.read(n * 7) - fmt = '>' + 'BBHBBB' * n + if self._csiz < 257: + numbytes = int((length - 2) / 7) + read_buffer = fptr.read(numbytes * 7) + fmt = '>' + 'BBHBBB' * numbytes else: - n = int((length - 2) / 9) - buffer = f.read(n * 9) - fmt = '>' + 'BHHBHB' * n + numbytes = int((length - 2) / 9) + read_buffer = fptr.read(numbytes * 9) + fmt = '>' + 'BHHBHB' * numbytes - data = struct.unpack(fmt, buffer) + pod_params = struct.unpack(fmt, read_buffer) - kwargs['length'] = length - kwargs['RSpod'] = data[0::6] - kwargs['CSpod'] = data[1::6] - kwargs['LYEpod'] = data[2::6] - kwargs['REpod'] = data[3::6] - kwargs['CEpod'] = data[4::6] - kwargs['Ppod'] = data[5::6] + return PODsegment(pod_params, length, offset) - return PODsegment(**kwargs) - - def _parsePPMsegment(self, f): - """Parse the PPM segment. - - Parameters - ---------- - f : file - Open file object. - - Returns - ------- - PPM segment instance. - """ - kwargs = {} - kwargs['offset'] = f.tell() - 2 - - buffer = f.read(3) - length, zppm = struct.unpack('>HB', buffer) - kwargs['length'] = length - kwargs['Zppm'] = zppm - - n = length - 3 - kwargs['data'] = f.read(n) - - return PPMsegment(**kwargs) - - def _parsePLTsegment(self, f): - """Parse the PLT segment. - - The packet headers are not parsed, i.e. they remain "uninterpreted" - raw data beffers. - - Parameters - ---------- - f : file - Open file object. - - Returns - ------- - PLT segment instance. - """ - kwargs = {} - kwargs['offset'] = f.tell() - 2 - - buffer = f.read(3) - length, zplt = struct.unpack('>HB', buffer) - kwargs['length'] = length - kwargs['Zplt'] = zplt - - n = length - 3 - buffer = f.read(n) - iplt = np.frombuffer(buffer, dtype=np.uint8) - - packet_len = [] - plen = 0 - for x in iplt: - plen |= (x & 0x7f) - if x & 0x80: - # Continue by or-ing in the next byte. - plen <<= 7 - else: - packet_len.append(plen) - plen = 0 - - kwargs['Iplt'] = packet_len - - return PLTsegment(**kwargs) - - def _parsePPTsegment(self, f): - """Parse the PPT segment. - - The packet headers are not parsed, i.e. they remain "uninterpreted" - raw data beffers. - - Parameters - ---------- - f : file - Open file object. - - Returns - ------- - PPT segment instance. - """ - kwargs = {} - kwargs['offset'] = f.tell() - 2 - - buffer = f.read(3) - length, zppt = struct.unpack('>HB', buffer) - kwargs['length'] = length - kwargs['Zppt'] = zppt - - n = length - 3 - kwargs['Ippt'] = f.read(n) - - return PPTsegment(**kwargs) - - def _parseQuantization(self, buffer, sqcd): - """Tease out the quantization values. - - Args: - buffer: sequence of bytes from the QCC and QCD segments. - """ - n = len(buffer) - - exponent = [] - mantissa = [] - - if sqcd & 0x1f == 0: # no quantization - data = struct.unpack('>' + 'B' * n, buffer) - for j in range(len(data)): - exponent.append(data[j] >> 3) - mantissa.append(0) - else: - fmt = '>' + 'H' * int(n / 2) - data = struct.unpack(fmt, buffer) - for j in range(len(data)): - exponent.append(data[j] >> 11) - mantissa.append(data[j] & 0x07ff) - - return mantissa, exponent - - def _parseQCCsegment(self, f): + def _parse_qcc_segment(self, fptr): """Parse the QCC segment. Parameters ---------- - f : file + fptr : file Open file object. Returns ------- QCC Segment instance. """ - kwargs = {} - offset = f.tell() - 2 - kwargs['offset'] = offset + offset = fptr.tell() - 2 - buffer = f.read(2) - length, = struct.unpack('>H', buffer) - kwargs['length'] = length + read_buffer = fptr.read(2) + length, = struct.unpack('>H', read_buffer) - if self._Csiz > 256: - buffer = f.read(3) + if self._csiz > 256: + read_buffer = fptr.read(3) fmt = '>HB' - n = length - 5 + mantissa_exponent_buffer_length = length - 5 else: - buffer = f.read(2) + read_buffer = fptr.read(2) fmt = '>BB' - n = length - 4 - Cqcc, Sqcc = struct.unpack(fmt, buffer) - if Cqcc >= self._Csiz: + mantissa_exponent_buffer_length = length - 4 + cqcc, sqcc = struct.unpack(fmt, read_buffer) + if cqcc >= self._csiz: msg = "Invalid component number (%d), " msg += "number of components is only %d." - msg = msg.format(Cqcc, self._Csiz) + msg = msg.format(cqcc, self._csiz) warnings.warn(msg) - kwargs['Cqcc'] = Cqcc - kwargs['Sqcc'] = Sqcc - kwargs['_guardBits'] = (Sqcc & 0xe0) >> 5 + spqcc = fptr.read(mantissa_exponent_buffer_length) - buffer = f.read(n) + return QCCsegment(cqcc, sqcc, spqcc, length, offset) - mantissa, exponent = self._parseQuantization(buffer, Sqcc) - - kwargs['SPqcc'] = buffer - kwargs['_exponent'] = exponent - kwargs['_mantissa'] = mantissa - - return QCCsegment(**kwargs) - - def _parseQCDsegment(self, f): - """Parse the QCD segment. - - Parameters - ---------- - f : file - Open file object. - - Returns - ------- - QCD Segment instance. - """ - kwargs = {} - kwargs['offset'] = f.tell() - 2 - - buffer = f.read(3) - length, sqcd = struct.unpack('>HB', buffer) - kwargs['length'] = length - kwargs['Sqcd'] = sqcd - - kwargs['_guardBits'] = (sqcd & 0xe0) >> 5 - - buffer = f.read(length - 3) - - mantissa, exponent = self._parseQuantization(buffer, sqcd) - - kwargs['SPqcd'] = buffer - kwargs['_exponent'] = exponent - kwargs['_mantissa'] = mantissa - - return QCDsegment(**kwargs) - - def _parseRGNsegment(self, f): + def _parse_rgn_segment(self, fptr): """Parse the RGN segment. Parameters ---------- - f : file + fptr : file Open file object. Returns ------- RGN segment instance. """ - kwargs = {} - kwargs['offset'] = f.tell() - 2 + offset = fptr.tell() - 2 - buffer = f.read(2) - length, = struct.unpack('>H', buffer) + read_buffer = fptr.read(2) + length, = struct.unpack('>H', read_buffer) - if self._Csiz < 257: - buffer = f.read(3) - data = struct.unpack('>BBB', buffer) + if self._csiz < 257: + read_buffer = fptr.read(3) + data = struct.unpack('>BBB', read_buffer) else: - buffer = f.read(4) - data = struct.unpack('>HBB', buffer) + read_buffer = fptr.read(4) + data = struct.unpack('>HBB', read_buffer) - kwargs['length'] = length - kwargs['Crgn'] = data[0] - kwargs['Srgn'] = data[1] - kwargs['SPrgn'] = data[2] + length = length + crgn = data[0] + srgn = data[1] + sprgn = data[2] - return RGNsegment(**kwargs) - - def _parseSODsegment(self, f): - """Parse the SOD segment. - - Parameters - ---------- - f : file - Open file object. - - Returns - ------- - SOD segment instance. - """ - kwargs = {} - kwargs['offset'] = f.tell() - 2 - kwargs['length'] = 0 - - return SODsegment(**kwargs) - - def _parseSOTsegment(self, f): - """Parse the SOT segment. - - Parameters - ---------- - f : file - Open file object. - - Returns - ------- - SOT segment instance. - """ - kwargs = {} - kwargs['offset'] = f.tell() - 2 - - buffer = f.read(10) - data = struct.unpack('>HHIBB', buffer) - - kwargs['length'] = data[0] - kwargs['Isot'] = data[1] - kwargs['Psot'] = data[2] - kwargs['TPsot'] = data[3] - kwargs['TNsot'] = data[4] - - return SOTsegment(**kwargs) - - def _parseTLMsegment(self, f): - """Parse the TLM segment. - - Parameters - ---------- - f : file - Open file object. - - Returns - ------- - TLM segment instance. - """ - kwargs = {} - offset = f.tell() - 2 - kwargs['offset'] = offset - - buffer = f.read(2) - length, = struct.unpack('>H', buffer) - kwargs['length'] = length - - buffer = f.read(2) - Ztlm, Stlm = struct.unpack('>BB', buffer) - st = (Stlm >> 4) & 0x3 - sp = (Stlm >> 6) & 0x1 - - nbytes = length - 4 - if st == 0: - ntiles = nbytes / ((sp + 1) * 2) - else: - ntiles = nbytes / (st + (sp + 1) * 2) - - buffer = f.read(nbytes) - if st == 0: - Ttlm = None - fmt = '' - elif st == 1: - fmt = 'B' - elif st == 2: - fmt = 'H' - - if sp == 0: - fmt += 'H' - else: - fmt += 'I' - - data = struct.unpack('>' + fmt * int(ntiles), buffer) - if st == 0: - Ttlm = None - Ptlm = data - else: - Ttlm = data[0::2] - Ptlm = data[1::2] - - kwargs['Ztlm'] = Ztlm - kwargs['Ttlm'] = Ttlm - kwargs['Ptlm'] = Ptlm - - return TLMsegment(**kwargs) + return RGNsegment(length, offset, crgn, srgn, sprgn) class Segment(object): @@ -874,7 +424,7 @@ class Segment(object): Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. @@ -882,47 +432,36 @@ class Segment(object): Length of marker segment in bytes. This number does not include the two bytes constituting the marker. """ - def __init__(self, id='', offset=-1, length=-1): - self.id = id + def __init__(self, marker_id='', offset=-1, length=-1, data=None): + self.marker_id = marker_id self.offset = offset self.length = length + self._data = data def __str__(self): - msg = '{0} marker segment @ ({1}, {2})'.format(self.id, + msg = '{0} marker segment @ ({1}, {2})'.format(self.marker_id, self.offset, self.length) return msg - def _print_quantization_style(self, sqcc): - """Only to be used with QCC and QCD segments.""" - - msg = '\n Quantization style: ' - if sqcc & 0x1f == 0: - msg += 'no quantization, ' - elif sqcc & 0x1f == 1: - msg += 'scalar implicit, ' - elif sqcc & 0x1f == 2: - msg += 'scalar explicit, ' - return msg - class COCsegment(Segment): """COC (Coding style Component) segment information. Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. length : int Length of marker segment in bytes. This number does not include the two bytes constituting the marker. - Ccoc : byte + ccoc : int Index of associated component. - Scoc : byte + scoc : int Coding style for this component. - SPcoc : byte array + spcoc : byte array Coding style parameters for this component. References @@ -931,32 +470,45 @@ class COCsegment(Segment): 15444-1:2004 - Information technology -- JPEG 2000 image coding system: Core coding system """ - def __init__(self, **kwargs): - Segment.__init__(self, id='COC') - self.__dict__.update(**kwargs) + def __init__(self, ccoc, scoc, spcoc, length, offset): + Segment.__init__(self, marker_id='COC') + self.ccoc = ccoc + self.scoc = scoc + self.spcoc = spcoc + + self._code_block_size = (4 * math.pow(2, self.spcoc[2]), + 4 * math.pow(2, self.spcoc[1])) + + if len(self.spcoc) > 5: + self._precinct_size = _parse_precinct_size(self.spcoc[5:]) + else: + self._precinct_size = None + + self.length = length + self.offset = offset def __str__(self): msg = Segment.__str__(self) - msg += '\n Associated component: {0}'.format(self.Ccoc) + msg += '\n Associated component: {0}'.format(self.ccoc) msg += '\n Coding style for this component: ' - if self.Scoc == 0: + if self.scoc == 0: msg += 'Entropy coder, PARTITION = 0' - elif self.Scoc & 0x01: + elif self.scoc & 0x01: msg += 'Entropy coder, PARTITION = 1' msg += '\n Coding style parameters:' msg += '\n Number of resolutions: {0}' msg += '\n Code block height, width: ({1} x {2})' msg += '\n Wavelet transform: {3}' - msg = msg.format(self.SPcoc[0] + 1, + msg = msg.format(self.spcoc[0] + 1, int(self._code_block_size[0]), int(self._code_block_size[1]), - _wavelet_transform_display[self.SPcoc[4]]) + _WAVELET_TRANSFORM_DISPLAY[self.spcoc[4]]) msg += '\n ' - msg += _context_string(self.SPcoc[3]) + msg += _context_string(self.spcoc[3]) if self._precinct_size is not None: msg += '\n Precinct size: ' @@ -971,16 +523,16 @@ class CODsegment(Segment): Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. length : int Length of marker segment in bytes. This number does not include the two bytes constituting the marker. - Scod : int + scod : int Default coding style. - SPcod : bytes + spcod : bytes Coding style parameters, including quality layers, multicomponent transform usage, decomposition levels, code block size, style of code- block passes, and which wavelet transform is used. @@ -991,9 +543,31 @@ class CODsegment(Segment): 15444-1:2004 - Information technology -- JPEG 2000 image coding system: Core coding system """ - def __init__(self, **kwargs): - Segment.__init__(self, id='COD') - self.__dict__.update(**kwargs) + def __init__(self, scod, spcod, length, offset): + Segment.__init__(self, marker_id='COD') + self.scod = scod + self.spcod = spcod + self.length = length + self.offset = offset + + params = struct.unpack('>BHBBBBBB', self.spcod[0:9]) + self._layers = params[1] + self._numresolutions = params[3] + + if params[3] > opj2.J2K_MAXRLVLS: + msg = "Invalid number of resolutions ({0})." + msg = msg.format(params[3] + 1) + warnings.warn(msg) + + cblk_width = 4 * math.pow(2, params[4]) + cblk_height = 4 * math.pow(2, params[5]) + code_block_size = (cblk_height, cblk_width) + self._code_block_size = code_block_size + + if len(self.spcod) > 9: + self._precinct_size = _parse_precinct_size(self.spcod[9:]) + else: + self._precinct_size = None def __str__(self): msg = Segment.__str__(self) @@ -1002,15 +576,15 @@ class CODsegment(Segment): msg += '\n Entropy coder, {0} partitions' msg += '\n SOP marker segments: {1}' msg += '\n EPH marker segments: {2}' - msg = msg.format('with' if (self.Scod & 1) else 'without', - ((self.Scod & 2) > 0), - ((self.Scod & 4) > 0)) + msg = msg.format('with' if (self.scod & 1) else 'without', + ((self.scod & 2) > 0), + ((self.scod & 4) > 0)) - if self.SPcod[3] == 0: + if self.spcod[3] == 0: mct = 'no transform specified' - elif self.SPcod[3] & 0x01: + elif self.spcod[3] & 0x01: mct = 'reversible' - elif self.SPcod[3] & 0x02: + elif self.spcod[3] & 0x02: mct = 'irreversible' else: mct = 'unknown' @@ -1025,13 +599,13 @@ class CODsegment(Segment): ' Wavelet transform: {6}'] msg += '\n '.join(lines) - msg = msg.format(_progression_order_display[self.SPcod[0]], + msg = msg.format(_PROGRESSION_ORDER_DISPLAY[self.spcod[0]], self._layers, mct, - self.SPcod[4] + 1, + self.spcod[4] + 1, int(self._code_block_size[0]), int(self._code_block_size[1]), - _wavelet_transform_display[self.SPcod[8]]) + _WAVELET_TRANSFORM_DISPLAY[self.spcod[8]]) msg += '\n Precinct size: ' if self._precinct_size is None: @@ -1041,7 +615,7 @@ class CODsegment(Segment): msg += '({0}, {1})'.format(pps[0], pps[1]) msg += '\n ' - msg += _context_string(self.SPcod[7]) + msg += _context_string(self.spcod[7]) return msg @@ -1051,17 +625,17 @@ class CMEsegment(Segment): Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. length : int Length of marker segment in bytes. This number does not include the two bytes constituting the marker. - Rcme : int + rcme : int Registration value of the marker segment. Zero means general binary values, otherwise probably a string encoded in latin-1. - Ccme: bytes + ccme: bytes Raw bytes representing the comment data. References @@ -1070,19 +644,22 @@ class CMEsegment(Segment): 15444-1:2004 - Information technology -- JPEG 2000 image coding system: Core coding system """ - def __init__(self, **kwargs): - Segment.__init__(self, id='CME') - self.__dict__.update(**kwargs) + def __init__(self, rcme, ccme, length, offset): + Segment.__init__(self, marker_id='CME') + self.rcme = rcme + self.ccme = ccme + self.length = length + self.offset = offset def __str__(self): msg = Segment.__str__(self) + '\n' - if self.Rcme == 1: + if self.rcme == 1: # latin-1 string msg += ' "{0}"' - msg = msg.format(self.Ccme.decode('latin-1')) + msg = msg.format(self.ccme.decode('latin-1')) else: - msg += " binary data (Rcme = {0}): {1} bytes" - msg = msg.format(self.Rcme, len(self.Ccme)) + msg += " binary data (rcme = {0}): {1} bytes" + msg = msg.format(self.rcme, len(self.ccme)) return msg @@ -1091,26 +668,29 @@ class CRGsegment(Segment): Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. length : int Length of marker segment in bytes. This number does not include the two bytes constituting the marker. - Xcrg, Ycrg : int + xcrg, ycrg : int Horizontal, vertical offset for each component """ - def __init__(self, **kwargs): - Segment.__init__(self, id='CRG') - self.__dict__.update(**kwargs) + def __init__(self, xcrg, ycrg, length, offset): + Segment.__init__(self, marker_id='CRG') + self.xcrg = xcrg + self.ycrg = ycrg + self.length = length + self.offset = offset def __str__(self): msg = Segment.__str__(self) msg += '\n Vertical, Horizontal offset: ' - for j in range(len(self.Xcrg)): - msg += ' ({0:.2f}, {1:.2f})'.format(self.Ycrg[j]/65535.0, - self.Xcrg[j]/65535.0) + for j in range(len(self.xcrg)): + msg += ' ({0:.2f}, {1:.2f})'.format(self.ycrg[j]/65535.0, + self.xcrg[j]/65535.0) return msg @@ -1119,7 +699,7 @@ class EOCsegment(Segment): Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. @@ -1134,9 +714,10 @@ class EOCsegment(Segment): 15444-1:2004 - Information technology -- JPEG 2000 image coding system: Core coding system """ - def __init__(self, **kwargs): - Segment.__init__(self, id='EOC') - self.__dict__.update(**kwargs) + def __init__(self, length, offset): + Segment.__init__(self, marker_id='EOC') + self.length = length + self.offset = offset class PODsegment(Segment): @@ -1144,24 +725,24 @@ class PODsegment(Segment): Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. length : int Length of marker segment in bytes. This number does not include the two bytes constituting the marker. - RSpod : tuple + rspod : tuple resolution indices for start of a progression - CSpod : tuple + cspod : tuple component indices for start of a progression - LYEpod : tuple + lyepod : tuple layer indices for end of a progression - REpod : tuple + repod : tuple resolution indices for end of a progression - CEpod : tuple + cdpod : tuple component indices for end of a progression - Ppod : tuple + ppod : tuple progression order for each change References @@ -1170,13 +751,21 @@ class PODsegment(Segment): 15444-1:2004 - Information technology -- JPEG 2000 image coding system: Core coding system """ - def __init__(self, **kwargs): - Segment.__init__(self, id='POD') - self.__dict__.update(**kwargs) + def __init__(self, pod_params, length, offset): + Segment.__init__(self, marker_id='POD') + + self.rspod = pod_params[0::6] + self.cspod = pod_params[1::6] + self.lyepod = pod_params[2::6] + self.repod = pod_params[3::6] + self.cdpod = pod_params[4::6] + self.ppod = pod_params[5::6] + self.length = length + self.offset = offset def __str__(self): msg = Segment.__str__(self) - for j in range(len(self.RSpod)): + for j in range(len(self.rspod)): msg += '\n ' lines = ['Progression change {0}:', @@ -1188,12 +777,12 @@ class PODsegment(Segment): ' Progression order: {6}'] submsg = '\n '.join(lines) msg += submsg.format(j, - self.RSpod[j], - self.CSpod[j], - self.LYEpod[j], - self.REpod[j], - self.CEpod[j], - _progression_order_display[self.Ppod[j]]) + self.rspod[j], + self.cspod[j], + self.lyepod[j], + self.repod[j], + self.cdpod[j], + _PROGRESSION_ORDER_DISPLAY[self.ppod[j]]) return msg @@ -1203,16 +792,16 @@ class PLTsegment(Segment): Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. length : int Length of marker segment in bytes. This number does not include the two bytes constituting the marker. - Zplt : int + zplt : int Index of this segment relative to other PLT segments. - Iplt : list + iplt : list Packet lengths. References @@ -1221,15 +810,18 @@ class PLTsegment(Segment): 15444-1:2004 - Information technology -- JPEG 2000 image coding system: Core coding system """ - def __init__(self, **kwargs): - Segment.__init__(self, id='PLT') - self.__dict__.update(**kwargs) + def __init__(self, zplt, iplt, length, offset): + Segment.__init__(self, marker_id='PLT') + self.zplt = zplt + self.iplt = iplt + self.length = length + self.offset = offset def __str__(self): msg = Segment.__str__(self) msg += "\n Index: {0}" msg += "\n Iplt: {1}" - msg = msg.format(self.Zplt, self.Iplt) + msg = msg.format(self.zplt, self.iplt) return msg @@ -1239,17 +831,15 @@ class PPMsegment(Segment): Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. length : int Length of marker segment in bytes. This number does not include the two bytes constituting the marker. - Zppm : int + zppm : int Index of this segment relative to other PPM segments. - data: byte array - Raw data buffer, constitutes both Nppm and Ippm fields. References ---------- @@ -1257,15 +847,21 @@ class PPMsegment(Segment): 15444-1:2004 - Information technology -- JPEG 2000 image coding system: Core coding system """ - def __init__(self, **kwargs): - Segment.__init__(self, id='PPM') - self.__dict__.update(**kwargs) + def __init__(self, zppm, data, length, offset): + Segment.__init__(self, marker_id='PPM') + self.zppm = zppm + + # both Nppm and Ippms information stored in _data + self._data = data + + self.length = length + self.offset = offset def __str__(self): msg = Segment.__str__(self) msg += '\n Index: {0}' msg += '\n Data: {1} uninterpreted bytes' - msg = msg.format(self.Zppm, len(self.data)) + msg = msg.format(self.zppm, len(self._data)) return msg @@ -1274,16 +870,16 @@ class PPTsegment(Segment): Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. length : int Length of marker segment in bytes. This number does not include the two bytes constituting the marker. - Zppt : int + zppt : int Index of this segment relative to other PPT segments - Ippt : list + ippt : list Uninterpreted packet headers. References @@ -1292,15 +888,18 @@ class PPTsegment(Segment): 15444-1:2004 - Information technology -- JPEG 2000 image coding system: Core coding system """ - def __init__(self, **kwargs): - Segment.__init__(self, id='PPT') - self.__dict__.update(**kwargs) + def __init__(self, zppt, ippt, length, offset): + Segment.__init__(self, marker_id='PPT') + self.zppt = zppt + self.ippt = ippt + self.length = length + self.offset = offset def __str__(self): msg = Segment.__str__(self) msg += '\n Index: {0}' msg += '\n Packet headers: {1} uninterpreted bytes' - msg = msg.format(self.Zppt, len(self.Ippt)) + msg = msg.format(self.zppt, len(self.ippt)) return msg @@ -1309,18 +908,18 @@ class QCCsegment(Segment): Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. length : int Length of marker segment in bytes. This number does not include the two bytes constituting the marker. - Cqcc : int + cqcc : int Index of associated component. - Sqcc : int + sqcc : int Quantization style for this component. - SPqcc : iterable bytes + spqcc : iterable bytes Quantization value for each sub-band. References @@ -1329,16 +928,24 @@ class QCCsegment(Segment): 15444-1:2004 - Information technology -- JPEG 2000 image coding system: Core coding system """ - def __init__(self, **kwargs): - Segment.__init__(self, id='QCC') - self.__dict__.update(**kwargs) + def __init__(self, cqcc, sqcc, spqcc, length, offset): + Segment.__init__(self, marker_id='QCC') + self.cqcc = cqcc + self.sqcc = sqcc + self.spqcc = spqcc + self.length = length + self.offset = offset + + self._mantissa, self._exponent = parse_quantization(self.spqcc, + self.sqcc) + self._guard_bits = (self.sqcc & 0xe0) >> 5 def __str__(self): msg = Segment.__str__(self) - msg += '\n Associated Component: {0}'.format(self.Cqcc) - msg += self._print_quantization_style(self.Sqcc) - msg += '{0} guard bits'.format(self._guardBits) + msg += '\n Associated Component: {0}'.format(self.cqcc) + msg += _print_quantization_style(self.sqcc) + msg += '{0} guard bits'.format(self._guard_bits) step_size = zip(self._mantissa, self._exponent) msg += '\n Step size: ' + str(list(step_size)) @@ -1350,16 +957,16 @@ class QCDsegment(Segment): Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. length : int Length of marker segment in bytes. This number does not include the two bytes constituting the marker. - Sqcd : int + sqcd : int Quantization style for all components. - SPqcd : iterable bytes + spqcd : iterable bytes Quantization step size values (uninterpreted). References @@ -1368,16 +975,25 @@ class QCDsegment(Segment): 15444-1:2004 - Information technology -- JPEG 2000 image coding system: Core coding system """ - def __init__(self, **kwargs): - Segment.__init__(self, id='QCD') - self.__dict__.update(**kwargs) + def __init__(self, sqcd, spqcd, length, offset): + Segment.__init__(self, marker_id='QCD') + + self.sqcd = sqcd + self.spqcd = spqcd + self.length = length + self.offset = offset + + mantissa, exponent = parse_quantization(self.spqcd, self.sqcd) + self._mantissa = mantissa + self._exponent = exponent + self._guard_bits = (self.sqcd & 0xe0) >> 5 def __str__(self): msg = Segment.__str__(self) - msg += self._print_quantization_style(self.Sqcd) + msg += _print_quantization_style(self.sqcd) - msg += '{0} guard bits'.format(self._guardBits) + msg += '{0} guard bits'.format(self._guard_bits) step_size = zip(self._mantissa, self._exponent) msg += '\n Step size: ' + str(list(step_size)) @@ -1389,18 +1005,18 @@ class RGNsegment(Segment): Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. length : int Length of marker segment in bytes. This number does not include the two bytes constituting the marker. - Crgn : int + crgn : int Associated component. - Srgn : int + srgn : int ROI style. - SPrgn : int + sprgn : int Parameter for ROI style. References @@ -1409,9 +1025,13 @@ class RGNsegment(Segment): 15444-1:2004 - Information technology -- JPEG 2000 image coding system: Core coding system """ - def __init__(self, **kwargs): - Segment.__init__(self, id='RGN') - self.__dict__.update(**kwargs) + def __init__(self, length, offset, crgn, srgn, sprgn): + Segment.__init__(self, marker_id='RGN') + self.length = length + self.offset = offset + self.crgn = crgn + self.srgn = srgn + self.sprgn = sprgn def __str__(self): msg = Segment.__str__(self) @@ -1419,7 +1039,7 @@ class RGNsegment(Segment): msg += '\n Associated component: {0}' msg += '\n ROI style: {1}' msg += '\n Parameter: {2}' - msg = msg.format(self.Crgn, self.Srgn, self.SPrgn) + msg = msg.format(self.crgn, self.srgn, self.sprgn) return msg @@ -1429,26 +1049,26 @@ class SIZsegment(Segment): Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. length : int Length of marker segment in bytes. This number does not include the two bytes constituting the marker. - Rsiz : int + rsiz : int Capabilities (profile) of codestream. - Xsiz, Ysiz : int + xsiz, ysiz : int Width, height of reference grid. - XOsiz, YOsiz : int + xosiz, yosiz : int Horizontal, vertical offset of reference grid. - XTsiz, YTsiz : int + xtsiz, ytsiz : int Width and height of reference tile with respect to the reference grid. - XTOsiz, YTOsiz : int + xtosiz, ytosiz : int Horizontal and vertical offsets of tile from origin of reference grid. - Ssiz : iterable bytes + ssiz : iterable bytes Precision (depth) in bits and sign of each component. - XRsiz, YRsiz : int + xrsiz, yrsiz : int Horizontal and vertical sample separations with respect to reference grid. @@ -1458,9 +1078,48 @@ class SIZsegment(Segment): 15444-1:2004 - Information technology -- JPEG 2000 image coding system: Core coding system """ - def __init__(self, **kwargs): - Segment.__init__(self, id='SIZ') - self.__dict__.update(**kwargs) + def __init__(self, xy_buffer, component_buffer, length, offset): + Segment.__init__(self, marker_id='SIZ') + + data = struct.unpack('>HIIIIIIIIH', xy_buffer) + + self.rsiz = data[0] + self.xsiz = data[1] + self.ysiz = data[2] + self.xosiz = data[3] + self.yosiz = data[4] + self.xtsiz = data[5] + self.ytsiz = data[6] + self.xtosiz = data[7] + self.ytosiz = data[8] + # disregarding the last element in data + + num_tiles_x = (self.xsiz - self.xosiz) / (self.xtsiz - self.xtosiz) + num_tiles_y = (self.ysiz - self.yosiz) / (self.ytsiz - self.ytosiz) + numtiles = math.ceil(num_tiles_x) * math.ceil(num_tiles_y) + if numtiles > 65535: + msg = "Invalid number of tiles ({0}).".format(numtiles) + warnings.warn(msg) + + data = struct.unpack('>' + 'B' * len(component_buffer), + component_buffer) + + self.ssiz = data[0::3] + + for j, subsampling in enumerate(list(zip(data[1::3], data[2::3]))): + if 0 in subsampling: + msg = "Invalid subsampling value for component {0}: " + msg += "dx={1}, dy={2}." + msg = msg.format(j, subsampling[0], subsampling[1]) + warnings.warn(msg) + self.xrsiz = data[1::3] + self.yrsiz = data[2::3] + + self._bitdepth = tuple(((x & 0x7f) + 1) for x in self.ssiz) + self._signed = tuple(((x & 0xb0) > 0) for x in self.ssiz) + + self.length = length + self.offset = offset def __str__(self): msg = Segment.__str__(self) @@ -1475,14 +1134,14 @@ class SIZsegment(Segment): 'Signed: {10}', 'Vertical, Horizontal Subsampling: {11}'] msg += '\n '.join(lines) - msg = msg.format(_capabilities_display[self.Rsiz], - self.Ysiz, self.Xsiz, - self.YOsiz, self.XOsiz, - self.YTsiz, self.XTsiz, - self.YTOsiz, self.XTOsiz, + msg = msg.format(_CAPABILITIES_DISPLAY[self.rsiz], + self.ysiz, self.xsiz, + self.yosiz, self.xosiz, + self.ytsiz, self.xtsiz, + self.ytosiz, self.xtosiz, self._bitdepth, self._signed, - tuple(zip(self.YRsiz, self.XRsiz))) + tuple(zip(self.yrsiz, self.xrsiz))) return msg @@ -1492,7 +1151,7 @@ class SOCsegment(Segment): Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. @@ -1508,7 +1167,7 @@ class SOCsegment(Segment): Core coding system """ def __init__(self, **kwargs): - Segment.__init__(self, id='SOC') + Segment.__init__(self, marker_id='SOC') self.__dict__.update(**kwargs) @@ -1517,7 +1176,7 @@ class SODsegment(Segment): Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. @@ -1532,9 +1191,10 @@ class SODsegment(Segment): 15444-1:2004 - Information technology -- JPEG 2000 image coding system: Core coding system """ - def __init__(self, **kwargs): - Segment.__init__(self, id='SOD') - self.__dict__.update(**kwargs) + def __init__(self, length, offset): + Segment.__init__(self, marker_id='SOD') + self.length = length + self.offset = offset class EPHsegment(Segment): @@ -1542,7 +1202,7 @@ class EPHsegment(Segment): Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. @@ -1557,23 +1217,26 @@ class EPHsegment(Segment): 15444-1:2004 - Information technology -- JPEG 2000 image coding system: Core coding system """ - def __init__(self, **kwargs): - Segment.__init__(self, id='EPH') - self.__dict__.update(**kwargs) + def __init__(self, length, offset): + Segment.__init__(self, marker_id='EPH') + self.length = length + self.offset = offset class SOPsegment(Segment): - """Container for Start of Pata (SOP) segment information. + """Container for Start of Packet (SOP) segment information. Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. length : int Length of marker segment in bytes. This number does not include the two bytes constituting the marker. + nsop : int + Packet sequence number. References ---------- @@ -1581,13 +1244,15 @@ class SOPsegment(Segment): 15444-1:2004 - Information technology -- JPEG 2000 image coding system: Core coding system """ - def __init__(self, **kwargs): - Segment.__init__(self, id='SOP') - self.__dict__.update(**kwargs) + def __init__(self, nsop, length, offset): + Segment.__init__(self, marker_id='SOP') + self.nsop = nsop + self.length = length + self.offset = offset def __str__(self): msg = Segment.__str__(self) - msg += '\n Nsop: {0}'.format(self.Nsop) + msg += '\n Nsop: {0}'.format(self.nsop) return msg @@ -1596,21 +1261,21 @@ class SOTsegment(Segment): Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. length : int Length of marker segment in bytes. This number does not include the two bytes constituting the marker. - Isot : int + isot : int Index of this particular tile. - Psot : int + psot : int Length, in bytes, from first byte of this SOT marker segment to the end of the data of that tile part. - TPsot : int + tpsot : int Tile part instance. - TNsot : int + tnsot : int Number of tile-parts of a tile in codestream. References @@ -1619,9 +1284,14 @@ class SOTsegment(Segment): 15444-1:2004 - Information technology -- JPEG 2000 image coding system: Core coding system """ - def __init__(self, **kwargs): - Segment.__init__(self, id='SOT') - self.__dict__.update(**kwargs) + def __init__(self, isot, psot, tpsot, tnsot, length, offset): + Segment.__init__(self, marker_id='SOT') + self.isot = isot + self.psot = psot + self.tpsot = tpsot + self.tnsot = tnsot + self.length = length + self.offset = offset def __str__(self): msg = Segment.__str__(self) @@ -1631,10 +1301,10 @@ class SOTsegment(Segment): 'Tile part instance: {2}', 'Number of tile parts: {3}'] msg += '\n '.join(lines) - msg = msg.format(self.Isot, - self.Psot, - self.TPsot, - self.TNsot) + msg = msg.format(self.isot, + self.psot, + self.tpsot, + self.tnsot) return msg @@ -1643,18 +1313,18 @@ class TLMsegment(Segment): Attributes ---------- - id : str + marker_id : str Identifier for the segment. offset : int Offset of marker segment in bytes from beginning of file. length : int Length of marker segment in bytes. This number does not include the two bytes constituting the marker. - Ztlm : int + ztlm : int index relative to other TML marksers - Ttlm : int + ttlm : int number of the ith tile-part - Ptlm : int + ptlm : int length in bytes from beginning of the SOT marker of the ith tile-part to the end of the data for that tile part @@ -1664,9 +1334,13 @@ class TLMsegment(Segment): 15444-1:2004 - Information technology -- JPEG 2000 image coding system: Core coding system """ - def __init__(self, **kwargs): - Segment.__init__(self, id='TLM') - self.__dict__.update(**kwargs) + def __init__(self, length, offset, ztlm, ttlm, ptlm): + Segment.__init__(self, marker_id='TLM') + self.length = length + self.offset = offset + self.ztlm = ztlm + self.ttlm = ttlm + self.ptlm = ptlm def __str__(self): msg = Segment.__str__(self) @@ -1675,20 +1349,20 @@ class TLMsegment(Segment): 'Tile number: {1}', 'Length: {2}'] msg += '\n '.join(lines) - msg = msg.format(self.Ztlm, - self.Ttlm, - self.Ptlm) + msg = msg.format(self.ztlm, + self.ttlm, + self.ptlm) return msg -def _parse_precinct_size(buffer): +def _parse_precinct_size(spcod): """Compute precinct size from SPcod or SPcoc.""" - SPcocd = np.frombuffer(buffer, dtype=np.uint8) + spcod = np.frombuffer(spcod, dtype=np.uint8) precinct_size = [] - for x in SPcocd: - ep2 = (x & 0xF0) >> 4 - ep1 = x & 0x0F + for item in spcod: + ep2 = (item & 0xF0) >> 4 + ep1 = item & 0x0F precinct_size.append((2 ** ep1, 2 ** ep2)) return precinct_size @@ -1710,3 +1384,396 @@ def _context_string(context): ((context & 0x10) > 0), ((context & 0x20) > 0)) return msg + + +def parse_quantization(read_buffer, sqcd): + """Tease out the quantization values. + + Parameters + ---------- + read_buffer: sequence of bytes from the QCC and QCD segments. + + Returns + ------ + Tuple of mantissa, exponents from quantization buffer. + """ + numbytes = len(read_buffer) + + exponent = [] + mantissa = [] + + if sqcd & 0x1f == 0: # no quantization + data = struct.unpack('>' + 'B' * numbytes, read_buffer) + for j in range(len(data)): + exponent.append(data[j] >> 3) + mantissa.append(0) + else: + fmt = '>' + 'H' * int(numbytes / 2) + data = struct.unpack(fmt, read_buffer) + for j in range(len(data)): + exponent.append(data[j] >> 11) + mantissa.append(data[j] & 0x07ff) + + return mantissa, exponent + + +def _print_quantization_style(sqcc): + """Only to be used with QCC and QCD segments.""" + + msg = '\n Quantization style: ' + if sqcc & 0x1f == 0: + msg += 'no quantization, ' + elif sqcc & 0x1f == 1: + msg += 'scalar implicit, ' + elif sqcc & 0x1f == 2: + msg += 'scalar explicit, ' + return msg + + +def _parse_tlm_segment(fptr): + """Parse the TLM segment. + + Parameters + ---------- + fptr : file + Open file object. + + Returns + ------- + TLM segment instance. + """ + offset = fptr.tell() - 2 + + read_buffer = fptr.read(2) + length, = struct.unpack('>H', read_buffer) + + read_buffer = fptr.read(2) + ztlm, stlm = struct.unpack('>BB', read_buffer) + ttlm_st = (stlm >> 4) & 0x3 + ptlm_sp = (stlm >> 6) & 0x1 + + nbytes = length - 4 + if ttlm_st == 0: + ntiles = nbytes / ((ptlm_sp + 1) * 2) + else: + ntiles = nbytes / (ttlm_st + (ptlm_sp + 1) * 2) + + read_buffer = fptr.read(nbytes) + if ttlm_st == 0: + ttlm = None + fmt = '' + elif ttlm_st == 1: + fmt = 'B' + elif ttlm_st == 2: + fmt = 'H' + + if ptlm_sp == 0: + fmt += 'H' + else: + fmt += 'I' + + data = struct.unpack('>' + fmt * int(ntiles), read_buffer) + if ttlm_st == 0: + ttlm = None + ptlm = data + else: + ttlm = data[0::2] + ptlm = data[1::2] + + return TLMsegment(length, offset, ztlm, ttlm, ptlm) + + +def _parse_sot_segment(fptr): + """Parse the SOT segment. + + Parameters + ---------- + fptr : file + Open file object. + + Returns + ------- + SOT segment instance. + """ + offset = fptr.tell() - 2 + + read_buffer = fptr.read(10) + data = struct.unpack('>HHIBB', read_buffer) + + length = data[0] + isot = data[1] + psot = data[2] + tpsot = data[3] + tnsot = data[4] + + return SOTsegment(isot, psot, tpsot, tnsot, length, offset) + + +def _parse_sod_segment(fptr): + """Parse the SOD segment. + + Parameters + ---------- + fptr : file + Open file object. + + Returns + ------- + SOD segment instance. + """ + offset = fptr.tell() - 2 + length = 0 + + return SODsegment(length, offset) + + +def _parse_qcd_segment(fptr): + """Parse the QCD segment. + + Parameters + ---------- + fptr : file + Open file object. + + Returns + ------- + QCD Segment instance. + """ + offset = fptr.tell() - 2 + + read_buffer = fptr.read(3) + length, sqcd = struct.unpack('>HB', read_buffer) + spqcd = fptr.read(length - 3) + + return QCDsegment(sqcd, spqcd, length, offset) + + +def _parse_ppt_segment(fptr): + """Parse the PPT segment. + + The packet headers are not parsed, i.e. they remain "uninterpreted" + raw data beffers. + + Parameters + ---------- + fptr : file + Open file object. + + Returns + ------- + PPT segment instance. + """ + offset = fptr.tell() - 2 + + read_buffer = fptr.read(3) + length, zppt = struct.unpack('>HB', read_buffer) + length = length + zppt = zppt + + numbytes = length - 3 + ippt = fptr.read(numbytes) + + return PPTsegment(zppt, ippt, length, offset) + + +def _parse_plt_segment(fptr): + """Parse the PLT segment. + + The packet headers are not parsed, i.e. they remain "uninterpreted" + raw data beffers. + + Parameters + ---------- + fptr : file + Open file object. + + Returns + ------- + PLT segment instance. + """ + offset = fptr.tell() - 2 + + read_buffer = fptr.read(3) + length, zplt = struct.unpack('>HB', read_buffer) + + numbytes = length - 3 + read_buffer = fptr.read(numbytes) + iplt = np.frombuffer(read_buffer, dtype=np.uint8) + + packet_len = [] + plen = 0 + for byte in iplt: + plen |= (byte & 0x7f) + if byte & 0x80: + # Continue by or-ing in the next byte. + plen <<= 7 + else: + packet_len.append(plen) + plen = 0 + + iplt = packet_len + + return PLTsegment(zplt, iplt, length, offset) + + +def _parse_ppm_segment(fptr): + """Parse the PPM segment. + + Parameters + ---------- + fptr : file + Open file object. + + Returns + ------- + PPM segment instance. + """ + offset = fptr.tell() - 2 + + read_buffer = fptr.read(3) + length, zppm = struct.unpack('>HB', read_buffer) + + numbytes = length - 3 + read_buffer = fptr.read(numbytes) + + return PPMsegment(zppm, read_buffer, length, offset) + + +def _parse_crg_segment(fptr, csiz): + """Parse the CRG marker segment. + + Parameters + ---------- + fptr : file + Open file object. + + Returns + ------- + CRG segment instance. + """ + offset = fptr.tell() - 2 + + read_buffer = fptr.read(2) + length, = struct.unpack('>H', read_buffer) + + read_buffer = fptr.read(4 * csiz) + data = struct.unpack('>' + 'HH' * csiz, read_buffer) + xcrg = data[0::2] + ycrg = data[1::2] + + return CRGsegment(xcrg, ycrg, length, offset) + + +def _parse_eoc_segment(fptr): + """Parse the EOC marker segment. + + Parameters + ---------- + fptr : file + Open file object. + + Returns + ------- + EOC Segment instance. + """ + offset = fptr.tell() - 2 + length = 0 + + return EOCsegment(length, offset) + + +def _parse_cme_segment(fptr): + """Parse the CME marker segment. + + Parameters + ---------- + fptr : file + Open file object. + + Returns + ------- + CME segment instance. + """ + offset = fptr.tell() - 2 + + read_buffer = fptr.read(4) + data = struct.unpack('>HH', read_buffer) + length = data[0] + rcme = data[1] + ccme = fptr.read(length - 4) + + return CMEsegment(rcme, ccme, length, offset) + + +def _parse_siz_segment(fptr): + """Parse the SIZ segment. + + Parameters + ---------- + fptr : file + Open file object. + + Returns + ------- + SIZsegment instance. + """ + offset = fptr.tell() - 2 + + read_buffer = fptr.read(2) + length, = struct.unpack('>H', read_buffer) + + xy_buffer = fptr.read(36) + + num_components, = struct.unpack('>H', xy_buffer[-2:]) + + component_buffer = fptr.read(num_components * 3) + + return SIZsegment(xy_buffer, component_buffer, length, offset) + + +def _parse_cod_segment(fptr): + """Parse the COD segment. + + Parameters + ---------- + fptr : file + Open file object. + + Returns + ------- + COD segment instance. + """ + offset = fptr.tell() - 2 + offset = fptr.tell() - 2 + + read_buffer = fptr.read(3) + length, scod = struct.unpack('>HB', read_buffer) + + numbytes = offset + 2 + length - fptr.tell() + spcod = fptr.read(numbytes) + spcod = np.frombuffer(spcod, dtype=np.uint8) + + return CODsegment(scod, spcod, length, offset) + + +def _parse_generic_segment(fptr, marker_id): + """Parse a generic marker segment. + + Parameters + ---------- + fptr : file + Open file object. + + Returns + ------- + Segment instance. + """ + offset = fptr.tell() - 2 + + read_buffer = fptr.read(2) + length, = struct.unpack('>H', read_buffer) + data = fptr.read(length-2) + + segment = Segment(marker_id='0x{0:x}'.format(marker_id), offset=offset, + length=length, data=data) + return segment diff --git a/glymur/core.py b/glymur/core.py index 6483558..3959dd0 100644 --- a/glymur/core.py +++ b/glymur/core.py @@ -1,3 +1,5 @@ +"""Core definitions to be shared amongst the modules. +""" # Progression order LRCP = 0 RLCP = 1 @@ -5,44 +7,21 @@ RPCL = 2 PCRL = 3 CPRL = 4 -_progression_order_display = { - LRCP: 'LRCP', - RLCP: 'RLCP', - RPCL: 'RPCL', - PCRL: 'PCRL', - CPRL: 'CPRL'} - -progression_order = { +PROGRESSION_ORDER = { 'LRCP': LRCP, 'RLCP': RLCP, 'RPCL': RPCL, 'PCRL': PCRL, 'CPRL': CPRL} -WAVELET_TRANSFORM_9x7_IRREVERSIBLE = 0 -WAVELET_TRANSFORM_5x3_REVERSIBLE = 1 - -_wavelet_transform_display = { - WAVELET_TRANSFORM_9x7_IRREVERSIBLE: '9-7 irreversible', - WAVELET_TRANSFORM_5x3_REVERSIBLE: '5-3 reversible'} +WAVELET_XFORM_9X7_IRREVERSIBLE = 0 +WAVELET_XFORM_5X3_REVERSIBLE = 1 ENUMERATED_COLORSPACE = 1 RESTRICTED_ICC_PROFILE = 2 ANY_ICC_PROFILE = 3 VENDOR_COLOR_METHOD = 4 -_method_display = { - ENUMERATED_COLORSPACE: 'enumerated colorspace', - RESTRICTED_ICC_PROFILE: 'restricted ICC profile', - ANY_ICC_PROFILE: 'any ICC profile', - VENDOR_COLOR_METHOD: 'vendor color method'} - -_ = {1: 'accurately represents correct colorspace definition', - 2: 'approximates correct colorspace definition, exceptional quality', - 3: 'approximates correct colorspace definition, reasonable quality', - 4: 'approximates correct colorspace definition, poor quality'} -_approximation_display = _ - # Registration values for comment markers. RCME_BINARY = 0 # binary value comments RCME_ISO_8859_1 = 1 # comments in latin-1 codec @@ -55,7 +34,7 @@ YCC = 18 E_SRGB = 20 ROMM_RGB = 21 -_colorspace_map_display = { +_COLORSPACE_MAP_DISPLAY = { CMYK: 'CMYK', SRGB: 'sRGB', GREYSCALE: 'greyscale', @@ -68,7 +47,7 @@ _COLOR = 0 _OPACITY = 1 _PRE_MULTIPLIED_OPACITY = 2 _UNSPECIFIED = 65535 -_color_type_map_display = { +_COLOR_TYPE_MAP_DISPLAY = { _COLOR: 'color', _OPACITY: 'opacity', _PRE_MULTIPLIED_OPACITY: 'pre-multiplied opacity', @@ -81,49 +60,15 @@ BLUE = 3 GREY = 1 # enumerated color channel associations -_rgb_colorspace = {"R": 1, "G": 2, "B": 3} -_greyscale_colorspace = {"Y": 1} -_ycbcr_colorspace = {"Y": 1, "Cb": 2, "Cr": 3} -_colorspace = {SRGB: _rgb_colorspace, - GREYSCALE: _greyscale_colorspace, - YCC: _ycbcr_colorspace, - E_SRGB: _rgb_colorspace, - ROMM_RGB: _rgb_colorspace} +_COLORSPACE = {SRGB: {"R": 1, "G": 2, "B": 3}, + GREYSCALE: {"Y": 1}, + YCC: {"Y": 1, "Cb": 2, "Cr": 3}, + E_SRGB: {"R": 1, "G": 2, "B": 3}, + ROMM_RGB: {"R": 1, "G": 2, "B": 3}} # How to display the codestream profile. -_capabilities_display = { +_CAPABILITIES_DISPLAY = { 0: '2', 1: '0', 2: '1', 3: '3'} - -# Reader requirements -RREQ_UNRESTRICTED_JPEG2000_PART_1 = 5 -RREQ_UNRESTRICTED_JPEG2000_PART_2 = 6 -RREQ_CMYK_ENUMERATED_COLORSPACE = 55 -RREQ_CMYK_ENUMERATED_COLORSPACE = 55 -RREQ_E_SRGB_ENUMERATED_COLORSPACE = 60 -RREQ_ROMM_RGB_ENUMERATED_COLORSPACE = 61 -_reader_requirements_display = { - 0: 'File not completely understood', - 1: 'Deprecated', - 2: 'Contains multiple composition layers', - 3: 'Deprecated', - 4: 'JPEG 2000 Part 1 Profile 1 codestream', - RREQ_UNRESTRICTED_JPEG2000_PART_1: - 'Unrestricted JPEG 2000 Part 1 codestream, ITU-T Rec. T.800 ' - + '| ISO/IEC 15444-1', - RREQ_UNRESTRICTED_JPEG2000_PART_2: - 'Unrestricted JPEG 2000 Part 2 codestream', - 7: 'JPEG codestream as defined in ISO/IEC 10918-1', - 8: 'Deprecated', - 9: 'Non-premultiplied opacity channel', - 10: 'Premultiplied opacity channel', - 12: 'Deprecated', - 18: 'Deprecated', - 43: '(Deprecated) compositing layer uses restricted ICC profile', - 44: 'Compositing layer uses Any ICC profile', - 45: 'Deprecated', - RREQ_CMYK_ENUMERATED_COLORSPACE: 'CMYK enumerated colorspace', - RREQ_E_SRGB_ENUMERATED_COLORSPACE: 'e-sRGB enumerated colorspace', - RREQ_ROMM_RGB_ENUMERATED_COLORSPACE: 'ROMM_RGB enumerated colorspace'} diff --git a/glymur/data/__init__.py b/glymur/data/__init__.py index bebfb08..c95b144 100644 --- a/glymur/data/__init__.py +++ b/glymur/data/__init__.py @@ -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 diff --git a/glymur/data/nemo.jp2 b/glymur/data/nemo.jp2 index 2bb8638..55d199c 100644 Binary files a/glymur/data/nemo.jp2 and b/glymur/data/nemo.jp2 differ diff --git a/glymur/jp2box.py b/glymur/jp2box.py index e0107f3..7e5014c 100644 --- a/glymur/jp2box.py +++ b/glymur/jp2box.py @@ -11,11 +11,12 @@ References Extensions """ +# pylint: disable=C0302,R0903,R0913 + import collections import copy import datetime import math -import os import pprint import struct import sys @@ -26,12 +27,24 @@ import xml.etree.cElementTree as ET import numpy as np from .codestream import Codestream -from .core import _approximation_display -from .core import _colorspace_map_display -from .core import _color_type_map_display -from .core import _method_display -from .core import _reader_requirements_display -from .core import * +from .core import _COLORSPACE_MAP_DISPLAY +from .core import _COLOR_TYPE_MAP_DISPLAY +from .core import ENUMERATED_COLORSPACE, RESTRICTED_ICC_PROFILE +from .core import ANY_ICC_PROFILE, VENDOR_COLOR_METHOD + +_METHOD_DISPLAY = { + ENUMERATED_COLORSPACE: 'enumerated colorspace', + RESTRICTED_ICC_PROFILE: 'restricted ICC profile', + ANY_ICC_PROFILE: 'any ICC profile', + VENDOR_COLOR_METHOD: 'vendor color method'} + +_APPROX_DISPLAY = {1: 'accurately represents correct colorspace definition', + 2: 'approximates correct colorspace definition, ' + + 'exceptional quality', + 3: 'approximates correct colorspace definition, ' + + 'reasonable quality', + 4: 'approximates correct colorspace definition, ' + + 'poor quality'} class Jp2kBox(object): @@ -39,7 +52,7 @@ class Jp2kBox(object): Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : int length of the box in bytes. @@ -49,29 +62,32 @@ class Jp2kBox(object): more verbose description of the box. """ - def __init__(self, id='', offset=0, length=0, longname=''): - self.id = id + def __init__(self, box_id='', offset=0, length=0, longname=''): + self.box_id = box_id self.length = length self.offset = offset self.longname = longname + # should never be used except for last box in file. + self._file_size = -1 + def __str__(self): - msg = "{0} Box ({1})".format(self.longname, self.id) + msg = "{0} Box ({1})".format(self.longname, self.box_id) msg += " @ ({0}, {1})".format(self.offset, self.length) return msg - def _write(self, f): + def write(self, _): """Must be implemented in a subclass. """ msg = "Not supported for {0} box.".format(self.longname) raise NotImplementedError(msg) - def _parse_superbox(self, f): + def parse_superbox(self, fptr): """Parse a superbox (box consisting of nothing but other boxes. Parameters ---------- - f : file + fptr : file Open file object. Returns @@ -81,7 +97,7 @@ class Jp2kBox(object): superbox = [] - start = f.tell() + start = fptr.tell() while True: @@ -89,31 +105,31 @@ class Jp2kBox(object): if start >= self.offset + self.length: break - buffer = f.read(8) - (L, T) = struct.unpack('>I4s', buffer) + read_buffer = fptr.read(8) + (box_length, box_id) = struct.unpack('>I4s', read_buffer) if sys.hexversion >= 0x03000000: - T = T.decode('utf-8') + box_id = box_id.decode('utf-8') - if L == 0: + if box_length == 0: # The length of the box is presumed to last until the end of # the file. Compute the effective length of the box. - num_bytes = self._file_size - f.tell() + 8 + num_bytes = self._file_size - fptr.tell() + 8 - elif L == 1: + elif box_length == 1: # The length of the box is in the XL field, a 64-bit value. - buffer = f.read(8) - num_bytes, = struct.unpack('>Q', buffer) + read_buffer = fptr.read(8) + num_bytes, = struct.unpack('>Q', read_buffer) else: - num_bytes = L + num_bytes = box_length # Call the proper parser for the given box with ID "T". try: - box = _box_with_id[T]._parse(f, T, start, num_bytes) + box = _BOX_WITH_ID[box_id].parse(fptr, start, num_bytes) except KeyError: - msg = 'Unrecognized box ({0}) encountered.'.format(T) + msg = 'Unrecognized box ({0}) encountered.'.format(box_id) warnings.warn(msg) - box = Jp2kBox(T, offset=start, length=num_bytes, + box = Jp2kBox(box_id, offset=start, length=num_bytes, longname='Unknown box') superbox.append(box) @@ -123,16 +139,16 @@ class Jp2kBox(object): # Length of the current box goes past the end of the # enclosing superbox. msg = '{0} box has incorrect box length ({1})' - msg = msg.format(T, num_bytes) + msg = msg.format(box_id, num_bytes) warnings.warn(msg) - elif f.tell() > start + num_bytes: + elif fptr.tell() > start + num_bytes: # The box must be invalid somehow, as the file pointer is # positioned past the end of the box. msg = '{0} box may be invalid, the file pointer is positioned ' msg += '{1} bytes past the end of the box.' - msg = msg.format(T, f.tell() - (start + num_bytes)) + msg = msg.format(box_id, fptr.tell() - (start + num_bytes)) warnings.warn(msg) - f.seek(start + num_bytes) + fptr.seek(start + num_bytes) start += num_bytes @@ -144,7 +160,7 @@ class ColourSpecificationBox(Jp2kBox): Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : int Length of the box in bytes. @@ -166,9 +182,11 @@ class ColourSpecificationBox(Jp2kBox): ICC profile header according to ICC profile specification. If colorspace is not None, then icc_profile must be empty. """ + def __init__(self, method=ENUMERATED_COLORSPACE, precedence=0, - approximation=0, colorspace=None, icc_profile=None, **kwargs): - Jp2kBox.__init__(self, id='colr', longname='Colour Specification') + approximation=0, colorspace=None, icc_profile=None, + length=0, offset=-1): + Jp2kBox.__init__(self, box_id='colr', longname='Colour Specification') if colorspace is not None and icc_profile is not None: raise IOError("colorspace and icc_profile cannot both be set.") @@ -176,25 +194,27 @@ class ColourSpecificationBox(Jp2kBox): raise IOError("Invalid method.") if approximation not in (0, 1, 2, 3, 4): raise IOError("Invalid approximation.") - self.__dict__.update(**kwargs) self.method = method self.precedence = precedence self.approximation = approximation self.colorspace = colorspace self.icc_profile = icc_profile + self.length = length + self.offset = offset def __str__(self): msg = Jp2kBox.__str__(self) - msg += '\n Method: {0}'.format(_method_display[self.method]) + msg += '\n Method: {0}'.format(_METHOD_DISPLAY[self.method]) msg += '\n Precedence: {0}'.format(self.precedence) if self.approximation is not 0: - x = _approximation_display[self.approximation] - msg += '\n Approximation: {0}'.format(x) + dispvalue = _APPROX_DISPLAY[self.approximation] + msg += '\n Approximation: {0}'.format(dispvalue) + if self.colorspace is not None: - x = _colorspace_map_display[self.colorspace] - msg += '\n Colorspace: {0}'.format(x) + dispvalue = _COLORSPACE_MAP_DISPLAY[self.colorspace] + msg += '\n Colorspace: {0}'.format(dispvalue) else: # 2.7 has trouble pretty-printing ordered dicts so we just have # to print as a regular dict in this case. @@ -202,13 +222,13 @@ class ColourSpecificationBox(Jp2kBox): icc_profile = dict(self.icc_profile) else: icc_profile = self.icc_profile - x = pprint.pformat(icc_profile) - lines = [' ' * 8 + y for y in x.split('\n')] + dispvalue = pprint.pformat(icc_profile) + lines = [' ' * 8 + y for y in dispvalue.split('\n')] msg += '\n ICC Profile:\n{0}'.format('\n'.join(lines)) return msg - def _write(self, f): + def write(self, fptr): """Write an Colour Specification box to file. """ if self.colorspace is None: @@ -216,26 +236,24 @@ class ColourSpecificationBox(Jp2kBox): msg += "colorspaces is not supported at this time." raise NotImplementedError(msg) length = 15 if self.icc_profile is None else 11 + len(self.icc_profile) - f.write(struct.pack('>I', length)) - f.write('colr'.encode()) + fptr.write(struct.pack('>I', length)) + fptr.write('colr'.encode()) - buffer = struct.pack('>BBBI', - self.method, - self.precedence, - self.approximation, - self.colorspace) - f.write(buffer) + read_buffer = struct.pack('>BBBI', + self.method, + self.precedence, + self.approximation, + self.colorspace) + fptr.write(read_buffer) @staticmethod - def _parse(f, id, offset, length): + def parse(fptr, offset, length): """Parse JPEG 2000 color specification box. Parameters ---------- - f : file + fptr : file Open file object. - id : byte - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int @@ -243,46 +261,45 @@ class ColourSpecificationBox(Jp2kBox): Returns ------- - kwargs : dictionary - dictionary of parameter values + ColourSpecificationBox instance """ - kwargs = {} - kwargs['id'] = id - kwargs['length'] = length - kwargs['offset'] = offset - # Read the brand, minor version. - buffer = f.read(3) - (method, precedence, approximation) = struct.unpack('>BBB', buffer) - kwargs['method'] = method - kwargs['precedence'] = precedence - kwargs['approximation'] = approximation + read_buffer = fptr.read(3) + (method, precedence, approximation) = struct.unpack('>BBB', + read_buffer) if method == 1: # enumerated colour space - buffer = f.read(4) - kwargs['colorspace'], = struct.unpack('>I', buffer) - kwargs['icc_profile'] = None + read_buffer = fptr.read(4) + colorspace, = struct.unpack('>I', read_buffer) + icc_profile = None else: # ICC profile - kwargs['colorspace'] = None - n = offset + length - f.tell() - if n < 128: + colorspace = None + numbytes = offset + length - fptr.tell() + if numbytes < 128: msg = "ICC profile header is corrupt, length is " msg += "only {0} instead of 128." - warnings.warn(msg.format(n), UserWarning) - kwargs['icc_profile'] = None + warnings.warn(msg.format(numbytes), UserWarning) + icc_profile = None else: - icc_profile = _ICCProfile(f.read(n)) - kwargs['icc_profile'] = icc_profile.header + profile = _ICCProfile(fptr.read(numbytes)) + icc_profile = profile.header - box = ColourSpecificationBox(**kwargs) + box = ColourSpecificationBox(method=method, + precedence=precedence, + approximation=approximation, + colorspace=colorspace, + icc_profile=icc_profile, + length=length, + offset=offset) return box class _ICCProfile(object): """ + Container for ICC profile information. """ profile_class = {b'scnr': 'input device profile', b'mntr': 'display device profile', @@ -323,8 +340,8 @@ class _ICCProfile(object): 2: 'saturation', 3: 'ICC-absolute colorimetric'} - def __init__(self, buffer): - self._raw_buffer = buffer + def __init__(self, read_buffer): + self._raw_buffer = read_buffer header = collections.OrderedDict() data = struct.unpack('>IIBB', self._raw_buffer[0:10]) @@ -342,50 +359,50 @@ class _ICCProfile(object): data = struct.unpack('>HHHHHH', self._raw_buffer[24:36]) header['Datetime'] = datetime.datetime(*data) - header['File Signature'] = buffer[36:40].decode('utf-8') - if buffer[40:44] == b'\x00\x00\x00\x00': + header['File Signature'] = read_buffer[36:40].decode('utf-8') + if read_buffer[40:44] == b'\x00\x00\x00\x00': header['Platform'] = 'unrecognized' else: - header['Platform'] = buffer[40:44].decode('utf-8') + header['Platform'] = read_buffer[40:44].decode('utf-8') - x, = struct.unpack('>I', buffer[44:48]) - y = 'embedded, ' if x & 0x01 else 'not embedded, ' - y += 'cannot ' if x & 0x02 else 'can ' - y += 'be used independently' - header['Flags'] = y + fval, = struct.unpack('>I', read_buffer[44:48]) + flags = 'embedded, ' if fval & 0x01 else 'not embedded, ' + flags += 'cannot ' if fval & 0x02 else 'can ' + flags += 'be used independently' + header['Flags'] = flags - header['Device Manufacturer'] = buffer[48:52].decode('utf-8') - if buffer[52:56] == b'\x00\x00\x00\x00': + header['Device Manufacturer'] = read_buffer[48:52].decode('utf-8') + if read_buffer[52:56] == b'\x00\x00\x00\x00': device_model = '' else: - device_model = buffer[52:56].decode('utf-8') + device_model = read_buffer[52:56].decode('utf-8') header['Device Model'] = device_model - x, = struct.unpack('>Q', buffer[56:64]) - y = 'transparency, ' if x & 0x01 else 'reflective, ' - y += 'matte, ' if x & 0x02 else 'glossy, ' - y += 'negative ' if x & 0x04 else 'positive ' - y += 'media polarity, ' - y += 'black and white media' if x & 0x08 else 'color media' - header['Device Attributes'] = y + val, = struct.unpack('>Q', read_buffer[56:64]) + attr = 'transparency, ' if val & 0x01 else 'reflective, ' + attr += 'matte, ' if val & 0x02 else 'glossy, ' + attr += 'negative ' if val & 0x04 else 'positive ' + attr += 'media polarity, ' + attr += 'black and white media' if val & 0x08 else 'color media' + header['Device Attributes'] = attr - x, = struct.unpack('>I', buffer[64:68]) + rval, = struct.unpack('>I', read_buffer[64:68]) try: - header['Rendering Intent'] = self.rendering_intent_dict[x] + header['Rendering Intent'] = self.rendering_intent_dict[rval] except KeyError: header['Rendering Intent'] = 'unknown' - data = struct.unpack('>iii', buffer[68:80]) + data = struct.unpack('>iii', read_buffer[68:80]) header['Illuminant'] = np.array(data, dtype=np.float64) / 65536 - if buffer[80:84] == b'\x00\x00\x00\x00': + if read_buffer[80:84] == b'\x00\x00\x00\x00': creator = 'unrecognized' else: - creator = buffer[80:84].decode('utf-8') + creator = read_buffer[80:84].decode('utf-8') header['Creator'] = creator if header['Version'][0] == '4': - header['Profile Id'] = buffer[84:100] + header['Profile Id'] = read_buffer[84:100] # Final 27 bytes are reserved. @@ -397,7 +414,7 @@ class ChannelDefinitionBox(Jp2kBox): Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : numeric scalar length of the box in bytes. @@ -413,7 +430,7 @@ class ChannelDefinitionBox(Jp2kBox): index of the associated color """ def __init__(self, index, channel_type, association, **kwargs): - Jp2kBox.__init__(self, id='cdef', longname='Channel Definition') + Jp2kBox.__init__(self, box_id='cdef', longname='Channel Definition') if len(index) != len(channel_type) or len(index) != len(association): msg = "Length of channel definition box inputs must be the same." raise IOError(msg) @@ -435,7 +452,7 @@ class ChannelDefinitionBox(Jp2kBox): def __str__(self): msg = Jp2kBox.__str__(self) for j in range(len(self.association)): - color_type_string = _color_type_map_display[self.channel_type[j]] + color_type_string = _COLOR_TYPE_MAP_DISPLAY[self.channel_type[j]] if self.association[j] == 0: assn = 'whole image' else: @@ -444,29 +461,27 @@ class ChannelDefinitionBox(Jp2kBox): msg = msg.format(self.index[j], color_type_string, assn) return msg - def _write(self, f): + def write(self, fptr): """Write a channel definition box to file. """ - N = len(self.association) - f.write(struct.pack('>I', 8 + 2 + N * 6)) - f.write('cdef'.encode('utf-8')) - f.write(struct.pack('>H', N)) - for j in range(N): - f.write(struct.pack('>' + 'H' * 3, - self.index[j], - self.channel_type[j], - self.association[j])) + num_components = len(self.association) + fptr.write(struct.pack('>I', 8 + 2 + num_components * 6)) + fptr.write('cdef'.encode('utf-8')) + fptr.write(struct.pack('>H', num_components)) + for j in range(num_components): + fptr.write(struct.pack('>' + 'H' * 3, + self.index[j], + self.channel_type[j], + self.association[j])) @staticmethod - def _parse(f, id, offset, length): + def parse(fptr, offset, length): """Parse component definition box. Parameters ---------- - f : file + fptr : file Open file object. - id : byte - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int @@ -474,28 +489,20 @@ class ChannelDefinitionBox(Jp2kBox): Returns ------- - kwargs : dictionary of parameter values + ComponentDefinitionBox instance """ - kwargs = {} - kwargs['id'] = id - kwargs['length'] = length - kwargs['offset'] = offset - # Read the number of components. - buffer = f.read(2) - N, = struct.unpack('>H', buffer) + read_buffer = fptr.read(2) + num_components, = struct.unpack('>H', read_buffer) - index = [] - chan_type = [] - association = [] + read_buffer = fptr.read(num_components * 6) + data = struct.unpack('>' + 'HHH' * num_components, read_buffer) + index = data[0:num_components * 6:3] + channel_type = data[1:num_components * 6:3] + association = data[2:num_components * 6:3] - buffer = f.read(N * 6) - data = struct.unpack('>' + 'HHH' * N, buffer) - index = data[0:N * 6:3] - channel_type = data[1:N * 6:3] - association = data[2:N * 6:3] - - box = ChannelDefinitionBox(index, channel_type, association, **kwargs) + box = ChannelDefinitionBox(index, channel_type, association, + length=length, offset=offset) return box @@ -504,7 +511,7 @@ class ComponentMappingBox(Jp2kBox): Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : numeric scalar Length of the box in bytes. @@ -519,9 +526,14 @@ class ComponentMappingBox(Jp2kBox): palette_index : int Index component from palette """ - def __init__(self, **kwargs): - Jp2kBox.__init__(self, id='', longname='Component Mapping') - self.__dict__.update(**kwargs) + def __init__(self, component_index, mapping_type, palette_index, + length=0, offset=-1): + Jp2kBox.__init__(self, box_id='cmap', longname='Component Mapping') + self.component_index = component_index + self.mapping_type = mapping_type + self.palette_index = palette_index + self.length = length + self.offset = offset def __str__(self): msg = Jp2kBox.__str__(self) @@ -537,15 +549,13 @@ class ComponentMappingBox(Jp2kBox): return msg @staticmethod - def _parse(f, id, offset, length): + def parse(fptr, offset, length): """Parse component mapping box. Parameters ---------- - f : file + fptr : file Open file object. - id : byte - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int @@ -553,24 +563,20 @@ class ComponentMappingBox(Jp2kBox): Returns ------- - kwargs : dictionary of parameter values + ComponentMappingBox instance """ - kwargs = {} - kwargs['id'] = id - kwargs['length'] = length - kwargs['offset'] = offset + num_bytes = offset + length - fptr.tell() + num_components = int(num_bytes/4) - N = offset + length - f.tell() - num_components = int(N/4) + read_buffer = fptr.read(num_bytes) + data = struct.unpack('>' + 'HBB' * num_components, read_buffer) - buffer = f.read(N) - data = struct.unpack('>' + 'HBB' * num_components, buffer) + component_index = data[0:num_bytes:num_components] + mapping_type = data[1:num_bytes:num_components] + palette_index = data[2:num_bytes:num_components] - kwargs['component_index'] = data[0:N:num_components] - kwargs['mapping_type'] = data[1:N:num_components] - kwargs['palette_index'] = data[2:N:num_components] - - box = ComponentMappingBox(**kwargs) + box = ComponentMappingBox(component_index, mapping_type, palette_index, + length=length, offset=offset) return box @@ -579,7 +585,7 @@ class ContiguousCodestreamBox(Jp2kBox): Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : int length of the box in bytes. @@ -590,11 +596,11 @@ class ContiguousCodestreamBox(Jp2kBox): main_header : list List of segments in the codestream header. """ - - def __init__(self, main_header=[], **kwargs): - Jp2kBox.__init__(self, id='jp2c', longname='Contiguous Codestream') - self.__dict__.update(**kwargs) + def __init__(self, main_header=None, length=0, offset=-1): + Jp2kBox.__init__(self, box_id='jp2c', longname='Contiguous Codestream') self.main_header = main_header + self.length = length + self.offset = offset def __str__(self): msg = Jp2kBox.__str__(self) @@ -608,15 +614,13 @@ class ContiguousCodestreamBox(Jp2kBox): return msg @staticmethod - def _parse(f, id='jp2c', offset=0, length=0): + def parse(fptr, offset=0, length=0): """Parse a codestream box. Parameters ---------- - f : file + fptr : file Open file object. - id : byte - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int @@ -624,16 +628,11 @@ class ContiguousCodestreamBox(Jp2kBox): Returns ------- - kwargs : dictionary of parameter values + ContiguousCodestreamBox instance """ - kwargs = {} - kwargs['id'] = id - kwargs['length'] = length - kwargs['offset'] = offset - - kwargs['main_header'] = Codestream(f, header_only=True) - - box = ContiguousCodestreamBox(**kwargs) + main_header = Codestream(fptr, header_only=True) + box = ContiguousCodestreamBox(main_header, length=length, + offset=offset) return box @@ -642,7 +641,7 @@ class FileTypeBox(Jp2kBox): Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : int length of the box in bytes. @@ -658,15 +657,18 @@ class FileTypeBox(Jp2kBox): compatibility_list: list List of file conformance profiles. """ - def __init__(self, **kwargs): - Jp2kBox.__init__(self, id='ftyp', longname='File Type') - self.__dict__.update(**kwargs) - if 'brand' not in kwargs.keys(): - self.brand = 'jp2 ' - if 'minor_version' not in kwargs.keys(): - self.minor_version = 0 - if 'compatibility_list' not in kwargs.keys(): + def __init__(self, brand='jp2 ', minor_version=0, + compatibility_list=None, length=0, offset=-1): + Jp2kBox.__init__(self, box_id='ftyp', longname='File Type') + self.brand = brand + self.minor_version = minor_version + if compatibility_list is None: + # see W0102, pylint self.compatibility_list = ['jp2 '] + else: + self.compatibility_list = compatibility_list + self.length = length + self.offset = offset def __str__(self): lst = [Jp2kBox.__str__(self), @@ -677,64 +679,57 @@ class FileTypeBox(Jp2kBox): return msg - def _write(self, f): + def write(self, fptr): """Write a File Type box to file. """ length = 16 + 4*len(self.compatibility_list) - f.write(struct.pack('>I', length)) - f.write('ftyp'.encode()) - f.write(self.brand.encode()) - f.write(struct.pack('>I', self.minor_version)) + fptr.write(struct.pack('>I', length)) + fptr.write('ftyp'.encode()) + fptr.write(self.brand.encode()) + fptr.write(struct.pack('>I', self.minor_version)) for item in self.compatibility_list: - f.write(item.encode()) + fptr.write(item.encode()) @staticmethod - def _parse(f, id, offset, length): + def parse(fptr, offset, length): """Parse JPEG 2000 file type box. Parameters ---------- f : file Open file object. - id : byte - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int Length of the box in bytes. - Returns: - kwargs: dictionary of parameter values + Returns + ------- + FileTypeBox instance """ - kwargs = {} - kwargs['id'] = id - kwargs['length'] = length - kwargs['offset'] = offset - # Read the brand, minor version. - buffer = f.read(8) - (brand, minor_version) = struct.unpack('>4sI', buffer) - if sys.hexversion < 0x030000: - kwargs['brand'] = brand - else: - kwargs['brand'] = brand.decode('utf-8') - kwargs['minor_version'] = minor_version + read_buffer = fptr.read(8) + (brand, minor_version) = struct.unpack('>4sI', read_buffer) + if sys.hexversion >= 0x030000: + brand = brand.decode('utf-8') # Read the compatibility list. Each entry has 4 bytes. - current_pos = f.tell() - n = (offset + length - current_pos) / 4 - buffer = f.read(int(n) * 4) + current_pos = fptr.tell() + num_bytes = (offset + length - current_pos) / 4 + read_buffer = fptr.read(int(num_bytes) * 4) compatibility_list = [] - for j in range(int(n)): - CL, = struct.unpack('>4s', buffer[4*j:4*(j+1)]) + for j in range(int(num_bytes)): + entry, = struct.unpack('>4s', read_buffer[4*j:4*(j+1)]) if sys.hexversion >= 0x03000000: - CL = CL.decode('utf-8') - compatibility_list.append(CL) + entry = entry.decode('utf-8') + compatibility_list.append(entry) - kwargs['compatibility_list'] = compatibility_list + compatibility_list = compatibility_list - box = FileTypeBox(**kwargs) + box = FileTypeBox(brand=brand, minor_version=minor_version, + compatibility_list=compatibility_list, + length=length, offset=offset) return box @@ -743,7 +738,7 @@ class ImageHeaderBox(Jp2kBox): Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : int length of the box in bytes. @@ -769,14 +764,14 @@ class ImageHeaderBox(Jp2kBox): """ def __init__(self, height, width, num_components=1, signed=False, bits_per_component=8, compression=7, colorspace_unknown=False, - ip_provided=False, **kwargs): + ip_provided=False, length=0, offset=-1): """ Examples -------- >>> import glymur >>> box = glymur.jp2box.ImageHeaderBox(height=512, width=256) """ - Jp2kBox.__init__(self, id='ihdr', longname='Image Header') + Jp2kBox.__init__(self, box_id='ihdr', longname='Image Header') self.height = height self.width = width self.num_components = num_components @@ -784,8 +779,9 @@ class ImageHeaderBox(Jp2kBox): self.bits_per_component = bits_per_component self.compression = compression self.colorspace_unknown = colorspace_unknown - self.ip_provided = False - self.__dict__.update(**kwargs) + self.ip_provided = ip_provided + self.length = length + self.offset = offset def __str__(self): msg = Jp2kBox.__str__(self) @@ -803,61 +799,61 @@ class ImageHeaderBox(Jp2kBox): self.colorspace_unknown) return msg - def _write(self, f): + def write(self, fptr): """Write an Image Header box to file. """ - f.write(struct.pack('>I', 22)) - f.write('ihdr'.encode()) + fptr.write(struct.pack('>I', 22)) + fptr.write('ihdr'.encode()) # signedness and bps are stored together in a single byte bit_depth_signedness = 0x80 if self.signed else 0x00 bit_depth_signedness |= self.bits_per_component - 1 - buffer = struct.pack('>IIHBBBB', - self.height, - self.width, - self.num_components, - bit_depth_signedness, - self.compression, - 1 if self.colorspace_unknown else 0, - 1 if self.ip_provided else 0) - f.write(buffer) + read_buffer = struct.pack('>IIHBBBB', + self.height, + self.width, + self.num_components, + bit_depth_signedness, + self.compression, + 1 if self.colorspace_unknown else 0, + 1 if self.ip_provided else 0) + fptr.write(read_buffer) @staticmethod - def _parse(f, id, offset, length): + def parse(fptr, offset, length): """Parse JPEG 2000 image header box. Parameters ---------- - f : file + fptr : file Open file object. - id : byte - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int Length of the box in bytes. - Returns: - kwargs: dictionary of parameter values + Returns + ------- + ImageHeaderBox instance """ - kwargs = {} - kwargs['id'] = id - kwargs['length'] = length - kwargs['offset'] = offset - # Read the box information - buffer = f.read(14) - params = struct.unpack('>IIHBBBB', buffer) + read_buffer = fptr.read(14) + params = struct.unpack('>IIHBBBB', read_buffer) height = params[0] width = params[1] - kwargs['num_components'] = params[2] - kwargs['bits_per_component'] = (params[3] & 0x7f) + 1 - kwargs['signed'] = (params[3] & 0x80) > 1 - kwargs['compression'] = params[4] - kwargs['colorspace_unknown'] = True if params[5] else False - kwargs['ip_provided'] = True if params[6] else False + num_components = params[2] + bits_per_component = (params[3] & 0x7f) + 1 + signed = (params[3] & 0x80) > 1 + compression = params[4] + colorspace_unknown = True if params[5] else False + ip_provided = True if params[6] else False - box = ImageHeaderBox(height, width, **kwargs) + box = ImageHeaderBox(height, width, num_components=num_components, + bits_per_component=bits_per_component, + signed=signed, + compression=compression, + colorspace_unknown=colorspace_unknown, + ip_provided=ip_provided, + length=length, offset=offset) return box @@ -866,7 +862,7 @@ class AssociationBox(Jp2kBox): Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : int length of the box in bytes. @@ -877,9 +873,11 @@ class AssociationBox(Jp2kBox): box : list List of boxes contained in this superbox. """ - def __init__(self, **kwargs): - Jp2kBox.__init__(self, id='', longname='Association') - self.__dict__.update(**kwargs) + def __init__(self, length=0, offset=-1): + Jp2kBox.__init__(self, box_id='asoc', longname='Association') + self.length = length + self.offset = offset + self.box = [] def __str__(self): msg = Jp2kBox.__str__(self) @@ -892,15 +890,13 @@ class AssociationBox(Jp2kBox): return msg @staticmethod - def _parse(f, id, offset, length): + def parse(fptr, offset, length): """Parse association box. Parameters ---------- - f : file + fptr : file Open file object. - id : byte - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int @@ -908,19 +904,13 @@ class AssociationBox(Jp2kBox): Returns ------- - kwargs : dictionary of parameter values, for now just a single - 4-byte tuple. + AssociationBox instance """ - kwargs = {} - kwargs['id'] = id - kwargs['length'] = length - kwargs['offset'] = offset + box = AssociationBox(length=length, offset=offset) - box = AssociationBox(**kwargs) - - # The JP2 header box is a superbox, so go ahead and parse its child + # The Association box is a superbox, so go ahead and parse its child # boxes. - box.box = box._parse_superbox(f) + box.box = box.parse_superbox(fptr) return box @@ -930,7 +920,7 @@ class JP2HeaderBox(Jp2kBox): Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : int length of the box in bytes. @@ -941,9 +931,11 @@ class JP2HeaderBox(Jp2kBox): box : list List of boxes contained in this superbox. """ - def __init__(self, **kwargs): - Jp2kBox.__init__(self, id='jp2h', longname='JP2 Header') - self.__dict__.update(**kwargs) + def __init__(self, length=0, offset=-1): + Jp2kBox.__init__(self, box_id='jp2h', longname='JP2 Header') + self.length = length + self.offset = offset + self.box = [] def __str__(self): msg = Jp2kBox.__str__(self) @@ -955,31 +947,29 @@ class JP2HeaderBox(Jp2kBox): msg += ''.join(strs) return msg - def _write(self, f): + def write(self, fptr): """Write a JP2 Header box to file. """ # Write the contained boxes, then come back and write the length. - orig_pos = f.tell() - f.write(struct.pack('>I', 0)) - f.write('jp2h'.encode()) + orig_pos = fptr.tell() + fptr.write(struct.pack('>I', 0)) + fptr.write('jp2h'.encode()) for box in self.box: - box._write(f) + box.write(fptr) - end_pos = f.tell() - f.seek(orig_pos) - f.write(struct.pack('>I', end_pos - orig_pos)) - f.seek(end_pos) + end_pos = fptr.tell() + fptr.seek(orig_pos) + fptr.write(struct.pack('>I', end_pos - orig_pos)) + fptr.seek(end_pos) @staticmethod - def _parse(f, id, offset, length): + def parse(fptr, offset, length): """Parse JPEG 2000 header box. Parameters ---------- - f : file + fptr : file Open file object. - id : byte - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int @@ -987,19 +977,13 @@ class JP2HeaderBox(Jp2kBox): Returns ------- - kwargs : dictionary of parameter values, for now just a single - 4-byte tuple. + JP2HeaderBox instance """ - kwargs = {} - kwargs['id'] = id - kwargs['length'] = length - kwargs['offset'] = offset - - box = JP2HeaderBox(**kwargs) + box = JP2HeaderBox(length=length, offset=offset) # The JP2 header box is a superbox, so go ahead and parse its child # boxes. - box.box = box._parse_superbox(f) + box.box = box.parse_superbox(fptr) return box @@ -1009,7 +993,7 @@ class JPEG2000SignatureBox(Jp2kBox): Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : int length of the box in bytes. @@ -1020,11 +1004,11 @@ class JPEG2000SignatureBox(Jp2kBox): signature : byte Four-byte tuple identifying the file as JPEG 2000. """ - def __init__(self, **kwargs): - Jp2kBox.__init__(self, id='jP ', longname='JPEG 2000 Signature') - self.__dict__.update(**kwargs) - if 'signature' not in kwargs.keys(): - self.signature = (13, 10, 135, 10) + def __init__(self, signature=(13, 10, 135, 10), length=0, offset=-1): + Jp2kBox.__init__(self, box_id='jP ', longname='JPEG 2000 Signature') + self.signature = signature + self.length = length + self.offset = offset def __str__(self): msg = Jp2kBox.__str__(self) @@ -1032,41 +1016,35 @@ class JPEG2000SignatureBox(Jp2kBox): msg = msg.format(*self.signature) return msg - def _write(self, f): + def write(self, fptr): """Write a JPEG 2000 Signature box to file. """ - f.write(struct.pack('>I', 12)) - f.write(self.id.encode()) - f.write(struct.pack('>BBBB', *self.signature)) + fptr.write(struct.pack('>I', 12)) + fptr.write(self.box_id.encode()) + fptr.write(struct.pack('>BBBB', *self.signature)) @staticmethod - def _parse(f, id, offset, length): + def parse(fptr, offset, length): """Parse JPEG 2000 signature box. Parameters ---------- - f : file + fptr : file Open file object. - id : byte - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int Length of the box in bytes. - Returns: - kwargs: dictionary of parameter values, for now just a single - 4-byte tuple. + Returns + ------- + JPEG2000SignatureBox instance """ - kwargs = {} - kwargs['id'] = id - kwargs['length'] = length - kwargs['offset'] = offset + read_buffer = fptr.read(4) + signature = struct.unpack('>BBBB', read_buffer) - buffer = f.read(4) - kwargs['signature'] = struct.unpack('>BBBB', buffer) - - box = JPEG2000SignatureBox(**kwargs) + box = JPEG2000SignatureBox(signature=signature, length=length, + offset=offset) return box @@ -1075,7 +1053,7 @@ class PaletteBox(Jp2kBox): Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : int length of the box in bytes. @@ -1086,9 +1064,14 @@ class PaletteBox(Jp2kBox): palette : list Colormap represented as list of 1D arrays, one per color component. """ - def __init__(self, **kwargs): - Jp2kBox.__init__(self, id='', longname='Palette') - self.__dict__.update(**kwargs) + def __init__(self, palette, bits_per_component, signed, length=0, + offset=-1): + Jp2kBox.__init__(self, box_id='pclr', longname='Palette') + self.palette = palette + self.bits_per_component = bits_per_component + self.signed = signed + self.length = length + self.offset = offset def __str__(self): msg = Jp2kBox.__str__(self) @@ -1097,15 +1080,13 @@ class PaletteBox(Jp2kBox): return msg @staticmethod - def _parse(f, id, offset, length): + def parse(fptr, offset, length): """Parse palette box. Parameters ---------- - f : file + fptr : file Open file object. - id : byte - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int @@ -1113,24 +1094,17 @@ class PaletteBox(Jp2kBox): Returns ------- - kwargs: dictionary of parameter values + PaletteBox instance """ - kwargs = {} - kwargs['id'] = id - kwargs['length'] = length - kwargs['offset'] = offset - # Get the size of the palette. - buffer = f.read(3) - (NE, NC) = struct.unpack('>HB', buffer) + read_buffer = fptr.read(3) + (num_entries, num_columns) = struct.unpack('>HB', read_buffer) # Need to determine bps and signed or not - buffer = f.read(NC) - data = struct.unpack('>' + 'B' * NC, buffer) + read_buffer = fptr.read(num_columns) + data = struct.unpack('>' + 'B' * num_columns, read_buffer) bps = [((x & 0x07f) + 1) for x in data] signed = [((x & 0x80) > 1) for x in data] - kwargs['bits_per_component'] = bps - kwargs['signed'] = signed # Form the format string so that we can intelligently unpack the # colormap. We have to do this because it is possible that the @@ -1140,43 +1114,127 @@ class PaletteBox(Jp2kBox): # which reverses the usual indexing scheme. palette = [] fmt = '>' - bytes_per_row = 0 - for j in range(NC): + row_nbytes = 0 + for j in range(num_columns): if bps[j] <= 8: fmt += 'B' - bytes_per_row += 1 - palette.append(np.zeros(NE, dtype=np.uint8)) + row_nbytes += 1 + palette.append(np.zeros(num_entries, dtype=np.uint8)) elif bps[j] <= 16: fmt += 'H' - bytes_per_row += 2 - palette.append(np.zeros(NE, dtype=np.uint16)) + row_nbytes += 2 + palette.append(np.zeros(num_entries, dtype=np.uint16)) elif bps[j] <= 32: fmt += 'I' - bytes_per_row += 4 - palette.append(np.zeros(NE, dtype=np.uint32)) + row_nbytes += 4 + palette.append(np.zeros(num_entries, dtype=np.uint32)) else: - msg = 'Unsupported palette bitdepth (%d).' + msg = 'Unsupported palette bitdepth (%d).'.format(bps[j]) raise IOError(msg) - n = NE * bytes_per_row - buffer = f.read(n) + read_buffer = fptr.read(num_entries * row_nbytes) - for j in range(NE): - row_buffer = buffer[(bytes_per_row * j):(bytes_per_row * (j + 1))] + for j in range(num_entries): + row_buffer = read_buffer[(row_nbytes * j):(row_nbytes * (j + 1))] row = struct.unpack(fmt, row_buffer) - for k in range(NC): + for k in range(num_columns): palette[k][j] = row[k] - kwargs['palette'] = palette - box = PaletteBox(**kwargs) + box = PaletteBox(palette, bps, signed, length=length, + offset=offset) return box +# Map rreq codes to display text. +_READER_REQUIREMENTS_DISPLAY = { + 0: 'File not completely understood', + 1: 'Deprecated', + 2: 'Contains multiple composition layers', + 3: 'Deprecated', + 4: 'JPEG 2000 Part 1 Profile 1 codestream', + 5: 'Unrestricted JPEG 2000 Part 1 codestream, ITU-T Rec. T.800 ' + + '| ISO/IEC 15444-1', + 6: 'Unrestricted JPEG 2000 Part 2 codestream', + 7: 'JPEG codestream as defined in ISO/IEC 10918-1', + 8: 'Deprecated', + 9: 'Non-premultiplied opacity channel', + 10: 'Premultiplied opacity channel', + 11: 'Chroma-key based opacity', + 12: 'Deprecated', + 13: 'Fragmented codestream where all fragments are in file and in order', + 14: 'Fragmented codestream where all fragments are in file ' + + 'but are out of order', + 15: 'Fragmented codestream where not all fragments are within the file ' + + 'but are all in locally accessible files', + 16: 'Fragmented codestream where some fragments may be accessible ' + + 'only through a URL specified network connection', + 17: 'Compositing required to produce rendered result from multiple ' + + 'compositing layers', + 18: 'Deprecated', + 19: 'Deprecated', + 20: 'Deprecated', + 21: 'At least one compositing layer consists of multiple codestreams', + 22: 'Deprecated', + 23: 'Colourspace transformations are required to combine compositing ' + + 'layers; not all compositing layers are in the same colourspace', + 24: 'Deprecated', + 25: 'Deprecated', + 26: 'First animation layer does not cover entire rendered result', + 27: 'Deprecated', + 28: 'Reuse of animation layers', + 29: 'Deprecated', + 30: 'Some animated frames are non-persistent', + 31: 'Deprecated', + 32: 'Rendered result involves scaling within a layer', + 33: 'Rendered result involves scaling between layers', + 34: 'ROI metadata', + 35: 'IPR metadata', + 36: 'Content metadata', + 37: 'History metadata', + 38: 'Creation metadata', + 39: 'JPX digital signatures', + 40: 'JPX checksums', + 41: 'Desires Graphics Arts Reproduction specified', + 42: 'Deprecated', + 43: '(Deprecated) compositing layer uses restricted ICC profile', + 44: 'Compositing layer uses Any ICC profile', + 45: 'Deprecated', + 46: 'Deprecated', + 47: 'BiLevel 1 enumerated colourspace', + 48: 'BiLevel 2 enumerated colourspace', + 49: 'YCbCr 1 enumerated colourspace', + 50: 'YCbCr 2 enumerated colourspace', + 51: 'YCbCr 3 enumerated colourspace', + 52: 'PhotoYCC enumerated colourspace', + 53: 'YCCK enumerated colourspace', + 54: 'CMY enumerated colourspace', + 55: 'CMYK enumerated colorspace', + 56: 'CIELab enumerated colourspace with default parameters', + 57: 'CIELab enumerated colourspace with non-default parameters', + 58: 'CIEJab enumerated colourspace with default parameters', + 59: 'CIEJab enumerated colourspace with non-default parameters', + 60: 'e-sRGB enumerated colorspace', + 61: 'ROMM_RGB enumerated colorspace', + 62: 'Non-square samples', + 63: 'Deprecated', + 64: 'Deprecated', + 65: 'Deprecated', + 66: 'Deprecated', + 67: 'GIS metadata XML box', + 68: 'JPSEC extensions in codestream as specified by ISO/IEC 15444-8', + 69: 'JP3D extensions in codestream as specified by ISO/IEC 15444-10', + 70: 'Deprecated', + 71: 'e-sYCC enumerated colourspace', + 72: 'JPEG 2000 Part 2 codestream as restricted by baseline conformance ' + + 'requirements in M.9.2.3', + 73: 'YPbPr(1125/60) enumerated colourspace', + 74: 'YPbPr(1250/50) enumerated colourspace'} + class ReaderRequirementsBox(Jp2kBox): """Container for reader requirements box information. Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : int length of the box in bytes. @@ -1184,9 +1242,9 @@ class ReaderRequirementsBox(Jp2kBox): offset of the box from the start of the file. longname : str more verbose description of the box. - FUAM : int + fuam : int Fully Understand Aspects mask. - DCM : int + dcm : int Decode completely mask. standard_flag : list Integers specifying standard features. @@ -1199,23 +1257,27 @@ class ReaderRequirementsBox(Jp2kBox): Specifies the compatibility mask for each corresponding vendor feature. """ - def __init__(self, **kwargs): - Jp2kBox.__init__(self, id='', longname='Reader Requirements') - self.__dict__.update(**kwargs) + def __init__(self, fuam, dcm, standard_flag, standard_mask, vendor_feature, + vendor_mask, length=0, offset=-1): + Jp2kBox.__init__(self, box_id='rreq', longname='Reader Requirements') + self.fuam = fuam + self.dcm = dcm + self.standard_flag = standard_flag + self.standard_mask = standard_mask + self.vendor_feature = vendor_feature + self.vendor_mask = vendor_mask + self.length = length + self.offset = offset def __str__(self): msg = Jp2kBox.__str__(self) - # TODO: include FUAM, DCM - msg += '\n Standard Features:' - # TODO: include each standard mask for j in range(len(self.standard_flag)): sfl = self.standard_flag[j] - rrdisp = _reader_requirements_display[self.standard_flag[j]] + rrdisp = _READER_REQUIREMENTS_DISPLAY[self.standard_flag[j]] msg += '\n Feature {0:03d}: {1}'.format(sfl, rrdisp) - # TODO: include the vendor mask msg += '\n Vendor Features:' for j in range(len(self.vendor_feature)): msg += '\n UUID {0}'.format(self.vendor_feature[j]) @@ -1223,15 +1285,13 @@ class ReaderRequirementsBox(Jp2kBox): return msg @staticmethod - def _parse(f, id, offset, length): + def parse(fptr, offset, length): """Parse reader requirements box. Parameters ---------- - f : file + fptr : file Open file object. - id : byte - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int @@ -1239,15 +1299,10 @@ class ReaderRequirementsBox(Jp2kBox): Returns ------- - ReaderRequirementsBox. + ReaderRequirementsBox instance """ - kwargs = {} - kwargs['id'] = id - kwargs['length'] = length - kwargs['offset'] = offset - - buffer = f.read(1) - mask_length, = struct.unpack('>B', buffer) + read_buffer = fptr.read(1) + mask_length, = struct.unpack('>B', read_buffer) if mask_length == 1: mask_format = 'B' elif mask_length == 2: @@ -1261,44 +1316,43 @@ class ReaderRequirementsBox(Jp2kBox): # Fully Understands Aspect Mask # Decodes Completely Mask - buffer = f.read(2 * mask_length) - data = struct.unpack('>' + mask_format * 2, buffer) - kwargs['FUAM'] = data[0] - kwargs['DCM'] = data[1] + read_buffer = fptr.read(2 * mask_length) + data = struct.unpack('>' + mask_format * 2, read_buffer) + fuam = data[0] + dcm = data[1] - buffer = f.read(2) - num_standard_flags, = struct.unpack('>H', buffer) + read_buffer = fptr.read(2) + num_standard_flags, = struct.unpack('>H', read_buffer) # Read in standard flags and standard masks. Each standard flag should # be two bytes, but the standard mask flag is as long as specified by # the mask length. - buffer = f.read(num_standard_flags * (2 + mask_length)) + read_buffer = fptr.read(num_standard_flags * (2 + mask_length)) data = struct.unpack('>' + ('H' + mask_format) * num_standard_flags, - buffer) - kwargs['standard_flag'] = data[0:num_standard_flags * 2:2] - kwargs['standard_mask'] = data[1:num_standard_flags * 2:2] + read_buffer) + standard_flag = data[0:num_standard_flags * 2:2] + standard_mask = data[1:num_standard_flags * 2:2] # Vendor features - buffer = f.read(2) - num_vendor_features, = struct.unpack('>H', buffer) + read_buffer = fptr.read(2) + num_vendor_features, = struct.unpack('>H', read_buffer) # Each vendor feature consists of a 16-byte UUID plus a mask whose # length is specified by, you guessed it, "mask_length". entry_length = 16 + mask_length - buffer = f.read(num_vendor_features * entry_length) + read_buffer = fptr.read(num_vendor_features * entry_length) vendor_feature = [] vendor_mask = [] for j in range(num_vendor_features): - ubuffer = buffer[j * entry_length:(j + 1) * entry_length] + ubuffer = read_buffer[j * entry_length:(j + 1) * entry_length] vendor_feature.append(uuid.UUID(bytes=ubuffer[0:16])) - vm = struct.unpack('>' + mask_format, ubuffer[16:]) - vendor_mask.append(vm) + vmask = struct.unpack('>' + mask_format, ubuffer[16:]) + vendor_mask.append(vmask) - kwargs['vendor_feature'] = vendor_feature - kwargs['vendor_mask'] = vendor_mask - - box = ReaderRequirementsBox(**kwargs) + box = ReaderRequirementsBox(fuam, dcm, standard_flag, standard_mask, + vendor_feature, vendor_mask, + length=length, offset=offset) return box @@ -1307,7 +1361,7 @@ class ResolutionBox(Jp2kBox): Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : int length of the box in bytes. @@ -1318,9 +1372,11 @@ class ResolutionBox(Jp2kBox): box : list List of boxes contained in this superbox. """ - def __init__(self, **kwargs): - Jp2kBox.__init__(self, id='', longname='Resolution') - self.__dict__.update(**kwargs) + def __init__(self, length=0, offset=-1): + Jp2kBox.__init__(self, box_id='res ', longname='Resolution') + self.length = length + self.offset = offset + self.box = [] def __str__(self): msg = Jp2kBox.__str__(self) @@ -1333,15 +1389,13 @@ class ResolutionBox(Jp2kBox): return msg @staticmethod - def _parse(f, id, offset, length): + def parse(fptr, offset, length): """Parse Resolution box. Parameters ---------- - f : file + fptr : file Open file object. - id : byte - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int @@ -1349,29 +1403,23 @@ class ResolutionBox(Jp2kBox): Returns ------- - kwargs : dictionary of parameter values, for now just a single - 4-byte tuple. + ResolutionBox instance """ - kwargs = {} - kwargs['id'] = id - kwargs['length'] = length - kwargs['offset'] = offset - - box = ResolutionBox(**kwargs) + box = ResolutionBox(length=length, offset=offset) # The JP2 header box is a superbox, so go ahead and parse its child # boxes. - box.box = box._parse_superbox(f) + box.box = box.parse_superbox(fptr) return box -class CaptureResolutionBox(ResolutionBox): +class CaptureResolutionBox(Jp2kBox): """Container for Capture resolution box information. Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : int length of the box in bytes. @@ -1379,29 +1427,31 @@ class CaptureResolutionBox(ResolutionBox): offset of the box from the start of the file. longname : str more verbose description of the box. - VR, HR : float + vertical_resolution, horizontal_resolution : float Vertical, horizontal resolution. """ - def __init__(self, **kwargs): - ResolutionBox.__init__(self, id='', longname='Capture Resolution') - self.__dict__.update(**kwargs) + def __init__(self, vertical_resolution, horizontal_resolution, length=0, + offset=-1): + Jp2kBox.__init__(self, box_id='resc', longname='Capture Resolution') + self.vertical_resolution = vertical_resolution + self.horizontal_resolution = horizontal_resolution + self.length = length + self.offset = offset def __str__(self): msg = Jp2kBox.__str__(self) - msg += '\n VCR: {0}'.format(self.VR) - msg += '\n HCR: {0}'.format(self.HR) + msg += '\n VCR: {0}'.format(self.vertical_resolution) + msg += '\n HCR: {0}'.format(self.horizontal_resolution) return msg @staticmethod - def _parse(f, id, offset, length): + def parse(fptr, offset, length): """Parse Resolution box. Parameters ---------- - f : file + fptr : file Open file object. - id : byte - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int @@ -1409,30 +1459,24 @@ class CaptureResolutionBox(ResolutionBox): Returns ------- - kwargs : dictionary of parameter values, for now just a single - 4-byte tuple. + CaptureResolutionBox instance """ - kwargs = {} - kwargs['id'] = id - kwargs['length'] = length - kwargs['offset'] = offset + read_buffer = fptr.read(10) + (rn1, rd1, rn2, rd2, re1, re2) = struct.unpack('>HHHHBB', read_buffer) + vres = rn1 / rd1 * math.pow(10, re1) + hres = rn2 / rd2 * math.pow(10, re2) - buffer = f.read(10) - (RN1, RD1, RN2, RD2, RE1, RE2) = struct.unpack('>HHHHBB', buffer) - kwargs['VR'] = RN1 / RD1 * math.pow(10, RE1) - kwargs['HR'] = RN2 / RD2 * math.pow(10, RE2) - - box = CaptureResolutionBox(**kwargs) + box = CaptureResolutionBox(vres, hres, length=length, offset=offset) return box -class DisplayResolutionBox(ResolutionBox): +class DisplayResolutionBox(Jp2kBox): """Container for Display resolution box information. Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : int length of the box in bytes. @@ -1440,29 +1484,31 @@ class DisplayResolutionBox(ResolutionBox): offset of the box from the start of the file. longname : str more verbose description of the box. - VR, HR : float + vertical_resolution, horizontal_resolution : float Vertical, horizontal resolution. """ - def __init__(self, **kwargs): - ResolutionBox.__init__(self, id='', longname='Display Resolution') - self.__dict__.update(**kwargs) + def __init__(self, vertical_resolution, horizontal_resolution, + length=0, offset=-1): + Jp2kBox.__init__(self, box_id='resd', longname='Display Resolution') + self.vertical_resolution = vertical_resolution + self.horizontal_resolution = horizontal_resolution + self.length = length + self.offset = offset def __str__(self): msg = Jp2kBox.__str__(self) - msg += '\n VDR: {0}'.format(self.VR) - msg += '\n HDR: {0}'.format(self.HR) + msg += '\n VDR: {0}'.format(self.vertical_resolution) + msg += '\n HDR: {0}'.format(self.horizontal_resolution) return msg @staticmethod - def _parse(f, id, offset, length): + def parse(fptr, offset, length): """Parse Resolution box. Parameters ---------- - f : file + fptr : file Open file object. - id : byte - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int @@ -1470,20 +1516,15 @@ class DisplayResolutionBox(ResolutionBox): Returns ------- - kwargs : dictionary of parameter values, for now just a single - 4-byte tuple. + DisplayResolutionBox instance """ - kwargs = {} - kwargs['id'] = id - kwargs['length'] = length - kwargs['offset'] = offset - buffer = f.read(10) - (RN1, RD1, RN2, RD2, RE1, RE2) = struct.unpack('>HHHHBB', buffer) - kwargs['VR'] = RN1 / RD1 * math.pow(10, RE1) - kwargs['HR'] = RN2 / RD2 * math.pow(10, RE2) + read_buffer = fptr.read(10) + (rn1, rd1, rn2, rd2, re1, re2) = struct.unpack('>HHHHBB', read_buffer) + vres = rn1 / rd1 * math.pow(10, re1) + hres = rn2 / rd2 * math.pow(10, re2) - box = DisplayResolutionBox(**kwargs) + box = DisplayResolutionBox(vres, hres, length=length, offset=offset) return box @@ -1493,7 +1534,7 @@ class LabelBox(Jp2kBox): Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : int length of the box in bytes. @@ -1504,9 +1545,11 @@ class LabelBox(Jp2kBox): label : str Label """ - def __init__(self, **kwargs): - Jp2kBox.__init__(self, id='', longname='Label') - self.__dict__.update(**kwargs) + def __init__(self, label, length=0, offset=-1): + Jp2kBox.__init__(self, box_id='lbl ', longname='Label') + self.label = label + self.length = length + self.offset = offset def __str__(self): msg = Jp2kBox.__str__(self) @@ -1514,15 +1557,13 @@ class LabelBox(Jp2kBox): return msg @staticmethod - def _parse(f, id, offset, length): + def parse(fptr, offset, length): """Parse Label box. Parameters ---------- - f : file + fptr : file Open file object. - id : byte - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int @@ -1530,17 +1571,12 @@ class LabelBox(Jp2kBox): Returns ------- - kwargs : dictionary of parameter values + LabelBox instance """ - kwargs = {} - kwargs['id'] = id - kwargs['length'] = length - kwargs['offset'] = offset - - num_bytes = offset + length - f.tell() - buffer = f.read(num_bytes) - kwargs['label'] = buffer.decode('utf-8') - box = LabelBox(**kwargs) + num_bytes = offset + length - fptr.tell() + read_buffer = fptr.read(num_bytes) + label = read_buffer.decode('utf-8') + box = LabelBox(label, length=length, offset=offset) return box @@ -1549,7 +1585,7 @@ class XMLBox(Jp2kBox): Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : int length of the box in bytes. @@ -1560,7 +1596,7 @@ class XMLBox(Jp2kBox): xml : ElementTree.Element XML section. """ - def __init__(self, xml=None, filename=None, **kwargs): + def __init__(self, xml=None, filename=None, length=0, offset=-1): """ Parameters ---------- @@ -1570,7 +1606,7 @@ class XMLBox(Jp2kBox): File from which to read XML. If filename is not None, then the xml keyword argument must be None. """ - Jp2kBox.__init__(self, id='xml ', longname='XML') + Jp2kBox.__init__(self, box_id='xml ', longname='XML') if filename is not None and xml is not None: msg = "Only one of either filename or xml should be provided." raise IOError(msg) @@ -1578,7 +1614,8 @@ class XMLBox(Jp2kBox): self.xml = ET.parse(filename) else: self.xml = xml - self.__dict__.update(**kwargs) + self.length = length + self.offset = offset def __str__(self): msg = Jp2kBox.__str__(self) @@ -1592,28 +1629,26 @@ class XMLBox(Jp2kBox): msg += '\n {0}'.format(xml) return msg - def _write(self, f): + def write(self, fptr): """Write an XML box to file. """ try: - buffer = ET.tostring(self.xml, encoding='utf-8') + read_buffer = ET.tostring(self.xml, encoding='utf-8') except AttributeError: - buffer = ET.tostring(self.xml.getroot(), encoding='utf-8') + read_buffer = ET.tostring(self.xml.getroot(), encoding='utf-8') - f.write(struct.pack('>I', len(buffer) + 8)) - f.write(self.id.encode()) - f.write(buffer) + fptr.write(struct.pack('>I', len(read_buffer) + 8)) + fptr.write(self.box_id.encode()) + fptr.write(read_buffer) @staticmethod - def _parse(f, id, offset, length): + def parse(fptr, offset, length): """Parse XML box. Parameters ---------- - f : file + fptr : file Open file object. - id : byte - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int @@ -1621,29 +1656,24 @@ class XMLBox(Jp2kBox): Returns ------- - kwargs : dictionary of parameter values + XMLBox instance """ - kwargs = {} - kwargs['id'] = id - kwargs['length'] = length - kwargs['offset'] = offset - - num_bytes = offset + length - f.tell() - buffer = f.read(num_bytes) - text = buffer.decode('utf-8') + num_bytes = offset + length - fptr.tell() + read_buffer = fptr.read(num_bytes) + text = read_buffer.decode('utf-8') # Strip out any trailing nulls. text = text.rstrip('\0') try: - kwargs['xml'] = ET.fromstring(text) - except ET.ParseError as e: + xml = ET.fromstring(text) + except ET.ParseError as parse_error: msg = 'A problem was encountered while parsing an XML box: "{0}"' - msg = msg.format(str(e)) + msg = msg.format(str(parse_error)) warnings.warn(msg, UserWarning) - kwargs['xml'] = None + xml = None - box = XMLBox(**kwargs) + box = XMLBox(xml=xml, length=length, offset=offset) return box @@ -1652,7 +1682,7 @@ class UUIDListBox(Jp2kBox): Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : int length of the box in bytes. @@ -1663,26 +1693,26 @@ class UUIDListBox(Jp2kBox): ulst : list List of UUIDs. """ - def __init__(self, **kwargs): - Jp2kBox.__init__(self, id='', longname='UUID List') - self.__dict__.update(**kwargs) + def __init__(self, ulst, length=0, offset=-1): + Jp2kBox.__init__(self, box_id='ulst', longname='UUID List') + self.ulst = ulst + self.length = length + self.offset = offset def __str__(self): msg = Jp2kBox.__str__(self) - for enumerated_item in enumerate(self.ulst): - msg += '\n UUID[{0}]: {1}'.format(*enumerated_item) + for j, uuid_item in enumerate(self.ulst): + msg += '\n UUID[{0}]: {1}'.format(j, uuid_item) return(msg) @staticmethod - def _parse(f, id, offset, length): + def parse(fptr, offset, length): """Parse UUIDList box. Parameters ---------- f : file Open file object. - id : byte - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int @@ -1690,22 +1720,17 @@ class UUIDListBox(Jp2kBox): Returns ------- - kwargs : dictionary of parameter values + UUIDListBox instance """ - buffer = f.read(2) - N, = struct.unpack('>H', buffer) + read_buffer = fptr.read(2) + num_uuids, = struct.unpack('>H', read_buffer) ulst = [] - for j in range(N): - buffer = f.read(16) - ulst.append(uuid.UUID(bytes=buffer)) + for _ in range(num_uuids): + read_buffer = fptr.read(16) + ulst.append(uuid.UUID(bytes=read_buffer)) - kwargs = {} - kwargs['id'] = id - kwargs['offset'] = offset - kwargs['length'] = length - kwargs['ulst'] = ulst - box = UUIDListBox(**kwargs) + box = UUIDListBox(ulst, length=length, offset=offset) return(box) @@ -1714,7 +1739,7 @@ class UUIDInfoBox(Jp2kBox): Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : int length of the box in bytes. @@ -1725,9 +1750,11 @@ class UUIDInfoBox(Jp2kBox): box : list List of boxes contained in this superbox. """ - def __init__(self, **kwargs): - Jp2kBox.__init__(self, id='', longname='UUIDInfo') - self.__dict__.update(**kwargs) + def __init__(self, length=0, offset=-1): + Jp2kBox.__init__(self, box_id='uinf', longname='UUIDInfo') + self.length = length + self.offset = offset + self.box = [] def __str__(self): msg = Jp2kBox.__str__(self) @@ -1742,15 +1769,13 @@ class UUIDInfoBox(Jp2kBox): return(msg) @staticmethod - def _parse(f, id, offset, length): + def parse(fptr, offset, length): """Parse UUIDInfo super box. Parameters ---------- - f : file + fptr : file Open file object. - id : byte - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int @@ -1758,18 +1783,14 @@ class UUIDInfoBox(Jp2kBox): Returns ------- - kwargs : dictionary of parameter values + UUIDInfoBox instance """ - kwargs = {} - kwargs['id'] = id - kwargs['length'] = length - kwargs['offset'] = offset - box = UUIDInfoBox(**kwargs) + box = UUIDInfoBox(length=length, offset=offset) # The UUIDInfo box is a superbox, so go ahead and parse its child # boxes. - box.box = box._parse_superbox(f) + box.box = box.parse_superbox(fptr) return box @@ -1779,7 +1800,7 @@ class DataEntryURLBox(Jp2kBox): Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : int length of the box in bytes. @@ -1794,9 +1815,13 @@ class DataEntryURLBox(Jp2kBox): URL : str Associated URL. """ - def __init__(self, **kwargs): - Jp2kBox.__init__(self, id='', longname='Data Entry URL') - self.__dict__.update(**kwargs) + def __init__(self, version, flag, url, length=0, offset=-1): + Jp2kBox.__init__(self, box_id='url ', longname='Data Entry URL') + self.version = version + self.flag = flag + self.url = url + self.length = length + self.offset = offset def __str__(self): msg = Jp2kBox.__str__(self) @@ -1808,19 +1833,17 @@ class DataEntryURLBox(Jp2kBox): msg += '\n '.join(lines) msg = msg.format(self.version, self.flag[0], self.flag[1], self.flag[2], - self.URL) + self.url) return msg @staticmethod - def _parse(f, id, offset, length): + def parse(fptr, offset, length): """Parse Data Entry URL box. Parameters ---------- - f : file + fptr : file Open file object. - id : byte - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int @@ -1828,22 +1851,17 @@ class DataEntryURLBox(Jp2kBox): Returns ------- - kwargs : dictionary of parameter values + DataEntryURLbox instance """ - kwargs = {} - kwargs['id'] = id - kwargs['length'] = length - kwargs['offset'] = offset + read_buffer = fptr.read(4) + data = struct.unpack('>BBBB', read_buffer) + version = data[0] + flag = data[1:4] - buffer = f.read(4) - data = struct.unpack('>BBBB', buffer) - kwargs['version'] = data[0] - kwargs['flag'] = data[1:4] - - n = offset + length - f.tell() - buffer = f.read(n) - kwargs['URL'] = buffer.decode('utf-8') - box = DataEntryURLBox(**kwargs) + numbytes = offset + length - fptr.tell() + read_buffer = fptr.read(numbytes) + url = read_buffer.decode('utf-8') + box = DataEntryURLBox(version, flag, url, length=length, offset=offset) return box @@ -1852,7 +1870,7 @@ class UUIDBox(Jp2kBox): Attributes ---------- - id : str + box_id : str 4-character identifier for the box. length : int length of the box in bytes. @@ -1872,9 +1890,44 @@ class UUIDBox(Jp2kBox): 16684-1:2012 - Graphic technology -- Extensible metadata platform (XMP) specification -- Part 1: Data model, serialization and core properties """ - def __init__(self, **kwargs): - Jp2kBox.__init__(self, id='', longname='UUID') - self.__dict__.update(**kwargs) + def __init__(self, the_uuid, raw_data, length=0, offset=-1): + """ + Parameters + ---------- + the_uuid : uuid.UUID + Identifies the type of UUID box. + raw_data : byte array + This is the "payload" of data for the specified UUID. + length : int + length of the box in bytes. + offset : int + offset of the box from the start of the file. + """ + Jp2kBox.__init__(self, box_id='uuid', longname='UUID') + self.uuid = the_uuid + + if the_uuid == uuid.UUID('be7acfcb-97a9-42e8-9c71-999491e3afac'): + # XMP data. Parse as XML. Seems to be a difference between + # ElementTree in version 2.7 and 3.3. + if sys.hexversion < 0x03000000: + parser = ET.XMLParser(encoding='utf-8') + self.data = ET.fromstringlist(raw_data, parser=parser) + else: + text = raw_data.decode('utf-8') + self.data = ET.fromstring(text) + elif the_uuid.bytes == b'JpgTiffExif->JP2': + exif_obj = Exif(raw_data) + ifds = collections.OrderedDict() + ifds['Image'] = exif_obj.exif_image + ifds['Photo'] = exif_obj.exif_photo + ifds['GPSInfo'] = exif_obj.exif_gpsinfo + ifds['Iop'] = exif_obj.exif_iop + self.data = ifds + else: + self.data = raw_data + + self.length = length + self.offset = offset def __str__(self): msg = '{0}\n' @@ -1888,8 +1941,11 @@ class UUIDBox(Jp2kBox): uuid_type = ' (Exif)' # 2.7 has trouble pretty-printing ordered dicts, so print them # as regular dicts. Not ideal, but at least it's good on 3.3+. - x = self.data if sys.hexversion >= 0x03000000 else dict(self.data) - uuid_data = '\n' + pprint.pformat(x) + if sys.hexversion < 0x03000000: + data = dict(self.data) + else: + data = self.data + uuid_data = '\n' + pprint.pformat(data) else: uuid_type = '' uuid_data = '{0} bytes'.format(len(self.data)) @@ -1902,53 +1958,29 @@ class UUIDBox(Jp2kBox): return msg @staticmethod - def _parse(f, id, offset, length): - """Parse JPEG 2000 signature box. + def parse(fptr, offset, length): + """Parse UUID box. Parameters ---------- - f : file + fptr : file Open file object. - id : str - 4-byte unique identifier for this box. offset : int Start position of box in bytes. length : int Length of the box in bytes. - Returns: - kwargs: dictionary of parameter values + Returns + ------- + UUIDBox instance """ - kwargs = {} - kwargs['id'] = id - kwargs['length'] = length - kwargs['offset'] = offset - buffer = f.read(16) - kwargs['uuid'] = uuid.UUID(bytes=buffer) + read_buffer = fptr.read(16) + the_uuid = uuid.UUID(bytes=read_buffer) - n = offset + length - f.tell() - buffer = f.read(n) - if kwargs['uuid'] == uuid.UUID('be7acfcb-97a9-42e8-9c71-999491e3afac'): - # XMP data. Parse as XML. Seems to be a difference between - # ElementTree in version 2.7 and 3.3. - if sys.hexversion < 0x03000000: - parser = ET.XMLParser(encoding='utf-8') - kwargs['data'] = ET.fromstringlist(buffer, parser=parser) - else: - text = buffer.decode('utf-8') - kwargs['data'] = ET.fromstring(text) - elif kwargs['uuid'].bytes == b'JpgTiffExif->JP2': - e = Exif(buffer) - d = collections.OrderedDict() - d['Image'] = e.exif_image - d['Photo'] = e.exif_photo - d['GPSInfo'] = e.exif_gpsinfo - d['Iop'] = e.exif_iop - kwargs['data'] = d - else: - kwargs['data'] = buffer - box = UUIDBox(**kwargs) + numbytes = offset + length - fptr.tell() + read_buffer = fptr.read(numbytes) + box = UUIDBox(the_uuid, read_buffer, length=length, offset=offset) return box @@ -1956,13 +1988,13 @@ class Exif(object): """ Attributes ---------- - buffer : bytes + read_buffer : bytes Raw byte stream consisting of the UUID data. endian : str Either '<' for big-endian, or '>' for little-endian. """ - def __init__(self, buffer): + def __init__(self, read_buffer): """Interpret raw buffer consisting of Exif IFD. """ self.exif_image = None @@ -1970,11 +2002,11 @@ class Exif(object): self.exif_gpsinfo = None self.exif_iop = None - self.buffer = buffer + self.read_buffer = read_buffer # Ignore the first six bytes. # Next 8 should be (73, 73, 42, 8) - data = struct.unpack('= 0x03030000: from contextlib import ExitStack @@ -16,14 +19,23 @@ import warnings import numpy as np from .codestream import Codestream -from .core import * -from .jp2box import * -from .lib import openjp2 as opj2 +from .core import SRGB +from .core import GREYSCALE +from .core import PROGRESSION_ORDER +from .jp2box import Jp2kBox +from .jp2box import JPEG2000SignatureBox +from .jp2box import FileTypeBox +from .jp2box import JP2HeaderBox +from .jp2box import ContiguousCodestreamBox +from .jp2box import ImageHeaderBox +from .jp2box import ColourSpecificationBox +from .lib import _openjpeg as _opj +from .lib import _openjp2 as _opj2 -_cspace_map = {'rgb': opj2._CLRSPC_SRGB, - 'gray': opj2._CLRSPC_GRAY, - 'grey': opj2._CLRSPC_GRAY, - 'ycc': opj2._CLRSPC_YCC} +_COLORSPACE_MAP = {'rgb': _opj2.CLRSPC_SRGB, + 'gray': _opj2.CLRSPC_GRAY, + 'grey': _opj2.CLRSPC_GRAY, + 'ycc': _opj2.CLRSPC_YCC} # Setup the default callback handlers. See the callback functions subsection # in the ctypes section of the Python documentation for a solid explanation of @@ -31,23 +43,26 @@ _cspace_map = {'rgb': opj2._CLRSPC_SRGB, _CMPFUNC = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_char_p, ctypes.c_void_p) -def _default_error_handler(msg, client_data): +def _default_error_handler(msg, _): + """Default error handler callback for openjpeg library.""" msg = "OpenJPEG library error: {0}".format(msg.decode('utf-8').rstrip()) - opj2._set_error_message(msg) + _opj2.set_error_message(msg) -def _default_info_handler(msg, client_data): +def _default_info_handler(msg, _): + """Default info handler callback for openjpeg library.""" print("[INFO] {0}".format(msg.decode('utf-8').rstrip())) -def _default_warning_handler(library_msg, client_data): +def _default_warning_handler(library_msg, _): + """Default warning handler callback for openjpeg library.""" library_msg = library_msg.decode('utf-8').rstrip() msg = "OpenJPEG library warning: {0}".format(library_msg) warnings.warn(msg) -_error_callback = _CMPFUNC(_default_error_handler) -_info_callback = _CMPFUNC(_default_info_handler) -_warning_callback = _CMPFUNC(_default_warning_handler) +_ERROR_CALLBACK = _CMPFUNC(_default_error_handler) +_INFO_CALLBACK = _CMPFUNC(_default_info_handler) +_WARNING_CALLBACK = _CMPFUNC(_default_warning_handler) class Jp2k(Jp2kBox): @@ -74,14 +89,16 @@ class Jp2k(Jp2kBox): mode : str, optional The mode used to open the file. """ + Jp2kBox.__init__(self) self.filename = filename self.mode = mode self.box = [] - self.offset = 0 + self._codec_format = None + self._file_size = 0 # Parse the file for JP2/JPX contents only if we are reading it. if mode == 'rb': - self._parse() + self.parse() def __str__(self): metadata = ['File: ' + os.path.basename(self.filename)] @@ -89,11 +106,11 @@ class Jp2k(Jp2kBox): for box in self.box: metadata.append(str(box)) else: - c = self.get_codestream() - metadata.append(str(c)) + codestream = self.get_codestream() + metadata.append(str(codestream)) return '\n'.join(metadata) - def _parse(self): + def parse(self): """Parses the JPEG 2000 file. Raises @@ -105,39 +122,41 @@ class Jp2k(Jp2kBox): self.length = stat.st_size self._file_size = stat.st_size - with open(self.filename, 'rb') as f: + with open(self.filename, 'rb') as fptr: # Make sure we have a JPEG2000 file. It could be either JP2 or # J2C. Check for J2C first, single box in that case. - buffer = f.read(2) - signature, = struct.unpack('>H', buffer) + read_buffer = fptr.read(2) + signature, = struct.unpack('>H', read_buffer) if signature == 0xff4f: - self._codec_format = opj2._CODEC_J2K + self._codec_format = _opj2.CODEC_J2K # That's it, we're done. The codestream object is only # produced upon explicit request. return - self._codec_format = opj2._CODEC_JP2 + self._codec_format = _opj2.CODEC_JP2 # Should be JP2. # First 4 bytes should be 12, the length of the 'jP ' box. # 2nd 4 bytes should be the box ID ('jP '). # 3rd 4 bytes should be the box signature (13, 10, 135, 10). - f.seek(0) - buffer = f.read(12) - values = struct.unpack('>I4s4B', buffer) - L = values[0] - T = values[1] + fptr.seek(0) + read_buffer = fptr.read(12) + values = struct.unpack('>I4s4B', read_buffer) + box_length = values[0] + box_id = values[1] signature = values[2:] - if L != 12 or T != b'jP ' or signature != (13, 10, 135, 10): + if (((box_length != 12) or (box_id != b'jP ') or + (signature != (13, 10, 135, 10)))): msg = '{0} is not a JPEG 2000 file.'.format(self.filename) raise IOError(msg) # Back up and start again, we know we have a superbox (box of # boxes) here. - f.seek(0) - self.box = self._parse_superbox(f) + fptr.seek(0) + self.box = self.parse_superbox(fptr) + # pylint: disable-msg=W0221 def write(self, img_array, cratios=None, eph=False, psnr=None, numres=None, cbsize=None, psizes=None, grid_offset=None, sop=False, subsam=None, tilesize=None, prog=None, modesw=None, @@ -202,24 +221,24 @@ class Jp2k(Jp2kBox): >>> import glymur >>> jfile = glymur.data.nemo() >>> jp2 = glymur.Jp2k(jfile) - >>> data = jp2.read(reduce=3) + >>> data = jp2.read(rlevel=1) >>> from tempfile import NamedTemporaryFile >>> tfile = NamedTemporaryFile(suffix='.jp2', delete=False) >>> j = Jp2k(tfile.name, mode='wb') >>> j.write(data.astype(np.uint8)) """ - cparams = opj2._set_default_encoder_parameters() + cparams = _opj2.set_default_encoder_parameters() outfile = self.filename.encode() - n = opj2._PATH_LEN - len(outfile) - outfile += b'0' * n + num_pad_bytes = _opj2.PATH_LEN - len(outfile) + outfile += b'0' * num_pad_bytes cparams.outfile = outfile if self.filename[-4:].lower() == '.jp2': - codec_fmt = opj2._CODEC_JP2 + codec_fmt = _opj2.CODEC_JP2 else: - codec_fmt = opj2._CODEC_J2K + codec_fmt = _opj2.CODEC_J2K cparams.cod_format = codec_fmt @@ -229,19 +248,19 @@ class Jp2k(Jp2kBox): cparams.cp_disto_alloc = 1 if cbsize is not None: - w = cbsize[1] - h = cbsize[0] - if h * w > 4096 or h < 4 or w < 4: + width = cbsize[1] + height = cbsize[0] + if height * width > 4096 or height < 4 or width < 4: msg = "Code block area cannot exceed 4096. " msg += "Code block height and width must be larger than 4." raise RuntimeError(msg) - if ((math.log(h, 2) != math.floor(math.log(h, 2)) or - math.log(w, 2) != math.floor(math.log(w, 2)))): + if ((math.log(height, 2) != math.floor(math.log(height, 2)) or + math.log(width, 2) != math.floor(math.log(width, 2)))): msg = "Bad code block size ({0}, {1}), " msg += "must be powers of 2." - raise IOError(msg.format(h, w)) - cparams.cblockw_init = w - cparams.cblockh_init = h + raise IOError(msg.format(height, width)) + cparams.cblockw_init = width + cparams.cblockh_init = height if cratios is not None: cparams.tcp_numlayers = len(cratios) @@ -257,16 +276,17 @@ class Jp2k(Jp2kBox): cparams.image_offset_y0 = grid_offset[0] if modesw is not None: - for x in range(6): - if modesw & (1 << x): - cparams.mode |= (1 << x) + for shift in range(6): + power_of_two = 1 << shift + if modesw & power_of_two: + cparams.mode |= power_of_two if numres is not None: cparams.numresolution = numres if prog is not None: prog = prog.upper() - cparams.prog_order = progression_order[prog] + cparams.prog_order = PROGRESSION_ORDER[prog] if psnr is not None: cparams.tcp_numlayers = len(psnr) @@ -303,7 +323,7 @@ class Jp2k(Jp2kBox): if tilesize is not None: cparams.cp_tdx = tilesize[1] cparams.cp_tdy = tilesize[0] - cparams.tile_size_on = opj2._TRUE + cparams.tile_size_on = _opj2.TRUE if cratios is not None and psnr is not None: msg = "Cannot specify cratios and psnr together." @@ -322,12 +342,12 @@ class Jp2k(Jp2kBox): if colorspace is None: if img_array.shape[2] == 1 or img_array.shape[2] == 2: - colorspace = opj2._CLRSPC_GRAY + colorspace = _opj2.CLRSPC_GRAY else: # No YCC unless specifically told to do so. - colorspace = opj2._CLRSPC_SRGB + colorspace = _opj2.CLRSPC_SRGB else: - if codec_fmt == opj2._CODEC_J2K: + if codec_fmt == _opj2.CODEC_J2K: raise IOError('Do not specify a colorspace with J2K.') colorspace = colorspace.lower() if colorspace not in ('rgb', 'grey', 'gray'): @@ -337,15 +357,15 @@ class Jp2k(Jp2kBox): msg = 'RGB colorspace requires at least 3 components.' raise IOError(msg) else: - colorspace = _cspace_map[colorspace] + colorspace = _COLORSPACE_MAP[colorspace] if mct is None: - if colorspace == opj2._CLRSPC_SRGB: + if colorspace == _opj2.CLRSPC_SRGB: cparams.tcp_mct = 1 else: cparams.tcp_mct = 0 else: - if mct and colorspace == opj2._CLRSPC_GRAY: + if mct and colorspace == _opj2.CLRSPC_GRAY: msg = "Cannot specify usage of the multi component transform " msg += "if the colorspace is gray." raise IOError(msg) @@ -358,7 +378,7 @@ class Jp2k(Jp2kBox): else: raise RuntimeError("unhandled datatype") - comptparms = (opj2._image_comptparm_t * num_comps)() + comptparms = (_opj2.ImageComptParmType * num_comps)() for j in range(num_comps): comptparms[j].dx = cparams.subsampling_dx comptparms[j].dy = cparams.subsampling_dy @@ -370,7 +390,7 @@ class Jp2k(Jp2kBox): comptparms[j].bpp = comp_prec comptparms[j].sgnd = 0 - image = opj2._image_create(comptparms, colorspace) + image = _opj2.image_create(comptparms, colorspace) # set image offset and reference grid image.contents.x0 = cparams.image_offset_x0 @@ -387,25 +407,25 @@ class Jp2k(Jp2kBox): src = layer.ctypes.data ctypes.memmove(dest, src, layer.nbytes) - codec = opj2._create_compress(codec_fmt) + codec = _opj2.create_compress(codec_fmt) if verbose: - opj2._set_info_handler(codec, _info_callback) + _opj2.set_info_handler(codec, _INFO_CALLBACK) else: - opj2._set_info_handler(codec, None) + _opj2.set_info_handler(codec, None) - opj2._set_warning_handler(codec, _warning_callback) - opj2._set_error_handler(codec, _error_callback) - opj2._setup_encoder(codec, cparams, image) - strm = opj2._stream_create_default_file_stream_v3(self.filename, False) - opj2._start_compress(codec, image, strm) - opj2._encode(codec, strm) - opj2._end_compress(codec, strm) - opj2._stream_destroy_v3(strm) - opj2._destroy_codec(codec) - opj2._image_destroy(image) + _opj2.set_warning_handler(codec, _WARNING_CALLBACK) + _opj2.set_error_handler(codec, _ERROR_CALLBACK) + _opj2.setup_encoder(codec, cparams, image) + strm = _opj2.stream_create_default_file_stream_v3(self.filename, False) + _opj2.start_compress(codec, image, strm) + _opj2.encode(codec, strm) + _opj2.end_compress(codec, strm) + _opj2.stream_destroy_v3(strm) + _opj2.destroy_codec(codec) + _opj2.image_destroy(image) - self._parse() + self.parse() def wrap(self, filename, boxes=None): """Write the codestream back out to file, wrapped in new JP2 jacket. @@ -438,10 +458,10 @@ class Jp2k(Jp2kBox): FileTypeBox(), JP2HeaderBox(), ContiguousCodestreamBox()] - c = self.get_codestream() - height = c.segment[1].Ysiz - width = c.segment[1].Xsiz - num_components = len(c.segment[1].XRsiz) + codestream = self.get_codestream() + height = codestream.segment[1].ysiz + width = codestream.segment[1].xsiz + num_components = len(codestream.segment[1].xrsiz) boxes[2].box = [ImageHeaderBox(height=height, width=width, num_components=num_components), @@ -449,15 +469,17 @@ class Jp2k(Jp2kBox): # Check for a bad sequence of boxes. # 1st two boxes must be 'jP ' and 'ftyp' - if boxes[0].id != 'jP ' or boxes[1].id != 'ftyp': + if boxes[0].box_id != 'jP ' or boxes[1].box_id != 'ftyp': msg = "The first box must be the signature box and the second " msg += "must be the file type box." raise IOError(msg) # jp2c must be preceeded by jp2h - jp2h_lst = [idx for (idx, box) in enumerate(boxes) if box.id == 'jp2h'] + jp2h_lst = [idx for (idx, box) in enumerate(boxes) + if box.box_id == 'jp2h'] jp2h_idx = jp2h_lst[0] - jp2c_lst = [idx for (idx, box) in enumerate(boxes) if box.id == 'jp2c'] + jp2c_lst = [idx for (idx, box) in enumerate(boxes) + if box.box_id == 'jp2c'] if len(jp2c_lst) == 0: msg = "A codestream box must be defined in the outermost " msg += "list of boxes." @@ -470,27 +492,28 @@ class Jp2k(Jp2kBox): # 1st jp2 header box must be ihdr jp2h = boxes[jp2h_idx] - if jp2h.box[0].id != 'ihdr': + if jp2h.box[0].box_id != 'ihdr': msg = "The first box in the jp2 header box must be the image " msg += "header box." raise IOError(msg) # colr must be present in jp2 header box. - jp2hb = jp2h.box - colr_lst = [j for (j, box) in enumerate(jp2h.box) if box.id == 'colr'] + colr_lst = [j for (j, box) in enumerate(jp2h.box) + if box.box_id == 'colr'] if len(colr_lst) == 0: msg = "The jp2 header box must contain a color definition box." raise IOError(msg) colr = jp2h.box[colr_lst[0]] # Any cdef box must be in the jp2 header following the image header. - cdef_lst = [j for (j, box) in enumerate(boxes) if box.id == 'cdef'] + cdef_lst = [j for (j, box) in enumerate(boxes) if box.box_id == 'cdef'] if len(cdef_lst) != 0: msg = "Any channel defintion box must be in the JP2 header " msg += "following the image header." raise IOError(msg) - cdef_lst = [j for (j, box) in enumerate(jp2h.box) if box.id == 'cdef'] + cdef_lst = [j for (j, box) in enumerate(jp2h.box) + if box.box_id == 'cdef'] if len(cdef_lst) > 1: msg = "Only one channel definition box is allowed in the " msg += "JP2 header." @@ -499,7 +522,6 @@ class Jp2k(Jp2kBox): cdef = jp2h.box[cdef_lst[0]] assn = cdef.association typ = cdef.channel_type - index = cdef.index if colr.colorspace == SRGB: if any([chan + 1 not in assn or typ[chan] != 0 for chan in [0, 1, 2]]): @@ -514,8 +536,8 @@ class Jp2k(Jp2kBox): with open(filename, 'wb') as ofile: for box in boxes: - if box.id != 'jp2c': - box._write(ofile) + if box.box_id != 'jp2c': + box.write(ofile) else: # The codestream gets written last. if len(self.box) == 0: @@ -529,7 +551,8 @@ class Jp2k(Jp2kBox): else: # OK, I'm a jp2 file. Need to find out where the # raw codestream actually starts. - jp2c = [box for box in self.box if box.id == 'jp2c'] + jp2c = [box for box in self.box + if box.box_id == 'jp2c'] jp2c = jp2c[0] ofile.write(struct.pack('>I', jp2c.length + 8)) ofile.write('jp2c'.encode()) @@ -544,16 +567,17 @@ class Jp2k(Jp2kBox): jp2 = Jp2k(filename) return jp2 - def read(self, reduce=0, layer=0, area=None, tile=None, verbose=False): + def read(self, **kwargs): """Read a JPEG 2000 image. Parameters ---------- + rlevel : int, optional + Factor by which to rlevel output resolution. Use -1 to get the + lowest resolution thumbnail. This is the only keyword option + available to use when only OpenJPEG version 1.5.1 is present. layer : int, optional Number of quality layer to decode. - reduce : int, optional - Factor by which to reduce output resolution. Use -1 to get the - lowest resolution thumbnail. area : tuple, optional Specifies decoding image area, (first_row, first_col, last_row, last_col) @@ -583,19 +607,169 @@ class Jp2k(Jp2kBox): Read the lowest resolution thumbnail. - >>> thumbnail = jp.read(reduce=-1) + >>> thumbnail = jp.read(rlevel=-1) >>> thumbnail.shape - (46, 81, 3) + (728, 1296, 3) + """ + if _opj2.OPENJP2 is not None: + img = self._read_openjp2(**kwargs) + else: + img = self._read_openjpeg(**kwargs) + return img + + def _read_openjpeg(self, rlevel=0, verbose=False): + """Read a JPEG 2000 image using libopenjpeg. + + Parameters + ---------- + rlevel : int, optional + Factor by which to rlevel output resolution. Use -1 to get the + lowest resolution thumbnail. + verbose : bool, optional + Print informational messages produced by the OpenJPEG library. + + Returns + ------- + img_array : ndarray + The image data. + + Raises + ------ + RuntimeError + If the image has differing subsample factors. """ # Check for differing subsample factors. codestream = self.get_codestream(header_only=True) - dxs = np.array(codestream.segment[1].XRsiz) - dys = np.array(codestream.segment[1].YRsiz) + dxs = np.array(codestream.segment[1].xrsiz) + dys = np.array(codestream.segment[1].yrsiz) + if np.any(dxs - dxs[0]) or np.any(dys - dys[0]): + msg = "Components must all have the same subsampling factors " + msg += "to use this method with OpenJPEG 1.5.1. Please consider " + msg += "using OPENJP2 instead." + raise RuntimeError(msg) + + with ExitStack() as stack: + # Set decoding parameters. + dparameters = _opj.DecompressionParametersType() + _opj.set_default_decoder_parameters(ctypes.byref(dparameters)) + dparameters.cp_reduce = rlevel + dparameters.decod_format = self._codec_format + + infile = self.filename.encode() + nelts = _opj.PATH_LEN - len(infile) + infile += b'0' * nelts + dparameters.infile = infile + + dinfo = _opj.create_decompress(dparameters.decod_format) + + event_mgr = _opj.EventMgrType() + info_handler = ctypes.cast(_INFO_CALLBACK, ctypes.c_void_p) + event_mgr.info_handler = info_handler if verbose else None + event_mgr.warning_handler = ctypes.cast(_WARNING_CALLBACK, + ctypes.c_void_p) + event_mgr.error_handler = ctypes.cast(_ERROR_CALLBACK, + ctypes.c_void_p) + _opj.set_event_mgr(dinfo, ctypes.byref(event_mgr)) + + _opj.setup_decoder(dinfo, dparameters) + + with open(self.filename, 'rb') as fptr: + src = fptr.read() + cio = _opj.cio_open(dinfo, src) + + image = _opj.decode(dinfo, cio) + + stack.callback(_opj.image_destroy, image) + stack.callback(_opj.destroy_decompress, dinfo) + stack.callback(_opj.cio_close, cio) + + ncomps = image.contents.numcomps + component = image.contents.comps[0] + if component.sgnd: + if component.prec <= 8: + dtype = np.int8 + elif component.prec <= 16: + dtype = np.int16 + else: + raise RuntimeError("Unhandled precision, datatype") + else: + if component.prec <= 8: + dtype = np.uint8 + elif component.prec <= 16: + dtype = np.uint16 + else: + raise RuntimeError("Unhandled precision, datatype") + + nrows = image.contents.comps[0].h + ncols = image.contents.comps[0].w + ncomps = image.contents.numcomps + data = np.zeros((nrows, ncols, ncomps), dtype) + + for k in range(image.contents.numcomps): + component = image.contents.comps[k] + nrows = component.h + ncols = component.w + + if nrows == 0 or ncols == 0: + # Letting this situation continue would segfault + # Python. + msg = "Component {0} has dimensions {1} x {2}" + msg = msg.format(k, nrows, ncols) + raise IOError(msg) + + addr = ctypes.addressof(component.data.contents) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + nelts = nrows * ncols + band = np.ctypeslib.as_array( + (ctypes.c_int32 * nelts).from_address(addr)) + data[:, :, k] = np.reshape(band.astype(dtype), + (nrows, ncols)) + + if data.shape[2] == 1: + data = data.view() + data.shape = data.shape[0:2] + + return data + + def _read_openjp2(self, rlevel=0, layer=0, area=None, tile=None, + verbose=False): + """Read a JPEG 2000 image using libopenjp2. + + Parameters + ---------- + layer : int, optional + Number of quality layer to decode. + rlevel : int, optional + Factor by which to rlevel output resolution. Use -1 to get the + lowest resolution thumbnail. + area : tuple, optional + Specifies decoding image area, + (first_row, first_col, last_row, last_col) + tile : int, optional + Number of tile to decode. + verbose : bool, optional + Print informational messages produced by the OpenJPEG library. + + Returns + ------- + img_array : ndarray + The image data. + + Raises + ------ + RuntimeError + If the image has differing subsample factors. + """ + # Check for differing subsample factors. + codestream = self.get_codestream(header_only=True) + dxs = np.array(codestream.segment[1].xrsiz) + dys = np.array(codestream.segment[1].yrsiz) if np.any(dxs - dxs[0]) or np.any(dys - dys[0]): msg = "Components must all have the same subsampling factors." - raise IOError(msg) + raise RuntimeError(msg) - img_array = self._read_common(reduce=reduce, + img_array = self._read_common(rlevel=rlevel, layer=layer, area=area, tile=tile, @@ -608,7 +782,7 @@ class Jp2k(Jp2kBox): return img_array - def _read_common(self, reduce=0, layer=0, area=None, tile=None, + def _read_common(self, rlevel=0, layer=0, area=None, tile=None, verbose=False, as_bands=False): """Read a JPEG 2000 image. @@ -616,8 +790,8 @@ class Jp2k(Jp2kBox): ---------- layer : int, optional Number of quality layer to decode. - reduce : int, optional - Factor by which to reduce output resolution. + rlevel : int, optional + Factor by which to rlevel output resolution. area : tuple, optional Specifies decoding image area, (first_row, first_col, last_row, last_col) @@ -633,10 +807,10 @@ class Jp2k(Jp2kBox): img_array : ndarray The individual image components or a single array. """ - dparam = opj2._set_default_decoder_parameters() + dparam = _opj2.set_default_decoder_parameters() infile = self.filename.encode() - nelts = opj2._PATH_LEN - len(infile) + nelts = _opj2.PATH_LEN - len(infile) infile += b'0' * nelts dparam.infile = infile @@ -644,12 +818,12 @@ class Jp2k(Jp2kBox): dparam.cp_layer = layer - if reduce == -1: + if rlevel == -1: # Get the lowest resolution thumbnail. codestream = self.get_codestream() - reduce = codestream.segment[2].SPcod[4] + rlevel = codestream.segment[2].spcod[4] - dparam.cp_reduce = reduce + dparam.cp_reduce = rlevel if area is not None: if area[0] < 0 or area[1] < 0: msg = "Upper left corner coordinates must be nonnegative: {0}" @@ -669,31 +843,31 @@ class Jp2k(Jp2kBox): dparam.nb_tile_to_decode = 1 with ExitStack() as stack: - stream = opj2._stream_create_default_file_stream_v3(self.filename, + stream = _opj2.stream_create_default_file_stream_v3(self.filename, True) - stack.callback(opj2._stream_destroy_v3, stream) - codec = opj2._create_decompress(self._codec_format) - stack.callback(opj2._destroy_codec, codec) + stack.callback(_opj2.stream_destroy_v3, stream) + codec = _opj2.create_decompress(self._codec_format) + stack.callback(_opj2.destroy_codec, codec) - opj2._set_error_handler(codec, _error_callback) - opj2._set_warning_handler(codec, _warning_callback) + _opj2.set_error_handler(codec, _ERROR_CALLBACK) + _opj2.set_warning_handler(codec, _WARNING_CALLBACK) if verbose: - opj2._set_info_handler(codec, _info_callback) + _opj2.set_info_handler(codec, _INFO_CALLBACK) else: - opj2._set_info_handler(codec, None) + _opj2.set_info_handler(codec, None) - opj2._setup_decoder(codec, dparam) - image = opj2._read_header(stream, codec) - stack.callback(opj2._image_destroy, image) + _opj2.setup_decoder(codec, dparam) + image = _opj2.read_header(stream, codec) + stack.callback(_opj2.image_destroy, image) if dparam.nb_tile_to_decode: - opj2._get_decoded_tile(codec, stream, image, dparam.tile_index) + _opj2.get_decoded_tile(codec, stream, image, dparam.tile_index) else: - opj2._set_decode_area(codec, image, + _opj2.set_decode_area(codec, image, dparam.DA_x0, dparam.DA_y0, dparam.DA_x1, dparam.DA_y1) - opj2._decode(codec, stream, image) - opj2._end_decompress(codec, stream) + _opj2.decode(codec, stream, image) + _opj2.end_decompress(codec, stream) component = image.contents.comps[0] if component.sgnd: @@ -734,16 +908,17 @@ class Jp2k(Jp2kBox): addr = ctypes.addressof(component.data.contents) with warnings.catch_warnings(): warnings.simplefilter("ignore") - x = np.ctypeslib.as_array( + band = np.ctypeslib.as_array( (ctypes.c_int32 * nrows * ncols).from_address(addr)) if as_bands: - data.append(np.reshape(x.astype(dtype), (nrows, ncols))) + data.append(np.reshape(band.astype(dtype), (nrows, ncols))) else: - data[:, :, k] = np.reshape(x.astype(dtype), (nrows, ncols)) + data[:, :, k] = np.reshape(band.astype(dtype), + (nrows, ncols)) return data - def read_bands(self, reduce=0, layer=0, area=None, tile=None, + def read_bands(self, rlevel=0, layer=0, area=None, tile=None, verbose=False): """Read a JPEG 2000 image. @@ -755,8 +930,8 @@ class Jp2k(Jp2kBox): ---------- layer : int, optional Number of quality layer to decode. - reduce : int, optional - Factor by which to reduce output resolution. + rlevel : int, optional + Factor by which to rlevel output resolution. area : tuple, optional Specifies decoding image area, (first_row, first_col, last_row, last_col) @@ -779,9 +954,18 @@ class Jp2k(Jp2kBox): >>> import glymur >>> jfile = glymur.data.nemo() >>> jp = glymur.Jp2k(jfile) - >>> components_lst = jp.read_bands(reduce=1) + >>> components_lst = jp.read_bands(rlevel=1) + + Raises + ------ + NotImplementedError + If the openjp2 library is not available. """ - lst = self._read_common(reduce=reduce, + if _opj2.OPENJP2 is None: + msg = "Requires openjp2 library." + raise NotImplementedError(msg) + + lst = self._read_common(rlevel=rlevel, layer=layer, area=area, tile=tile, @@ -807,14 +991,14 @@ class Jp2k(Jp2kBox): -------- >>> import glymur >>> jfile = glymur.data.nemo() - >>> jp = glymur.Jp2k(jfile) - >>> codestream = jp.get_codestream() + >>> jp2 = glymur.Jp2k(jfile) + >>> codestream = jp2.get_codestream() >>> print(codestream.segment[1]) SIZ marker segment @ (3137, 47) Profile: 2 Reference Grid Height, Width: (1456 x 2592) Vertical, Horizontal Reference Grid Offset: (0 x 0) - Reference Tile Height, Width: (512 x 512) + Reference Tile Height, Width: (1456 x 2592) Vertical, Horizontal Reference Tile Offset: (0 x 0) Bitdepth: (8, 8, 8) Signed: (False, False, False) @@ -825,20 +1009,20 @@ class Jp2k(Jp2kBox): IOError If the file is JPX with more than one codestream. """ - with open(self.filename, 'rb') as fp: - if self._codec_format == opj2._CODEC_J2K: - codestream = Codestream(fp, header_only=header_only) + with open(self.filename, 'rb') as fptr: + if self._codec_format == _opj2.CODEC_J2K: + codestream = Codestream(fptr, header_only=header_only) else: - box = [x for x in self.box if x.id == 'jp2c'] + box = [x for x in self.box if x.box_id == 'jp2c'] if len(box) != 1: msg = "JP2 files must have a single codestream." raise RuntimeError(msg) - fp.seek(box[0].offset) - buffer = fp.read(8) - (L, T) = struct.unpack('>I4s', buffer) - if L == 1: + fptr.seek(box[0].offset) + read_buffer = fptr.read(8) + (box_length, _) = struct.unpack('>I4s', read_buffer) + if box_length == 1: # Seek past the XL field. - buffer = fp.read(8) - codestream = Codestream(fp, header_only=header_only) + read_buffer = fptr.read(8) + codestream = Codestream(fptr, header_only=header_only) return codestream diff --git a/glymur/lib/__init__.py b/glymur/lib/__init__.py index ca7460c..ebd4fa7 100644 --- a/glymur/lib/__init__.py +++ b/glymur/lib/__init__.py @@ -1,3 +1,4 @@ """This package organizes individual libraries employed by glymur.""" -from . import openjp2 -from . import test +from . import openjp2 as _openjp2 +from . import openjpeg as _openjpeg +#from . import test diff --git a/glymur/lib/config.py b/glymur/lib/config.py new file mode 100644 index 0000000..fc0e4cb --- /dev/null +++ b/glymur/lib/config.py @@ -0,0 +1,153 @@ +""" +Configure glymur to use installed libraries if possible. +""" +import ctypes +from ctypes.util import find_library +import os +import platform +import warnings + +import sys +if sys.hexversion <= 0x03000000: + from ConfigParser import SafeConfigParser as ConfigParser + from ConfigParser import NoOptionError +else: + from configparser import ConfigParser + from configparser import NoOptionError + + +def glymurrc_fname(): + """Return the path to the configuration file. + + Search order: + 1) current working directory + 2) environ var XDG_CONFIG_HOME + 3) $HOME/.config/glymur/glymurrc + """ + + # Current directory. + fname = os.path.join(os.getcwd(), 'glymurrc') + if os.path.exists(fname): + return fname + + confdir = get_configdir() + if confdir is not None: + fname = os.path.join(confdir, 'glymurrc') + if os.path.exists(fname): + return fname + + # didn't find a configuration file. + return None + + +def load_openjpeg(libopenjpeg_path): + """Load the openjpeg library, falling back on defaults if necessary. + """ + if libopenjpeg_path is None: + # Let ctypes try to find it. + libopenjpeg_path = find_library('openjpeg') + + # If we could not find it, then look in some likely locations. + if libopenjpeg_path is None: + if platform.system() == 'Darwin': + path = '/opt/local/lib/libopenjpeg.dylib' + if os.path.exists(path): + libopenjpeg_path = path + elif os.name == 'nt': + path = os.path.join('C:\\', 'Program files', 'OpenJPEG 1.5', + 'bin', 'openjpeg.dll') + if os.path.exists(path): + libopenjpeg_path = path + + try: + if os.name == "nt": + openjpeg_lib = ctypes.windll.LoadLibrary(libopenjpeg_path) + else: + openjpeg_lib = ctypes.CDLL(libopenjpeg_path) + except OSError: + openjpeg_lib = None + + if openjpeg_lib is not None: + # Must be at least 1.5.0 + openjpeg_lib.opj_version.restype = ctypes.c_char_p + version = openjpeg_lib.opj_version().decode('utf-8') + _, minor, _ = version.split('.') + if minor != '5': + openjpeg_lib = None + return openjpeg_lib + + +def read_config_file(): + """ + We expect to not find openjp2 on the system path since the only version + 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 = {'openjp2': None, 'openjpeg': None} + filename = glymurrc_fname() + if filename is not None: + # Read the configuration file for the library location. + parser = ConfigParser() + parser.read(filename) + try: + lib['openjp2'] = parser.get('library', 'openjp2') + except NoOptionError: + pass + try: + lib['openjpeg'] = parser.get('library', 'openjpeg') + except NoOptionError: + pass + + return lib + + +def load_openjp2(libopenjp2_path): + """Load the openjp2 library, falling back on defaults if necessary. + """ + if libopenjp2_path is None: + # No help from the config file, try to find it ourselves. + libopenjp2_path = find_library('openjp2') + + if libopenjp2_path is None: + return None + + try: + if os.name == "nt": + openjp2_lib = ctypes.windll.LoadLibrary(libopenjp2_path) + else: + openjp2_lib = ctypes.CDLL(libopenjp2_path) + except (TypeError, OSError): + msg = '"Library {0}" could not be loaded. Operating in degraded mode.' + msg = msg.format(libopenjp2_path) + warnings.warn(msg, UserWarning) + openjp2_lib = None + + return openjp2_lib + + +def glymur_config(): + """Try to ascertain locations of openjp2, openjpeg libraries. + """ + libs = read_config_file() + libopenjp2_handle = load_openjp2(libs['openjp2']) + libopenjpeg_handle = load_openjpeg(libs['openjpeg']) + return libopenjp2_handle, libopenjpeg_handle + + +def get_configdir(): + """Return string representing the configuration directory. + + Default is $HOME/.config/glymur. You can override this with the + XDG_CONFIG_HOME environment variable. + """ + + if 'XDG_CONFIG_HOME' in os.environ: + return os.path.join(os.environ['XDG_CONFIG_HOME'], 'glymur') + + if 'HOME' in os.environ: + return os.path.join(os.environ['HOME'], '.config', 'glymur') + + if 'USERPROFILE' in os.environ: + # Windows? + return os.path.join(os.environ['USERPROFILE'], 'Application Data', + 'glymur') diff --git a/glymur/lib/openjp2.py b/glymur/lib/openjp2.py index d7578d0..be9981b 100644 --- a/glymur/lib/openjp2.py +++ b/glymur/lib/openjp2.py @@ -2,138 +2,53 @@ Wraps individual functions in openjp2 library. """ - -def _glymurrc_fname(): - """Return the path to the configuration file. - - Search order: - 1) current working directory - 2) environ var XDG_CONFIG_HOME - 3) $HOME/.config/glymur/glymurrc - """ - - # Current directory. - fname = os.path.join(os.getcwd(), 'glymurrc') - if os.path.exists(fname): - return fname - - # Either GLYMURCONFIGDIR/glymurrc or $HOME/.glymur/glymurrc - confdir = _get_configdir() - if confdir is not None: - fname = os.path.join(confdir, 'glymurrc') - if os.path.exists(fname): - return fname - else: - msg = "Configuration file '{0}' does not exist.".format(confdir) - warnings.warn(msg, UserWarning) - - # didn't find a configuration file. - return None - - -def _config(): - """Read configuration file. - - Based on matplotlib. - """ - filename = _glymurrc_fname() - if filename is not None: - # Read the configuration file for the library location. - parser = ConfigParser() - parser.read(filename) - libopenjp2_path = parser.get('library', 'openjp2') - else: - # No help from the config file, try to find it ourselves. - from ctypes.util import find_library - libopenjp2_path = find_library('openjp2') - - if libopenjp2_path is None: - return None - - try: - _OPENJP2 = ctypes.CDLL(libopenjp2_path) - except OSError: - msg = '"Library {0}" could not be loaded. Operating in degraded mode.' - msg = msg.format(libopenjp2_path) - warnings.warn(msg, UserWarning) - _OPENJP2 = None - return _OPENJP2 - - -def _get_configdir(): - """Return string representing the configuration directory. - - Default is $HOME/.config/glymur. You can override this with the - XDG_CONFIG_HOME environment variable. - """ - - if 'XDG_CONFIG_HOME' in os.environ: - return os.path.join(os.environ['XDG_CONFIG_HOME'], 'glymur') - - if 'HOME' in os.environ: - return os.path.join(os.environ['HOME'], '.config', 'glymur') +# pylint: disable=C0302,R0903 import ctypes -import os -import warnings -import sys -if sys.hexversion <= 0x03000000: - from ConfigParser import SafeConfigParser as ConfigParser - from ConfigParser import NoOptionError -else: - from configparser import ConfigParser - from configparser import NoOptionError +from .config import glymur_config +OPENJP2, OPENJPEG = glymur_config() -_OPENJP2 = _config() - -import numpy as np - -# Progression order -LRCP = 0 -RLCP = 1 -RPCL = 2 -PCRL = 3 -CPRL = 4 - - -_ERROR_MSG_LST = [] +ERROR_MSG_LST = [] # Map certain atomic OpenJPEG datatypes to the ctypes equivalents. -_bool_t = ctypes.c_int32 -_codec_t_p = ctypes.c_void_p -_prog_order_t_p = ctypes.c_int32 -_cinema_mode_t = ctypes.c_int32 -_rsiz_capabilities_t = ctypes.c_int32 -_stream_t_p = ctypes.c_void_p +BOOL_TYPE = ctypes.c_int32 +CODEC_TYPE = ctypes.c_void_p +PROG_ORDER_TYPE = ctypes.c_int32 +CINEMA_MODE_TYPE = ctypes.c_int32 +RSIZ_CAPABILITIES_TYPE = ctypes.c_int32 +STREAM_TYPE_P = ctypes.c_void_p -_PATH_LEN = 4096 -_J2K_MAXRLVLS = 33 -_J2K_MAXBANDS = (3 * _J2K_MAXRLVLS - 2) +PATH_LEN = 4096 +J2K_MAXRLVLS = 33 +J2K_MAXBANDS = (3 * J2K_MAXRLVLS - 2) -_JPWL_MAX_NO_TILESPECS = 16 +JPWL_MAX_NO_TILESPECS = 16 -_TRUE = 1 -_FALSE = 0 +TRUE = 1 +FALSE = 0 # supported color spaces -_CLRSPC_UNKNOWN = -1 -_CLRSPC_UNSPECIFIED = 0 -_CLRSPC_SRGB = 1 -_CLRSPC_GRAY = 2 -_CLRSPC_YCC = 3 -color_space_t = ctypes.c_int +CLRSPC_UNKNOWN = -1 +CLRSPC_UNSPECIFIED = 0 +CLRSPC_SRGB = 1 +CLRSPC_GRAY = 2 +CLRSPC_YCC = 3 +COLOR_SPACE_TYPE = ctypes.c_int # supported codec -_codec_format_t = ctypes.c_int -_CODEC_UNKNOWN = -1 -_CODEC_J2K = 0 -_CODEC_JPT = 1 -_CODEC_JP2 = 2 +CODEC_FORMAT_TYPE = ctypes.c_int +CODEC_UNKNOWN = -1 +CODEC_J2K = 0 +CODEC_JPT = 1 +CODEC_JP2 = 2 -class _poc_t(ctypes.Structure): - """Progression order changes.""" +class PocType(ctypes.Structure): + """Progression order changes. + + Corresponds to poc_t type in openjp2 headers. + """ # Resolution num start, Component num start, given by POC _fields_ = [ ("resno0", ctypes.c_uint32), @@ -150,8 +65,8 @@ class _poc_t(ctypes.Structure): ("precno1", ctypes.c_uint32), # Progression order enum - ("prg1", _prog_order_t_p), - ("prg", _prog_order_t_p), + ("prg1", PROG_ORDER_TYPE), + ("prg", PROG_ORDER_TYPE), # Progression order string ("progorder", ctypes.c_char * 5), @@ -195,8 +110,11 @@ class _poc_t(ctypes.Structure): ("ty0_t", ctypes.c_uint32)] -class _dparameters_t(ctypes.Structure): - """Decompression parameters""" +class DecompressionParametersType(ctypes.Structure): + """Decompression parameters. + + Corresponds to dparameters_t type in openjp2 headers. + """ _fields_ = [ # Set the number of highest resolutio levels to be discarded. The # image resolution is effectively divided by 2 to the power of @@ -216,10 +134,10 @@ class _dparameters_t(ctypes.Structure): ("cp_layer", ctypes.c_uint32), # input file name - ("infile", ctypes.c_char * _PATH_LEN), + ("infile", ctypes.c_char * PATH_LEN), # output file name - ("outfile", ctypes.c_char * _PATH_LEN), + ("outfile", ctypes.c_char * PATH_LEN), # input file format 0: PGX, 1: PxM, 2: BMP 3:TIF # output file format 0: J2K, 1: JP2, 2: JPT @@ -234,7 +152,7 @@ class _dparameters_t(ctypes.Structure): ("DA_y1", ctypes.c_uint32), # verbose mode - ("m_verbose", _bool_t), + ("m_verbose", BOOL_TYPE), # tile number of the decoded tile ("tile_index", ctypes.c_uint32), @@ -243,7 +161,7 @@ class _dparameters_t(ctypes.Structure): ("nb_tile_to_decode", ctypes.c_uint32), # activates the JPWL correction capabilities - ("jpwl_correct", _bool_t), + ("jpwl_correct", BOOL_TYPE), # activates the JPWL correction capabilities ("jpwl_exp_comps", ctypes.c_int32), @@ -255,13 +173,16 @@ class _dparameters_t(ctypes.Structure): ("flags", ctypes.c_uint32)] -class _cparameters_t(ctypes.Structure): - """Compression parameters""" +class CompressionParametersType(ctypes.Structure): + """Compression parameters. + + Corresponds to cparameters_t type in openjp2 headers. + """ _fields_ = [ # size of tile: # tile_size_on = false (not in argument) or # = true (in argument) - ("tile_size_on", _bool_t), + ("tile_size_on", BOOL_TYPE), # XTOsiz, YTOsiz ("cp_tx0", ctypes.c_int), @@ -293,7 +214,7 @@ class _cparameters_t(ctypes.Structure): ("prog_order", ctypes.c_int), # progression order changes - ("poc", _poc_t * 32), + ("poc", PocType * 32), # number of progression order changes (POC), default to 0 ("numpocs", ctypes.c_uint), @@ -333,22 +254,22 @@ class _cparameters_t(ctypes.Structure): ("res_spec", ctypes.c_int), # initial precinct width - ("prcw_init", ctypes.c_int * _J2K_MAXRLVLS), + ("prcw_init", ctypes.c_int * J2K_MAXRLVLS), # initial precinct height - ("prch_init", ctypes.c_int * _J2K_MAXRLVLS), + ("prch_init", ctypes.c_int * J2K_MAXRLVLS), # input file name - ("infile", ctypes.c_char * _PATH_LEN), + ("infile", ctypes.c_char * PATH_LEN), # output file name - ("outfile", ctypes.c_char * _PATH_LEN), + ("outfile", ctypes.c_char * PATH_LEN), # DEPRECATED. ("index_on", ctypes.c_int), # DEPRECATED. - ("index", ctypes.c_char * _PATH_LEN), + ("index", ctypes.c_char * PATH_LEN), # subimage encoding: origin image offset in x direction # subimage encoding: origin image offset in y direction @@ -367,25 +288,25 @@ class _cparameters_t(ctypes.Structure): # JPWL encoding parameters # enables writing of EPC in MH, thus activating JPWL - ("jpwl_epc_on", _bool_t), + ("jpwl_epc_on", BOOL_TYPE), # error protection method for MH (0,1,16,32,37-128) ("jpwl_hprot_mh", ctypes.c_int), # tile number of header protection specification (>=0) - ("jpwl_hprot_tph_tileno", ctypes.c_int * _JPWL_MAX_NO_TILESPECS), + ("jpwl_hprot_tph_tileno", ctypes.c_int * JPWL_MAX_NO_TILESPECS), # error protection methods for TPHs (0,1,16,32,37-128) - ("jpwl_hprot_tph", ctypes.c_int * _JPWL_MAX_NO_TILESPECS), + ("jpwl_hprot_tph", ctypes.c_int * JPWL_MAX_NO_TILESPECS), # tile number of packet protection specification (>=0) - ("jpwl_pprot_tileno", ctypes.c_int * _JPWL_MAX_NO_TILESPECS), + ("jpwl_pprot_tileno", ctypes.c_int * JPWL_MAX_NO_TILESPECS), # packet number of packet protection specification (>=0) - ("jpwl_pprot_packno", ctypes.c_int * _JPWL_MAX_NO_TILESPECS), + ("jpwl_pprot_packno", ctypes.c_int * JPWL_MAX_NO_TILESPECS), # error protection methods for packets (0,1,16,32,37-128) - ("jpwl_pprot", ctypes.c_int * _JPWL_MAX_NO_TILESPECS), + ("jpwl_pprot", ctypes.c_int * JPWL_MAX_NO_TILESPECS), # enables writing of ESD, (0=no/1/2 bytes) ("jpwl_sens_size", ctypes.c_int), @@ -400,20 +321,20 @@ class _cparameters_t(ctypes.Structure): ("jpwl_sens_mh", ctypes.c_int), # tile number of sensitivity specification (>=0) - ("jpwl_sens_tph_tileno", ctypes.c_int * _JPWL_MAX_NO_TILESPECS), + ("jpwl_sens_tph_tileno", ctypes.c_int * JPWL_MAX_NO_TILESPECS), # sensitivity methods for TPHs (-1=no,0-7) - ("jpwl_sens_tph", ctypes.c_int * _JPWL_MAX_NO_TILESPECS), + ("jpwl_sens_tph", ctypes.c_int * JPWL_MAX_NO_TILESPECS), # Digital Cinema compliance 0-not compliant, 1-compliant - ("cp_cinema", _cinema_mode_t), + ("cp_cinema", CINEMA_MODE_TYPE), # Maximum rate for each component. # If == 0, component size limitation is not considered ("max_comp_size", ctypes.c_int), # Profile name - ("cp_rsiz", _rsiz_capabilities_t), + ("cp_rsiz", RSIZ_CAPABILITIES_TYPE), # Tile part generation ("tp_on", ctypes.c_uint8), @@ -425,15 +346,18 @@ class _cparameters_t(ctypes.Structure): ("tcp_mct", ctypes.c_uint8), # Enable JPIP indexing - ("jpip_on", _bool_t), + ("jpip_on", BOOL_TYPE), # Naive implementation of MCT restricted to a single reversible array # based encoding without offset concerning all the components. ("mct_data", ctypes.c_void_p)] -class _image_comp_t(ctypes.Structure): - """defines a single image component""" +class ImageCompType(ctypes.Structure): + """Defines a single image component. + + Corresponds to image_comp_t type in openjp2 headers. + """ _fields_ = [ # XRsiz, YRsiz: horizontal, vertical separation of ith component with # respect to the reference grid @@ -468,8 +392,11 @@ class _image_comp_t(ctypes.Structure): ("data", ctypes.POINTER(ctypes.c_int32))] -class _image_t(ctypes.Structure): - """defines image data and characteristics""" +class ImageType(ctypes.Structure): + """Defines image data and characteristics. + + Corresponds to image_t type in openjp2 headers. + """ _fields_ = [ # XOsiz, YOsiz: horizontal and vertical offset from the origin of the # reference grid to the left side of the image area @@ -484,10 +411,10 @@ class _image_t(ctypes.Structure): ("numcomps", ctypes.c_uint32), # color space: should be sRGB, greyscale, or YUV - ("color_space", color_space_t), + ("color_space", COLOR_SPACE_TYPE), # image components - ("comps", ctypes.POINTER(_image_comp_t)), + ("comps", ctypes.POINTER(ImageCompType)), # restricted ICC profile buffer ("icc_profile_buf", ctypes.POINTER(ctypes.c_uint8)), @@ -496,8 +423,11 @@ class _image_t(ctypes.Structure): ("icc_profile_len", ctypes.c_uint32)] -class _image_comptparm_t(ctypes.Structure): - """component parameters structure used by image_create function""" +class ImageComptParmType(ctypes.Structure): + """Component parameters structure used by image_create function. + + Corresponds to image_comptparm_t type in openjp2 headers. + """ _fields_ = [ # XRsiz, YRsiz: horizontal, vertical separation of a sample of ith # component with respect to the reference grid @@ -522,8 +452,11 @@ class _image_comptparm_t(ctypes.Structure): ("sgnd", ctypes.c_uint32)] -class _tccp_info_t(ctypes.Structure): - """tile-component coding parameters information""" +class TccpInfo(ctypes.Structure): + """Tile-component coding parameters information. + + Corresponds to tccp_info_t type in openjp2 header file. + """ _fields_ = [ # component index ("compno", ctypes.c_uint32), @@ -550,8 +483,8 @@ class _tccp_info_t(ctypes.Structure): ("qntsty", ctypes.c_uint32), # stepsizes used for quantization - ("stepsizes_mant", ctypes.c_uint32 * _J2K_MAXBANDS), - ("stepsizes_expn", ctypes.c_uint32 * _J2K_MAXBANDS), + ("stepsizes_mant", ctypes.c_uint32 * J2K_MAXBANDS), + ("stepsizes_expn", ctypes.c_uint32 * J2K_MAXBANDS), # stepsizes used for quantization ("numgbits", ctypes.c_uint32), @@ -560,14 +493,17 @@ class _tccp_info_t(ctypes.Structure): ("roishift", ctypes.c_int32), # precinct width - ("prcw", ctypes.c_uint32 * _J2K_MAXRLVLS), + ("prcw", ctypes.c_uint32 * J2K_MAXRLVLS), # precinct width - ("prch", ctypes.c_uint32 * _J2K_MAXRLVLS)] + ("prch", ctypes.c_uint32 * J2K_MAXRLVLS)] -class _tile_info_v2_t(ctypes.Structure): - """tile coding parameters information""" +class TileInfoV2(ctypes.Structure): + """Tile coding parameters information + + Corresponds to tile_info_v2_t type in openjp2 headers. + """ _fields_ = [ # number (index) of tile ("tileno", ctypes.c_int32), @@ -576,7 +512,7 @@ class _tile_info_v2_t(ctypes.Structure): ("csty", ctypes.c_uint32), # progression order - ("prg", _prog_order_t_p), + ("prg", PROG_ORDER_TYPE), # number of layers ("numlayers", ctypes.c_uint32), @@ -585,11 +521,14 @@ class _tile_info_v2_t(ctypes.Structure): ("mct", ctypes.c_uint32), # information concerning tile component parameters - ("tccp_info", ctypes.POINTER(_tccp_info_t))] + ("tccp_info", ctypes.POINTER(TccpInfo))] -class _codestream_info_v2_t(ctypes.Structure): - """information about the codestream""" +class CodestreamInfoV2(ctypes.Structure): + """information about the codestream. + + Corresponds to codestream_info_v2_t type in openjp2 header files. + """ _fields_ = [ # tile info # tile origin in x, y (XTOsiz, YTOsiz) @@ -608,152 +547,151 @@ class _codestream_info_v2_t(ctypes.Structure): ("nbcomps", ctypes.c_uint32), # default information regarding tiles inside of image - ("m_default_tile_info", _tile_info_v2_t), + ("m_default_tile_info", TileInfoV2), # information regarding tiles inside of image - ("tile_info", ctypes.POINTER(_tile_info_v2_t))] + ("tile_info", ctypes.POINTER(TileInfoV2))] # Restrict the input and output argument types for each function used in the # API. -if _OPENJP2 is not None: - _OPENJP2.opj_create_compress.argtypes = [_codec_format_t] - _OPENJP2.opj_create_compress.restype = _codec_t_p +if OPENJP2 is not None: + OPENJP2.opj_create_compress.restype = CODEC_TYPE + OPENJP2.opj_create_compress.argtypes = [CODEC_FORMAT_TYPE] - _OPENJP2.opj_create_decompress.argtypes = [_codec_format_t] - _OPENJP2.opj_create_decompress.restype = _codec_t_p + OPENJP2.opj_create_decompress.argtypes = [CODEC_FORMAT_TYPE] + OPENJP2.opj_create_decompress.restype = CODEC_TYPE - _argtypes = [_codec_t_p, _stream_t_p, ctypes.POINTER(_image_t)] - _OPENJP2.opj_decode.argtypes = _argtypes + ARGTYPES = [CODEC_TYPE, STREAM_TYPE_P, ctypes.POINTER(ImageType)] + OPENJP2.opj_decode.argtypes = ARGTYPES - _argtypes = [_codec_t_p, ctypes.c_uint32, - ctypes.POINTER(ctypes.c_uint8), - ctypes.c_uint32, - _stream_t_p] - _OPENJP2.opj_decode_tile_data.argtypes = _argtypes + ARGTYPES = [CODEC_TYPE, ctypes.c_uint32, + ctypes.POINTER(ctypes.c_uint8), + ctypes.c_uint32, + STREAM_TYPE_P] + OPENJP2.opj_decode_tile_data.argtypes = ARGTYPES - _argtypes = [ctypes.POINTER(ctypes.POINTER(_codestream_info_v2_t))] - _OPENJP2.opj_destroy_cstr_info.argtypes = _argtypes - _OPENJP2.opj_destroy_cstr_info.restype = ctypes.c_void_p + ARGTYPES = [ctypes.POINTER(ctypes.POINTER(CodestreamInfoV2))] + OPENJP2.opj_destroy_cstr_info.argtypes = ARGTYPES + OPENJP2.opj_destroy_cstr_info.restype = ctypes.c_void_p - _argtypes = [_codec_t_p, _stream_t_p] - _OPENJP2.opj_encode.argtypes = _argtypes + ARGTYPES = [CODEC_TYPE, STREAM_TYPE_P] + OPENJP2.opj_encode.argtypes = ARGTYPES - _OPENJP2.opj_get_cstr_info.argtypes = [_codec_t_p] - _OPENJP2.opj_get_cstr_info.restype = ctypes.POINTER(_codestream_info_v2_t) + OPENJP2.opj_get_cstr_info.argtypes = [CODEC_TYPE] + OPENJP2.opj_get_cstr_info.restype = ctypes.POINTER(CodestreamInfoV2) - _argtypes = [_codec_t_p, - _stream_t_p, - ctypes.POINTER(_image_t), - ctypes.c_uint32] - _OPENJP2.opj_get_decoded_tile.argtypes = _argtypes + ARGTYPES = [CODEC_TYPE, + STREAM_TYPE_P, + ctypes.POINTER(ImageType), + ctypes.c_uint32] + OPENJP2.opj_get_decoded_tile.argtypes = ARGTYPES - _argtypes = [ctypes.c_uint32, - ctypes.POINTER(_image_comptparm_t), - color_space_t] - _OPENJP2.opj_image_create.argtypes = _argtypes - _OPENJP2.opj_image_create.restype = ctypes.POINTER(_image_t) + ARGTYPES = [ctypes.c_uint32, + ctypes.POINTER(ImageComptParmType), + COLOR_SPACE_TYPE] + OPENJP2.opj_image_create.argtypes = ARGTYPES + OPENJP2.opj_image_create.restype = ctypes.POINTER(ImageType) - _argtypes = [ctypes.c_uint32, - ctypes.POINTER(_image_comptparm_t), - color_space_t] - _OPENJP2.opj_image_tile_create.argtypes = _argtypes - _OPENJP2.opj_image_tile_create.restype = ctypes.POINTER(_image_t) + ARGTYPES = [ctypes.c_uint32, + ctypes.POINTER(ImageComptParmType), + COLOR_SPACE_TYPE] + OPENJP2.opj_image_tile_create.argtypes = ARGTYPES + OPENJP2.opj_image_tile_create.restype = ctypes.POINTER(ImageType) - _OPENJP2.opj_image_destroy.argtypes = [ctypes.POINTER(_image_t)] + OPENJP2.opj_image_destroy.argtypes = [ctypes.POINTER(ImageType)] - _argtypes = [_stream_t_p, _codec_t_p, - ctypes.POINTER(ctypes.POINTER(_image_t))] - _OPENJP2.opj_read_header.argtypes = _argtypes + ARGTYPES = [STREAM_TYPE_P, CODEC_TYPE, + ctypes.POINTER(ctypes.POINTER(ImageType))] + OPENJP2.opj_read_header.argtypes = ARGTYPES - _argtypes = [_codec_t_p, - _stream_t_p, - ctypes.POINTER(ctypes.c_uint32), - ctypes.POINTER(ctypes.c_uint32), - ctypes.POINTER(ctypes.c_int32), - ctypes.POINTER(ctypes.c_int32), - ctypes.POINTER(ctypes.c_int32), - ctypes.POINTER(ctypes.c_int32), - ctypes.POINTER(ctypes.c_uint32), - ctypes.POINTER(_bool_t)] - _OPENJP2.opj_read_tile_header.argtypes = _argtypes + ARGTYPES = [CODEC_TYPE, + STREAM_TYPE_P, + ctypes.POINTER(ctypes.c_uint32), + ctypes.POINTER(ctypes.c_uint32), + ctypes.POINTER(ctypes.c_int32), + ctypes.POINTER(ctypes.c_int32), + ctypes.POINTER(ctypes.c_int32), + ctypes.POINTER(ctypes.c_int32), + ctypes.POINTER(ctypes.c_uint32), + ctypes.POINTER(BOOL_TYPE)] + OPENJP2.opj_read_tile_header.argtypes = ARGTYPES - _argtypes = [_codec_t_p, ctypes.POINTER(_image_t), ctypes.c_int32, - ctypes.c_int32, ctypes.c_int32, ctypes.c_int32] - _OPENJP2.opj_set_decode_area.argtypes = _argtypes + ARGTYPES = [CODEC_TYPE, ctypes.POINTER(ImageType), ctypes.c_int32, + ctypes.c_int32, ctypes.c_int32, ctypes.c_int32] + OPENJP2.opj_set_decode_area.argtypes = ARGTYPES - _argtypes = [ctypes.POINTER(_cparameters_t)] - _OPENJP2.opj_set_default_encoder_parameters.argtypes = _argtypes + ARGTYPES = [ctypes.POINTER(CompressionParametersType)] + OPENJP2.opj_set_default_encoder_parameters.argtypes = ARGTYPES - _argtypes = [ctypes.POINTER(_dparameters_t)] - _OPENJP2.opj_set_default_decoder_parameters.argtypes = _argtypes + ARGTYPES = [ctypes.POINTER(DecompressionParametersType)] + OPENJP2.opj_set_default_decoder_parameters.argtypes = ARGTYPES - _argtypes = [_codec_t_p, ctypes.c_void_p, ctypes.c_void_p] - _OPENJP2.opj_set_error_handler.argtypes = _argtypes - _OPENJP2.opj_set_info_handler.argtypes = _argtypes - _OPENJP2.opj_set_warning_handler.argtypes = _argtypes + ARGTYPES = [CODEC_TYPE, ctypes.c_void_p, ctypes.c_void_p] + OPENJP2.opj_set_error_handler.argtypes = ARGTYPES + OPENJP2.opj_set_info_handler.argtypes = ARGTYPES + OPENJP2.opj_set_warning_handler.argtypes = ARGTYPES - _argtypes = [_codec_t_p, ctypes.POINTER(_dparameters_t)] - _OPENJP2.opj_setup_decoder.argtypes = _argtypes + ARGTYPES = [CODEC_TYPE, ctypes.POINTER(DecompressionParametersType)] + OPENJP2.opj_setup_decoder.argtypes = ARGTYPES - _argtypes = [_codec_t_p, - ctypes.POINTER(_cparameters_t), - ctypes.POINTER(_image_t)] - _OPENJP2.opj_setup_encoder.argtypes = _argtypes + ARGTYPES = [CODEC_TYPE, + ctypes.POINTER(CompressionParametersType), + ctypes.POINTER(ImageType)] + OPENJP2.opj_setup_encoder.argtypes = ARGTYPES - _argtypes = [ctypes.c_char_p, ctypes.c_int32] - _OPENJP2.opj_stream_create_default_file_stream_v3.argtypes = _argtypes - _OPENJP2.opj_stream_create_default_file_stream_v3.restype = _stream_t_p + ARGTYPES = [ctypes.c_char_p, ctypes.c_int32] + OPENJP2.opj_stream_create_default_file_stream_v3.argtypes = ARGTYPES + OPENJP2.opj_stream_create_default_file_stream_v3.restype = STREAM_TYPE_P - _argtypes = [_codec_t_p, ctypes.POINTER(_image_t), _stream_t_p] - _OPENJP2.opj_start_compress.argtypes = _argtypes + ARGTYPES = [CODEC_TYPE, ctypes.POINTER(ImageType), STREAM_TYPE_P] + OPENJP2.opj_start_compress.argtypes = ARGTYPES - _OPENJP2.opj_end_compress.argtypes = [_codec_t_p, _stream_t_p] - _OPENJP2.opj_end_decompress.argtypes = [_codec_t_p, _stream_t_p] + OPENJP2.opj_end_compress.argtypes = [CODEC_TYPE, STREAM_TYPE_P] + OPENJP2.opj_end_decompress.argtypes = [CODEC_TYPE, STREAM_TYPE_P] - _OPENJP2.opj_stream_destroy_v3.argtypes = [_stream_t_p] - _OPENJP2.opj_destroy_codec.argtypes = [_codec_t_p] + OPENJP2.opj_stream_destroy_v3.argtypes = [STREAM_TYPE_P] + OPENJP2.opj_destroy_codec.argtypes = [CODEC_TYPE] - _argtypes = [_codec_t_p, - ctypes.c_uint32, - ctypes.POINTER(ctypes.c_uint8), - ctypes.c_uint32, - _stream_t_p] - _OPENJP2.opj_write_tile.argtypes = _argtypes + ARGTYPES = [CODEC_TYPE, + ctypes.c_uint32, + ctypes.POINTER(ctypes.c_uint8), + ctypes.c_uint32, + STREAM_TYPE_P] + OPENJP2.opj_write_tile.argtypes = ARGTYPES -def _check_error(status): +def check_error(status): """Set a generic function as the restype attribute of all OpenJPEG - functions that return a _bool_t value. This way we do not have to check + functions that return a BOOL_TYPE value. This way we do not have to check for error status in each wrapping function and an exception will always be appropriately raised. """ - global _ERROR_MSG_LST + global ERROR_MSG_LST if status != 1: - if len(_ERROR_MSG_LST) > 0: + if len(ERROR_MSG_LST) > 0: # clear out the existing error message so that we don't pick up # a bad one next time around. - msg = '\n'.join(_ERROR_MSG_LST) - _ERROR_MSG_LST = [] + msg = '\n'.join(ERROR_MSG_LST) + ERROR_MSG_LST = [] raise IOError(msg) else: raise IOError("OpenJPEG function failure.") # These library functions all return an error status. Circumvent that and # force # them to raise an exception. -_fcns = ['opj_decode', 'opj_decode_tile_data', 'opj_end_compress', - 'opj_encode', 'opj_end_decompress', 'opj_get_decoded_tile', - 'opj_read_header', 'opj_read_tile_header', 'opj_set_decode_area', - 'opj_set_error_handler', 'opj_set_info_handler', - 'opj_set_warning_handler', - 'opj_setup_decoder', 'opj_setup_encoder', 'opj_start_compress', - 'opj_write_tile'] -if _OPENJP2 is not None: - for _fcn in _fcns: - _attr = getattr(_OPENJP2, _fcn) - setattr(_attr, 'restype', _check_error) +FCNS = ['opj_decode', 'opj_decode_tile_data', 'opj_end_compress', + 'opj_encode', 'opj_end_decompress', 'opj_get_decoded_tile', + 'opj_read_header', 'opj_read_tile_header', 'opj_set_decode_area', + 'opj_set_error_handler', 'opj_set_info_handler', + 'opj_set_warning_handler', + 'opj_setup_decoder', 'opj_setup_encoder', 'opj_start_compress', + 'opj_write_tile'] +if OPENJP2 is not None: + for fcn in FCNS: + setattr(getattr(OPENJP2, fcn), 'restype', check_error) -def _create_compress(codec_format): +def create_compress(codec_format): """Creates a J2K/JP2 compress structure. Wraps the openjp2 library function opj_create_compress. @@ -761,28 +699,28 @@ def _create_compress(codec_format): Parameters ---------- codec_format : int - Specifies codec to select. Should be one of _CODEC_J2K or _CODEC_JP2. + Specifies codec to select. Should be one of CODEC_J2K or CODEC_JP2. Returns ------- - codec : Reference to _codec_t_p instance. + codec : Reference to CODEC_TYPE instance. """ - codec = _OPENJP2.opj_create_compress(codec_format) + codec = OPENJP2.opj_create_compress(codec_format) return codec -def _decode(codec, stream, image): +def decode(codec, stream, image): """Reads an entire image. Wraps the openjp2 library function opj_decode. Parameters ---------- - codec : _codec_t_p + codec : CODEC_TYPE The JPEG2000 codec - stream : _stream_t_p + stream : STREAM_TYPE_P The stream to decode. - image : _image_t + image : ImageType Output image structure. Raises @@ -790,17 +728,17 @@ def _decode(codec, stream, image): RuntimeError If the OpenJPEG library routine opj_decode fails. """ - _OPENJP2.opj_decode(codec, stream, image) + OPENJP2.opj_decode(codec, stream, image) -def _decode_tile_data(codec, tidx, data, data_size, stream): +def decode_tile_data(codec, tidx, data, data_size, stream): """Reads tile data. Wraps the openjp2 library function opj_decode_tile_data. Parameters ---------- - codec : _codec_t_p + codec : CODEC_TYPE The JPEG2000 codec tile_index : int The index of the tile being decoded @@ -808,7 +746,7 @@ def _decode_tile_data(codec, tidx, data, data_size, stream): Holds a memory block into which data will be decoded. data_size : int The size of data in bytes - stream : _stream_t_p + stream : STREAM_TYPE_P The stream to decode. Raises @@ -817,15 +755,15 @@ def _decode_tile_data(codec, tidx, data, data_size, stream): If the OpenJPEG library routine opj_decode fails. """ datap = data.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8)) - _OPENJP2.opj_decode_tile_data(codec, - ctypes.c_uint32(tidx), - datap, - ctypes.c_uint32(data_size), - stream) + OPENJP2.opj_decode_tile_data(codec, + ctypes.c_uint32(tidx), + datap, + ctypes.c_uint32(data_size), + stream) return codec -def _create_decompress(codec_format): +def create_decompress(codec_format): """Creates a J2K/JP2 decompress structure. Wraps the openjp2 library function opj_create_decompress. @@ -833,39 +771,39 @@ def _create_decompress(codec_format): Parameters ---------- codec_format : int - Specifies codec to select. Should be one of _CODEC_J2K or _CODEC_JP2. + Specifies codec to select. Should be one of CODEC_J2K or CODEC_JP2. Returns ------- - codec : Reference to _codec_t_p instance. + codec : Reference to CODEC_TYPE instance. """ - codec = _OPENJP2.opj_create_decompress(codec_format) + codec = OPENJP2.opj_create_decompress(codec_format) return codec -def _destroy_codec(codec): +def destroy_codec(codec): """Destroy a decompressor handle. Wraps the openjp2 library function opj_destroy_codec. Parameters ---------- - codec : _codec_t_p + codec : CODEC_TYPE Decompressor handle to destroy. """ - _OPENJP2.opj_destroy_codec(codec) + OPENJP2.opj_destroy_codec(codec) -def _encode(codec, stream): +def encode(codec, stream): """Wraps openjp2 library function opj_encode. Encode an image into a JPEG 2000 codestream. Parameters ---------- - codec : _codec_t_p + codec : CODEC_TYPE The jpeg2000 codec. - stream : _stream_t_p + stream : STREAM_TYPE_P The stream to which data is written. Raises @@ -873,40 +811,40 @@ def _encode(codec, stream): RuntimeError If the OpenJPEG library routine opj_encode fails. """ - _OPENJP2.opj_encode(codec, stream) + OPENJP2.opj_encode(codec, stream) -def _get_cstr_info(codec): +def get_cstr_info(codec): """get the codestream information from the codec Wraps the openjp2 library function opj_get_cstr_info. Parameters ---------- - codec : _codec_t_p + codec : CODEC_TYPE The jpeg2000 codec. Returns ------- - cstr_info_p : _codestream_info_v2_t + cstr_info_p : CodestreamInfoV2 Reference to codestream information. """ - cstr_info_p = _OPENJP2.opj_get_cstr_info(codec) + cstr_info_p = OPENJP2.opj_get_cstr_info(codec) return cstr_info_p -def _get_decoded_tile(codec, stream, imagep, tile_index): +def get_decoded_tile(codec, stream, imagep, tile_index): """get the decoded tile from the codec Wraps the openjp2 library function opj_get_decoded_tile. Parameters ---------- - codec : _codec_t_p + codec : CODEC_TYPE The jpeg2000 codec. - stream : _stream_t_p + stream : STREAM_TYPE_P The input stream. - image : _image_t + image : ImageType Output image structure. tiler_index : int Index of the tile which will be decoded. @@ -916,32 +854,32 @@ def _get_decoded_tile(codec, stream, imagep, tile_index): RuntimeError If the OpenJPEG library routine opj_get_decoded_tile fails. """ - _OPENJP2.opj_get_decoded_tile(codec, stream, imagep, tile_index) + OPENJP2.opj_get_decoded_tile(codec, stream, imagep, tile_index) -def _destroy_cstr_info(cstr_info_p): +def destroy_cstr_info(cstr_info_p): """destroy codestream information after compression or decompression Wraps the openjp2 library function opj_destroy_cstr_info. Parameters ---------- - cstr_info_p : _codestream_info_v2_t pointer + cstr_info_p : CodestreamInfoV2 pointer Pointer to codestream info structure. """ - _OPENJP2.opj_destroy_cstr_info(ctypes.byref(cstr_info_p)) + OPENJP2.opj_destroy_cstr_info(ctypes.byref(cstr_info_p)) -def _end_compress(codec, stream): +def end_compress(codec, stream): """End of compressing the current image. Wraps the openjp2 library function opj_end_compress. Parameters ---------- - codec : _codec_t_p + codec : CODEC_TYPE Compressor handle. - stream : _stream_t_p + stream : STREAM_TYPE_P Output stream buffer. Raises @@ -949,19 +887,19 @@ def _end_compress(codec, stream): RuntimeError If the OpenJPEG library routine opj_end_compress fails. """ - _OPENJP2.opj_end_compress(codec, stream) + OPENJP2.opj_end_compress(codec, stream) -def _end_decompress(codec, stream): +def end_decompress(codec, stream): """End of decompressing the current image. Wraps the openjp2 library function opj_end_decompress. Parameters ---------- - codec : _codec_t_p + codec : CODEC_TYPE Compressor handle. - stream : _stream_t_p + stream : STREAM_TYPE_P Output stream buffer. Raises @@ -969,23 +907,23 @@ def _end_decompress(codec, stream): RuntimeError If the OpenJPEG library routine opj_end_decompress fails. """ - _OPENJP2.opj_end_decompress(codec, stream) + OPENJP2.opj_end_decompress(codec, stream) -def _image_destroy(image): +def image_destroy(image): """Deallocate any resources associated with an image. Wraps the openjp2 library function opj_image_destroy. Parameters ---------- - image : _image_t pointer + image : ImageType pointer Image resource to be disposed. """ - _OPENJP2.opj_image_destroy(image) + OPENJP2.opj_image_destroy(image) -def _image_create(comptparms, clrspc): +def image_create(comptparms, clrspc): """Creates a new image structure. Wraps the openjp2 library function opj_image_create. @@ -999,16 +937,16 @@ def _image_create(comptparms, clrspc): Returns ------- - image : _image_t - Reference to _image_t instance. + image : ImageType + Reference to ImageType instance. """ - image = _OPENJP2.opj_image_create(len(comptparms), - comptparms, - clrspc) + image = OPENJP2.opj_image_create(len(comptparms), + comptparms, + clrspc) return image -def _image_tile_create(comptparms, clrspc): +def image_tile_create(comptparms, clrspc): """Creates a new image structure. Wraps the openjp2 library function opj_image_tile_create. @@ -1022,30 +960,30 @@ def _image_tile_create(comptparms, clrspc): Returns ------- - image : _image_t - Reference to _image_t instance. + image : ImageType + Reference to ImageType instance. """ - image = _OPENJP2.opj_image_tile_create(len(comptparms), - comptparms, - clrspc) + image = OPENJP2.opj_image_tile_create(len(comptparms), + comptparms, + clrspc) return image -def _read_header(stream, codec): +def read_header(stream, codec): """Decodes an image header. Wraps the openjp2 library function opj_read_header. Parameters ---------- - stream: _stream_t_p + stream: STREAM_TYPE_P The JPEG2000 stream. codec: codec_t The JPEG2000 codec to read. Returns ------- - imagep : reference to _image_t instance + imagep : reference to ImageType instance The image structure initialized with image characteristics. Raises @@ -1053,12 +991,12 @@ def _read_header(stream, codec): RuntimeError If the OpenJPEG library routine opj_read_header fails. """ - imagep = ctypes.POINTER(_image_t)() - _OPENJP2.opj_read_header(stream, codec, ctypes.byref(imagep)) + imagep = ctypes.POINTER(ImageType)() + OPENJP2.opj_read_header(stream, codec, ctypes.byref(imagep)) return imagep -def _read_tile_header(codec, stream): +def read_tile_header(codec, stream): """Reads a tile header. Wraps the openjp2 library function opj_read_tile_header. @@ -1067,7 +1005,7 @@ def _read_tile_header(codec, stream): ---------- codec : codec_t The JPEG2000 codec to read. - stream : _stream_t_p + stream : STREAM_TYPE_P The JPEG2000 stream. Returns @@ -1092,34 +1030,34 @@ def _read_tile_header(codec, stream): """ tile_index = ctypes.c_uint32() data_size = ctypes.c_uint32() - x0 = ctypes.c_int32() - y0 = ctypes.c_int32() - x1 = ctypes.c_int32() - y1 = ctypes.c_int32() + col0 = ctypes.c_int32() + row0 = ctypes.c_int32() + col1 = ctypes.c_int32() + row1 = ctypes.c_int32() ncomps = ctypes.c_uint32() - go_on = _bool_t() - _OPENJP2.opj_read_tile_header(codec, - stream, - ctypes.byref(tile_index), - ctypes.byref(data_size), - ctypes.byref(x0), - ctypes.byref(y0), - ctypes.byref(x1), - ctypes.byref(y1), - ctypes.byref(ncomps), - ctypes.byref(go_on)) + go_on = BOOL_TYPE() + OPENJP2.opj_read_tile_header(codec, + stream, + ctypes.byref(tile_index), + ctypes.byref(data_size), + ctypes.byref(col0), + ctypes.byref(row0), + ctypes.byref(col1), + ctypes.byref(row1), + ctypes.byref(ncomps), + ctypes.byref(go_on)) go_on = bool(go_on.value) return (tile_index.value, data_size.value, - x0.value, - y0.value, - x1.value, - y1.value, + col0.value, + row0.value, + col1.value, + row1.value, ncomps.value, go_on) -def _set_decode_area(codec, image, start_x=0, start_y=0, end_x=0, end_y=0): +def set_decode_area(codec, image, start_x=0, start_y=0, end_x=0, end_y=0): """Wraps openjp2 library function opj_set_decode area. Sets the given area to be decoded. This function should be called right @@ -1127,9 +1065,9 @@ def _set_decode_area(codec, image, start_x=0, start_y=0, end_x=0, end_y=0): Parameters ---------- - codec : _codec_t_p + codec : CODEC_TYPE Codec initialized by create_decompress function. - image : _image_t pointer + image : ImageType pointer The decoded image previously set by read_header. start_x, start_y : optional, int The left and upper position of the rectangle to decode. @@ -1141,29 +1079,29 @@ def _set_decode_area(codec, image, start_x=0, start_y=0, end_x=0, end_y=0): RuntimeError If the OpenJPEG library routine opj_set_decode_area fails. """ - _OPENJP2.opj_set_decode_area(codec, image, - ctypes.c_int32(start_x), - ctypes.c_int32(start_y), - ctypes.c_int32(end_x), - ctypes.c_int32(end_y)) + OPENJP2.opj_set_decode_area(codec, image, + ctypes.c_int32(start_x), + ctypes.c_int32(start_y), + ctypes.c_int32(end_x), + ctypes.c_int32(end_y)) -def _set_default_decoder_parameters(): +def set_default_decoder_parameters(): """Wraps openjp2 library function opj_set_default_decoder_parameters. Sets decoding parameters to default values. Returns ------- - dparam : _dparameters_t + dparam : DecompressionParametersType Decompression parameters. """ - dparams = _dparameters_t() - _OPENJP2.opj_set_default_decoder_parameters(ctypes.byref(dparams)) + dparams = DecompressionParametersType() + OPENJP2.opj_set_default_decoder_parameters(ctypes.byref(dparams)) return dparams -def _set_default_encoder_parameters(): +def set_default_encoder_parameters(): """Wraps openjp2 library function opj_set_default_encoder_parameters. Sets encoding parameters to default values. That means @@ -1190,22 +1128,22 @@ def _set_default_encoder_parameters(): Returns ------- - cparameters : _cparameters_t + cparameters : CompressionParametersType Compression parameters. """ - cparams = _cparameters_t() - _OPENJP2.opj_set_default_encoder_parameters(ctypes.byref(cparams)) + cparams = CompressionParametersType() + OPENJP2.opj_set_default_encoder_parameters(ctypes.byref(cparams)) return cparams -def _set_error_handler(codec, handler, data=None): +def set_error_handler(codec, handler, data=None): """Wraps openjp2 library function opj_set_error_handler. Set the error handler use by openjpeg. Parameters ---------- - codec : _codec_t_p + codec : CODEC_TYPE Codec initialized by create_compress function. handler : python function The callback function to be used. @@ -1217,17 +1155,17 @@ def _set_error_handler(codec, handler, data=None): RuntimeError If the OpenJPEG library routine opj_set_error_handler fails. """ - _OPENJP2.opj_set_error_handler(codec, handler, data) + OPENJP2.opj_set_error_handler(codec, handler, data) -def _set_info_handler(codec, handler, data=None): +def set_info_handler(codec, handler, data=None): """Wraps openjp2 library function opj_set_info_handler. Set the info handler use by openjpeg. Parameters ---------- - codec : _codec_t_p + codec : CODEC_TYPE Codec initialized by create_compress function. handler : python function The callback function to be used. @@ -1239,17 +1177,17 @@ def _set_info_handler(codec, handler, data=None): RuntimeError If the OpenJPEG library routine opj_set_info_handler fails. """ - _OPENJP2.opj_set_info_handler(codec, handler, data) + OPENJP2.opj_set_info_handler(codec, handler, data) -def _set_warning_handler(codec, handler, data=None): +def set_warning_handler(codec, handler, data=None): """Wraps openjp2 library function opj_set_warning_handler. Set the warning handler use by openjpeg. Parameters ---------- - codec : _codec_t_p + codec : CODEC_TYPE Codec initialized by create_compress function. handler : python function The callback function to be used. @@ -1261,19 +1199,19 @@ def _set_warning_handler(codec, handler, data=None): RuntimeError If the OpenJPEG library routine opj_set_warning_handler fails. """ - _OPENJP2.opj_set_warning_handler(codec, handler, data) + OPENJP2.opj_set_warning_handler(codec, handler, data) -def _setup_decoder(codec, dparams): +def setup_decoder(codec, dparams): """Wraps openjp2 library function opj_setup_decoder. Setup the decoder with decompression parameters. Parameters ---------- - codec: _codec_t_p + codec: CODEC_TYPE Codec initialized by create_compress function. - dparams: _dparameters_t + dparams: DecompressionParametersType Decompression parameters. Raises @@ -1281,10 +1219,10 @@ def _setup_decoder(codec, dparams): RuntimeError If the OpenJPEG library routine opj_setup_decoder fails. """ - _OPENJP2.opj_setup_decoder(codec, ctypes.byref(dparams)) + OPENJP2.opj_setup_decoder(codec, ctypes.byref(dparams)) -def _setup_encoder(codec, cparams, image): +def setup_encoder(codec, cparams, image): """Wraps openjp2 library function opj_setup_encoder. Setup the encoder parameters using the current image and using user @@ -1292,11 +1230,11 @@ def _setup_encoder(codec, cparams, image): Parameters ---------- - codec : _codec_t_p + codec : CODEC_TYPE codec initialized by create_compress function - cparams : _cparameters_t + cparams : CompressionParametersType compression parameters - image : _image_t + image : ImageType input-filled image Raises @@ -1304,21 +1242,21 @@ def _setup_encoder(codec, cparams, image): RuntimeError If the OpenJPEG library routine opj_setup_encoder fails. """ - _OPENJP2.opj_setup_encoder(codec, ctypes.byref(cparams), image) + OPENJP2.opj_setup_encoder(codec, ctypes.byref(cparams), image) -def _start_compress(codec, image, stream): +def start_compress(codec, image, stream): """Wraps openjp2 library function opj_start_compress. Start to compress the current image. Parameters ---------- - codec : _codec_t_p + codec : CODEC_TYPE Compressor handle. - image : pointer to _image_t + image : pointer to ImageType Input filled image. - stream : _stream_t_p + stream : STREAM_TYPE_P Input stream. Raises @@ -1326,10 +1264,10 @@ def _start_compress(codec, image, stream): RuntimeError If the OpenJPEG library routine opj_start_compress fails. """ - _OPENJP2.opj_start_compress(codec, image, stream) + OPENJP2.opj_start_compress(codec, image, stream) -def _stream_create_default_file_stream_v3(fname, a_read_stream): +def stream_create_default_file_stream_v3(fname, a_read_stream): """Wraps openjp2 library function opj_stream_create_default_vile_stream_v3. Sets the stream to be a file stream. @@ -1346,33 +1284,34 @@ def _stream_create_default_file_stream_v3(fname, a_read_stream): stream : stream_t An OpenJPEG file stream. """ - tf = 1 if a_read_stream else 0 - fn = ctypes.c_char_p(fname.encode()) - stream = _OPENJP2.opj_stream_create_default_file_stream_v3(fn, tf) + read_stream = 1 if a_read_stream else 0 + file_argument = ctypes.c_char_p(fname.encode()) + stream = OPENJP2.opj_stream_create_default_file_stream_v3(file_argument, + read_stream) return stream -def _stream_destroy_v3(stream): +def stream_destroy_v3(stream): """Wraps openjp2 library function opj_stream_destroy. Destroys the stream created by create_stream_v3. Parameters ---------- - stream : _stream_t_p + stream : STREAM_TYPE_P The file stream. """ - _OPENJP2.opj_stream_destroy_v3(stream) + OPENJP2.opj_stream_destroy_v3(stream) -def _write_tile(codec, tile_index, data, data_size, stream): +def write_tile(codec, tile_index, data, data_size, stream): """Wraps openjp2 library function opj_write_tile. Write a tile into an image. Parameters ---------- - codec : _codec_t_p + codec : CODEC_TYPE The jpeg2000 codec tile_index : int The index of the tile to write, zero-indexing assumed @@ -1380,7 +1319,7 @@ def _write_tile(codec, tile_index, data, data_size, stream): Image data arranged in usual C-order data_size : int Size of a tile in bytes - stream : _stream_t_p + stream : STREAM_TYPE_P The stream to write data to Raises @@ -1389,14 +1328,14 @@ def _write_tile(codec, tile_index, data, data_size, stream): If the OpenJPEG library routine opj_write_tile fails. """ datap = data.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8)) - _OPENJP2.opj_write_tile(codec, - ctypes.c_uint32(int(tile_index)), - datap, - ctypes.c_uint32(int(data_size)), - stream) + OPENJP2.opj_write_tile(codec, + ctypes.c_uint32(int(tile_index)), + datap, + ctypes.c_uint32(int(data_size)), + stream) -def _set_error_message(msg): +def set_error_message(msg): """The openjpeg error handler has recorded an error message.""" - global _ERROR_MSG_LST - _ERROR_MSG_LST.append(msg) + global ERROR_MSG_LST + ERROR_MSG_LST.append(msg) diff --git a/glymur/lib/openjpeg.py b/glymur/lib/openjpeg.py new file mode 100644 index 0000000..ef16c0a --- /dev/null +++ b/glymur/lib/openjpeg.py @@ -0,0 +1,213 @@ +"""Wraps library calls to openjpeg. +""" + +# pylint: disable=R0903 + +import ctypes + +from .config import glymur_config +_, OPENJPEG = glymur_config() + +PATH_LEN = 4096 # maximum allowed size for filenames + + +class EventMgrType(ctypes.Structure): + """Message handler object. + + Corresponds to event_mgr_t type in openjpeg headers. + """ + _fields_ = [("error_handler", ctypes.c_void_p), + ("warning_handler", ctypes.c_void_p), + ("info_handler", ctypes.c_void_p)] + + +class CommonStructType(ctypes.Structure): + """Common fields between JPEG 2000 compression and decompression contextx. + """ + _fields_ = [("event_mgr", ctypes.POINTER(EventMgrType)), + ("client_data", ctypes.c_void_p), + ("is_decompressor", ctypes.c_bool), + ("codec_format", ctypes.c_int), + ("j2k_handle", ctypes.c_void_p), + ("jp2_handle", ctypes.c_void_p), + ("mj2_handle", ctypes.c_void_p)] + + +class DecompressionInfoType(ctypes.Structure): + """This is for decompression contexts. + + Corresponds to dinfo_t type in openjpeg headers. + """ + pass + + +class CioType(ctypes.Structure): + """Byte input-output stream (CIO) + + Corresponds to cio_t in openjpeg headers. + """ + _fields_ = [("cinfo", ctypes.POINTER(CommonStructType)), # codec context + # STREAM_READ or STREAM_WRITE + ("openmode", ctypes.c_int), + # pointer to start of buffer + ("buffer", ctypes.POINTER(ctypes.c_char)), + # buffer size in bytes + ("length", ctypes.c_int), + # pointer to start of stream + ("start", ctypes.c_char_p), + # pointer to end of stream + ("end", ctypes.c_char_p), + # pointer to current position + ("bp", ctypes.c_char_p)] + + +class DecompressionParametersType(ctypes.Structure): + """Decompression parameters. + + Corresponds to dparameters_t type in openjpeg headers. + """ + # cp_reduce: the number of highest resolution levels to be discarded + _fields_ = [("cp_reduce", ctypes.c_int), + # cp_layer: the maximum number of quality layers to decode + ("cp_layer", ctypes.c_int), + # infile: input file name + ("infile", ctypes.c_char * PATH_LEN), + # outfile: output file name + ("outfile", ctypes.c_char * PATH_LEN), + # decod_format: input file format 0: J2K, 1: JP2, 2: JPT + ("decod_format", ctypes.c_int), + # cod_format: output file format 0: PGX, 1: PxM, 2: BMP + ("cod_format", ctypes.c_int), + # jpwl_correct: activates the JPWL correction capabilities + ("jpwl_correct", ctypes.c_bool), + # jpwl_exp_comps: expected number of components + ("jpwl_exp_comps", ctypes.c_int), + # jpwl_max_tiles: maximum number of tiles + ("jpwl_max_tiles", ctypes.c_int), + # cp_limit_decoding: whether decoding should be done on the + # entire codestream or be limited to the main header + ("cp_limit_decoding", ctypes.c_int), + ("flags", ctypes.c_uint)] + + +class ImageCompType(ctypes.Structure): + """Defines a single image component. + + Corresponds to image_comp_t type in openjpeg. + """ + _fields_ = [("dx", ctypes.c_int), + ("dy", ctypes.c_int), + ("w", ctypes.c_int), + ("h", ctypes.c_int), + ("x0", ctypes.c_int), + ("y0", ctypes.c_int), + ("prec", ctypes.c_int), + ("bpp", ctypes.c_int), + ("sgnd", ctypes.c_int), + ("resno_decoded", ctypes.c_int), + ("factor", ctypes.c_int), + ("data", ctypes.POINTER(ctypes.c_int))] + + +class ImageType(ctypes.Structure): + """Defines image data and characteristics. + + Corresponds to image_t type in openjpeg headers. + """ + _fields_ = [("x0", ctypes.c_int), + ("y0", ctypes.c_int), + ("x1", ctypes.c_int), + ("y1", ctypes.c_int), + ("numcomps", ctypes.c_int), + ("color_space", ctypes.c_int), + ("comps", ctypes.POINTER(ImageCompType)), + ("icc_profile_buf", ctypes.c_char_p), + ("icc_profile_len", ctypes.c_int)] + + +def cio_open(cinfo, src): + """Wrapper for openjpeg library function opj_cio_open.""" + argtypes = [ctypes.POINTER(CommonStructType), ctypes.c_char_p, + ctypes.c_int] + OPENJPEG.opj_cio_open.argtypes = argtypes + OPENJPEG.opj_cio_open.restype = ctypes.POINTER(CioType) + + cio = OPENJPEG.opj_cio_open(ctypes.cast(cinfo, + ctypes.POINTER(CommonStructType)), + src, len(src)) + return cio + + +def cio_close(cio): + """Wraps openjpeg library function cio_close. + """ + OPENJPEG.opj_cio_close.argtypes = [ctypes.POINTER(CioType)] + OPENJPEG.opj_cio_close(cio) + + +def create_decompress(fmt): + """Wraps openjpeg library function opj_create_decompress. + """ + OPENJPEG.opj_create_decompress.argtypes = [ctypes.c_int] + restype = ctypes.POINTER(DecompressionInfoType) + OPENJPEG.opj_create_decompress.restype = restype + dinfo = OPENJPEG.opj_create_decompress(fmt) + return dinfo + + +def decode(dinfo, cio): + """Wrapper for opj_decode. + """ + argtypes = [ctypes.POINTER(DecompressionInfoType), ctypes.POINTER(CioType)] + OPENJPEG.opj_decode.argtypes = argtypes + OPENJPEG.opj_decode.restype = ctypes.POINTER(ImageType) + image = OPENJPEG.opj_decode(dinfo, cio) + return image + + +def destroy_decompress(dinfo): + """Wraps openjpeg library function opj_destroy_decompress.""" + argtypes = [ctypes.POINTER(DecompressionInfoType)] + OPENJPEG.opj_destroy_decompress.argtypes = argtypes + OPENJPEG.opj_destroy_decompress(dinfo) + + +def image_destroy(image): + """Wraps openjpeg library function opj_image_destroy.""" + OPENJPEG.opj_image_destroy.argtypes = [ctypes.POINTER(ImageType)] + OPENJPEG.opj_image_destroy(image) + + +def set_default_decoder_parameters(dparams_p): + """Wrapper for opj_set_default_decoder_parameters. + """ + argtypes = [ctypes.POINTER(DecompressionParametersType)] + OPENJPEG.opj_set_default_decoder_parameters.argtypes = argtypes + OPENJPEG.opj_set_default_decoder_parameters(dparams_p) + + +def set_event_mgr(dinfo, event_mgr, context=None): + """Wrapper for openjpeg library function opj_set_event_mgr. + """ + argtypes = [ctypes.POINTER(CommonStructType), + ctypes.POINTER(EventMgrType), + ctypes.c_void_p] + OPENJPEG.opj_set_event_mgr.argtypes = argtypes + OPENJPEG.opj_set_event_mgr(ctypes.cast(dinfo, + ctypes.POINTER(CommonStructType)), + event_mgr, context) + + +def setup_decoder(dinfo, dparams): + """Wrapper for openjpeg library function opj_setup_decoder.""" + argtypes = [ctypes.POINTER(DecompressionInfoType), + ctypes.POINTER(DecompressionParametersType)] + OPENJPEG.opj_setup_decoder.argtypes = argtypes + OPENJPEG.opj_setup_decoder(dinfo, dparams) + + +def version(): + """Wrapper for opj_version library routine.""" + OPENJPEG.opj_version.restype = ctypes.c_char_p + library_version = OPENJPEG.opj_version() + return library_version.decode('utf-8') diff --git a/glymur/lib/test/test_openjp2.py b/glymur/lib/test/test_openjp2.py index 90a5f08..10b0084 100644 --- a/glymur/lib/test/test_openjp2.py +++ b/glymur/lib/test/test_openjp2.py @@ -1,3 +1,4 @@ +#pylint: disable-all import doctest import os import pkg_resources @@ -12,13 +13,8 @@ import numpy as np import glymur -def load_tests(loader, tests, ignore): - if glymur.lib.openjp2._OPENJP2 is not None: - tests.addTests(doctest.DocTestSuite('glymur.lib.openjp2')) - return tests - - -@unittest.skipIf(glymur.lib.openjp2._OPENJP2 is None, +@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): @@ -29,7 +25,7 @@ class TestOpenJP2(unittest.TestCase): pass def test_set_default_encoder_parameters(self): - cparams = glymur.lib.openjp2._set_default_encoder_parameters() + cparams = glymur.lib._openjp2.set_default_encoder_parameters() self.assertEqual(cparams.res_spec, 0) self.assertEqual(cparams.cblockw_init, 64) @@ -38,7 +34,7 @@ class TestOpenJP2(unittest.TestCase): self.assertEqual(cparams.subsampling_dx, 1) self.assertEqual(cparams.subsampling_dy, 1) self.assertEqual(cparams.mode, 0) - self.assertEqual(cparams.prog_order, glymur.lib.openjp2.LRCP) + self.assertEqual(cparams.prog_order, glymur.core.LRCP) self.assertEqual(cparams.roi_shift, 0) self.assertEqual(cparams.cp_tx0, 0) self.assertEqual(cparams.cp_ty0, 0) @@ -46,7 +42,7 @@ class TestOpenJP2(unittest.TestCase): self.assertEqual(cparams.irreversible, 0) def test_set_default_decoder_parameters(self): - dparams = glymur.lib.openjp2._set_default_decoder_parameters() + dparams = glymur.lib._openjp2.set_default_decoder_parameters() self.assertEqual(dparams.DA_x0, 0) self.assertEqual(dparams.DA_y0, 0) @@ -55,34 +51,34 @@ class TestOpenJP2(unittest.TestCase): def tile_macro(self, codec, stream, imagep, tidx): # called only by j2k_random_tile_access - glymur.lib.openjp2._get_decoded_tile(codec, stream, imagep, tidx) + glymur.lib._openjp2.get_decoded_tile(codec, stream, imagep, tidx) for j in range(imagep.contents.numcomps): self.assertIsNotNone(imagep.contents.comps[j].data) def j2k_random_tile_access(self, filename, codec_format=None): # called by the test_rtaX methods - dparam = glymur.lib.openjp2._set_default_decoder_parameters() + dparam = glymur.lib._openjp2.set_default_decoder_parameters() infile = filename.encode() - nelts = glymur.lib.openjp2._PATH_LEN - len(infile) + nelts = glymur.lib._openjp2.PATH_LEN - len(infile) infile += b'0' * nelts dparam.infile = infile dparam.decod_format = codec_format - codec = glymur.lib.openjp2._create_decompress(codec_format) + codec = glymur.lib._openjp2.create_decompress(codec_format) - glymur.lib.openjp2._set_info_handler(codec, None) - glymur.lib.openjp2._set_warning_handler(codec, None) - glymur.lib.openjp2._set_error_handler(codec, None) + glymur.lib._openjp2.set_info_handler(codec, None) + glymur.lib._openjp2.set_warning_handler(codec, None) + glymur.lib._openjp2.set_error_handler(codec, None) x = (filename, True) - stream = glymur.lib.openjp2._stream_create_default_file_stream_v3(*x) + stream = glymur.lib._openjp2.stream_create_default_file_stream_v3(*x) - glymur.lib.openjp2._setup_decoder(codec, dparam) - image = glymur.lib.openjp2._read_header(stream, codec) + glymur.lib._openjp2.setup_decoder(codec, dparam) + image = glymur.lib._openjp2.read_header(stream, codec) - cstr_info = glymur.lib.openjp2._get_cstr_info(codec) + cstr_info = glymur.lib._openjp2.get_cstr_info(codec) tile_ul = 0 tile_ur = cstr_info.contents.tw - 1 @@ -94,18 +90,18 @@ class TestOpenJP2(unittest.TestCase): self.tile_macro(codec, stream, image, tile_lr) self.tile_macro(codec, stream, image, tile_ll) - glymur.lib.openjp2._destroy_cstr_info(cstr_info) + glymur.lib._openjp2.destroy_cstr_info(cstr_info) - glymur.lib.openjp2._end_decompress(codec, stream) - glymur.lib.openjp2._destroy_codec(codec) - glymur.lib.openjp2._stream_destroy_v3(stream) - glymur.lib.openjp2._image_destroy(image) + glymur.lib._openjp2.end_decompress(codec, stream) + glymur.lib._openjp2.destroy_codec(codec) + glymur.lib._openjp2.stream_destroy_v3(stream) + glymur.lib._openjp2.image_destroy(image) def tile_decoder(self, x0=None, y0=None, x1=None, y1=None, filename=None, codec_format=None): x = (filename, True) - stream = glymur.lib.openjp2._stream_create_default_file_stream_v3(*x) - dparam = glymur.lib.openjp2._set_default_decoder_parameters() + stream = glymur.lib._openjp2.stream_create_default_file_stream_v3(*x) + dparam = glymur.lib._openjp2.set_default_decoder_parameters() dparam.decod_format = codec_format @@ -115,30 +111,30 @@ class TestOpenJP2(unittest.TestCase): # do not use resolution reductions. dparam.cp_reduce = 0 - codec = glymur.lib.openjp2._create_decompress(codec_format) + codec = glymur.lib._openjp2.create_decompress(codec_format) - glymur.lib.openjp2._set_info_handler(codec, None) - glymur.lib.openjp2._set_warning_handler(codec, None) - glymur.lib.openjp2._set_error_handler(codec, None) + glymur.lib._openjp2.set_info_handler(codec, None) + glymur.lib._openjp2.set_warning_handler(codec, None) + glymur.lib._openjp2.set_error_handler(codec, None) - glymur.lib.openjp2._setup_decoder(codec, dparam) - image = glymur.lib.openjp2._read_header(stream, codec) - glymur.lib.openjp2._set_decode_area(codec, image, x0, y0, x1, y1) + glymur.lib._openjp2.setup_decoder(codec, dparam) + image = glymur.lib._openjp2.read_header(stream, codec) + glymur.lib._openjp2.set_decode_area(codec, image, x0, y0, x1, y1) data = np.zeros((1150, 2048, 3), dtype=np.uint8) while True: - rargs = glymur.lib.openjp2._read_tile_header(codec, stream) + rargs = glymur.lib._openjp2.read_tile_header(codec, stream) tidx = rargs[0] sz = rargs[1] go_on = rargs[-1] if not go_on: break - glymur.lib.openjp2._decode_tile_data(codec, tidx, data, sz, stream) + glymur.lib._openjp2.decode_tile_data(codec, tidx, data, sz, stream) - glymur.lib.openjp2._end_decompress(codec, stream) - glymur.lib.openjp2._destroy_codec(codec) - glymur.lib.openjp2._stream_destroy_v3(stream) - glymur.lib.openjp2._image_destroy(image) + glymur.lib._openjp2.end_decompress(codec, stream) + glymur.lib._openjp2.destroy_codec(codec) + glymur.lib._openjp2.stream_destroy_v3(stream) + glymur.lib._openjp2.image_destroy(image) def tile_encoder(self, num_comps=None, tile_width=None, tile_height=None, filename=None, codec=None, comp_prec=None, @@ -150,7 +146,7 @@ class TestOpenJP2(unittest.TestCase): data = np.random.random((tile_height, tile_width, num_comps)) data = (data * 255).astype(np.uint8) - l_param = glymur.lib.openjp2._set_default_encoder_parameters() + l_param = glymur.lib._openjp2.set_default_encoder_parameters() l_param.tcp_numlayers = 1 l_param.cp_fixed_quality = 1 @@ -170,9 +166,9 @@ class TestOpenJP2(unittest.TestCase): l_param.numresolution = 6 - l_param.prog_order = glymur.lib.openjp2.LRCP + l_param.prog_order = glymur.core.LRCP - l_params = (glymur.lib.openjp2._image_comptparm_t * num_comps)() + l_params = (glymur.lib._openjp2.ImageComptParmType * num_comps)() for j in range(num_comps): l_params[j].dx = 1 l_params[j].dy = 1 @@ -183,38 +179,38 @@ class TestOpenJP2(unittest.TestCase): l_params[j].x0 = 0 l_params[j].y0 = 0 - codec = glymur.lib.openjp2._create_compress(codec) + codec = glymur.lib._openjp2.create_compress(codec) - glymur.lib.openjp2._set_info_handler(codec, None) - glymur.lib.openjp2._set_warning_handler(codec, None) - glymur.lib.openjp2._set_error_handler(codec, None) + glymur.lib._openjp2.set_info_handler(codec, None) + glymur.lib._openjp2.set_warning_handler(codec, None) + glymur.lib._openjp2.set_error_handler(codec, None) - cspace = glymur.lib.openjp2._CLRSPC_SRGB - l_image = glymur.lib.openjp2._image_tile_create(l_params, cspace) + cspace = glymur.lib._openjp2.CLRSPC_SRGB + l_image = glymur.lib._openjp2.image_tile_create(l_params, cspace) l_image.contents.x0 = 0 l_image.contents.y0 = 0 l_image.contents.x1 = image_width l_image.contents.y1 = image_height - l_image.contents.color_space = glymur.lib.openjp2._CLRSPC_SRGB + l_image.contents.color_space = glymur.lib._openjp2.CLRSPC_SRGB - glymur.lib.openjp2._setup_encoder(codec, l_param, l_image) + glymur.lib._openjp2.setup_encoder(codec, l_param, l_image) x = (filename, False) - stream = glymur.lib.openjp2._stream_create_default_file_stream_v3(*x) - glymur.lib.openjp2._start_compress(codec, l_image, stream) + stream = glymur.lib._openjp2.stream_create_default_file_stream_v3(*x) + glymur.lib._openjp2.start_compress(codec, l_image, stream) for j in np.arange(num_tiles): - glymur.lib.openjp2._write_tile(codec, j, data, tile_size, stream) + glymur.lib._openjp2.write_tile(codec, j, data, tile_size, stream) - glymur.lib.openjp2._end_compress(codec, stream) - glymur.lib.openjp2._stream_destroy_v3(stream) - glymur.lib.openjp2._destroy_codec(codec) - glymur.lib.openjp2._image_destroy(l_image) + glymur.lib._openjp2.end_compress(codec, stream) + glymur.lib._openjp2.stream_destroy_v3(stream) + glymur.lib._openjp2.destroy_codec(codec) + glymur.lib._openjp2.image_destroy(l_image) def tte0_setup(self, filename): kwargs = {'filename': filename, - 'codec': glymur.lib.openjp2._CODEC_J2K, + 'codec': glymur.lib._openjp2.CODEC_J2K, 'comp_prec': 8, 'irreversible': 1, 'num_comps': 3, @@ -241,12 +237,12 @@ class TestOpenJP2(unittest.TestCase): 'x1': 1000, 'y1': 1000, 'filename': tfile.name, - 'codec_format': glymur.lib.openjp2._CODEC_J2K} + 'codec_format': glymur.lib._openjp2.CODEC_J2K} self.tile_decoder(**kwargs) def tte1_setup(self, filename): kwargs = {'filename': filename, - 'codec': glymur.lib.openjp2._CODEC_J2K, + 'codec': glymur.lib._openjp2.CODEC_J2K, 'comp_prec': 8, 'irreversible': 1, 'num_comps': 3, @@ -273,7 +269,7 @@ class TestOpenJP2(unittest.TestCase): 'x1': 128, 'y1': 128, 'filename': tfile.name, - 'codec_format': glymur.lib.openjp2._CODEC_J2K} + 'codec_format': glymur.lib._openjp2.CODEC_J2K} self.tile_decoder(**kwargs) def test_rta1(self): @@ -281,12 +277,12 @@ class TestOpenJP2(unittest.TestCase): # Runs test designated rta1 in OpenJPEG test suite. self.tte1_setup(tfile.name) - kwargs = {'codec_format': glymur.lib.openjp2._CODEC_J2K} + kwargs = {'codec_format': glymur.lib._openjp2.CODEC_J2K} self.j2k_random_tile_access(tfile.name, **kwargs) def tte2_setup(self, filename): kwargs = {'filename': filename, - 'codec': glymur.lib.openjp2._CODEC_JP2, + 'codec': glymur.lib._openjp2.CODEC_JP2, 'comp_prec': 8, 'irreversible': 1, 'num_comps': 3, @@ -312,7 +308,7 @@ class TestOpenJP2(unittest.TestCase): 'x1': 128, 'y1': 128, 'filename': tfile.name, - 'codec_format': glymur.lib.openjp2._CODEC_JP2} + 'codec_format': glymur.lib._openjp2.CODEC_JP2} self.tile_decoder(**kwargs) def test_rta2(self): @@ -320,12 +316,12 @@ class TestOpenJP2(unittest.TestCase): # Runs test designated rta2 in OpenJPEG test suite. self.tte2_setup(tfile.name) - kwargs = {'codec_format': glymur.lib.openjp2._CODEC_JP2} + kwargs = {'codec_format': glymur.lib._openjp2.CODEC_JP2} self.j2k_random_tile_access(tfile.name, **kwargs) def tte3_setup(self, filename): kwargs = {'filename': filename, - 'codec': glymur.lib.openjp2._CODEC_J2K, + 'codec': glymur.lib._openjp2.CODEC_J2K, 'comp_prec': 8, 'irreversible': 1, 'num_comps': 1, @@ -345,12 +341,12 @@ class TestOpenJP2(unittest.TestCase): with tempfile.NamedTemporaryFile(suffix=".j2k") as tfile: self.tte3_setup(tfile.name) - kwargs = {'codec_format': glymur.lib.openjp2._CODEC_J2K} + kwargs = {'codec_format': glymur.lib._openjp2.CODEC_J2K} self.j2k_random_tile_access(tfile.name, **kwargs) def tte4_setup(self, filename): kwargs = {'filename': filename, - 'codec': glymur.lib.openjp2._CODEC_J2K, + 'codec': glymur.lib._openjp2.CODEC_J2K, 'comp_prec': 8, 'irreversible': 0, 'num_comps': 1, @@ -370,12 +366,12 @@ class TestOpenJP2(unittest.TestCase): with tempfile.NamedTemporaryFile(suffix=".j2k") as tfile: self.tte4_setup(tfile.name) - kwargs = {'codec_format': glymur.lib.openjp2._CODEC_J2K} + kwargs = {'codec_format': glymur.lib._openjp2.CODEC_J2K} self.j2k_random_tile_access(tfile.name, **kwargs) def tte5_setup(self, filename): kwargs = {'filename': filename, - 'codec': glymur.lib.openjp2._CODEC_J2K, + 'codec': glymur.lib._openjp2.CODEC_J2K, 'comp_prec': 8, 'irreversible': 0, 'num_comps': 1, @@ -395,7 +391,7 @@ class TestOpenJP2(unittest.TestCase): with tempfile.NamedTemporaryFile(suffix=".j2k") as tfile: self.tte5_setup(tfile.name) - kwargs = {'codec_format': glymur.lib.openjp2._CODEC_J2K} + kwargs = {'codec_format': glymur.lib._openjp2.CODEC_J2K} self.j2k_random_tile_access(tfile.name, **kwargs) if __name__ == "__main__": diff --git a/glymur/lib/test/test_openjpeg.py b/glymur/lib/test/test_openjpeg.py new file mode 100644 index 0000000..4f2d099 --- /dev/null +++ b/glymur/lib/test/test_openjpeg.py @@ -0,0 +1,39 @@ +#pylint: disable-all +import ctypes +import unittest + +import glymur + + +@unittest.skipIf(glymur.lib._openjpeg.OPENJPEG is None, + "Missing openjpeg library.") +class TestOpenJPEG(unittest.TestCase): + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_version(self): + v = glymur.lib._openjpeg.version() + parts = v.split('.') + self.assertEqual(parts[0], '1') + self.assertEqual(parts[1], '5') + + def test_set_default_decoder_parameters(self): + # Verify that we properly set the default decode parameters. + dp = glymur.lib._openjpeg.DecompressionParametersType() + glymur.lib._openjpeg.set_default_decoder_parameters(ctypes.byref(dp)) + + self.assertEqual(dp.cp_reduce, 0) + self.assertEqual(dp.cp_layer, 0) + self.assertEqual(dp.infile, b'') + self.assertEqual(dp.outfile, b'') + self.assertEqual(dp.decod_format, -1) + self.assertEqual(dp.cod_format, -1) + self.assertEqual(dp.jpwl_correct, 0) + self.assertEqual(dp.jpwl_exp_comps, 0) + self.assertEqual(dp.jpwl_max_tiles, 0) + self.assertEqual(dp.cp_limit_decoding, 0) + self.assertEqual(dp.flags, 0) diff --git a/glymur/test/__init__.py b/glymur/test/__init__.py index aec2d72..89c7eea 100644 --- a/glymur/test/__init__.py +++ b/glymur/test/__init__.py @@ -1,9 +1,11 @@ from .test_callbacks import TestCallbacks as callbacks from .test_codestream import TestCodestream as codestream +from .test_config import TestSuite as config 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 import TestSuiteDump as suitedump from .test_opj_suite_write import TestSuiteWrite as suitew from .test_opj_suite_neg import TestSuiteNegative as suiteneg from .test_jp2box import TestJp2Boxes as box diff --git a/glymur/test/fixtures.py b/glymur/test/fixtures.py new file mode 100644 index 0000000..3babc8a --- /dev/null +++ b/glymur/test/fixtures.py @@ -0,0 +1,91 @@ +import re +import sys + +import numpy as np + + +def mse(amat, bmat): + """Mean Square Error""" + diff = amat.astype(np.double) - bmat.astype(np.double) + err = np.mean(diff**2) + return err + + +def peak_tolerance(amat, bmat): + """Peak Tolerance""" + diff = np.abs(amat.astype(np.double) - bmat.astype(np.double)) + ptol = diff.max() + return ptol + + +def read_pgx(pgx_file): + """Helper function for reading the PGX comparison files. + + Open the file in ascii mode and read the header line. + Will look something like + + PG ML + 8 128 128 + PG%[ \t]%c%c%[ \t+-]%d%[ \t]%d%[ \t]%d" + """ + header = '' + with open(pgx_file, 'rb') as fptr: + while True: + char = fptr.read(1) + if char[0] == 10 or char == '\n': + pos = fptr.tell() + break + else: + if sys.hexversion < 0x03000000: + header += char + else: + header += chr(char[0]) + + header = header.rstrip() + tokens = re.split('\s', header) + + if (tokens[1][0] == 'M') and (sys.byteorder == 'little'): + swapbytes = True + elif (tokens[1][0] == 'L') and (sys.byteorder == 'big'): + swapbytes = True + else: + swapbytes = False + + if (len(tokens) == 6): + bitdepth = int(tokens[3]) + signed = bitdepth < 0 + if signed: + bitdepth = -1 * bitdepth + nrows = int(tokens[5]) + ncols = int(tokens[4]) + else: + bitdepth = int(tokens[2]) + signed = bitdepth < 0 + if signed: + bitdepth = -1 * bitdepth + nrows = int(tokens[4]) + ncols = int(tokens[3]) + + if signed: + if bitdepth <= 8: + dtype = np.int8 + elif bitdepth <= 16: + dtype = np.int16 + else: + raise RuntimeError("unhandled bitdepth") + else: + if bitdepth <= 8: + dtype = np.uint8 + elif bitdepth <= 16: + dtype = np.uint16 + else: + raise RuntimeError("unhandled bitdepth") + + shape = [nrows, ncols] + + # Reopen the file in binary mode and seek to the start of the binary + # data + with open(pgx_file, 'rb') as fptr: + fptr.seek(pos) + data = np.fromfile(file=fptr, dtype=dtype).reshape(shape) + + return(data.byteswap(swapbytes)) diff --git a/glymur/test/test_callbacks.py b/glymur/test/test_callbacks.py index 9a1250b..bb6ea07 100644 --- a/glymur/test/test_callbacks.py +++ b/glymur/test/test_callbacks.py @@ -1,5 +1,7 @@ +#pylint: disable-all import os import pkg_resources +import re import sys import tempfile import unittest @@ -13,7 +15,7 @@ else: import glymur -@unittest.skipIf(glymur.lib.openjp2._OPENJP2 is None, +@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None, "Missing openjp2 library.") class TestCallbacks(unittest.TestCase): @@ -21,13 +23,14 @@ class TestCallbacks(unittest.TestCase): # Save sys.stdout. self.stdout = sys.stdout sys.stdout = StringIO() - self.jp2file = pkg_resources.resource_filename(glymur.__name__, - "data/nemo.jp2") + self.jp2file = glymur.data.nemo() + self.j2kfile = glymur.data.goodstuff() def tearDown(self): # 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) @@ -44,24 +47,69 @@ class TestCallbacks(unittest.TestCase): def test_info_warning_callbacks_on_read(self): # Verify that we get the expected stdio output when our internal info # callback handler is enabled. - j = glymur.Jp2k(self.jp2file) - d = j.read(reduce=3, verbose=True, area=(0, 0, 512, 1024)) + j = glymur.Jp2k(self.j2kfile) + d = j.read(rlevel=1, verbose=True, area=(0, 0, 200, 150)) actual = sys.stdout.getvalue().strip() - lines = ['[INFO] Start to read j2k main header (3135).', + lines = ['[INFO] Start to read j2k main header (0).', '[INFO] Main header has been correctly decoded.', - '[INFO] Setting decoding area to 0,0,1024,512', - '[INFO] Header of tile 0 / 17 has been read.', - '[INFO] Tile 1/18 has been decoded.', - '[INFO] Image data has been updated with tile 1.', - '[INFO] Header of tile 1 / 17 has been read.', - '[INFO] Tile 2/18 has been decoded.', - '[INFO] Image data has been updated with tile 2.', - '[INFO] Stream reached its end !'] + '[INFO] Setting decoding area to 0,0,150,200', + '[INFO] Header of tile 0 / 0 has been read.', + '[INFO] Tile 1/1 has been decoded.', + '[INFO] Image data has been updated with tile 1.'] expected = '\n'.join(lines) self.assertEqual(actual, expected) +@unittest.skipIf(glymur.lib.openjp2.OPENJPEG is None, + "Missing openjpeg library.") +class TestCallbacks15(unittest.TestCase): + """This test suite is for OpenJPEG 1.5.1 properties. + """ + + @classmethod + def setUpClass(cls): + # Monkey patch the package so as to use OPENJPEG instead of OPENJP2 + cls.openjp2 = glymur.lib.openjp2.OPENJP2 + glymur.lib.openjp2.OPENJP2 = None + + @classmethod + def tearDownClass(cls): + # Restore OPENJP2 + glymur.lib.openjp2.OPENJP2 = cls.openjp2 + + def setUp(self): + # Save sys.stdout. + self.stdout = sys.stdout + sys.stdout = StringIO() + self.jp2file = glymur.data.nemo() + self.j2kfile = glymur.data.goodstuff() + + def tearDown(self): + # Restore stdout. + sys.stdout = self.stdout + + def test_info_callbacks_on_read(self): + # Verify that we get the expected stdio output when our internal info + # callback handler is enabled. + j = glymur.Jp2k(self.j2kfile) + d = j.read(rlevel=1, verbose=True) + actual = sys.stdout.getvalue().strip() + + regex = re.compile(r"""\[INFO\]\stile\s1\sof\s1\s+ + \[INFO\]\s-\stiers-1\stook\s + [0-9]+\.[0-9]+\ss\s+ + \[INFO\]\s-\sdwt\stook\s + (-){0,1}[0-9]+\.[0-9]+\ss\s+ + \[INFO\]\s-\stile\sdecoded\sin\s + [0-9]+\.[0-9]+\ss""", + re.VERBOSE) + if sys.hexversion <= 0x03020000: + self.assertRegexpMatches(actual, regex) + else: + self.assertRegex(actual, regex) + + if __name__ == "__main__": unittest.main() diff --git a/glymur/test/test_codestream.py b/glymur/test/test_codestream.py index 4acfb79..d2e3b11 100644 --- a/glymur/test/test_codestream.py +++ b/glymur/test/test_codestream.py @@ -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. @@ -54,10 +56,11 @@ class TestCodestream(unittest.TestCase): j = Jp2k(tfile.name) c = j.get_codestream() - self.assertEqual(c.segment[2].id, '0xff6f') + self.assertEqual(c.segment[2].marker_id, '0xff6f') self.assertEqual(c.segment[2].length, 3) - self.assertEqual(c.segment[2].data, b'\x00') + 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): @@ -84,9 +87,9 @@ class TestCodestream(unittest.TestCase): j = Jp2k(tfile.name) c = j.get_codestream() - self.assertEqual(c.segment[2].id, '0xff79') + self.assertEqual(c.segment[2].marker_id, '0xff79') self.assertEqual(c.segment[2].length, 3) - self.assertEqual(c.segment[2].data, b'\x00') + self.assertEqual(c.segment[2]._data, b'\x00') if __name__ == "__main__": unittest.main() diff --git a/glymur/test/test_config.py b/glymur/test/test_config.py index 1abf02f..bcc2327 100644 --- a/glymur/test/test_config.py +++ b/glymur/test/test_config.py @@ -1,3 +1,8 @@ +"""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 import sys @@ -16,14 +21,28 @@ from glymur import Jp2k from glymur.lib import openjp2 as opj2 +@unittest.skip("Cannot work when both OPENJPEG and OPENJP2 are both present.") +@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None, + "Needs openjp2 library first before these tests make sense.") @unittest.skipIf(sys.hexversion < 0x03020000, "Uses features introduced in 3.2.") -class TestJp2k(unittest.TestCase): +class TestSuite(unittest.TestCase): + + @classmethod + def setUpClass(cls): + # Monkey patch the package so as to ignore OPENJPEG if it exists. + cls.openjpeg = glymur.lib.openjpeg._OPENJPEG + glymur.lib.openjp2._OPENJPEG = None + + @classmethod + def tearDownClass(cls): + # Restore OPENJPEG + glymur.lib.openjpeg._OPENJPEG = cls.openjpeg + def setUp(self): - self.jp2file = pkg_resources.resource_filename(glymur.__name__, - "data/nemo.jp2") imp.reload(glymur) imp.reload(glymur.lib.openjp2) + self.jp2file = glymur.data.nemo() def tearDown(self): imp.reload(glymur) @@ -37,7 +56,7 @@ class TestJp2k(unittest.TestCase): filename = os.path.join(configdir, 'glymurrc') with open(filename, 'wb') as tfile: tfile.write('[library]\n'.encode()) - libloc = glymur.lib.openjp2._OPENJP2._name + libloc = glymur.lib.openjp2.OPENJP2._name line = 'openjp2: {0}\n'.format(libloc) tfile.write(line.encode()) tfile.flush() diff --git a/glymur/test/test_icc.py b/glymur/test/test_icc.py index b989bbe..30b4dc0 100644 --- a/glymur/test/test_icc.py +++ b/glymur/test/test_icc.py @@ -1,3 +1,4 @@ +#pylint: disable-all import datetime import os import struct diff --git a/glymur/test/test_jp2box.py b/glymur/test/test_jp2box.py index e0500f5..72bb476 100644 --- a/glymur/test/test_jp2box.py +++ b/glymur/test/test_jp2box.py @@ -1,4 +1,6 @@ +#pylint: disable-all import doctest +import os import tempfile import xml.etree.cElementTree as ET import unittest @@ -13,10 +15,16 @@ 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): @classmethod @@ -55,9 +63,9 @@ class TestChannelDefinition(unittest.TestCase): j2k = Jp2k(self.j2kfile) c = j2k.get_codestream() - height = c.segment[1].Ysiz - width = c.segment[1].Xsiz - num_components = len(c.segment[1].XRsiz) + height = c.segment[1].ysiz + width = c.segment[1].xsiz + num_components = len(c.segment[1].xrsiz) self.jP = JPEG2000SignatureBox() self.ftyp = FileTypeBox() @@ -85,7 +93,7 @@ class TestChannelDefinition(unittest.TestCase): jp2 = Jp2k(tfile.name) jp2h = jp2.box[2] - boxes = [box.id for box in jp2h.box] + boxes = [box.box_id for box in jp2h.box] self.assertEqual(boxes, ['ihdr', 'colr', 'cdef']) self.assertEqual(jp2h.box[2].index, (0, 1, 2)) self.assertEqual(jp2h.box[2].channel_type, (0, 0, 0)) @@ -105,7 +113,7 @@ class TestChannelDefinition(unittest.TestCase): jp2 = Jp2k(tfile.name) jp2h = jp2.box[2] - boxes = [box.id for box in jp2h.box] + boxes = [box.box_id for box in jp2h.box] self.assertEqual(boxes, ['ihdr', 'colr', 'cdef']) self.assertEqual(jp2h.box[2].index, (0, 1, 2, 3)) self.assertEqual(jp2h.box[2].channel_type, (0, 0, 0, 1)) @@ -138,7 +146,7 @@ class TestChannelDefinition(unittest.TestCase): jp2 = Jp2k(tfile.name) jp2h = jp2.box[2] - boxes = [box.id for box in jp2h.box] + boxes = [box.box_id for box in jp2h.box] self.assertEqual(boxes, ['ihdr', 'colr', 'cdef']) self.assertEqual(jp2h.box[2].index, (0,)) self.assertEqual(jp2h.box[2].channel_type, (0,)) @@ -158,7 +166,7 @@ class TestChannelDefinition(unittest.TestCase): jp2 = Jp2k(tfile.name) jp2h = jp2.box[2] - boxes = [box.id for box in jp2h.box] + boxes = [box.box_id for box in jp2h.box] self.assertEqual(boxes, ['ihdr', 'colr', 'cdef']) self.assertEqual(jp2h.box[2].index, (0, 1)) self.assertEqual(jp2h.box[2].channel_type, (0, 1)) @@ -229,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): @@ -265,9 +274,9 @@ class TestXML(unittest.TestCase): j2k = Jp2k(self.j2kfile) c = j2k.get_codestream() - height = c.segment[1].Ysiz - width = c.segment[1].Xsiz - num_components = len(c.segment[1].XRsiz) + height = c.segment[1].ysiz + width = c.segment[1].xsiz + num_components = len(c.segment[1].xrsiz) self.jP = JPEG2000SignatureBox() self.ftyp = FileTypeBox() @@ -288,6 +297,8 @@ class TestXML(unittest.TestCase): with self.assertRaises((IOError, OSError)) as ce: xmlb = glymur.jp2box.XMLBox(filename=self.xmlfile, xml=xml_object) + @unittest.skipIf(os.name == "nt", + "Problems using NamedTemporaryFile on windows.") def test_basic_xml(self): # Should be able to write an XMLBox. j2k = Jp2k(self.j2kfile) @@ -304,10 +315,12 @@ class TestXML(unittest.TestCase): with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile: j2k.wrap(tfile.name, boxes=boxes) jp2 = Jp2k(tfile.name) - self.assertEqual(jp2.box[3].id, 'xml ') + self.assertEqual(jp2.box[3].box_id, 'xml ') self.assertEqual(ET.tostring(jp2.box[3].xml), b'0') + @unittest.skipIf(os.name == "nt", + "Problems using NamedTemporaryFile on windows.") def test_xml_from_file(self): j2k = Jp2k(self.j2kfile) @@ -319,7 +332,7 @@ class TestXML(unittest.TestCase): j2k.wrap(tfile.name, boxes=boxes) jp2 = Jp2k(tfile.name) - output_boxes = [box.id for box in jp2.box] + output_boxes = [box.box_id for box in jp2.box] self.assertEqual(output_boxes, ['jP ', 'ftyp', 'jp2h', 'xml ', 'jp2c']) @@ -338,9 +351,9 @@ class TestColourSpecificationBox(unittest.TestCase): j2k = Jp2k(self.j2kfile) c = j2k.get_codestream() - height = c.segment[1].Ysiz - width = c.segment[1].Xsiz - num_components = len(c.segment[1].XRsiz) + height = c.segment[1].ysiz + width = c.segment[1].xsiz + num_components = len(c.segment[1].xrsiz) self.jP = JPEG2000SignatureBox() self.ftyp = FileTypeBox() @@ -352,6 +365,8 @@ class TestColourSpecificationBox(unittest.TestCase): def tearDown(self): pass + @unittest.skipIf(os.name == "nt", + "Problems using NamedTemporaryFile on windows.") def test_color_specification_box_with_out_enumerated_colorspace(self): j2k = Jp2k(self.j2kfile) @@ -361,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] @@ -400,7 +416,7 @@ class TestColourSpecificationBox(unittest.TestCase): approximation=approx) -@unittest.skipIf(glymur.lib.openjp2._OPENJP2 is None, +@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None, "Missing openjp2 library.") class TestJp2Boxes(unittest.TestCase): @@ -440,37 +456,37 @@ class TestJp2Boxes(unittest.TestCase): def test_default_ContiguousCodestreamBox(self): b = ContiguousCodestreamBox() - self.assertEqual(b.id, 'jp2c') - self.assertEqual(b.main_header, []) + self.assertEqual(b.box_id, 'jp2c') + self.assertIsNone(b.main_header) def verify_wrapped_raw(self, jp2file): # Shared method by at least two tests. jp2 = Jp2k(jp2file) self.assertEqual(len(jp2.box), 4) - self.assertEqual(jp2.box[0].id, 'jP ') + self.assertEqual(jp2.box[0].box_id, 'jP ') self.assertEqual(jp2.box[0].offset, 0) self.assertEqual(jp2.box[0].length, 12) self.assertEqual(jp2.box[0].longname, 'JPEG 2000 Signature') - self.assertEqual(jp2.box[1].id, 'ftyp') + self.assertEqual(jp2.box[1].box_id, 'ftyp') self.assertEqual(jp2.box[1].offset, 12) self.assertEqual(jp2.box[1].length, 20) self.assertEqual(jp2.box[1].longname, 'File Type') - self.assertEqual(jp2.box[2].id, 'jp2h') + self.assertEqual(jp2.box[2].box_id, 'jp2h') self.assertEqual(jp2.box[2].offset, 32) self.assertEqual(jp2.box[2].length, 45) self.assertEqual(jp2.box[2].longname, 'JP2 Header') - self.assertEqual(jp2.box[3].id, 'jp2c') + self.assertEqual(jp2.box[3].box_id, 'jp2c') self.assertEqual(jp2.box[3].offset, 77) self.assertEqual(jp2.box[3].length, 115228) # jp2h super box self.assertEqual(len(jp2.box[2].box), 2) - self.assertEqual(jp2.box[2].box[0].id, 'ihdr') + self.assertEqual(jp2.box[2].box[0].box_id, 'ihdr') self.assertEqual(jp2.box[2].box[0].offset, 40) self.assertEqual(jp2.box[2].box[0].length, 22) self.assertEqual(jp2.box[2].box[0].longname, 'Image Header') @@ -483,7 +499,7 @@ class TestJp2Boxes(unittest.TestCase): self.assertEqual(jp2.box[2].box[0].colorspace_unknown, False) self.assertEqual(jp2.box[2].box[0].ip_provided, False) - self.assertEqual(jp2.box[2].box[1].id, 'colr') + self.assertEqual(jp2.box[2].box[1].box_id, 'colr') self.assertEqual(jp2.box[2].box[1].offset, 62) self.assertEqual(jp2.box[2].box[1].length, 15) self.assertEqual(jp2.box[2].box[1].longname, 'Colour Specification') @@ -492,19 +508,22 @@ 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: jp2 = j2k.wrap(tfile.name) - boxes = [box.id for box in jp2.box] + 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(), @@ -512,9 +531,9 @@ class TestJp2Boxes(unittest.TestCase): JP2HeaderBox(), ContiguousCodestreamBox()] c = j2k.get_codestream() - height = c.segment[1].Ysiz - width = c.segment[1].Xsiz - num_components = len(c.segment[1].XRsiz) + height = c.segment[1].ysiz + width = c.segment[1].xsiz + num_components = len(c.segment[1].xrsiz) boxes[2].box = [ImageHeaderBox(height=height, width=width, num_components=num_components), @@ -523,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) @@ -531,9 +551,9 @@ class TestJp2Boxes(unittest.TestCase): JP2HeaderBox(), ContiguousCodestreamBox()] c = j2k.get_codestream() - height = c.segment[1].Ysiz - width = c.segment[1].Xsiz - num_components = len(c.segment[1].XRsiz) + height = c.segment[1].ysiz + width = c.segment[1].xsiz + num_components = len(c.segment[1].xrsiz) boxes[2].box = [ColourSpecificationBox(colorspace=glymur.core.SRGB), ImageHeaderBox(height=height, width=width, @@ -542,12 +562,13 @@ 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() - height = c.segment[1].Ysiz - width = c.segment[1].Xsiz - num_components = len(c.segment[1].XRsiz) + height = c.segment[1].ysiz + width = c.segment[1].xsiz + num_components = len(c.segment[1].xrsiz) jP = JPEG2000SignatureBox() ftyp = FileTypeBox() @@ -562,12 +583,13 @@ 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() - height = c.segment[1].Ysiz - width = c.segment[1].Xsiz - num_components = len(c.segment[1].XRsiz) + height = c.segment[1].ysiz + width = c.segment[1].xsiz + num_components = len(c.segment[1].xrsiz) jP = JPEG2000SignatureBox() ftyp = FileTypeBox() @@ -582,12 +604,13 @@ 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() - height = c.segment[1].Ysiz - width = c.segment[1].Xsiz - num_components = len(c.segment[1].XRsiz) + height = c.segment[1].ysiz + width = c.segment[1].xsiz + num_components = len(c.segment[1].xrsiz) jP = JPEG2000SignatureBox() ftyp = FileTypeBox() diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index d9549c5..3c1197d 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -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 glymur.lib.openjp2._OPENJP2 is not None: + 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(glymur.lib.openjp2._OPENJP2 is None, +@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): @@ -74,10 +76,8 @@ class TestJp2k(unittest.TestCase): os.unlink(cls._bad_xml_file) def setUp(self): - self.jp2file = pkg_resources.resource_filename(glymur.__name__, - "data/nemo.jp2") - self.j2kfile = pkg_resources.resource_filename(glymur.__name__, - "data/goodstuff.j2k") + self.jp2file = glymur.data.nemo() + self.j2kfile = glymur.data.goodstuff() def tearDown(self): pass @@ -90,25 +90,37 @@ class TestJp2k(unittest.TestCase): with self.assertWarns(UserWarning) as cw: jp2k = Jp2k(self._bad_xml_file) - def test_reduce_max(self): - # Verify that reduce=-1 gets us the lowest resolution image - j = Jp2k(self.jp2file) - thumbnail1 = j.read(reduce=-1) - thumbnail2 = j.read(reduce=5) - np.testing.assert_array_equal(thumbnail1, thumbnail2) - self.assertEqual(thumbnail1.shape, (46, 81, 3)) - def test_invalid_xml_box(self): # Should be able to recover from xml box with bad xml. with warnings.catch_warnings(): warnings.simplefilter("ignore") jp2k = Jp2k(self._bad_xml_file) - self.assertEqual(jp2k.box[3].id, 'xml ') + self.assertEqual(jp2k.box[3].box_id, 'xml ') self.assertEqual(jp2k.box[3].offset, 77) 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) @@ -122,11 +134,11 @@ class TestJp2k(unittest.TestCase): # End corner must be >= start corner d = j.read(area=(10, 10, 8, 8)) - def test_reduce_too_high(self): + def test_rlevel_too_high(self): # Verify that we error out appropriately if not given a JPEG 2000 file. j = Jp2k(self.jp2file) with self.assertRaises(IOError): - d = j.read(reduce=6) + d = j.read(rlevel=6) def test_not_JPEG2000(self): # Verify that we error out appropriately if not given a JPEG 2000 file. @@ -145,15 +157,7 @@ class TestJp2k(unittest.TestCase): filename = 'this file does not actually exist on the file system.' jp2k = Jp2k(filename) - def test_nemo_tile(self): - # Issue 134, trouble reading first nemo tile. - j = Jp2k(self.jp2file) - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - tiledata = j.read(tile=0) - subsetdata = j.read(area=(0, 0, 512, 512)) - np.testing.assert_array_equal(tiledata, subsetdata) - + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") def test_write_srgb_without_mct(self): j2k = Jp2k(self.j2kfile) expdata = j2k.read() @@ -164,8 +168,9 @@ class TestJp2k(unittest.TestCase): np.testing.assert_array_equal(actdata, expdata) c = ofile.get_codestream() - self.assertEqual(c.segment[2].SPcod[3], 0) # no mct + 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) @@ -175,10 +180,11 @@ 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) - expdata = j.read(reduce=2) + expdata = j.read(rlevel=1) with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: ofile = Jp2k(tfile.name, 'wb') ofile.write(expdata, prog='CPRL') @@ -186,7 +192,7 @@ class TestJp2k(unittest.TestCase): np.testing.assert_array_equal(actdata, expdata) c = ofile.get_codestream() - self.assertEqual(c.segment[2].SPcod[0], glymur.core.CPRL) + self.assertEqual(c.segment[2].spcod[0], glymur.core.CPRL) def test_jp2_boxes(self): # Verify the boxes of a JP2 file. @@ -195,37 +201,37 @@ class TestJp2k(unittest.TestCase): # top-level boxes self.assertEqual(len(jp2k.box), 6) - self.assertEqual(jp2k.box[0].id, 'jP ') + self.assertEqual(jp2k.box[0].box_id, 'jP ') self.assertEqual(jp2k.box[0].offset, 0) self.assertEqual(jp2k.box[0].length, 12) self.assertEqual(jp2k.box[0].longname, 'JPEG 2000 Signature') - self.assertEqual(jp2k.box[1].id, 'ftyp') + self.assertEqual(jp2k.box[1].box_id, 'ftyp') self.assertEqual(jp2k.box[1].offset, 12) self.assertEqual(jp2k.box[1].length, 20) self.assertEqual(jp2k.box[1].longname, 'File Type') - self.assertEqual(jp2k.box[2].id, 'jp2h') + self.assertEqual(jp2k.box[2].box_id, 'jp2h') self.assertEqual(jp2k.box[2].offset, 32) self.assertEqual(jp2k.box[2].length, 45) self.assertEqual(jp2k.box[2].longname, 'JP2 Header') - self.assertEqual(jp2k.box[3].id, 'uuid') + self.assertEqual(jp2k.box[3].box_id, 'uuid') self.assertEqual(jp2k.box[3].offset, 77) self.assertEqual(jp2k.box[3].length, 638) - self.assertEqual(jp2k.box[4].id, 'uuid') + self.assertEqual(jp2k.box[4].box_id, 'uuid') self.assertEqual(jp2k.box[4].offset, 715) self.assertEqual(jp2k.box[4].length, 2412) - self.assertEqual(jp2k.box[5].id, 'jp2c') + self.assertEqual(jp2k.box[5].box_id, 'jp2c') self.assertEqual(jp2k.box[5].offset, 3127) - self.assertEqual(jp2k.box[5].length, 1133427) + self.assertEqual(jp2k.box[5].length, 1132296) # jp2h super box self.assertEqual(len(jp2k.box[2].box), 2) - self.assertEqual(jp2k.box[2].box[0].id, 'ihdr') + self.assertEqual(jp2k.box[2].box[0].box_id, 'ihdr') self.assertEqual(jp2k.box[2].box[0].offset, 40) self.assertEqual(jp2k.box[2].box[0].length, 22) self.assertEqual(jp2k.box[2].box[0].longname, 'Image Header') @@ -238,7 +244,7 @@ class TestJp2k(unittest.TestCase): self.assertEqual(jp2k.box[2].box[0].colorspace_unknown, False) self.assertEqual(jp2k.box[2].box[0].ip_provided, False) - self.assertEqual(jp2k.box[2].box[1].id, 'colr') + self.assertEqual(jp2k.box[2].box[1].box_id, 'colr') self.assertEqual(jp2k.box[2].box[1].offset, 62) self.assertEqual(jp2k.box[2].box[1].length, 15) self.assertEqual(jp2k.box[2].box[1].longname, 'Colour Specification') @@ -255,6 +261,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 @@ -283,10 +290,11 @@ class TestJp2k(unittest.TestCase): jp2k = Jp2k(tfile.name) - self.assertEqual(jp2k.box[5].id, 'jp2c') + self.assertEqual(jp2k.box[5].box_id, 'jp2c') 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. @@ -314,8 +322,8 @@ class TestJp2k(unittest.TestCase): # The top level boxes in each file should match. for j in range(len(baseline_jp2.box)): - self.assertEqual(new_jp2.box[j].id, - baseline_jp2.box[j].id) + self.assertEqual(new_jp2.box[j].box_id, + baseline_jp2.box[j].box_id) self.assertEqual(new_jp2.box[j].offset, baseline_jp2.box[j].offset) self.assertEqual(new_jp2.box[j].length, @@ -330,7 +338,7 @@ class TestJp2k(unittest.TestCase): # Issue 86. filename = os.path.join(data_root, 'input/conformance/p0_05.j2k') j = Jp2k(filename) - with self.assertRaises(IOError): + with self.assertRaises(RuntimeError): j.read() @unittest.skipIf(data_root is None, @@ -342,6 +350,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. @@ -355,8 +364,9 @@ class TestJp2k(unittest.TestCase): c = j.get_codestream() # Code block size is reported as XY in the codestream. - self.assertEqual(tuple(c.segment[2].SPcod[5:7]), (3, 2)) + 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: @@ -365,6 +375,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: @@ -373,6 +384,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: @@ -381,6 +393,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: @@ -389,6 +402,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') @@ -396,6 +410,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') @@ -404,6 +419,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') @@ -412,6 +428,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') @@ -423,6 +440,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') @@ -434,6 +452,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') @@ -452,6 +471,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 @@ -490,24 +510,25 @@ class TestJp2k(unittest.TestCase): jp2k = Jp2k(tfile.name) - self.assertEqual(jp2k.box[3].id, 'uinf') + self.assertEqual(jp2k.box[3].box_id, 'uinf') self.assertEqual(jp2k.box[3].offset, 77) self.assertEqual(jp2k.box[3].length, 50) - self.assertEqual(jp2k.box[3].box[0].id, 'ulst') + self.assertEqual(jp2k.box[3].box[0].box_id, 'ulst') self.assertEqual(jp2k.box[3].box[0].offset, 85) self.assertEqual(jp2k.box[3].box[0].length, 26) ulst = [] ulst.append(uuid.UUID('00000000-0000-0000-0000-000000000000')) self.assertEqual(jp2k.box[3].box[0].ulst, ulst) - self.assertEqual(jp2k.box[3].box[1].id, 'url ') + self.assertEqual(jp2k.box[3].box[1].box_id, 'url ') self.assertEqual(jp2k.box[3].box[1].offset, 111) self.assertEqual(jp2k.box[3].box[1].length, 16) self.assertEqual(jp2k.box[3].box[1].version, 0) self.assertEqual(jp2k.box[3].box[1].flag, (0, 0, 0)) - self.assertEqual(jp2k.box[3].box[1].URL, 'abcd') + 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. @@ -533,14 +554,15 @@ class TestJp2k(unittest.TestCase): jp2k = Jp2k(tfile.name) - self.assertEqual(jp2k.box[3].id, 'xml ') + self.assertEqual(jp2k.box[3].box_id, 'xml ') 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. - data = Jp2k(self.jp2file).read(reduce=3) + data = Jp2k(self.jp2file).read(rlevel=1) with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: j = Jp2k(tfile.name, 'wb') j.write(data) @@ -578,11 +600,12 @@ class TestJp2k(unittest.TestCase): tfile2.flush() jasoc = Jp2k(tfile2.name) - self.assertEqual(jasoc.box[3].id, 'asoc') - self.assertEqual(jasoc.box[3].box[0].id, 'lbl ') + self.assertEqual(jasoc.box[3].box_id, 'asoc') + self.assertEqual(jasoc.box[3].box[0].box_id, 'lbl ') self.assertEqual(jasoc.box[3].box[0].label, 'label') - self.assertEqual(jasoc.box[3].box[1].id, 'xml ') + 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. @@ -610,11 +633,11 @@ class TestJp2k(unittest.TestCase): Invalid\svalues\sfor\scomp\s=\s0\s+ :\sdx=1\sdy=0''', re.VERBOSE) if sys.hexversion < 0x03020000: - with self.assertRaisesRegexp(IOError, regexp) as ce: - d = j.read(reduce=3) + with self.assertRaisesRegexp((IOError, OSError), regexp): + d = j.read(rlevel=1) else: - with self.assertRaisesRegex(IOError, regexp) as ce: - d = j.read(reduce=3) + with self.assertRaisesRegex((IOError, OSError), regexp): + d = j.read(rlevel=1) def test_xmp_attribute(self): # Verify that we can read the XMP packet in our shipping example file. @@ -627,6 +650,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: @@ -659,5 +683,72 @@ class TestJp2k(unittest.TestCase): self.assertFalse('Make' in exif['Image'].keys()) +@unittest.skipIf(glymur.lib.openjpeg.OPENJPEG is None, + "Missing openjpeg library.") +class TestJp2k15(unittest.TestCase): + + @classmethod + def setUpClass(cls): + # Monkey patch the package so as to use OPENJPEG instead of OPENJP2 + cls.openjp2 = glymur.lib.openjp2.OPENJP2 + glymur.lib.openjp2.OPENJP2 = None + + @classmethod + def tearDownClass(cls): + # Restore OPENJP2 + glymur.lib.openjp2.OPENJP2 = cls.openjp2 + + def setUp(self): + self.jp2file = glymur.data.nemo() + self.j2kfile = glymur.data.goodstuff() + + def tearDown(self): + pass + + def test_bands(self): + """Reading individual bands is an advanced maneuver. + """ + jp2k = Jp2k(self.j2kfile) + with self.assertRaises(NotImplementedError): + jp2k.read_bands() + + def test_area(self): + """Area option not allowed for 1.5.1. + """ + j2k = Jp2k(self.j2kfile) + with self.assertRaises(TypeError): + j2k.read(area=(0, 0, 100, 100)) + + def test_tile(self): + """tile option not allowed for 1.5.1. + """ + j2k = Jp2k(self.j2kfile) + with self.assertRaises(TypeError): + j2k.read(tile=0) + + def test_layer(self): + """layer option not allowed for 1.5.1. + """ + j2k = Jp2k(self.j2kfile) + 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. + """ + j2k = Jp2k(self.jp2file) + 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. + """ + j2k = Jp2k(self.j2kfile) + j2k.read() + + if __name__ == "__main__": unittest.main() diff --git a/glymur/test/test_opj_suite.py b/glymur/test/test_opj_suite.py index 4e47971..41d4f8b 100644 --- a/glymur/test/test_opj_suite.py +++ b/glymur/test/test_opj_suite.py @@ -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 @@ -24,6 +25,8 @@ import numpy as np from glymur import Jp2k import glymur +from .fixtures import * + try: data_root = os.environ['OPJ_DATA_ROOT'] except KeyError: @@ -32,95 +35,7 @@ except: raise -def mse(A, B): - """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 - - -def peak_tolerance(A, B): - """Peak Tolerance""" - diff = np.abs(A.astype(np.double) - B.astype(np.double)) - p = diff.max() - return p - - -def read_pgx(pgx_file): - """Helper function for reading the PGX comparison files. - - Open the file in ascii mode and read the header line. - Will look something like - - PG ML + 8 128 128 - PG%[ \t]%c%c%[ \t+-]%d%[ \t]%d%[ \t]%d" - """ - header = '' - with open(pgx_file, 'rb') as fp: - while True: - x = fp.read(1) - if x[0] == 10 or x == '\n': - pos = fp.tell() - break - else: - if sys.hexversion < 0x03000000: - header += x - else: - header += chr(x[0]) - - header = header.rstrip() - n = re.split('\s', header) - - if (n[1][0] == 'M') and (sys.byteorder == 'little'): - swapbytes = True - elif (n[1][0] == 'L') and (sys.byteorder == 'big'): - swapbytes = True - else: - swapbytes = False - - if (len(n) == 6): - bitdepth = int(n[3]) - signed = bitdepth < 0 - if signed: - bitdepth = -1 * bitdepth - nrows = int(n[5]) - ncols = int(n[4]) - else: - bitdepth = int(n[2]) - signed = bitdepth < 0 - if signed: - bitdepth = -1 * bitdepth - nrows = int(n[4]) - ncols = int(n[3]) - - if signed: - if bitdepth <= 8: - dtype = np.int8 - elif bitdepth <= 16: - dtype = np.int16 - else: - raise RuntimeError("unhandled bitdepth") - else: - if bitdepth <= 8: - dtype = np.uint8 - elif bitdepth <= 16: - dtype = np.uint16 - else: - raise RuntimeError("unhandled bitdepth") - - shape = [nrows, ncols] - - # 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) - - return(data.byteswap(swapbytes)) - - -@unittest.skipIf(glymur.lib.openjp2._OPENJP2 is None, +@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None, "Missing openjp2 library.") @unittest.skipIf(data_root is None, "OPJ_DATA_ROOT environment variable not set") @@ -135,7 +50,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P0_p0_01_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_01.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_01.pgx') pgxdata = read_pgx(pgxfile) @@ -148,7 +63,7 @@ class TestSuite(unittest.TestCase): # really know what to do with it. Just ignore. warnings.simplefilter("ignore") jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_02.pgx') pgxdata = read_pgx(pgxfile) @@ -158,7 +73,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P0_p0_03_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_03.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_03r0.pgx') pgxdata = read_pgx(pgxfile) @@ -167,7 +82,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P0_p0_03_j2k_r1(self): jfile = os.path.join(data_root, 'input/conformance/p0_03.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=1) + jpdata = jp2k.read(rlevel=1) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_03r1.pgx') @@ -178,7 +93,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P0_p0_04_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=3) + jpdata = jp2k.read(rlevel=3) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_04.pgx') @@ -191,7 +106,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P0_p0_05_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_05.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read_bands(reduce=3) + jpdata = jp2k.read_bands(rlevel=3) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_05.pgx') @@ -203,7 +118,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P0_p0_06_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_06.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=3) + jpdata = jp2k.read(rlevel=3) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_06.pgx') @@ -228,7 +143,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P0_p0_08_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_08.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=5) + jpdata = jp2k.read(rlevel=5) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_08.pgx') @@ -240,7 +155,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P0_p0_09_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_09.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=2) + jpdata = jp2k.read(rlevel=2) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_09.pgx') @@ -253,7 +168,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P0_p0_10_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_10.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_10.pgx') @@ -265,7 +180,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P0_p0_11_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_11.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_11.pgx') @@ -277,7 +192,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P0_p0_12_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_12.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_12.pgx') @@ -289,7 +204,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P0_p0_13_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_13.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_13.pgx') @@ -301,7 +216,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P0_p0_14_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_14.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=2) + jpdata = jp2k.read(rlevel=2) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_14.pgx') @@ -313,7 +228,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P0_p0_15_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_15.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_15r0.pgx') @@ -324,7 +239,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P0_p0_15_j2k_r1(self): jfile = os.path.join(data_root, 'input/conformance/p0_15.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=1) + jpdata = jp2k.read(rlevel=1) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_15r1.pgx') @@ -335,7 +250,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P0_p0_16_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_16.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_16.pgx') @@ -346,7 +261,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P1_p1_01_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p1_01.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p1_01.pgx') @@ -358,7 +273,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P1_p1_02_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p1_02.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=3) + jpdata = jp2k.read(rlevel=3) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p1_02.pgx') @@ -374,7 +289,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P1_p1_03_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p1_03.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=3) + jpdata = jp2k.read(rlevel=3) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p1_03.pgx') @@ -390,7 +305,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P1_p1_04_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p1_04r0.pgx') @@ -404,7 +319,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P1_p1_04_j2k_r3(self): jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=3) + jpdata = jp2k.read(rlevel=3) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p1_04r3.pgx') @@ -418,7 +333,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P1_p1_05_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p1_05.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=4) + jpdata = jp2k.read(rlevel=4) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p1_05.pgx') @@ -433,7 +348,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P1_p1_06_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=1) + jpdata = jp2k.read(rlevel=1) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p1_06.pgx') @@ -448,7 +363,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C0P1_p1_07_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p1_07.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c0p1_07.pgx') @@ -462,7 +377,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C1P0_p0_01_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_01.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_01_0.pgx') pgxdata = read_pgx(pgxfile) @@ -476,7 +391,7 @@ class TestSuite(unittest.TestCase): # really know what to do with it. Just ignore. warnings.simplefilter("ignore") jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_02_0.pgx') pgxdata = read_pgx(pgxfile) @@ -486,7 +401,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C1P0_p0_03_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_03.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_03_0.pgx') pgxdata = read_pgx(pgxfile) @@ -496,7 +411,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C1P0_p0_04_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_04_0.pgx') pgxdata = read_pgx(pgxfile) @@ -584,7 +499,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C1P0_p0_08_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_08.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=1) + jpdata = jp2k.read(rlevel=1) pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_08_0.pgx') pgxdata = read_pgx(pgxfile) @@ -601,7 +516,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C1P0_p0_09_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_09.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_09_0.pgx') pgxdata = read_pgx(pgxfile) @@ -610,7 +525,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C1P0_p0_10_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_10.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_10_0.pgx') pgxdata = read_pgx(pgxfile) @@ -627,7 +542,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C1P0_p0_11_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_11.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_11_0.pgx') pgxdata = read_pgx(pgxfile) @@ -637,7 +552,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C1P0_p0_12_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_12.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_12_0.pgx') pgxdata = read_pgx(pgxfile) @@ -647,7 +562,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C1P0_p0_13_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_13.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_13_0.pgx') pgxdata = read_pgx(pgxfile) @@ -668,7 +583,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C1P0_p0_14_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_14.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_14_0.pgx') pgxdata = read_pgx(pgxfile) @@ -685,7 +600,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C1P0_p0_15_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_15.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_15_0.pgx') pgxdata = read_pgx(pgxfile) @@ -694,7 +609,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C1P0_p0_16_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p0_16.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_16_0.pgx') pgxdata = read_pgx(pgxfile) @@ -703,7 +618,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C1P1_p1_01_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p1_01.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_01_0.pgx') pgxdata = read_pgx(pgxfile) @@ -712,7 +627,7 @@ class TestSuite(unittest.TestCase): def test_ETS_C1P1_p1_02_j2k(self): jfile = os.path.join(data_root, 'input/conformance/p1_02.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(reduce=0) + jpdata = jp2k.read(rlevel=0) pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_02_0.pgx') pgxdata = read_pgx(pgxfile) @@ -1155,7 +1070,7 @@ class TestSuite(unittest.TestCase): def test_NR_DEC_file_409752_jp2_40_decode(self): jfile = os.path.join(data_root, 'input/nonregression/file409752.jp2') - with self.assertRaises(IOError): + with self.assertRaises(RuntimeError): data = Jp2k(jfile).read() @unittest.skipIf(sys.hexversion < 0x03020000, @@ -1226,51 +1141,51 @@ class TestSuite(unittest.TestCase): def test_NR_DEC_p1_04_j2k_50_decode(self): jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(0, 0, 1024, 1024), reduce=2) - odata = jp2k.read(reduce=2) + ssdata = jp2k.read(area=(0, 0, 1024, 1024), rlevel=2) + odata = jp2k.read(rlevel=2) np.testing.assert_array_equal(ssdata, odata[0:256, 0:256]) def test_NR_DEC_p1_04_j2k_51_decode(self): jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(640, 512, 768, 640), reduce=2) - odata = jp2k.read(reduce=2) + ssdata = jp2k.read(area=(640, 512, 768, 640), rlevel=2) + odata = jp2k.read(rlevel=2) np.testing.assert_array_equal(ssdata, odata[160:192, 128:160]) def test_NR_DEC_p1_04_j2k_52_decode(self): jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(896, 896, 1024, 1024), reduce=2) - odata = jp2k.read(reduce=2) + ssdata = jp2k.read(area=(896, 896, 1024, 1024), rlevel=2) + odata = jp2k.read(rlevel=2) np.testing.assert_array_equal(ssdata, odata[224:352, 224:352]) def test_NR_DEC_p1_04_j2k_53_decode(self): jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(500, 100, 800, 300), reduce=2) - odata = jp2k.read(reduce=2) + ssdata = jp2k.read(area=(500, 100, 800, 300), rlevel=2) + odata = jp2k.read(rlevel=2) np.testing.assert_array_equal(ssdata, odata[125:200, 25:75]) def test_NR_DEC_p1_04_j2k_54_decode(self): jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(520, 260, 600, 360), reduce=2) - odata = jp2k.read(reduce=2) + ssdata = jp2k.read(area=(520, 260, 600, 360), rlevel=2) + odata = jp2k.read(rlevel=2) np.testing.assert_array_equal(ssdata, odata[130:150, 65:90]) def test_NR_DEC_p1_04_j2k_55_decode(self): jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(520, 260, 660, 360), reduce=2) - odata = jp2k.read(reduce=2) + ssdata = jp2k.read(area=(520, 260, 660, 360), rlevel=2) + odata = jp2k.read(rlevel=2) np.testing.assert_array_equal(ssdata, odata[130:165, 65:90]) def test_NR_DEC_p1_04_j2k_56_decode(self): jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(520, 360, 600, 400), reduce=2) - odata = jp2k.read(reduce=2) + ssdata = jp2k.read(area=(520, 360, 600, 400), rlevel=2) + odata = jp2k.read(rlevel=2) np.testing.assert_array_equal(ssdata, odata[130:150, 90:100]) def test_NR_DEC_p1_04_j2k_57_decode(self): @@ -1287,8 +1202,8 @@ class TestSuite(unittest.TestCase): jp2k = Jp2k(jfile) with warnings.catch_warnings(): warnings.simplefilter("ignore") - tdata = jp2k.read(tile=63, reduce=2) # last tile - odata = jp2k.read(reduce=2) + tdata = jp2k.read(tile=63, rlevel=2) # last tile + odata = jp2k.read(rlevel=2) np.testing.assert_array_equal(tdata, odata[224:256, 224:256]) def test_NR_DEC_p1_04_j2k_59_decode(self): @@ -1305,8 +1220,8 @@ class TestSuite(unittest.TestCase): jp2k = Jp2k(jfile) with warnings.catch_warnings(): warnings.simplefilter("ignore") - tdata = jp2k.read(tile=12, reduce=1) # 2nd row, 5th column - odata = jp2k.read(reduce=1) + tdata = jp2k.read(tile=12, rlevel=1) # 2nd row, 5th column + odata = jp2k.read(rlevel=1) np.testing.assert_array_equal(tdata, odata[64:128, 256:320]) @unittest.skip("fprintf stderr output in r2343.") @@ -1369,45 +1284,45 @@ class TestSuite(unittest.TestCase): def test_NR_DEC_p1_06_j2k_68_decode(self): jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(0, 0, 12, 12), reduce=1) - odata = jp2k.read(reduce=1) + ssdata = jp2k.read(area=(0, 0, 12, 12), rlevel=1) + odata = jp2k.read(rlevel=1) np.testing.assert_array_equal(ssdata, odata[0:6, 0:6]) @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_69_decode(self): jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(1, 8, 8, 11), reduce=1) + ssdata = jp2k.read(area=(1, 8, 8, 11), rlevel=1) self.assertEqual(ssdata.shape, (3, 2, 3)) def test_NR_DEC_p1_06_j2k_70_decode(self): jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(9, 9, 12, 12), reduce=1) + ssdata = jp2k.read(area=(9, 9, 12, 12), rlevel=1) self.assertEqual(ssdata.shape, (1, 1, 3)) def test_NR_DEC_p1_06_j2k_71_decode(self): jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(10, 4, 12, 10), reduce=1) + ssdata = jp2k.read(area=(10, 4, 12, 10), rlevel=1) self.assertEqual(ssdata.shape, (1, 3, 3)) def test_NR_DEC_p1_06_j2k_72_decode(self): jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(3, 3, 9, 9), reduce=1) + ssdata = jp2k.read(area=(3, 3, 9, 9), rlevel=1) self.assertEqual(ssdata.shape, (3, 3, 3)) def test_NR_DEC_p1_06_j2k_73_decode(self): jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(4, 4, 7, 7), reduce=1) + ssdata = jp2k.read(area=(4, 4, 7, 7), rlevel=1) self.assertEqual(ssdata.shape, (2, 2, 3)) def test_NR_DEC_p1_06_j2k_74_decode(self): jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(4, 4, 5, 5), reduce=1) + ssdata = jp2k.read(area=(4, 4, 5, 5), rlevel=1) self.assertEqual(ssdata.shape, (1, 1, 3)) def test_NR_DEC_p1_06_j2k_75_decode(self): @@ -1415,7 +1330,7 @@ class TestSuite(unittest.TestCase): jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) with self.assertRaises((IOError, OSError)) as ce: - ssdata = jp2k.read(area=(9, 9, 12, 12), reduce=2) + ssdata = jp2k.read(area=(9, 9, 12, 12), rlevel=2) @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_76_decode(self): @@ -1464,7 +1379,7 @@ class TestSuite(unittest.TestCase): jp2k = Jp2k(jfile) with warnings.catch_warnings(): warnings.simplefilter("ignore") - tiledata = jp2k.read(tile=0, reduce=2) + tiledata = jp2k.read(tile=0, rlevel=2) @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_81_decode(self): @@ -1473,7 +1388,7 @@ class TestSuite(unittest.TestCase): jp2k = Jp2k(jfile) with warnings.catch_warnings(): warnings.simplefilter("ignore") - tiledata = jp2k.read(tile=5, reduce=2) + tiledata = jp2k.read(tile=5, rlevel=2) @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_82_decode(self): @@ -1482,7 +1397,7 @@ class TestSuite(unittest.TestCase): jp2k = Jp2k(jfile) with warnings.catch_warnings(): warnings.simplefilter("ignore") - tiledata = jp2k.read(tile=9, reduce=2) + tiledata = jp2k.read(tile=9, rlevel=2) @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_83_decode(self): @@ -1492,14 +1407,14 @@ class TestSuite(unittest.TestCase): with warnings.catch_warnings(): warnings.simplefilter("ignore") with self.assertRaises((IOError, OSError)) as ce: - tiledata = jp2k.read(tile=15, reduce=2) + tiledata = jp2k.read(tile=15, rlevel=2) @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_84_decode(self): # Just read the data, don't bother verifying. jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) - data = jp2k.read(reduce=4) + data = jp2k.read(rlevel=4) def test_NR_DEC_p0_04_j2k_85_decode(self): jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') @@ -1546,43 +1461,43 @@ class TestSuite(unittest.TestCase): def test_NR_DEC_p0_04_j2k_91_decode(self): jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(0, 0, 256, 256), reduce=2) - fulldata = jp2k.read(reduce=2) + ssdata = jp2k.read(area=(0, 0, 256, 256), rlevel=2) + fulldata = jp2k.read(rlevel=2) np.testing.assert_array_equal(fulldata[0:64, 0:64], ssdata) def test_NR_DEC_p0_04_j2k_92_decode(self): jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(0, 128, 128, 256), reduce=2) - fulldata = jp2k.read(reduce=2) + ssdata = jp2k.read(area=(0, 128, 128, 256), rlevel=2) + fulldata = jp2k.read(rlevel=2) np.testing.assert_array_equal(fulldata[0:32, 32:64], ssdata) def test_NR_DEC_p0_04_j2k_93_decode(self): jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(10, 50, 200, 120), reduce=2) - fulldata = jp2k.read(reduce=2) + ssdata = jp2k.read(area=(10, 50, 200, 120), rlevel=2) + fulldata = jp2k.read(rlevel=2) np.testing.assert_array_equal(fulldata[3:50, 13:30], ssdata) def test_NR_DEC_p0_04_j2k_94_decode(self): jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(150, 10, 210, 190), reduce=2) - fulldata = jp2k.read(reduce=2) + ssdata = jp2k.read(area=(150, 10, 210, 190), rlevel=2) + fulldata = jp2k.read(rlevel=2) np.testing.assert_array_equal(fulldata[38:53, 3:48], ssdata) def test_NR_DEC_p0_04_j2k_95_decode(self): jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(80, 100, 150, 200), reduce=2) - fulldata = jp2k.read(reduce=2) + ssdata = jp2k.read(area=(80, 100, 150, 200), rlevel=2) + fulldata = jp2k.read(rlevel=2) np.testing.assert_array_equal(fulldata[20:38, 25:50], ssdata) def test_NR_DEC_p0_04_j2k_96_decode(self): jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(20, 150, 50, 200), reduce=2) - fulldata = jp2k.read(reduce=2) + ssdata = jp2k.read(area=(20, 150, 50, 200), rlevel=2) + fulldata = jp2k.read(rlevel=2) np.testing.assert_array_equal(fulldata[5:13, 38:50], ssdata) @@ -1601,67 +1516,67 @@ class TestSuiteDump(unittest.TestCase): c = Jp2k(jfile).get_codestream(header_only=False) # Segment IDs. - actual = [x.id for x in c.segment] + actual = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'QCD', 'COD', 'SOT', 'SOD', 'EOC'] self.assertEqual(actual, expected) # SIZ: Image and tile size # Profile: "1" means profile 0 - self.assertEqual(c.segment[1].Rsiz, 1) + self.assertEqual(c.segment[1].rsiz, 1) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 128) - self.assertEqual(c.segment[1].Ysiz, 128) + self.assertEqual(c.segment[1].xsiz, 128) + self.assertEqual(c.segment[1].ysiz, 128) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (128, 128)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (128, 128)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)]) # QCD: Quantization default - self.assertEqual(c.segment[2].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[2]._guardBits, 2) + self.assertEqual(c.segment[2].sqcd & 0x1f, 0) + self.assertEqual(c.segment[2]._guard_bits, 2) self.assertEqual(c.segment[2]._exponent, [8, 9, 9, 10, 9, 9, 10, 9, 9, 10]) self.assertEqual(c.segment[2]._mantissa, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) # COD: Coding style default - self.assertFalse(c.segment[3].Scod & 2) # no sop - self.assertFalse(c.segment[3].Scod & 4) # no eph - self.assertEqual(c.segment[3].SPcod[0], glymur.core.RLCP) + self.assertFalse(c.segment[3].scod & 2) # no sop + self.assertFalse(c.segment[3].scod & 4) # no eph + self.assertEqual(c.segment[3].spcod[0], glymur.core.RLCP) self.assertEqual(c.segment[3]._layers, 1) # layers = 1 - self.assertEqual(c.segment[3].SPcod[3], 0) # mct - self.assertEqual(c.segment[3].SPcod[4], 3) # layers + self.assertEqual(c.segment[3].spcod[3], 0) # mct + self.assertEqual(c.segment[3].spcod[4], 3) # layers self.assertEqual(tuple(c.segment[3]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[3].SPcod[7] & 0x01) + self.assertFalse(c.segment[3].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[3].SPcod[7] & 0x02) + self.assertFalse(c.segment[3].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[3].SPcod[7] & 0x04) + self.assertFalse(c.segment[3].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[3].SPcod[7] & 0x08) + self.assertFalse(c.segment[3].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[3].SPcod[7] & 0x0010) + self.assertFalse(c.segment[3].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[3].SPcod[7] & 0x0020) - self.assertEqual(c.segment[3].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) + self.assertFalse(c.segment[3].spcod[7] & 0x0020) + self.assertEqual(c.segment[3].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) # SOT: start of tile part - self.assertEqual(c.segment[4].Isot, 0) - self.assertEqual(c.segment[4].Psot, 7314) - self.assertEqual(c.segment[4].TPsot, 0) - self.assertEqual(c.segment[4].TNsot, 1) + self.assertEqual(c.segment[4].isot, 0) + self.assertEqual(c.segment[4].psot, 7314) + self.assertEqual(c.segment[4].tpsot, 0) + self.assertEqual(c.segment[4].tnsot, 1) def test_NR_p0_02_dump(self): jfile = os.path.join(data_root, 'input/conformance/p0_02.j2k') @@ -1669,72 +1584,72 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "1" means profile 0 - self.assertEqual(c.segment[1].Rsiz, 1) + self.assertEqual(c.segment[1].rsiz, 1) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 127) - self.assertEqual(c.segment[1].Ysiz, 126) + self.assertEqual(c.segment[1].xsiz, 127) + self.assertEqual(c.segment[1].ysiz, 126) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (127, 126)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (127, 126)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(2, 1)]) # COD: Coding style default - self.assertTrue(c.segment[2].Scod & 2) # sop - self.assertTrue(c.segment[2].Scod & 4) # eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertTrue(c.segment[2].scod & 2) # sop + self.assertTrue(c.segment[2].scod & 4) # eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 6) # layers = 6 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 3) # levels + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 3) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertTrue(c.segment[2].SPcod[7] & 0x04) + self.assertTrue(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertTrue(c.segment[2].SPcod[7] & 0x0010) + self.assertTrue(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertTrue(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) + self.assertTrue(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) # COC: Coding style component - self.assertEqual(c.segment[3].Ccoc, 0) - self.assertEqual(c.segment[3].SPcoc[0], 3) # levels + self.assertEqual(c.segment[3].ccoc, 0) + self.assertEqual(c.segment[3].spcoc[0], 3) # levels self.assertEqual(tuple(c.segment[3]._code_block_size), (32, 32)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[3].SPcoc[3] & 0x01) + self.assertFalse(c.segment[3].spcoc[3] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[3].SPcoc[3] & 0x02) + self.assertFalse(c.segment[3].spcoc[3] & 0x02) # Termination on each coding pass - self.assertTrue(c.segment[3].SPcoc[3] & 0x04) + self.assertTrue(c.segment[3].spcoc[3] & 0x04) # Vertically causal context - self.assertFalse(c.segment[3].SPcoc[3] & 0x08) + self.assertFalse(c.segment[3].spcoc[3] & 0x08) # Predictable termination - self.assertTrue(c.segment[3].SPcoc[3] & 0x0010) + self.assertTrue(c.segment[3].spcoc[3] & 0x0010) # Segmentation symbols - self.assertTrue(c.segment[3].SPcoc[3] & 0x0020) - self.assertEqual(c.segment[3].SPcoc[4], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) + self.assertTrue(c.segment[3].spcoc[3] & 0x0020) + self.assertEqual(c.segment[3].spcoc[4], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[4].Sqcd & 0x1f, 0) # none - self.assertEqual(c.segment[4]._guardBits, 3) + self.assertEqual(c.segment[4].sqcd & 0x1f, 0) # none + self.assertEqual(c.segment[4]._guard_bits, 3) self.assertEqual(c.segment[4]._exponent, [8, 9, 9, 10, 9, 9, 10, 9, 9, 10]) self.assertEqual(c.segment[4]._mantissa, @@ -1742,32 +1657,32 @@ class TestSuiteDump(unittest.TestCase): # COM: comment # Registration - self.assertEqual(c.segment[5].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[5].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[5].Ccme.decode('latin-1'), + self.assertEqual(c.segment[5].ccme.decode('latin-1'), "Creator: AV-J2K (c) 2000,2001 Algo Vision") # One unknown marker - self.assertEqual(c.segment[6].id, '0xff30') + self.assertEqual(c.segment[6].marker_id, '0xff30') # SOT: start of tile part - self.assertEqual(c.segment[7].Isot, 0) - self.assertEqual(c.segment[7].Psot, 6047) - self.assertEqual(c.segment[7].TPsot, 0) - self.assertEqual(c.segment[7].TNsot, 1) + self.assertEqual(c.segment[7].isot, 0) + self.assertEqual(c.segment[7].psot, 6047) + self.assertEqual(c.segment[7].tpsot, 0) + self.assertEqual(c.segment[7].tnsot, 1) # SOD: start of data # Just one. - self.assertEqual(c.segment[8].id, 'SOD') + self.assertEqual(c.segment[8].marker_id, 'SOD') # SOP, EPH - sop = [x.id for x in c.segment if x.id == 'SOP'] - eph = [x.id for x in c.segment if x.id == 'EPH'] + sop = [x.marker_id for x in c.segment if x.marker_id == 'SOP'] + eph = [x.marker_id for x in c.segment if x.marker_id == 'EPH'] self.assertEqual(len(sop), 24) self.assertEqual(len(eph), 24) # EOC: end of codestream - self.assertEqual(c.segment[-1].id, 'EOC') + self.assertEqual(c.segment[-1].marker_id, 'EOC') def test_NR_p0_03_dump(self): jfile = os.path.join(data_root, 'input/conformance/p0_03.j2k') @@ -1775,116 +1690,116 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "1" means profile 0 - self.assertEqual(c.segment[1].Rsiz, 1) + self.assertEqual(c.segment[1].rsiz, 1) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 256) - self.assertEqual(c.segment[1].Ysiz, 256) + self.assertEqual(c.segment[1].xsiz, 256) + self.assertEqual(c.segment[1].ysiz, 256) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (128, 128)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (128, 128)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (4,)) # signed self.assertEqual(c.segment[1]._signed, (True,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)]) # COD: Coding style default - self.assertTrue(c.segment[2].Scod & 2) - self.assertFalse(c.segment[2].Scod & 4) - self.assertEqual(c.segment[2].SPcod[0], glymur.core.PCRL) + self.assertTrue(c.segment[2].scod & 2) + self.assertFalse(c.segment[2].scod & 4) + self.assertEqual(c.segment[2].spcod[0], glymur.core.PCRL) self.assertEqual(c.segment[2]._layers, 8) # 8 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 1) # levels + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 1) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 1) # scalar implicit - self.assertEqual(c.segment[3]._guardBits, 2) + self.assertEqual(c.segment[3].sqcd & 0x1f, 1) # scalar implicit + self.assertEqual(c.segment[3]._guard_bits, 2) self.assertEqual(c.segment[3]._exponent, [0]) self.assertEqual(c.segment[3]._mantissa, [0]) # QCC: Quantization component # associated component - self.assertEqual(c.segment[4].Cqcc, 0) - self.assertEqual(c.segment[4]._guardBits, 2) + self.assertEqual(c.segment[4].cqcc, 0) + self.assertEqual(c.segment[4]._guard_bits, 2) # quantization type - self.assertEqual(c.segment[4].Sqcc & 0x1f, 0) # none + self.assertEqual(c.segment[4].sqcc & 0x1f, 0) # none self.assertEqual(c.segment[4]._exponent, [4, 5, 5, 6]) self.assertEqual(c.segment[4]._mantissa, [0, 0, 0, 0]) # POD: progression order change - self.assertEqual(c.segment[5].RSpod, (0,)) - self.assertEqual(c.segment[5].CSpod, (0,)) - self.assertEqual(c.segment[5].LYEpod, (8,)) - self.assertEqual(c.segment[5].REpod, (33,)) - self.assertEqual(c.segment[5].CEpod, (255,)) - self.assertEqual(c.segment[5].Ppod, (glymur.core.LRCP,)) + self.assertEqual(c.segment[5].rspod, (0,)) + self.assertEqual(c.segment[5].cspod, (0,)) + self.assertEqual(c.segment[5].lyepod, (8,)) + self.assertEqual(c.segment[5].repod, (33,)) + self.assertEqual(c.segment[5].cdpod, (255,)) + self.assertEqual(c.segment[5].ppod, (glymur.core.LRCP,)) # CRG: component registration - self.assertEqual(c.segment[6].Xcrg, (65424,)) - self.assertEqual(c.segment[6].Ycrg, (32558,)) + self.assertEqual(c.segment[6].xcrg, (65424,)) + self.assertEqual(c.segment[6].ycrg, (32558,)) # COM: comment # Registration - self.assertEqual(c.segment[7].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[7].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[7].Ccme.decode('latin-1'), + self.assertEqual(c.segment[7].ccme.decode('latin-1'), "Creator: AV-J2K (c) 2000,2001 Algo Vision") # COM: comment # Registration - self.assertEqual(c.segment[8].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[8].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[8].Ccme.decode('latin-1'), + self.assertEqual(c.segment[8].ccme.decode('latin-1'), "Creator: AV-J2K (c) 2000," + "2001 Algo Vision Technology") # COM: comment # Registration - self.assertEqual(c.segment[9].Rcme, glymur.core.RCME_BINARY) + self.assertEqual(c.segment[9].rcme, glymur.core.RCME_BINARY) # Comment value - self.assertEqual(len(c.segment[9].Ccme), 62) + self.assertEqual(len(c.segment[9].ccme), 62) # TLM (tile-part length) - self.assertEqual(c.segment[10].Ztlm, 0) - self.assertEqual(c.segment[10].Ttlm, (0, 1, 2, 3)) - self.assertEqual(c.segment[10].Ptlm, (4267, 2117, 4080, 2081)) + self.assertEqual(c.segment[10].ztlm, 0) + self.assertEqual(c.segment[10].ttlm, (0, 1, 2, 3)) + self.assertEqual(c.segment[10].ptlm, (4267, 2117, 4080, 2081)) # SOT: start of tile part - self.assertEqual(c.segment[11].Isot, 0) - self.assertEqual(c.segment[11].Psot, 4267) - self.assertEqual(c.segment[11].TPsot, 0) - self.assertEqual(c.segment[11].TNsot, 1) + self.assertEqual(c.segment[11].isot, 0) + self.assertEqual(c.segment[11].psot, 4267) + self.assertEqual(c.segment[11].tpsot, 0) + self.assertEqual(c.segment[11].tnsot, 1) # RGN: region of interest - self.assertEqual(c.segment[12].Crgn, 0) - self.assertEqual(c.segment[12].Srgn, 0) - self.assertEqual(c.segment[12].SPrgn, 7) + self.assertEqual(c.segment[12].crgn, 0) + self.assertEqual(c.segment[12].srgn, 0) + self.assertEqual(c.segment[12].sprgn, 7) # SOD: start of data # Just one. - self.assertEqual(c.segment[13].id, 'SOD') + self.assertEqual(c.segment[13].marker_id, 'SOD') def test_NR_p0_04_dump(self): jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') @@ -1892,55 +1807,55 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "1" means profile 0 - self.assertEqual(c.segment[1].Rsiz, 1) + self.assertEqual(c.segment[1].rsiz, 1) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 640) - self.assertEqual(c.segment[1].Ysiz, 480) + self.assertEqual(c.segment[1].xsiz, 640) + self.assertEqual(c.segment[1].ysiz, 480) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (640, 480)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (640, 480)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1), (1, 1), (1, 1)]) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) - self.assertFalse(c.segment[2].Scod & 4) - self.assertEqual(c.segment[2].SPcod[0], glymur.core.RLCP) + self.assertFalse(c.segment[2].scod & 2) + self.assertFalse(c.segment[2].scod & 4) + self.assertEqual(c.segment[2].spcod[0], glymur.core.RLCP) self.assertEqual(c.segment[2]._layers, 20) # 20 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 6) # levels + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 6) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertTrue(c.segment[2].SPcod[7] & 0x04) + self.assertTrue(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) self.assertEqual(c.segment[2]._precinct_size, [(128, 128), (128, 128), (128, 128), (128, 128), (128, 128), (128, 128), (128, 128)]) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 2) # scalar expounded - self.assertEqual(c.segment[3]._guardBits, 3) + self.assertEqual(c.segment[3].sqcd & 0x1f, 2) # scalar expounded + self.assertEqual(c.segment[3]._guard_bits, 3) self.assertEqual(c.segment[3]._exponent, [16, 16, 16, 16, 15, 15, 15, 14, 14, 14, 13, 13, 13, 11, 11, 11, 11, 11, 11]) @@ -1951,10 +1866,10 @@ class TestSuiteDump(unittest.TestCase): # QCC: Quantization component # associated component - self.assertEqual(c.segment[4].Cqcc, 1) + self.assertEqual(c.segment[4].cqcc, 1) # quantization type - self.assertEqual(c.segment[4].Sqcc & 0x1f, 2) # none - self.assertEqual(c.segment[4]._guardBits, 3) + self.assertEqual(c.segment[4].sqcc & 0x1f, 2) # none + self.assertEqual(c.segment[4]._guard_bits, 3) self.assertEqual(c.segment[4]._exponent, [14, 14, 14, 14, 13, 13, 13, 12, 12, 12, 11, 11, 11, 9, 9, 9, 9, 9, 9]) @@ -1965,10 +1880,10 @@ class TestSuiteDump(unittest.TestCase): # QCC: Quantization component # associated component - self.assertEqual(c.segment[5].Cqcc, 2) + self.assertEqual(c.segment[5].cqcc, 2) # quantization type - self.assertEqual(c.segment[5].Sqcc & 0x1f, 2) # none - self.assertEqual(c.segment[5]._guardBits, 3) + self.assertEqual(c.segment[5].sqcc & 0x1f, 2) # none + self.assertEqual(c.segment[5]._guard_bits, 3) self.assertEqual(c.segment[5]._exponent, [14, 14, 14, 14, 13, 13, 13, 12, 12, 12, 11, 11, 11, 9, 9, 9, 9, 9, 9]) @@ -1979,20 +1894,20 @@ class TestSuiteDump(unittest.TestCase): # COM: comment # Registration - self.assertEqual(c.segment[6].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[6].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[6].Ccme.decode('latin-1'), + self.assertEqual(c.segment[6].ccme.decode('latin-1'), "Creator: AV-J2K (c) 2000,2001 Algo Vision") # SOT: start of tile part - self.assertEqual(c.segment[7].Isot, 0) - self.assertEqual(c.segment[7].Psot, 264383) - self.assertEqual(c.segment[7].TPsot, 0) - self.assertEqual(c.segment[7].TNsot, 1) + self.assertEqual(c.segment[7].isot, 0) + self.assertEqual(c.segment[7].psot, 264383) + self.assertEqual(c.segment[7].tpsot, 0) + self.assertEqual(c.segment[7].tnsot, 1) # SOD: start of data # Just one. - self.assertEqual(c.segment[8].id, 'SOD') + self.assertEqual(c.segment[8].marker_id, 'SOD') def test_NR_p0_05_dump(self): jfile = os.path.join(data_root, 'input/conformance/p0_05.j2k') @@ -2000,94 +1915,94 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "1" means profile 0 - self.assertEqual(c.segment[1].Rsiz, 1) + self.assertEqual(c.segment[1].rsiz, 1) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 1024) - self.assertEqual(c.segment[1].Ysiz, 1024) + self.assertEqual(c.segment[1].xsiz, 1024) + self.assertEqual(c.segment[1].ysiz, 1024) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (1024, 1024)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1), (1, 1), (2, 2), (2, 2)]) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) - self.assertFalse(c.segment[2].Scod & 4) - self.assertEqual(c.segment[2].SPcod[0], glymur.core.PCRL) + self.assertFalse(c.segment[2].scod & 2) + self.assertFalse(c.segment[2].scod & 4) + self.assertEqual(c.segment[2].spcod[0], glymur.core.PCRL) self.assertEqual(c.segment[2]._layers, 7) # 7 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 6) # levels + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 6) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (32, 32)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # COC: Coding style component - self.assertEqual(c.segment[3].Ccoc, 1) - self.assertEqual(c.segment[3].SPcoc[0], 3) # levels + self.assertEqual(c.segment[3].ccoc, 1) + self.assertEqual(c.segment[3].spcoc[0], 3) # levels self.assertEqual(tuple(c.segment[3]._code_block_size), (32, 32)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[3].SPcoc[3] & 0x01) + self.assertFalse(c.segment[3].spcoc[3] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[3].SPcoc[3] & 0x02) + self.assertFalse(c.segment[3].spcoc[3] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[3].SPcoc[3] & 0x04) + self.assertFalse(c.segment[3].spcoc[3] & 0x04) # Vertically causal context - self.assertFalse(c.segment[3].SPcoc[3] & 0x08) + self.assertFalse(c.segment[3].spcoc[3] & 0x08) # Predictable termination - self.assertFalse(c.segment[3].SPcoc[3] & 0x0010) + self.assertFalse(c.segment[3].spcoc[3] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[3].SPcoc[3] & 0x0020) - self.assertEqual(c.segment[3].SPcoc[4], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) + self.assertFalse(c.segment[3].spcoc[3] & 0x0020) + self.assertEqual(c.segment[3].spcoc[4], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) # COC: Coding style component - self.assertEqual(c.segment[4].Ccoc, 3) - self.assertEqual(c.segment[4].SPcoc[0], 6) # levels + self.assertEqual(c.segment[4].ccoc, 3) + self.assertEqual(c.segment[4].spcoc[0], 6) # levels self.assertEqual(tuple(c.segment[4]._code_block_size), (32, 32)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[4].SPcoc[3] & 0x01) + self.assertFalse(c.segment[4].spcoc[3] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[4].SPcoc[3] & 0x02) + self.assertFalse(c.segment[4].spcoc[3] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[4].SPcoc[3] & 0x04) + self.assertFalse(c.segment[4].spcoc[3] & 0x04) # Vertically causal context - self.assertFalse(c.segment[4].SPcoc[3] & 0x08) + self.assertFalse(c.segment[4].spcoc[3] & 0x08) # Predictable termination - self.assertFalse(c.segment[4].SPcoc[3] & 0x0010) + self.assertFalse(c.segment[4].spcoc[3] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[4].SPcoc[3] & 0x0020) - self.assertEqual(c.segment[4].SPcoc[4], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) + self.assertFalse(c.segment[4].spcoc[3] & 0x0020) + self.assertEqual(c.segment[4].spcoc[4], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[5].Sqcd & 0x1f, 2) # scalar expounded - self.assertEqual(c.segment[5]._guardBits, 3) + self.assertEqual(c.segment[5].sqcd & 0x1f, 2) # scalar expounded + self.assertEqual(c.segment[5]._guard_bits, 3) self.assertEqual(c.segment[5]._exponent, [16, 16, 16, 16, 15, 15, 15, 14, 14, 14, 13, 13, 13, 11, 11, 11, 11, 11, 11]) @@ -2098,19 +2013,19 @@ class TestSuiteDump(unittest.TestCase): # QCC: Quantization component # associated component - self.assertEqual(c.segment[6].Cqcc, 0) + self.assertEqual(c.segment[6].cqcc, 0) # quantization type - self.assertEqual(c.segment[6].Sqcc & 0x1f, 1) # scalar derived - self.assertEqual(c.segment[6]._guardBits, 3) + self.assertEqual(c.segment[6].sqcc & 0x1f, 1) # scalar derived + self.assertEqual(c.segment[6]._guard_bits, 3) self.assertEqual(c.segment[6]._exponent, [14]) self.assertEqual(c.segment[6]._mantissa, [0]) # QCC: Quantization component # associated component - self.assertEqual(c.segment[7].Cqcc, 3) + self.assertEqual(c.segment[7].cqcc, 3) # quantization type - self.assertEqual(c.segment[7].Sqcc & 0x1f, 0) # none - self.assertEqual(c.segment[7]._guardBits, 3) + self.assertEqual(c.segment[7].sqcc & 0x1f, 0) # none + self.assertEqual(c.segment[7]._guard_bits, 3) self.assertEqual(c.segment[7]._exponent, [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) @@ -2118,25 +2033,25 @@ class TestSuiteDump(unittest.TestCase): # COM: comment # Registration - self.assertEqual(c.segment[8].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[8].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[8].Ccme.decode('latin-1'), + self.assertEqual(c.segment[8].ccme.decode('latin-1'), "Creator: AV-J2K (c) 2000,2001 Algo Vision") # TLM (tile-part length) - self.assertEqual(c.segment[9].Ztlm, 0) - self.assertEqual(c.segment[9].Ttlm, (0,)) - self.assertEqual(c.segment[9].Ptlm, (1310540,)) + self.assertEqual(c.segment[9].ztlm, 0) + self.assertEqual(c.segment[9].ttlm, (0,)) + self.assertEqual(c.segment[9].ptlm, (1310540,)) # SOT: start of tile part - self.assertEqual(c.segment[10].Isot, 0) - self.assertEqual(c.segment[10].Psot, 1310540) - self.assertEqual(c.segment[10].TPsot, 0) - self.assertEqual(c.segment[10].TNsot, 1) + self.assertEqual(c.segment[10].isot, 0) + self.assertEqual(c.segment[10].psot, 1310540) + self.assertEqual(c.segment[10].tpsot, 0) + self.assertEqual(c.segment[10].tnsot, 1) # SOD: start of data # Just one. - self.assertEqual(c.segment[11].id, 'SOD') + self.assertEqual(c.segment[11].marker_id, 'SOD') def test_NR_p0_06_dump(self): jfile = os.path.join(data_root, 'input/conformance/p0_06.j2k') @@ -2144,53 +2059,53 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "1" means profile 0 - self.assertEqual(c.segment[1].Rsiz, 2) + self.assertEqual(c.segment[1].rsiz, 2) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 513) - self.assertEqual(c.segment[1].Ysiz, 129) + self.assertEqual(c.segment[1].xsiz, 513) + self.assertEqual(c.segment[1].ysiz, 129) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (513, 129)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (513, 129)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (12, 12, 12, 12)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1), (2, 1), (1, 2), (2, 2)]) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) - self.assertFalse(c.segment[2].Scod & 4) - self.assertEqual(c.segment[2].SPcod[0], glymur.core.RPCL) + self.assertFalse(c.segment[2].scod & 2) + self.assertFalse(c.segment[2].scod & 4) + self.assertEqual(c.segment[2].spcod[0], glymur.core.RPCL) self.assertEqual(c.segment[2]._layers, 4) # 4 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 6) # levels + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 6) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 2) # scalar expounded - self.assertEqual(c.segment[3]._guardBits, 3) + self.assertEqual(c.segment[3].sqcd & 0x1f, 2) # scalar expounded + self.assertEqual(c.segment[3]._guard_bits, 3) self.assertEqual(c.segment[3]._mantissa, [512, 518, 522, 524, 516, 524, 522, 527, 523, 549, 557, 561, 853, 852, 700, 163, 78, 1508, 1831]) @@ -2200,10 +2115,10 @@ class TestSuiteDump(unittest.TestCase): # QCC: Quantization component # associated component - self.assertEqual(c.segment[4].Cqcc, 1) + self.assertEqual(c.segment[4].cqcc, 1) # quantization type - self.assertEqual(c.segment[4].Sqcc & 0x1f, 2) # scalar derived - self.assertEqual(c.segment[4]._guardBits, 4) + self.assertEqual(c.segment[4].sqcc & 0x1f, 2) # scalar derived + self.assertEqual(c.segment[4]._guard_bits, 4) self.assertEqual(c.segment[4]._mantissa, [1527, 489, 665, 506, 487, 502, 493, 493, 500, 485, 505, 491, 490, 491, 499, 509, 503, 496, 558]) @@ -2213,10 +2128,10 @@ class TestSuiteDump(unittest.TestCase): # QCC: Quantization component # associated component - self.assertEqual(c.segment[5].Cqcc, 2) + self.assertEqual(c.segment[5].cqcc, 2) # quantization type - self.assertEqual(c.segment[5].Sqcc & 0x1f, 2) # scalar derived - self.assertEqual(c.segment[5]._guardBits, 5) + self.assertEqual(c.segment[5].sqcc & 0x1f, 2) # scalar derived + self.assertEqual(c.segment[5]._guard_bits, 5) self.assertEqual(c.segment[5]._mantissa, [1337, 728, 890, 719, 716, 726, 700, 718, 704, 704, 712, 712, 717, 719, 701, 749, 753, 718, 841]) @@ -2226,54 +2141,54 @@ class TestSuiteDump(unittest.TestCase): # QCC: Quantization component # associated component - self.assertEqual(c.segment[6].Cqcc, 3) + self.assertEqual(c.segment[6].cqcc, 3) # quantization type - self.assertEqual(c.segment[6].Sqcc & 0x1f, 0) # none - self.assertEqual(c.segment[6]._guardBits, 6) + self.assertEqual(c.segment[6].sqcc & 0x1f, 0) # none + self.assertEqual(c.segment[6]._guard_bits, 6) self.assertEqual(c.segment[6]._mantissa, [0] * 19) self.assertEqual(c.segment[6]._exponent, [12, 13, 13, 14, 13, 13, 14, 13, 13, 14, 13, 13, 14, 13, 13, 14, 13, 13, 14]) # COC: Coding style component - self.assertEqual(c.segment[7].Ccoc, 3) - self.assertEqual(c.segment[7].SPcoc[0], 6) # levels + self.assertEqual(c.segment[7].ccoc, 3) + self.assertEqual(c.segment[7].spcoc[0], 6) # levels self.assertEqual(tuple(c.segment[7]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[7].SPcoc[3] & 0x01) + self.assertFalse(c.segment[7].spcoc[3] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[7].SPcoc[3] & 0x02) + self.assertFalse(c.segment[7].spcoc[3] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[7].SPcoc[3] & 0x04) + self.assertFalse(c.segment[7].spcoc[3] & 0x04) # Vertically causal context - self.assertFalse(c.segment[7].SPcoc[3] & 0x08) + self.assertFalse(c.segment[7].spcoc[3] & 0x08) # Predictable termination - self.assertFalse(c.segment[7].SPcoc[3] & 0x0010) + self.assertFalse(c.segment[7].spcoc[3] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[7].SPcoc[3] & 0x0020) - self.assertEqual(c.segment[7].SPcoc[4], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) + self.assertFalse(c.segment[7].spcoc[3] & 0x0020) + self.assertEqual(c.segment[7].spcoc[4], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) # RGN: region of interest - self.assertEqual(c.segment[8].Crgn, 0) # component - self.assertEqual(c.segment[8].Srgn, 0) # implicit - self.assertEqual(c.segment[8].SPrgn, 11) + self.assertEqual(c.segment[8].crgn, 0) # component + self.assertEqual(c.segment[8].srgn, 0) # implicit + self.assertEqual(c.segment[8].sprgn, 11) # SOT: start of tile part - self.assertEqual(c.segment[9].Isot, 0) - self.assertEqual(c.segment[9].Psot, 33582) - self.assertEqual(c.segment[9].TPsot, 0) - self.assertEqual(c.segment[9].TNsot, 1) + self.assertEqual(c.segment[9].isot, 0) + self.assertEqual(c.segment[9].psot, 33582) + self.assertEqual(c.segment[9].tpsot, 0) + self.assertEqual(c.segment[9].tnsot, 1) # RGN: region of interest - self.assertEqual(c.segment[10].Crgn, 0) # component - self.assertEqual(c.segment[10].Srgn, 0) # implicit - self.assertEqual(c.segment[10].SPrgn, 9) + self.assertEqual(c.segment[10].crgn, 0) # component + self.assertEqual(c.segment[10].srgn, 0) # implicit + self.assertEqual(c.segment[10].sprgn, 9) # SOD: start of data # Just one. - self.assertEqual(c.segment[11].id, 'SOD') + self.assertEqual(c.segment[11].marker_id, 'SOD') def test_NR_p0_07_dump(self): jfile = os.path.join(data_root, 'input/conformance/p0_07.j2k') @@ -2281,84 +2196,84 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "1" means profile 0 - self.assertEqual(c.segment[1].Rsiz, 1) + self.assertEqual(c.segment[1].rsiz, 1) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 2048) - self.assertEqual(c.segment[1].Ysiz, 2048) + self.assertEqual(c.segment[1].xsiz, 2048) + self.assertEqual(c.segment[1].ysiz, 2048) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (128, 128)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (128, 128)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (12, 12, 12)) # signed self.assertEqual(c.segment[1]._signed, (True, True, True)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1), (1, 1), (1, 1)]) # COD: Coding style default - self.assertTrue(c.segment[2].Scod & 2) - self.assertTrue(c.segment[2].Scod & 4) - self.assertEqual(c.segment[2].SPcod[0], glymur.core.RLCP) + self.assertTrue(c.segment[2].scod & 2) + self.assertTrue(c.segment[2].scod & 4) + self.assertEqual(c.segment[2].spcod[0], glymur.core.RLCP) self.assertEqual(c.segment[2]._layers, 8) # 8 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 3) # levels + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 3) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) # none - self.assertEqual(c.segment[3]._guardBits, 1) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) # none + self.assertEqual(c.segment[3]._guard_bits, 1) self.assertEqual(c.segment[3]._mantissa, [0] * 10) self.assertEqual(c.segment[3]._exponent, [14, 15, 15, 16, 15, 15, 16, 15, 15, 16]) # COM: comment # Registration - self.assertEqual(c.segment[4].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[4].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[4].Ccme.decode('latin-1'), + self.assertEqual(c.segment[4].ccme.decode('latin-1'), "Kakadu-3.0.7") # SOT: start of tile part - self.assertEqual(c.segment[5].Isot, 0) - self.assertEqual(c.segment[5].Psot, 9951) - self.assertEqual(c.segment[5].TPsot, 0) - self.assertEqual(c.segment[5].TNsot, 0) # unknown + self.assertEqual(c.segment[5].isot, 0) + self.assertEqual(c.segment[5].psot, 9951) + self.assertEqual(c.segment[5].tpsot, 0) + self.assertEqual(c.segment[5].tnsot, 0) # unknown # POD: progression order change - self.assertEqual(c.segment[6].RSpod, (0,)) - self.assertEqual(c.segment[6].CSpod, (0,)) - self.assertEqual(c.segment[6].LYEpod, (9,)) - self.assertEqual(c.segment[6].REpod, (3,)) - self.assertEqual(c.segment[6].CEpod, (3,)) - self.assertEqual(c.segment[6].Ppod, (glymur.core.LRCP,)) + self.assertEqual(c.segment[6].rspod, (0,)) + self.assertEqual(c.segment[6].cspod, (0,)) + self.assertEqual(c.segment[6].lyepod, (9,)) + self.assertEqual(c.segment[6].repod, (3,)) + self.assertEqual(c.segment[6].cdpod, (3,)) + self.assertEqual(c.segment[6].ppod, (glymur.core.LRCP,)) # PLT: packet length, tile part - self.assertEqual(c.segment[7].Zplt, 0) + self.assertEqual(c.segment[7].zplt, 0) #self.assertEqual(c.segment[7].iplt), 99) # SOD: start of data - self.assertEqual(c.segment[8].id, 'SOD') + self.assertEqual(c.segment[8].marker_id, 'SOD') def test_NR_p0_08_dump(self): jfile = os.path.join(data_root, 'input/conformance/p0_08.j2k') @@ -2366,113 +2281,113 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "1" means profile 0 - self.assertEqual(c.segment[1].Rsiz, 1) + self.assertEqual(c.segment[1].rsiz, 1) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 513) - self.assertEqual(c.segment[1].Ysiz, 3072) + self.assertEqual(c.segment[1].xsiz, 513) + self.assertEqual(c.segment[1].ysiz, 3072) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (513, 3072)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (513, 3072)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (12, 12, 12)) # signed self.assertEqual(c.segment[1]._signed, (True, True, True)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1), (1, 1), (1, 1)]) # COD: Coding style default - self.assertTrue(c.segment[2].Scod & 2) - self.assertTrue(c.segment[2].Scod & 4) - self.assertEqual(c.segment[2].SPcod[0], glymur.core.CPRL) + self.assertTrue(c.segment[2].scod & 2) + self.assertTrue(c.segment[2].scod & 4) + self.assertEqual(c.segment[2].spcod[0], glymur.core.CPRL) self.assertEqual(c.segment[2]._layers, 30) # 30 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 7) # levels + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 7) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # COC: Coding style component - self.assertEqual(c.segment[3].Ccoc, 0) - self.assertEqual(c.segment[3].SPcoc[0], 6) # levels + self.assertEqual(c.segment[3].ccoc, 0) + self.assertEqual(c.segment[3].spcoc[0], 6) # levels self.assertEqual(tuple(c.segment[3]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[3].SPcoc[3] & 0x01) + self.assertFalse(c.segment[3].spcoc[3] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[3].SPcoc[3] & 0x02) + self.assertFalse(c.segment[3].spcoc[3] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[3].SPcoc[3] & 0x04) + self.assertFalse(c.segment[3].spcoc[3] & 0x04) # Vertically causal context - self.assertFalse(c.segment[3].SPcoc[3] & 0x08) + self.assertFalse(c.segment[3].spcoc[3] & 0x08) # Predictable termination - self.assertFalse(c.segment[3].SPcoc[3] & 0x0010) + self.assertFalse(c.segment[3].spcoc[3] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[3].SPcoc[3] & 0x0020) - self.assertEqual(c.segment[3].SPcoc[4], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) + self.assertFalse(c.segment[3].spcoc[3] & 0x0020) + self.assertEqual(c.segment[3].spcoc[4], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) # COC: Coding style component - self.assertEqual(c.segment[4].Ccoc, 1) - self.assertEqual(c.segment[4].SPcoc[0], 7) # levels + self.assertEqual(c.segment[4].ccoc, 1) + self.assertEqual(c.segment[4].spcoc[0], 7) # levels self.assertEqual(tuple(c.segment[4]._code_block_size), (32, 32)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[4].SPcoc[3] & 0x01) + self.assertFalse(c.segment[4].spcoc[3] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[4].SPcoc[3] & 0x02) + self.assertFalse(c.segment[4].spcoc[3] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[4].SPcoc[3] & 0x04) + self.assertFalse(c.segment[4].spcoc[3] & 0x04) # Vertically causal context - self.assertFalse(c.segment[4].SPcoc[3] & 0x08) + self.assertFalse(c.segment[4].spcoc[3] & 0x08) # Predictable termination - self.assertFalse(c.segment[4].SPcoc[3] & 0x0010) + self.assertFalse(c.segment[4].spcoc[3] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[4].SPcoc[3] & 0x0020) - self.assertEqual(c.segment[4].SPcoc[4], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) + self.assertFalse(c.segment[4].spcoc[3] & 0x0020) + self.assertEqual(c.segment[4].spcoc[4], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) # COC: Coding style component - self.assertEqual(c.segment[5].Ccoc, 2) - self.assertEqual(c.segment[5].SPcoc[0], 8) # levels + self.assertEqual(c.segment[5].ccoc, 2) + self.assertEqual(c.segment[5].spcoc[0], 8) # levels self.assertEqual(tuple(c.segment[5]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[5].SPcoc[3] & 0x01) + self.assertFalse(c.segment[5].spcoc[3] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[5].SPcoc[3] & 0x02) + self.assertFalse(c.segment[5].spcoc[3] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[5].SPcoc[3] & 0x04) + self.assertFalse(c.segment[5].spcoc[3] & 0x04) # Vertically causal context - self.assertFalse(c.segment[5].SPcoc[3] & 0x08) + self.assertFalse(c.segment[5].spcoc[3] & 0x08) # Predictable termination - self.assertFalse(c.segment[5].SPcoc[3] & 0x0010) + self.assertFalse(c.segment[5].spcoc[3] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[5].SPcoc[3] & 0x0020) - self.assertEqual(c.segment[5].SPcoc[4], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) + self.assertFalse(c.segment[5].spcoc[3] & 0x0020) + self.assertEqual(c.segment[5].spcoc[4], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[6].Sqcd & 0x1f, 0) # none - self.assertEqual(c.segment[6]._guardBits, 4) + self.assertEqual(c.segment[6].sqcd & 0x1f, 0) # none + self.assertEqual(c.segment[6]._guard_bits, 4) self.assertEqual(c.segment[6]._mantissa, [0] * 22) self.assertEqual(c.segment[6]._exponent, [11, 12, 12, 13, 12, 12, 13, 12, 12, 13, 12, 12, 13, @@ -2480,10 +2395,10 @@ class TestSuiteDump(unittest.TestCase): # QCC: Quantization component # associated component - self.assertEqual(c.segment[7].Cqcc, 0) + self.assertEqual(c.segment[7].cqcc, 0) # quantization type - self.assertEqual(c.segment[7].Sqcc & 0x1f, 0) # none - self.assertEqual(c.segment[7]._guardBits, 4) + self.assertEqual(c.segment[7].sqcc & 0x1f, 0) # none + self.assertEqual(c.segment[7]._guard_bits, 4) self.assertEqual(c.segment[7]._mantissa, [0] * 19) self.assertEqual(c.segment[7]._exponent, [11, 12, 12, 13, 12, 12, 13, 12, 12, 13, 12, 12, 13, @@ -2491,10 +2406,10 @@ class TestSuiteDump(unittest.TestCase): # QCC: Quantization component # associated component - self.assertEqual(c.segment[8].Cqcc, 2) + self.assertEqual(c.segment[8].cqcc, 2) # quantization type - self.assertEqual(c.segment[8].Sqcc & 0x1f, 0) # none - self.assertEqual(c.segment[8]._guardBits, 4) + self.assertEqual(c.segment[8].sqcc & 0x1f, 0) # none + self.assertEqual(c.segment[8]._guard_bits, 4) self.assertEqual(c.segment[8]._mantissa, [0] * 25) self.assertEqual(c.segment[8]._exponent, [11, 12, 12, 13, 12, 12, 13, 12, 12, 13, 12, 12, 13, @@ -2502,16 +2417,16 @@ class TestSuiteDump(unittest.TestCase): # COM: comment # Registration - self.assertEqual(c.segment[9].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[9].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[9].Ccme.decode('latin-1'), + self.assertEqual(c.segment[9].ccme.decode('latin-1'), "Kakadu-3.0.7") # SOT: start of tile part - self.assertEqual(c.segment[10].Isot, 0) - self.assertEqual(c.segment[10].Psot, 3820593) - self.assertEqual(c.segment[10].TPsot, 0) - self.assertEqual(c.segment[10].TNsot, 1) # unknown + self.assertEqual(c.segment[10].isot, 0) + self.assertEqual(c.segment[10].psot, 3820593) + self.assertEqual(c.segment[10].tpsot, 0) + self.assertEqual(c.segment[10].tnsot, 1) # unknown def test_NR_p0_09_dump(self): jfile = os.path.join(data_root, 'input/conformance/p0_09.j2k') @@ -2519,53 +2434,53 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "0" means profile 2, or full capabilities - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 17) - self.assertEqual(c.segment[1].Ysiz, 37) + self.assertEqual(c.segment[1].xsiz, 17) + self.assertEqual(c.segment[1].ysiz, 37) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (17, 37)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (17, 37)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)]) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) - self.assertFalse(c.segment[2].Scod & 4) - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) + self.assertFalse(c.segment[2].scod & 4) + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # levels + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 2) # scalar expounded - self.assertEqual(c.segment[3]._guardBits, 1) + self.assertEqual(c.segment[3].sqcd & 0x1f, 2) # scalar expounded + self.assertEqual(c.segment[3]._guard_bits, 1) self.assertEqual(c.segment[3]._mantissa, [1915, 1884, 1884, 1853, 1884, 1884, 1853, 1962, 1962, 1986, 53, 53, 120, 26, 26, 1983]) @@ -2575,23 +2490,23 @@ class TestSuiteDump(unittest.TestCase): # COM: comment # Registration - self.assertEqual(c.segment[4].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[4].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[4].Ccme.decode('latin-1'), + self.assertEqual(c.segment[4].ccme.decode('latin-1'), "Kakadu-3.0.7") # SOT: start of tile part - self.assertEqual(c.segment[5].Isot, 0) - self.assertEqual(c.segment[5].Psot, 478) - self.assertEqual(c.segment[5].TPsot, 0) - self.assertEqual(c.segment[5].TNsot, 1) # unknown + self.assertEqual(c.segment[5].isot, 0) + self.assertEqual(c.segment[5].psot, 478) + self.assertEqual(c.segment[5].tpsot, 0) + self.assertEqual(c.segment[5].tnsot, 1) # unknown # SOD: start of data # Just one. - self.assertEqual(c.segment[6].id, 'SOD') + self.assertEqual(c.segment[6].marker_id, 'SOD') # EOC: end of codestream - self.assertEqual(c.segment[7].id, 'EOC') + self.assertEqual(c.segment[7].marker_id, 'EOC') def test_NR_p0_10_dump(self): jfile = os.path.join(data_root, 'input/conformance/p0_10.j2k') @@ -2599,140 +2514,140 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "1" means profile 0 - self.assertEqual(c.segment[1].Rsiz, 1) + self.assertEqual(c.segment[1].rsiz, 1) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 256) - self.assertEqual(c.segment[1].Ysiz, 256) + self.assertEqual(c.segment[1].xsiz, 256) + self.assertEqual(c.segment[1].ysiz, 256) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (128, 128)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (128, 128)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(4, 4), (4, 4), (4, 4)]) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) - self.assertFalse(c.segment[2].Scod & 4) - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) + self.assertFalse(c.segment[2].scod & 4) + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 2) # 2 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 3) # levels + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 3) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) # none - self.assertEqual(c.segment[3]._guardBits, 0) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) # none + self.assertEqual(c.segment[3]._guard_bits, 0) self.assertEqual(c.segment[3]._mantissa, [0] * 10) self.assertEqual(c.segment[3]._exponent, [11, 12, 12, 13, 12, 12, 13, 12, 12, 13]) # SOT: start of tile part - self.assertEqual(c.segment[4].Isot, 0) - self.assertEqual(c.segment[4].Psot, 2453) - self.assertEqual(c.segment[4].TPsot, 0) - self.assertEqual(c.segment[4].TNsot, 0) + self.assertEqual(c.segment[4].isot, 0) + self.assertEqual(c.segment[4].psot, 2453) + self.assertEqual(c.segment[4].tpsot, 0) + self.assertEqual(c.segment[4].tnsot, 0) # SOD: start of data - self.assertEqual(c.segment[5].id, 'SOD') + self.assertEqual(c.segment[5].marker_id, 'SOD') # SOT: start of tile part - self.assertEqual(c.segment[6].Isot, 1) - self.assertEqual(c.segment[6].Psot, 2403) - self.assertEqual(c.segment[6].TPsot, 0) - self.assertEqual(c.segment[6].TNsot, 0) + self.assertEqual(c.segment[6].isot, 1) + self.assertEqual(c.segment[6].psot, 2403) + self.assertEqual(c.segment[6].tpsot, 0) + self.assertEqual(c.segment[6].tnsot, 0) # SOD: start of data - self.assertEqual(c.segment[7].id, 'SOD') + self.assertEqual(c.segment[7].marker_id, 'SOD') # SOT: start of tile part - self.assertEqual(c.segment[8].Isot, 2) - self.assertEqual(c.segment[8].Psot, 2420) - self.assertEqual(c.segment[8].TPsot, 0) - self.assertEqual(c.segment[8].TNsot, 0) + self.assertEqual(c.segment[8].isot, 2) + self.assertEqual(c.segment[8].psot, 2420) + self.assertEqual(c.segment[8].tpsot, 0) + self.assertEqual(c.segment[8].tnsot, 0) # SOD: start of data - self.assertEqual(c.segment[9].id, 'SOD') + self.assertEqual(c.segment[9].marker_id, 'SOD') # SOT: start of tile part - self.assertEqual(c.segment[10].Isot, 3) - self.assertEqual(c.segment[10].Psot, 2472) - self.assertEqual(c.segment[10].TPsot, 0) - self.assertEqual(c.segment[10].TNsot, 0) + self.assertEqual(c.segment[10].isot, 3) + self.assertEqual(c.segment[10].psot, 2472) + self.assertEqual(c.segment[10].tpsot, 0) + self.assertEqual(c.segment[10].tnsot, 0) # SOD: start of data - self.assertEqual(c.segment[11].id, 'SOD') + self.assertEqual(c.segment[11].marker_id, 'SOD') # SOT: start of tile part - self.assertEqual(c.segment[12].Isot, 0) - self.assertEqual(c.segment[12].Psot, 1043) - self.assertEqual(c.segment[12].TPsot, 1) - self.assertEqual(c.segment[12].TNsot, 2) + self.assertEqual(c.segment[12].isot, 0) + self.assertEqual(c.segment[12].psot, 1043) + self.assertEqual(c.segment[12].tpsot, 1) + self.assertEqual(c.segment[12].tnsot, 2) # SOD: start of data - self.assertEqual(c.segment[13].id, 'SOD') + self.assertEqual(c.segment[13].marker_id, 'SOD') # SOT: start of tile part - self.assertEqual(c.segment[14].Isot, 1) - self.assertEqual(c.segment[14].Psot, 1101) - self.assertEqual(c.segment[14].TPsot, 1) - self.assertEqual(c.segment[14].TNsot, 2) + self.assertEqual(c.segment[14].isot, 1) + self.assertEqual(c.segment[14].psot, 1101) + self.assertEqual(c.segment[14].tpsot, 1) + self.assertEqual(c.segment[14].tnsot, 2) # SOD: start of data - self.assertEqual(c.segment[15].id, 'SOD') + self.assertEqual(c.segment[15].marker_id, 'SOD') # SOT: start of tile part - self.assertEqual(c.segment[16].Isot, 3) - self.assertEqual(c.segment[16].Psot, 1054) - self.assertEqual(c.segment[16].TPsot, 1) - self.assertEqual(c.segment[16].TNsot, 2) + self.assertEqual(c.segment[16].isot, 3) + self.assertEqual(c.segment[16].psot, 1054) + self.assertEqual(c.segment[16].tpsot, 1) + self.assertEqual(c.segment[16].tnsot, 2) # SOD: start of data - self.assertEqual(c.segment[17].id, 'SOD') + self.assertEqual(c.segment[17].marker_id, 'SOD') # SOT: start of tile part - self.assertEqual(c.segment[18].Isot, 2) - self.assertEqual(c.segment[18].Psot, 14) - self.assertEqual(c.segment[18].TPsot, 1) - self.assertEqual(c.segment[18].TNsot, 0) + self.assertEqual(c.segment[18].isot, 2) + self.assertEqual(c.segment[18].psot, 14) + self.assertEqual(c.segment[18].tpsot, 1) + self.assertEqual(c.segment[18].tnsot, 0) # SOD: start of data - self.assertEqual(c.segment[19].id, 'SOD') + self.assertEqual(c.segment[19].marker_id, 'SOD') # SOT: start of tile part - self.assertEqual(c.segment[20].Isot, 2) - self.assertEqual(c.segment[20].Psot, 1089) - self.assertEqual(c.segment[20].TPsot, 2) - self.assertEqual(c.segment[20].TNsot, 0) + self.assertEqual(c.segment[20].isot, 2) + self.assertEqual(c.segment[20].psot, 1089) + self.assertEqual(c.segment[20].tpsot, 2) + self.assertEqual(c.segment[20].tnsot, 0) # SOD: start of data - self.assertEqual(c.segment[21].id, 'SOD') + self.assertEqual(c.segment[21].marker_id, 'SOD') # EOC: end of codestream - self.assertEqual(c.segment[22].id, 'EOC') + self.assertEqual(c.segment[22].marker_id, 'EOC') def test_NR_p0_11_dump(self): jfile = os.path.join(data_root, 'input/conformance/p0_11.j2k') @@ -2740,80 +2655,80 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "1" means profile 0 - self.assertEqual(c.segment[1].Rsiz, 1) + self.assertEqual(c.segment[1].rsiz, 1) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 128) - self.assertEqual(c.segment[1].Ysiz, 1) + self.assertEqual(c.segment[1].xsiz, 128) + self.assertEqual(c.segment[1].ysiz, 1) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (128, 128)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (128, 128)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)]) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) - self.assertTrue(c.segment[2].Scod & 4) - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) + self.assertTrue(c.segment[2].scod & 4) + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 0) # levels + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 0) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertTrue(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) + self.assertTrue(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) self.assertEqual(c.segment[2]._precinct_size, [(128, 2)]) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) # none - self.assertEqual(c.segment[3]._guardBits, 3) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) # none + self.assertEqual(c.segment[3]._guard_bits, 3) self.assertEqual(c.segment[3]._mantissa, [0]) self.assertEqual(c.segment[3]._exponent, [8]) # COM: comment # Registration - self.assertEqual(c.segment[4].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[4].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[4].Ccme.decode('latin-1'), + self.assertEqual(c.segment[4].ccme.decode('latin-1'), "Creator: AV-J2K (c) 2000,2001 Algo Vision") # SOT: start of tile part - self.assertEqual(c.segment[5].Isot, 0) - self.assertEqual(c.segment[5].Psot, 118) - self.assertEqual(c.segment[5].TPsot, 0) - self.assertEqual(c.segment[5].TNsot, 1) + self.assertEqual(c.segment[5].isot, 0) + self.assertEqual(c.segment[5].psot, 118) + self.assertEqual(c.segment[5].tpsot, 0) + self.assertEqual(c.segment[5].tnsot, 1) # SOD: start of data - self.assertEqual(c.segment[6].id, 'SOD') + self.assertEqual(c.segment[6].marker_id, 'SOD') # SOP, EPH - sop = [x.id for x in c.segment if x.id == 'SOP'] - eph = [x.id for x in c.segment if x.id == 'EPH'] + sop = [x.marker_id for x in c.segment if x.marker_id == 'SOP'] + eph = [x.marker_id for x in c.segment if x.marker_id == 'EPH'] self.assertEqual(len(sop), 0) self.assertEqual(len(eph), 1) # EOC: end of codestream - self.assertEqual(c.segment[-1].id, 'EOC') + self.assertEqual(c.segment[-1].marker_id, 'EOC') def test_NR_p0_12_dump(self): jfile = os.path.join(data_root, 'input/conformance/p0_12.j2k') @@ -2821,81 +2736,81 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "1" means profile 0 - self.assertEqual(c.segment[1].Rsiz, 1) + self.assertEqual(c.segment[1].rsiz, 1) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 3) - self.assertEqual(c.segment[1].Ysiz, 5) + self.assertEqual(c.segment[1].xsiz, 3) + self.assertEqual(c.segment[1].ysiz, 5) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (3, 5)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (3, 5)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)]) # COD: Coding style default - self.assertTrue(c.segment[2].Scod & 2) - self.assertFalse(c.segment[2].Scod & 4) - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertTrue(c.segment[2].scod & 2) + self.assertFalse(c.segment[2].scod & 4) + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 3) # levels + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 3) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (32, 32)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertTrue(c.segment[2].SPcod[7] & 0x04) + self.assertTrue(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) # none - self.assertEqual(c.segment[3]._guardBits, 3) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) # none + self.assertEqual(c.segment[3]._guard_bits, 3) self.assertEqual(c.segment[3]._mantissa, [0] * 10) self.assertEqual(c.segment[3]._exponent, [8, 9, 9, 10, 9, 9, 10, 9, 9, 10]) # COM: comment # Registration - self.assertEqual(c.segment[4].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[4].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[4].Ccme.decode('latin-1'), + self.assertEqual(c.segment[4].ccme.decode('latin-1'), "Creator: AV-J2K (c) 2000,2001 Algo Vision") # SOT: start of tile part - self.assertEqual(c.segment[5].Isot, 0) - self.assertEqual(c.segment[5].Psot, 162) - self.assertEqual(c.segment[5].TPsot, 0) - self.assertEqual(c.segment[5].TNsot, 1) + self.assertEqual(c.segment[5].isot, 0) + self.assertEqual(c.segment[5].psot, 162) + self.assertEqual(c.segment[5].tpsot, 0) + self.assertEqual(c.segment[5].tnsot, 1) # SOD: start of data - self.assertEqual(c.segment[6].id, 'SOD') + self.assertEqual(c.segment[6].marker_id, 'SOD') # SOP, EPH - sop = [x.id for x in c.segment if x.id == 'SOP'] - eph = [x.id for x in c.segment if x.id == 'EPH'] + sop = [x.marker_id for x in c.segment if x.marker_id == 'SOP'] + eph = [x.marker_id for x in c.segment if x.marker_id == 'EPH'] self.assertEqual(len(sop), 4) self.assertEqual(len(eph), 0) # EOC: end of codestream - self.assertEqual(c.segment[-1].id, 'EOC') + self.assertEqual(c.segment[-1].marker_id, 'EOC') def test_NR_p0_13_dump(self): jfile = os.path.join(data_root, 'input/conformance/p0_13.j2k') @@ -2903,125 +2818,125 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "1" means profile 0 - self.assertEqual(c.segment[1].Rsiz, 1) + self.assertEqual(c.segment[1].rsiz, 1) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 1) - self.assertEqual(c.segment[1].Ysiz, 1) + self.assertEqual(c.segment[1].xsiz, 1) + self.assertEqual(c.segment[1].ysiz, 1) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (1, 1)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (1, 1)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, tuple([8] * 257)) # signed self.assertEqual(c.segment[1]._signed, tuple([False] * 257)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 257) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.RLCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.RLCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 1) # levels + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 1) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (32, 32)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertTrue(c.segment[2].SPcod[7] & 0x0010) + self.assertTrue(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # COC: Coding style component - self.assertEqual(c.segment[3].Ccoc, 2) - self.assertEqual(c.segment[3].SPcoc[0], 1) # levels + self.assertEqual(c.segment[3].ccoc, 2) + self.assertEqual(c.segment[3].spcoc[0], 1) # levels self.assertEqual(tuple(c.segment[3]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[3].SPcoc[3] & 0x01) + self.assertFalse(c.segment[3].spcoc[3] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[3].SPcoc[3] & 0x02) + self.assertFalse(c.segment[3].spcoc[3] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[3].SPcoc[3] & 0x04) + self.assertFalse(c.segment[3].spcoc[3] & 0x04) # Vertically causal context - self.assertFalse(c.segment[3].SPcoc[3] & 0x08) + self.assertFalse(c.segment[3].spcoc[3] & 0x08) # Predictable termination - self.assertFalse(c.segment[3].SPcoc[3] & 0x0010) + self.assertFalse(c.segment[3].spcoc[3] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[3].SPcoc[3] & 0x0020) - self.assertEqual(c.segment[3].SPcoc[4], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) + self.assertFalse(c.segment[3].spcoc[3] & 0x0020) + self.assertEqual(c.segment[3].spcoc[4], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[4].Sqcd & 0x1f, 0) # none - self.assertEqual(c.segment[4]._guardBits, 2) + self.assertEqual(c.segment[4].sqcd & 0x1f, 0) # none + self.assertEqual(c.segment[4]._guard_bits, 2) self.assertEqual(c.segment[4]._mantissa, [0] * 4) self.assertEqual(c.segment[4]._exponent, [8, 9, 9, 10]) # QCC: Quantization component # associated component - self.assertEqual(c.segment[5].Cqcc, 1) - self.assertEqual(c.segment[5]._guardBits, 3) + self.assertEqual(c.segment[5].cqcc, 1) + self.assertEqual(c.segment[5]._guard_bits, 3) # quantization type - self.assertEqual(c.segment[5].Sqcc & 0x1f, 0) # none + self.assertEqual(c.segment[5].sqcc & 0x1f, 0) # none self.assertEqual(c.segment[5]._exponent, [9, 10, 10, 11]) self.assertEqual(c.segment[5]._mantissa, [0, 0, 0, 0]) # QCC: Quantization component # associated component - self.assertEqual(c.segment[6].Cqcc, 2) - self.assertEqual(c.segment[6]._guardBits, 2) + self.assertEqual(c.segment[6].cqcc, 2) + self.assertEqual(c.segment[6]._guard_bits, 2) # quantization type - self.assertEqual(c.segment[6].Sqcc & 0x1f, 0) # none + self.assertEqual(c.segment[6].sqcc & 0x1f, 0) # none self.assertEqual(c.segment[6]._exponent, [9, 10, 10, 11]) self.assertEqual(c.segment[6]._mantissa, [0, 0, 0, 0]) # RGN: region of interest - self.assertEqual(c.segment[7].Crgn, 3) - self.assertEqual(c.segment[7].Srgn, 0) - self.assertEqual(c.segment[7].SPrgn, 11) + self.assertEqual(c.segment[7].crgn, 3) + self.assertEqual(c.segment[7].srgn, 0) + self.assertEqual(c.segment[7].sprgn, 11) # POD: progression order change - self.assertEqual(c.segment[8].RSpod, (0, 0)) - self.assertEqual(c.segment[8].CSpod, (0, 128)) - self.assertEqual(c.segment[8].LYEpod, (1, 1)) - self.assertEqual(c.segment[8].REpod, (33, 33)) - self.assertEqual(c.segment[8].CEpod, (128, 257)) - self.assertEqual(c.segment[8].Ppod, + self.assertEqual(c.segment[8].rspod, (0, 0)) + self.assertEqual(c.segment[8].cspod, (0, 128)) + self.assertEqual(c.segment[8].lyepod, (1, 1)) + self.assertEqual(c.segment[8].repod, (33, 33)) + self.assertEqual(c.segment[8].cdpod, (128, 257)) + self.assertEqual(c.segment[8].ppod, (glymur.core.RLCP, glymur.core.CPRL)) # COM: comment # Registration - self.assertEqual(c.segment[9].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[9].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[9].Ccme.decode('latin-1'), + self.assertEqual(c.segment[9].ccme.decode('latin-1'), "Creator: AV-J2K (c) 2000,2001 Algo Vision") # SOT: start of tile part - self.assertEqual(c.segment[10].Isot, 0) - self.assertEqual(c.segment[10].Psot, 1537) - self.assertEqual(c.segment[10].TPsot, 0) - self.assertEqual(c.segment[10].TNsot, 1) + self.assertEqual(c.segment[10].isot, 0) + self.assertEqual(c.segment[10].psot, 1537) + self.assertEqual(c.segment[10].tpsot, 0) + self.assertEqual(c.segment[10].tnsot, 1) # SOD: start of data - self.assertEqual(c.segment[11].id, 'SOD') + self.assertEqual(c.segment[11].marker_id, 'SOD') # EOC: end of codestream - self.assertEqual(c.segment[12].id, 'EOC') + self.assertEqual(c.segment[12].marker_id, 'EOC') def test_NR_p0_14_dump(self): jfile = os.path.join(data_root, 'input/conformance/p0_14.j2k') @@ -3029,52 +2944,52 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "0" means profile 2 - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 49) - self.assertEqual(c.segment[1].Ysiz, 49) + self.assertEqual(c.segment[1].xsiz, 49) + self.assertEqual(c.segment[1].ysiz, 49) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (49, 49)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (49, 49)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) - self.assertFalse(c.segment[2].Scod & 4) - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) + self.assertFalse(c.segment[2].scod & 4) + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # 1 layer - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # levels + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) # none - self.assertEqual(c.segment[3]._guardBits, 1) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) # none + self.assertEqual(c.segment[3]._guard_bits, 1) self.assertEqual(c.segment[3]._mantissa, [0] * 16) self.assertEqual(c.segment[3]._exponent, [10, 11, 11, 12, 11, 11, 12, 11, 11, 12, 11, 11, 12, @@ -3082,22 +2997,22 @@ class TestSuiteDump(unittest.TestCase): # COM: comment # Registration - self.assertEqual(c.segment[4].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[4].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[4].Ccme.decode('latin-1'), + self.assertEqual(c.segment[4].ccme.decode('latin-1'), "Kakadu-3.0.7") # SOT: start of tile part - self.assertEqual(c.segment[5].Isot, 0) - self.assertEqual(c.segment[5].Psot, 1528) - self.assertEqual(c.segment[5].TPsot, 0) - self.assertEqual(c.segment[5].TNsot, 1) + self.assertEqual(c.segment[5].isot, 0) + self.assertEqual(c.segment[5].psot, 1528) + self.assertEqual(c.segment[5].tpsot, 0) + self.assertEqual(c.segment[5].tnsot, 1) # SOD: start of data - self.assertEqual(c.segment[6].id, 'SOD') + self.assertEqual(c.segment[6].marker_id, 'SOD') # EOC: end of codestream - self.assertEqual(c.segment[7].id, 'EOC') + self.assertEqual(c.segment[7].marker_id, 'EOC') def test_NR_p0_15_dump(self): jfile = os.path.join(data_root, 'input/conformance/p0_15.j2k') @@ -3105,153 +3020,153 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "1" means profile 0 - self.assertEqual(c.segment[1].Rsiz, 1) + self.assertEqual(c.segment[1].rsiz, 1) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 256) - self.assertEqual(c.segment[1].Ysiz, 256) + self.assertEqual(c.segment[1].xsiz, 256) + self.assertEqual(c.segment[1].ysiz, 256) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (128, 128)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (128, 128)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (4,)) # signed self.assertEqual(c.segment[1]._signed, (True,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)]) # COD: Coding style default - self.assertTrue(c.segment[2].Scod & 2) - self.assertFalse(c.segment[2].Scod & 4) - self.assertEqual(c.segment[2].SPcod[0], glymur.core.PCRL) + self.assertTrue(c.segment[2].scod & 2) + self.assertFalse(c.segment[2].scod & 4) + self.assertEqual(c.segment[2].spcod[0], glymur.core.PCRL) self.assertEqual(c.segment[2]._layers, 8) # layers = 8 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 1) # levels + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 1) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 1) # derived - self.assertEqual(c.segment[3]._guardBits, 2) + self.assertEqual(c.segment[3].sqcd & 0x1f, 1) # derived + self.assertEqual(c.segment[3]._guard_bits, 2) self.assertEqual(c.segment[3]._mantissa, [0]) self.assertEqual(c.segment[3]._exponent, [0]) # QCC: Quantization component # associated component - self.assertEqual(c.segment[4].Cqcc, 0) - self.assertEqual(c.segment[4]._guardBits, 2) + self.assertEqual(c.segment[4].cqcc, 0) + self.assertEqual(c.segment[4]._guard_bits, 2) # quantization type - self.assertEqual(c.segment[4].Sqcc & 0x1f, 0) # none + self.assertEqual(c.segment[4].sqcc & 0x1f, 0) # none self.assertEqual(c.segment[4]._mantissa, [0] * 4) self.assertEqual(c.segment[4]._exponent, [4, 5, 5, 6]) # POD: progression order change - self.assertEqual(c.segment[5].RSpod, (0,)) - self.assertEqual(c.segment[5].CSpod, (0,)) - self.assertEqual(c.segment[5].LYEpod, (8,)) - self.assertEqual(c.segment[5].REpod, (33,)) - self.assertEqual(c.segment[5].CEpod, (255,)) - self.assertEqual(c.segment[5].Ppod, (glymur.core.LRCP,)) + self.assertEqual(c.segment[5].rspod, (0,)) + self.assertEqual(c.segment[5].cspod, (0,)) + self.assertEqual(c.segment[5].lyepod, (8,)) + self.assertEqual(c.segment[5].repod, (33,)) + self.assertEqual(c.segment[5].cdpod, (255,)) + self.assertEqual(c.segment[5].ppod, (glymur.core.LRCP,)) # CRG: component registration - self.assertEqual(c.segment[6].Xcrg, (65424,)) - self.assertEqual(c.segment[6].Ycrg, (32558,)) + self.assertEqual(c.segment[6].xcrg, (65424,)) + self.assertEqual(c.segment[6].ycrg, (32558,)) # COM: comment # Registration - self.assertEqual(c.segment[7].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[7].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[7].Ccme.decode('latin-1'), + self.assertEqual(c.segment[7].ccme.decode('latin-1'), "Creator: AV-J2K (c) 2000,2001 Algo Vision") # COM: comment # Registration - self.assertEqual(c.segment[8].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[8].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[8].Ccme.decode('latin-1'), + self.assertEqual(c.segment[8].ccme.decode('latin-1'), "Creator: AV-J2K (c) 2000," + "2001 Algo Vision Technology") # COM: comment # Registration - self.assertEqual(c.segment[9].Rcme, glymur.core.RCME_BINARY) + self.assertEqual(c.segment[9].rcme, glymur.core.RCME_BINARY) # Comment value - self.assertEqual(len(c.segment[9].Ccme), 62) + self.assertEqual(len(c.segment[9].ccme), 62) # TLM: tile-part length - self.assertEqual(c.segment[10].Ztlm, 0) - self.assertEqual(c.segment[10].Ttlm, (0, 1, 2, 3)) - self.assertEqual(c.segment[10].Ptlm, (4267, 2117, 4080, 2081)) + self.assertEqual(c.segment[10].ztlm, 0) + self.assertEqual(c.segment[10].ttlm, (0, 1, 2, 3)) + self.assertEqual(c.segment[10].ptlm, (4267, 2117, 4080, 2081)) # SOT: start of tile part - self.assertEqual(c.segment[11].Isot, 0) - self.assertEqual(c.segment[11].Psot, 4267) - self.assertEqual(c.segment[11].TPsot, 0) - self.assertEqual(c.segment[11].TNsot, 1) + self.assertEqual(c.segment[11].isot, 0) + self.assertEqual(c.segment[11].psot, 4267) + self.assertEqual(c.segment[11].tpsot, 0) + self.assertEqual(c.segment[11].tnsot, 1) # RGN: region of interest - self.assertEqual(c.segment[12].Crgn, 0) - self.assertEqual(c.segment[12].Srgn, 0) - self.assertEqual(c.segment[12].SPrgn, 7) + self.assertEqual(c.segment[12].crgn, 0) + self.assertEqual(c.segment[12].srgn, 0) + self.assertEqual(c.segment[12].sprgn, 7) # SOD: start of data - self.assertEqual(c.segment[13].id, 'SOD') + self.assertEqual(c.segment[13].marker_id, 'SOD') # 16 SOP markers would be here if we were looking for them # SOT: start of tile part - self.assertEqual(c.segment[31].Isot, 1) - self.assertEqual(c.segment[31].Psot, 2117) - self.assertEqual(c.segment[31].TPsot, 0) - self.assertEqual(c.segment[31].TNsot, 1) + self.assertEqual(c.segment[31].isot, 1) + self.assertEqual(c.segment[31].psot, 2117) + self.assertEqual(c.segment[31].tpsot, 0) + self.assertEqual(c.segment[31].tnsot, 1) # SOD: start of data - self.assertEqual(c.segment[32].id, 'SOD') + self.assertEqual(c.segment[32].marker_id, 'SOD') # 16 SOP markers would be here if we were looking for them # SOT: start of tile part - self.assertEqual(c.segment[49].Isot, 2) - self.assertEqual(c.segment[49].Psot, 4080) - self.assertEqual(c.segment[49].TPsot, 0) - self.assertEqual(c.segment[49].TNsot, 1) + self.assertEqual(c.segment[49].isot, 2) + self.assertEqual(c.segment[49].psot, 4080) + self.assertEqual(c.segment[49].tpsot, 0) + self.assertEqual(c.segment[49].tnsot, 1) # SOD: start of data - self.assertEqual(c.segment[50].id, 'SOD') + self.assertEqual(c.segment[50].marker_id, 'SOD') # 16 SOP markers would be here if we were looking for them # SOT: start of tile part - self.assertEqual(c.segment[67].Isot, 3) - self.assertEqual(c.segment[67].Psot, 2081) - self.assertEqual(c.segment[67].TPsot, 0) - self.assertEqual(c.segment[67].TNsot, 1) + self.assertEqual(c.segment[67].isot, 3) + self.assertEqual(c.segment[67].psot, 2081) + self.assertEqual(c.segment[67].tpsot, 0) + self.assertEqual(c.segment[67].tnsot, 1) # SOD: start of data - self.assertEqual(c.segment[68].id, 'SOD') + self.assertEqual(c.segment[68].marker_id, 'SOD') # 16 SOP markers would be here if we were looking for them # EOC: end of codestream - self.assertEqual(c.segment[85].id, 'EOC') + self.assertEqual(c.segment[85].marker_id, 'EOC') def test_NR_p0_16_dump(self): jfile = os.path.join(data_root, 'input/conformance/p0_16.j2k') @@ -3259,67 +3174,67 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "0" means profile 2 - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 128) - self.assertEqual(c.segment[1].Ysiz, 128) + self.assertEqual(c.segment[1].xsiz, 128) + self.assertEqual(c.segment[1].ysiz, 128) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (128, 128)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (128, 128)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)]) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) - self.assertFalse(c.segment[2].Scod & 4) - self.assertEqual(c.segment[2].SPcod[0], glymur.core.RLCP) + self.assertFalse(c.segment[2].scod & 2) + self.assertFalse(c.segment[2].scod & 4) + self.assertEqual(c.segment[2].spcod[0], glymur.core.RLCP) self.assertEqual(c.segment[2]._layers, 3) # layers = 3 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 3) # levels + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 3) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) # none - self.assertEqual(c.segment[3]._guardBits, 2) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) # none + self.assertEqual(c.segment[3]._guard_bits, 2) self.assertEqual(c.segment[3]._mantissa, [0] * 10) self.assertEqual(c.segment[3]._exponent, [8, 9, 9, 10, 9, 9, 10, 9, 9, 10]) # SOT: start of tile part - self.assertEqual(c.segment[4].Isot, 0) - self.assertEqual(c.segment[4].Psot, 7331) - self.assertEqual(c.segment[4].TPsot, 0) - self.assertEqual(c.segment[4].TNsot, 1) + self.assertEqual(c.segment[4].isot, 0) + self.assertEqual(c.segment[4].psot, 7331) + self.assertEqual(c.segment[4].tpsot, 0) + self.assertEqual(c.segment[4].tnsot, 1) # SOD: start of data - self.assertEqual(c.segment[5].id, 'SOD') + self.assertEqual(c.segment[5].marker_id, 'SOD') # EOC: end of codestream - self.assertEqual(c.segment[6].id, 'EOC') + self.assertEqual(c.segment[6].marker_id, 'EOC') def test_NR_p1_01_dump(self): jfile = os.path.join(data_root, 'input/conformance/p1_01.j2k') @@ -3327,99 +3242,99 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "1" means profile 1 - self.assertEqual(c.segment[1].Rsiz, 2) + self.assertEqual(c.segment[1].rsiz, 2) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 127) - self.assertEqual(c.segment[1].Ysiz, 227) + self.assertEqual(c.segment[1].xsiz, 127) + self.assertEqual(c.segment[1].ysiz, 227) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (5, 128)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (5, 128)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (127, 126)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (127, 126)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (1, 101)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (1, 101)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(2, 1)]) # COD: Coding style default - self.assertTrue(c.segment[2].Scod & 2) # SOP - self.assertTrue(c.segment[2].Scod & 4) # EPH - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertTrue(c.segment[2].scod & 2) # SOP + self.assertTrue(c.segment[2].scod & 4) # EPH + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 5) # layers = 5 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 3) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 3) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertTrue(c.segment[2].SPcod[7] & 0x04) + self.assertTrue(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertTrue(c.segment[2].SPcod[7] & 0x0010) + self.assertTrue(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertTrue(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertTrue(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # COC: Coding style component - self.assertEqual(c.segment[3].Ccoc, 0) - self.assertEqual(c.segment[3].SPcoc[0], 3) # level + self.assertEqual(c.segment[3].ccoc, 0) + self.assertEqual(c.segment[3].spcoc[0], 3) # level self.assertEqual(tuple(c.segment[3]._code_block_size), (32, 32)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[3].SPcoc[3] & 0x01) + self.assertFalse(c.segment[3].spcoc[3] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[3].SPcoc[3] & 0x02) + self.assertFalse(c.segment[3].spcoc[3] & 0x02) # Termination on each coding pass - self.assertTrue(c.segment[3].SPcoc[3] & 0x04) + self.assertTrue(c.segment[3].spcoc[3] & 0x04) # Vertically causal context - self.assertFalse(c.segment[3].SPcoc[3] & 0x08) + self.assertFalse(c.segment[3].spcoc[3] & 0x08) # Predictable termination - self.assertTrue(c.segment[3].SPcoc[3] & 0x0010) + self.assertTrue(c.segment[3].spcoc[3] & 0x0010) # Segmentation symbols - self.assertTrue(c.segment[3].SPcoc[3] & 0x0020) - self.assertEqual(c.segment[3].SPcoc[4], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) + self.assertTrue(c.segment[3].spcoc[3] & 0x0020) + self.assertEqual(c.segment[3].spcoc[4], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[4].Sqcd & 0x1f, 0) # none - self.assertEqual(c.segment[4]._guardBits, 3) + self.assertEqual(c.segment[4].sqcd & 0x1f, 0) # none + self.assertEqual(c.segment[4]._guard_bits, 3) self.assertEqual(c.segment[4]._mantissa, [0] * 10) self.assertEqual(c.segment[4]._exponent, [8, 9, 9, 10, 9, 9, 10, 9, 9, 10]) # COM: comment # Registration - self.assertEqual(c.segment[5].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[5].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[5].Ccme.decode('latin-1'), + self.assertEqual(c.segment[5].ccme.decode('latin-1'), "Creator: AV-J2K (c) 2000,2001 Algo Vision") # SOT: start of tile part - self.assertEqual(c.segment[6].Isot, 0) - self.assertEqual(c.segment[6].Psot, 4627) - self.assertEqual(c.segment[6].TPsot, 0) - self.assertEqual(c.segment[6].TNsot, 1) + self.assertEqual(c.segment[6].isot, 0) + self.assertEqual(c.segment[6].psot, 4627) + self.assertEqual(c.segment[6].tpsot, 0) + self.assertEqual(c.segment[6].tnsot, 1) # SOD: start of data - self.assertEqual(c.segment[7].id, 'SOD') + self.assertEqual(c.segment[7].marker_id, 'SOD') # SOP, EPH - sop = [x.id for x in c.segment if x.id == 'SOP'] - eph = [x.id for x in c.segment if x.id == 'EPH'] + sop = [x.marker_id for x in c.segment if x.marker_id == 'SOP'] + eph = [x.marker_id for x in c.segment if x.marker_id == 'EPH'] self.assertEqual(len(sop), 20) self.assertEqual(len(eph), 20) # EOC: end of codestream - self.assertEqual(c.segment[-1].id, 'EOC') + self.assertEqual(c.segment[-1].marker_id, 'EOC') def test_NR_p1_02_dump(self): jfile = os.path.join(data_root, 'input/conformance/p1_02.j2k') @@ -3427,55 +3342,55 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "1" means profile 1 - self.assertEqual(c.segment[1].Rsiz, 2) + self.assertEqual(c.segment[1].rsiz, 2) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 640) - self.assertEqual(c.segment[1].Ysiz, 480) + self.assertEqual(c.segment[1].xsiz, 640) + self.assertEqual(c.segment[1].ysiz, 480) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (640, 480)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (640, 480)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, tuple([8] * 3)) # signed self.assertEqual(c.segment[1]._signed, tuple([False] * 3)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 19) # layers = 19 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 6) # level + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 6) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertTrue(c.segment[2].SPcod[7] & 0x02) + self.assertTrue(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertTrue(c.segment[2].SPcod[7] & 0x08) + self.assertTrue(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) self.assertEqual(c.segment[2]._precinct_size, [(128, 128), (256, 256), (512, 512), (1024, 1024), (2048, 2048), (4096, 4096), (8192, 8192)]) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 2) # expounded - self.assertEqual(c.segment[3]._guardBits, 3) + self.assertEqual(c.segment[3].sqcd & 0x1f, 2) # expounded + self.assertEqual(c.segment[3]._guard_bits, 3) self.assertEqual(c.segment[3]._mantissa, [1814, 1815, 1815, 1817, 1821, 1821, 1827, 1845, 1845, 1868, 1925, 1925, 2007, 32, 32, 131, 2002, 2002, @@ -3486,10 +3401,10 @@ class TestSuiteDump(unittest.TestCase): # QCC: Quantization component # associated component - self.assertEqual(c.segment[4].Cqcc, 1) - self.assertEqual(c.segment[4]._guardBits, 3) + self.assertEqual(c.segment[4].cqcc, 1) + self.assertEqual(c.segment[4]._guard_bits, 3) # quantization type - self.assertEqual(c.segment[4].Sqcc & 0x1f, 2) # expounded + self.assertEqual(c.segment[4].sqcc & 0x1f, 2) # expounded self.assertEqual(c.segment[4]._mantissa, [1814, 1815, 1815, 1817, 1821, 1821, 1827, 1845, 1845, 1868, 1925, 1925, 2007, 32, 32, 131, 2002, 2002, @@ -3500,10 +3415,10 @@ class TestSuiteDump(unittest.TestCase): # QCC: Quantization component # associated component - self.assertEqual(c.segment[5].Cqcc, 2) - self.assertEqual(c.segment[5]._guardBits, 3) + self.assertEqual(c.segment[5].cqcc, 2) + self.assertEqual(c.segment[5]._guard_bits, 3) # quantization type - self.assertEqual(c.segment[5].Sqcc & 0x1f, 2) # expounded + self.assertEqual(c.segment[5].sqcc & 0x1f, 2) # expounded self.assertEqual(c.segment[5]._mantissa, [1814, 1815, 1815, 1817, 1821, 1821, 1827, 1845, 1845, 1868, 1925, 1925, 2007, 32, 32, 131, 2002, 2002, @@ -3514,26 +3429,26 @@ class TestSuiteDump(unittest.TestCase): # COM: comment # Registration - self.assertEqual(c.segment[6].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[6].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[6].Ccme.decode('latin-1'), + self.assertEqual(c.segment[6].ccme.decode('latin-1'), "Creator: AV-J2K (c) 2000,2001 Algo Vision") # SOT: start of tile part - self.assertEqual(c.segment[7].Isot, 0) - self.assertEqual(c.segment[7].Psot, 262838) - self.assertEqual(c.segment[7].TPsot, 0) - self.assertEqual(c.segment[7].TNsot, 1) + self.assertEqual(c.segment[7].isot, 0) + self.assertEqual(c.segment[7].psot, 262838) + self.assertEqual(c.segment[7].tpsot, 0) + self.assertEqual(c.segment[7].tnsot, 1) # PPT: packed packet headers, tile-part header - self.assertEqual(c.segment[8].id, 'PPT') - self.assertEqual(c.segment[8].Zppt, 0) + self.assertEqual(c.segment[8].marker_id, 'PPT') + self.assertEqual(c.segment[8].zppt, 0) # SOD: start of data - self.assertEqual(c.segment[9].id, 'SOD') + self.assertEqual(c.segment[9].marker_id, 'SOD') # EOC: end of codestream - self.assertEqual(c.segment[10].id, 'EOC') + self.assertEqual(c.segment[10].marker_id, 'EOC') def test_NR_p1_03_dump(self): jfile = os.path.join(data_root, 'input/conformance/p1_03.j2k') @@ -3541,91 +3456,91 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "1" means profile 1 - self.assertEqual(c.segment[1].Rsiz, 2) + self.assertEqual(c.segment[1].rsiz, 2) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 1024) - self.assertEqual(c.segment[1].Ysiz, 1024) + self.assertEqual(c.segment[1].xsiz, 1024) + self.assertEqual(c.segment[1].ysiz, 1024) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (1024, 1024)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, tuple([8] * 4)) # signed self.assertEqual(c.segment[1]._signed, tuple([False] * 4)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1), (1, 1), (2, 2), (2, 2)]) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.PCRL) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.PCRL) self.assertEqual(c.segment[2]._layers, 10) # layers = 10 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 6) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 6) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (32, 32)) # Selective arithmetic coding bypass - self.assertTrue(c.segment[2].SPcod[7] & 0x01) + self.assertTrue(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertTrue(c.segment[2].SPcod[7] & 0x04) + self.assertTrue(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # COC: Coding style component - self.assertEqual(c.segment[3].Ccoc, 1) - self.assertEqual(c.segment[3].SPcoc[0], 3) # level + self.assertEqual(c.segment[3].ccoc, 1) + self.assertEqual(c.segment[3].spcoc[0], 3) # level self.assertEqual(tuple(c.segment[3]._code_block_size), (32, 32)) # Selective arithmetic coding bypass - self.assertTrue(c.segment[3].SPcoc[3] & 0x01) + self.assertTrue(c.segment[3].spcoc[3] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[3].SPcoc[3] & 0x02) + self.assertFalse(c.segment[3].spcoc[3] & 0x02) # Termination on each coding pass - self.assertTrue(c.segment[3].SPcoc[3] & 0x04) + self.assertTrue(c.segment[3].spcoc[3] & 0x04) # Vertically causal context - self.assertFalse(c.segment[3].SPcoc[3] & 0x08) + self.assertFalse(c.segment[3].spcoc[3] & 0x08) # Predictable termination - self.assertFalse(c.segment[3].SPcoc[3] & 0x0010) + self.assertFalse(c.segment[3].spcoc[3] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[3].SPcoc[3] & 0x0020) - self.assertEqual(c.segment[3].SPcoc[4], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) + self.assertFalse(c.segment[3].spcoc[3] & 0x0020) + self.assertEqual(c.segment[3].spcoc[4], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) # COC: Coding style component - self.assertEqual(c.segment[4].Ccoc, 3) - self.assertEqual(c.segment[4].SPcoc[0], 6) # level + self.assertEqual(c.segment[4].ccoc, 3) + self.assertEqual(c.segment[4].spcoc[0], 6) # level self.assertEqual(tuple(c.segment[4]._code_block_size), (32, 32)) # Selective arithmetic coding bypass - self.assertTrue(c.segment[4].SPcoc[3] & 0x01) + self.assertTrue(c.segment[4].spcoc[3] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[4].SPcoc[3] & 0x02) + self.assertFalse(c.segment[4].spcoc[3] & 0x02) # Termination on each coding pass - self.assertTrue(c.segment[4].SPcoc[3] & 0x04) + self.assertTrue(c.segment[4].spcoc[3] & 0x04) # Vertically causal context - self.assertFalse(c.segment[4].SPcoc[3] & 0x08) + self.assertFalse(c.segment[4].spcoc[3] & 0x08) # Predictable termination - self.assertFalse(c.segment[4].SPcoc[3] & 0x0010) + self.assertFalse(c.segment[4].spcoc[3] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[4].SPcoc[3] & 0x0020) - self.assertEqual(c.segment[4].SPcoc[4], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) + self.assertFalse(c.segment[4].spcoc[3] & 0x0020) + self.assertEqual(c.segment[4].spcoc[4], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[5].Sqcd & 0x1f, 2) # expounded - self.assertEqual(c.segment[5]._guardBits, 3) + self.assertEqual(c.segment[5].sqcd & 0x1f, 2) # expounded + self.assertEqual(c.segment[5]._guard_bits, 3) self.assertEqual(c.segment[5]._mantissa, [1814, 1815, 1815, 1817, 1821, 1821, 1827, 1845, 1845, 1868, 1925, 1925, 2007, 32, 32, 131, 2002, 2002, @@ -3636,19 +3551,19 @@ class TestSuiteDump(unittest.TestCase): # QCC: Quantization component # associated component - self.assertEqual(c.segment[6].Cqcc, 0) - self.assertEqual(c.segment[6]._guardBits, 3) + self.assertEqual(c.segment[6].cqcc, 0) + self.assertEqual(c.segment[6]._guard_bits, 3) # quantization type - self.assertEqual(c.segment[6].Sqcc & 0x1f, 1) # derived + self.assertEqual(c.segment[6].sqcc & 0x1f, 1) # derived self.assertEqual(c.segment[6]._mantissa, [0]) self.assertEqual(c.segment[6]._exponent, [14]) # QCC: Quantization component # associated component - self.assertEqual(c.segment[7].Cqcc, 3) - self.assertEqual(c.segment[7]._guardBits, 3) + self.assertEqual(c.segment[7].cqcc, 3) + self.assertEqual(c.segment[7]._guard_bits, 3) # quantization type - self.assertEqual(c.segment[7].Sqcc & 0x1f, 0) # none + self.assertEqual(c.segment[7].sqcc & 0x1f, 0) # none self.assertEqual(c.segment[7]._mantissa, [0] * 19) self.assertEqual(c.segment[7]._exponent, [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, @@ -3656,31 +3571,31 @@ class TestSuiteDump(unittest.TestCase): # COM: comment # Registration - self.assertEqual(c.segment[8].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[8].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[8].Ccme.decode('latin-1'), + self.assertEqual(c.segment[8].ccme.decode('latin-1'), "Creator: AV-J2K (c) 2000,2001 Algo Vision") # PPM: packed packet headers, main header - self.assertEqual(c.segment[9].id, 'PPM') - self.assertEqual(c.segment[9].Zppm, 0) + self.assertEqual(c.segment[9].marker_id, 'PPM') + self.assertEqual(c.segment[9].zppm, 0) # TLM (tile-part length) - self.assertEqual(c.segment[10].Ztlm, 0) - self.assertEqual(c.segment[10].Ttlm, (0,)) - self.assertEqual(c.segment[10].Ptlm, (1366780,)) + self.assertEqual(c.segment[10].ztlm, 0) + self.assertEqual(c.segment[10].ttlm, (0,)) + self.assertEqual(c.segment[10].ptlm, (1366780,)) # SOT: start of tile part - self.assertEqual(c.segment[11].Isot, 0) - self.assertEqual(c.segment[11].Psot, 1366780) - self.assertEqual(c.segment[11].TPsot, 0) - self.assertEqual(c.segment[11].TNsot, 1) + self.assertEqual(c.segment[11].isot, 0) + self.assertEqual(c.segment[11].psot, 1366780) + self.assertEqual(c.segment[11].tpsot, 0) + self.assertEqual(c.segment[11].tnsot, 1) # SOD: start of data - self.assertEqual(c.segment[12].id, 'SOD') + self.assertEqual(c.segment[12].marker_id, 'SOD') # EOC: end of codestream - self.assertEqual(c.segment[13].id, 'EOC') + self.assertEqual(c.segment[13].marker_id, 'EOC') def test_NR_p1_04_dump(self): jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') @@ -3688,61 +3603,61 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "1" means profile 1 - self.assertEqual(c.segment[1].Rsiz, 2) + self.assertEqual(c.segment[1].rsiz, 2) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 1024) - self.assertEqual(c.segment[1].Ysiz, 1024) + self.assertEqual(c.segment[1].xsiz, 1024) + self.assertEqual(c.segment[1].ysiz, 1024) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (128, 128)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (128, 128)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (12,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)]) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 3) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 3) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 2) # expounded - self.assertEqual(c.segment[3]._guardBits, 2) + self.assertEqual(c.segment[3].sqcd & 0x1f, 2) # expounded + self.assertEqual(c.segment[3]._guard_bits, 2) self.assertEqual(c.segment[3]._mantissa, [84, 423, 408, 435, 450, 435, 470, 549, 520, 618]) self.assertEqual(c.segment[3]._exponent, [8, 10, 10, 10, 9, 9, 9, 8, 8, 8]) # TLM (tile-part length) - self.assertEqual(c.segment[4].Ztlm, 0) - self.assertIsNone(c.segment[4].Ttlm) - self.assertEqual(c.segment[4].Ptlm, + self.assertEqual(c.segment[4].ztlm, 0) + self.assertIsNone(c.segment[4].ttlm) + self.assertEqual(c.segment[4].ptlm, (350, 356, 402, 245, 402, 564, 675, 283, 317, 299, 330, 333, 346, 403, 839, 667, 328, 349, 274, 325, 501, 561, 756, 710, 779, 620, 628, 675, 600, 66195, @@ -3753,30 +3668,30 @@ class TestSuiteDump(unittest.TestCase): # COM: comment # Registration - self.assertEqual(c.segment[5].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[5].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[5].Ccme.decode('latin-1'), + self.assertEqual(c.segment[5].ccme.decode('latin-1'), "Created by Aware, Inc.") # SOT: start of tile part - self.assertEqual(c.segment[6].Isot, 0) - self.assertEqual(c.segment[6].Psot, 350) - self.assertEqual(c.segment[6].TPsot, 0) - self.assertEqual(c.segment[6].TNsot, 1) + self.assertEqual(c.segment[6].isot, 0) + self.assertEqual(c.segment[6].psot, 350) + self.assertEqual(c.segment[6].tpsot, 0) + self.assertEqual(c.segment[6].tnsot, 1) # SOD: start of data - self.assertEqual(c.segment[7].id, 'SOD') + self.assertEqual(c.segment[7].marker_id, 'SOD') # SOT: start of tile part - self.assertEqual(c.segment[8].Isot, 1) - self.assertEqual(c.segment[8].Psot, 356) - self.assertEqual(c.segment[8].TPsot, 0) - self.assertEqual(c.segment[8].TNsot, 1) + self.assertEqual(c.segment[8].isot, 1) + self.assertEqual(c.segment[8].psot, 356) + self.assertEqual(c.segment[8].tpsot, 0) + self.assertEqual(c.segment[8].tnsot, 1) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[9].Sqcd & 0x1f, 2) # expounded - self.assertEqual(c.segment[9]._guardBits, 2) + self.assertEqual(c.segment[9].sqcd & 0x1f, 2) # expounded + self.assertEqual(c.segment[9]._guard_bits, 2) self.assertEqual(c.segment[9]._mantissa, [75, 1093, 1098, 1115, 1157, 1134, 1186, 1217, 1245, 1248]) @@ -3784,30 +3699,30 @@ class TestSuiteDump(unittest.TestCase): [8, 10, 10, 10, 9, 9, 9, 8, 8, 8]) # SOD: start of data - self.assertEqual(c.segment[10].id, 'SOD') + self.assertEqual(c.segment[10].marker_id, 'SOD') # SOT: start of tile part - self.assertEqual(c.segment[11].Isot, 2) - self.assertEqual(c.segment[11].Psot, 402) - self.assertEqual(c.segment[11].TPsot, 0) - self.assertEqual(c.segment[11].TNsot, 1) + self.assertEqual(c.segment[11].isot, 2) + self.assertEqual(c.segment[11].psot, 402) + self.assertEqual(c.segment[11].tpsot, 0) + self.assertEqual(c.segment[11].tnsot, 1) # and so on # There should be 64 SOD, SOT, QCD segments. - ids = [x.id for x in c.segment if x.id == 'SOT'] + ids = [x.marker_id for x in c.segment if x.marker_id == 'SOT'] self.assertEqual(len(ids), 64) - ids = [x.id for x in c.segment if x.id == 'SOD'] + ids = [x.marker_id for x in c.segment if x.marker_id == 'SOD'] self.assertEqual(len(ids), 64) - ids = [x.id for x in c.segment if x.id == 'QCD'] + ids = [x.marker_id for x in c.segment if x.marker_id == 'QCD'] self.assertEqual(len(ids), 64) # Tiles should be in order, right? - tiles = [x.Isot for x in c.segment if x.id == 'SOT'] + tiles = [x.isot for x in c.segment if x.marker_id == 'SOT'] self.assertEqual(tiles, list(range(64))) # EOC: end of codestream - self.assertEqual(c.segment[-1].id, 'EOC') + self.assertEqual(c.segment[-1].marker_id, 'EOC') def test_NR_p1_05_dump(self): jfile = os.path.join(data_root, 'input/conformance/p1_05.j2k') @@ -3815,50 +3730,50 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "1" means profile 1 - self.assertEqual(c.segment[1].Rsiz, 2) + self.assertEqual(c.segment[1].rsiz, 2) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 529) - self.assertEqual(c.segment[1].Ysiz, 524) + self.assertEqual(c.segment[1].xsiz, 529) + self.assertEqual(c.segment[1].ysiz, 524) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (17, 12)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (17, 12)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (37, 37)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (37, 37)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (8, 2)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (8, 2)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertTrue(c.segment[2].Scod & 2) # sop - self.assertTrue(c.segment[2].Scod & 4) # eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.PCRL) + self.assertTrue(c.segment[2].scod & 2) # sop + self.assertTrue(c.segment[2].scod & 4) # eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.PCRL) self.assertEqual(c.segment[2]._layers, 2) # levels = 2 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 7) # level + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 7) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 8)) # cblk # Selective arithmetic coding bypass - self.assertTrue(c.segment[2].SPcod[7] & 0x01) + self.assertTrue(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertTrue(c.segment[2].SPcod[7] & 0x08) + self.assertTrue(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertTrue(c.segment[2].SPcod[7] & 0x0010) + self.assertTrue(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) self.assertEqual(c.segment[2]._precinct_size, [(16, 16)] * 8) - self.assertEqual(c.segment[3].Sqcd & 0x1f, 2) # expounded - self.assertEqual(c.segment[3]._guardBits, 3) + self.assertEqual(c.segment[3].sqcd & 0x1f, 2) # expounded + self.assertEqual(c.segment[3]._guard_bits, 3) self.assertEqual(c.segment[3]._mantissa, [1813, 1814, 1814, 1814, 1815, 1815, 1817, 1821, 1821, 1827, 1845, 1845, 1868, 1925, 1925, 2007, @@ -3869,33 +3784,33 @@ class TestSuiteDump(unittest.TestCase): # COM: comment # Registration - self.assertEqual(c.segment[4].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[4].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[4].Ccme.decode('latin-1'), + self.assertEqual(c.segment[4].ccme.decode('latin-1'), "Creator: AV-J2K (c) 2000,2001 Algo Vision") # 225 consecutive PPM segments. - zppm = [x.Zppm for x in c.segment[5:230]] + zppm = [x.zppm for x in c.segment[5:230]] self.assertEqual(zppm, list(range(225))) # SOT: start of tile part - self.assertEqual(c.segment[230].Isot, 0) - self.assertEqual(c.segment[230].Psot, 580) - self.assertEqual(c.segment[230].TPsot, 0) - self.assertEqual(c.segment[230].TNsot, 1) + self.assertEqual(c.segment[230].isot, 0) + self.assertEqual(c.segment[230].psot, 580) + self.assertEqual(c.segment[230].tpsot, 0) + self.assertEqual(c.segment[230].tnsot, 1) # 225 total SOT segments - Isot = [x.Isot for x in c.segment if x.id == 'SOT'] - self.assertEqual(Isot, list(range(225))) + isot = [x.isot for x in c.segment if x.marker_id == 'SOT'] + self.assertEqual(isot, list(range(225))) # scads of SOP, EPH segments - sop = [x.id for x in c.segment if x.id == 'SOP'] - eph = [x.id for x in c.segment if x.id == 'EPH'] + sop = [x.marker_id for x in c.segment if x.marker_id == 'SOP'] + eph = [x.marker_id for x in c.segment if x.marker_id == 'EPH'] self.assertEqual(len(sop), 26472) self.assertEqual(len(eph), 0) # EOC: end of codestream - self.assertEqual(c.segment[-1].id, 'EOC') + self.assertEqual(c.segment[-1].marker_id, 'EOC') def test_NR_p1_06_dump(self): jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') @@ -3903,52 +3818,52 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "1" means profile 1 - self.assertEqual(c.segment[1].Rsiz, 2) + self.assertEqual(c.segment[1].rsiz, 2) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 12) - self.assertEqual(c.segment[1].Ysiz, 12) + self.assertEqual(c.segment[1].xsiz, 12) + self.assertEqual(c.segment[1].ysiz, 12) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (3, 3)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (3, 3)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertTrue(c.segment[2].Scod & 2) # sop - self.assertTrue(c.segment[2].Scod & 4) # eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.PCRL) + self.assertTrue(c.segment[2].scod & 2) # sop + self.assertTrue(c.segment[2].scod & 4) # eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.PCRL) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 4) # level + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 4) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (32, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertTrue(c.segment[2].SPcod[7] & 0x08) + self.assertTrue(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertTrue(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertTrue(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 2) # expounded - self.assertEqual(c.segment[3]._guardBits, 3) + self.assertEqual(c.segment[3].sqcd & 0x1f, 2) # expounded + self.assertEqual(c.segment[3]._guard_bits, 3) self.assertEqual(c.segment[3]._mantissa, [1821, 1845, 1845, 1868, 1925, 1925, 2007, 32, 32, 131, 2002, 2002, 1888]) @@ -3958,37 +3873,37 @@ class TestSuiteDump(unittest.TestCase): # COM: comment # Registration - self.assertEqual(c.segment[4].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[4].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[4].Ccme.decode('latin-1'), + self.assertEqual(c.segment[4].ccme.decode('latin-1'), "Creator: AV-J2K (c) 2000,2001 Algo Vision") # SOT: start of tile part - self.assertEqual(c.segment[5].Isot, 0) - self.assertEqual(c.segment[5].Psot, 349) - self.assertEqual(c.segment[5].TPsot, 0) - self.assertEqual(c.segment[5].TNsot, 1) + self.assertEqual(c.segment[5].isot, 0) + self.assertEqual(c.segment[5].psot, 349) + self.assertEqual(c.segment[5].tpsot, 0) + self.assertEqual(c.segment[5].tnsot, 1) # PPT: packed packet headers, tile-part header - self.assertEqual(c.segment[6].id, 'PPT') - self.assertEqual(c.segment[6].Zppt, 0) + self.assertEqual(c.segment[6].marker_id, 'PPT') + self.assertEqual(c.segment[6].zppt, 0) # scads of SOP, EPH segments # 16 SOD segments - sods = [x for x in c.segment if x.id == 'SOD'] + sods = [x for x in c.segment if x.marker_id == 'SOD'] self.assertEqual(len(sods), 16) # 16 PPT segments - ppts = [x for x in c.segment if x.id == 'PPT'] + ppts = [x for x in c.segment if x.marker_id == 'PPT'] self.assertEqual(len(ppts), 16) # 16 SOT segments - Isots = [x.Isot for x in c.segment if x.id == 'SOT'] - self.assertEqual(Isots, list(range(16))) + isots = [x.isot for x in c.segment if x.marker_id == 'SOT'] + self.assertEqual(isots, list(range(16))) # EOC: end of codestream - self.assertEqual(c.segment[-1].id, 'EOC') + self.assertEqual(c.segment[-1].marker_id, 'EOC') def test_NR_p1_07_dump(self): jfile = os.path.join(data_root, 'input/conformance/p1_07.j2k') @@ -3996,102 +3911,102 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "1" means profile 1 - self.assertEqual(c.segment[1].Rsiz, 2) + self.assertEqual(c.segment[1].rsiz, 2) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 12) - self.assertEqual(c.segment[1].Ysiz, 12) + self.assertEqual(c.segment[1].xsiz, 12) + self.assertEqual(c.segment[1].ysiz, 12) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (4, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (4, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (12, 12)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (12, 12)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (4, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (4, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(4, 1), (1, 1)]) # COD: Coding style default - self.assertTrue(c.segment[2].Scod & 2) # sop - self.assertTrue(c.segment[2].Scod & 4) # eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.RPCL) + self.assertTrue(c.segment[2].scod & 2) # sop + self.assertTrue(c.segment[2].scod & 4) # eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.RPCL) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 1) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 1) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) self.assertEqual(c.segment[2]._precinct_size, [(1, 1), (2, 2)]) # COC: Coding style component - self.assertEqual(c.segment[3].Ccoc, 1) - self.assertEqual(c.segment[3].SPcoc[0], 1) # level + self.assertEqual(c.segment[3].ccoc, 1) + self.assertEqual(c.segment[3].spcoc[0], 1) # level self.assertEqual(tuple(c.segment[3]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[3].SPcoc[3] & 0x01) + self.assertFalse(c.segment[3].spcoc[3] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[3].SPcoc[3] & 0x02) + self.assertFalse(c.segment[3].spcoc[3] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[3].SPcoc[3] & 0x04) + self.assertFalse(c.segment[3].spcoc[3] & 0x04) # Vertically causal context - self.assertFalse(c.segment[3].SPcoc[3] & 0x08) + self.assertFalse(c.segment[3].spcoc[3] & 0x08) # Predictable termination - self.assertFalse(c.segment[3].SPcoc[3] & 0x0010) + self.assertFalse(c.segment[3].spcoc[3] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[3].SPcoc[3] & 0x0020) - self.assertEqual(c.segment[3].SPcoc[4], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) + self.assertFalse(c.segment[3].spcoc[3] & 0x0020) + self.assertEqual(c.segment[3].spcoc[4], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) self.assertEqual(c.segment[3]._precinct_size, [(2, 2), (4, 4)]) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[4].Sqcd & 0x1f, 0) # none - self.assertEqual(c.segment[4]._guardBits, 2) + self.assertEqual(c.segment[4].sqcd & 0x1f, 0) # none + self.assertEqual(c.segment[4]._guard_bits, 2) self.assertEqual(c.segment[4]._mantissa, [0] * 4) self.assertEqual(c.segment[4]._exponent, [8, 9, 9, 10]) # COM: comment # Registration - self.assertEqual(c.segment[5].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[5].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[5].Ccme.decode('latin-1'), + self.assertEqual(c.segment[5].ccme.decode('latin-1'), "Creator: AV-J2K (c) 2000,2001 Algo Vision") # SOT: start of tile part - self.assertEqual(c.segment[6].Isot, 0) - self.assertEqual(c.segment[6].Psot, 434) - self.assertEqual(c.segment[6].TPsot, 0) - self.assertEqual(c.segment[6].TNsot, 1) + self.assertEqual(c.segment[6].isot, 0) + self.assertEqual(c.segment[6].psot, 434) + self.assertEqual(c.segment[6].tpsot, 0) + self.assertEqual(c.segment[6].tnsot, 1) # scads of SOP, EPH segments # EOC: end of codestream - self.assertEqual(c.segment[-1].id, 'EOC') + self.assertEqual(c.segment[-1].marker_id, 'EOC') def test_NR_file1_dump(self): jfile = os.path.join(data_root, 'input/conformance/file1.jp2') jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'xml ', 'jp2h', 'xml ', 'jp2c']) - ids = [box.id for box in jp2.box[3].box] + ids = [box.box_id for box in jp2.box[3].box] self.assertEqual(ids, ['ihdr', 'colr']) # Signature box. Check for corruption. @@ -4121,7 +4036,8 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[3].box[1].method, 1) + self.assertEqual(jp2.box[3].box[1].method, + glymur.core.ENUMERATED_COLORSPACE) self.assertEqual(jp2.box[3].box[1].precedence, 0) self.assertEqual(jp2.box[3].box[1].approximation, 1) # JPX exact ?? self.assertEqual(jp2.box[3].box[1].colorspace, glymur.core.SRGB) @@ -4136,10 +4052,10 @@ class TestSuiteDump(unittest.TestCase): jfile = os.path.join(data_root, 'input/conformance/file2.jp2') jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) - ids = [box.id for box in jp2.box[2].box] + ids = [box.box_id for box in jp2.box[2].box] self.assertEqual(ids, ['ihdr', 'colr', 'cdef']) # Signature box. Check for corruption. @@ -4163,7 +4079,8 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[2].box[1].method, 1) + self.assertEqual(jp2.box[2].box[1].method, + glymur.core.ENUMERATED_COLORSPACE) self.assertEqual(jp2.box[2].box[1].precedence, 0) self.assertEqual(jp2.box[2].box[1].approximation, 1) # JPX exact?? self.assertEqual(jp2.box[2].box[1].colorspace, glymur.core.YCC) @@ -4182,10 +4099,10 @@ class TestSuiteDump(unittest.TestCase): jfile = os.path.join(data_root, 'input/conformance/file3.jp2') jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) - ids = [box.id for box in jp2.box[2].box] + ids = [box.box_id for box in jp2.box[2].box] self.assertEqual(ids, ['ihdr', 'colr']) # Signature box. Check for corruption. @@ -4209,29 +4126,30 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[2].box[1].method, 1) + self.assertEqual(jp2.box[2].box[1].method, + glymur.core.ENUMERATED_COLORSPACE) self.assertEqual(jp2.box[2].box[1].precedence, 0) self.assertEqual(jp2.box[2].box[1].approximation, 1) # JPX exact self.assertEqual(jp2.box[2].box[1].colorspace, glymur.core.YCC) # sub-sampling codestream = jp2.get_codestream() - self.assertEqual(codestream.segment[1].XRsiz[0], 1) - self.assertEqual(codestream.segment[1].YRsiz[0], 1) - self.assertEqual(codestream.segment[1].XRsiz[1], 2) - self.assertEqual(codestream.segment[1].YRsiz[1], 2) - self.assertEqual(codestream.segment[1].XRsiz[2], 2) - self.assertEqual(codestream.segment[1].YRsiz[2], 2) + self.assertEqual(codestream.segment[1].xrsiz[0], 1) + self.assertEqual(codestream.segment[1].yrsiz[0], 1) + self.assertEqual(codestream.segment[1].xrsiz[1], 2) + self.assertEqual(codestream.segment[1].yrsiz[1], 2) + self.assertEqual(codestream.segment[1].xrsiz[2], 2) + self.assertEqual(codestream.segment[1].yrsiz[2], 2) def test_NR_file4_dump(self): # One 8-bit component in the sRGB-grey colourspace. jfile = os.path.join(data_root, 'input/conformance/file4.jp2') jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) - ids = [box.id for box in jp2.box[2].box] + ids = [box.box_id for box in jp2.box[2].box] self.assertEqual(ids, ['ihdr', 'colr']) # Signature box. Check for corruption. @@ -4255,7 +4173,8 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[2].box[1].method, 1) + self.assertEqual(jp2.box[2].box[1].method, + glymur.core.ENUMERATED_COLORSPACE) self.assertEqual(jp2.box[2].box[1].precedence, 0) self.assertEqual(jp2.box[2].box[1].approximation, 1) # JPX exact? self.assertEqual(jp2.box[2].box[1].colorspace, glymur.core.GREYSCALE) @@ -4269,10 +4188,10 @@ class TestSuiteDump(unittest.TestCase): jfile = os.path.join(data_root, 'input/conformance/file5.jp2') jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'rreq', 'jp2h', 'jp2c']) - ids = [box.id for box in jp2.box[3].box] + ids = [box.box_id for box in jp2.box[3].box] self.assertEqual(ids, ['ihdr', 'colr', 'colr']) # Signature box. Check for corruption. @@ -4297,7 +4216,8 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[3].box[1].method, 2) # enumerated + self.assertEqual(jp2.box[3].box[1].method, + glymur.core.RESTRICTED_ICC_PROFILE) # enumerated self.assertEqual(jp2.box[3].box[1].precedence, 0) self.assertEqual(jp2.box[3].box[1].approximation, 1) # JPX exact self.assertEqual(jp2.box[3].box[1].icc_profile['Size'], 546) @@ -4305,7 +4225,8 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[3].box[2].method, 1) # enumerated + self.assertEqual(jp2.box[3].box[2].method, + glymur.core.ENUMERATED_COLORSPACE) self.assertEqual(jp2.box[3].box[2].precedence, 1) self.assertEqual(jp2.box[3].box[2].approximation, 1) # JPX exact self.assertIsNone(jp2.box[3].box[2].icc_profile) @@ -4316,10 +4237,10 @@ class TestSuiteDump(unittest.TestCase): jfile = os.path.join(data_root, 'input/conformance/file6.jp2') jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) - ids = [box.id for box in jp2.box[2].box] + ids = [box.box_id for box in jp2.box[2].box] self.assertEqual(ids, ['ihdr', 'colr']) # Signature box. Check for corruption. @@ -4343,7 +4264,8 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[2].box[1].method, 1) + self.assertEqual(jp2.box[2].box[1].method, + glymur.core.ENUMERATED_COLORSPACE) self.assertEqual(jp2.box[2].box[1].precedence, 0) self.assertEqual(jp2.box[2].box[1].approximation, 1) # JPX exact self.assertIsNone(jp2.box[2].box[1].icc_profile) @@ -4359,10 +4281,10 @@ class TestSuiteDump(unittest.TestCase): jfile = os.path.join(data_root, 'input/conformance/file7.jp2') jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'rreq', 'jp2h', 'jp2c']) - ids = [box.id for box in jp2.box[3].box] + ids = [box.box_id for box in jp2.box[3].box] self.assertEqual(ids, ['ihdr', 'colr', 'colr']) # Signature box. Check for corruption. @@ -4376,8 +4298,8 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(jp2.box[1].minor_version, 0) # Reader requirements talk. - self.assertTrue(glymur.core.RREQ_E_SRGB_ENUMERATED_COLORSPACE - in jp2.box[2].standard_flag) + # e-SRGB enumerated colourspace + self.assertTrue(60 in jp2.box[2].standard_flag) # Jp2 Header # Image header @@ -4392,7 +4314,8 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[3].box[1].method, 2) + self.assertEqual(jp2.box[3].box[1].method, + glymur.core.RESTRICTED_ICC_PROFILE) self.assertEqual(jp2.box[3].box[1].precedence, 0) self.assertEqual(jp2.box[3].box[1].approximation, 1) # JPX exact self.assertEqual(jp2.box[3].box[1].icc_profile['Size'], 13332) @@ -4400,7 +4323,8 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[3].box[2].method, 1) # enumerated cspace + self.assertEqual(jp2.box[3].box[2].method, + glymur.core.ENUMERATED_COLORSPACE) self.assertEqual(jp2.box[3].box[2].precedence, 1) self.assertEqual(jp2.box[3].box[2].approximation, 1) # JPX exact self.assertIsNone(jp2.box[3].box[2].icc_profile) @@ -4413,11 +4337,11 @@ class TestSuiteDump(unittest.TestCase): jfile = os.path.join(data_root, 'input/conformance/file8.jp2') jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'xml ', 'jp2c', 'xml ']) - ids = [box.id for box in jp2.box[2].box] + ids = [box.box_id for box in jp2.box[2].box] self.assertEqual(ids, ['ihdr', 'colr']) # Signature box. Check for corruption. @@ -4441,7 +4365,8 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[2].box[1].method, 2) # enumerated + self.assertEqual(jp2.box[2].box[1].method, + glymur.core.RESTRICTED_ICC_PROFILE) # enumerated self.assertEqual(jp2.box[2].box[1].precedence, 0) self.assertEqual(jp2.box[2].box[1].approximation, 1) # JPX exact self.assertEqual(jp2.box[2].box[1].icc_profile['Size'], 414) @@ -4466,10 +4391,10 @@ class TestSuiteDump(unittest.TestCase): jfile = os.path.join(data_root, 'input/conformance/file9.jp2') jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) - ids = [box.id for box in jp2.box[2].box] + ids = [box.box_id for box in jp2.box[2].box] self.assertEqual(ids, ['ihdr', 'pclr', 'cmap', 'colr']) # Signature box. Check for corruption. @@ -4513,7 +4438,8 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[2].box[3].method, 1) + self.assertEqual(jp2.box[2].box[3].method, + glymur.core.ENUMERATED_COLORSPACE) self.assertEqual(jp2.box[2].box[3].precedence, 0) self.assertEqual(jp2.box[2].box[3].approximation, 1) # JPX exact self.assertIsNone(jp2.box[2].box[3].icc_profile) @@ -4527,54 +4453,54 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "3" means profile 3 - self.assertEqual(c.segment[1].Rsiz, 3) + self.assertEqual(c.segment[1].rsiz, 3) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 1920) - self.assertEqual(c.segment[1].Ysiz, 1080) + self.assertEqual(c.segment[1].xsiz, 1920) + self.assertEqual(c.segment[1].ysiz, 1080) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (1920, 1080)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (12, 12, 12)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.CPRL) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.CPRL) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (32, 32)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) self.assertEqual(c.segment[2]._precinct_size[0], (128, 128)) self.assertEqual(c.segment[2]._precinct_size[1:], [(256, 256)] * 5) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 2) - self.assertEqual(c.segment[3]._guardBits, 2) + self.assertEqual(c.segment[3].sqcd & 0x1f, 2) + self.assertEqual(c.segment[3]._guard_bits, 2) self.assertEqual(c.segment[3]._mantissa, [1824, 1776, 1776, 1728, 1792, 1792, 1760, 1872, 1872, 1896, 5, 5, 71, 2003, 2003, 1890]) @@ -4583,30 +4509,30 @@ class TestSuiteDump(unittest.TestCase): 16, 16, 14, 14, 14, 14, 14, 14]) # COC: Coding style component - self.assertEqual(c.segment[4].Ccoc, 1) - self.assertEqual(c.segment[4].SPcoc[0], 5) # level + self.assertEqual(c.segment[4].ccoc, 1) + self.assertEqual(c.segment[4].spcoc[0], 5) # level self.assertEqual(tuple(c.segment[4]._code_block_size), (32, 32)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[4].SPcoc[3] & 0x01) + self.assertFalse(c.segment[4].spcoc[3] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[4].SPcoc[3] & 0x02) + self.assertFalse(c.segment[4].spcoc[3] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[4].SPcoc[3] & 0x04) + self.assertFalse(c.segment[4].spcoc[3] & 0x04) # Vertically causal context - self.assertFalse(c.segment[4].SPcoc[3] & 0x08) + self.assertFalse(c.segment[4].spcoc[3] & 0x08) # Predictable termination - self.assertFalse(c.segment[4].SPcoc[3] & 0x0010) + self.assertFalse(c.segment[4].spcoc[3] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[4].SPcoc[3] & 0x0020) - self.assertEqual(c.segment[4].SPcoc[4], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) + self.assertFalse(c.segment[4].spcoc[3] & 0x0020) + self.assertEqual(c.segment[4].spcoc[4], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) # QCC: Quantization component # associated component - self.assertEqual(c.segment[5].Cqcc, 1) - self.assertEqual(c.segment[5]._guardBits, 2) + self.assertEqual(c.segment[5].cqcc, 1) + self.assertEqual(c.segment[5]._guard_bits, 2) # quantization type - self.assertEqual(c.segment[5].Sqcc & 0x1f, 2) + self.assertEqual(c.segment[5].sqcc & 0x1f, 2) self.assertEqual(c.segment[5]._mantissa, [1824, 1776, 1776, 1728, 1792, 1792, 1760, 1872, 1872, 1896, 5, 5, 71, 2003, 2003, 1890]) @@ -4615,30 +4541,30 @@ class TestSuiteDump(unittest.TestCase): 14, 14, 14]) # COC: Coding style component - self.assertEqual(c.segment[6].Ccoc, 2) - self.assertEqual(c.segment[6].SPcoc[0], 5) # level + self.assertEqual(c.segment[6].ccoc, 2) + self.assertEqual(c.segment[6].spcoc[0], 5) # level self.assertEqual(tuple(c.segment[6]._code_block_size), (32, 32)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[6].SPcoc[3] & 0x01) + self.assertFalse(c.segment[6].spcoc[3] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[6].SPcoc[3] & 0x02) + self.assertFalse(c.segment[6].spcoc[3] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[6].SPcoc[3] & 0x04) + self.assertFalse(c.segment[6].spcoc[3] & 0x04) # Vertically causal context - self.assertFalse(c.segment[6].SPcoc[3] & 0x08) + self.assertFalse(c.segment[6].spcoc[3] & 0x08) # Predictable termination - self.assertFalse(c.segment[6].SPcoc[3] & 0x0010) + self.assertFalse(c.segment[6].spcoc[3] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[6].SPcoc[3] & 0x0020) - self.assertEqual(c.segment[6].SPcoc[4], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) + self.assertFalse(c.segment[6].spcoc[3] & 0x0020) + self.assertEqual(c.segment[6].spcoc[4], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) # QCC: Quantization component # associated component - self.assertEqual(c.segment[7].Cqcc, 2) - self.assertEqual(c.segment[7]._guardBits, 2) + self.assertEqual(c.segment[7].cqcc, 2) + self.assertEqual(c.segment[7]._guard_bits, 2) # quantization type - self.assertEqual(c.segment[7].Sqcc & 0x1f, 2) # none + self.assertEqual(c.segment[7].sqcc & 0x1f, 2) # none self.assertEqual(c.segment[7]._mantissa, [1824, 1776, 1776, 1728, 1792, 1792, 1760, 1872, 1872, 1896, 5, 5, 71, 2003, 2003, 1890]) @@ -4648,29 +4574,29 @@ class TestSuiteDump(unittest.TestCase): # COM: comment # Registration - self.assertEqual(c.segment[8].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[8].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[8].Ccme.decode('latin-1'), + self.assertEqual(c.segment[8].ccme.decode('latin-1'), "Created by OpenJPEG version 1.3.0") # TLM (tile-part length) - self.assertEqual(c.segment[9].Ztlm, 0) - self.assertEqual(c.segment[9].Ttlm, (0, 0, 0)) - self.assertEqual(c.segment[9].Ptlm, (45274, 20838, 8909)) + self.assertEqual(c.segment[9].ztlm, 0) + self.assertEqual(c.segment[9].ttlm, (0, 0, 0)) + self.assertEqual(c.segment[9].ptlm, (45274, 20838, 8909)) # 3 tiles, one for each component - idx = [x.Isot for x in c.segment if x.id == 'SOT'] + idx = [x.isot for x in c.segment if x.marker_id == 'SOT'] self.assertEqual(idx, [0, 0, 0]) - lens = [x.Psot for x in c.segment if x.id == 'SOT'] + lens = [x.psot for x in c.segment if x.marker_id == 'SOT'] self.assertEqual(lens, [45274, 20838, 8909]) - TPsot = [x.TPsot for x in c.segment if x.id == 'SOT'] - self.assertEqual(TPsot, [0, 1, 2]) + tpsot = [x.tpsot for x in c.segment if x.marker_id == 'SOT'] + self.assertEqual(tpsot, [0, 1, 2]) - sods = [x for x in c.segment if x.id == 'SOD'] + sods = [x for x in c.segment if x.marker_id == 'SOD'] self.assertEqual(len(sods), 3) # EOC: end of codestream - self.assertEqual(c.segment[-1].id, 'EOC') + self.assertEqual(c.segment[-1].marker_id, 'EOC') def test_Bretagne2_j2k_dump(self): # Profile 3. @@ -4680,51 +4606,51 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: "3" means profile 3 - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 2592) - self.assertEqual(c.segment[1].Ysiz, 1944) + self.assertEqual(c.segment[1].xsiz, 2592) + self.assertEqual(c.segment[1].ysiz, 1944) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (640, 480)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (640, 480)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 3) # layers = 3 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (32, 32)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) self.assertEqual(c.segment[2]._precinct_size, [(16, 16), (32, 32), (64, 64), (128, 128), (128, 128), (128, 128)]) - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD', 'CME'] expected += ['SOT', 'COC', 'QCC', 'COC', 'QCC', 'SOD'] * 25 expected += ['EOC'] @@ -4737,49 +4663,49 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 512) - self.assertEqual(c.segment[1].Ysiz, 512) + self.assertEqual(c.segment[1].xsiz, 512) + self.assertEqual(c.segment[1].ysiz, 512) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (512, 512)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (512, 512)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (16,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 1) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 2) # layers = 2 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD', 'CME', 'SOT', 'SOD', 'EOC'] self.assertEqual(ids, expected) @@ -4790,49 +4716,49 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 512) - self.assertEqual(c.segment[1].Ysiz, 512) + self.assertEqual(c.segment[1].xsiz, 512) + self.assertEqual(c.segment[1].ysiz, 512) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (512, 512)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (512, 512)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (16,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 1) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 2) # layers = 2 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD', 'CME', 'SOT', 'SOD', 'EOC'] self.assertEqual(ids, expected) @@ -4845,59 +4771,59 @@ class TestSuiteDump(unittest.TestCase): jp2k = Jp2k(jfile) c = jp2k.get_codestream() - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 1420) - self.assertEqual(c.segment[1].Ysiz, 1416) + self.assertEqual(c.segment[1].xsiz, 1420) + self.assertEqual(c.segment[1].ysiz, 1416) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (1420, 1416)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (16,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 1) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 11) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 11) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 4) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 4) self.assertEqual(c.segment[3]._mantissa, [0] * 34) self.assertEqual(c.segment[3]._exponent, [16] + [17, 17, 18] * 11) @@ -4908,58 +4834,58 @@ class TestSuiteDump(unittest.TestCase): jp2k = Jp2k(jfile) c = jp2k.get_codestream() - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD', 'CME'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 512) - self.assertEqual(c.segment[1].Ysiz, 614) + self.assertEqual(c.segment[1].xsiz, 512) + self.assertEqual(c.segment[1].ysiz, 614) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (512, 614)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (512, 614)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (12,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 1) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 2) - self.assertEqual(c.segment[3]._guardBits, 1) + self.assertEqual(c.segment[3].sqcd & 0x1f, 2) + self.assertEqual(c.segment[3]._guard_bits, 1) self.assertEqual(c.segment[3]._mantissa, [442, 422, 422, 403, 422, 422, 403, 472, 472, 487, 591, 591, 676, 558, 558, 485]) @@ -4969,9 +4895,9 @@ class TestSuiteDump(unittest.TestCase): # COM: comment # Registration - self.assertEqual(c.segment[4].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[4].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[4].Ccme.decode('latin-1'), "Kakadu-3.2") + self.assertEqual(c.segment[4].ccme.decode('latin-1'), "Kakadu-3.2") def test_NR_cthead1_dump(self): jfile = os.path.join(data_root, @@ -4979,58 +4905,58 @@ class TestSuiteDump(unittest.TestCase): jp2k = Jp2k(jfile) c = jp2k.get_codestream() - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD', 'CME', 'CME'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 256) - self.assertEqual(c.segment[1].Ysiz, 256) + self.assertEqual(c.segment[1].xsiz, 256) + self.assertEqual(c.segment[1].ysiz, 256) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (256, 256)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (256, 256)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 1) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 1) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 1) self.assertEqual(c.segment[3]._mantissa, [0] * 16) self.assertEqual(c.segment[3]._exponent, [9, 10, 10, 11, 10, 10, 11, 10, 10, 11, 10, 10, 10, @@ -5038,15 +4964,15 @@ class TestSuiteDump(unittest.TestCase): # COM: comment # Registration - self.assertEqual(c.segment[4].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[4].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[4].Ccme.decode('latin-1'), "Kakadu-v6.3.1") + self.assertEqual(c.segment[4].ccme.decode('latin-1'), "Kakadu-v6.3.1") # COM: comment # Registration - self.assertEqual(c.segment[4].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[4].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[4].Ccme.decode('latin-1'), "Kakadu-v6.3.1") + self.assertEqual(c.segment[4].ccme.decode('latin-1'), "Kakadu-v6.3.1") @unittest.skip("fprintf stderr output in r2343.") def test_NR_illegalcolortransform_dump(self): @@ -5055,59 +4981,59 @@ class TestSuiteDump(unittest.TestCase): jp2k = Jp2k(jfile) c = jp2k.get_codestream() - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 1420) - self.assertEqual(c.segment[1].Ysiz, 1416) + self.assertEqual(c.segment[1].xsiz, 1420) + self.assertEqual(c.segment[1].ysiz, 1416) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (1420, 1416)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (16,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 1) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 11) # level + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 11) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 4) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 4) self.assertEqual(c.segment[3]._mantissa, [0] * 34) self.assertEqual(c.segment[3]._exponent, [16] + [17, 17, 18] * 11) @@ -5116,67 +5042,67 @@ class TestSuiteDump(unittest.TestCase): jp2k = Jp2k(jfile) c = jp2k.get_codestream() - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD', 'CME'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 256) - self.assertEqual(c.segment[1].Ysiz, 256) + self.assertEqual(c.segment[1].xsiz, 256) + self.assertEqual(c.segment[1].ysiz, 256) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (256, 256)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (256, 256)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (True, True, True)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default # quantization type - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 2) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 2) self.assertEqual(c.segment[3]._mantissa, [0] * 16) self.assertEqual(c.segment[3]._exponent, [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) # COM: comment # Registration - self.assertEqual(c.segment[4].Rcme, glymur.core.RCME_BINARY) + self.assertEqual(c.segment[4].rcme, glymur.core.RCME_BINARY) # Comment value - self.assertEqual(len(c.segment[4].Ccme), 36) + self.assertEqual(len(c.segment[4].ccme), 36) def test_NR_kakadu_v4_4_openjpegv2_broken_dump(self): jfile = os.path.join(data_root, @@ -5187,52 +5113,52 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 2048) - self.assertEqual(c.segment[1].Ysiz, 2500) + self.assertEqual(c.segment[1].xsiz, 2048) + self.assertEqual(c.segment[1].ysiz, 2500) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (2048, 2500)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (16,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 1) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 12) # layers = 12 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 8) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 8) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 1) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 1) self.assertEqual(c.segment[3]._mantissa, [0] * 25) self.assertEqual(c.segment[3]._exponent, [17, 18, 18, 19, 18, 18, 19, 18, 18, 19, 18, 18, 19, @@ -5240,13 +5166,13 @@ class TestSuiteDump(unittest.TestCase): # COM: comment # Registration - self.assertEqual(c.segment[4].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[4].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[4].Ccme.decode('latin-1'), "Kakadu-v4.4") + self.assertEqual(c.segment[4].ccme.decode('latin-1'), "Kakadu-v4.4") # COM: comment # Registration - self.assertEqual(c.segment[5].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[5].rcme, glymur.core.RCME_ISO_8859_1) # Comment value expected = "Kdu-Layer-Info: log_2{Delta-D(MSE)/[2^16*Delta-L(bytes)]}," expected += " L(bytes)\n" @@ -5262,7 +5188,7 @@ class TestSuiteDump(unittest.TestCase): expected += " -71.9, 1.4e+006\n" expected += " -73.8, 2.0e+006\n" expected += "-256.0, 3.7e+006\n" - self.assertEqual(c.segment[5].Ccme.decode('latin-1'), expected) + self.assertEqual(c.segment[5].ccme.decode('latin-1'), expected) def test_NR_MarkerIsNotCompliant_j2k_dump(self): jfile = os.path.join(data_root, @@ -5272,52 +5198,52 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 1420) - self.assertEqual(c.segment[1].Ysiz, 1416) + self.assertEqual(c.segment[1].xsiz, 1420) + self.assertEqual(c.segment[1].ysiz, 1416) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (1420, 1416)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (16,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 1) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 11) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 11) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 4) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 4) self.assertEqual(c.segment[3]._mantissa, [0] * 34) self.assertEqual(c.segment[3]._exponent, [16, 17, 17, 18, 17, 17, 18, 17, 17, 18, 17, 17, 18, @@ -5332,52 +5258,52 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 1920) - self.assertEqual(c.segment[1].Ysiz, 1080) + self.assertEqual(c.segment[1].xsiz, 1920) + self.assertEqual(c.segment[1].ysiz, 1080) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (1920, 1080)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 2) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 2) self.assertEqual(c.segment[3]._mantissa, [0] * 16) self.assertEqual(c.segment[3]._exponent, [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) @@ -5390,52 +5316,52 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 1920) - self.assertEqual(c.segment[1].Ysiz, 1080) + self.assertEqual(c.segment[1].xsiz, 1920) + self.assertEqual(c.segment[1].ysiz, 1080) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (1920, 1080)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 2) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 2) self.assertEqual(c.segment[3]._mantissa, [0] * 16) self.assertEqual(c.segment[3]._exponent, [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) @@ -5448,52 +5374,52 @@ class TestSuiteDump(unittest.TestCase): # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 1920) - self.assertEqual(c.segment[1].Ysiz, 1080) + self.assertEqual(c.segment[1].xsiz, 1920) + self.assertEqual(c.segment[1].ysiz, 1080) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (1920, 1080)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 2) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 2) self.assertEqual(c.segment[3]._mantissa, [0] * 16) self.assertEqual(c.segment[3]._exponent, [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) @@ -5504,57 +5430,57 @@ class TestSuiteDump(unittest.TestCase): jp2k = Jp2k(jfile) c = jp2k.get_codestream() - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 117) - self.assertEqual(c.segment[1].Ysiz, 117) + self.assertEqual(c.segment[1].xsiz, 117) + self.assertEqual(c.segment[1].ysiz, 117) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (117, 117)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (117, 117)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 4) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 2) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 2) self.assertEqual(c.segment[3]._mantissa, [0] * 16) self.assertEqual(c.segment[3]._exponent, [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) @@ -5565,57 +5491,57 @@ class TestSuiteDump(unittest.TestCase): jp2k = Jp2k(jfile) c = jp2k.get_codestream() - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 117) - self.assertEqual(c.segment[1].Ysiz, 117) + self.assertEqual(c.segment[1].xsiz, 117) + self.assertEqual(c.segment[1].ysiz, 117) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (117, 117)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (117, 117)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 4) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 2) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 2) self.assertEqual(c.segment[3]._mantissa, [0] * 16) self.assertEqual(c.segment[3]._exponent, [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) @@ -5625,57 +5551,57 @@ class TestSuiteDump(unittest.TestCase): jp2k = Jp2k(jfile) c = jp2k.get_codestream() - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD', 'CME'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 512) - self.assertEqual(c.segment[1].Ysiz, 512) + self.assertEqual(c.segment[1].xsiz, 512) + self.assertEqual(c.segment[1].ysiz, 512) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (512, 512)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (512, 512)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (16,)) # signed self.assertEqual(c.segment[1]._signed, (True,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 1) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 16) # layers = 16 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 1) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 1) self.assertEqual(c.segment[3]._mantissa, [0] * 16) self.assertEqual(c.segment[3]._exponent, [18, 19, 19, 20, 19, 19, 20, 19, 19, 20, 19, 19, 20, @@ -5683,9 +5609,9 @@ class TestSuiteDump(unittest.TestCase): # COM: comment # Registration - self.assertEqual(c.segment[4].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[4].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[4].Ccme.decode('latin-1'), + self.assertEqual(c.segment[4].ccme.decode('latin-1'), "Kakadu-2.0.2") def test_NR_test_lossless_j2k_dump(self): @@ -5694,58 +5620,58 @@ class TestSuiteDump(unittest.TestCase): jp2k = Jp2k(jfile) c = jp2k.get_codestream() - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD', 'CME'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 1024) - self.assertEqual(c.segment[1].Ysiz, 1024) + self.assertEqual(c.segment[1].xsiz, 1024) + self.assertEqual(c.segment[1].ysiz, 1024) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (1024, 1024)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (12,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 1) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 2) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 2) self.assertEqual(c.segment[3]._mantissa, [0] * 16) self.assertEqual(c.segment[3]._exponent, [12, 13, 13, 14, 13, 13, 14, 13, 13, 14, 13, 13, 14, @@ -5753,9 +5679,9 @@ class TestSuiteDump(unittest.TestCase): # COM: comment # Registration - self.assertEqual(c.segment[4].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[4].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[4].Ccme.decode('latin-1'), + self.assertEqual(c.segment[4].ccme.decode('latin-1'), "ClearCanvas DICOM OpenJPEG") def test_NR_123_j2c_dump(self): @@ -5763,59 +5689,59 @@ class TestSuiteDump(unittest.TestCase): jp2k = Jp2k(jfile) c = jp2k.get_codestream() - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 1800) - self.assertEqual(c.segment[1].Ysiz, 1800) + self.assertEqual(c.segment[1].xsiz, 1800) + self.assertEqual(c.segment[1].ysiz, 1800) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (1800, 1800)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (16,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 1) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 11) # level + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 11) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 4) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 4) self.assertEqual(c.segment[3]._mantissa, [0] * 34) self.assertEqual(c.segment[3]._exponent, [16] + [17, 17, 18] * 11) @@ -5825,59 +5751,59 @@ class TestSuiteDump(unittest.TestCase): jp2k = Jp2k(jfile) c = jp2k.get_codestream() - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 1800) - self.assertEqual(c.segment[1].Ysiz, 1800) + self.assertEqual(c.segment[1].xsiz, 1800) + self.assertEqual(c.segment[1].ysiz, 1800) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (1800, 1800)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (16,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 1) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 11) # level + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 11) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 4) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 4) self.assertEqual(c.segment[3]._mantissa, [0] * 34) self.assertEqual(c.segment[3]._exponent, [16] + [17, 17, 18] * 11) @@ -5888,60 +5814,60 @@ class TestSuiteDump(unittest.TestCase): jp2k = Jp2k(jfile) c = jp2k.get_codestream() - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD', 'CME'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 2048) - self.assertEqual(c.segment[1].Ysiz, 1556) + self.assertEqual(c.segment[1].xsiz, 2048) + self.assertEqual(c.segment[1].ysiz, 1556) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (2048, 1556)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (12, 12, 12)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 2) # layers = 2 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (32, 32)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) self.assertEqual(c.segment[2]._precinct_size, [(128, 128)] + [(256, 256)] * 5) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 2) - self.assertEqual(c.segment[3]._guardBits, 2) + self.assertEqual(c.segment[3].sqcd & 0x1f, 2) + self.assertEqual(c.segment[3]._guard_bits, 2) self.assertEqual(c.segment[3]._mantissa, [0] * 16) self.assertEqual(c.segment[3]._exponent, [13, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, @@ -5949,9 +5875,9 @@ class TestSuiteDump(unittest.TestCase): # COM: comment # Registration - self.assertEqual(c.segment[4].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[4].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[4].Ccme.decode('latin-1'), + self.assertEqual(c.segment[4].ccme.decode('latin-1'), "DCP-Werkstatt") @unittest.skipIf(sys.hexversion < 0x03020000, @@ -5963,10 +5889,10 @@ class TestSuiteDump(unittest.TestCase): # colr box has bad length. jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) - ids = [box.id for box in jp2.box[2].box] + ids = [box.box_id for box in jp2.box[2].box] self.assertEqual(ids, ['ihdr', 'colr']) # Signature box. Check for corruption. @@ -5990,92 +5916,93 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[2].box[1].method, 1) + self.assertEqual(jp2.box[2].box[1].method, + glymur.core.ENUMERATED_COLORSPACE) self.assertEqual(jp2.box[2].box[1].precedence, 0) self.assertEqual(jp2.box[2].box[1].approximation, 0) # not allowed? self.assertEqual(jp2.box[2].box[1].colorspace, glymur.core.SRGB) c = jp2.box[3].main_header - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'CME', 'COD', 'QCD', 'QCC', 'QCC'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 203) - self.assertEqual(c.segment[1].Ysiz, 152) + self.assertEqual(c.segment[1].xsiz, 203) + self.assertEqual(c.segment[1].ysiz, 152) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (203, 152)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (203, 152)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COM: comment # Registration - self.assertEqual(c.segment[2].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[2].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[2].Ccme.decode('latin-1'), + self.assertEqual(c.segment[2].ccme.decode('latin-1'), "Creator: JasPer Version 1.701.0") # COD: Coding style default - self.assertFalse(c.segment[3].Scod & 2) # no sop - self.assertFalse(c.segment[3].Scod & 4) # no eph - self.assertEqual(c.segment[3].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[3].scod & 2) # no sop + self.assertFalse(c.segment[3].scod & 4) # no eph + self.assertEqual(c.segment[3].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[3]._layers, 1) # layers = 1 - self.assertEqual(c.segment[3].SPcod[3], 1) # mct - self.assertEqual(c.segment[3].SPcod[4], 5) # level + self.assertEqual(c.segment[3].spcod[3], 1) # mct + self.assertEqual(c.segment[3].spcod[4], 5) # level self.assertEqual(tuple(c.segment[3]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[3].SPcod[7] & 0x01) + self.assertFalse(c.segment[3].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[3].SPcod[7] & 0x02) + self.assertFalse(c.segment[3].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[3].SPcod[7] & 0x04) + self.assertFalse(c.segment[3].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[3].SPcod[7] & 0x08) + self.assertFalse(c.segment[3].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[3].SPcod[7] & 0x0010) + self.assertFalse(c.segment[3].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[3].SPcod[7] & 0x0020) - self.assertEqual(c.segment[3].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[3].SPcod), 9) + self.assertFalse(c.segment[3].spcod[7] & 0x0020) + self.assertEqual(c.segment[3].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[3].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[4].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[4]._guardBits, 2) + self.assertEqual(c.segment[4].sqcd & 0x1f, 0) + self.assertEqual(c.segment[4]._guard_bits, 2) self.assertEqual(c.segment[4]._mantissa, [0] * 16) self.assertEqual(c.segment[4]._exponent, [8] + [9, 9, 10] * 5) # QCC: Quantization component # associated component - self.assertEqual(c.segment[5].Cqcc, 1) - self.assertEqual(c.segment[5]._guardBits, 2) + self.assertEqual(c.segment[5].cqcc, 1) + self.assertEqual(c.segment[5]._guard_bits, 2) # quantization type - self.assertEqual(c.segment[5].Sqcc & 0x1f, 0) # none + self.assertEqual(c.segment[5].sqcc & 0x1f, 0) # none self.assertEqual(c.segment[5]._mantissa, [0] * 16) self.assertEqual(c.segment[5]._exponent, [8] + [9, 9, 10] * 5) # QCC: Quantization component # associated component - self.assertEqual(c.segment[6].Cqcc, 2) - self.assertEqual(c.segment[6]._guardBits, 2) + self.assertEqual(c.segment[6].cqcc, 2) + self.assertEqual(c.segment[6]._guard_bits, 2) # quantization type - self.assertEqual(c.segment[6].Sqcc & 0x1f, 0) # none + self.assertEqual(c.segment[6].sqcc & 0x1f, 0) # none self.assertEqual(c.segment[6]._mantissa, [0] * 16) self.assertEqual(c.segment[6]._exponent, [8] + [9, 9, 10] * 5) @@ -6096,10 +6023,10 @@ class TestSuiteDump(unittest.TestCase): # colr box has bad length. jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) - ids = [box.id for box in jp2.box[2].box] + ids = [box.box_id for box in jp2.box[2].box] self.assertEqual(ids, ['ihdr', 'colr']) # Signature box. Check for corruption. @@ -6123,92 +6050,93 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[2].box[1].method, 1) + self.assertEqual(jp2.box[2].box[1].method, + glymur.core.ENUMERATED_COLORSPACE) self.assertEqual(jp2.box[2].box[1].precedence, 0) self.assertEqual(jp2.box[2].box[1].approximation, 0) # JP2 self.assertEqual(jp2.box[2].box[1].colorspace, glymur.core.SRGB) c = jp2.box[3].main_header - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'CME', 'COD', 'QCD', 'QCC', 'QCC'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 203) - self.assertEqual(c.segment[1].Ysiz, 152) + self.assertEqual(c.segment[1].xsiz, 203) + self.assertEqual(c.segment[1].ysiz, 152) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (203, 152)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (203, 152)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COM: comment # Registration - self.assertEqual(c.segment[2].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[2].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[2].Ccme.decode('latin-1'), + self.assertEqual(c.segment[2].ccme.decode('latin-1'), "Creator: JasPer Vers)on 1.701.0") # COD: Coding style default - self.assertFalse(c.segment[3].Scod & 2) # no sop - self.assertFalse(c.segment[3].Scod & 4) # no eph - self.assertEqual(c.segment[3].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[3].scod & 2) # no sop + self.assertFalse(c.segment[3].scod & 4) # no eph + self.assertEqual(c.segment[3].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[3]._layers, 1) # layers = 1 - self.assertEqual(c.segment[3].SPcod[3], 1) # mct - self.assertEqual(c.segment[3].SPcod[4], 5) # level + self.assertEqual(c.segment[3].spcod[3], 1) # mct + self.assertEqual(c.segment[3].spcod[4], 5) # level self.assertEqual(tuple(c.segment[3]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[3].SPcod[7] & 0x01) + self.assertFalse(c.segment[3].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[3].SPcod[7] & 0x02) + self.assertFalse(c.segment[3].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[3].SPcod[7] & 0x04) + self.assertFalse(c.segment[3].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[3].SPcod[7] & 0x08) + self.assertFalse(c.segment[3].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[3].SPcod[7] & 0x0010) + self.assertFalse(c.segment[3].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[3].SPcod[7] & 0x0020) - self.assertEqual(c.segment[3].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[3].SPcod), 9) + self.assertFalse(c.segment[3].spcod[7] & 0x0020) + self.assertEqual(c.segment[3].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[3].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[4].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[4]._guardBits, 2) + self.assertEqual(c.segment[4].sqcd & 0x1f, 0) + self.assertEqual(c.segment[4]._guard_bits, 2) self.assertEqual(c.segment[4]._mantissa, [0] * 16) self.assertEqual(c.segment[4]._exponent, [8] + [9, 9, 10] * 5) # QCC: Quantization component # associated component - self.assertEqual(c.segment[5].Cqcc, 1) - self.assertEqual(c.segment[5]._guardBits, 2) + self.assertEqual(c.segment[5].cqcc, 1) + self.assertEqual(c.segment[5]._guard_bits, 2) # quantization type - self.assertEqual(c.segment[5].Sqcc & 0x1f, 0) # none + self.assertEqual(c.segment[5].sqcc & 0x1f, 0) # none self.assertEqual(c.segment[5]._mantissa, [0] * 16) self.assertEqual(c.segment[5]._exponent, [8] + [9, 9, 10] * 5) # QCC: Quantization component # associated component - self.assertEqual(c.segment[6].Cqcc, 2) - self.assertEqual(c.segment[6]._guardBits, 2) + self.assertEqual(c.segment[6].cqcc, 2) + self.assertEqual(c.segment[6]._guard_bits, 2) # quantization type - self.assertEqual(c.segment[6].Sqcc & 0x1f, 0) # none + self.assertEqual(c.segment[6].sqcc & 0x1f, 0) # none self.assertEqual(c.segment[6]._mantissa, [0] * 16) self.assertEqual(c.segment[6]._exponent, [8] + [9, 9, 10] * 5) @@ -6224,10 +6152,10 @@ class TestSuiteDump(unittest.TestCase): 'input/nonregression/file409752.jp2') jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) - ids = [box.id for box in jp2.box[2].box] + ids = [box.box_id for box in jp2.box[2].box] self.assertEqual(ids, ['ihdr', 'colr']) # Signature box. Check for corruption. @@ -6251,65 +6179,66 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[2].box[1].method, 1) + self.assertEqual(jp2.box[2].box[1].method, + glymur.core.ENUMERATED_COLORSPACE) self.assertEqual(jp2.box[2].box[1].precedence, 0) self.assertEqual(jp2.box[2].box[1].approximation, 0) # JP2 self.assertEqual(jp2.box[2].box[1].colorspace, glymur.core.YCC) c = jp2.box[3].main_header - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 720) - self.assertEqual(c.segment[1].Ysiz, 243) + self.assertEqual(c.segment[1].xsiz, 720) + self.assertEqual(c.segment[1].ysiz, 243) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (720, 243)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (720, 243)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1), (2, 1), (2, 1)]) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (32, 128)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 2) - self.assertEqual(c.segment[3]._guardBits, 1) + self.assertEqual(c.segment[3].sqcd & 0x1f, 2) + self.assertEqual(c.segment[3]._guard_bits, 1) self.assertEqual(c.segment[3]._mantissa, [1816, 1792, 1792, 1724, 1770, 1770, 1724, 1868, 1868, 1892, 3, 3, 69, 2002, 2002, 1889]) @@ -6358,10 +6287,10 @@ class TestSuiteDump(unittest.TestCase): 'input/nonregression/issue104_jpxstream.jp2') jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'rreq', 'jp2h', 'jp2c']) - ids = [box.id for box in jp2.box[3].box] + ids = [box.box_id for box in jp2.box[3].box] self.assertEqual(ids, ['ihdr', 'colr', 'pclr', 'cmap']) # Signature box. Check for corruption. @@ -6375,8 +6304,8 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(jp2.box[1].compatibility_list[2], 'jpx ') # Reader requirements talk. - self.assertTrue(glymur.core.RREQ_UNRESTRICTED_JPEG2000_PART_1 - in jp2.box[2].standard_flag) + # unrestricted jpeg 2000 part 1 + self.assertTrue(5 in jp2.box[2].standard_flag) # Jp2 Header # Image header @@ -6391,7 +6320,8 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[3].box[1].method, 1) # enumerated + self.assertEqual(jp2.box[3].box[1].method, + glymur.core.ENUMERATED_COLORSPACE) self.assertEqual(jp2.box[3].box[1].precedence, 2) self.assertEqual(jp2.box[3].box[1].approximation, 1) # exact self.assertEqual(jp2.box[3].box[1].colorspace, glymur.core.SRGB) @@ -6411,58 +6341,58 @@ class TestSuiteDump(unittest.TestCase): c = jp2.box[4].main_header - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 479) - self.assertEqual(c.segment[1].Ysiz, 203) + self.assertEqual(c.segment[1].xsiz, 479) + self.assertEqual(c.segment[1].ysiz, 203) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (256, 203)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (256, 203)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)]) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.RLCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.RLCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (32, 32)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 2) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 2) self.assertEqual(c.segment[3]._mantissa, [0] * 16) self.assertEqual(c.segment[3]._exponent, [8] + [9, 9, 10] * 5) @@ -6475,10 +6405,10 @@ class TestSuiteDump(unittest.TestCase): warnings.simplefilter("ignore") jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'XML ', 'jp2c']) - ids = [box.id for box in jp2.box[2].box] + ids = [box.box_id for box in jp2.box[2].box] self.assertEqual(ids, ['ihdr', 'colr']) # Signature box. Check for corruption. @@ -6502,7 +6432,8 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[2].box[1].method, 1) + self.assertEqual(jp2.box[2].box[1].method, + glymur.core.ENUMERATED_COLORSPACE) self.assertEqual(jp2.box[2].box[1].precedence, 0) self.assertEqual(jp2.box[2].box[1].approximation, 0) self.assertEqual(jp2.box[2].box[1].colorspace, glymur.core.SRGB) @@ -6511,68 +6442,68 @@ class TestSuiteDump(unittest.TestCase): c = jp2.box[4].main_header - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD', 'CME', 'CME'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 200) - self.assertEqual(c.segment[1].Ysiz, 200) + self.assertEqual(c.segment[1].xsiz, 200) + self.assertEqual(c.segment[1].ysiz, 200) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (200, 200)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (200, 200)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 2) - self.assertEqual(c.segment[3]._guardBits, 1) + self.assertEqual(c.segment[3].sqcd & 0x1f, 2) + self.assertEqual(c.segment[3]._guard_bits, 1) def test_NR_issue206_image_000_dump(self): jfile = os.path.join(data_root, 'input/nonregression/issue206_image-000.jp2') jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'rreq', 'jp2h', 'jp2c']) - ids = [box.id for box in jp2.box[3].box] + ids = [box.box_id for box in jp2.box[3].box] self.assertEqual(ids, ['ihdr', 'colr']) # Signature box. Check for corruption. @@ -6586,8 +6517,8 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(jp2.box[1].compatibility_list[2], 'jpx ') # Reader requirements talk. - self.assertTrue(glymur.core.RREQ_UNRESTRICTED_JPEG2000_PART_1 - in jp2.box[2].standard_flag) + # unrestricted jpeg 2000 part 1 + self.assertTrue(5 in jp2.box[2].standard_flag) # Jp2 Header # Image header @@ -6602,65 +6533,66 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[3].box[1].method, 1) # ICC + self.assertEqual(jp2.box[3].box[1].method, + glymur.core.ENUMERATED_COLORSPACE) self.assertEqual(jp2.box[3].box[1].precedence, 2) self.assertEqual(jp2.box[3].box[1].approximation, 1) # JPX exact self.assertEqual(jp2.box[3].box[1].colorspace, glymur.core.SRGB) c = jp2.box[4].main_header - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 431) - self.assertEqual(c.segment[1].Ysiz, 326) + self.assertEqual(c.segment[1].xsiz, 431) + self.assertEqual(c.segment[1].ysiz, 326) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (256, 256)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (256, 256)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.RLCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.RLCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (32, 32)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 2) - self.assertEqual(c.segment[3]._guardBits, 2) + self.assertEqual(c.segment[3].sqcd & 0x1f, 2) + self.assertEqual(c.segment[3]._guard_bits, 2) self.assertEqual(c.segment[3]._mantissa, [0] * 16) self.assertEqual(c.segment[3]._exponent, [8] + [9, 9, 10] * 5) @@ -6669,13 +6601,13 @@ class TestSuiteDump(unittest.TestCase): 'input/nonregression/Marrin.jp2') jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) - ids = [box.id for box in jp2.box[2].box] + ids = [box.box_id for box in jp2.box[2].box] self.assertEqual(ids, ['ihdr', 'colr', 'cdef', 'res ']) - ids = [box.id for box in jp2.box[2].box[3].box] + ids = [box.box_id for box in jp2.box[2].box[3].box] self.assertEqual(ids, ['resd']) # Signature box. Check for corruption. @@ -6699,7 +6631,8 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[2].box[1].method, 1) + self.assertEqual(jp2.box[2].box[1].method, + glymur.core.ENUMERATED_COLORSPACE) self.assertEqual(jp2.box[2].box[1].precedence, 0) self.assertEqual(jp2.box[2].box[1].approximation, 0) # JP2 self.assertEqual(jp2.box[2].box[1].colorspace, glymur.core.GREYSCALE) @@ -6712,58 +6645,58 @@ class TestSuiteDump(unittest.TestCase): c = jp2.box[3].main_header - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD', 'CME'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 135) - self.assertEqual(c.segment[1].Ysiz, 135) + self.assertEqual(c.segment[1].xsiz, 135) + self.assertEqual(c.segment[1].ysiz, 135) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (135, 135)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (135, 135)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 2) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 2) # layers = 2 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_9x7_IRREVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_9X7_IRREVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 2) - self.assertEqual(c.segment[3]._guardBits, 1) + self.assertEqual(c.segment[3].sqcd & 0x1f, 2) + self.assertEqual(c.segment[3]._guard_bits, 1) self.assertEqual(c.segment[3]._mantissa, [1822, 1770, 1770, 1724, 1792, 1792, 1762, 1868, 1868, 1892, 3, 3, 69, 2002, 2002, 1889]) @@ -6772,9 +6705,9 @@ class TestSuiteDump(unittest.TestCase): # COM: comment # Registration - self.assertEqual(c.segment[4].Rcme, glymur.core.RCME_ISO_8859_1) + self.assertEqual(c.segment[4].rcme, glymur.core.RCME_ISO_8859_1) # Comment value - self.assertEqual(c.segment[4].Ccme.decode('latin-1'), + self.assertEqual(c.segment[4].ccme.decode('latin-1'), "Kakadu-v5.2.1") def test_NR_mem_b2ace68c_1381_dump(self): @@ -6785,10 +6718,10 @@ class TestSuiteDump(unittest.TestCase): warnings.simplefilter("ignore") jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'rreq', 'jp2h', 'jp2c']) - ids = [box.id for box in jp2.box[3].box] + ids = [box.box_id for box in jp2.box[3].box] self.assertEqual(ids, ['ihdr', 'colr', 'pclr', 'cmap']) # Signature box. Check for corruption. @@ -6802,8 +6735,8 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(jp2.box[1].compatibility_list[2], 'jpx ') # Reader requirements talk. - self.assertTrue(glymur.core.RREQ_CMYK_ENUMERATED_COLORSPACE - in jp2.box[2].standard_flag) + # cmyk colourspace + self.assertTrue(55 in jp2.box[2].standard_flag) # Jp2 Header # Image header @@ -6818,7 +6751,8 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[3].box[1].method, 1) # enumerated + self.assertEqual(jp2.box[3].box[1].method, + glymur.core.ENUMERATED_COLORSPACE) self.assertEqual(jp2.box[3].box[1].precedence, 2) self.assertEqual(jp2.box[3].box[1].approximation, 1) # JPX exact self.assertEqual(jp2.box[3].box[1].colorspace, glymur.core.CMYK) @@ -6839,58 +6773,58 @@ class TestSuiteDump(unittest.TestCase): c = jp2.box[4].main_header - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 649) - self.assertEqual(c.segment[1].Ysiz, 865) + self.assertEqual(c.segment[1].xsiz, 649) + self.assertEqual(c.segment[1].ysiz, 865) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (256, 256)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (256, 256)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (1,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)]) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.RLCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.RLCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (32, 32)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 3) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 3) self.assertEqual(c.segment[3]._mantissa, [0] * 16) self.assertEqual(c.segment[3]._exponent, [1] + [2, 2, 3] * 5) @@ -6899,10 +6833,10 @@ class TestSuiteDump(unittest.TestCase): 'input/nonregression/mem-b2b86b74-2753.jp2') jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'rreq', 'jp2h', 'jp2c']) - ids = [box.id for box in jp2.box[3].box] + ids = [box.box_id for box in jp2.box[3].box] self.assertEqual(ids, ['ihdr', 'colr', 'pclr', 'cmap']) # Signature box. Check for corruption. @@ -6916,8 +6850,8 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(jp2.box[1].compatibility_list[2], 'jpx ') # Reader requirements talk. - self.assertTrue(glymur.core.RREQ_UNRESTRICTED_JPEG2000_PART_1 - in jp2.box[2].standard_flag) + # unrestricted jpeg 2000 part 1 + self.assertTrue(5 in jp2.box[2].standard_flag) # Jp2 Header # Image header @@ -6932,7 +6866,8 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[3].box[1].method, 1) # enumerated + self.assertEqual(jp2.box[3].box[1].method, + glymur.core.ENUMERATED_COLORSPACE) self.assertEqual(jp2.box[3].box[1].precedence, 2) self.assertEqual(jp2.box[3].box[1].approximation, 1) # JPX exact self.assertEqual(jp2.box[3].box[1].colorspace, glymur.core.SRGB) @@ -6953,58 +6888,58 @@ class TestSuiteDump(unittest.TestCase): c = jp2.box[4].main_header - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 124) - self.assertEqual(c.segment[1].Ysiz, 46) + self.assertEqual(c.segment[1].xsiz, 124) + self.assertEqual(c.segment[1].ysiz, 46) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (124, 46)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (124, 46)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (4,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)]) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.RLCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.RLCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (32, 32)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 2) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 2) self.assertEqual(c.segment[3]._mantissa, [0] * 16) self.assertEqual(c.segment[3]._exponent, [4] + [5, 5, 6] * 5) @@ -7013,10 +6948,10 @@ class TestSuiteDump(unittest.TestCase): 'input/nonregression/merged.jp2') jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) - ids = [box.id for box in jp2.box[2].box] + ids = [box.box_id for box in jp2.box[2].box] self.assertEqual(ids, ['ihdr', 'colr']) # Signature box. Check for corruption. @@ -7040,77 +6975,78 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[2].box[1].method, 1) + self.assertEqual(jp2.box[2].box[1].method, + glymur.core.ENUMERATED_COLORSPACE) self.assertEqual(jp2.box[2].box[1].precedence, 0) self.assertEqual(jp2.box[2].box[1].approximation, 0) # JP2 self.assertEqual(jp2.box[2].box[1].colorspace, glymur.core.YCC) c = jp2.box[3].main_header - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD', 'POD'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 766) - self.assertEqual(c.segment[1].Ysiz, 576) + self.assertEqual(c.segment[1].xsiz, 766) + self.assertEqual(c.segment[1].ysiz, 576) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (766, 576)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (766, 576)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1), (2, 1), (2, 1)]) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (32, 128)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 1) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 1) self.assertEqual(c.segment[3]._mantissa, [0] * 16) self.assertEqual(c.segment[3]._exponent, [8] + [9, 9, 10] * 5) # POD: progression order change - self.assertEqual(c.segment[4].RSpod, (0, 0)) - self.assertEqual(c.segment[4].CSpod, (0, 1)) - self.assertEqual(c.segment[4].LYEpod, (1, 1)) - self.assertEqual(c.segment[4].REpod, (6, 6)) - self.assertEqual(c.segment[4].CEpod, (1, 3)) + self.assertEqual(c.segment[4].rspod, (0, 0)) + self.assertEqual(c.segment[4].cspod, (0, 1)) + self.assertEqual(c.segment[4].lyepod, (1, 1)) + self.assertEqual(c.segment[4].repod, (6, 6)) + self.assertEqual(c.segment[4].cdpod, (1, 3)) podvals = (glymur.core.LRCP, glymur.core.LRCP) - self.assertEqual(c.segment[4].Ppod, podvals) + self.assertEqual(c.segment[4].ppod, podvals) def test_NR_orb_blue10_lin_jp2_dump(self): jfile = os.path.join(data_root, @@ -7120,10 +7056,10 @@ class TestSuiteDump(unittest.TestCase): warnings.simplefilter("ignore") jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) - ids = [box.id for box in jp2.box[2].box] + ids = [box.box_id for box in jp2.box[2].box] self.assertEqual(ids, ['ihdr', 'colr']) # Signature box. Check for corruption. @@ -7147,7 +7083,8 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[2].box[1].method, 2) # res icc + self.assertEqual(jp2.box[2].box[1].method, + glymur.core.RESTRICTED_ICC_PROFILE) self.assertEqual(jp2.box[2].box[1].precedence, 0) self.assertEqual(jp2.box[2].box[1].approximation, 0) # JP2 self.assertIsNone(jp2.box[2].box[1].icc_profile) @@ -7155,58 +7092,58 @@ class TestSuiteDump(unittest.TestCase): c = jp2.box[3].main_header - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 117) - self.assertEqual(c.segment[1].Ysiz, 117) + self.assertEqual(c.segment[1].xsiz, 117) + self.assertEqual(c.segment[1].ysiz, 117) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (117, 117)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (117, 117)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 4) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 2) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 2) self.assertEqual(c.segment[3]._mantissa, [0] * 16) self.assertEqual(c.segment[3]._exponent, [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) @@ -7219,10 +7156,10 @@ class TestSuiteDump(unittest.TestCase): warnings.simplefilter("ignore") jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c']) - ids = [box.id for box in jp2.box[2].box] + ids = [box.box_id for box in jp2.box[2].box] self.assertEqual(ids, ['ihdr', 'colr']) # Signature box. Check for corruption. @@ -7246,7 +7183,8 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[2].box[1].method, 2) # restricted icc + self.assertEqual(jp2.box[2].box[1].method, + glymur.core.RESTRICTED_ICC_PROFILE) self.assertEqual(jp2.box[2].box[1].precedence, 0) self.assertEqual(jp2.box[2].box[1].approximation, 0) # JP2 self.assertIsNone(jp2.box[2].box[1].icc_profile) @@ -7254,58 +7192,58 @@ class TestSuiteDump(unittest.TestCase): c = jp2.box[3].main_header - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 117) - self.assertEqual(c.segment[1].Ysiz, 117) + self.assertEqual(c.segment[1].xsiz, 117) + self.assertEqual(c.segment[1].ysiz, 117) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (117, 117)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (117, 117)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 4) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 2) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 2) self.assertEqual(c.segment[3]._mantissa, [0] * 16) self.assertEqual(c.segment[3]._exponent, [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) @@ -7315,12 +7253,12 @@ class TestSuiteDump(unittest.TestCase): 'input/nonregression/text_GBR.jp2') jp2 = Jp2k(jfile) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] lst = ['jP ', 'ftyp', 'rreq', 'jp2h', 'uuid', 'uuid', 'uuid', 'uuid', 'jp2c'] self.assertEqual(ids, lst) - ids = [box.id for box in jp2.box[3].box] + ids = [box.box_id for box in jp2.box[3].box] self.assertEqual(ids, ['ihdr', 'colr', 'res ']) # Signature box. Check for corruption. @@ -7348,7 +7286,8 @@ class TestSuiteDump(unittest.TestCase): # Jp2 Header # Colour specification - self.assertEqual(jp2.box[3].box[1].method, 3) # any icc + self.assertEqual(jp2.box[3].box[1].method, + glymur.core.ANY_ICC_PROFILE) self.assertEqual(jp2.box[3].box[1].precedence, 2) self.assertEqual(jp2.box[3].box[1].approximation, 1) # JPX exact self.assertEqual(jp2.box[3].box[1].icc_profile['Size'], 1328) @@ -7362,61 +7301,671 @@ class TestSuiteDump(unittest.TestCase): c = jp2.box[8].main_header - ids = [x.id for x in c.segment] + ids = [x.marker_id for x in c.segment] expected = ['SOC', 'SIZ', 'COD', 'QCD'] self.assertEqual(ids, expected) # SIZ: Image and tile size # Profile: - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual(c.segment[1].Xsiz, 400) - self.assertEqual(c.segment[1].Ysiz, 400) + self.assertEqual(c.segment[1].xsiz, 400) + self.assertEqual(c.segment[1].ysiz, 400) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), (128, 128)) + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (128, 128)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), (0, 0)) + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.RLCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.RLCP) self.assertEqual(c.segment[2]._layers, 6) # layers = 6 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # level + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # level self.assertEqual(tuple(c.segment[2]._code_block_size), (32, 32)) # cblk # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # QCD: Quantization default - self.assertEqual(c.segment[3].Sqcd & 0x1f, 0) - self.assertEqual(c.segment[3]._guardBits, 2) + self.assertEqual(c.segment[3].sqcd & 0x1f, 0) + self.assertEqual(c.segment[3]._guard_bits, 2) self.assertEqual(c.segment[3]._mantissa, [0] * 16) self.assertEqual(c.segment[3]._exponent, [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) + +@unittest.skipIf(glymur.lib.openjpeg.OPENJPEG is None, + "Missing openjpeg library.") +@unittest.skipIf(data_root is None, + "OPJ_DATA_ROOT environment variable not set") +class TestSuite15(unittest.TestCase): + """Suite of tests for libopenjpeg 1.5.1""" + + @classmethod + def setUpClass(cls): + # Monkey patch the package so as to use OPENJPEG instead of OPENJP2 + cls.openjp2 = glymur.lib.openjp2.OPENJP2 + glymur.lib.openjp2.OPENJP2 = None + + @classmethod + def tearDownClass(cls): + # Restore OPENJP2 + glymur.lib.openjp2.OPENJP2 = cls.openjp2 + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_ETS_C0P0_p0_01_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p0_01.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_01.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata, pgxdata) + + def test_ETS_C0P0_p0_02_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p0_02.j2k') + with warnings.catch_warnings(): + # There's a 0xff30 marker segment. Not illegal, but we don't + # really know what to do with it. Just ignore. + warnings.simplefilter("ignore") + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_02.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata, pgxdata) + + def test_ETS_C0P0_p0_09_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p0_09.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=2) + + pgxfile = os.path.join(data_root, + 'baseline/conformance/c0p0_09.pgx') + pgxdata = read_pgx(pgxfile) + + self.assertTrue(peak_tolerance(jpdata, pgxdata) < 4) + self.assertTrue(mse(jpdata, pgxdata) < 1.47) + + def test_ETS_C0P0_p0_11_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p0_11.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, + 'baseline/conformance/c0p0_11.pgx') + pgxdata = read_pgx(pgxfile) + + np.testing.assert_array_equal(jpdata, pgxdata) + + @unittest.skip("fprintf stderr output in r2343.") + def test_ETS_C0P0_p0_12_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p0_12.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, + 'baseline/conformance/c0p0_12.pgx') + pgxdata = read_pgx(pgxfile) + + np.testing.assert_array_equal(jpdata, pgxdata) + + def test_ETS_C0P0_p0_16_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p0_16.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, + 'baseline/conformance/c0p0_16.pgx') + pgxdata = read_pgx(pgxfile) + + np.testing.assert_array_equal(jpdata, pgxdata) + + def test_ETS_C0P1_p1_01_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p1_01.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, + 'baseline/conformance/c0p1_01.pgx') + pgxdata = read_pgx(pgxfile) + + np.testing.assert_array_equal(jpdata, pgxdata) + + def test_ETS_C1P0_p0_01_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p0_01.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_01_0.pgx') + pgxdata = read_pgx(pgxfile) + + np.testing.assert_array_equal(jpdata, pgxdata) + + def test_ETS_C1P0_p0_02_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p0_02.j2k') + with warnings.catch_warnings(): + # There's a 0xff30 marker segment. Not illegal, but we don't + # really know what to do with it. Just ignore. + warnings.simplefilter("ignore") + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_02_0.pgx') + pgxdata = read_pgx(pgxfile) + + np.testing.assert_array_equal(jpdata, pgxdata) + + def test_ETS_C1P0_p0_03_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p0_03.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_03_0.pgx') + pgxdata = read_pgx(pgxfile) + + np.testing.assert_array_equal(jpdata, pgxdata) + + def test_ETS_C1P0_p0_04_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_04_0.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 5) + self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 0.776) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_04_1.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[:, :, 1], pgxdata) < 4) + self.assertTrue(mse(jpdata[:, :, 1], pgxdata) < 0.626) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_04_2.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 6) + self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 1.07) + + def test_ETS_C1P0_p0_08_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p0_08.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=1) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_08_0.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_08_1.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_08_2.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata[:, :, 2], pgxdata) + + def test_ETS_C1P0_p0_09_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p0_09.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_09_0.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata, pgxdata) + + def test_ETS_C1P0_p0_10_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p0_10.j2k') + jp2k = Jp2k(jfile) + with warnings.catch_warnings(): + # This file has an invalid ICC profile + warnings.simplefilter("ignore") + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_10_0.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_10_1.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_10_2.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata[:, :, 2], pgxdata) + + def test_ETS_C1P0_p0_11_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p0_11.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_11_0.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata, pgxdata) + + @unittest.skip("fprintf stderr output in r2343.") + def test_ETS_C1P0_p0_12_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p0_12.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_12_0.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata, pgxdata) + + @unittest.skip("fprintf stderr output in r2343.") + def test_ETS_C1P0_p0_13_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p0_13.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_13_0.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_13_1.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_13_2.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata[:, :, 2], pgxdata) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_13_3.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata[:, :, 3], pgxdata) + + def test_ETS_C1P0_p0_14_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p0_14.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_14_0.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_14_1.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_14_2.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata[:, :, 2], pgxdata) + + def test_ETS_C1P0_p0_15_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p0_15.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_15_0.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata, pgxdata) + + def test_ETS_C1P0_p0_16_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p0_16.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_16_0.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata, pgxdata) + + def test_ETS_C1P1_p1_01_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p1_01.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_01_0.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata, pgxdata) + + def test_ETS_C1P1_p1_02_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p1_02.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_02_0.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 5) + self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 0.765) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_02_1.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[:, :, 1], pgxdata) < 4) + self.assertTrue(mse(jpdata[:, :, 1], pgxdata) < 0.616) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_02_2.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 6) + self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 1.051) + + def test_ETS_C1P1_p1_04_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read() + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_04_0.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata, pgxdata) < 624) + self.assertTrue(mse(jpdata, pgxdata) < 3080) + + @unittest.skip("fprintf stderr output in r2343.") + def test_ETS_C1P1_p1_05_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p1_05.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read() + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_05_0.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 40) + self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 8.458) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_05_1.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[:, :, 1], pgxdata) < 40) + self.assertTrue(mse(jpdata[:, :, 1], pgxdata) < 9.816) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_05_2.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 40) + self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 10.154) + + @unittest.skip("fprintf stderr output in r2343.") + def test_ETS_C1P1_p1_06_j2k(self): + jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read() + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_06_0.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 2) + self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 0.6) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_06_1.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[:, :, 1], pgxdata) < 2) + self.assertTrue(mse(jpdata[:, :, 1], pgxdata) < 0.6) + + pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_06_2.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 2) + self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 0.6) + + def test_ETS_JP2_file1(self): + jfile = os.path.join(data_root, 'input/conformance/file1.jp2') + jp2k = Jp2k(jfile) + jpdata = jp2k.read() + self.assertEqual(jpdata.shape, (512, 768, 3)) + + def test_ETS_JP2_file2(self): + jfile = os.path.join(data_root, 'input/conformance/file2.jp2') + jp2k = Jp2k(jfile) + jpdata = jp2k.read() + self.assertEqual(jpdata.shape, (640, 480, 3)) + + def test_ETS_JP2_file4(self): + jfile = os.path.join(data_root, 'input/conformance/file4.jp2') + jp2k = Jp2k(jfile) + jpdata = jp2k.read() + self.assertEqual(jpdata.shape, (512, 768)) + + def test_ETS_JP2_file5(self): + jfile = os.path.join(data_root, 'input/conformance/file5.jp2') + jp2k = Jp2k(jfile) + jpdata = jp2k.read() + self.assertEqual(jpdata.shape, (512, 768, 3)) + + def test_ETS_JP2_file6(self): + jfile = os.path.join(data_root, 'input/conformance/file6.jp2') + jp2k = Jp2k(jfile) + jpdata = jp2k.read() + self.assertEqual(jpdata.shape, (512, 768)) + + def test_ETS_JP2_file7(self): + jfile = os.path.join(data_root, 'input/conformance/file7.jp2') + jp2k = Jp2k(jfile) + jpdata = jp2k.read() + self.assertEqual(jpdata.shape, (640, 480, 3)) + + def test_ETS_JP2_file8(self): + jfile = os.path.join(data_root, 'input/conformance/file8.jp2') + jp2k = Jp2k(jfile) + jpdata = jp2k.read() + self.assertEqual(jpdata.shape, (400, 700)) + + def test_ETS_JP2_file9(self): + jfile = os.path.join(data_root, 'input/conformance/file9.jp2') + jp2k = Jp2k(jfile) + jpdata = jp2k.read() + self.assertEqual(jpdata.shape, (512, 768, 3)) + + def test_NR_DEC_Bretagne2_j2k_1_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/Bretagne2.j2k') + jp2 = Jp2k(jfile) + data = jp2.read() + self.assertTrue(True) + + def test_NR_DEC__00042_j2k_2_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/_00042.j2k') + jp2 = Jp2k(jfile) + data = jp2.read() + self.assertTrue(True) + + @unittest.skip("fprintf stderr output in r2343.") + def test_NR_DEC_123_j2c_3_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/123.j2c') + jp2 = Jp2k(jfile) + data = jp2.read() + self.assertTrue(True) + + @unittest.skipIf(sys.hexversion < 0x03020000, + "Uses features introduced in 3.2.") + def test_NR_DEC_broken_jp2_4_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/broken.jp2') + with self.assertWarns(UserWarning) as cw: + # colr box has bad length. + jp2 = Jp2k(jfile) + with self.assertRaises(ValueError): + data = jp2.read() + self.assertTrue(True) + + def test_NR_DEC_broken2_jp2_5_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/broken2.jp2') + with self.assertRaises(IOError): + data = Jp2k(jfile).read() + self.assertTrue(True) + + @unittest.skipIf(sys.hexversion < 0x03020000, + "Uses features introduced in 3.2.") + def test_NR_DEC_broken3_jp2_6_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/broken3.jp2') + with self.assertWarns(UserWarning) as cw: + # colr box has bad length. + j = Jp2k(jfile) + + with self.assertRaises(ValueError) as ce: + d = j.read() + + def test_NR_DEC_broken4_jp2_7_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/broken4.jp2') + with self.assertRaises(IOError): + data = Jp2k(jfile).read() + self.assertTrue(True) + + @unittest.skip("fprintf stderr output in r2343.") + def test_NR_DEC_bug_j2c_8_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/bug.j2c') + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_buxI_j2k_9_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/buxI.j2k') + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_buxR_j2k_10_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/buxR.j2k') + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_Cannotreaddatawithnosizeknown_j2k_11_decode(self): + relpath = 'input/nonregression/Cannotreaddatawithnosizeknown.j2k' + jfile = os.path.join(data_root, relpath) + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_cthead1_j2k_12_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/cthead1.j2k') + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_CT_Phillips_JPEG2K_Decompr_Problem_j2k_13_decode(self): + relpath = 'input/nonregression/CT_Phillips_JPEG2K_Decompr_Problem.j2k' + jfile = os.path.join(data_root, relpath) + data = Jp2k(jfile).read() + self.assertTrue(True) + + @unittest.skip("fprintf stderr output in r2343.") + def test_NR_DEC_illegalcolortransform_j2k_14_decode(self): + # Stream too short, expected SOT. + jfile = os.path.join(data_root, + 'input/nonregression/illegalcolortransform.j2k') + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_j2k32_j2k_15_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/j2k32.j2k') + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_kakadu_v4_4_openjpegv2_broken_j2k_16_decode(self): + relpath = 'input/nonregression/kakadu_v4-4_openjpegv2_broken.j2k' + jfile = os.path.join(data_root, relpath) + with warnings.catch_warnings(): + # This file has an invalid ICC profile + warnings.simplefilter("ignore") + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_MarkerIsNotCompliant_j2k_17_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/MarkerIsNotCompliant.j2k') + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_Marrin_jp2_18_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/Marrin.jp2') + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_movie_00000_j2k_20_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/movie_00000.j2k') + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_movie_00001_j2k_21_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/movie_00001.j2k') + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_movie_00002_j2k_22_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/movie_00002.j2k') + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_orb_blue_lin_j2k_j2k_23_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/orb-blue10-lin-j2k.j2k') + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_orb_blue_win_j2k_j2k_24_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/orb-blue10-win-j2k.j2k') + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_orb_blue_lin_jp2_25_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/orb-blue10-lin-jp2.jp2') + with warnings.catch_warnings(): + # This file has an invalid ICC profile + warnings.simplefilter("ignore") + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_orb_blue_win_jp2_26_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/orb-blue10-win-jp2.jp2') + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_relax_jp2_27_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/relax.jp2') + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_test_lossless_j2k_28_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/test_lossless.j2k') + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_issue104_jpxstream_jp2_33_decode(self): + jfile = os.path.join(data_root, + 'input/nonregression/issue104_jpxstream.jp2') + data = Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_file_409752_jp2_40_decode(self): + jfile = os.path.join(data_root, 'input/nonregression/file409752.jp2') + j = Jp2k(jfile) + with self.assertRaises(RuntimeError) as ce: + data = j.read() + if __name__ == "__main__": unittest.main() diff --git a/glymur/test/test_opj_suite_neg.py b/glymur/test/test_opj_suite_neg.py index 5754e16..8a89d09 100644 --- a/glymur/test/test_opj_suite_neg.py +++ b/glymur/test/test_opj_suite_neg.py @@ -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 @@ -57,7 +58,7 @@ def read_image(infile): return data -@unittest.skipIf(glymur.lib.openjp2._OPENJP2 is None, +@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None, "Missing openjp2 library.") @unittest.skipIf(no_read_backend, no_read_backend_msg) @unittest.skipIf(data_root is None, @@ -65,12 +66,13 @@ def read_image(infile): class TestSuiteNegative(unittest.TestCase): def setUp(self): - self.jp2file = pkg_resources.resource_filename(glymur.__name__, - "data/nemo.jp2") + self.jp2file = glymur.data.nemo() + self.j2kfile = glymur.data.goodstuff() 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. @@ -94,7 +96,7 @@ class TestSuiteNegative(unittest.TestCase): # Verify that the last segment returned in the codestream is SOD, # not EOC. Codestream parsing should stop when we try to jump to # the end of SOT. - self.assertEqual(c.segment[-1].id, 'SOD') + self.assertEqual(c.segment[-1].marker_id, 'SOD') @unittest.skipIf(sys.hexversion < 0x03020000, "Uses features introduced in 3.2.") @@ -109,7 +111,7 @@ class TestSuiteNegative(unittest.TestCase): # Verify that the last segment returned in the codestream is SOD, # not EOC. Codestream parsing should stop when we try to jump to # the end of SOT. - self.assertEqual(c.segment[-1].id, 'SOD') + self.assertEqual(c.segment[-1].marker_id, 'SOD') @unittest.skipIf(sys.hexversion < 0x03020000, "Uses features introduced in 3.2.") @@ -124,8 +126,9 @@ class TestSuiteNegative(unittest.TestCase): # Verify that the last segment returned in the codestream is SOD, # not EOC. Codestream parsing should stop when we try to jump to # the end of SOT. - self.assertEqual(c.segment[-1].id, 'SOD') + 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,29 +157,32 @@ 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.jp2file) - data = ifile.read(reduce=3) + ifile = Jp2k(self.j2kfile) + data = ifile.read(rlevel=2) with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: ofile = Jp2k(tfile.name, 'wb') 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.jp2file) - data = ifile.read(reduce=3) + ifile = Jp2k(self.j2kfile) + data = ifile.read(rlevel=2) with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: ofile = Jp2k(tfile.name, 'wb') 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. - ifile = Jp2k(self.jp2file) - data = ifile.read(reduce=3) + ifile = Jp2k(self.j2kfile) + data = ifile.read(rlevel=2) with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: ofile = Jp2k(tfile.name, 'wb') with self.assertRaises(IOError) as ce: diff --git a/glymur/test/test_opj_suite_write.py b/glymur/test/test_opj_suite_write.py index 50e0e48..4023239 100644 --- a/glymur/test/test_opj_suite_write.py +++ b/glymur/test/test_opj_suite_write.py @@ -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,7 +58,8 @@ def read_image(infile): return data -@unittest.skipIf(glymur.lib.openjp2._OPENJP2 is None, +@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) @unittest.skipIf(data_root is None, @@ -83,50 +85,50 @@ class TestSuiteWrite(unittest.TestCase): # SIZ: Image and tile size # Profile: "0" means profile 2 - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual((c.segment[1].Xsiz, c.segment[1].Ysiz), + self.assertEqual((c.segment[1].xsiz, c.segment[1].ysiz), (640, 480)) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (640, 480)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 3) # layers = 3 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # levels + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblksz # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) def test_NR_ENC_Bretagne1_ppm_2_encode(self): # NR-ENC-Bretagne1.ppm-2-encode @@ -141,50 +143,50 @@ class TestSuiteWrite(unittest.TestCase): # SIZ: Image and tile size # Profile: "0" means profile 2 - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual((c.segment[1].Xsiz, c.segment[1].Ysiz), + self.assertEqual((c.segment[1].xsiz, c.segment[1].ysiz), (640, 480)) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (640, 480)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 3) # layers = 3 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 1) # levels + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 1) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblksz # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) def test_NR_ENC_Bretagne1_ppm_3_encode(self): # NR-ENC-Bretagne1.ppm-3-encode @@ -200,49 +202,49 @@ class TestSuiteWrite(unittest.TestCase): # SIZ: Image and tile size # Profile: "0" means profile 2 - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual((c.segment[1].Xsiz, c.segment[1].Ysiz), + self.assertEqual((c.segment[1].xsiz, c.segment[1].ysiz), (640, 480)) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (640, 480)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 3) # layers = 3 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # levels + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (16, 16)) # cblksz # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) self.assertEqual(c.segment[2]._precinct_size, [(2, 2), (4, 4), (8, 8), (16, 16), (32, 32), (64, 64)]) @@ -263,49 +265,49 @@ class TestSuiteWrite(unittest.TestCase): # SIZ: Image and tile size # Profile: "0" means profile 2 - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual((c.segment[1].Xsiz, c.segment[1].Ysiz), + self.assertEqual((c.segment[1].xsiz, c.segment[1].ysiz), (data.shape[1], data.shape[0])) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size. Reported as XY, not RC. - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (640, 480)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 3) # layers = 3 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # levels + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (32, 32)) # cblksz # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) self.assertEqual(c.segment[2]._precinct_size, [(16, 16), (32, 32), (64, 64)] + [(128, 128)] * 3) @@ -321,50 +323,50 @@ class TestSuiteWrite(unittest.TestCase): # SIZ: Image and tile size # Profile: "0" means profile 2 - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual((c.segment[1].Xsiz, c.segment[1].Ysiz), + self.assertEqual((c.segment[1].xsiz, c.segment[1].ysiz), (data.shape[1], data.shape[0])) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (127, 127)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.PCRL) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.PCRL) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # levels + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblksz # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) def test_NR_ENC_Bretagne2_ppm_6_encode(self): # NR-ENC-Bretagne2.ppm-6-encode @@ -378,53 +380,53 @@ class TestSuiteWrite(unittest.TestCase): # SIZ: Image and tile size # Profile: "0" means profile 2 - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual((c.segment[1].Xsiz, c.segment[1].Ysiz), + self.assertEqual((c.segment[1].xsiz, c.segment[1].ysiz), (5183, 3887)) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (5183, 3887)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(2, 2)] * 3) # COD: Coding style default - self.assertTrue(c.segment[2].Scod & 2) # sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertTrue(c.segment[2].scod & 2) # sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # levels + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblksz # Selective arithmetic coding bypass - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # Reset context probabilities - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # 18 SOP segments. - nsops = [x.Nsop for x in c.segment if x.id == 'SOP'] + nsops = [x.nsop for x in c.segment if x.marker_id == 'SOP'] self.assertEqual(nsops, list(range(18))) def test_NR_ENC_Bretagne2_ppm_7_encode(self): @@ -438,53 +440,53 @@ class TestSuiteWrite(unittest.TestCase): # SIZ: Image and tile size # Profile: "0" means profile 2 - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual((c.segment[1].Xsiz, c.segment[1].Ysiz), + self.assertEqual((c.segment[1].xsiz, c.segment[1].ysiz), (2592, 1944)) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (2592, 1944)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertTrue(c.segment[2].Scod & 4) # eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertTrue(c.segment[2].scod & 4) # eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # levels + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblksz # Selective arithmetic coding BYPASS - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # RESET context probabilities (RESET) - self.assertTrue(c.segment[2].SPcod[7] & 0x02) + self.assertTrue(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass, RESTART(TERMALL) - self.assertTrue(c.segment[2].SPcod[7] & 0x04) + self.assertTrue(c.segment[2].spcod[7] & 0x04) # Vertically causal context (VSC) - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination, ERTERM(SEGTERM) - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols, SEGMARK(SEGSYSM) - self.assertTrue(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertTrue(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) # 18 EPH segments. - ephs = [x for x in c.segment if x.id == 'EPH'] + ephs = [x for x in c.segment if x.marker_id == 'EPH'] self.assertEqual(len(ephs), 18) def test_NR_ENC_Bretagne2_ppm_8_encode(self): @@ -498,51 +500,51 @@ class TestSuiteWrite(unittest.TestCase): # SIZ: Image and tile size # Profile: "0" means profile 2 - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual((c.segment[1].Xsiz, c.segment[1].Ysiz), + self.assertEqual((c.segment[1].xsiz, c.segment[1].ysiz), (2742, 2244)) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (150, 300)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (2742, 2244)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # levels + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblksz # Selective arithmetic coding BYPASS - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # RESET context probabilities (RESET) - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass, RESTART(TERMALL) - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context (VSC) - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination, ERTERM(SEGTERM) - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols, SEGMARK(SEGSYSM) - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) def test_NR_ENC_Cevennes1_bmp_9_encode(self): infile = os.path.join(data_root, 'input/nonregression/Cevennes1.bmp') @@ -555,50 +557,50 @@ class TestSuiteWrite(unittest.TestCase): # SIZ: Image and tile size # Profile: "0" means profile 2 - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual((c.segment[1].Xsiz, c.segment[1].Ysiz), + self.assertEqual((c.segment[1].xsiz, c.segment[1].ysiz), (2592, 1944)) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (2592, 1944)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # levels + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblksz # Selective arithmetic coding BYPASS - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # RESET context probabilities (RESET) - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass, RESTART(TERMALL) - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context (VSC) - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination, ERTERM(SEGTERM) - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols, SEGMARK(SEGSYSM) - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) def test_NR_ENC_Cevennes2_ppm_10_encode(self): infile = os.path.join(data_root, 'input/nonregression/Cevennes2.ppm') @@ -611,50 +613,50 @@ class TestSuiteWrite(unittest.TestCase): # SIZ: Image and tile size # Profile: "0" means profile 2 - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual((c.segment[1].Xsiz, c.segment[1].Ysiz), + self.assertEqual((c.segment[1].xsiz, c.segment[1].ysiz), (640, 480)) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (640, 480)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # levels + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblksz # Selective arithmetic coding BYPASS - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # RESET context probabilities (RESET) - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass, RESTART(TERMALL) - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context (VSC) - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination, ERTERM(SEGTERM) - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols, SEGMARK(SEGSYSM) - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) def test_NR_ENC_Rome_bmp_11_encode(self): infile = os.path.join(data_root, 'input/nonregression/Rome.bmp') @@ -663,11 +665,11 @@ class TestSuiteWrite(unittest.TestCase): jp2 = Jp2k(tfile.name, 'wb') jp2.write(data, psnr=[30, 35, 50], prog='LRCP', numres=3) - ids = [box.id for box in jp2.box] + ids = [box.box_id for box in jp2.box] lst = ['jP ', 'ftyp', 'jp2h', 'jp2c'] self.assertEqual(ids, lst) - ids = [box.id for box in jp2.box[2].box] + ids = [box.box_id for box in jp2.box[2].box] self.assertEqual(ids, ['ihdr', 'colr']) # Signature box. Check for corruption. @@ -701,51 +703,51 @@ class TestSuiteWrite(unittest.TestCase): # SIZ: Image and tile size # Profile: "0" means profile 2 - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual((c.segment[1].Xsiz, c.segment[1].Ysiz), + self.assertEqual((c.segment[1].xsiz, c.segment[1].ysiz), (640, 480)) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (640, 480)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (8, 8, 8)) # signed self.assertEqual(c.segment[1]._signed, (False, False, False)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)] * 3) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 3) # layers = 3 - self.assertEqual(c.segment[2].SPcod[3], 1) # mct - self.assertEqual(c.segment[2].SPcod[4], 2) # levels + self.assertEqual(c.segment[2].spcod[3], 1) # mct + self.assertEqual(c.segment[2].spcod[4], 2) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblksz # Selective arithmetic coding BYPASS - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # RESET context probabilities (RESET) - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass, RESTART(TERMALL) - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context (VSC) - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination, ERTERM(SEGTERM) - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols, SEGMARK(SEGSYSM) - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) @unittest.skip("Known failure in openjpeg test suite.") def test_NR_ENC_random_issue_0005_tif_12_encode(self): @@ -762,50 +764,50 @@ class TestSuiteWrite(unittest.TestCase): # SIZ: Image and tile size # Profile: "0" means profile 2 - self.assertEqual(c.segment[1].Rsiz, 0) + self.assertEqual(c.segment[1].rsiz, 0) # Reference grid size - self.assertEqual((c.segment[1].Xsiz, c.segment[1].Ysiz), + self.assertEqual((c.segment[1].xsiz, c.segment[1].ysiz), (1024, 1024)) # Reference grid offset - self.assertEqual((c.segment[1].XOsiz, c.segment[1].YOsiz), (0, 0)) + self.assertEqual((c.segment[1].xosiz, c.segment[1].yosiz), (0, 0)) # Tile size - self.assertEqual((c.segment[1].XTsiz, c.segment[1].YTsiz), + self.assertEqual((c.segment[1].xtsiz, c.segment[1].ytsiz), (1024, 1024)) # Tile offset - self.assertEqual((c.segment[1].XTOsiz, c.segment[1].YTOsiz), + self.assertEqual((c.segment[1].xtosiz, c.segment[1].ytosiz), (0, 0)) # bitdepth self.assertEqual(c.segment[1]._bitdepth, (16,)) # signed self.assertEqual(c.segment[1]._signed, (False,)) # subsampling - self.assertEqual(list(zip(c.segment[1].XRsiz, c.segment[1].YRsiz)), + self.assertEqual(list(zip(c.segment[1].xrsiz, c.segment[1].yrsiz)), [(1, 1)]) # COD: Coding style default - self.assertFalse(c.segment[2].Scod & 2) # no sop - self.assertFalse(c.segment[2].Scod & 4) # no eph - self.assertEqual(c.segment[2].SPcod[0], glymur.core.LRCP) + self.assertFalse(c.segment[2].scod & 2) # no sop + self.assertFalse(c.segment[2].scod & 4) # no eph + self.assertEqual(c.segment[2].spcod[0], glymur.core.LRCP) self.assertEqual(c.segment[2]._layers, 1) # layers = 1 - self.assertEqual(c.segment[2].SPcod[3], 0) # mct - self.assertEqual(c.segment[2].SPcod[4], 5) # levels + self.assertEqual(c.segment[2].spcod[3], 0) # mct + self.assertEqual(c.segment[2].spcod[4], 5) # levels self.assertEqual(tuple(c.segment[2]._code_block_size), (64, 64)) # cblksz # Selective arithmetic coding BYPASS - self.assertFalse(c.segment[2].SPcod[7] & 0x01) + self.assertFalse(c.segment[2].spcod[7] & 0x01) # RESET context probabilities (RESET) - self.assertFalse(c.segment[2].SPcod[7] & 0x02) + self.assertFalse(c.segment[2].spcod[7] & 0x02) # Termination on each coding pass, RESTART(TERMALL) - self.assertFalse(c.segment[2].SPcod[7] & 0x04) + self.assertFalse(c.segment[2].spcod[7] & 0x04) # Vertically causal context (VSC) - self.assertFalse(c.segment[2].SPcod[7] & 0x08) + self.assertFalse(c.segment[2].spcod[7] & 0x08) # Predictable termination, ERTERM(SEGTERM) - self.assertFalse(c.segment[2].SPcod[7] & 0x0010) + self.assertFalse(c.segment[2].spcod[7] & 0x0010) # Segmentation symbols, SEGMARK(SEGSYSM) - self.assertFalse(c.segment[2].SPcod[7] & 0x0020) - self.assertEqual(c.segment[2].SPcod[8], - glymur.core.WAVELET_TRANSFORM_5x3_REVERSIBLE) - self.assertEqual(len(c.segment[2].SPcod), 9) + self.assertFalse(c.segment[2].spcod[7] & 0x0020) + self.assertEqual(c.segment[2].spcod[8], + glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) + self.assertEqual(len(c.segment[2].spcod), 9) if __name__ == "__main__": unittest.main() diff --git a/glymur/test/test_printing.py b/glymur/test/test_printing.py index 4090a2d..3b920cc 100644 --- a/glymur/test/test_printing.py +++ b/glymur/test/test_printing.py @@ -1,3 +1,4 @@ +#pylint: disable-all import os import pkg_resources import struct @@ -21,7 +22,8 @@ except: raise -@unittest.skipIf(glymur.lib.openjp2._OPENJP2 is None, +@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): """These tests require the library, mostly in order to just setup the test. @@ -34,7 +36,7 @@ class TestPrintingNeedsLib(unittest.TestCase): with tempfile.NamedTemporaryFile(suffix='.jp2', delete=False) as tfile: cls._plain_nemo_file = tfile.name ijfile = Jp2k(jp2file) - data = ijfile.read(reduce=3) + data = ijfile.read(rlevel=1) ojfile = Jp2k(cls._plain_nemo_file, 'wb') ojfile.write(data) @@ -43,8 +45,9 @@ class TestPrintingNeedsLib(unittest.TestCase): os.unlink(cls._plain_nemo_file) def setUp(self): - self.jp2file = pkg_resources.resource_filename(glymur.__name__, - "data/nemo.jp2") + self.jp2file = glymur.data.nemo() + self.j2kfile = glymur.data.goodstuff() + # Save sys.stdout. self.stdout = sys.stdout sys.stdout = StringIO() @@ -57,7 +60,7 @@ class TestPrintingNeedsLib(unittest.TestCase): " Compatibility: ['jp2 ']", 'JP2 Header Box (jp2h) @ (32, 45)', ' Image Header Box (ihdr) @ (40, 22)', - ' Size: [182 324 3]', + ' Size: [728 1296 3]', ' Bitdepth: 8', ' Signed: False', ' Compression: wavelet', @@ -66,15 +69,15 @@ class TestPrintingNeedsLib(unittest.TestCase): ' Method: enumerated colorspace', ' Precedence: 0', ' Colorspace: sRGB', - 'Contiguous Codestream Box (jp2c) @ (77, 112814)', + 'Contiguous Codestream Box (jp2c) @ (77, 1632355)', ' Main header:', ' SOC marker segment @ (85, 0)', ' SIZ marker segment @ (87, 47)', ' Profile: 2', - ' Reference Grid Height, Width: (182 x 324)', + ' Reference Grid Height, Width: (728 x 1296)', ' Vertical, Horizontal Reference Grid Offset: ' + '(0 x 0)', - ' Reference Tile Height, Width: (182 x 324)', + ' Reference Tile Height, Width: (728 x 1296)', ' Vertical, Horizontal Reference Tile Offset: ' + '(0 x 0)', ' Bitdepth: (8, 8, 8)', @@ -121,7 +124,7 @@ class TestPrintingNeedsLib(unittest.TestCase): 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. - data = glymur.Jp2k(self.jp2file).read(reduce=3) + data = glymur.Jp2k(self.jp2file).read(rlevel=1) with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: j = glymur.Jp2k(tfile.name, 'wb') j.write(data) @@ -177,7 +180,7 @@ class TestPrintingNeedsLib(unittest.TestCase): lst = actual.split('\n') lst = lst[1:] actual = '\n'.join(lst) - + self.maxDiff = None self.assertEqual(actual, self.expectedPlain) def test_entire_file(self): @@ -209,15 +212,15 @@ class TestPrinting(unittest.TestCase): def test_COC_segment(self): j = glymur.Jp2k(self.jp2file) codestream = j.get_codestream(header_only=False) - print(codestream.segment[5]) + print(codestream.segment[6]) actual = sys.stdout.getvalue().strip() - lines = ['COC marker segment @ (3233, 9)', + lines = ['COC marker segment @ (3260, 9)', ' Associated component: 1', ' Coding style for this component: ' + 'Entropy coder, PARTITION = 0', ' Coding style parameters:', - ' Number of resolutions: 6', + ' Number of resolutions: 2', ' Code block height, width: (64 x 64)', ' Wavelet transform: 5-3 reversible', ' Code block context:', @@ -230,6 +233,7 @@ class TestPrinting(unittest.TestCase): ' Segmentation symbols: False'] expected = '\n'.join(lines) + self.maxDiff = None self.assertEqual(actual, expected) def test_COD_segment(self): @@ -245,10 +249,10 @@ class TestPrinting(unittest.TestCase): ' EPH marker segments: False', ' Coding style parameters:', ' Progression order: LRCP', - ' Number of layers: 3', + ' Number of layers: 2', ' Multiple component transformation usage: ' + 'reversible', - ' Number of resolutions: 6', + ' Number of resolutions: 2', ' Code block height, width: (64 x 64)', ' Wavelet transform: 5-3 reversible', ' Precinct size: default, 2^15 x 2^15', @@ -392,7 +396,7 @@ class TestPrinting(unittest.TestCase): print(codestream.segment[-1]) actual = sys.stdout.getvalue().strip() - lines = ['EOC marker segment @ (1136552, 0)'] + lines = ['EOC marker segment @ (1135421, 0)'] expected = '\n'.join(lines) self.assertEqual(actual, expected) @@ -476,15 +480,13 @@ class TestPrinting(unittest.TestCase): def test_QCC_segment(self): j = glymur.Jp2k(self.jp2file) codestream = j.get_codestream(header_only=False) - print(codestream.segment[6]) + print(codestream.segment[7]) actual = sys.stdout.getvalue().strip() - lines = ['QCC marker segment @ (3244, 20)', + lines = ['QCC marker segment @ (3271, 8)', ' Associated Component: 1', ' Quantization style: no quantization, 2 guard bits', - ' Step size: [(0, 8), (0, 9), (0, 9), (0, 10), (0, 9), ' - + '(0, 9), (0, 10), (0, 9), (0, 9), (0, 10), (0, 9), (0, 9), ' - + '(0, 10), (0, 9), (0, 9), (0, 10)]'] + ' Step size: [(0, 8), (0, 9), (0, 9), (0, 10)]'] expected = '\n'.join(lines) self.assertEqual(actual, expected) @@ -495,11 +497,9 @@ class TestPrinting(unittest.TestCase): print(codestream.segment[3]) actual = sys.stdout.getvalue().strip() - lines = ['QCD marker segment @ (3200, 19)', + lines = ['QCD marker segment @ (3200, 7)', ' Quantization style: no quantization, 2 guard bits', - ' Step size: [(0, 8), (0, 9), (0, 9), (0, 10), (0, 9), ' - + '(0, 9), (0, 10), (0, 9), (0, 9), (0, 10), (0, 9), ' - + '(0, 9), (0, 10), (0, 9), (0, 9), (0, 10)]'] + ' Step size: [(0, 8), (0, 9), (0, 9), (0, 10)]'] expected = '\n'.join(lines) self.assertEqual(actual, expected) @@ -514,7 +514,7 @@ class TestPrinting(unittest.TestCase): ' Profile: 2', ' Reference Grid Height, Width: (1456 x 2592)', ' Vertical, Horizontal Reference Grid Offset: (0 x 0)', - ' Reference Tile Height, Width: (512 x 512)', + ' Reference Tile Height, Width: (1456 x 2592)', ' Vertical, Horizontal Reference Tile Offset: (0 x 0)', ' Bitdepth: (8, 8, 8)', ' Signed: (False, False, False)', @@ -537,26 +537,27 @@ class TestPrinting(unittest.TestCase): def test_SOD_segment(self): j = glymur.Jp2k(self.jp2file) codestream = j.get_codestream(header_only=False) - print(codestream.segment[9]) + print(codestream.segment[10]) actual = sys.stdout.getvalue().strip() - lines = ['SOD marker segment @ (3299, 0)'] + lines = ['SOD marker segment @ (3302, 0)'] expected = '\n'.join(lines) self.assertEqual(actual, expected) def test_SOT_segment(self): j = glymur.Jp2k(self.jp2file) codestream = j.get_codestream(header_only=False) - print(codestream.segment[4]) + print(codestream.segment[5]) actual = sys.stdout.getvalue().strip() - lines = ['SOT marker segment @ (3221, 10)', + lines = ['SOT marker segment @ (3248, 10)', ' Tile part index: 0', - ' Tile part length: 78629', + ' Tile part length: 1132173', ' Tile part instance: 0', ' Number of tile parts: 1'] expected = '\n'.join(lines) + self.maxDiff = None self.assertEqual(actual, expected) @unittest.skipIf(data_root is None, @@ -606,7 +607,7 @@ class TestPrinting(unittest.TestCase): ' Profile: 2', ' Reference Grid Height, Width: (1456 x 2592)', ' Vertical, Horizontal Reference Grid Offset: (0 x 0)', - ' Reference Tile Height, Width: (512 x 512)', + ' Reference Tile Height, Width: (1456 x 2592)', ' Vertical, Horizontal Reference Tile Offset: (0 x 0)', ' Bitdepth: (8, 8, 8)', ' Signed: (False, False, False)', @@ -619,10 +620,10 @@ class TestPrinting(unittest.TestCase): ' EPH marker segments: False', ' Coding style parameters:', ' Progression order: LRCP', - ' Number of layers: 3', + ' Number of layers: 2', ' Multiple component transformation usage: ' + 'reversible', - ' Number of resolutions: 6', + ' Number of resolutions: 2', ' Code block height, width: (64 x 64)', ' Wavelet transform: 5-3 reversible', ' Precinct size: default, 2^15 x 2^15', @@ -634,14 +635,14 @@ class TestPrinting(unittest.TestCase): ' Vertically stripe causal context: False', ' Predictable termination: False', ' Segmentation symbols: False', - ' QCD marker segment @ (3200, 19)', + ' QCD marker segment @ (3200, 7)', ' Quantization style: no quantization, ' + '2 guard bits', - ' Step size: [(0, 8), (0, 9), (0, 9), ' - + '(0, 10), (0, 9), (0, 9), (0, 10), (0, 9), (0, 9), ' - + '(0, 10), (0, 9), (0, 9), (0, 10), (0, 9), (0, 9), ' - + '(0, 10)]'] + ' Step size: [(0, 8), (0, 9), (0, 9), (0, 10)]', + ' CME marker segment @ (3209, 37)', + ' "Created by OpenJPEG version 2.0.0"'] expected = '\n'.join(lst) + self.maxDiff = None self.assertEqual(actual, expected) @unittest.skipIf(data_root is None, @@ -783,6 +784,7 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) + @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: diff --git a/release.txt b/release.txt new file mode 100644 index 0000000..4f2b068 --- /dev/null +++ b/release.txt @@ -0,0 +1,30 @@ +| OS | Python 2.7 | Python 3.3 | Notes | ++------------+------------+------------+--------------------------------------+ +| 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 | +| | | | should pass. | ++------------+------------+------------+--------------------------------------+ +| Mac | | X | MacPorts with both OpenJPEG 1.5.1 | +| | | | and OpenJPEG svn. 390 of 450 | +| | | | tests should pass. | ++------------+------------+------------+--------------------------------------+ +| Fedora 19 | | X | Ships with 1.5.1. 390 of 450 tests | +| | | | should pass. | ++------------+------------+------------+--------------------------------------+ +| Fedora 18 | | X | Ships with 1.5.1. 167 of 445 tests | +| | | | should pass. | ++------------+------------+------------+--------------------------------------+ +| Fedora 17 | X | | Ships with 1.4. Should error out | +| | | | gracefully. | ++------------+------------+------------+--------------------------------------+ + +Pylint on entire package should be at least 0.95. +pep8 should be pass cleanly. +Coverage should exceed 95%. diff --git a/setup.py b/setup.py index 0e213a3..c9ed916 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages import sys kwargs = {'name': 'Glymur', - 'version': '0.1.10', + 'version': '0.2.0', 'description': 'Tools for accessing JPEG2000 files', 'long_description': open('README.md').read(), 'author': 'John Evans', @@ -26,9 +26,10 @@ clssfrs = ["Programming Language :: Python", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: Implementation :: CPython", "License :: OSI Approved :: MIT License", - "Development Status :: 3 - Alpha", + "Development Status :: 5 - Production/Stable", "Operating System :: MacOS", "Operating System :: POSIX :: Linux", + "Operating System :: Microsoft :: Windows :: Windows XP", "Intended Audience :: Science/Research", "Intended Audience :: Information Technology", "Topic :: Software Development :: Libraries :: Python Modules"]