diff --git a/.travis.yml b/.travis.yml
index 30dd864..a8a0d1b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -12,6 +12,11 @@ before_install:
# command to install dependencies
install:
- pip install . --use-mirrors
+
# command to run tests
script:
- "python -m unittest discover"
+
+notifications:
+ email:
+ - john.g.evans.ne@gmail.com
diff --git a/CHANGES.txt b/CHANGES.txt
index 9a71f81..35b355e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,5 @@
+Sep 16, 2013 - v0.5.0 Added write support for 1.5.x. Added version module.
+
Aug 21, 2013 - v0.4.1 Fixed segfault with openjpeg 1.x when rlevel=-1
Aug 18, 2013 - v0.4.0 Added append method.
diff --git a/docs/source/conf.py b/docs/source/conf.py
index c5dccb4..6b9eb18 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -76,9 +76,9 @@ copyright = u'2013, John Evans'
# built documents.
#
# The short X.Y version.
-version = '0.4'
+version = '0.5'
# The full version, including alpha/beta/rc tags.
-release = '0.4.1'
+release = '0.5.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 dab4c3f..7fb5b3b 100644
--- a/docs/source/detailed_installation.rst
+++ b/docs/source/detailed_installation.rst
@@ -1,31 +1,33 @@
----------------------------------
Advanced Installation Instructions
----------------------------------
+Most users won't need to read this! You've been warned...
''''''''''''''''''''''
Glymur Configuration
''''''''''''''''''''''
The default glymur installation process relies upon OpenJPEG version
-1.X 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 install version 2.0 or
-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.
+1.X being properly installed on your system. If you have version 1.5 you can
+both read and write JPEG 2000 files, but you may wish to install version 2.0
+or the 2.0+ version from OpenJPEG's development trunk for better performance.
+If you do that, you should compile it 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. ::
+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
+Glymur uses ctypes to access the openjp2/openjpeg libraries,
+and because ctypes accesses libraries in a platform-dependent manner, it is
recommended that you create a configuration file to help Glymur properly find
-the openjp2 library. The configuration format is the same as used by Python's
-configparser module, i.e. ::
+the openjpeg or openjp2 libraries (linux users don't need to bother if you are
+using OpenJPEG as provided by your package manager). The configuration
+format is the same as used by Python's configparser module, i.e. ::
[library]
openjp2: /opt/openjp2-svn/lib/libopenjp2.so
@@ -37,7 +39,8 @@ to the configuration file would normally be ::
$HOME/.config/glymur/glymurrc
-but if you have **$XDG_CONFIG_HOME** defined, the path will be ::
+but if you have the **XDG_CONFIG_HOME** environment variable defined,
+the path will be ::
$XDG_CONFIG_HOME/glymur/glymurrc
@@ -52,12 +55,11 @@ You may also include a line for the version 1.x openjpeg 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
-'''''''''''''''''''''''''''''''''''''''''''
+''''''''''''''''''''''''''''''
+Package Management Suggestions
+''''''''''''''''''''''''''''''
You only need to read this section if you want detailed
platform-specific instructions on running as many tests as possible or wish to
@@ -67,8 +69,8 @@ packages/RPMs/ports/whatever without going through pip.
Mac OS X
--------
-All the necessary packages are available to use glymur with Python 3.3 via
-MacPorts. You should install the following set of ports:
+All the necessary packages are available to use glymur with Python 2.6, 2.7,
+and 3.3 via MacPorts. You should install the following set of ports:
* python33
* py33-numpy
@@ -80,72 +82,38 @@ MacPorts supplies both OpenJPEG 1.5.0 and OpenJPEG 2.0.0.
Linux
-----
+For the most part, you only need python and numpy to run glymur, so on
+just about all distributions you are already set to go (and you don't
+need to mess around with a configuration file, as the openjpeg shared
+libraries are found in the usual places thanks to your package manager).
+In order to run as many tests as possible, however, the following Python
+packages may also need to be installed. Consult your package manager
+documentation or use pip.
-Fedora 19
-'''''''''
-Fedora 18 ships with Python 3.3 and all the necessary RPMs are available to
-run the maximum number of tests.
+ * setuptools
+ * matplotlib
+ * pillow
+ * contextlib2 (python 2.6, 2.7 only)
+ * mock (python 2.6, 2.7 only)
+ * ordereddict (python 2.6 only)
- * 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 and the following RPMs are available to
-meet the minimal set of requirements for running glymur.
-
- * python3
- * python3-numpy
- * python3-setuptools
-
-For running the maximal number of tests, you also need
-
- * python3-matplotlib
- * python3-matplotlib-tk (or whichever matplotlib backend you prefer)
-
-Pillow is also needed in order to run the maximum number of tests, so
-go ahead and install Pillow via pip since Pillow is not available
-in Fedora 18 default repositories::
-
- $ yum install python3-devel # pip needs this in order to compile Pillow
- $ yum install python3-pip
- $ pip-python3 install Pillow --user
- $ export PYTHONPATH=$HOME/.local/lib/python3.3/site-packages:$PYTHONPATH
-
-Fedora 17
-'''''''''
-Fedora 17 ships with Python 2.7 and OpenJPEG 1.4. You should have the
-following RPMs installed.
-
- * python
- * python-mock
- * python-pip
- * python-setuptools
- * numpy
- * matplotlib (optional)
-
-In addition, you must install contextlib2 and Pillow via pip. ::
-
- $ yum install python-devel # pip needs this in order to compile Pillow
- $ pip-python install Pillow --user
- $ pip-python install contextlib2 --user
- $ export PYTHONPATH=$HOME/.local/lib/python2.7/site-packages:$PYTHONPATH
+Glymur's been tested on the following linux platforms without any unexpected
+difficulties:
+
+ * OpenSUSE 12.3
+ * Fedora 17, 18, 19
+ * Raspian
+ * Travis CI (currently Ubuntu 12.04?)
+ * CentOS 6.4
Windows
-------
32-bit WinPython 2.7.5 seemed to work with OpenJPEG 1.X, 2.0, and the
development version, but still required contextlib2 and mock to be
installed via pip. WinPython 3.3.2, however, seems to have trouble
-with OpenJPEG 2.0, so I would suggest using the development version
-there (I'm unwilling to spend ANY more time trying to figure out what
-the problem is there).
-
-At the moment I do not have access to a win32 machine, and
-64-bit windows is completely untested.
+with OpenJPEG 2.0, so I would suggest using the development version with
+that configuration. I no longer have any access to a windows machine,
+so I cannot currently offer much guidance here.
'''''''
@@ -155,8 +123,8 @@ Testing
There are two environment variables you may wish to set before running the
tests.
- * **OPJ_DATA_ROOT** - points to directory for OpenJPEG test data
- * **FORMAT_CORPUS_ROOT** - points to directory for format-corpus repository (see https://github.com/openplanets/format-corpus if you wish, but you really don't need to bother with this)
+ * **OPJ_DATA_ROOT** - points to directory for OpenJPEG test data (see above)
+ * **FORMAT_CORPUS_DATA_ROOT** - points to directory for format-corpus repository (see https://github.com/openplanets/format-corpus if you wish, but you really don't need to bother with this)
Setting these two environment variables is not required, as any tests using
either of them will be skipped.
@@ -175,7 +143,7 @@ or from the command line. ::
Quite a few tests are currently skipped. These include tests whose
OpenJPEG counterparts are already failing, and others which do pass but
still produce heaps of output on stderr. Rather than let this swamp
-the signal (that most of the tests are actually passing), they've been
+the signal (that most of those tests are actually passing), they've been
filtered out for now. There are also more skipped tests on Python 2.7
than on Python 3.3. The important part is whether or not any test
errors are reported at the end.
diff --git a/docs/source/introduction.rst b/docs/source/introduction.rst
index 0a59ebd..37dcb5a 100644
--- a/docs/source/introduction.rst
+++ b/docs/source/introduction.rst
@@ -20,7 +20,7 @@ OpenJPEG Installation
=====================
Glymur will read JPEG 2000 images with versions 1.3, 1.4, 1.5, 2.0,
and the trunk/development version of OpenJPEG. Writing images is
-only supported with the 2.0 series, however, and the trunk/development
+only supported with the 1.5 or better, however, and the trunk/development
version is strongly recommended. For more information about OpenJPEG,
please consult http://www.openjpeg.org.
@@ -55,6 +55,5 @@ You can run the tests from within python as follows::
>>> import glymur
>>> glymur.runtests()
-Many tests are currently skipped; in fact most of them are skipped if you
-are relying on OpenJPEG 1.X. The important thing, though, is whether or
+Many tests are currently skipped, but the The important thing is whether or
not any tests fail.
diff --git a/docs/source/roadmap.rst b/docs/source/roadmap.rst
index 7f50a87..f9216a3 100644
--- a/docs/source/roadmap.rst
+++ b/docs/source/roadmap.rst
@@ -1,9 +1,3 @@
-------------
-Known Issues
-------------
-
- * WinPython 3.3.2 and OpenJPEG 2.0 don't seem to want to play well together. If you do not need write support, just use OpenJPEG 1.5 instead. If you do need write support, try the development version of OpenJPEG.
-
-------
Roadmap
-------
diff --git a/glymur/__init__.py b/glymur/__init__.py
index cc80a72..bf2f625 100644
--- a/glymur/__init__.py
+++ b/glymur/__init__.py
@@ -2,6 +2,9 @@
"""
import sys
+from glymur import version
+__version__ = version.version
+
from .jp2k import Jp2k
from .jp2dump import jp2dump
diff --git a/glymur/jp2k.py b/glymur/jp2k.py
index bd90dfe..00b71c2 100644
--- a/glymur/jp2k.py
+++ b/glymur/jp2k.py
@@ -1,4 +1,8 @@
-"""Access to JPEG2000 files.
+"""This file is part of glymur, a Python interface for accessing JPEG 2000.
+
+http://glymur.readthedocs.org
+
+Copyright 2013 John Evans
License: MIT
"""
@@ -21,8 +25,7 @@ import warnings
import numpy as np
from .codestream import Codestream
-from .core import SRGB
-from .core import GREYSCALE
+from .core import SRGB, GREYSCALE
from .core import PROGRESSION_ORDER
from .core import ENUMERATED_COLORSPACE, RESTRICTED_ICC_PROFILE
from .jp2box import Jp2kBox
@@ -31,6 +34,7 @@ from .jp2box import ColourSpecificationBox, ContiguousCodestreamBox
from .jp2box import ImageHeaderBox
from .lib import openjpeg as opj
from .lib import openjp2 as opj2
+from . import version
from .lib import c as libc
@@ -185,7 +189,10 @@ class Jp2k(Jp2kBox):
cparams : CompressionParametersType(ctypes.Structure)
Corresponds to cparameters_t type in openjp2 headers.
"""
- cparams = opj2.set_default_encoder_parameters()
+ if version.openjpeg_version_tuple[0] == 1:
+ cparams = opj.set_default_encoder_parameters()
+ else:
+ cparams = opj2.set_default_encoder_parameters()
outfile = self.filename.encode()
num_pad_bytes = opj2.PATH_LEN - len(outfile)
@@ -280,9 +287,6 @@ class Jp2k(Jp2kBox):
Corresponds to cparameters_t type in openjp2 headers.
colorspace : int
Either CLRSPC_SRGB or CLRSPC_GRAY
- mct : bool, optional
- Specifies usage of the multi component transform. If not
- specified, defaults to True if the colorspace is RGB.
"""
if 'cratios' in kwargs and 'psnr' in kwargs:
@@ -380,11 +384,87 @@ class Jp2k(Jp2kBox):
glymur.LibraryNotFoundError
If glymur is unable to load the openjp2 library.
"""
- if opj2.OPENJP2 is None:
- raise LibraryNotFoundError("You must have the openjp2 library "
- "installed before using this "
+ if opj2.OPENJP2 is not None:
+ self._write_openjp2(img_array, verbose=verbose, **kwargs)
+ elif opj.OPENJPEG is not None:
+ self._write_openjpeg(img_array, verbose=verbose, **kwargs)
+ else:
+ raise LibraryNotFoundError("You must have at least version 1.5 of "
+ "OpenJPEG before using this "
"functionality.")
+ def _write_openjpeg(self, img_array, verbose=False, **kwargs):
+ """
+ Write JPEG 2000 file using OpenJPEG 1.5 interface.
+ """
+ cparams, colorspace = self._process_write_inputs(img_array, **kwargs)
+
+ if img_array.ndim == 2:
+ # Force the image to be 3D. Just makes things easier later on.
+ img_array = img_array.reshape(img_array.shape[0],
+ img_array.shape[1],
+ 1)
+
+ comptparms = _populate_comptparms(img_array, cparams)
+
+ with ExitStack() as stack:
+ image = opj.image_create(comptparms, colorspace)
+ stack.callback(opj.image_destroy, image)
+
+ numrows, numcols, numlayers = img_array.shape
+
+ # set image offset and reference grid
+ image.contents.x0 = cparams.image_offset_x0
+ image.contents.y0 = cparams.image_offset_y0
+ image.contents.x1 = image.contents.x0 \
+ + (numcols - 1) * cparams.subsampling_dx + 1
+ image.contents.y1 = image.contents.y0 \
+ + (numrows - 1) * cparams.subsampling_dy + 1
+
+ # Stage the image data to the openjpeg data structure.
+ for k in range(0, numlayers):
+ layer = np.ascontiguousarray(img_array[:, :, k],
+ dtype=np.int32)
+ dest = image.contents.comps[k].data
+ src = layer.ctypes.data
+ ctypes.memmove(dest, src, layer.nbytes)
+
+ cinfo = opj.create_compress(cparams.codec_fmt)
+ stack.callback(opj.destroy_compress, cinfo)
+
+ # Setup the info, warning, and error handlers.
+ # Always use the warning and error handler. Use of an info
+ # handler is optional.
+ event_mgr = opj.EventMgrType()
+ _info_handler = _INFO_CALLBACK if verbose else None
+ event_mgr.info_handler = _info_handler
+ 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.setup_encoder(cinfo, ctypes.byref(cparams), image)
+
+ cio = opj.cio_open(cinfo)
+ stack.callback(opj.cio_close, cio)
+
+ if not opj.encode(cinfo, cio, image):
+ raise IOError("Encode error.")
+
+ pos = opj.cio_tell(cio)
+
+ blob = ctypes.string_at(cio.contents.buffer, pos)
+ fptr = open(self.filename, 'wb')
+ stack.callback(fptr.close)
+ fptr.write(blob)
+
+ self.parse()
+
+
+ def _write_openjp2(self, img_array, verbose=False, **kwargs):
+ """
+ Write JPEG 2000 file using OpenJPEG 1.5 interface.
+ """
cparams, colorspace = self._process_write_inputs(img_array, **kwargs)
if img_array.ndim == 2:
@@ -650,41 +730,45 @@ class Jp2k(Jp2kBox):
raise IOError(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
+ try:
+ # 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
+ infile = self.filename.encode()
+ nelts = opj.PATH_LEN - len(infile)
+ infile += b'0' * nelts
+ dparameters.infile = infile
- dinfo = opj.create_decompress(dparameters.decod_format)
+ 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))
+ 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)
+ opj.setup_decoder(dinfo, dparameters)
- with open(self.filename, 'rb') as fptr:
- src = fptr.read()
- cio = opj.cio_open(dinfo, src)
+ with open(self.filename, 'rb') as fptr:
+ src = fptr.read()
+ cio = opj.cio_open(dinfo, src)
- image = opj.decode(dinfo, cio)
+ image = opj.decode(dinfo, cio)
- stack.callback(opj.image_destroy, image)
- stack.callback(opj.destroy_decompress, dinfo)
- stack.callback(opj.cio_close, cio)
+ stack.callback(opj.image_destroy, image)
+ stack.callback(opj.destroy_decompress, dinfo)
+ stack.callback(opj.cio_close, cio)
- data = extract_image_cube(image)
+ data = extract_image_cube(image)
+
+ except ValueError:
+ opj2.check_error(0)
if data.shape[2] == 1:
# The third dimension has just a single layer. Make the image
@@ -864,8 +948,8 @@ class Jp2k(Jp2kBox):
glymur.LibraryNotFoundError
If glymur is unable to load the openjp2 library.
"""
- if opj2.OPENJP2 is None:
- raise LibraryNotFoundError("You must have the development version "
+ if version.openjpeg_version_tuple[0] < 2:
+ raise LibraryNotFoundError("You must have at least version 2.0.0 "
"of OpenJP2 installed before using "
"this functionality.")
@@ -1207,7 +1291,10 @@ def _populate_comptparms(img_array, cparams):
comp_prec = 16
numrows, numcols, num_comps = img_array.shape
- comptparms = (opj2.ImageComptParmType * num_comps)()
+ if version.openjpeg_version_tuple[0] == 1:
+ comptparms = (opj.ImageComptParmType * num_comps)()
+ else:
+ comptparms = (opj2.ImageComptParmType * num_comps)()
for j in range(num_comps):
comptparms[j].dx = cparams.subsampling_dx
comptparms[j].dy = cparams.subsampling_dy
@@ -1339,18 +1426,18 @@ _CMPFUNC = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_char_p, ctypes.c_void_p)
def _default_error_handler(msg, _):
- """Default error handler callback for openjpeg library."""
+ """Default error handler callback for libopenjp2."""
msg = "OpenJPEG library error: {0}".format(msg.decode('utf-8').rstrip())
opj2.set_error_message(msg)
def _default_info_handler(msg, _):
- """Default info handler callback for openjpeg library."""
+ """Default info handler callback."""
print("[INFO] {0}".format(msg.decode('utf-8').rstrip()))
def _default_warning_handler(library_msg, _):
- """Default warning handler callback for openjpeg library."""
+ """Default warning handler callback."""
library_msg = library_msg.decode('utf-8').rstrip()
msg = "OpenJPEG library warning: {0}".format(library_msg)
warnings.warn(msg)
diff --git a/glymur/lib/openjp2.py b/glymur/lib/openjp2.py
index f0f72c0..8c0ae32 100644
--- a/glymur/lib/openjp2.py
+++ b/glymur/lib/openjp2.py
@@ -685,7 +685,7 @@ def check_error(status):
raise IOError("OpenJPEG function failure.")
# These library functions all return an error status. Circumvent that and
-# force # them to raise an exception.
+# 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',
diff --git a/glymur/lib/openjpeg.py b/glymur/lib/openjpeg.py
index 704cf9c..5b1183f 100644
--- a/glymur/lib/openjpeg.py
+++ b/glymur/lib/openjpeg.py
@@ -6,10 +6,16 @@
import ctypes
import sys
+import numpy as np
+
from .config import glymur_config
_, OPENJPEG = glymur_config()
-PATH_LEN = 4096 # maximum allowed size for filenames
+# Maximum number of tile parts expected by JPWL: increase at your will
+JPWL_MAX_NO_TILESPECS = 16
+
+J2K_MAXRLVLS = 33 # Number of maximum resolution level authorized
+PATH_LEN = 4096 # maximum allowed size for filenames
def version():
@@ -52,14 +58,8 @@ class CommonStructType(ctypes.Structure):
("mj2_handle", ctypes.c_void_p)]
-class DecompressionInfoType(ctypes.Structure):
- """This is for decompression contexts.
-
- Corresponds to dinfo_t type in openjpeg headers.
- """
- pass
-
-
+STREAM_READ = 0x0001 # The stream was opened for reading.
+STREAM_WRITE = 0x0002 # The stream was opened for writing.
class CioType(ctypes.Structure):
"""Byte input-output stream (CIO)
@@ -80,6 +80,266 @@ class CioType(ctypes.Structure):
("bp", ctypes.c_char_p)]
+class CompressionInfoType(CommonStructType):
+ """Common fields between JPEG-2000 compression and decompression contexts.
+ This is for compression contexts. Corresponds to common_struct_t.
+ """
+ pass
+
+
+class PocType(ctypes.Structure):
+ """Progression order changes."""
+ _fields_ = [("resno", ctypes.c_int),
+ # Resolution num start, Component num start, given by POC
+ ("compno0", ctypes.c_int),
+
+ # Layer num end,Resolution num end, Component num end, given by POC
+ ("layno1", ctypes.c_int),
+ ("resno1", ctypes.c_int),
+ ("compno1", ctypes.c_int),
+
+ # Layer num start,Precinct num start, Precinct num end
+ ("layno0", ctypes.c_int),
+ ("precno0", ctypes.c_int),
+ ("precno1", ctypes.c_int),
+
+ # Progression order enum
+ # OPJ_PROG_ORDER prg1,prg;
+ ("prg1", ctypes.c_int),
+ ("prg", ctypes.c_int),
+
+ # Progression order string
+ # char progorder[5];
+ ("progorder", ctypes.c_char * 5),
+
+ # Tile number
+ # int tile;
+ ("tile", ctypes.c_int),
+
+ # /** Start and end values for Tile width and height*/
+ # int tx0,tx1,ty0,ty1;
+ ("tx0", ctypes.c_int),
+ ("tx1", ctypes.c_int),
+ ("ty0", ctypes.c_int),
+ ("ty1", ctypes.c_int),
+
+ # /** Start value, initialised in pi_initialise_encode*/
+ # int layS, resS, compS, prcS;
+ ("layS", ctypes.c_int),
+ ("resS", ctypes.c_int),
+ ("compS", ctypes.c_int),
+ ("prcS", ctypes.c_int),
+
+ # /** End value, initialised in pi_initialise_encode */
+ # int layE, resE, compE, prcE;
+ ("layE", ctypes.c_int),
+ ("resE", ctypes.c_int),
+ ("compE", ctypes.c_int),
+ ("prcE", ctypes.c_int),
+
+ # Start and end values of Tile width and height, initialised in
+ # pi_initialise_encode int txS,txE,tyS,tyE,dx,dy;
+ ("txS", ctypes.c_int),
+ ("txE", ctypes.c_int),
+ ("tyS", ctypes.c_int),
+ ("tyE", ctypes.c_int),
+ ("dx", ctypes.c_int),
+ ("dy", ctypes.c_int),
+
+ # Temporary values for Tile parts, initialised in pi_create_encode
+ # int lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t;
+ ("lay_t", ctypes.c_int),
+ ("res_t", ctypes.c_int),
+ ("comp_t", ctypes.c_int),
+ ("prc_t", ctypes.c_int),
+ ("tx0_t", ctypes.c_int),
+ ("ty0_t", ctypes.c_int)]
+
+
+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", ctypes.c_int),
+
+ # XTOsiz, YTOsiz
+ ("cp_tx0", ctypes.c_int),
+ ("cp_ty0", ctypes.c_int),
+
+ # XTsiz, YTsiz
+ ("cp_tdx", ctypes.c_int),
+ ("cp_tdy", ctypes.c_int),
+
+ # allocation by rate/distortion
+ ("cp_disto_alloc", ctypes.c_int),
+
+ # allocation by fixed layer
+ ("cp_fixed_alloc", ctypes.c_int),
+
+ # add fixed_quality
+ ("cp_fixed_quality", ctypes.c_int),
+
+ # fixed layer
+ ("cp_matrice", ctypes.c_void_p),
+
+ # comment for coding
+ ("cp_comment", ctypes.c_char_p),
+
+ # csty : coding style
+ ("csty", ctypes.c_int),
+
+ # progression order (default OPJ_LRCP)
+ ("prog_order", ctypes.c_int),
+
+ # progression order changes
+ ("poc", PocType * 32),
+
+ # number of progression order changes (POC), default to 0
+ ("numpocs", ctypes.c_uint),
+
+ # number of layers
+ ("tcp_numlayers", ctypes.c_int),
+
+ # rates of layers
+ ("tcp_rates", ctypes.c_float * 100),
+
+ # different psnr for successive layers
+ ("tcp_distoratio", ctypes.c_float * 100),
+
+ # number of resolutions
+ ("numresolution", ctypes.c_int),
+
+ # initial code block width, default to 64
+ ("cblockw_init", ctypes.c_int),
+
+ # initial code block height, default to 64
+ ("cblockh_init", ctypes.c_int),
+
+ # mode switch (cblk_style)
+ ("mode", ctypes.c_int),
+
+ # 1 : use the irreversible DWT 9-7
+ # 0 : use lossless compression (default)
+ ("irreversible", ctypes.c_int),
+
+ # region of interest: affected component in [0..3], -1 means no ROI
+ ("roi_compno", ctypes.c_int),
+
+ # region of interest: upshift value
+ ("roi_shift", ctypes.c_int),
+
+ # number of precinct size specifications
+ ("res_spec", ctypes.c_int),
+
+ # initial precinct width
+ ("prcw_init", ctypes.c_int * J2K_MAXRLVLS),
+
+ # initial precinct height
+ ("prch_init", ctypes.c_int * J2K_MAXRLVLS),
+
+ # input file name
+ ("infile", ctypes.c_char * PATH_LEN),
+
+ # output file name
+ ("outfile", ctypes.c_char * PATH_LEN),
+
+ # DEPRECATED.
+ ("index_on", ctypes.c_int),
+
+ # DEPRECATED.
+ ("index", ctypes.c_char * PATH_LEN),
+
+ # subimage encoding: origin image offset in x direction
+ # subimage encoding: origin image offset in y direction
+ ("image_offset_x0", ctypes.c_int),
+ ("image_offset_y0", ctypes.c_int),
+
+ # subsampling value for dx
+ # subsampling value for dy
+ ("subsampling_dx", ctypes.c_int),
+ ("subsampling_dy", ctypes.c_int),
+
+ # input file format 0: PGX, 1: PxM, 2: BMP 3:TIF
+ # output file format 0: J2K, 1: JP2, 2: JPT
+ ("decod_format", ctypes.c_int),
+ ("cod_format", ctypes.c_int),
+
+ # JPWL encoding parameters
+ # enables writing of EPC in MH, thus activating JPWL
+ ("jpwl_epc_on", ctypes.c_int),
+
+ # 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),
+
+ # error protection methods for TPHs (0,1,16,32,37-128)
+ ("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),
+
+ # packet number of packet protection specification (>=0)
+ ("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),
+
+ # enables writing of ESD, (0=no/1/2 bytes)
+ ("jpwl_sens_size", ctypes.c_int),
+
+ # sensitivity addressing size (0=auto/2/4 bytes)
+ ("jpwl_sens_addr", ctypes.c_int),
+
+ # sensitivity range (0-3)
+ ("jpwl_sens_range", ctypes.c_int),
+
+ # sensitivity method for MH (-1=no,0-7)
+ ("jpwl_sens_mh", ctypes.c_int),
+
+ # tile number of sensitivity specification (>=0)
+ ("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),
+
+ # Digital Cinema compliance 0-not compliant, 1-compliant
+ ("cp_cinema", ctypes.c_int),
+
+ # Maximum rate for each component.
+ # If == 0, component size limitation is not considered
+ ("max_comp_size", ctypes.c_int),
+
+ # Profile name
+ ("cp_rsiz", ctypes.c_int),
+
+ # Tile part generation
+ ("tp_on", ctypes.c_uint8),
+
+ # Flag for Tile part generation
+ ("tp_flag", ctypes.c_uint8),
+
+ # MCT (multiple component transform)
+ ("tcp_mct", ctypes.c_uint8),
+
+ # Enable JPIP indexing
+ ("jpip_on", ctypes.c_int)]
+
+
+class DecompressionInfoType(ctypes.Structure):
+ """This is for decompression contexts.
+
+ Corresponds to dinfo_t type in openjpeg headers.
+ """
+ pass
+
+
class DecompressionParametersType(ctypes.Structure):
"""Decompression parameters.
@@ -111,23 +371,51 @@ class DecompressionParametersType(ctypes.Structure):
_fields_.append(("flags", ctypes.c_uint))
-class ImageCompType(ctypes.Structure):
- """Defines a single image component.
-
- Corresponds to image_comp_t type in openjpeg.
+class ImageComptParmType(ctypes.Structure):
+ """Component parameters structure used by the opj_image_create function.
"""
- _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))]
+ _fields_ = [
+ # XRsiz: horizontal separation of a sample of ith component with
+ # respect to the reference grid
+ ("dx", ctypes.c_int),
+
+ # YRsiz: vertical separation of a sample of ith component with
+ # respect to the reference grid */
+ ("dy", ctypes.c_int),
+
+ # data width, height
+ ("w", ctypes.c_int),
+ ("h", ctypes.c_int),
+
+ # x component offset compared to the whole image
+ # y component offset compared to the whole image
+ ("x0", ctypes.c_int),
+ ("y0", ctypes.c_int),
+
+ # precision
+ ('prec', ctypes.c_int),
+
+ # image depth in bits
+ ('bpp', ctypes.c_int),
+
+ # signed (1) / unsigned (0)
+ ('sgnd', ctypes.c_int)]
+
+
+class ImageCompType(ctypes.Structure):
+ """Defines a single image component. """
+ _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):
@@ -146,16 +434,22 @@ class ImageType(ctypes.Structure):
("icc_profile_len", ctypes.c_int)]
-def cio_open(cinfo, src):
+def cio_open(cinfo, src=None):
"""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)
+ if src is None:
+ length = 0
+ else:
+ length = len(src)
+
cio = OPENJPEG.opj_cio_open(ctypes.cast(cinfo,
ctypes.POINTER(CommonStructType)),
- src, len(src))
+ src,
+ length)
return cio
@@ -166,6 +460,24 @@ def cio_close(cio):
OPENJPEG.opj_cio_close(cio)
+def cio_tell(cio):
+ """Get position in byte stream."""
+ OPENJPEG.cio_tell.argtypes = [ctypes.POINTER(CioType)]
+ OPENJPEG.cio_tell.restype = ctypes.c_int
+ pos = OPENJPEG.cio_tell(cio)
+ return pos
+
+def create_compress(fmt):
+ """Wrapper for openjpeg library function opj_create_compress.
+
+ Creates a J2K/JPT/JP2 compression structure.
+ """
+ OPENJPEG.opj_create_compress.argtypes = [ctypes.c_int]
+ OPENJPEG.opj_create_compress.restype = ctypes.POINTER(CompressionInfoType)
+ cinfo = OPENJPEG.opj_create_compress(fmt)
+ return cinfo
+
+
def create_decompress(fmt):
"""Wraps openjpeg library function opj_create_decompress.
"""
@@ -186,6 +498,38 @@ def decode(dinfo, cio):
return image
+def destroy_compress(cinfo):
+ """Wrapper for openjpeg library function opj_destroy_compress.
+
+ Release resources for a compressor handle.
+ """
+ argtypes = [ctypes.POINTER(CompressionInfoType)]
+ OPENJPEG.opj_destroy_compress.argtypes = argtypes
+ OPENJPEG.opj_destroy_compress(cinfo)
+
+
+def encode(cinfo, cio, image):
+ """Wrapper for openjpeg library function opj_encode.
+
+ Encodes an image into a JPEG-2000 codestream.
+
+ Parameters
+ ----------
+ cinfo : compression handle
+
+ cio : output buffer stream
+
+ image : image to encode
+ """
+ argtypes = [ctypes.POINTER(CompressionInfoType),
+ ctypes.POINTER(CioType),
+ ctypes.POINTER(ImageType)]
+ OPENJPEG.opj_encode.argtypes = argtypes
+ OPENJPEG.opj_encode.restype = ctypes.c_int
+ status = OPENJPEG.opj_encode(cinfo, cio, image)
+ return status
+
+
def destroy_decompress(dinfo):
"""Wraps openjpeg library function opj_destroy_decompress."""
argtypes = [ctypes.POINTER(DecompressionInfoType)]
@@ -193,12 +537,78 @@ def destroy_decompress(dinfo):
OPENJPEG.opj_destroy_decompress(dinfo)
+def image_cmptparm_t_from_np(np_image):
+ """Return appropriate image_cmptparm_t based on given numpy array.
+ """
+ try:
+ num_comps = np_image.shape[2]
+ except IndexError:
+ num_comps = 1
+
+ cmpt_parm_array_t = ImageCmptparmType * num_comps
+ tarr = cmpt_parm_array_t()
+
+ if np_image.dtype == np.uint8:
+ prec = 8
+ bpp = 8
+ sgnd = 0
+ elif np_image.dtype == np.int8:
+ prec = 8
+ bpp = 8
+ sgnd = 1
+ elif np_image.dtype == np.uint16:
+ prec = 16
+ bpp = 16
+ sgnd = 0
+ elif np_image.dtype == np.int16:
+ prec = 16
+ bpp = 16
+ sgnd = 1
+ else:
+ raise(TypeError("unhandled"))
+
+ for j in range(0, num_comps):
+ tarr[j].dx = 1
+ tarr[j].dy = 1
+ tarr[j].w = np_image.shape[1]
+ tarr[j].h = np_image.shape[0]
+ tarr[j].x0 = 0
+ tarr[j].y0 = 0
+ tarr[j].prec = prec
+ tarr[j].bpp = bpp
+ tarr[j].sgnd = sgnd
+
+ return(tarr)
+
+
+def image_create(cmptparms, cspace):
+ """Wrapper for openjpeg library function opj_image_create.
+ """
+ OPENJPEG.opj_image_create.argtypes = [ctypes.c_int,
+ ctypes.POINTER(ImageComptParmType),
+ ctypes.c_int]
+ OPENJPEG.opj_image_create.restype = ctypes.POINTER(ImageType)
+
+ image = OPENJPEG.opj_image_create(len(cmptparms), cmptparms, cspace)
+ return(image)
+
+
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_encoder_parameters():
+ """Wrapper for openjpeg library function opj_set_default_encoder_parameters.
+ """
+ cparams = CompressionParametersType()
+ argtypes = [ctypes.POINTER(CompressionParametersType)]
+ OPENJPEG.opj_set_default_encoder_parameters.argtypes = argtypes
+ OPENJPEG.opj_set_default_encoder_parameters(ctypes.byref(cparams))
+ return cparams
+
+
def set_default_decoder_parameters(dparams_p):
"""Wrapper for opj_set_default_decoder_parameters.
"""
@@ -219,6 +629,15 @@ def set_event_mgr(dinfo, event_mgr, context=None):
event_mgr, context)
+def setup_encoder(cinfo, cparameters, image):
+ """Wrapper for openjpeg library function opj_setup_decoder."""
+ argtypes = [ctypes.POINTER(CompressionInfoType),
+ ctypes.POINTER(CompressionParametersType),
+ ctypes.POINTER(ImageType)]
+ OPENJPEG.opj_setup_encoder.argtypes = argtypes
+ OPENJPEG.opj_setup_encoder(cinfo, cparameters, image)
+
+
def setup_decoder(dinfo, dparams):
"""Wrapper for openjpeg library function opj_setup_decoder."""
argtypes = [ctypes.POINTER(DecompressionInfoType),
diff --git a/glymur/test/fixtures.py b/glymur/test/fixtures.py
index eec9e22..b872f1d 100644
--- a/glymur/test/fixtures.py
+++ b/glymur/test/fixtures.py
@@ -1,6 +1,7 @@
"""
Test fixtures common to more than one test point.
"""
+import os
import re
import sys
import warnings
@@ -9,11 +10,6 @@ import numpy as np
import glymur
-# Need to know the openjpeg version. If openjpeg is not installed, we use
-# '0.0.0'
-OPENJPEG_VERSION = '0.0.0'
-if glymur.lib.openjpeg.OPENJPEG is not None:
- OPENJPEG_VERSION = glymur.lib.openjpeg.version()
# Need to know of the libopenjp2 version is the official 2.0.0 release and NOT
# the 2.0+ development version.
@@ -27,6 +23,19 @@ if glymur.lib.openjp2.OPENJP2 is not None:
NO_READ_BACKEND_MSG = "Matplotlib with the PIL backend must be available in "
NO_READ_BACKEND_MSG += "order to run the tests in this suite."
+try:
+ OPJ_DATA_ROOT = os.environ['OPJ_DATA_ROOT']
+except KeyError:
+ OPJ_DATA_ROOT = None
+except:
+ raise
+
+
+def opj_data_file(relative_file_name):
+ """Compact way of forming a full filename from OpenJPEG's test suite."""
+ jfile = os.path.join(OPJ_DATA_ROOT, relative_file_name)
+ return jfile
+
try:
from matplotlib.pyplot import imread
diff --git a/glymur/test/test_config.py b/glymur/test/test_config.py
index af95bd3..16af663 100644
--- a/glymur/test/test_config.py
+++ b/glymur/test/test_config.py
@@ -117,8 +117,10 @@ class TestConfig(unittest.TestCase):
"""
with patch('glymur.lib.openjp2.OPENJP2', new=None):
with patch('glymur.lib.openjpeg.OPENJPEG', new=None):
- with self.assertRaises(glymur.jp2k.LibraryNotFoundError):
- glymur.Jp2k(self.jp2file).read_bands()
+ with patch('glymur.version.openjpeg_version_tuple',
+ new=(0, 0, 0)):
+ with self.assertRaises(glymur.jp2k.LibraryNotFoundError):
+ glymur.Jp2k(self.jp2file).read_bands()
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
def test_write_without_library(self):
diff --git a/glymur/test/test_conformance.py b/glymur/test/test_conformance.py
index 3c7c9c4..5f53b5f 100644
--- a/glymur/test/test_conformance.py
+++ b/glymur/test/test_conformance.py
@@ -12,6 +12,7 @@ These tests deal with JPX/JP2/J2K images in the format-corpus repository.
import os
from os.path import join
+import re
import sys
if sys.hexversion < 0x02070000:
@@ -19,6 +20,7 @@ if sys.hexversion < 0x02070000:
else:
import unittest
+import glymur
from glymur import Jp2k
try:
@@ -39,6 +41,9 @@ except KeyError:
class TestSuiteFormatCorpus(unittest.TestCase):
"""Test suite for files in format corpus repository."""
+ @unittest.skipIf(re.match(r"""1\.[0123]""",
+ glymur.version.openjpeg_version) is not None,
+ "Needs 1.3+ to catch this.")
def test_balloon_trunc1(self):
"""Has one byte shaved off of EOC marker."""
jfile = os.path.join(FORMAT_CORPUS_DATA_ROOT,
@@ -54,6 +59,9 @@ class TestSuiteFormatCorpus(unittest.TestCase):
with self.assertRaises(OSError):
j2k.read(rlevel=-1)
+ @unittest.skipIf(re.match(r"""1\.[01234]""",
+ glymur.version.openjpeg_version) is not None,
+ "Needs 1.4+ to catch this.")
def test_balloon_trunc2(self):
"""Shortened by 5000 bytes."""
jfile = os.path.join(FORMAT_CORPUS_DATA_ROOT,
diff --git a/glymur/test/test_icc.py b/glymur/test/test_icc.py
index bf589a5..8668999 100644
--- a/glymur/test/test_icc.py
+++ b/glymur/test/test_icc.py
@@ -20,16 +20,10 @@ else:
import numpy as np
from glymur import Jp2k
-
-try:
- DATA_ROOT = os.environ['OPJ_DATA_ROOT']
-except KeyError:
- DATA_ROOT = None
-except:
- raise
+from .fixtures import OPJ_DATA_ROOT, opj_data_file
-@unittest.skipIf(DATA_ROOT is None,
+@unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
class TestICC(unittest.TestCase):
"""ICC profile tests"""
@@ -42,7 +36,7 @@ class TestICC(unittest.TestCase):
def test_file5(self):
"""basic ICC profile"""
- filename = os.path.join(DATA_ROOT, 'input/conformance/file5.jp2')
+ filename = opj_data_file('input/conformance/file5.jp2')
j = Jp2k(filename)
profile = j.box[3].box[1].icc_profile
self.assertEqual(profile['Size'], 546)
@@ -75,8 +69,7 @@ class TestICC(unittest.TestCase):
"Uses features introduced in 3.2.")
def test_invalid_profile_header(self):
"""invalid ICC header data should cause UserWarning"""
- jfile = os.path.join(DATA_ROOT,
- 'input/nonregression/orb-blue10-lin-jp2.jp2')
+ jfile = opj_data_file('input/nonregression/orb-blue10-lin-jp2.jp2')
# assertWarns in Python 3.3 (python2.7/pylint issue)
# pylint: disable=E1101
diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py
index ea19199..bbf551b 100644
--- a/glymur/test/test_jp2k.py
+++ b/glymur/test/test_jp2k.py
@@ -25,10 +25,6 @@ if sys.hexversion < 0x02070000:
else:
import unittest
-if sys.hexversion <= 0x03030000:
- from mock import patch
-else:
- from unittest.mock import patch
import warnings
import numpy as np
@@ -38,14 +34,7 @@ import glymur
from glymur import Jp2k
from .fixtures import OPENJP2_IS_V2_OFFICIAL
-from .fixtures import OPENJPEG_VERSION
-
-try:
- DATA_ROOT = os.environ['OPJ_DATA_ROOT']
-except KeyError:
- DATA_ROOT = None
-except:
- raise
+from .fixtures import OPJ_DATA_ROOT, opj_data_file
# Doc tests should be run as well.
@@ -130,10 +119,164 @@ class TestJp2kBadXmlFile(unittest.TestCase):
self.assertIsNone(jp2k.box[3].xml)
+@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None and not OPENJP2_IS_V2_OFFICIAL,
+ "Missing openjp2 library version 2.0+.")
+class TestJp2k_2_1(unittest.TestCase):
+ """Test suite for version 2.0+ of openjpeg software"""
+
+ def setUp(self):
+ self.jp2file = glymur.data.nemo()
+ self.j2kfile = glymur.data.goodstuff()
+
+ def tearDown(self):
+ pass
+
+ @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
+ def test_grey_with_extra_component(self):
+ """version 2.0 cannot write gray + extra"""
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
+ j = Jp2k(tfile.name, 'wb')
+ data = np.zeros((128, 128, 2), dtype=np.uint8)
+ j.write(data)
+ self.assertEqual(j.box[2].box[0].height, 128)
+ self.assertEqual(j.box[2].box[0].width, 128)
+ self.assertEqual(j.box[2].box[0].num_components, 2)
+ 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):
+ """v2.0+ should be able to write extra components"""
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
+ j = Jp2k(tfile.name, 'wb')
+ data = np.zeros((128, 128, 4), dtype=np.uint8)
+ j.write(data)
+ self.assertEqual(j.box[2].box[0].height, 128)
+ self.assertEqual(j.box[2].box[0].width, 128)
+ self.assertEqual(j.box[2].box[0].num_components, 4)
+ self.assertEqual(j.box[2].box[1].colorspace, glymur.core.SRGB)
+
+ @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.
+ with open(self.jp2file, 'rb') as fptr:
+ data = fptr.read()
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
+ # Codestream starts at byte 3127. SIZ marker at 3137.
+ # COD marker at 3186. Subsampling at 3180.
+ tfile.write(data[0:3179])
+
+ # Make the DY bytes of the SIZ segment zero. That means that
+ # a subsampling factor is zero, which is illegal.
+ tfile.write(b'\x00')
+ tfile.write(data[3180:3182])
+ tfile.write(b'\x00')
+ tfile.write(data[3184:3186])
+ tfile.write(b'\x00')
+
+ tfile.write(data[3186:])
+ tfile.flush()
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore")
+ j = Jp2k(tfile.name)
+ regexp = re.compile(r'''OpenJPEG\slibrary\serror:\s+
+ Invalid\svalues\sfor\scomp\s=\s0\s+
+ :\sdx=1\sdy=0''', re.VERBOSE)
+ if sys.hexversion < 0x03020000:
+ with self.assertRaisesRegexp((IOError, OSError), regexp):
+ j.read(rlevel=1)
+ else:
+ with self.assertRaisesRegex((IOError, OSError), regexp):
+ j.read(rlevel=1)
+
+
+@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] < 2,
+ "Not tested for 1.x")
+class TestJp2k_2_0(unittest.TestCase):
+ """Test suite requiring at least version 2.0"""
+
+ def setUp(self):
+ self.jp2file = glymur.data.nemo()
+ self.j2kfile = glymur.data.goodstuff()
+
+ def tearDown(self):
+ pass
+
+ @unittest.skipIf(not OPENJP2_IS_V2_OFFICIAL,
+ "Behavior is specific to 2.0 official.")
+ @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
+ def test_extra_components_on_v2(self):
+ """must error out in 1.x with extra components."""
+ # Extra components seems to require 2.0+. Verify that we error out.
+ with self.assertRaises(OSError):
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
+ j = Jp2k(tfile.name, 'wb')
+ data = np.zeros((128, 128, 4), dtype=np.uint8)
+ j.write(data)
+
+ @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
+ def test_unrecognized_jp2_clrspace(self):
+ """We only allow RGB and GRAYSCALE. Should error out with others"""
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
+ j = Jp2k(tfile.name, 'wb')
+ with self.assertRaises(IOError):
+ 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_asoc_label_box(self):
+ """Test asoc and label box"""
+ # Construct a fake file with an asoc and a label box, as
+ # OpenJPEG doesn't have such a file.
+ data = Jp2k(self.jp2file).read(rlevel=1)
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
+ j = Jp2k(tfile.name, 'wb')
+ j.write(data)
+
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile2:
+
+ # Offset of the codestream is where we start.
+ read_buffer = tfile.read(77)
+ tfile2.write(read_buffer)
+
+ # read the rest of the file, it's the codestream.
+ codestream = tfile.read()
+
+ # Write the asoc superbox.
+ # Length = 36, id is 'asoc'.
+ write_buffer = struct.pack('>I4s', int(56), b'asoc')
+ tfile2.write(write_buffer)
+
+ # Write the contained label box
+ write_buffer = struct.pack('>I4s', int(13), b'lbl ')
+ tfile2.write(write_buffer)
+ tfile2.write('label'.encode())
+
+ # Write the xml box
+ # Length = 36, id is 'xml '.
+ write_buffer = struct.pack('>I4s', int(35), b'xml ')
+ tfile2.write(write_buffer)
+
+ write_buffer = 'this is a test'
+ write_buffer = write_buffer.encode()
+ tfile2.write(write_buffer)
+
+ # Now append the codestream.
+ tfile2.write(codestream)
+ tfile2.flush()
+
+ jasoc = Jp2k(tfile2.name)
+ 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].box_id, 'xml ')
+
+
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
"Missing openjp2 library.")
-class TestJp2k(unittest.TestCase):
- """Test suite for version 2.0/2.0+ of openjpeg"""
+class TestJp2k_1_x(unittest.TestCase):
+ """Test suite for versions up to 1.5.1 of openjpeg but no further"""
def setUp(self):
self.jp2file = glymur.data.nemo()
@@ -169,20 +312,6 @@ class TestJp2k(unittest.TestCase):
with self.assertRaises(IOError):
j.read(rlevel=6)
- def test_not_jpeg2000(self):
- """Should error out appropriately if not given a JPEG 2000 file."""
- filename = pkg_resources.resource_filename(glymur.__name__, "jp2k.py")
- with self.assertRaises(IOError):
- Jp2k(filename)
-
- def test_file_not_present(self):
- """Should error out if reading from a file that does not exist"""
- # Verify that we error out appropriately if not given an existing file
- # at all.
- with self.assertRaises(OSError):
- filename = 'this file does not actually exist on the file system.'
- Jp2k(filename)
-
@unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
def test_write_with_jp2_in_caps(self):
"""should be able to write with JP2 suffix."""
@@ -368,669 +497,445 @@ class TestJp2k(unittest.TestCase):
self.assertEqual(new_jp2.box[j].length,
baseline_jp2.box[j].length)
+ @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
+ def test_cblkh_different_than_width(self):
+ """Verify that we can set a code block size where height does not equal
+ width.
+ """
+ data = np.zeros((128, 128), dtype=np.uint8)
+ with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
+ j = Jp2k(tfile.name, 'wb')
+
+ # The code block dimensions are given as rows x columns.
+ j.write(data, cbsize=(16, 32))
+
+ codestream = j.get_codestream()
+
+ # Code block size is reported as XY in the codestream.
+ self.assertEqual(tuple(codestream.segment[2].spcod[5:7]), (3, 2))
+
+ @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
+ def test_too_many_dimensions(self):
+ """OpenJP2 only allows 2D or 3D images."""
+ with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
+ j = Jp2k(tfile.name, 'wb')
+ with self.assertRaises(IOError):
+ data = np.zeros((128, 128, 2, 2), dtype=np.uint8)
+ j.write(data)
+
+ @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:
+ j = Jp2k(tfile.name, 'wb')
+ with self.assertRaises(IOError):
+ 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:
+ j = Jp2k(tfile.name, 'wb')
+ with self.assertRaises(IOError):
+ 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):
+ """specify RGB explicitly"""
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
+ j = Jp2k(tfile.name, 'wb')
+ data = np.zeros((128, 128, 3), dtype=np.uint8)
+ 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):
+ """test gray explicitly specified (that's GRAY, not GREY)"""
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
+ j = Jp2k(tfile.name, 'wb')
+ data = np.zeros((128, 128), dtype=np.uint8)
+ j.write(data, colorspace='gray')
+ 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):
+ """test grey explicitly specified"""
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
+ j = Jp2k(tfile.name, 'wb')
+ data = np.zeros((128, 128), dtype=np.uint8)
+ j.write(data, colorspace='grey')
+ 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_comps(self):
+ """should be able to write gray + two extra components"""
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
+ j = Jp2k(tfile.name, 'wb')
+ data = np.zeros((128, 128, 3), dtype=np.uint8)
+ j.write(data, colorspace='gray')
+ self.assertEqual(j.box[2].box[0].height, 128)
+ self.assertEqual(j.box[2].box[0].width, 128)
+ self.assertEqual(j.box[2].box[0].num_components, 3)
+ self.assertEqual(j.box[2].box[1].colorspace,
+ glymur.core.GREYSCALE)
+
+ def test_specify_ycc(self):
+ """Should reject YCC"""
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
+ j = Jp2k(tfile.name, 'wb')
+ with self.assertRaises(IOError):
+ 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_write_with_jp2_in_caps(self):
+ """should be able to write with JP2 suffix."""
+ j2k = Jp2k(self.j2kfile)
+ expdata = j2k.read()
+ with tempfile.NamedTemporaryFile(suffix='.JP2') as tfile:
+ ofile = Jp2k(tfile.name, 'wb')
+ ofile.write(expdata)
+ actdata = ofile.read()
+ np.testing.assert_array_equal(actdata, expdata)
+
+ @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
+ def test_write_srgb_without_mct(self):
+ """should be able to write RGB without specifying mct"""
+ j2k = Jp2k(self.j2kfile)
+ expdata = j2k.read()
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
+ ofile = Jp2k(tfile.name, 'wb')
+ ofile.write(expdata, mct=False)
+ actdata = ofile.read()
+ np.testing.assert_array_equal(actdata, expdata)
+
+ codestream = ofile.get_codestream()
+ self.assertEqual(codestream.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)
+ expdata = j2k.read()
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
+ ofile = Jp2k(tfile.name, 'wb')
+ with self.assertRaises(IOError):
+ ofile.write(expdata[:, :, 0], mct=True)
+
+ @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
+ def test_write_cprl(self):
+ """Must be able to write a CPRL progression order file"""
+ # Issue 17
+ j = Jp2k(self.jp2file)
+ expdata = j.read(rlevel=1)
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
+ ofile = Jp2k(tfile.name, 'wb')
+ ofile.write(expdata, prog='CPRL')
+ actdata = ofile.read()
+ np.testing.assert_array_equal(actdata, expdata)
+
+ codestream = ofile.get_codestream()
+ self.assertEqual(codestream.segment[2].spcod[0], glymur.core.CPRL)
+
+
+@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is not None,
+ "Don't bother if openjp2 is present.")
+@unittest.skipIf(glymur.lib.openjpeg.OPENJPEG is None,
+ "Missing openjpeg library.")
+class TestJp2k15(unittest.TestCase):
+ """Test suite for openjpeg 1.x, not appropriate for 2.x"""
+
+ def setUp(self):
+ self.jp2file = glymur.data.nemo()
+ self.j2kfile = glymur.data.goodstuff()
+
+ def tearDown(self):
+ pass
+
+ 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)
+
+ @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
+ @unittest.skipIf(glymur.version.openjpeg_version_tuple[1] < 5,
+ "Writing only supported with openjpeg version 1.5+.")
+ def test_2d_rgb(self):
+ """RGB must have at least 3 components."""
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
+ j = Jp2k(tfile.name, 'wb')
+ with self.assertRaises(IOError):
+ 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_xml_with_trailing_nulls(self):
+ """ElementTree doesn't like trailing null chars after valid XML text"""
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
+ with open(self.jp2file, 'rb') as ifile:
+ # Everything up until the jp2c box.
+ write_buffer = ifile.read(77)
+ tfile.write(write_buffer)
+
+ # Write the xml box
+ # Length = 36, id is 'xml '.
+ write_buffer = struct.pack('>I4s', int(36), b'xml ')
+ tfile.write(write_buffer)
+
+ write_buffer = 'this is a test' + chr(0)
+ write_buffer = write_buffer.encode()
+ tfile.write(write_buffer)
+
+ # Get the rest of the input file.
+ write_buffer = ifile.read()
+ tfile.write(write_buffer)
+ tfile.flush()
+
+ jp2k = Jp2k(tfile.name)
+
+ self.assertEqual(jp2k.box[3].box_id, 'xml ')
+ self.assertEqual(jp2k.box[3].offset, 77)
+ self.assertEqual(jp2k.box[3].length, 36)
+ self.assertEqual(ET.tostring(jp2k.box[3].xml.getroot()),
+ b'this is a test')
+
+ @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
+ @unittest.skipIf(glymur.version.openjpeg_version_tuple[0] < 2,
+ "Segfault on official v1.x series.")
+ 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.
+ with open(self.jp2file, 'rb') as fptr:
+ data = fptr.read()
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
+ # Codestream starts at byte 3127. SIZ marker at 3137.
+ # COD marker at 3186. Subsampling at 3180.
+ tfile.write(data[0:3179])
+
+ # Make the DY bytes of the SIZ segment zero. That means that
+ # a subsampling factor is zero, which is illegal.
+ tfile.write(b'\x00')
+ tfile.write(data[3180:3182])
+ tfile.write(b'\x00')
+ tfile.write(data[3184:3186])
+ tfile.write(b'\x00')
+
+ tfile.write(data[3186:])
+ tfile.flush()
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore")
+ j = Jp2k(tfile.name)
+ regexp = re.compile(r'''OpenJPEG\slibrary\serror:\s+
+ Invalid\svalues\sfor\scomp\s=\s0\s+
+ :\sdx=1\sdy=0''', re.VERBOSE)
+ if sys.hexversion < 0x03020000:
+ with self.assertRaisesRegexp((IOError, OSError), regexp):
+ j.read(rlevel=1)
+ else:
+ with self.assertRaisesRegex((IOError, OSError), regexp):
+ j.read(rlevel=1)
+
+
+class TestJp2k(unittest.TestCase):
+ """Test suite for openjpeg software starting at 1.3"""
+
+ 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_rlevel_too_high(self):
+ """Should error out appropriately if reduce level too high"""
+ j = Jp2k(self.jp2file)
+ with self.assertRaises(IOError):
+ j.read(rlevel=6)
+
+ def test_not_jpeg2000(self):
+ """Should error out appropriately if not given a JPEG 2000 file."""
+ filename = pkg_resources.resource_filename(glymur.__name__, "jp2k.py")
+ with self.assertRaises(IOError):
+ Jp2k(filename)
+
+ def test_file_not_present(self):
+ """Should error out if reading from a file that does not exist"""
+ # Verify that we error out appropriately if not given an existing file
+ # at all.
+ with self.assertRaises(OSError):
+ filename = 'this file does not actually exist on the file system.'
+ Jp2k(filename)
+
+ def test_jp2_boxes(self):
+ """Verify the boxes of a JP2 file. Basic jp2 test."""
+ jp2k = Jp2k(self.jp2file)
+
+ # top-level boxes
+ self.assertEqual(len(jp2k.box), 6)
+
+ 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].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].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].box_id, 'uuid')
+ self.assertEqual(jp2k.box[3].offset, 77)
+ self.assertEqual(jp2k.box[3].length, 638)
+
+ 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].box_id, 'jp2c')
+ self.assertEqual(jp2k.box[5].offset, 3127)
+ 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].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')
+ self.assertEqual(jp2k.box[2].box[0].height, 1456)
+ self.assertEqual(jp2k.box[2].box[0].width, 2592)
+ self.assertEqual(jp2k.box[2].box[0].num_components, 3)
+ self.assertEqual(jp2k.box[2].box[0].bits_per_component, 8)
+ self.assertEqual(jp2k.box[2].box[0].signed, False)
+ self.assertEqual(jp2k.box[2].box[0].compression, 7)
+ 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].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')
+ self.assertEqual(jp2k.box[2].box[1].precedence, 0)
+ self.assertEqual(jp2k.box[2].box[1].approximation, 0)
+ self.assertEqual(jp2k.box[2].box[1].colorspace, glymur.core.SRGB)
+ self.assertIsNone(jp2k.box[2].box[1].icc_profile)
+
+ def test_j2k_box(self):
+ """A J2K/J2C file must not have any boxes."""
+ # Verify that a J2K file has no boxes.
+ jp2k = Jp2k(self.j2kfile)
+ self.assertEqual(len(jp2k.box), 0)
+
+ @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
+ def test_64bit_xl_field(self):
+ """XL field should be supported"""
+ # 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
+ # file, but making the codestream have a 64-bit XL field.
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
+ with open(self.jp2file, 'rb') as ifile:
+ # Everything up until the jp2c box.
+ write_buffer = ifile.read(3127)
+ tfile.write(write_buffer)
+
+ # The L field must be 1 in order to signal the presence of the
+ # XL field. The actual length of the jp2c box increased by 8
+ # (8 bytes for the XL field).
+ length = 1
+ typ = b'jp2c'
+ xlen = 1133427 + 8
+ write_buffer = struct.pack('>I4sQ', int(length), typ, xlen)
+ tfile.write(write_buffer)
+
+ # Get the rest of the input file (minus the 8 bytes for L and
+ # T.
+ ifile.seek(8, 1)
+ write_buffer = ifile.read()
+ tfile.write(write_buffer)
+ tfile.flush()
+
+ jp2k = Jp2k(tfile.name)
+
+ 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_length_field_is_zero(self):
+ """L=0 (length field in box header) is allowed"""
+ # 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.
+ # Our example image has its last box at byte 588458.
+ baseline_jp2 = Jp2k(self.jp2file)
+ with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
+ with open(self.jp2file, 'rb') as ifile:
+ # Everything up until the jp2c box.
+ write_buffer = ifile.read(588458)
+ tfile.write(write_buffer)
+
+ length = 0
+ typ = b'uuid'
+ write_buffer = struct.pack('>I4s', int(length), typ)
+ tfile.write(write_buffer)
+
+ # Get the rest of the input file (minus the 8 bytes for L and
+ # T.
+ ifile.seek(8, 1)
+ write_buffer = ifile.read()
+ tfile.write(write_buffer)
+ tfile.flush()
+
+ new_jp2 = Jp2k(tfile.name)
+
+ # The top level boxes in each file should match.
+ for j in range(len(baseline_jp2.box)):
+ 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,
+ baseline_jp2.box[j].length)
+
def test_basic_jp2(self):
"""Just a very basic test that reading a JP2 file does not error out.
"""
j2k = Jp2k(self.jp2file)
j2k.read(rlevel=1)
- def test_basic_j2k(self):
- """Just a very basic test that reading a J2K file does not error out.
- """
- j2k = Jp2k(self.j2kfile)
- j2k.read()
-
- @unittest.skipIf(DATA_ROOT is None,
- "OPJ_DATA_ROOT environment variable not set")
- def test_read_differing_subsamples(self):
- """should error out with read used on differently subsampled images"""
- # Verify that we error out appropriately if we use the read method
- # on an image with differing subsamples
- #
- # Issue 86.
- filename = os.path.join(DATA_ROOT, 'input/conformance/p0_05.j2k')
- j = Jp2k(filename)
- with self.assertRaises(RuntimeError):
- j.read()
-
- def test_empty_box_with_j2k(self):
- """Verify that the list of boxes in a J2C/J2K file is present, but
- empty.
- """
- j = Jp2k(self.j2kfile)
- self.assertEqual(j.box, [])
-
- @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
- def test_cblkh_different_than_width(self):
- """Verify that we can set a code block size where height does not equal
- width.
- """
- data = np.zeros((128, 128), dtype=np.uint8)
- with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
- j = Jp2k(tfile.name, 'wb')
-
- # The code block dimensions are given as rows x columns.
- j.write(data, cbsize=(16, 32))
-
- codestream = j.get_codestream()
-
- # Code block size is reported as XY in the codestream.
- self.assertEqual(tuple(codestream.segment[2].spcod[5:7]), (3, 2))
-
- @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
- def test_too_many_dimensions(self):
- """OpenJP2 only allows 2D or 3D images."""
- with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
- j = Jp2k(tfile.name, 'wb')
- with self.assertRaises(IOError):
- 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_clrspace(self):
- """We only allow RGB and GRAYSCALE. Should error out with others"""
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- with self.assertRaises(IOError):
- 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:
- j = Jp2k(tfile.name, 'wb')
- with self.assertRaises(IOError):
- 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:
- j = Jp2k(tfile.name, 'wb')
- with self.assertRaises(IOError):
- 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):
- """specify RGB explicitly"""
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- data = np.zeros((128, 128, 3), dtype=np.uint8)
- 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):
- """test gray explicitly specified (that's GRAY, not GREY)"""
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- data = np.zeros((128, 128), dtype=np.uint8)
- j.write(data, colorspace='gray')
- 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):
- """test grey explicitly specified"""
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- data = np.zeros((128, 128), dtype=np.uint8)
- j.write(data, colorspace='grey')
- self.assertEqual(j.box[2].box[1].colorspace,
- glymur.core.GREYSCALE)
-
- @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL,
- "Does not seem to work on official v2.0.0 release.")
- @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
- def test_grey_with_extra_component(self):
- """version 2.0 cannot write gray + extra"""
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- data = np.zeros((128, 128, 2), dtype=np.uint8)
- j.write(data)
- self.assertEqual(j.box[2].box[0].height, 128)
- self.assertEqual(j.box[2].box[0].width, 128)
- self.assertEqual(j.box[2].box[0].num_components, 2)
- 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_comps(self):
- """should be able to write gray + two extra components"""
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- data = np.zeros((128, 128, 3), dtype=np.uint8)
- j.write(data, colorspace='gray')
- self.assertEqual(j.box[2].box[0].height, 128)
- self.assertEqual(j.box[2].box[0].width, 128)
- self.assertEqual(j.box[2].box[0].num_components, 3)
- self.assertEqual(j.box[2].box[1].colorspace,
- glymur.core.GREYSCALE)
-
- @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL,
- "Does not seem to work on official v2.0.0 release.")
- @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
- def test_rgb_with_extra_component(self):
- """v2.0+ should be able to write extra components"""
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- data = np.zeros((128, 128, 4), dtype=np.uint8)
- j.write(data)
- self.assertEqual(j.box[2].box[0].height, 128)
- self.assertEqual(j.box[2].box[0].width, 128)
- self.assertEqual(j.box[2].box[0].num_components, 4)
- self.assertEqual(j.box[2].box[1].colorspace, glymur.core.SRGB)
-
- @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL is False,
- "Test is specific for v2.0.0 release")
- @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
- def test_extra_components_on_v2(self):
- """must error out in 1.x with extra components."""
- # Extra components seems to require 2.0+. Verify that we error out.
- with self.assertRaises(IOError):
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- data = np.zeros((128, 128, 4), dtype=np.uint8)
- j.write(data)
-
- def test_specify_ycc(self):
- """Should reject YCC"""
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- with self.assertRaises(IOError):
- 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"""
- # 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
- # openjpeg repository, so I'll fake one.
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- with open(self.jp2file, 'rb') as ifile:
- # Everything up until the jp2c box.
- write_buffer = ifile.read(77)
- tfile.write(write_buffer)
-
- # Write the UINF superbox
- # Length = 50, id is uinf.
- write_buffer = struct.pack('>I4s', int(50), b'uinf')
- tfile.write(write_buffer)
-
- # Write the ULST box.
- # Length is 26, 1 UUID, hard code that UUID as zeros.
- write_buffer = struct.pack('>I4sHIIII', int(26), b'ulst',
- int(1), int(0), int(0), int(0),
- int(0))
- tfile.write(write_buffer)
-
- # Write the URL box.
- # Length is 16, version is one byte, flag is 3 bytes, url
- # is the rest.
- write_buffer = struct.pack('>I4sBBBB',
- int(16), b'url ',
- int(0), int(0), int(0), int(0))
- tfile.write(write_buffer)
- write_buffer = struct.pack('>ssss', b'a', b'b', b'c', b'd')
- tfile.write(write_buffer)
-
- # Get the rest of the input file.
- write_buffer = ifile.read()
- tfile.write(write_buffer)
- tfile.flush()
-
- jp2k = Jp2k(tfile.name)
-
- 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].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].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')
-
- @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
- def test_xml_with_trailing_nulls(self):
- """ElementTree doesn't like trailing null chars after valid XML text"""
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- with open(self.jp2file, 'rb') as ifile:
- # Everything up until the jp2c box.
- write_buffer = ifile.read(77)
- tfile.write(write_buffer)
-
- # Write the xml box
- # Length = 36, id is 'xml '.
- write_buffer = struct.pack('>I4s', int(36), b'xml ')
- tfile.write(write_buffer)
-
- write_buffer = 'this is a test' + chr(0)
- write_buffer = write_buffer.encode()
- tfile.write(write_buffer)
-
- # Get the rest of the input file.
- write_buffer = ifile.read()
- tfile.write(write_buffer)
- tfile.flush()
-
- jp2k = Jp2k(tfile.name)
-
- self.assertEqual(jp2k.box[3].box_id, 'xml ')
- self.assertEqual(jp2k.box[3].offset, 77)
- self.assertEqual(jp2k.box[3].length, 36)
- self.assertEqual(ET.tostring(jp2k.box[3].xml.getroot()),
- b'this is a test')
-
- @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
- def test_asoc_label_box(self):
- """Test asoc and label box"""
- # Construct a fake file with an asoc and a label box, as
- # OpenJPEG doesn't have such a file.
- data = Jp2k(self.jp2file).read(rlevel=1)
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- j.write(data)
-
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile2:
-
- # Offset of the codestream is where we start.
- read_buffer = tfile.read(77)
- tfile2.write(read_buffer)
-
- # read the rest of the file, it's the codestream.
- codestream = tfile.read()
-
- # Write the asoc superbox.
- # Length = 36, id is 'asoc'.
- write_buffer = struct.pack('>I4s', int(56), b'asoc')
- tfile2.write(write_buffer)
-
- # Write the contained label box
- write_buffer = struct.pack('>I4s', int(13), b'lbl ')
- tfile2.write(write_buffer)
- tfile2.write('label'.encode())
-
- # Write the xml box
- # Length = 36, id is 'xml '.
- write_buffer = struct.pack('>I4s', int(35), b'xml ')
- tfile2.write(write_buffer)
-
- write_buffer = 'this is a test'
- write_buffer = write_buffer.encode()
- tfile2.write(write_buffer)
-
- # Now append the codestream.
- tfile2.write(codestream)
- tfile2.flush()
-
- jasoc = Jp2k(tfile2.name)
- 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].box_id, 'xml ')
-
- @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
- @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL,
- "Segfault on official v2.0.0 release.")
- 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.
- with open(self.jp2file, 'rb') as fptr:
- data = fptr.read()
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- # Codestream starts at byte 3127. SIZ marker at 3137.
- # COD marker at 3186. Subsampling at 3180.
- tfile.write(data[0:3179])
-
- # Make the DY bytes of the SIZ segment zero. That means that
- # a subsampling factor is zero, which is illegal.
- tfile.write(b'\x00')
- tfile.write(data[3180:3182])
- tfile.write(b'\x00')
- tfile.write(data[3184:3186])
- tfile.write(b'\x00')
-
- tfile.write(data[3186:])
- tfile.flush()
- with warnings.catch_warnings():
- warnings.simplefilter("ignore")
- j = Jp2k(tfile.name)
- regexp = re.compile(r'''OpenJPEG\slibrary\serror:\s+
- Invalid\svalues\sfor\scomp\s=\s0\s+
- :\sdx=1\sdy=0''', re.VERBOSE)
- if sys.hexversion < 0x03020000:
- with self.assertRaisesRegexp((IOError, OSError), regexp):
- j.read(rlevel=1)
- else:
- with self.assertRaisesRegex((IOError, OSError), regexp):
- j.read(rlevel=1)
-
- def test_xmp_attribute(self):
- """Verify the XMP packet in the shipping example file can be read."""
- j = Jp2k(self.jp2file)
- xmp = j.box[4].data
- ns0 = '{http://www.w3.org/1999/02/22-rdf-syntax-ns#}'
- ns1 = '{http://ns.adobe.com/xap/1.0/}'
- name = '{0}RDF/{0}Description'.format(ns0)
- elt = xmp.find(name)
- 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:
- shutil.copyfile(self.jp2file, tfile.name)
-
- # The Exif UUID starts at byte 77. There are 8 bytes for the L and
- # T fields, then 16 bytes for the UUID identifier, then 6 exif
- # header bytes, then 8 bytes for the TIFF header, then 2 bytes
- # the the Image IFD number of tags, where we finally find the first
- # tag, "Make" (271). We'll corrupt it by changing it into 171,
- # which does not correspond to any known Exif Image tag.
- with open(tfile.name, 'r+b') as fptr:
- fptr.seek(117)
- write_buffer = struct.pack('I4sQ', int(length), typ, xlen)
- tfile.write(write_buffer)
-
- # Get the rest of the input file (minus the 8 bytes for L and
- # T.
- ifile.seek(8, 1)
- write_buffer = ifile.read()
- tfile.write(write_buffer)
- tfile.flush()
-
- jp2k = Jp2k(tfile.name)
-
- 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_length_field_is_zero(self):
- """L=0 (length field in box header) is allowed"""
- # 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.
- # Our example image has its last box at byte 588458.
- baseline_jp2 = Jp2k(self.jp2file)
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- with open(self.jp2file, 'rb') as ifile:
- # Everything up until the jp2c box.
- write_buffer = ifile.read(588458)
- tfile.write(write_buffer)
-
- length = 0
- typ = b'uuid'
- write_buffer = struct.pack('>I4s', int(length), typ)
- tfile.write(write_buffer)
-
- # Get the rest of the input file (minus the 8 bytes for L and
- # T.
- ifile.seek(8, 1)
- write_buffer = ifile.read()
- tfile.write(write_buffer)
- tfile.flush()
-
- new_jp2 = Jp2k(tfile.name)
-
- # The top level boxes in each file should match.
- for j in range(len(baseline_jp2.box)):
- 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,
- baseline_jp2.box[j].length)
-
- 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
@@ -1039,7 +944,7 @@ class TestJp2k15(unittest.TestCase):
j2k = Jp2k(self.j2kfile)
j2k.read()
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_read_differing_subsamples(self):
"""should error out with read used on differently subsampled images"""
@@ -1047,7 +952,7 @@ class TestJp2k15(unittest.TestCase):
# on an image with differing subsamples
#
# Issue 86.
- filename = os.path.join(DATA_ROOT, 'input/conformance/p0_05.j2k')
+ filename = opj_data_file('input/conformance/p0_05.j2k')
j = Jp2k(filename)
with self.assertRaises(RuntimeError):
j.read()
@@ -1059,154 +964,6 @@ class TestJp2k15(unittest.TestCase):
j = Jp2k(self.j2kfile)
self.assertEqual(j.box, [])
- @unittest.skip("Writing requires openjp2 library at the moment.")
- @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
- def test_cblkh_different_than_width(self):
- """Verify that we can set a code block size where height does not equal
- width.
- """
- data = np.zeros((128, 128), dtype=np.uint8)
- with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
- j = Jp2k(tfile.name, 'wb')
-
- # The code block dimensions are given as rows x columns.
- j.write(data, cbsize=(16, 32))
-
- codestream = j.get_codestream()
-
- # Code block size is reported as XY in the codestream.
- self.assertEqual(tuple(codestream.segment[2].spcod[5:7]), (3, 2))
-
- @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
- def test_too_many_dimensions(self):
- """OpenJP2 only allows 2D or 3D images."""
- with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
- j = Jp2k(tfile.name, 'wb')
- with self.assertRaises(IOError):
- 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_clrspace(self):
- """We only allow RGB and GRAYSCALE. Should error out with others"""
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- with self.assertRaises(IOError):
- 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:
- j = Jp2k(tfile.name, 'wb')
- with self.assertRaises(IOError):
- data = np.zeros((128, 128, 2), dtype=np.uint8)
- j.write(data, colorspace='rgb')
-
- @unittest.skip("Writing requires openjp2 library at the moment.")
- @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:
- j = Jp2k(tfile.name, 'wb')
- with self.assertRaises(IOError):
- data = np.zeros((128, 128, 3), dtype=np.uint8)
- j.write(data, colorspace='rgb')
-
- @unittest.skip("Writing requires openjp2 library at the moment.")
- @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
- def test_specify_rgb(self):
- """specify RGB explicitly"""
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- data = np.zeros((128, 128, 3), dtype=np.uint8)
- j.write(data, colorspace='rgb')
- self.assertEqual(j.box[2].box[1].colorspace, glymur.core.SRGB)
-
- @unittest.skip("Writing requires openjp2 library at the moment.")
- @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
- def test_specify_gray(self):
- """test gray explicitly specified (that's GRAY, not GREY)"""
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- data = np.zeros((128, 128), dtype=np.uint8)
- j.write(data, colorspace='gray')
- self.assertEqual(j.box[2].box[1].colorspace,
- glymur.core.GREYSCALE)
-
- @unittest.skip("Writing requires openjp2 library at the moment.")
- @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
- def test_specify_grey(self):
- """test grey explicitly specified"""
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- data = np.zeros((128, 128), dtype=np.uint8)
- j.write(data, colorspace='grey')
- self.assertEqual(j.box[2].box[1].colorspace,
- glymur.core.GREYSCALE)
-
- @unittest.skip("Writing requires openjp2 library at the moment.")
- @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
- def test_grey_with_extra_component(self):
- """version 2.0 cannot write gray + extra"""
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- data = np.zeros((128, 128, 2), dtype=np.uint8)
- j.write(data)
- self.assertEqual(j.box[2].box[0].height, 128)
- self.assertEqual(j.box[2].box[0].width, 128)
- self.assertEqual(j.box[2].box[0].num_components, 2)
- self.assertEqual(j.box[2].box[1].colorspace,
- glymur.core.GREYSCALE)
-
- @unittest.skip("Writing requires openjp2 library at the moment.")
- @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
- def test_grey_with_two_extra_comps(self):
- """should be able to write gray + two extra components"""
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- data = np.zeros((128, 128, 3), dtype=np.uint8)
- j.write(data, colorspace='gray')
- self.assertEqual(j.box[2].box[0].height, 128)
- self.assertEqual(j.box[2].box[0].width, 128)
- self.assertEqual(j.box[2].box[0].num_components, 3)
- self.assertEqual(j.box[2].box[1].colorspace,
- glymur.core.GREYSCALE)
-
- @unittest.skip("Writing requires openjp2 library at the moment.")
- @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
- def test_rgb_with_extra_component(self):
- """v2.0+ should be able to write extra components"""
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- data = np.zeros((128, 128, 4), dtype=np.uint8)
- j.write(data)
- self.assertEqual(j.box[2].box[0].height, 128)
- self.assertEqual(j.box[2].box[0].width, 128)
- self.assertEqual(j.box[2].box[0].num_components, 4)
- self.assertEqual(j.box[2].box[1].colorspace, glymur.core.SRGB)
-
- @unittest.skip("Writing requires openjp2 library at the moment.")
- @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
- def test_extra_components_on_v2(self):
- """must error out in 1.x with extra components."""
- # Extra components seems to require 2.0+. Verify that we error out.
- with self.assertRaises(IOError):
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- data = np.zeros((128, 128, 4), dtype=np.uint8)
- j.write(data)
-
- @unittest.skip("Writing requires openjp2 library at the moment.")
- def test_specify_ycc(self):
- """Should reject YCC"""
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- with self.assertRaises(IOError):
- 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"""
@@ -1297,91 +1054,6 @@ class TestJp2k15(unittest.TestCase):
self.assertEqual(ET.tostring(jp2k.box[3].xml.getroot()),
b'this is a test')
- @unittest.skip("Writing requires openjp2 library at the moment.")
- @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
- def test_asoc_label_box(self):
- """Test asoc and label box"""
- # Construct a fake file with an asoc and a label box, as
- # OpenJPEG doesn't have such a file.
- data = Jp2k(self.jp2file).read(rlevel=1)
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- j = Jp2k(tfile.name, 'wb')
- j.write(data)
-
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile2:
-
- # Offset of the codestream is where we start.
- read_buffer = tfile.read(77)
- tfile2.write(read_buffer)
-
- # read the rest of the file, it's the codestream.
- codestream = tfile.read()
-
- # Write the asoc superbox.
- # Length = 36, id is 'asoc'.
- write_buffer = struct.pack('>I4s', int(56), b'asoc')
- tfile2.write(write_buffer)
-
- # Write the contained label box
- write_buffer = struct.pack('>I4s', int(13), b'lbl ')
- tfile2.write(write_buffer)
- tfile2.write('label'.encode())
-
- # Write the xml box
- # Length = 36, id is 'xml '.
- write_buffer = struct.pack('>I4s', int(35), b'xml ')
- tfile2.write(write_buffer)
-
- write_buffer = 'this is a test'
- write_buffer = write_buffer.encode()
- tfile2.write(write_buffer)
-
- # Now append the codestream.
- tfile2.write(codestream)
- tfile2.flush()
-
- jasoc = Jp2k(tfile2.name)
- 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].box_id, 'xml ')
-
- @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows")
- @unittest.skipIf(re.match('1\.[345]\.\d', OPENJPEG_VERSION) is not None,
- "Segfault on official v1.x series.")
- 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.
- with open(self.jp2file, 'rb') as fptr:
- data = fptr.read()
- with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
- # Codestream starts at byte 3127. SIZ marker at 3137.
- # COD marker at 3186. Subsampling at 3180.
- tfile.write(data[0:3179])
-
- # Make the DY bytes of the SIZ segment zero. That means that
- # a subsampling factor is zero, which is illegal.
- tfile.write(b'\x00')
- tfile.write(data[3180:3182])
- tfile.write(b'\x00')
- tfile.write(data[3184:3186])
- tfile.write(b'\x00')
-
- tfile.write(data[3186:])
- tfile.flush()
- with warnings.catch_warnings():
- warnings.simplefilter("ignore")
- j = Jp2k(tfile.name)
- regexp = re.compile(r'''OpenJPEG\slibrary\serror:\s+
- Invalid\svalues\sfor\scomp\s=\s0\s+
- :\sdx=1\sdy=0''', re.VERBOSE)
- if sys.hexversion < 0x03020000:
- with self.assertRaisesRegexp((IOError, OSError), regexp):
- j.read(rlevel=1)
- else:
- with self.assertRaisesRegex((IOError, OSError), regexp):
- j.read(rlevel=1)
-
def test_xmp_attribute(self):
"""Verify the XMP packet in the shipping example file can be read."""
j = Jp2k(self.jp2file)
@@ -1426,6 +1098,5 @@ class TestJp2k15(unittest.TestCase):
self.assertFalse('Make' in exif['Image'].keys())
-
if __name__ == "__main__":
unittest.main()
diff --git a/glymur/test/test_opj_suite.py b/glymur/test/test_opj_suite.py
index c622f44..a5daf3e 100644
--- a/glymur/test/test_opj_suite.py
+++ b/glymur/test/test_opj_suite.py
@@ -30,7 +30,6 @@ suite.
# unittest2 is python2.6 only (pylint/python-2.7)
# pylint: disable=F0401
-import os
import re
import sys
@@ -46,22 +45,14 @@ import numpy as np
from glymur import Jp2k
import glymur
-from .fixtures import OPENJPEG_VERSION
-from .fixtures import OPENJP2_IS_V2_OFFICIAL
-from .fixtures import mse, peak_tolerance, read_pgx
+from .fixtures import OPENJP2_IS_V2_OFFICIAL, OPJ_DATA_ROOT
+from .fixtures import mse, peak_tolerance, read_pgx, opj_data_file
-try:
- data_root = os.environ['OPJ_DATA_ROOT']
-except KeyError:
- data_root = None
-except:
- raise
-
-
-@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
- "Missing openjp2 library.")
-@unittest.skipIf(data_root is None,
+@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None and
+ glymur.lib.openjpeg.OPENJPEG is None,
+ "Missing openjpeg libraries.")
+@unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
class TestSuite(unittest.TestCase):
@@ -72,92 +63,64 @@ class TestSuite(unittest.TestCase):
pass
def test_ETS_C0P0_p0_01_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_01.j2k')
+ jfile = opj_data_file('input/conformance/p0_01.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
- pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_01.pgx')
+ pgxfile = opj_data_file('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')
+ jfile = opj_data_file('input/conformance/p0_02.j2k')
jp2k = Jp2k(jfile)
with warnings.catch_warnings():
# Invalid marker ID.
warnings.simplefilter("ignore")
jpdata = jp2k.read(rlevel=0)
- pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_02.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p0_02.pgx')
pgxdata = read_pgx(pgxfile)
np.testing.assert_array_equal(jpdata, pgxdata)
@unittest.skip("Known failure in OPENJPEG test suite.")
def test_ETS_C0P0_p0_03_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_03.j2k')
+ jfile = opj_data_file('input/conformance/p0_03.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
- pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_03r0.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p0_03r0.pgx')
pgxdata = read_pgx(pgxfile)
np.testing.assert_array_equal(jpdata, pgxdata)
def test_ETS_C0P0_p0_03_j2k_r1(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_03.j2k')
+ jfile = opj_data_file('input/conformance/p0_03.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=1)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p0_03r1.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p0_03r1.pgx')
pgxdata = read_pgx(pgxfile)
np.testing.assert_array_equal(jpdata, pgxdata)
@unittest.skip("Known failure in OPENJPEG test suite.")
def test_ETS_C0P0_p0_04_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k')
+ jfile = opj_data_file('input/conformance/p0_04.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=3)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p0_04.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p0_04.pgx')
pgxdata = read_pgx(pgxfile)
self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 33)
self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 55.8)
- 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(rlevel=3)
-
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p0_05.pgx')
- pgxdata = read_pgx(pgxfile)
- self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 54)
- self.assertTrue(mse(jpdata[0], pgxdata) < 68)
-
- @unittest.skip("8-bit pgx data vs 12-bit j2k data")
- 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_bands(rlevel=3)
-
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p0_06.pgx')
- pgxdata = read_pgx(pgxfile)
- tol = peak_tolerance(jpdata[0], pgxdata)
- self.assertTrue(tol < 109)
- m = mse(jpdata[0], pgxdata)
- self.assertTrue(m < 743)
-
@unittest.skip("Known failure in OPENJPEG test suite.")
def test_ETS_C0P0_p0_07_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_07.j2k')
+ jfile = opj_data_file('input/conformance/p0_07.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read()
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p0_07.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p0_07.pgx')
pgxdata = read_pgx(pgxfile)
self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 10)
@@ -165,24 +128,22 @@ class TestSuite(unittest.TestCase):
@unittest.skip("8-bit pgx data vs 12-bit j2k data")
def test_ETS_C0P0_p0_08_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_08.j2k')
+ jfile = opj_data_file('input/conformance/p0_08.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=5)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p0_08.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p0_08.pgx')
pgxdata = read_pgx(pgxfile)
self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 7)
self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 6.72)
def test_ETS_C0P0_p0_09_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_09.j2k')
+ jfile = opj_data_file('input/conformance/p0_09.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=2)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p0_09.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p0_09.pgx')
pgxdata = read_pgx(pgxfile)
self.assertTrue(peak_tolerance(jpdata, pgxdata) < 4)
@@ -190,142 +151,119 @@ class TestSuite(unittest.TestCase):
@unittest.skip("Known failure in OPENJPEG test suite.")
def test_ETS_C0P0_p0_10_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_10.j2k')
+ jfile = opj_data_file('input/conformance/p0_10.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p0_10.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p0_10.pgx')
pgxdata = read_pgx(pgxfile)
self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 10)
self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 2.84)
def test_ETS_C0P0_p0_11_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_11.j2k')
+ jfile = opj_data_file('input/conformance/p0_11.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p0_11.pgx')
+ pgxfile = opj_data_file('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')
+ jfile = opj_data_file('input/conformance/p0_12.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p0_12.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p0_12.pgx')
pgxdata = read_pgx(pgxfile)
np.testing.assert_array_equal(jpdata, pgxdata)
@unittest.skip("Known failure in OPENJPEG test suite.")
def test_ETS_C0P0_p0_13_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_13.j2k')
+ jfile = opj_data_file('input/conformance/p0_13.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p0_13.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p0_13.pgx')
pgxdata = read_pgx(pgxfile)
np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata)
@unittest.skip("Known failure in OPENJPEG test suite.")
def test_ETS_C0P0_p0_14_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_14.j2k')
+ jfile = opj_data_file('input/conformance/p0_14.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=2)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p0_14.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p0_14.pgx')
pgxdata = read_pgx(pgxfile)
np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata)
@unittest.skip("Known failure in OPENJPEG test suite.")
def test_ETS_C0P0_p0_15_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_15.j2k')
+ jfile = opj_data_file('input/conformance/p0_15.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p0_15r0.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p0_15r0.pgx')
pgxdata = read_pgx(pgxfile)
np.testing.assert_array_equal(jpdata, pgxdata)
def test_ETS_C0P0_p0_15_j2k_r1(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_15.j2k')
+ jfile = opj_data_file('input/conformance/p0_15.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=1)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p0_15r1.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p0_15r1.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')
+ jfile = opj_data_file('input/conformance/p0_16.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p0_16.pgx')
+ pgxfile = opj_data_file('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')
+ jfile = opj_data_file('input/conformance/p1_01.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p1_01.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p1_01.pgx')
pgxdata = read_pgx(pgxfile)
np.testing.assert_array_equal(jpdata, pgxdata)
@unittest.skip("Known failure in OPENJPEG test suite operation.")
def test_ETS_C0P1_p1_02_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_02.j2k')
+ jfile = opj_data_file('input/conformance/p1_02.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=3)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p1_02.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p1_02.pgx')
pgxdata = read_pgx(pgxfile)
self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 35)
self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 74)
- 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_bands(rlevel=3)
-
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p1_03.pgx')
- pgxdata = read_pgx(pgxfile)
-
- self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 28)
- self.assertTrue(mse(jpdata[0], pgxdata) < 18.8)
-
@unittest.skip("Known failure in OPENJPEG test suite operation.")
def test_ETS_C0P1_p1_04_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k')
+ jfile = opj_data_file('input/conformance/p1_04.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p1_04r0.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p1_04r0.pgx')
pgxdata = read_pgx(pgxfile)
print(peak_tolerance(jpdata, pgxdata))
@@ -334,12 +272,11 @@ class TestSuite(unittest.TestCase):
@unittest.skip("Known failure in OPENJPEG test suite, precision issue.")
def test_ETS_C0P1_p1_04_j2k_r3(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k')
+ jfile = opj_data_file('input/conformance/p1_04.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=3)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p1_04r3.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p1_04r3.pgx')
pgxdata = read_pgx(pgxfile)
print(peak_tolerance(jpdata, pgxdata))
@@ -348,12 +285,11 @@ class TestSuite(unittest.TestCase):
@unittest.skip("Known failure in OPENJPEG test suite operation.")
def test_ETS_C0P1_p1_05_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_05.j2k')
+ jfile = opj_data_file('input/conformance/p1_05.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=4)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p1_05.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p1_05.pgx')
pgxdata = read_pgx(pgxfile)
print(peak_tolerance(jpdata[:, :, 0], pgxdata))
@@ -363,12 +299,11 @@ class TestSuite(unittest.TestCase):
@unittest.skip("Known failure in OPENJPEG test suite operation.")
def test_ETS_C0P1_p1_06_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k')
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=1)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p1_06.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p1_06.pgx')
pgxdata = read_pgx(pgxfile)
print(peak_tolerance(jpdata[:, :, 0], pgxdata))
@@ -378,388 +313,298 @@ class TestSuite(unittest.TestCase):
@unittest.skip("fprintf stderr output in r2345.")
def test_ETS_C0P1_p1_07_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_07.j2k')
+ jfile = opj_data_file('input/conformance/p1_07.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read_bands(rlevel=0)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p1_07.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p1_07.pgx')
pgxdata = read_pgx(pgxfile)
np.testing.assert_array_equal(jpdata[0], pgxdata)
def test_ETS_C1P0_p0_01_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_01.j2k')
+ jfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ jfile = opj_data_file('input/conformance/p0_02.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_02_0.pgx')
+ pgxfile = opj_data_file('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')
+ jfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ jfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ pgxfile = opj_data_file('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_05_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_05.j2k')
- jp2k = Jp2k(jfile)
- jpdata = jp2k.read_bands()
-
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_05_0.pgx')
- pgxdata = read_pgx(pgxfile)
- self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 2)
- self.assertTrue(mse(jpdata[0], pgxdata) < 0.302)
-
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_05_1.pgx')
- pgxdata = read_pgx(pgxfile)
- self.assertTrue(peak_tolerance(jpdata[1], pgxdata) < 2)
- self.assertTrue(mse(jpdata[1], pgxdata) < 0.307)
-
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_05_2.pgx')
- pgxdata = read_pgx(pgxfile)
- self.assertTrue(peak_tolerance(jpdata[2], pgxdata) < 2)
- self.assertTrue(mse(jpdata[2], pgxdata) < 0.269)
-
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_05_3.pgx')
- pgxdata = read_pgx(pgxfile)
- self.assertTrue(peak_tolerance(jpdata[3], pgxdata) == 0)
- self.assertTrue(mse(jpdata[3], pgxdata) == 0)
-
- def test_ETS_C1P0_p0_06_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_06.j2k')
- jp2k = Jp2k(jfile)
- jpdata = jp2k.read_bands()
-
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_06_0.pgx')
- pgxdata = read_pgx(pgxfile)
- self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 635)
- self.assertTrue(mse(jpdata[0], pgxdata) < 11287)
-
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_06_1.pgx')
- pgxdata = read_pgx(pgxfile)
- self.assertTrue(peak_tolerance(jpdata[1], pgxdata) < 403)
- self.assertTrue(mse(jpdata[1], pgxdata) < 6124)
-
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_06_2.pgx')
- pgxdata = read_pgx(pgxfile)
- self.assertTrue(peak_tolerance(jpdata[2], pgxdata) < 378)
- self.assertTrue(mse(jpdata[2], pgxdata) < 3968)
-
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_06_3.pgx')
- pgxdata = read_pgx(pgxfile)
- self.assertTrue(peak_tolerance(jpdata[3], pgxdata) == 0)
- self.assertTrue(mse(jpdata[3], pgxdata) == 0)
-
@unittest.skip("Known failure in OPENJPEG test suite operation.")
def test_ETS_C1P0_p0_07_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_07.j2k')
+ jfile = opj_data_file('input/conformance/p0_07.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read()
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_07_0.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c1p0_07_0.pgx')
pgxdata = read_pgx(pgxfile)
np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata)
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_07_1.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c1p0_07_1.pgx')
pgxdata = read_pgx(pgxfile)
np.testing.assert_array_equal(jpdata[:, : 1], pgxdata)
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_07_2.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c1p0_07_2.pgx')
pgxdata = read_pgx(pgxfile)
np.testing.assert_array_equal(jpdata[:, : 2], pgxdata)
def test_ETS_C1P0_p0_08_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_08.j2k')
+ jfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ jfile = opj_data_file('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')
+ pgxfile = opj_data_file('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)
- 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')
+ jfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ jfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ jfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ jfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ jfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ jfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ jfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ jfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ pgxfile = opj_data_file('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_03_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_03.j2k')
- jp2k = Jp2k(jfile)
- jpdata = jp2k.read_bands()
-
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_03_0.pgx')
- pgxdata = read_pgx(pgxfile)
- self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 2)
- self.assertTrue(mse(jpdata[0], pgxdata) < 0.3)
-
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_03_1.pgx')
- pgxdata = read_pgx(pgxfile)
- self.assertTrue(peak_tolerance(jpdata[1], pgxdata) < 2)
- self.assertTrue(mse(jpdata[1], pgxdata) < 0.21)
-
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_03_2.pgx')
- pgxdata = read_pgx(pgxfile)
- self.assertTrue(peak_tolerance(jpdata[2], pgxdata) <= 1)
- self.assertTrue(mse(jpdata[2], pgxdata) < 0.2)
-
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_03_3.pgx')
- pgxdata = read_pgx(pgxfile)
- np.testing.assert_array_equal(jpdata[3], pgxdata)
-
def test_ETS_C1P1_p1_04_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k')
+ jfile = opj_data_file('input/conformance/p1_04.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read()
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_04_0.pgx')
+ pgxfile = opj_data_file('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')
+ jfile = opj_data_file('input/conformance/p1_05.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read()
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_05_0.pgx')
+ pgxfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read()
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_06_0.pgx')
+ pgxfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ pgxfile = opj_data_file('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)
@unittest.skip("fprintf stderr output in r2343.")
def test_ETS_C1P1_p1_07_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_07.j2k')
+ jfile = opj_data_file('input/conformance/p1_07.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read_bands()
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_07_0.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c1p1_07_0.pgx')
pgxdata = read_pgx(pgxfile)
self.assertTrue(peak_tolerance(jpdata[0], pgxdata) <= 0)
self.assertTrue(mse(jpdata[0], pgxdata) <= 0)
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_07_1.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c1p1_07_1.pgx')
pgxdata = read_pgx(pgxfile)
self.assertTrue(peak_tolerance(jpdata[1], pgxdata) <= 0)
self.assertTrue(mse(jpdata[1], pgxdata) <= 0)
def test_ETS_JP2_file1(self):
- jfile = os.path.join(data_root, 'input/conformance/file1.jp2')
+ jfile = opj_data_file('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')
+ jfile = opj_data_file('input/conformance/file2.jp2')
jp2k = Jp2k(jfile)
jpdata = jp2k.read()
self.assertEqual(jpdata.shape, (640, 480, 3))
+ @unittest.skipIf(glymur.version.openjpeg_version_tuple[0] < 2,
+ "Functionality not implemented for 1.x")
def test_ETS_JP2_file3(self):
- jfile = os.path.join(data_root, 'input/conformance/file3.jp2')
+ jfile = opj_data_file('input/conformance/file3.jp2')
jp2k = Jp2k(jfile)
jpdata = jp2k.read_bands()
self.assertEqual(jpdata[0].shape, (640, 480))
@@ -767,59 +612,60 @@ class TestSuite(unittest.TestCase):
self.assertEqual(jpdata[2].shape, (320, 240))
def test_ETS_JP2_file4(self):
- jfile = os.path.join(data_root, 'input/conformance/file4.jp2')
+ jfile = opj_data_file('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')
+ jfile = opj_data_file('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')
+ jfile = opj_data_file('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')
+ jfile = opj_data_file('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')
+ jfile = opj_data_file('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')
+ jfile = opj_data_file('input/conformance/file9.jp2')
jp2k = Jp2k(jfile)
jpdata = jp2k.read()
- self.assertEqual(jpdata.shape, (512, 768, 3))
+ if re.match(r"""1\.3""", glymur.version.openjpeg_version):
+ # Version 1.3 reads the indexed image as indices, not as RGB.
+ self.assertEqual(jpdata.shape, (512, 768))
+ else:
+ 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')
+ jfile = opj_data_file('input/nonregression/Bretagne2.j2k')
jp2 = Jp2k(jfile)
jp2.read()
self.assertTrue(True)
def test_NR_DEC__00042_j2k_2_decode(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/_00042.j2k')
+ jfile = opj_data_file('input/nonregression/_00042.j2k')
jp2 = Jp2k(jfile)
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')
+ jfile = opj_data_file('input/nonregression/123.j2c')
jp2 = Jp2k(jfile)
jp2.read()
self.assertTrue(True)
@@ -827,8 +673,7 @@ class TestSuite(unittest.TestCase):
@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')
+ jfile = opj_data_file('input/nonregression/broken.jp2')
with self.assertWarns(UserWarning):
# colr box has bad length.
jp2 = Jp2k(jfile)
@@ -836,20 +681,10 @@ class TestSuite(unittest.TestCase):
jp2.read()
self.assertTrue(True)
- def test_NR_DEC_broken2_jp2_5_decode(self):
- # Null pointer access
- jfile = os.path.join(data_root, 'input/nonregression/broken2.jp2')
- with self.assertRaises(IOError):
- with warnings.catch_warnings():
- # Invalid marker ID.
- warnings.simplefilter("ignore")
- 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')
+ jfile = opj_data_file('input/nonregression/broken3.jp2')
with self.assertWarns(UserWarning):
# colr box has bad length.
j = Jp2k(jfile)
@@ -857,116 +692,88 @@ class TestSuite(unittest.TestCase):
with self.assertRaises(IOError):
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):
- with warnings.catch_warnings():
- # invalid number of subbands, bad marker ID
- warnings.simplefilter("ignore")
- 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')
+ jfile = opj_data_file('input/nonregression/bug.j2c')
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')
+ jfile = opj_data_file('input/nonregression/buxI.j2k')
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')
+ jfile = opj_data_file('input/nonregression/buxR.j2k')
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)
+ jfile = opj_data_file(relpath)
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')
+ jfile = opj_data_file('input/nonregression/cthead1.j2k')
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)
+ jfile = opj_data_file(relpath)
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')
+ jfile = opj_data_file('input/nonregression/illegalcolortransform.j2k')
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')
- 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)
+ jfile = opj_data_file('input/nonregression/j2k32.j2k')
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')
+ jfile = opj_data_file('input/nonregression/MarkerIsNotCompliant.j2k')
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')
+ jfile = opj_data_file('input/nonregression/Marrin.jp2')
Jp2k(jfile).read()
self.assertTrue(True)
- def test_NR_DEC_merged_jp2_19_decode(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/merged.jp2')
- Jp2k(jfile).read_bands()
- self.assertTrue(True)
-
def test_NR_DEC_movie_00000_j2k_20_decode(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/movie_00000.j2k')
+ jfile = opj_data_file('input/nonregression/movie_00000.j2k')
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')
+ jfile = opj_data_file('input/nonregression/movie_00001.j2k')
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')
+ jfile = opj_data_file('input/nonregression/movie_00002.j2k')
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')
+ jfile = opj_data_file('input/nonregression/orb-blue10-lin-j2k.j2k')
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')
+ jfile = opj_data_file('input/nonregression/orb-blue10-win-j2k.j2k')
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')
+ jfile = opj_data_file('input/nonregression/orb-blue10-lin-jp2.jp2')
with warnings.catch_warnings():
# This file has an invalid ICC profile
warnings.simplefilter("ignore")
@@ -974,393 +781,28 @@ class TestSuite(unittest.TestCase):
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')
+ jfile = opj_data_file('input/nonregression/orb-blue10-win-jp2.jp2')
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')
+ jfile = opj_data_file('input/nonregression/relax.jp2')
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')
+ jfile = opj_data_file('input/nonregression/test_lossless.j2k')
Jp2k(jfile).read()
self.assertTrue(True)
- @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL,
- "Test known to fail in v2.0.0 official")
- def test_NR_DEC_text_GBR_jp2_29_decode(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/text_GBR.jp2')
- with warnings.catch_warnings():
- # brand is 'jp2 ', but has any icc profile.
- warnings.simplefilter("ignore")
- jp2 = Jp2k(jfile)
- jp2.read()
- self.assertTrue(True)
-
def test_NR_DEC_pacs_ge_j2k_30_decode(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/pacs.ge.j2k')
+ jfile = opj_data_file('input/nonregression/pacs.ge.j2k')
Jp2k(jfile).read()
self.assertTrue(True)
- @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL,
- "Test known to fail in v2.0.0 official")
- def test_NR_DEC_kodak_2layers_lrcp_j2c_31_decode(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/kodak_2layers_lrcp.j2c')
- Jp2k(jfile).read()
- self.assertTrue(True)
-
- @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL,
- "Test known to fail in v2.0.0 official")
- def test_NR_DEC_kodak_2layers_lrcp_j2c_32_decode(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/kodak_2layers_lrcp.j2c')
- Jp2k(jfile).read(layer=2)
- self.assertTrue(True)
-
- def test_NR_DEC_issue104_jpxstream_jp2_33_decode(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/issue104_jpxstream.jp2')
- Jp2k(jfile).read()
- self.assertTrue(True)
-
- @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL,
- "Test known to fail in v2.0.0 official")
- def test_NR_DEC_mem_b2ace68c_1381_jp2_34_decode(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/mem-b2ace68c-1381.jp2')
- with warnings.catch_warnings():
- # This file has a bad pclr box, we test for this elsewhere.
- warnings.simplefilter("ignore")
- j = Jp2k(jfile)
- j.read()
- self.assertTrue(True)
-
- @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL,
- "Test known to fail in v2.0.0 official")
- def test_NR_DEC_mem_b2b86b74_2753_jp2_35_decode(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/mem-b2b86b74-2753.jp2')
- Jp2k(jfile).read()
- self.assertTrue(True)
-
- def test_NR_DEC_gdal_fuzzer_unchecked_num_resolutions_jp2_36_decode(self):
- f = 'input/nonregression/gdal_fuzzer_unchecked_numresolutions.jp2'
- jfile = os.path.join(data_root, f)
- with warnings.catch_warnings():
- # Invalid number of resolutions.
- warnings.simplefilter("ignore")
- j = Jp2k(jfile)
- with self.assertRaises(IOError):
- j.read()
-
- @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL,
- "Test not in done in v2.0.0 official")
- def test_NR_DEC_jp2_36_decode(self):
- lst = ('input',
- 'nonregression',
- 'gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.jp2')
- jfile = os.path.join(data_root, '/'.join(lst))
- with warnings.catch_warnings():
- # Invalid component number.
- warnings.simplefilter("ignore")
- j = Jp2k(jfile)
- with self.assertRaises(IOError):
- j.read()
-
- @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL,
- "Test not in done in v2.0.0 official")
- def test_NR_DEC_gdal_fuzzer_check_number_of_tiles_jp2_38_decode(self):
- relpath = 'input/nonregression/gdal_fuzzer_check_number_of_tiles.jp2'
- jfile = os.path.join(data_root, relpath)
- with warnings.catch_warnings():
- # Invalid number of tiles.
- warnings.simplefilter("ignore")
- j = Jp2k(jfile)
- with self.assertRaises(IOError):
- j.read()
-
- @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL,
- "Test not in done in v2.0.0 official")
- def test_NR_DEC_gdal_fuzzer_check_comp_dx_dy_jp2_39_decode(self):
- relpath = 'input/nonregression/gdal_fuzzer_check_comp_dx_dy.jp2'
- jfile = os.path.join(data_root, relpath)
- with warnings.catch_warnings():
- # Invalid subsampling value
- warnings.simplefilter("ignore")
- with self.assertRaises(IOError):
- Jp2k(jfile).read()
-
- def test_NR_DEC_file_409752_jp2_40_decode(self):
- jfile = os.path.join(data_root, 'input/nonregression/file409752.jp2')
- with self.assertRaises(RuntimeError):
- Jp2k(jfile).read()
-
- @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL,
- "Test not in done in v2.0.0 official")
- @unittest.skipIf(sys.hexversion < 0x03020000,
- "Uses features introduced in 3.2.")
- def test_NR_DEC_issue188_beach_64bitsbox_jp2_41_decode(self):
- # Has an 'XML ' box instead of 'xml '. Yes that is pedantic, but it
- # really does deserve a warning.
- relpath = 'input/nonregression/issue188_beach_64bitsbox.jp2'
- jfile = os.path.join(data_root, relpath)
- with self.assertWarns(UserWarning):
- Jp2k(jfile).read()
-
- @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL,
- "Test not in done in v2.0.0 official")
- def test_NR_DEC_issue206_image_000_jp2_42_decode(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/issue206_image-000.jp2')
- Jp2k(jfile).read()
- self.assertTrue(True)
-
- def test_NR_DEC_p1_04_j2k_43_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(0, 0, 1024, 1024))
- odata = jp2k.read()
- np.testing.assert_array_equal(ssdata, odata)
-
- def test_NR_DEC_p1_04_j2k_44_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(640, 512, 768, 640))
- odata = jp2k.read()
- np.testing.assert_array_equal(ssdata, odata[640:768, 512:640])
-
- def test_NR_DEC_p1_04_j2k_45_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(896, 896, 1024, 1024))
- odata = jp2k.read()
- np.testing.assert_array_equal(ssdata, odata[896:1024, 896:1024])
-
- def test_NR_DEC_p1_04_j2k_46_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(500, 100, 800, 300))
- odata = jp2k.read()
- np.testing.assert_array_equal(ssdata, odata[500:800, 100:300])
-
- def test_NR_DEC_p1_04_j2k_47_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(520, 260, 600, 360))
- odata = jp2k.read()
- np.testing.assert_array_equal(ssdata, odata[520:600, 260:360])
-
- def test_NR_DEC_p1_04_j2k_48_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(520, 260, 660, 360))
- odata = jp2k.read()
- np.testing.assert_array_equal(ssdata, odata[520:660, 260:360])
-
- def test_NR_DEC_p1_04_j2k_49_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(520, 360, 600, 400))
- odata = jp2k.read()
- np.testing.assert_array_equal(ssdata, odata[520:600, 360:400])
-
- 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), 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), 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), 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), 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), 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), 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), 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):
- jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k')
- jp2k = Jp2k(jfile)
- tdata = jp2k.read(tile=63) # last tile
- odata = jp2k.read()
- np.testing.assert_array_equal(tdata, odata[896:1024, 896:1024])
-
- def test_NR_DEC_p1_04_j2k_58_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k')
- jp2k = Jp2k(jfile)
- 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):
- jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k')
- jp2k = Jp2k(jfile)
- tdata = jp2k.read(tile=12) # 2nd row, 5th column
- odata = jp2k.read()
- np.testing.assert_array_equal(tdata, odata[128:256, 512:640])
-
- def test_NR_DEC_p1_04_j2k_60_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k')
- jp2k = Jp2k(jfile)
- 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.")
- def test_NR_DEC_p1_06_j2k_61_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(0, 0, 12, 12))
- odata = jp2k.read()
- np.testing.assert_array_equal(ssdata, odata[0:12, 0:12])
-
- @unittest.skip("fprintf stderr output in r2343.")
- def test_NR_DEC_p1_06_j2k_62_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(1, 8, 8, 11))
- odata = jp2k.read()
- np.testing.assert_array_equal(ssdata, odata[1:8, 8:11])
-
- @unittest.skip("fprintf stderr output in r2343.")
- def test_NR_DEC_p1_06_j2k_63_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(9, 9, 12, 12))
- odata = jp2k.read()
- np.testing.assert_array_equal(ssdata, odata[9:12, 9:12])
-
- @unittest.skip("fprintf stderr output in r2343.")
- def test_NR_DEC_p1_06_j2k_64_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(10, 4, 12, 10))
- odata = jp2k.read()
- np.testing.assert_array_equal(ssdata, odata[10:12, 4:10])
-
- @unittest.skip("fprintf stderr output in r2343.")
- def test_NR_DEC_p1_06_j2k_65_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(3, 3, 9, 9))
- odata = jp2k.read()
- np.testing.assert_array_equal(ssdata, odata[3:9, 3:9])
-
- @unittest.skip("fprintf stderr output in r2343.")
- def test_NR_DEC_p1_06_j2k_66_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(4, 4, 7, 7))
- odata = jp2k.read()
- np.testing.assert_array_equal(ssdata, odata[4:7, 4:7])
-
- @unittest.skip("fprintf stderr output in r2343.")
- def test_NR_DEC_p1_06_j2k_67_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(4, 4, 5, 5))
- odata = jp2k.read()
- np.testing.assert_array_equal(ssdata, odata[4:5, 4: 5])
-
- @unittest.skip("fprintf stderr output in r2343.")
- 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), 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), 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), 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), 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), 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), 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), rlevel=1)
- self.assertEqual(ssdata.shape, (1, 1, 3))
-
- def test_NR_DEC_p1_06_j2k_75_decode(self):
- # Image size would be 0 x 0.
- jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k')
- jp2k = Jp2k(jfile)
- with self.assertRaises((IOError, OSError)):
- 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):
- jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k')
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
jp2k = Jp2k(jfile)
fulldata = jp2k.read()
tiledata = jp2k.read(tile=0)
@@ -1368,7 +810,7 @@ class TestSuite(unittest.TestCase):
@unittest.skip("fprintf stderr output in r2343.")
def test_NR_DEC_p1_06_j2k_77_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k')
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
jp2k = Jp2k(jfile)
fulldata = jp2k.read()
tiledata = jp2k.read(tile=5)
@@ -1376,7 +818,7 @@ class TestSuite(unittest.TestCase):
@unittest.skip("fprintf stderr output in r2343.")
def test_NR_DEC_p1_06_j2k_78_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k')
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
jp2k = Jp2k(jfile)
fulldata = jp2k.read()
with warnings.catch_warnings():
@@ -1386,7 +828,7 @@ class TestSuite(unittest.TestCase):
@unittest.skip("fprintf stderr output in r2343.")
def test_NR_DEC_p1_06_j2k_79_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k')
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
jp2k = Jp2k(jfile)
fulldata = jp2k.read()
with warnings.catch_warnings():
@@ -1397,7 +839,7 @@ class TestSuite(unittest.TestCase):
@unittest.skip("fprintf stderr output in r2343.")
def test_NR_DEC_p1_06_j2k_80_decode(self):
# Just read the data, don't bother verifying.
- jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k')
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
jp2k = Jp2k(jfile)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
@@ -1406,7 +848,7 @@ class TestSuite(unittest.TestCase):
@unittest.skip("fprintf stderr output in r2343.")
def test_NR_DEC_p1_06_j2k_81_decode(self):
# Just read the data, don't bother verifying.
- jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k')
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
jp2k = Jp2k(jfile)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
@@ -1415,7 +857,7 @@ class TestSuite(unittest.TestCase):
@unittest.skip("fprintf stderr output in r2343.")
def test_NR_DEC_p1_06_j2k_82_decode(self):
# Just read the data, don't bother verifying.
- jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k')
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
jp2k = Jp2k(jfile)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
@@ -1424,7 +866,7 @@ class TestSuite(unittest.TestCase):
@unittest.skip("fprintf stderr output in r2343.")
def test_NR_DEC_p1_06_j2k_83_decode(self):
# tile size is 3x3. Reducing two levels results in no data.
- jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k')
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
jp2k = Jp2k(jfile)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
@@ -1434,96 +876,12 @@ class TestSuite(unittest.TestCase):
@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')
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
jp2k = Jp2k(jfile)
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')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(0, 0, 256, 256))
- fulldata = jp2k.read()
- np.testing.assert_array_equal(fulldata[0:256, 0:256], ssdata)
- def test_NR_DEC_p0_04_j2k_86_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(0, 128, 128, 256))
- fulldata = jp2k.read()
- np.testing.assert_array_equal(fulldata[0:128, 128:256], ssdata)
-
- def test_NR_DEC_p0_04_j2k_87_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(10, 50, 200, 120))
- fulldata = jp2k.read()
- np.testing.assert_array_equal(fulldata[10:200, 50:120], ssdata)
-
- def test_NR_DEC_p0_04_j2k_88_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(150, 10, 210, 190))
- fulldata = jp2k.read()
- np.testing.assert_array_equal(fulldata[150:210, 10:190], ssdata)
-
- def test_NR_DEC_p0_04_j2k_89_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(80, 100, 150, 200))
- fulldata = jp2k.read()
- np.testing.assert_array_equal(fulldata[80:150, 100:200], ssdata)
-
- def test_NR_DEC_p0_04_j2k_90_decode(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k')
- jp2k = Jp2k(jfile)
- ssdata = jp2k.read(area=(20, 150, 50, 200))
- fulldata = jp2k.read()
- np.testing.assert_array_equal(fulldata[20:50, 150:200], ssdata)
-
- 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), 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), 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), 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), 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), 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), rlevel=2)
- fulldata = jp2k.read(rlevel=2)
- np.testing.assert_array_equal(fulldata[5:13, 38:50], ssdata)
-
-
-@unittest.skipIf(data_root is None,
+@unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
class TestSuiteDump(unittest.TestCase):
@@ -1534,7 +892,7 @@ class TestSuiteDump(unittest.TestCase):
pass
def test_NR_p0_01_dump(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_01.j2k')
+ jfile = opj_data_file('input/conformance/p0_01.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# Segment IDs.
@@ -1601,7 +959,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p0_02.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -1707,7 +1065,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p0_03.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -1824,7 +1182,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p0_04.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -1932,7 +1290,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p0_05.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -2076,7 +1434,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p0_06.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -2213,7 +1571,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p0_07.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -2298,7 +1656,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p0_08.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -2451,7 +1809,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p0_09.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -2531,7 +1889,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p0_10.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -2672,7 +2030,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p0_11.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -2753,7 +2111,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p0_12.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -2835,7 +2193,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p0_13.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -2961,7 +2319,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p0_14.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -3037,7 +2395,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p0_15.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -3191,7 +2549,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p0_16.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -3259,7 +2617,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p1_01.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -3359,7 +2717,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p1_02.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -3473,7 +2831,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p1_03.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -3620,7 +2978,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p1_04.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -3747,7 +3105,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p1_05.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -3835,7 +3193,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -3928,7 +3286,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/p1_07.j2k')
c = Jp2k(jfile).get_codestream(header_only=False)
# SIZ: Image and tile size
@@ -4021,7 +3379,7 @@ class TestSuiteDump(unittest.TestCase):
self.assertEqual(c.segment[-1].marker_id, 'EOC')
def test_NR_file1_dump(self):
- jfile = os.path.join(data_root, 'input/conformance/file1.jp2')
+ jfile = opj_data_file('input/conformance/file1.jp2')
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box]
@@ -4071,7 +3429,7 @@ class TestSuiteDump(unittest.TestCase):
'{http://www.jpeg.org/jpx/1.0/xml}EVENT'])
def test_NR_file2_dump(self):
- jfile = os.path.join(data_root, 'input/conformance/file2.jp2')
+ jfile = opj_data_file('input/conformance/file2.jp2')
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box]
@@ -4118,7 +3476,7 @@ class TestSuiteDump(unittest.TestCase):
# Cr components being subsampled 2x in both the horizontal and
# vertical directions. The components are stored in the standard
# order.
- jfile = os.path.join(data_root, 'input/conformance/file3.jp2')
+ jfile = opj_data_file('input/conformance/file3.jp2')
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box]
@@ -4165,7 +3523,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/conformance/file4.jp2')
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box]
@@ -4207,7 +3565,7 @@ class TestSuiteDump(unittest.TestCase):
# the RCT. The colourspace is specified using both a Restricted ICC
# profile and using the JPX-defined enumerated code for the ROMM-RGB
# colourspace.
- jfile = os.path.join(data_root, 'input/conformance/file5.jp2')
+ jfile = opj_data_file('input/conformance/file5.jp2')
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box]
@@ -4256,7 +3614,7 @@ class TestSuiteDump(unittest.TestCase):
glymur.core.ROMM_RGB)
def test_NR_file6_dump(self):
- jfile = os.path.join(data_root, 'input/conformance/file6.jp2')
+ jfile = opj_data_file('input/conformance/file6.jp2')
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box]
@@ -4300,7 +3658,7 @@ class TestSuiteDump(unittest.TestCase):
# the RCT. The colourspace is specified using both a Restricted ICC
# profile and using the JPX-defined enumerated code for the e-sRGB
# colourspace.
- jfile = os.path.join(data_root, 'input/conformance/file7.jp2')
+ jfile = opj_data_file('input/conformance/file7.jp2')
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box]
@@ -4356,7 +3714,7 @@ class TestSuiteDump(unittest.TestCase):
def test_NR_file8_dump(self):
# One 8-bit component in a gamma 1.8 space. The colourspace is
# specified using a Restricted ICC profile.
- jfile = os.path.join(data_root, 'input/conformance/file8.jp2')
+ jfile = opj_data_file('input/conformance/file8.jp2')
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box]
@@ -4410,7 +3768,7 @@ class TestSuiteDump(unittest.TestCase):
def test_NR_file9_dump(self):
# Colormap
- jfile = os.path.join(data_root, 'input/conformance/file9.jp2')
+ jfile = opj_data_file('input/conformance/file9.jp2')
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box]
@@ -4469,7 +3827,7 @@ class TestSuiteDump(unittest.TestCase):
def test_NR_00042_j2k_dump(self):
# Profile 3.
- jfile = os.path.join(data_root, 'input/nonregression/_00042.j2k')
+ jfile = opj_data_file('input/nonregression/_00042.j2k')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream(header_only=False)
@@ -4622,7 +3980,7 @@ class TestSuiteDump(unittest.TestCase):
def test_Bretagne2_j2k_dump(self):
# Profile 3.
- jfile = os.path.join(data_root, 'input/nonregression/Bretagne2.j2k')
+ jfile = opj_data_file('input/nonregression/Bretagne2.j2k')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream(header_only=False)
@@ -4679,7 +4037,7 @@ class TestSuiteDump(unittest.TestCase):
self.assertEqual(ids, expected)
def test_NR_buxI_j2k_dump(self):
- jfile = os.path.join(data_root, 'input/nonregression/buxI.j2k')
+ jfile = opj_data_file('input/nonregression/buxI.j2k')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream(header_only=False)
@@ -4732,7 +4090,7 @@ class TestSuiteDump(unittest.TestCase):
self.assertEqual(ids, expected)
def test_NR_buxR_j2k_dump(self):
- jfile = os.path.join(data_root, 'input/nonregression/buxR.j2k')
+ jfile = opj_data_file('input/nonregression/buxR.j2k')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream(header_only=False)
@@ -4789,7 +4147,7 @@ class TestSuiteDump(unittest.TestCase):
'Cannotreaddatawithnosizeknown.j2k']
path = '/'.join(lst)
- jfile = os.path.join(data_root, path)
+ jfile = opj_data_file(path)
jp2k = Jp2k(jfile)
c = jp2k.get_codestream()
@@ -4850,9 +4208,8 @@ class TestSuiteDump(unittest.TestCase):
self.assertEqual(c.segment[3].exponent, [16] + [17, 17, 18] * 11)
def test_NR_CT_Phillips_JPEG2K_Decompr_Problem_dump(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/'
- + 'CT_Phillips_JPEG2K_Decompr_Problem.j2k')
+ jfile = opj_data_file('input/nonregression/'
+ + 'CT_Phillips_JPEG2K_Decompr_Problem.j2k')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream()
@@ -4922,8 +4279,7 @@ class TestSuiteDump(unittest.TestCase):
self.assertEqual(c.segment[4].ccme.decode('latin-1'), "Kakadu-3.2")
def test_NR_cthead1_dump(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/cthead1.j2k')
+ jfile = opj_data_file('input/nonregression/cthead1.j2k')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream()
@@ -4998,8 +4354,7 @@ class TestSuiteDump(unittest.TestCase):
@unittest.skip("fprintf stderr output in r2343.")
def test_NR_illegalcolortransform_dump(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/illegalcolortransform.j2k')
+ jfile = opj_data_file('input/nonregression/illegalcolortransform.j2k')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream()
@@ -5060,7 +4415,7 @@ class TestSuiteDump(unittest.TestCase):
self.assertEqual(c.segment[3].exponent, [16] + [17, 17, 18] * 11)
def test_NR_j2k32_dump(self):
- jfile = os.path.join(data_root, 'input/nonregression/j2k32.j2k')
+ jfile = opj_data_file('input/nonregression/j2k32.j2k')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream()
@@ -5127,9 +4482,8 @@ class TestSuiteDump(unittest.TestCase):
self.assertEqual(len(c.segment[4].ccme), 36)
def test_NR_kakadu_v4_4_openjpegv2_broken_dump(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/'
- + 'kakadu_v4-4_openjpegv2_broken.j2k')
+ jfile = opj_data_file('input/nonregression/'
+ + 'kakadu_v4-4_openjpegv2_broken.j2k')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream()
@@ -5213,8 +4567,7 @@ class TestSuiteDump(unittest.TestCase):
self.assertEqual(c.segment[5].ccme.decode('latin-1'), expected)
def test_NR_MarkerIsNotCompliant_j2k_dump(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/MarkerIsNotCompliant.j2k')
+ jfile = opj_data_file('input/nonregression/MarkerIsNotCompliant.j2k')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream()
@@ -5273,8 +4626,7 @@ class TestSuiteDump(unittest.TestCase):
17, 18, 17, 17, 18, 17, 17, 18])
def test_NR_movie_00000(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/movie_00000.j2k')
+ jfile = opj_data_file('input/nonregression/movie_00000.j2k')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream()
@@ -5331,8 +4683,7 @@ class TestSuiteDump(unittest.TestCase):
[8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10])
def test_NR_movie_00001(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/movie_00001.j2k')
+ jfile = opj_data_file('input/nonregression/movie_00001.j2k')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream()
@@ -5389,8 +4740,7 @@ class TestSuiteDump(unittest.TestCase):
[8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10])
def test_NR_movie_00002(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/movie_00002.j2k')
+ jfile = opj_data_file('input/nonregression/movie_00002.j2k')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream()
@@ -5447,8 +4797,7 @@ class TestSuiteDump(unittest.TestCase):
[8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10])
def test_NR_orb_blue10_lin_j2k_dump(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/orb-blue10-lin-j2k.j2k')
+ jfile = opj_data_file('input/nonregression/orb-blue10-lin-j2k.j2k')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream()
@@ -5508,8 +4857,7 @@ class TestSuiteDump(unittest.TestCase):
[8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10])
def test_NR_orb_blue10_win_j2k_dump(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/orb-blue10-win-j2k.j2k')
+ jfile = opj_data_file('input/nonregression/orb-blue10-win-j2k.j2k')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream()
@@ -5569,7 +4917,7 @@ class TestSuiteDump(unittest.TestCase):
[8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10])
def test_NR_pacs_ge_j2k_dump(self):
- jfile = os.path.join(data_root, 'input/nonregression/pacs.ge.j2k')
+ jfile = opj_data_file('input/nonregression/pacs.ge.j2k')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream()
@@ -5637,8 +4985,7 @@ class TestSuiteDump(unittest.TestCase):
"Kakadu-2.0.2")
def test_NR_test_lossless_j2k_dump(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/test_lossless.j2k')
+ jfile = opj_data_file('input/nonregression/test_lossless.j2k')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream()
@@ -5707,7 +5054,7 @@ class TestSuiteDump(unittest.TestCase):
"ClearCanvas DICOM OpenJPEG")
def test_NR_123_j2c_dump(self):
- jfile = os.path.join(data_root, 'input/nonregression/123.j2c')
+ jfile = opj_data_file('input/nonregression/123.j2c')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream()
@@ -5769,7 +5116,7 @@ class TestSuiteDump(unittest.TestCase):
[16] + [17, 17, 18] * 11)
def test_NR_bug_j2c_dump(self):
- jfile = os.path.join(data_root, 'input/nonregression/bug.j2c')
+ jfile = opj_data_file('input/nonregression/bug.j2c')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream()
@@ -5831,8 +5178,7 @@ class TestSuiteDump(unittest.TestCase):
[16] + [17, 17, 18] * 11)
def test_NR_kodak_2layers_lrcp_j2c_dump(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/kodak_2layers_lrcp.j2c')
+ jfile = opj_data_file('input/nonregression/kodak_2layers_lrcp.j2c')
jp2k = Jp2k(jfile)
c = jp2k.get_codestream()
@@ -5905,8 +5251,7 @@ class TestSuiteDump(unittest.TestCase):
@unittest.skipIf(sys.hexversion < 0x03020000,
"Uses features introduced in 3.2.")
def test_NR_broken_jp2_dump(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/broken.jp2')
+ jfile = opj_data_file('input/nonregression/broken.jp2')
with self.assertWarns(UserWarning):
# colr box has bad length.
jp2 = Jp2k(jfile)
@@ -6033,7 +5378,7 @@ class TestSuiteDump(unittest.TestCase):
"Uses features introduced in 3.2, 'assertWarns'.")
def test_NR_broken2_jp2_dump(self):
# Invalid marker ID on codestream.
- jfile = os.path.join(data_root, 'input/nonregression/broken2.jp2')
+ jfile = opj_data_file('input/nonregression/broken2.jp2')
with self.assertWarns(UserWarning):
jp2 = Jp2k(jfile)
@@ -6042,8 +5387,7 @@ class TestSuiteDump(unittest.TestCase):
@unittest.skipIf(sys.hexversion < 0x03020000,
"Uses features introduced in 3.2.")
def test_NR_broken3_jp2_dump(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/broken3.jp2')
+ jfile = opj_data_file('input/nonregression/broken3.jp2')
with self.assertWarns(UserWarning):
# colr box has bad length.
jp2 = Jp2k(jfile)
@@ -6170,15 +5514,14 @@ class TestSuiteDump(unittest.TestCase):
"Uses features introduced in 3.2, 'assertWarns'")
def test_NR_broken4_jp2_dump(self):
# Has an invalid marker in the main header
- jfile = os.path.join(data_root, 'input/nonregression/broken4.jp2')
+ jfile = opj_data_file('input/nonregression/broken4.jp2')
with self.assertWarns(UserWarning):
jp2 = Jp2k(jfile)
self.assertEqual(jp2.box[-1].main_header.segment[-1].marker_id, 'QCC')
def test_NR_file409752(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/file409752.jp2')
+ jfile = opj_data_file('input/nonregression/file409752.jp2')
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box]
@@ -6279,7 +5622,7 @@ class TestSuiteDump(unittest.TestCase):
def test_NR_gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc_patch_jp2(self):
lst = ['input', 'nonregression',
'gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.jp2']
- jfile = os.path.join(data_root, '/'.join(lst))
+ jfile = opj_data_file('/'.join(lst))
with self.assertWarns(UserWarning):
Jp2k(jfile)
@@ -6287,7 +5630,7 @@ class TestSuiteDump(unittest.TestCase):
"Uses features introduced in 3.2.")
def test_NR_gdal_fuzzer_check_comp_dx_dy_jp2_dump(self):
lst = ['input', 'nonregression', 'gdal_fuzzer_check_comp_dx_dy.jp2']
- jfile = os.path.join(data_root, '/'.join(lst))
+ jfile = opj_data_file('/'.join(lst))
with self.assertWarns(UserWarning):
Jp2k(jfile)
@@ -6297,7 +5640,7 @@ class TestSuiteDump(unittest.TestCase):
# Has an impossible tiling setup.
lst = ['input', 'nonregression',
'gdal_fuzzer_check_number_of_tiles.jp2']
- jfile = os.path.join(data_root, '/'.join(lst))
+ jfile = opj_data_file('/'.join(lst))
with self.assertWarns(UserWarning):
Jp2k(jfile)
@@ -6307,13 +5650,12 @@ class TestSuiteDump(unittest.TestCase):
# Has an invalid number of resolutions.
lst = ['input', 'nonregression',
'gdal_fuzzer_unchecked_numresolutions.jp2']
- jfile = os.path.join(data_root, '/'.join(lst))
+ jfile = opj_data_file('/'.join(lst))
with self.assertWarns(UserWarning):
Jp2k(jfile)
def test_NR_issue104_jpxstream_dump(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/issue104_jpxstream.jp2')
+ jfile = opj_data_file('input/nonregression/issue104_jpxstream.jp2')
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box]
@@ -6427,7 +5769,7 @@ class TestSuiteDump(unittest.TestCase):
def test_NR_issue188_beach_64bitsbox(self):
lst = ['input', 'nonregression', 'issue188_beach_64bitsbox.jp2']
- jfile = os.path.join(data_root, '/'.join(lst))
+ jfile = opj_data_file('/'.join(lst))
with warnings.catch_warnings():
# There's a warning for an unknown box. We explicitly test for
# that down below.
@@ -6525,8 +5867,7 @@ class TestSuiteDump(unittest.TestCase):
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')
+ jfile = opj_data_file('input/nonregression/issue206_image-000.jp2')
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box]
@@ -6626,8 +5967,7 @@ class TestSuiteDump(unittest.TestCase):
self.assertEqual(c.segment[3].exponent, [8] + [9, 9, 10] * 5)
def test_NR_Marrin_jp2_dump(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/Marrin.jp2')
+ jfile = opj_data_file('input/nonregression/Marrin.jp2')
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box]
@@ -6740,8 +6080,7 @@ class TestSuiteDump(unittest.TestCase):
"Kakadu-v5.2.1")
def test_NR_mem_b2ace68c_1381_dump(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/mem-b2ace68c-1381.jp2')
+ jfile = opj_data_file('input/nonregression/mem-b2ace68c-1381.jp2')
with warnings.catch_warnings():
# This file has a bad pclr box, we test for this elsewhere.
warnings.simplefilter("ignore")
@@ -6858,8 +6197,7 @@ class TestSuiteDump(unittest.TestCase):
self.assertEqual(c.segment[3].exponent, [1] + [2, 2, 3] * 5)
def test_NR_mem_b2b86b74_2753_dump(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/mem-b2b86b74-2753.jp2')
+ jfile = opj_data_file('input/nonregression/mem-b2b86b74-2753.jp2')
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box]
@@ -6973,7 +6311,7 @@ class TestSuiteDump(unittest.TestCase):
self.assertEqual(c.segment[3].exponent, [4] + [5, 5, 6] * 5)
def test_NR_merged_dump(self):
- jfile = os.path.join(data_root, 'input/nonregression/merged.jp2')
+ jfile = opj_data_file('input/nonregression/merged.jp2')
jp2 = Jp2k(jfile)
ids = [box.box_id for box in jp2.box]
@@ -7077,8 +6415,7 @@ class TestSuiteDump(unittest.TestCase):
self.assertEqual(c.segment[4].ppod, podvals)
def test_NR_orb_blue10_lin_jp2_dump(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/orb-blue10-lin-jp2.jp2')
+ jfile = opj_data_file('input/nonregression/orb-blue10-lin-jp2.jp2')
with warnings.catch_warnings():
# This file has an invalid ICC profile
warnings.simplefilter("ignore")
@@ -7177,8 +6514,7 @@ class TestSuiteDump(unittest.TestCase):
[8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10])
def test_NR_orb_blue10_win_jp2_dump(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/orb-blue10-win-jp2.jp2')
+ jfile = opj_data_file('input/nonregression/orb-blue10-win-jp2.jp2')
with warnings.catch_warnings():
# This file has an invalid ICC profile
warnings.simplefilter("ignore")
@@ -7277,8 +6613,7 @@ class TestSuiteDump(unittest.TestCase):
[8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10])
def test_NR_text_GBR_dump(self):
- jfile = os.path.join(data_root,
- 'input/nonregression/text_GBR.jp2')
+ jfile = opj_data_file('input/nonregression/text_GBR.jp2')
with warnings.catch_warnings():
# brand is 'jp2 ', but has any icc profile.
warnings.simplefilter("ignore")
@@ -7389,23 +6724,14 @@ class TestSuiteDump(unittest.TestCase):
[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"""
+@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] == 1,
+ "Feature not supported in glymur until openjpeg 2.0")
+class TestSuite_bands(unittest.TestCase):
+ """Runs tests introduced in version 1.x but only pass in glymur with 2.0
- @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
+ The deal here is that the feature works with 1.x, but glymur only supports
+ it with version 2.0.
+ """
def setUp(self):
pass
@@ -7413,625 +6739,613 @@ class TestSuite15(unittest.TestCase):
def tearDown(self):
pass
- def test_ETS_C0P0_p0_01_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_01.j2k')
+ def test_ETS_C0P0_p0_05_j2k(self):
+ jfile = opj_data_file('input/conformance/p0_05.j2k')
jp2k = Jp2k(jfile)
- jpdata = jp2k.read(rlevel=0)
+ jpdata = jp2k.read_bands(rlevel=3)
- pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_01.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p0_05.pgx')
pgxdata = read_pgx(pgxfile)
- np.testing.assert_array_equal(jpdata, pgxdata)
+ self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 54)
+ self.assertTrue(mse(jpdata[0], pgxdata) < 68)
- 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')
+ @unittest.skip("8-bit pgx data vs 12-bit j2k data")
+ def test_ETS_C0P0_p0_06_j2k(self):
+ jfile = opj_data_file('input/conformance/p0_06.j2k')
jp2k = Jp2k(jfile)
- jpdata = jp2k.read(rlevel=2)
+ jpdata = jp2k.read_bands(rlevel=3)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p0_09.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p0_06.pgx')
pgxdata = read_pgx(pgxfile)
+ tol = peak_tolerance(jpdata[0], pgxdata)
+ self.assertTrue(tol < 109)
+ m = mse(jpdata[0], pgxdata)
+ self.assertTrue(m < 743)
- 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')
+ def test_ETS_C0P1_p1_03_j2k(self):
+ jfile = opj_data_file('input/conformance/p1_03.j2k')
jp2k = Jp2k(jfile)
- jpdata = jp2k.read(rlevel=0)
+ jpdata = jp2k.read_bands(rlevel=3)
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p0_11.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c0p1_03.pgx')
pgxdata = read_pgx(pgxfile)
- np.testing.assert_array_equal(jpdata, pgxdata)
+ self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 28)
+ self.assertTrue(mse(jpdata[0], pgxdata) < 18.8)
- @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')
+ def test_ETS_C1P1_p1_03_j2k(self):
+ jfile = opj_data_file('input/conformance/p1_03.j2k')
jp2k = Jp2k(jfile)
- jpdata = jp2k.read(rlevel=0)
+ jpdata = jp2k.read_bands()
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p0_12.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c1p1_03_0.pgx')
pgxdata = read_pgx(pgxfile)
+ self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 2)
+ self.assertTrue(mse(jpdata[0], pgxdata) < 0.3)
- np.testing.assert_array_equal(jpdata, pgxdata)
+ pgxfile = opj_data_file('baseline/conformance/c1p1_03_1.pgx')
+ pgxdata = read_pgx(pgxfile)
+ self.assertTrue(peak_tolerance(jpdata[1], pgxdata) < 2)
+ self.assertTrue(mse(jpdata[1], pgxdata) < 0.21)
- def test_ETS_C0P0_p0_16_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_16.j2k')
+ pgxfile = opj_data_file('baseline/conformance/c1p1_03_2.pgx')
+ pgxdata = read_pgx(pgxfile)
+ self.assertTrue(peak_tolerance(jpdata[2], pgxdata) <= 1)
+ self.assertTrue(mse(jpdata[2], pgxdata) < 0.2)
+
+ pgxfile = opj_data_file('baseline/conformance/c1p1_03_3.pgx')
+ pgxdata = read_pgx(pgxfile)
+ np.testing.assert_array_equal(jpdata[3], pgxdata)
+
+ def test_ETS_C1P0_p0_05_j2k(self):
+ jfile = opj_data_file('input/conformance/p0_05.j2k')
jp2k = Jp2k(jfile)
- jpdata = jp2k.read(rlevel=0)
+ jpdata = jp2k.read_bands()
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p0_16.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c1p0_05_0.pgx')
pgxdata = read_pgx(pgxfile)
+ self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 2)
+ self.assertTrue(mse(jpdata[0], pgxdata) < 0.302)
- np.testing.assert_array_equal(jpdata, pgxdata)
+ pgxfile = opj_data_file('baseline/conformance/c1p0_05_1.pgx')
+ pgxdata = read_pgx(pgxfile)
+ self.assertTrue(peak_tolerance(jpdata[1], pgxdata) < 2)
+ self.assertTrue(mse(jpdata[1], pgxdata) < 0.307)
- def test_ETS_C0P1_p1_01_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p1_01.j2k')
+ pgxfile = opj_data_file('baseline/conformance/c1p0_05_2.pgx')
+ pgxdata = read_pgx(pgxfile)
+ self.assertTrue(peak_tolerance(jpdata[2], pgxdata) < 2)
+ self.assertTrue(mse(jpdata[2], pgxdata) < 0.269)
+
+ pgxfile = opj_data_file('baseline/conformance/c1p0_05_3.pgx')
+ pgxdata = read_pgx(pgxfile)
+ self.assertTrue(peak_tolerance(jpdata[3], pgxdata) == 0)
+ self.assertTrue(mse(jpdata[3], pgxdata) == 0)
+
+ def test_ETS_C1P0_p0_06_j2k(self):
+ jfile = opj_data_file('input/conformance/p0_06.j2k')
jp2k = Jp2k(jfile)
- jpdata = jp2k.read(rlevel=0)
+ jpdata = jp2k.read_bands()
- pgxfile = os.path.join(data_root,
- 'baseline/conformance/c0p1_01.pgx')
+ pgxfile = opj_data_file('baseline/conformance/c1p0_06_0.pgx')
pgxdata = read_pgx(pgxfile)
+ self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 635)
+ self.assertTrue(mse(jpdata[0], pgxdata) < 11287)
- 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')
+ pgxfile = opj_data_file('baseline/conformance/c1p0_06_1.pgx')
pgxdata = read_pgx(pgxfile)
+ self.assertTrue(peak_tolerance(jpdata[1], pgxdata) < 403)
+ self.assertTrue(mse(jpdata[1], pgxdata) < 6124)
- 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')
+ pgxfile = opj_data_file('baseline/conformance/c1p0_06_2.pgx')
pgxdata = read_pgx(pgxfile)
+ self.assertTrue(peak_tolerance(jpdata[2], pgxdata) < 378)
+ self.assertTrue(mse(jpdata[2], pgxdata) < 3968)
- 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')
+ pgxfile = opj_data_file('baseline/conformance/c1p0_06_3.pgx')
pgxdata = read_pgx(pgxfile)
+ self.assertTrue(peak_tolerance(jpdata[3], pgxdata) == 0)
+ self.assertTrue(mse(jpdata[3], pgxdata) == 0)
- np.testing.assert_array_equal(jpdata, pgxdata)
+ def test_NR_DEC_merged_jp2_19_decode(self):
+ jfile = opj_data_file('input/nonregression/merged.jp2')
+ Jp2k(jfile).read_bands()
+ self.assertTrue(True)
- 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)
+@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] == 1,
+ "Tests not passing until 2.0")
+class TestSuite2point0(unittest.TestCase):
+ """Runs tests introduced in version 2.0 or that pass only in 2.0"""
- 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)
+ def setUp(self):
+ pass
- 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 tearDown(self):
+ pass
def test_ETS_C1P0_p0_10_j2k(self):
- jfile = os.path.join(data_root, 'input/conformance/p0_10.j2k')
+ jfile = opj_data_file('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)
+ jpdata = jp2k.read(rlevel=0)
- pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_10_0.pgx')
+ pgxfile = opj_data_file('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')
+ pgxfile = opj_data_file('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')
+ pgxfile = opj_data_file('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):
- """ETS_JP2_file5"""
- 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):
- """ETS_JP2_file6"""
- 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):
- """ETS_JP2_file7"""
- 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):
- """ETS_JP2_file8"""
- 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):
- """ETS_JP2_file9"""
- jfile = os.path.join(data_root, 'input/conformance/file9.jp2')
- jp2k = Jp2k(jfile)
- jpdata = jp2k.read()
- if re.match(r'[01]\.3', OPENJPEG_VERSION):
- # Version 1.3 reads in the image as the palette indices.
- self.assertEqual(jpdata.shape, (512, 768))
- else:
- self.assertEqual(jpdata.shape, (512, 768, 3))
-
- def test_NR_DEC_Bretagne2_j2k_1_decode(self):
- """test_NR_DEC_Bretagne2_j2k_1_decode"""
- jfile = os.path.join(data_root, 'input/nonregression/Bretagne2.j2k')
- jp2 = Jp2k(jfile)
- jp2.read()
- self.assertTrue(True)
-
- def test_NR_DEC__00042_j2k_2_decode(self):
- """NR_DEC__00042_j2k_2_decode"""
- jfile = os.path.join(data_root, 'input/nonregression/_00042.j2k')
- jp2 = Jp2k(jfile)
- jp2.read()
- self.assertTrue(True)
-
- @unittest.skip("fprintf stderr output in r2343.")
- def test_NR_DEC_123_j2c_3_decode(self):
- """NR_DEC_123_j2c_3_decode"""
- jfile = os.path.join(data_root, 'input/nonregression/123.j2c')
- jp2 = Jp2k(jfile)
- 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):
- """NR_DEC_broken_jp2_4_decode"""
- jfile = os.path.join(data_root, 'input/nonregression/broken.jp2')
- with self.assertWarns(UserWarning):
- # colr box has bad length.
- jp2 = Jp2k(jfile)
- with self.assertRaises(ValueError):
- jp2.read()
- self.assertTrue(True)
-
- @unittest.skipIf(re.match(r'[01]\.[34]', OPENJPEG_VERSION),
- "Segfaults openjpeg 1.4 and earlier.")
def test_NR_DEC_broken2_jp2_5_decode(self):
- """NR_DEC_broken2_jp2_5_decode"""
# Null pointer access
- jfile = os.path.join(data_root, 'input/nonregression/broken2.jp2')
- with self.assertRaises(ValueError):
+ jfile = opj_data_file('input/nonregression/broken2.jp2')
+ with self.assertRaises(IOError):
with warnings.catch_warnings():
- # Library warning, invalid number of subbands.
+ # Invalid marker ID.
warnings.simplefilter("ignore")
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):
- """NR_DEC_broken3_jp2_6_decode"""
- jfile = os.path.join(data_root, 'input/nonregression/broken3.jp2')
- with self.assertWarns(UserWarning):
- # colr box has bad length.
- j = Jp2k(jfile)
-
- with self.assertRaises(ValueError):
- j.read()
-
- @unittest.skipIf(re.match(r'[01]\.[34]', OPENJPEG_VERSION),
- "Segfaults openjpeg 1.4 and earlier.")
def test_NR_DEC_broken4_jp2_7_decode(self):
- """NR_DEC_broken4_jp2_7_decode"""
- # Null pointer access
- jfile = os.path.join(data_root, 'input/nonregression/broken4.jp2')
- with self.assertRaises(ValueError):
+ jfile = opj_data_file('input/nonregression/broken4.jp2')
+ with self.assertRaises(IOError):
with warnings.catch_warnings():
- # Library warning, invalid number of subbands.
+ # invalid number of subbands, bad marker ID
warnings.simplefilter("ignore")
Jp2k(jfile).read()
self.assertTrue(True)
- @unittest.skip("fprintf stderr output in r2343.")
- def test_NR_DEC_bug_j2c_8_decode(self):
- """NR_DEC_bug_j2c_8_decode"""
- jfile = os.path.join(data_root, 'input/nonregression/bug.j2c')
- Jp2k(jfile).read()
- self.assertTrue(True)
-
- def test_NR_DEC_buxI_j2k_9_decode(self):
- """NR_DEC_buxI_j2k_9_decode"""
- jfile = os.path.join(data_root, 'input/nonregression/buxI.j2k')
- Jp2k(jfile).read()
- self.assertTrue(True)
-
- def test_NR_DEC_buxR_j2k_10_decode(self):
- """NR_DEC_buxR_j2k_10_decode"""
- jfile = os.path.join(data_root, 'input/nonregression/buxR.j2k')
- Jp2k(jfile).read()
- self.assertTrue(True)
-
- def test_NR_DEC_Cannotreaddatawithnosizeknown_j2k_11_decode(self):
- """NR_DEC_Cannotreaddatawithnosizeknown_j2k_11_decode"""
- relpath = 'input/nonregression/Cannotreaddatawithnosizeknown.j2k'
- jfile = os.path.join(data_root, relpath)
- Jp2k(jfile).read()
- self.assertTrue(True)
-
- def test_NR_DEC_cthead1_j2k_12_decode(self):
- """NR_DEC_cthead1_j2k_12_decode"""
- jfile = os.path.join(data_root, 'input/nonregression/cthead1.j2k')
- Jp2k(jfile).read()
- self.assertTrue(True)
-
- def test_NR_DEC_CT_Phillips_JPEG2K_Decompr_Problem_j2k_13_decode(self):
- """NR_DEC_CT_Phillips_JPEG2K_Decompr_Problem_j2k_13_decode"""
- relpath = 'input/nonregression/CT_Phillips_JPEG2K_Decompr_Problem.j2k'
- jfile = os.path.join(data_root, relpath)
- 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')
- Jp2k(jfile).read()
- self.assertTrue(True)
-
- def test_NR_DEC_j2k32_j2k_15_decode(self):
- """NR_DEC_j2k32_j2k_15_decode"""
- jfile = os.path.join(data_root, 'input/nonregression/j2k32.j2k')
- Jp2k(jfile).read()
- self.assertTrue(True)
-
def test_NR_DEC_kakadu_v4_4_openjpegv2_broken_j2k_16_decode(self):
- """NR_DEC_kakadu_v4_4_openjpegv2_broken_j2k_16_decode"""
+ # This test actually passes in 1.5, but produces unpleasant warning
+ # messages that cannot be turned off?
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")
+ jfile = opj_data_file(relpath)
+ if glymur.version.openjpeg_version_tuple[0] < 2:
+ with warnings.catch_warnings():
+ # Incorrect warning issued about tile parts.
+ warnings.simplefilter("ignore")
+ Jp2k(jfile).read()
+ else:
Jp2k(jfile).read()
self.assertTrue(True)
- def test_NR_DEC_MarkerIsNotCompliant_j2k_17_decode(self):
- """NR_DEC_MarkerIsNotCompliant_j2k_17_decode"""
- jfile = os.path.join(data_root,
- 'input/nonregression/MarkerIsNotCompliant.j2k')
- Jp2k(jfile).read()
- self.assertTrue(True)
- def test_NR_DEC_Marrin_jp2_18_decode(self):
- """NR_DEC_Marrin_jp2_18_decode"""
- jfile = os.path.join(data_root, 'input/nonregression/Marrin.jp2')
- Jp2k(jfile).read()
- self.assertTrue(True)
+@unittest.skipIf(OPENJP2_IS_V2_OFFICIAL,
+ "Test not in done in v2.0.0 official")
+@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] == 1,
+ "Tests not introduced until 2.1")
+class TestSuite2point1(unittest.TestCase):
+ """Runs tests introduced in version 2.0+ or that pass only in 2.0+"""
- def test_NR_DEC_movie_00000_j2k_20_decode(self):
- """test_NR_DEC_movie_00000_j2k_20_decode"""
- jfile = os.path.join(data_root,
- 'input/nonregression/movie_00000.j2k')
- Jp2k(jfile).read()
- self.assertTrue(True)
+ def setUp(self):
+ pass
- def test_NR_DEC_movie_00001_j2k_21_decode(self):
- """NR_DEC_movie_00001_j2k_21_decode"""
- jfile = os.path.join(data_root,
- 'input/nonregression/movie_00001.j2k')
- Jp2k(jfile).read()
- self.assertTrue(True)
+ def tearDown(self):
+ pass
- def test_NR_DEC_movie_00002_j2k_22_decode(self):
- """NR_DEC_movie_00002_j2k_22_decode"""
- jfile = os.path.join(data_root, 'input/nonregression/movie_00002.j2k')
- Jp2k(jfile).read()
- self.assertTrue(True)
-
- def test_NR_DEC_orb_blue_lin_j2k_j2k_23_decode(self):
- """NR_DEC_orb_blue_lin_j2k_j2k_23_decode"""
- jfile = os.path.join(data_root,
- 'input/nonregression/orb-blue10-lin-j2k.j2k')
- Jp2k(jfile).read()
- self.assertTrue(True)
-
- def test_NR_DEC_orb_blue_win_j2k_j2k_24_decode(self):
- """NR_DEC_orb_blue_win_j2k_j2k_24_decode"""
- jfile = os.path.join(data_root,
- 'input/nonregression/orb-blue10-win-j2k.j2k')
- Jp2k(jfile).read()
- self.assertTrue(True)
-
- def test_nc_dec_orb_blue_lin_jp2_25_decode(self):
- """NR-DEC-orb-blue-lin.jp2-25-decode"""
- jfile = os.path.join(data_root,
- 'input/nonregression/orb-blue10-lin-jp2.jp2')
+ def test_NR_DEC_text_GBR_jp2_29_decode(self):
+ jfile = opj_data_file('input/nonregression/text_GBR.jp2')
with warnings.catch_warnings():
- # This file has an invalid ICC profile
+ # brand is 'jp2 ', but has any icc profile.
warnings.simplefilter("ignore")
- Jp2k(jfile).read()
+ jp2 = Jp2k(jfile)
+ jp2.read()
self.assertTrue(True)
- def test_nr_dec_orb_blue_win_jp2_26_decode(self):
- """NR-DEC-orb-blue-win.jp2-26-decode"""
- jfile = os.path.join(data_root,
- 'input/nonregression/orb-blue10-win-jp2.jp2')
+ def test_NR_DEC_kodak_2layers_lrcp_j2c_31_decode(self):
+ jfile = opj_data_file('input/nonregression/kodak_2layers_lrcp.j2c')
Jp2k(jfile).read()
self.assertTrue(True)
- def test_nr_dec_relax_jp2_27_decode(self):
- """NR-DEC-relax.jp2-27-decode"""
- jfile = os.path.join(data_root,
- 'input/nonregression/relax.jp2')
+ def test_NR_DEC_kodak_2layers_lrcp_j2c_32_decode(self):
+ jfile = opj_data_file('input/nonregression/kodak_2layers_lrcp.j2c')
+ Jp2k(jfile).read(layer=2)
+ self.assertTrue(True)
+
+ def test_NR_DEC_issue104_jpxstream_jp2_33_decode(self):
+ jfile = opj_data_file('input/nonregression/issue104_jpxstream.jp2')
Jp2k(jfile).read()
self.assertTrue(True)
- def test_nr_dec_test_lossless_j2k_28_decode(self):
- """NR-DEC-test-lossless.j2k-28-decode"""
- jfile = os.path.join(data_root,
- 'input/nonregression/test_lossless.j2k')
+ def test_NR_DEC_mem_b2ace68c_1381_jp2_34_decode(self):
+ jfile = opj_data_file('input/nonregression/mem-b2ace68c-1381.jp2')
+ with warnings.catch_warnings():
+ # This file has a bad pclr box, we test for this elsewhere.
+ warnings.simplefilter("ignore")
+ j = Jp2k(jfile)
+ j.read()
+ self.assertTrue(True)
+
+ def test_NR_DEC_mem_b2b86b74_2753_jp2_35_decode(self):
+ jfile = opj_data_file('input/nonregression/mem-b2b86b74-2753.jp2')
Jp2k(jfile).read()
self.assertTrue(True)
- def test_nr_dec_issue104_jpxstream_jp2_33_decode(self):
- """NR-DEC-issue104-jpxstream.jp2-33-decode"""
- jfile = os.path.join(data_root,
- 'input/nonregression/issue104_jpxstream.jp2')
- Jp2k(jfile).read()
- self.assertTrue(True)
+ def test_NR_DEC_gdal_fuzzer_unchecked_num_resolutions_jp2_36_decode(self):
+ f = 'input/nonregression/gdal_fuzzer_unchecked_numresolutions.jp2'
+ jfile = opj_data_file(f)
+ with warnings.catch_warnings():
+ # Invalid number of resolutions.
+ warnings.simplefilter("ignore")
+ j = Jp2k(jfile)
+ with self.assertRaises(IOError):
+ j.read()
- def test_nr_dec_file_409752_jp2_40_decode(self):
- """NR-DEC-file-409752.jp2-40-decode"""
- jfile = os.path.join(data_root, 'input/nonregression/file409752.jp2')
- j = Jp2k(jfile)
+ def test_NR_DEC_gdal_fuzzer_check_number_of_tiles_jp2_38_decode(self):
+ relpath = 'input/nonregression/gdal_fuzzer_check_number_of_tiles.jp2'
+ jfile = opj_data_file(relpath)
+ with warnings.catch_warnings():
+ # Invalid number of tiles.
+ warnings.simplefilter("ignore")
+ j = Jp2k(jfile)
+ with self.assertRaises(IOError):
+ j.read()
+
+ def test_NR_DEC_gdal_fuzzer_check_comp_dx_dy_jp2_39_decode(self):
+ relpath = 'input/nonregression/gdal_fuzzer_check_comp_dx_dy.jp2'
+ jfile = opj_data_file(relpath)
+ with warnings.catch_warnings():
+ # Invalid subsampling value
+ warnings.simplefilter("ignore")
+ with self.assertRaises(IOError):
+ Jp2k(jfile).read()
+
+ def test_NR_DEC_file_409752_jp2_40_decode(self):
+ jfile = opj_data_file('input/nonregression/file409752.jp2')
with self.assertRaises(RuntimeError):
- j.read()
+ Jp2k(jfile).read()
+
+ @unittest.skipIf(sys.hexversion < 0x03020000,
+ "Uses features introduced in 3.2.")
+ def test_NR_DEC_issue188_beach_64bitsbox_jp2_41_decode(self):
+ # Has an 'XML ' box instead of 'xml '. Yes that is pedantic, but it
+ # really does deserve a warning.
+ relpath = 'input/nonregression/issue188_beach_64bitsbox.jp2'
+ jfile = opj_data_file(relpath)
+ with self.assertWarns(UserWarning):
+ Jp2k(jfile).read()
+
+ def test_NR_DEC_issue206_image_000_jp2_42_decode(self):
+ jfile = opj_data_file('input/nonregression/issue206_image-000.jp2')
+ Jp2k(jfile).read()
+ self.assertTrue(True)
+
+ def test_NR_DEC_p1_04_j2k_43_decode(self):
+ jfile = opj_data_file('input/conformance/p1_04.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(0, 0, 1024, 1024))
+ odata = jp2k.read()
+ np.testing.assert_array_equal(ssdata, odata)
+
+ def test_NR_DEC_p1_04_j2k_44_decode(self):
+ jfile = opj_data_file('input/conformance/p1_04.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(640, 512, 768, 640))
+ odata = jp2k.read()
+ np.testing.assert_array_equal(ssdata, odata[640:768, 512:640])
+
+ def test_NR_DEC_p1_04_j2k_45_decode(self):
+ jfile = opj_data_file('input/conformance/p1_04.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(896, 896, 1024, 1024))
+ odata = jp2k.read()
+ np.testing.assert_array_equal(ssdata, odata[896:1024, 896:1024])
+
+ def test_NR_DEC_p1_04_j2k_46_decode(self):
+ jfile = opj_data_file('input/conformance/p1_04.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(500, 100, 800, 300))
+ odata = jp2k.read()
+ np.testing.assert_array_equal(ssdata, odata[500:800, 100:300])
+
+ def test_NR_DEC_p1_04_j2k_47_decode(self):
+ jfile = opj_data_file('input/conformance/p1_04.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(520, 260, 600, 360))
+ odata = jp2k.read()
+ np.testing.assert_array_equal(ssdata, odata[520:600, 260:360])
+
+ def test_NR_DEC_p1_04_j2k_48_decode(self):
+ jfile = opj_data_file('input/conformance/p1_04.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(520, 260, 660, 360))
+ odata = jp2k.read()
+ np.testing.assert_array_equal(ssdata, odata[520:660, 260:360])
+
+ def test_NR_DEC_p1_04_j2k_49_decode(self):
+ jfile = opj_data_file('input/conformance/p1_04.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(520, 360, 600, 400))
+ odata = jp2k.read()
+ np.testing.assert_array_equal(ssdata, odata[520:600, 360:400])
+
+ def test_NR_DEC_p1_04_j2k_50_decode(self):
+ jfile = opj_data_file('input/conformance/p1_04.j2k')
+ jp2k = Jp2k(jfile)
+ 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 = opj_data_file('input/conformance/p1_04.j2k')
+ jp2k = Jp2k(jfile)
+ 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 = opj_data_file('input/conformance/p1_04.j2k')
+ jp2k = Jp2k(jfile)
+ 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 = opj_data_file('input/conformance/p1_04.j2k')
+ jp2k = Jp2k(jfile)
+ 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 = opj_data_file('input/conformance/p1_04.j2k')
+ jp2k = Jp2k(jfile)
+ 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 = opj_data_file('input/conformance/p1_04.j2k')
+ jp2k = Jp2k(jfile)
+ 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 = opj_data_file('input/conformance/p1_04.j2k')
+ jp2k = Jp2k(jfile)
+ 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):
+ jfile = opj_data_file('input/conformance/p1_04.j2k')
+ jp2k = Jp2k(jfile)
+ tdata = jp2k.read(tile=63) # last tile
+ odata = jp2k.read()
+ np.testing.assert_array_equal(tdata, odata[896:1024, 896:1024])
+
+ def test_NR_DEC_p1_04_j2k_58_decode(self):
+ jfile = opj_data_file('input/conformance/p1_04.j2k')
+ jp2k = Jp2k(jfile)
+ 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):
+ jfile = opj_data_file('input/conformance/p1_04.j2k')
+ jp2k = Jp2k(jfile)
+ tdata = jp2k.read(tile=12) # 2nd row, 5th column
+ odata = jp2k.read()
+ np.testing.assert_array_equal(tdata, odata[128:256, 512:640])
+
+ def test_NR_DEC_p1_04_j2k_60_decode(self):
+ jfile = opj_data_file('input/conformance/p1_04.j2k')
+ jp2k = Jp2k(jfile)
+ 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])
+
+ def test_NR_DEC_jp2_36_decode(self):
+ lst = ('input',
+ 'nonregression',
+ 'gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.jp2')
+ jfile = opj_data_file('/'.join(lst))
+ with warnings.catch_warnings():
+ # Invalid component number.
+ warnings.simplefilter("ignore")
+ j = Jp2k(jfile)
+ with self.assertRaises(IOError):
+ j.read()
+
+ @unittest.skip("fprintf stderr output in r2343.")
+ def test_NR_DEC_p1_06_j2k_61_decode(self):
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(0, 0, 12, 12))
+ odata = jp2k.read()
+ np.testing.assert_array_equal(ssdata, odata[0:12, 0:12])
+
+ @unittest.skip("fprintf stderr output in r2343.")
+ def test_NR_DEC_p1_06_j2k_62_decode(self):
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(1, 8, 8, 11))
+ odata = jp2k.read()
+ np.testing.assert_array_equal(ssdata, odata[1:8, 8:11])
+
+ @unittest.skip("fprintf stderr output in r2343.")
+ def test_NR_DEC_p1_06_j2k_63_decode(self):
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(9, 9, 12, 12))
+ odata = jp2k.read()
+ np.testing.assert_array_equal(ssdata, odata[9:12, 9:12])
+
+ @unittest.skip("fprintf stderr output in r2343.")
+ def test_NR_DEC_p1_06_j2k_64_decode(self):
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(10, 4, 12, 10))
+ odata = jp2k.read()
+ np.testing.assert_array_equal(ssdata, odata[10:12, 4:10])
+
+ @unittest.skip("fprintf stderr output in r2343.")
+ def test_NR_DEC_p1_06_j2k_65_decode(self):
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(3, 3, 9, 9))
+ odata = jp2k.read()
+ np.testing.assert_array_equal(ssdata, odata[3:9, 3:9])
+
+ @unittest.skip("fprintf stderr output in r2343.")
+ def test_NR_DEC_p1_06_j2k_66_decode(self):
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(4, 4, 7, 7))
+ odata = jp2k.read()
+ np.testing.assert_array_equal(ssdata, odata[4:7, 4:7])
+
+ @unittest.skip("fprintf stderr output in r2343.")
+ def test_NR_DEC_p1_06_j2k_67_decode(self):
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(4, 4, 5, 5))
+ odata = jp2k.read()
+ np.testing.assert_array_equal(ssdata, odata[4:5, 4: 5])
+
+ @unittest.skip("fprintf stderr output in r2343.")
+ def test_NR_DEC_p1_06_j2k_68_decode(self):
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
+ jp2k = Jp2k(jfile)
+ 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 = opj_data_file('input/conformance/p1_06.j2k')
+ jp2k = Jp2k(jfile)
+ 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 = opj_data_file('input/conformance/p1_06.j2k')
+ jp2k = Jp2k(jfile)
+ 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 = opj_data_file('input/conformance/p1_06.j2k')
+ jp2k = Jp2k(jfile)
+ 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 = opj_data_file('input/conformance/p1_06.j2k')
+ jp2k = Jp2k(jfile)
+ 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 = opj_data_file('input/conformance/p1_06.j2k')
+ jp2k = Jp2k(jfile)
+ 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 = opj_data_file('input/conformance/p1_06.j2k')
+ jp2k = Jp2k(jfile)
+ 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):
+ # Image size would be 0 x 0.
+ jfile = opj_data_file('input/conformance/p1_06.j2k')
+ jp2k = Jp2k(jfile)
+ with self.assertRaises((IOError, OSError)):
+ jp2k.read(area=(9, 9, 12, 12), rlevel=2)
+
+ def test_NR_DEC_p0_04_j2k_85_decode(self):
+ jfile = opj_data_file('input/conformance/p0_04.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(0, 0, 256, 256))
+ fulldata = jp2k.read()
+ np.testing.assert_array_equal(fulldata[0:256, 0:256], ssdata)
+
+ def test_NR_DEC_p0_04_j2k_86_decode(self):
+ jfile = opj_data_file('input/conformance/p0_04.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(0, 128, 128, 256))
+ fulldata = jp2k.read()
+ np.testing.assert_array_equal(fulldata[0:128, 128:256], ssdata)
+
+ def test_NR_DEC_p0_04_j2k_87_decode(self):
+ jfile = opj_data_file('input/conformance/p0_04.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(10, 50, 200, 120))
+ fulldata = jp2k.read()
+ np.testing.assert_array_equal(fulldata[10:200, 50:120], ssdata)
+
+ def test_NR_DEC_p0_04_j2k_88_decode(self):
+ jfile = opj_data_file('input/conformance/p0_04.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(150, 10, 210, 190))
+ fulldata = jp2k.read()
+ np.testing.assert_array_equal(fulldata[150:210, 10:190], ssdata)
+
+ def test_NR_DEC_p0_04_j2k_89_decode(self):
+ jfile = opj_data_file('input/conformance/p0_04.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(80, 100, 150, 200))
+ fulldata = jp2k.read()
+ np.testing.assert_array_equal(fulldata[80:150, 100:200], ssdata)
+
+ def test_NR_DEC_p0_04_j2k_90_decode(self):
+ jfile = opj_data_file('input/conformance/p0_04.j2k')
+ jp2k = Jp2k(jfile)
+ ssdata = jp2k.read(area=(20, 150, 50, 200))
+ fulldata = jp2k.read()
+ np.testing.assert_array_equal(fulldata[20:50, 150:200], ssdata)
+
+ def test_NR_DEC_p0_04_j2k_91_decode(self):
+ jfile = opj_data_file('input/conformance/p0_04.j2k')
+ jp2k = Jp2k(jfile)
+ 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 = opj_data_file('input/conformance/p0_04.j2k')
+ jp2k = Jp2k(jfile)
+ 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 = opj_data_file('input/conformance/p0_04.j2k')
+ jp2k = Jp2k(jfile)
+ 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 = opj_data_file('input/conformance/p0_04.j2k')
+ jp2k = Jp2k(jfile)
+ 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 = opj_data_file('input/conformance/p0_04.j2k')
+ jp2k = Jp2k(jfile)
+ 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 = opj_data_file('input/conformance/p0_04.j2k')
+ jp2k = Jp2k(jfile)
+ 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)
+
if __name__ == "__main__":
unittest.main()
diff --git a/glymur/test/test_opj_suite_neg.py b/glymur/test/test_opj_suite_neg.py
index e8675aa..66115a2 100644
--- a/glymur/test/test_opj_suite_neg.py
+++ b/glymur/test/test_opj_suite_neg.py
@@ -23,23 +23,17 @@ else:
import numpy as np
from .fixtures import read_image, NO_READ_BACKEND, NO_READ_BACKEND_MSG
+from .fixtures import OPJ_DATA_ROOT, opj_data_file
from glymur import Jp2k
import glymur
-try:
- DATA_ROOT = os.environ['OPJ_DATA_ROOT']
-except KeyError:
- DATA_ROOT = None
-except:
- raise
-
@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,
- "OPJ_DATA_ROOT environment variable not set")
+@unittest.skipIf(OPJ_DATA_ROOT is None,
+ "OPJ_OPJ_DATA_ROOT environment variable not set")
class TestSuiteNegative(unittest.TestCase):
"""Test suite for certain negative tests from openjpeg suite."""
@@ -54,7 +48,7 @@ class TestSuiteNegative(unittest.TestCase):
def test_psnr_with_cratios(self):
"""Using psnr with cratios options is not allowed."""
# Not an OpenJPEG test, but close.
- infile = os.path.join(DATA_ROOT, 'input/nonregression/Bretagne1.ppm')
+ infile = opj_data_file('input/nonregression/Bretagne1.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
@@ -64,7 +58,7 @@ class TestSuiteNegative(unittest.TestCase):
def test_nr_marker_not_compliant(self):
"""non-compliant marker, should still be able to read"""
relpath = 'input/nonregression/MarkerIsNotCompliant.j2k'
- jfile = os.path.join(DATA_ROOT, relpath)
+ jfile = opj_data_file(relpath)
jp2k = Jp2k(jfile)
jp2k.get_codestream(header_only=False)
self.assertTrue(True)
@@ -74,7 +68,7 @@ class TestSuiteNegative(unittest.TestCase):
def test_nr_illegalclrtransform(self):
"""EOC marker is bad"""
relpath = 'input/nonregression/illegalcolortransform.j2k'
- jfile = os.path.join(DATA_ROOT, relpath)
+ jfile = opj_data_file(relpath)
jp2k = Jp2k(jfile)
with self.assertWarns(UserWarning):
codestream = jp2k.get_codestream(header_only=False)
@@ -87,7 +81,7 @@ class TestSuiteNegative(unittest.TestCase):
def test_nr_cannotreadwnosizeknown(self):
"""not sure exactly what is wrong with this file"""
relpath = 'input/nonregression/Cannotreaddatawithnosizeknown.j2k'
- jfile = os.path.join(DATA_ROOT, relpath)
+ jfile = opj_data_file(relpath)
jp2k = Jp2k(jfile)
jp2k.get_codestream(header_only=False)
self.assertTrue(True)
@@ -118,7 +112,7 @@ class TestSuiteNegative(unittest.TestCase):
# Verify that a warning is issued if we read past the end of a box
# This file has a palette (pclr) box whose length is impossibly
# short.
- infile = os.path.join(DATA_ROOT,
+ infile = os.path.join(OPJ_DATA_ROOT,
'input/nonregression/mem-b2ace68c-1381.jp2')
with self.assertWarns(UserWarning):
Jp2k(infile)
diff --git a/glymur/test/test_opj_suite_write.py b/glymur/test/test_opj_suite_write.py
index e6f1575..2f699e6 100644
--- a/glymur/test/test_opj_suite_write.py
+++ b/glymur/test/test_opj_suite_write.py
@@ -10,6 +10,7 @@ suite.
# pylint: disable=F0401
import os
+import re
import sys
import tempfile
@@ -19,23 +20,18 @@ else:
import unittest
from .fixtures import read_image, NO_READ_BACKEND, NO_READ_BACKEND_MSG
+from .fixtures import OPJ_DATA_ROOT, opj_data_file
from glymur import Jp2k
import glymur
-try:
- data_root = os.environ['OPJ_DATA_ROOT']
-except KeyError:
- data_root = None
-except:
- raise
-
@unittest.skipIf(os.name == "nt", "no write support on windows, period")
-@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
- "Missing openjp2 library.")
+@unittest.skipIf(re.match(r"""1\.[01234]\.\d""",
+ glymur.version.openjpeg_version) is not None,
+ "Writing only supported with openjpeg version 1.5+.")
@unittest.skipIf(NO_READ_BACKEND, NO_READ_BACKEND_MSG)
-@unittest.skipIf(data_root is None,
+@unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
class TestSuiteWrite(unittest.TestCase):
"""Tests for writing with openjp2 backend.
@@ -51,7 +47,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Bretagne1_ppm_1_encode(self):
"""NR-ENC-Bretagne1.ppm-1-encode"""
- infile = os.path.join(data_root, 'input/nonregression/Bretagne1.ppm')
+ infile = opj_data_file('input/nonregression/Bretagne1.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
@@ -115,7 +111,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Bretagne1_ppm_2_encode(self):
"""NR-ENC-Bretagne1.ppm-2-encode"""
- infile = os.path.join(data_root, 'input/nonregression/Bretagne1.ppm')
+ infile = opj_data_file('input/nonregression/Bretagne1.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
@@ -180,7 +176,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Bretagne1_ppm_3_encode(self):
"""NR-ENC-Bretagne1.ppm-3-encode"""
- infile = os.path.join(data_root, 'input/nonregression/Bretagne1.ppm')
+ infile = opj_data_file('input/nonregression/Bretagne1.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
@@ -247,7 +243,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Bretagne2_ppm_4_encode(self):
"""NR-ENC-Bretagne2.ppm-4-encode"""
- infile = os.path.join(data_root, 'input/nonregression/Bretagne2.ppm')
+ infile = opj_data_file('input/nonregression/Bretagne2.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
@@ -316,7 +312,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Bretagne2_ppm_5_encode(self):
"""NR-ENC-Bretagne2.ppm-5-encode"""
- infile = os.path.join(data_root, 'input/nonregression/Bretagne2.ppm')
+ infile = opj_data_file('input/nonregression/Bretagne2.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
@@ -379,7 +375,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Bretagne2_ppm_6_encode(self):
"""NR-ENC-Bretagne2.ppm-6-encode"""
- infile = os.path.join(data_root, 'input/nonregression/Bretagne2.ppm')
+ infile = opj_data_file('input/nonregression/Bretagne2.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
@@ -447,7 +443,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Bretagne2_ppm_7_encode(self):
"""NR-ENC-Bretagne2.ppm-7-encode"""
- infile = os.path.join(data_root, 'input/nonregression/Bretagne2.ppm')
+ infile = opj_data_file('input/nonregression/Bretagne2.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
@@ -514,7 +510,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Bretagne2_ppm_8_encode(self):
"""NR-ENC-Bretagne2.ppm-8-encode"""
- infile = os.path.join(data_root, 'input/nonregression/Bretagne2.ppm')
+ infile = opj_data_file('input/nonregression/Bretagne2.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
@@ -578,7 +574,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Cevennes1_bmp_9_encode(self):
"""NR-ENC-Cevennes1.bmp-9-encode"""
- infile = os.path.join(data_root, 'input/nonregression/Cevennes1.bmp')
+ infile = opj_data_file('input/nonregression/Cevennes1.bmp')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
@@ -641,7 +637,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Cevennes2_ppm_10_encode(self):
"""NR-ENC-Cevennes2.ppm-10-encode"""
- infile = os.path.join(data_root, 'input/nonregression/Cevennes2.ppm')
+ infile = opj_data_file('input/nonregression/Cevennes2.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
@@ -704,8 +700,7 @@ class TestSuiteWrite(unittest.TestCase):
def test_NR_ENC_Rome_bmp_11_encode(self):
"""NR-ENC-Rome.bmp-11-encode"""
- data = read_image(os.path.join(data_root,
- 'input/nonregression/Rome.bmp'))
+ data = read_image(opj_data_file('input/nonregression/Rome.bmp'))
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
jp2 = Jp2k(tfile.name, 'wb')
jp2.write(data, psnr=[30, 35, 50], prog='LRCP', numres=3)
@@ -804,8 +799,7 @@ class TestSuiteWrite(unittest.TestCase):
"""NR-ENC-random-issue-0005.tif-12-encode"""
# opj_decompress has trouble reading it, but that is not an issue here.
# The nature of the image itself seems to give the compressor trouble.
- infile = os.path.join(data_root,
- 'input/nonregression/random-issue-0005.tif')
+ infile = opj_data_file('input/nonregression/random-issue-0005.tif')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
diff --git a/glymur/test/test_printing.py b/glymur/test/test_printing.py
index f533aa4..8591b1b 100644
--- a/glymur/test/test_printing.py
+++ b/glymur/test/test_printing.py
@@ -32,13 +32,7 @@ else:
import glymur
from glymur import Jp2k
-
-try:
- DATA_ROOT = os.environ['OPJ_DATA_ROOT']
-except KeyError:
- DATA_ROOT = None
-except:
- raise
+from .fixtures import OPJ_DATA_ROOT, opj_data_file
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
@@ -287,11 +281,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_icc_profile(self):
"""verify printing of colr box with ICC profile"""
- filename = os.path.join(DATA_ROOT, 'input/nonregression/text_GBR.jp2')
+ filename = opj_data_file('input/nonregression/text_GBR.jp2')
with warnings.catch_warnings():
# brand is 'jp2 ', but has any icc profile.
warnings.simplefilter("ignore")
@@ -356,11 +350,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_crg(self):
"""verify printing of CRG segment"""
- filename = os.path.join(DATA_ROOT, 'input/conformance/p0_03.j2k')
+ filename = opj_data_file('input/conformance/p0_03.j2k')
j = glymur.Jp2k(filename)
codestream = j.get_codestream()
with patch('sys.stdout', new=StringIO()) as fake_out:
@@ -371,11 +365,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_rgn(self):
"""verify printing of RGN segment"""
- filename = os.path.join(DATA_ROOT, 'input/conformance/p0_03.j2k')
+ filename = opj_data_file('input/conformance/p0_03.j2k')
j = glymur.Jp2k(filename)
codestream = j.get_codestream(header_only=False)
with patch('sys.stdout', new=StringIO()) as fake_out:
@@ -388,11 +382,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_sop(self):
"""verify printing of SOP segment"""
- filename = os.path.join(DATA_ROOT, 'input/conformance/p0_03.j2k')
+ filename = opj_data_file('input/conformance/p0_03.j2k')
j = glymur.Jp2k(filename)
codestream = j.get_codestream(header_only=False)
with patch('sys.stdout', new=StringIO()) as fake_out:
@@ -403,11 +397,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_cme(self):
"""Test printing a CME or comment marker segment."""
- filename = os.path.join(DATA_ROOT, 'input/conformance/p0_02.j2k')
+ filename = opj_data_file('input/conformance/p0_02.j2k')
j = glymur.Jp2k(filename)
codestream = j.get_codestream()
# 2nd to last segment in the main header
@@ -431,11 +425,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_plt_segment(self):
"""verify printing of PLT segment"""
- filename = os.path.join(DATA_ROOT, 'input/conformance/p0_07.j2k')
+ filename = opj_data_file('input/conformance/p0_07.j2k')
j = glymur.Jp2k(filename)
codestream = j.get_codestream(header_only=False)
with patch('sys.stdout', new=StringIO()) as fake_out:
@@ -450,11 +444,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_pod_segment(self):
"""verify printing of POD segment"""
- filename = os.path.join(DATA_ROOT, 'input/conformance/p0_13.j2k')
+ filename = opj_data_file('input/conformance/p0_13.j2k')
j = glymur.Jp2k(filename)
codestream = j.get_codestream()
with patch('sys.stdout', new=StringIO()) as fake_out:
@@ -480,11 +474,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_ppm_segment(self):
"""verify printing of PPM segment"""
- filename = os.path.join(DATA_ROOT, 'input/conformance/p1_03.j2k')
+ filename = opj_data_file('input/conformance/p1_03.j2k')
j = glymur.Jp2k(filename)
codestream = j.get_codestream()
with patch('sys.stdout', new=StringIO()) as fake_out:
@@ -498,11 +492,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_ppt_segment(self):
"""verify printing of ppt segment"""
- filename = os.path.join(DATA_ROOT, 'input/conformance/p1_06.j2k')
+ filename = opj_data_file('input/conformance/p1_06.j2k')
j = glymur.Jp2k(filename)
codestream = j.get_codestream(header_only=False)
with patch('sys.stdout', new=StringIO()) as fake_out:
@@ -610,11 +604,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_tlm_segment(self):
"""verify printing of TLM segment"""
- filename = os.path.join(DATA_ROOT, 'input/conformance/p0_15.j2k')
+ filename = opj_data_file('input/conformance/p0_15.j2k')
j = glymur.Jp2k(filename)
codestream = j.get_codestream()
with patch('sys.stdout', new=StringIO()) as fake_out:
@@ -704,11 +698,11 @@ class TestPrinting(unittest.TestCase):
@unittest.skipIf(sys.hexversion < 0x02070000,
"Differences in XML printing between 2.6 and 2.7")
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_xml(self):
"""verify printing of XML box"""
- filename = os.path.join(DATA_ROOT, 'input/conformance/file1.jp2')
+ filename = opj_data_file('input/conformance/file1.jp2')
j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2])
@@ -735,11 +729,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_channel_definition(self):
"""verify printing of cdef box"""
- filename = os.path.join(DATA_ROOT, 'input/conformance/file2.jp2')
+ filename = opj_data_file('input/conformance/file2.jp2')
j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2].box[2])
@@ -751,11 +745,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_component_mapping(self):
"""verify printing of cmap box"""
- filename = os.path.join(DATA_ROOT, 'input/conformance/file9.jp2')
+ filename = opj_data_file('input/conformance/file9.jp2')
j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2].box[2])
@@ -767,11 +761,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_palette7(self):
"""verify printing of pclr box"""
- filename = os.path.join(DATA_ROOT, 'input/conformance/file9.jp2')
+ filename = opj_data_file('input/conformance/file9.jp2')
j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2].box[1])
@@ -781,11 +775,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_rreq(self):
"""verify printing of reader requirements box"""
- filename = os.path.join(DATA_ROOT, 'input/conformance/file7.jp2')
+ filename = opj_data_file('input/conformance/file7.jp2')
j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2])
@@ -805,11 +799,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_differing_subsamples(self):
"""verify printing of SIZ with different subsampling... Issue 86."""
- filename = os.path.join(DATA_ROOT, 'input/conformance/p0_05.j2k')
+ filename = opj_data_file('input/conformance/p0_05.j2k')
j = glymur.Jp2k(filename)
codestream = j.get_codestream()
with patch('sys.stdout', new=StringIO()) as fake_out:
@@ -828,11 +822,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_palette_box(self):
"""Verify that palette (pclr) boxes are printed without error."""
- filename = os.path.join(DATA_ROOT, 'input/conformance/file9.jp2')
+ filename = opj_data_file('input/conformance/file9.jp2')
j = glymur.Jp2k(filename)
with patch('sys.stdout', new=StringIO()) as fake_out:
print(j.box[2].box[1])
@@ -921,13 +915,13 @@ class TestPrinting(unittest.TestCase):
@unittest.skipIf(sys.hexversion < 0x03000000,
"Ordered dicts not printing well in 2.7")
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_jpx_approx_icc_profile(self):
"""verify jpx with approx field equal to zero"""
# ICC profiles may be used in JP2, but the approximation field should
# be zero unless we have jpx. This file does both.
- filename = os.path.join(DATA_ROOT, 'input/nonregression/text_GBR.jp2')
+ filename = opj_data_file('input/nonregression/text_GBR.jp2')
with warnings.catch_warnings():
# brand is 'jp2 ', but has any icc profile.
warnings.simplefilter("ignore")
@@ -966,11 +960,11 @@ class TestPrinting(unittest.TestCase):
expected = '\n'.join(lines)
self.assertEqual(actual, expected)
- @unittest.skipIf(DATA_ROOT is None,
+ @unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
def test_uuid(self):
"""verify printing of UUID box"""
- filename = os.path.join(DATA_ROOT, 'input/nonregression/text_GBR.jp2')
+ filename = opj_data_file('input/nonregression/text_GBR.jp2')
with warnings.catch_warnings():
# brand is 'jp2 ', but has any icc profile.
warnings.simplefilter("ignore")
diff --git a/glymur/version.py b/glymur/version.py
new file mode 100644
index 0000000..740d610
--- /dev/null
+++ b/glymur/version.py
@@ -0,0 +1,53 @@
+# This file is part of glymur, a Python interface for accessing JPEG 2000.
+#
+# http://glymur.readthedocs.org
+#
+# Copyright 2013 John Evans
+#
+# License: MIT
+
+import sys
+import numpy as np
+from distutils.version import LooseVersion
+
+from .lib import openjpeg as opj
+from .lib import openjp2 as opj2
+
+version = "0.5.0"
+_sv = LooseVersion(version)
+version_tuple = _sv.version
+
+
+if opj.OPENJPEG is None and opj2.OPENJP2 is None:
+ openjpeg_version = '0.0.0'
+elif opj2.OPENJP2 is None:
+ openjpeg_version = opj.version()
+else:
+ openjpeg_version = opj2.version()
+
+_sv = LooseVersion(openjpeg_version)
+openjpeg_version_tuple = _sv.version
+
+__doc__ = """\
+This is glymur **{glymur_version}**
+
+* OPENJPEG version: **{openjpeg}**
+""".format(glymur_version=version,
+ openjpeg=openjpeg_version)
+
+info = """\
+Summary of glymur configuration
+-------------------------------
+
+glymur {glymur}
+OPENJPEG {openjpeg}
+Python {python}
+sys.platform {platform}
+sys.maxsize {maxsize}
+numpy {numpy}
+""".format(glymur=version,
+ openjpeg=openjpeg_version,
+ python=sys.version,
+ platform=sys.platform,
+ maxsize=sys.maxsize,
+ numpy=np.__version__)
diff --git a/setup.py b/setup.py
index ff533a7..8d62705 100644
--- a/setup.py
+++ b/setup.py
@@ -2,7 +2,6 @@ from setuptools import setup, find_packages
import sys
kwargs = {'name': 'Glymur',
- 'version': '0.4.1',
'description': 'Tools for accessing JPEG2000 files',
'long_description': open('README.md').read(),
'author': 'John Evans',
@@ -13,8 +12,7 @@ kwargs = {'name': 'Glymur',
'package_data': {'glymur': ['data/*.jp2', 'data/*.j2k']},
'scripts': ['bin/jp2dump'],
'license': 'MIT',
- 'test_suite': 'glymur.test',
- 'platforms': ['darwin']}
+ 'test_suite': 'glymur.test'}
instllrqrs = ['numpy>=1.4.1']
if sys.hexversion < 0x03030000:
@@ -39,4 +37,8 @@ clssfrs = ["Programming Language :: Python",
"Intended Audience :: Information Technology",
"Topic :: Software Development :: Libraries :: Python Modules"]
kwargs['classifiers'] = clssfrs
+
+import glymur
+kwargs['version'] = glymur.version.version
+
setup(**kwargs)