Compare commits

...
Sign in to create a new pull request.

24 commits

Author SHA1 Message Date
John Evans
e165edbe53 progress 2014-11-21 10:21:55 -05:00
John Evans
e446cb1577 filter out max rlevel test on version 1.x of openjpeg, closes #301
there's nothing that can be done about it, it's behavior in the library
2014-11-20 10:32:43 -05:00
jevans
3f7c08739c progress 2014-11-19 23:09:12 -05:00
John Evans
5e8a66c38e fix tab error 2014-11-19 17:08:29 -05:00
John Evans
e1846c31e0 progress on write 2014-11-19 15:34:03 -05:00
John Evans
8f8e9eff85 get write tests passing on travis 2014-11-19 14:49:15 -05:00
John Evans
6e1637e470 starting on incompatible changes to writing 2014-11-19 14:25:44 -05:00
John Evans
3c73415090 progress, no more deprecation warnings? 2014-11-19 09:22:40 -05:00
John Evans
3ebb708e11 progress 2014-11-19 07:59:05 -05:00
jevans
e2059d59e8 removed repeated array-style slicing tests 2014-11-19 07:24:47 -05:00
jevans
9025bb3ec3 layer is now a property 2014-11-18 23:15:09 -05:00
jevans
373afb692e progress 2014-11-18 20:45:25 -05:00
John Evans
117b7d1bbe refactored, skipping tests not to be run on openjpeg 1.3 2014-11-18 10:06:52 -05:00
John Evans
036b14cc2b filter out write tests that should not run on openjpeg 1.3 2014-11-18 09:48:19 -05:00
John Evans
a35ebe1836 backwards compatibility tests need to be filtered out on some platforms
The need to verify the warning means that the python-six issue applies.
2014-11-18 08:03:34 -05:00
jevans
2a3128e983 subsumed test_opj_suite_2p1 ito test_opj_suite 2014-11-17 22:27:52 -05:00
jevans
63d6a2f1e1 progress 2014-11-17 18:17:47 -05:00
jevans
4f1c34991f replacing more uses of read function with array-style slicing 2014-11-17 07:33:43 -05:00
jevans
4f2a896eff ignore_pclr_cmap_cdef is now a property 2014-11-13 13:39:36 -05:00
jevans
82a9edae62 progress 2014-11-12 21:09:09 -05:00
jevans
9691311633 merge branch 'issue299' of https://github.com/quintusdias/glymur into issue299 2014-11-12 20:53:46 -05:00
jevans
c15fe52f82 progress 2014-11-12 20:53:13 -05:00
John Evans
a1413b0f15 progress 2014-11-12 17:30:43 -05:00
John Evans
89a1b0bb1c progress, working on rlevel 2014-11-11 10:46:59 -05:00
16 changed files with 1113 additions and 1171 deletions

View file

@ -14,27 +14,22 @@ retrieve a full resolution and first lower-resolution image ::
>>> jp2file = glymur.data.nemo() # just a path to a JPEG2000 file
>>> jp2 = glymur.Jp2k(jp2file)
>>> fullres = jp2[:]
>>> print(fullres.shape)
>>> fullres.shape
(1456, 2592, 3)
>>> thumbnail = jp2[::2, ::2]
>>> print(thumbnail.shape)
>>> thumbnail.shape
(728, 1296, 3)
The :py:meth:`read` method exposes many more options for other JPEG 2000
features such as quality layers.
... write images?
=================
So long as the image data can fit entirely into memory, array-style slicing may
also be used to write JPEG 2000 files.
It's pretty simple, just supply the image data as the 2nd argument to the Jp2k
constructor.
>>> import glymur, numpy as np
>>> jp2 = glymur.Jp2k('zeros.jp2', mode='wb')
>>> jp2[:] = np.zeros((640, 480), dtype=np.uint8)
>>> data = np.zeros((640, 480), dtype=np.uint8)
>>> jp2 = glymur.Jp2k('zeros.jp2', data=data)
The :py:meth:`write` method exposes many more options for other JPEG 2000
features. You should have OpenJPEG version 1.5 or more recent before writing
JPEG 2000 images.
You should have OpenJPEG version 1.5 or more recent before writing JPEG 2000 images.
... display metadata?
=====================
@ -354,15 +349,14 @@ image isn't square. ::
>>> import numpy as np
>>> import glymur
>>> from glymur import Jp2k
>>> rgb = Jp2k(glymur.data.goodstuff()).read()
>>> rgb = Jp2k(glymur.data.goodstuff())[:]
>>> lx, ly = rgb.shape[0:2]
>>> X, Y = np.ogrid[0:lx, 0:ly]
>>> mask = ly**2*(X - lx / 2) ** 2 + lx**2*(Y - ly / 2) ** 2 > (lx * ly / 2)**2
>>> alpha = 255 * np.ones((lx, ly, 1), dtype=np.uint8)
>>> alpha[mask] = 0
>>> rgba = np.concatenate((rgb, alpha), axis=2)
>>> jp2 = Jp2k('tmp.jp2', 'wb')
>>> jp2[:] = rgba
>>> jp2 = Jp2k('tmp.jp2', data=rgba)
Next we need to specify what types of channels we have.
The first three channels are color channels, but we identify the fourth as
@ -465,8 +459,7 @@ http://photojournal.jpl.nasa.gov/tiff/PIA17145.tif info JPEG 2000::
>>> import skimage.io
>>> image = skimage.io.imread('PIA17145.tif')
>>> from glymur import Jp2k
>>> jp2 = Jp2k('PIA17145.jp2', 'wb')
>>> jp2[:] = image
>>> jp2 = Jp2k('PIA17145.jp2', data=image)
Next you can extract the XMP metadata.

View file

@ -1,12 +1,3 @@
-------------------------------------
Platforms Tested (0.7.0 release only)
-------------------------------------
* Linux Mint 17 / Python 3.4.0 and 2.7.6 / OpenJPEG 2.1.0 and 1.3.0
* MacOS 10.6.8 / MacPorts Python 3.4.1, 3.3.5,and 2.7.8 / OpenJPEG 2.1.0
* CentOS 6.5 / Anaconda Python 3.4.1 / OpenJPEG 1.3.0
* Fedora 20 i386 / Python 2.7.5 and 3.3.2 / OpenJPEG 1.5.1
* Windows 7 32bit / Anaconda Python 2.7.6 and 3.4.1 / OpenJPEG 2.1.0
------------
Known Issues
------------

View file

@ -2,10 +2,26 @@
Changes in glymur 0.7
=====================
Changes in 0.7.3
=================
* added read support back for metadata only when the OpenJPEG library is
not installed
Changes in 0.7.2
=================
* added ellipsis support in array-style slicing
Changes in 0.7.1
=================
* fixed release notes regarding Python 3.4
Changes in 0.7.0
=================
* implemented :py:meth:`__getitem__`, :py:meth:`__setitem__` support
* added back windows support
* box_id and longname are class attributes now instead of instance
attributes (see issue 248)
attributes

View file

@ -0,0 +1,10 @@
=====================
Changes in glymur 0.8
=====================
Changes in 0.8.0
=================
* Simplified writing images by moving data and options into the
constructor. This is backwards-incompatible with 0.7.x.
* Deprecated :py:meth:`read` method in favor of array-style slicing.

View file

@ -8,6 +8,7 @@ These document the changes between minor (or major) versions of glymur.
.. toctree::
0.5
0.6
0.8
0.7
0.6
0.5

View file

@ -37,16 +37,6 @@ from .jp2box import (
)
from .lib import openjpeg as opj, openjp2 as opj2, c as libc
JP2_IDS = ['colr', 'cdef', 'cmap', 'jp2c', 'ftyp', 'ihdr', 'jp2h', 'jP ',
'pclr', 'res ', 'resc', 'resd', 'xml ', 'ulst', 'uinf', 'url ',
'uuid']
JPX_IDS = ['asoc', 'nlst']
_COLORSPACE_MAP = {'rgb': opj2.CLRSPC_SRGB,
'gray': opj2.CLRSPC_GRAY,
'grey': opj2.CLRSPC_GRAY,
'ycc': opj2.CLRSPC_YCC}
class Jp2k(Jp2kBox):
"""JPEG 2000 file.
@ -54,34 +44,150 @@ class Jp2k(Jp2kBox):
----------
filename : str
The path to the JPEG 2000 file.
mode : str
The mode used to open the file.
box : sequence
List of top-level boxes in the file. Each box may in turn contain
its own list of boxes. Will be empty if the file consists only of a
raw codestream.
shape : tuple
Size of the image.
Properties
----------
ignore_pclr_cmap_cdef : bool
whether or not to ignore the pclr, cmap, or cdef boxes during any
color transformation, defaults to False.
layer : int
zero-based number of quality layer to decode
verbose : bool
whether or not to print informational messages produced by the
OpenJPEG library, defaults to false
Examples
--------
>>> import glymur
>>> jfile = glymur.data.nemo()
>>> jp2 = glymur.Jp2k(jfile)
>>> jp2.shape
(1456, 2592, 3)
>>> image = jp2[:]
>>> image.shape
(1456, 2592, 3)
Read a lower resolution thumbnail.
>>> thumbnail = jp2[::2, ::2]
>>> thumbnail.shape
(728, 1296, 3)
"""
def __init__(self, filename, mode='rb'):
def __init__(self, filename, data=None, shape=None, **kwargs):
"""
Only the filename parameter is required in order to read a JPEG 2000
file.
Parameters
----------
filename : str or file
The path to JPEG 2000 file.
mode : str, optional
The mode used to open the file.
the path to JPEG 2000 file
image_data : ndarray, optional
image data to be written
shape : tuple
size of image data, only required when image_data is not provided
cbsize : tuple, optional
code block size (DY, DX)
cinema2k : int, optional
frames per second, either 24 or 48
cinema4k : bool, optional
set to True to specify Cinema4K mode, defaults to false
colorspace : str, optional
either 'rgb' or 'gray'
cratios : iterable
compression ratios for successive layers
eph : bool, optional
if true, write SOP marker after each header packet
grid_offset : tuple, optional
offset (DY, DX) of the origin of the image in the reference grid
irreversible : bool, optional
if true, use the irreversible DWT 9-7 transform
mct : bool, optional
specifies usage of the multi component transform, if not
specified, defaults to True if the colorspace is RGB
modesw : int, optional
mode switch
1 = BYPASS(LAZY)
2 = RESET
4 = RESTART(TERMALL)
8 = VSC
16 = ERTERM(SEGTERM)
32 = SEGMARK(SEGSYM)
numres : int, optional
number of resolutions
prog : str, optional
progression order, one of "LRCP" "RLCP", "RPCL", "PCRL", "CPRL"
psnr : iterable, optional
different PSNR for successive layers
psizes : list, optional
list of precinct sizes, each precinct size tuple is defined in
(height x width)
sop : bool, optional
if true, write SOP marker before each packet
subsam : tuple, optional
subsampling factors (dy, dx)
tilesize : tuple, optional
numeric tuple specifying tile size in terms of (numrows, numcols),
not (X, Y)
verbose : bool, optional
print informational messages produced by the OpenJPEG library
"""
Jp2kBox.__init__(self)
self.filename = filename
self.mode = mode
self.box = []
self._codec_format = None
self._colorspace = None
self._shape = None
self._layer = 0
if data is not None:
self._shape = data.shape
else:
self._shape = shape
self._ignore_pclr_cmap_cdef = False
self._verbose = False
# Parse the file for JP2/JPX contents only if we are reading it.
if mode == 'rb':
if data is None and shape is None:
self.parse()
elif data is not None:
self._write(data, **kwargs)
@property
def ignore_pclr_cmap_cdef(self):
return self._ignore_pclr_cmap_cdef
@ignore_pclr_cmap_cdef.setter
def ignore_pclr_cmap_cdef(self, ignore_pclr_cmap_cdef):
self._ignore_pclr_cmap_cdef = ignore_pclr_cmap_cdef
@property
def layer(self):
return self._layer
@layer.setter
def layer(self, layer):
if version.openjpeg_version_tuple[0] < 2:
msg = "Layer property not supported unless the version of OpenJPEG "
msg += "is 2.0 or higher."
raise RuntimeError(msg)
self._layer = layer
@property
def verbose(self):
return self._verbose
@verbose.setter
def verbose(self, verbose):
self._verbose = verbose
@property
def shape(self):
@ -371,79 +477,17 @@ class Jp2k(Jp2kBox):
self._cparams = cparams
def write(self, img_array, verbose=False, **kwargs):
def _write(self, img_array, verbose=False, **kwargs):
"""Write image data to a JP2/JPX/J2k file. Intended usage of the
various parameters follows that of OpenJPEG's opj_compress utility.
This method can only be used to create JPEG 2000 images that can fit
in memory.
Parameters
----------
img_array : ndarray
Image data to be written to file.
cbsize : tuple, optional
Code block size (DY, DX).
cinema2k : int, optional
frames per second, either 24 or 48
cinema4k : bool, optional
Set to True to specify Cinema4K mode, defaults to false.
colorspace : str, optional
Either 'rgb' or 'gray'.
cratios : iterable
Compression ratios for successive layers.
eph : bool, optional
If true, write SOP marker after each header packet.
grid_offset : tuple, optional
Offset (DY, DX) of the origin of the image in the reference grid.
irreversible : bool, optional
If true, use the irreversible DWT 9-7 transform.
mct : bool, optional
Specifies usage of the multi component transform. If not
specified, defaults to True if the colorspace is RGB.
modesw : int, optional
Mode switch.
1 = BYPASS(LAZY)
2 = RESET
4 = RESTART(TERMALL)
8 = VSC
16 = ERTERM(SEGTERM)
32 = SEGMARK(SEGSYM)
numres : int, optional
Number of resolutions.
prog : str, optional
Progression order, one of "LRCP" "RLCP", "RPCL", "PCRL", "CPRL".
psnr : iterable, optional
Different PSNR for successive layers.
psizes : list, optional
List of precinct sizes. Each precinct size tuple is defined in
(height x width).
sop : bool, optional
If true, write SOP marker before each packet.
subsam : tuple, optional
Subsampling factors (dy, dx).
tilesize : tuple, optional
Numeric tuple specifying tile size in terms of (numrows, numcols),
not (X, Y).
verbose : bool, optional
Print informational messages produced by the OpenJPEG library.
Examples
--------
>>> import glymur
>>> jfile = glymur.data.nemo()
>>> jp2 = glymur.Jp2k(jfile)
>>> data = jp2.read(rlevel=1)
>>> from tempfile import NamedTemporaryFile
>>> tfile = NamedTemporaryFile(suffix='.jp2', delete=False)
>>> j = Jp2k(tfile.name, mode='wb')
>>> j.write(data.astype(np.uint8))
"""
if re.match("1.[0-4]", version.openjpeg_version) is not None:
raise RuntimeError("You must have at least version 1.5 of OpenJPEG "
"in order to write images.")
self._shape = img_array.shape
self._determine_colorspace(**kwargs)
self._populate_cparams(img_array, **kwargs)
@ -617,7 +661,12 @@ class Jp2k(Jp2kBox):
# Turn the colorspace from a string to the enumerated value that
# the library expects.
self._colorspace = _COLORSPACE_MAP[colorspace.lower()]
COLORSPACE_MAP = {'rgb': opj2.CLRSPC_SRGB,
'gray': opj2.CLRSPC_GRAY,
'grey': opj2.CLRSPC_GRAY,
'ycc': opj2.CLRSPC_YCC}
self._colorspace = COLORSPACE_MAP[colorspace.lower()]
def _write_openjp2(self, img_array, verbose=False):
@ -640,7 +689,11 @@ class Jp2k(Jp2kBox):
codec = opj2.create_compress(self._cparams.codec_fmt)
stack.callback(opj2.destroy_codec, codec)
info_handler = _INFO_CALLBACK if verbose else None
if self._verbose or verbose:
info_handler = _INFO_CALLBACK
else:
info_handler = None
opj2.set_info_handler(codec, info_handler)
opj2.set_warning_handler(codec, _WARNING_CALLBACK)
opj2.set_error_handler(codec, _ERROR_CALLBACK)
@ -844,7 +897,7 @@ class Jp2k(Jp2kBox):
# Case of jp2[:] = data, i.e. write the entire image.
#
# Should have a slice object where start = stop = step = None
self.write(data)
self._write(data)
else:
msg = "Partial write operations are currently not allowed."
raise TypeError(msg)
@ -863,16 +916,16 @@ class Jp2k(Jp2kBox):
# This retrieves a single row.
row = pargs
area = (row, 0, row + 1, numcols)
return self.read(area=area).squeeze()
return self._read(area=area).squeeze()
if pargs is Ellipsis:
# Case of jp2[...]
return self.read()
return self._read()
if isinstance(pargs, slice):
if pargs.start is None and pargs.stop is None and pargs.step is None:
# Case of jp2[:]
return self.read()
return self._read()
# Corner case of jp2[x] where x is a slice object with non-null
# members. Just augment it with an ellipsis and let the code
@ -949,7 +1002,7 @@ class Jp2k(Jp2kBox):
numrows if rows.stop is None else rows.stop,
numcols if cols.stop is None else cols.stop
)
data = self.read(area=area, rlevel=rlevel)
data = self._read(area=area, rlevel=rlevel)
if len(pargs) == 2:
return data
@ -957,6 +1010,25 @@ class Jp2k(Jp2kBox):
return data[:, :, bands]
def _read(self, **kwargs):
"""Read a JPEG 2000 image.
Returns
-------
img_array : ndarray
The image data.
Raises
------
IOError
If the image has differing subsample factors.
"""
if version.openjpeg_version_tuple[0] < 2:
img = self._read_openjpeg(**kwargs)
else:
img = self._read_openjp2(**kwargs)
return img
def read(self, **kwargs):
"""Read a JPEG 2000 image.
@ -973,9 +1045,6 @@ class Jp2k(Jp2kBox):
(first_row, first_col, last_row, last_col)
tile : int, optional
Number of tile to decode.
ignore_pclr_cmap_cdef : bool
Whether or not to ignore the pclr, cmap, or cdef boxes during any
color transformation. Defaults to False.
verbose : bool, optional
Print informational messages produced by the OpenJPEG library.
@ -988,22 +1057,10 @@ class Jp2k(Jp2kBox):
------
IOError
If the image has differing subsample factors.
Examples
--------
>>> import glymur
>>> jfile = glymur.data.nemo()
>>> jp = glymur.Jp2k(jfile)
>>> image = jp.read()
>>> image.shape
(1456, 2592, 3)
Read the lowest resolution thumbnail.
>>> thumbnail = jp.read(rlevel=-1)
>>> thumbnail.shape
(728, 1296, 3)
"""
if 'ignore_pclr_cmap_cdef' in kwargs:
self.ignore_pclr_cmap_cdef = kwargs['ignore_pclr_cmap_cdef']
warnings.warn("Use array-style slicing instead.", DeprecationWarning)
if version.openjpeg_version_tuple[0] < 2:
img = self._read_openjpeg(**kwargs)
else:
@ -1022,8 +1079,7 @@ class Jp2k(Jp2kBox):
msg += "the read_bands method instead."
raise RuntimeError(msg)
def _read_openjpeg(self, rlevel=0, ignore_pclr_cmap_cdef=False,
verbose=False, area=None):
def _read_openjpeg(self, rlevel=0, verbose=False, area=None):
"""Read a JPEG 2000 image using libopenjpeg.
Parameters
@ -1031,9 +1087,6 @@ class Jp2k(Jp2kBox):
rlevel : int, optional
Factor by which to rlevel output resolution. Use -1 to get the
lowest resolution thumbnail.
ignore_pclr_cmap_cdef : bool
Whether or not to ignore the pclr, cmap, or cdef boxes during any
color transformation. Defaults to False.
verbose : bool, optional
Print informational messages produced by the OpenJPEG library.
area : tuple, optional
@ -1052,7 +1105,7 @@ class Jp2k(Jp2kBox):
"""
self._subsampling_sanity_check()
self._populate_dparams(rlevel, ignore_pclr_cmap_cdef)
self._populate_dparams(rlevel)
with ExitStack() as stack:
try:
@ -1062,7 +1115,10 @@ class Jp2k(Jp2kBox):
event_mgr = opj.EventMgrType()
info_handler = ctypes.cast(_INFO_CALLBACK, ctypes.c_void_p)
event_mgr.info_handler = info_handler if verbose else None
if verbose or self._verbose:
event_mgr.info_handler = info_handler
else:
event_mgr.info_handler = None
event_mgr.warning_handler = ctypes.cast(_WARNING_CALLBACK,
ctypes.c_void_p)
event_mgr.error_handler = ctypes.cast(_ERROR_CALLBACK,
@ -1105,8 +1161,7 @@ class Jp2k(Jp2kBox):
return data
def _read_openjp2(self, rlevel=0, layer=0, area=None, tile=None,
verbose=False, ignore_pclr_cmap_cdef=False):
def _read_openjp2(self, rlevel=0, layer=None, area=None, tile=None, verbose=False):
"""Read a JPEG 2000 image using libopenjp2.
Parameters
@ -1134,10 +1189,12 @@ class Jp2k(Jp2kBox):
RuntimeError
If the image has differing subsample factors.
"""
if layer is not None:
self._layer = layer
self._subsampling_sanity_check()
self._populate_dparams(rlevel, ignore_pclr_cmap_cdef,
layer=layer, tile=tile, area=area)
self._populate_dparams(rlevel, tile=tile, area=area)
with ExitStack() as stack:
if re.match("2.1", version.openjpeg_version):
@ -1154,7 +1211,8 @@ class Jp2k(Jp2kBox):
opj2.set_error_handler(codec, _ERROR_CALLBACK)
opj2.set_warning_handler(codec, _WARNING_CALLBACK)
if verbose:
if self._verbose or verbose:
opj2.set_info_handler(codec, _INFO_CALLBACK)
else:
opj2.set_info_handler(codec, None)
@ -1181,14 +1239,11 @@ class Jp2k(Jp2kBox):
return img_array
def _populate_dparams(self, rlevel, ignore_pclr_cmap_cdef, tile=None,
layer=None, area=None):
def _populate_dparams(self, rlevel, tile=None, area=None):
"""Populate decompression structure with appropriate input parameters.
Parameters
----------
layer : int
Number of quality layer to decode.
rlevel : int
Factor by which to rlevel output resolution.
area : tuple
@ -1196,9 +1251,6 @@ class Jp2k(Jp2kBox):
(first_row, first_col, last_row, last_col)
tile : int
Number of tile to decode.
ignore_pclr_cmap_cdef : bool
Whether or not to ignore the pclr, cmap, or cdef boxes during any
color transformation. Defaults to False.
"""
if opj2.OPENJP2 is not None:
dparam = opj2.set_default_decoder_parameters()
@ -1211,10 +1263,13 @@ class Jp2k(Jp2kBox):
infile += b'0' * nelts
dparam.infile = infile
if self.ignore_pclr_cmap_cdef:
# Return raw codestream components.
dparam.flags |= 1
dparam.decod_format = self._codec_format
if layer is not None:
dparam.cp_layer = layer
dparam.cp_layer = self._layer
# Must check the specified rlevel against the maximum.
if rlevel != 0:
@ -1245,13 +1300,13 @@ class Jp2k(Jp2kBox):
dparam.tile_index = tile
dparam.nb_tile_to_decode = 1
if ignore_pclr_cmap_cdef is True:
if self.ignore_pclr_cmap_cdef:
# Return raw codestream components.
dparam.flags |= 1
self._dparams = dparam
def read_bands(self, rlevel=0, layer=0, area=None, tile=None,
def read_bands(self, rlevel=0, layer=None, area=None, tile=None,
verbose=False, ignore_pclr_cmap_cdef=False):
"""Read a JPEG 2000 image.
@ -1297,8 +1352,10 @@ class Jp2k(Jp2kBox):
"OpenJPEG installed before using this "
"functionality.")
self._populate_dparams(rlevel, ignore_pclr_cmap_cdef,
layer=layer, tile=tile, area=area)
self.ignore_pclr_cmap_cdef = ignore_pclr_cmap_cdef
if layer is not None:
self._layer = layer
self._populate_dparams(rlevel, tile=tile, area=area)
with ExitStack() as stack:
if re.match("2.1", version.openjpeg_version):
@ -1710,6 +1767,8 @@ def _validate_singletons(boxes):
if 'dtbl' in multiples:
raise IOError('There can only be one dtbl box in a file.')
JPX_IDS = ['asoc', 'nlst']
def _validate_jpx_brand(boxes, brand):
"""
If there is a JPX box then the brand must be 'jpx '.

View file

@ -39,15 +39,28 @@ class TestCallbacks(unittest.TestCase):
"Missing openjp2 library.")
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
def test_info_callback_on_write(self):
def test_info_callback_on_write_backwards_compatibility(self):
"""Verify messages printed when writing an image in verbose mode."""
j = glymur.Jp2k(self.jp2file)
with self.assertWarns(UserWarning):
tiledata = j.read(tile=0)
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
j = glymur.Jp2k(tfile.name, 'wb')
with patch('sys.stdout', new=StringIO()) as fake_out:
j.write(tiledata, verbose=True)
j = glymur.Jp2k(tfile.name, data=tiledata, verbose=True)
actual = fake_out.getvalue().strip()
expected = '[INFO] tile number 1 / 1'
self.assertEqual(actual, expected)
@unittest.skipIf(glymur.version.openjpeg_version[0] != '2',
"Missing openjp2 library.")
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
def test_info_callback_on_write(self):
"""Verify messages printed when writing an image in verbose mode."""
j = glymur.Jp2k(self.jp2file)
tiledata = j[:]
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
with patch('sys.stdout', new=StringIO()) as fake_out:
jp2 = glymur.Jp2k(tfile.name, data=tiledata, verbose=True)
actual = fake_out.getvalue().strip()
expected = '[INFO] tile number 1 / 1'
self.assertEqual(actual, expected)
@ -57,15 +70,16 @@ class TestCallbacks(unittest.TestCase):
# Verify that we get the expected stdio output when our internal info
# callback handler is enabled.
j = glymur.Jp2k(self.j2kfile)
jp2 = glymur.Jp2k(self.j2kfile)
with patch('sys.stdout', new=StringIO()) as fake_out:
j.read(rlevel=1, verbose=True)
jp2.verbose = True
jp2[::2, ::2]
actual = fake_out.getvalue().strip()
if glymur.version.openjpeg_version[0] == '2':
lines = ['[INFO] Start to read j2k main header (0).',
'[INFO] Main header has been correctly decoded.',
'[INFO] No decoded area parameters, set the decoded area to the whole image',
'[INFO] Setting decoding area to 0,0,480,800',
'[INFO] Header of tile 0 / 0 has been read.',
'[INFO] Tile 1/1 has been decoded.',
'[INFO] Image data has been updated with tile 1.']

View file

@ -1,149 +0,0 @@
"""
Test suite for codestream parsing.
"""
# unittest doesn't work well with R0904.
# pylint: disable=R0904
import os
import struct
import sys
import tempfile
import unittest
from glymur import Jp2k
import glymur
from .fixtures import opj_data_file, OPJ_DATA_ROOT
class TestCodestream(unittest.TestCase):
"""Test suite for unusual codestream cases."""
def setUp(self):
self.jp2file = glymur.data.nemo()
def tearDown(self):
pass
def test_siz_segment_ssiz_unsigned(self):
"""ssiz attribute to be removed in future release"""
j = Jp2k(self.jp2file)
codestream = j.get_codestream()
# The ssiz attribute was simply a tuple of raw bytes.
# The first 7 bits are interpreted as the bitdepth, the MSB determines
# whether or not it is signed.
self.assertEqual(codestream.segment[1].ssiz, (7, 7, 7))
@unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
class TestCodestreamOpjData(unittest.TestCase):
"""Test suite for unusual codestream cases. Uses OPJ_DATA_ROOT"""
def setUp(self):
self.jp2file = glymur.data.nemo()
def tearDown(self):
pass
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
def test_reserved_marker_segment(self):
"""Reserved marker segments are ok."""
# Some marker segments were reserved in FCD15444-1. Since that
# standard is old, some of them may have come into use.
#
# Let's inject a reserved marker segment into a file that
# we know something about to make sure we can still parse it.
filename = os.path.join(OPJ_DATA_ROOT, 'input/conformance/p0_01.j2k')
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
with open(filename, 'rb') as ifile:
# Everything up until the first QCD marker.
read_buffer = ifile.read(45)
tfile.write(read_buffer)
# Write the new marker segment, 0xff6f = 65391
read_buffer = struct.pack('>HHB', int(65391), int(3), int(0))
tfile.write(read_buffer)
# Get the rest of the input file.
read_buffer = ifile.read()
tfile.write(read_buffer)
tfile.flush()
codestream = Jp2k(tfile.name).get_codestream()
self.assertEqual(codestream.segment[2].marker_id, '0xff6f')
self.assertEqual(codestream.segment[2].length, 3)
self.assertEqual(codestream.segment[2].data, b'\x00')
def test_psot_is_zero(self):
"""Psot=0 in SOT is perfectly legal. Issue #78."""
filename = os.path.join(OPJ_DATA_ROOT,
'input/nonregression/123.j2c')
j = Jp2k(filename)
codestream = j.get_codestream(header_only=False)
# The codestream is valid, so we should be able to get the entire
# codestream, so the last one is EOC.
self.assertEqual(codestream.segment[-1].marker_id, 'EOC')
def test_siz_segment_ssiz_signed(self):
"""ssiz attribute to be removed in future release"""
filename = os.path.join(OPJ_DATA_ROOT, 'input/conformance/p0_03.j2k')
j = Jp2k(filename)
codestream = j.get_codestream()
# The ssiz attribute was simply a tuple of raw bytes.
# The first 7 bits are interpreted as the bitdepth, the MSB determines
# whether or not it is signed.
self.assertEqual(codestream.segment[1].ssiz, (131,))
class TestCodestreamRepr(unittest.TestCase):
def setUp(self):
self.jp2file = glymur.data.nemo()
def tearDown(self):
pass
def test_soc(self):
"""Test SOC segment repr"""
segment = glymur.codestream.SOCsegment()
newseg = eval(repr(segment))
self.assertEqual(newseg.marker_id, 'SOC')
def test_siz(self):
"""Test SIZ segment repr"""
kwargs = {'rsiz': 0,
'xysiz': (2592, 1456),
'xyosiz': (0, 0),
'xytsiz': (2592, 1456),
'xytosiz': (0, 0),
'Csiz': 3,
'bitdepth': (8, 8, 8),
'signed': (False, False, False),
'xyrsiz': ((1, 1, 1), (1, 1, 1))}
segment = glymur.codestream.SIZsegment(**kwargs)
newseg = eval(repr(segment))
self.assertEqual(newseg.marker_id, 'SIZ')
self.assertEqual(newseg.xsiz, 2592)
self.assertEqual(newseg.ysiz, 1456)
self.assertEqual(newseg.xosiz, 0)
self.assertEqual(newseg.yosiz, 0)
self.assertEqual(newseg.xtsiz, 2592)
self.assertEqual(newseg.ytsiz, 1456)
self.assertEqual(newseg.xtosiz, 0)
self.assertEqual(newseg.ytosiz, 0)
self.assertEqual(newseg.xrsiz, (1, 1, 1))
self.assertEqual(newseg.yrsiz, (1, 1, 1))
self.assertEqual(newseg.bitdepth, (8, 8, 8))
self.assertEqual(newseg.signed, (False, False, False))
if __name__ == "__main__":
unittest.main()

View file

@ -54,16 +54,17 @@ class TestDataEntryURL(unittest.TestCase):
def setUp(self):
self.jp2file = glymur.data.nemo()
@unittest.skipIf(re.match("1.5|2", glymur.version.openjpeg_version) is None,
"Must have openjpeg 1.5 or higher to run")
def test_wrap_greyscale(self):
"""A single component should be wrapped as GREYSCALE."""
j = Jp2k(self.jp2file)
data = j.read()
data = j[:]
red = data[:, :, 0]
# Write it back out as a raw codestream.
with tempfile.NamedTemporaryFile(suffix=".j2k") as tfile1:
j2k = glymur.Jp2k(tfile1.name, 'wb')
j2k.write(data[:, :, 0])
j2k = glymur.Jp2k(tfile1.name, data=red)
# Ok, now rewrap it as JP2. The colorspace should be GREYSCALE.
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile2:
@ -124,24 +125,21 @@ class TestChannelDefinition(unittest.TestCase):
def setUpClass(cls):
"""Need a one_plane plane image for greyscale testing."""
j2k = Jp2k(glymur.data.goodstuff())
data = j2k.read()
data = j2k[:]
# Write the first component back out to file.
with tempfile.NamedTemporaryFile(suffix=".j2k", delete=False) as tfile:
grey_j2k = Jp2k(tfile.name, 'wb')
grey_j2k.write(data[:, :, 0])
grey_j2k = Jp2k(tfile.name, data=data[:, :, 0])
cls.one_plane = tfile.name
# Write the first two components back out to file.
with tempfile.NamedTemporaryFile(suffix=".j2k", delete=False) as tfile:
grey_j2k = Jp2k(tfile.name, 'wb')
grey_j2k.write(data[:, :, 0:1])
grey_j2k = Jp2k(tfile.name, data=data[:, :, 0:1])
cls.two_planes = tfile.name
# Write four components back out to file.
with tempfile.NamedTemporaryFile(suffix=".j2k", delete=False) as tfile:
rgba_jp2 = Jp2k(tfile.name, 'wb')
shape = (data.shape[0], data.shape[1], 1)
alpha = np.zeros((shape), dtype=data.dtype)
data4 = np.concatenate((data, alpha), axis=2)
rgba_jp2.write(data4)
rgba_jp2 = Jp2k(tfile.name, data=data4)
cls.four_planes = tfile.name
@classmethod

File diff suppressed because it is too large Load diff

View file

@ -30,6 +30,7 @@ suite.
import re
import sys
import unittest
import warnings
import numpy as np
@ -57,7 +58,7 @@ class TestSuite(unittest.TestCase):
def test_ETS_C1P0_p0_01_j2k(self):
jfile = opj_data_file('input/conformance/p0_01.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
jpdata = jp2k[:]
pgxfile = opj_data_file('baseline/conformance/c1p0_01_0.pgx')
pgxdata = read_pgx(pgxfile)
@ -67,7 +68,7 @@ class TestSuite(unittest.TestCase):
def test_ETS_C1P0_p0_03_j2k(self):
jfile = opj_data_file('input/conformance/p0_03.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
jpdata = jp2k[:]
pgxfile = opj_data_file('baseline/conformance/c1p0_03_0.pgx')
pgxdata = read_pgx(pgxfile)
@ -77,7 +78,7 @@ class TestSuite(unittest.TestCase):
def test_ETS_C1P0_p0_04_j2k(self):
jfile = opj_data_file('input/conformance/p0_04.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
jpdata = jp2k[:]
pgxfile = opj_data_file('baseline/conformance/c1p0_04_0.pgx')
pgxdata = read_pgx(pgxfile)
@ -97,7 +98,7 @@ class TestSuite(unittest.TestCase):
def test_ETS_C1P0_p0_08_j2k(self):
jfile = opj_data_file('input/conformance/p0_08.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=1)
jpdata = jp2k[::2, ::2]
pgxfile = opj_data_file('baseline/conformance/c1p0_08_0.pgx')
pgxdata = read_pgx(pgxfile)
@ -114,7 +115,7 @@ class TestSuite(unittest.TestCase):
def test_ETS_C1P0_p0_09_j2k(self):
jfile = opj_data_file('input/conformance/p0_09.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
jpdata = jp2k[:]
pgxfile = opj_data_file('baseline/conformance/c1p0_09_0.pgx')
pgxdata = read_pgx(pgxfile)
@ -123,7 +124,7 @@ class TestSuite(unittest.TestCase):
def test_ETS_C1P0_p0_11_j2k(self):
jfile = opj_data_file('input/conformance/p0_11.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
jpdata = jp2k[:]
pgxfile = opj_data_file('baseline/conformance/c1p0_11_0.pgx')
pgxdata = read_pgx(pgxfile)
@ -132,7 +133,7 @@ class TestSuite(unittest.TestCase):
def test_ETS_C1P0_p0_14_j2k(self):
jfile = opj_data_file('input/conformance/p0_14.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
jpdata = jp2k[:]
pgxfile = opj_data_file('baseline/conformance/c1p0_14_0.pgx')
pgxdata = read_pgx(pgxfile)
@ -149,7 +150,7 @@ class TestSuite(unittest.TestCase):
def test_ETS_C1P0_p0_15_j2k(self):
jfile = opj_data_file('input/conformance/p0_15.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
jpdata = jp2k[:]
pgxfile = opj_data_file('baseline/conformance/c1p0_15_0.pgx')
pgxdata = read_pgx(pgxfile)
@ -158,7 +159,7 @@ class TestSuite(unittest.TestCase):
def test_ETS_C1P0_p0_16_j2k(self):
jfile = opj_data_file('input/conformance/p0_16.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
jpdata = jp2k[:]
pgxfile = opj_data_file('baseline/conformance/c1p0_16_0.pgx')
pgxdata = read_pgx(pgxfile)
@ -167,7 +168,7 @@ class TestSuite(unittest.TestCase):
def test_ETS_C1P1_p1_01_j2k(self):
jfile = opj_data_file('input/conformance/p1_01.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
jpdata = jp2k[:]
pgxfile = opj_data_file('baseline/conformance/c1p1_01_0.pgx')
pgxdata = read_pgx(pgxfile)
@ -176,7 +177,7 @@ class TestSuite(unittest.TestCase):
def test_ETS_C1P1_p1_02_j2k(self):
jfile = opj_data_file('input/conformance/p1_02.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
jpdata = jp2k[:]
pgxfile = opj_data_file('baseline/conformance/c1p1_02_0.pgx')
pgxdata = read_pgx(pgxfile)
@ -196,7 +197,7 @@ class TestSuite(unittest.TestCase):
def test_ETS_C1P1_p1_04_j2k(self):
jfile = opj_data_file('input/conformance/p1_04.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read()
jpdata = jp2k[:]
pgxfile = opj_data_file('baseline/conformance/c1p1_04_0.pgx')
pgxdata = read_pgx(pgxfile)
@ -206,95 +207,95 @@ class TestSuite(unittest.TestCase):
def test_NR_DEC_Bretagne2_j2k_1_decode(self):
jfile = opj_data_file('input/nonregression/Bretagne2.j2k')
jp2 = Jp2k(jfile)
jp2.read()
jp2[:]
self.assertTrue(True)
def test_NR_DEC__00042_j2k_2_decode(self):
jfile = opj_data_file('input/nonregression/_00042.j2k')
jp2 = Jp2k(jfile)
jp2.read()
jp2[:]
self.assertTrue(True)
def test_NR_DEC_buxI_j2k_9_decode(self):
jfile = opj_data_file('input/nonregression/buxI.j2k')
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
def test_NR_DEC_buxR_j2k_10_decode(self):
jfile = opj_data_file('input/nonregression/buxR.j2k')
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
def test_NR_DEC_Cannotreaddatawithnosizeknown_j2k_11_decode(self):
relpath = 'input/nonregression/Cannotreaddatawithnosizeknown.j2k'
jfile = opj_data_file(relpath)
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
def test_NR_DEC_cthead1_j2k_12_decode(self):
jfile = opj_data_file('input/nonregression/cthead1.j2k')
Jp2k(jfile).read()
Jp2k(jfile)[:]
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 = opj_data_file(relpath)
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
def test_NR_DEC_j2k32_j2k_15_decode(self):
jfile = opj_data_file('input/nonregression/j2k32.j2k')
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
def test_NR_DEC_MarkerIsNotCompliant_j2k_17_decode(self):
jfile = opj_data_file('input/nonregression/MarkerIsNotCompliant.j2k')
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
def test_NR_DEC_Marrin_jp2_18_decode(self):
jfile = opj_data_file('input/nonregression/Marrin.jp2')
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
def test_NR_DEC_movie_00000_j2k_20_decode(self):
jfile = opj_data_file('input/nonregression/movie_00000.j2k')
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
def test_NR_DEC_movie_00001_j2k_21_decode(self):
jfile = opj_data_file('input/nonregression/movie_00001.j2k')
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
def test_NR_DEC_movie_00002_j2k_22_decode(self):
jfile = opj_data_file('input/nonregression/movie_00002.j2k')
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
def test_NR_DEC_orb_blue_lin_j2k_j2k_23_decode(self):
jfile = opj_data_file('input/nonregression/orb-blue10-lin-j2k.j2k')
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
def test_NR_DEC_orb_blue_win_j2k_j2k_24_decode(self):
jfile = opj_data_file('input/nonregression/orb-blue10-win-j2k.j2k')
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
def test_NR_DEC_relax_jp2_27_decode(self):
jfile = opj_data_file('input/nonregression/relax.jp2')
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
def test_NR_DEC_test_lossless_j2k_28_decode(self):
jfile = opj_data_file('input/nonregression/test_lossless.j2k')
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
def test_NR_DEC_pacs_ge_j2k_30_decode(self):
jfile = opj_data_file('input/nonregression/pacs.ge.j2k')
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
@ -317,14 +318,14 @@ class TestSuiteWarns(MetadataBase):
with self.assertWarns(UserWarning):
# Bad compatibility list item.
jp2k = Jp2k(jfile)
jpdata = jp2k.read()
jpdata = jp2k[:]
self.assertEqual(jpdata.shape, (512, 768, 3))
def test_ETS_JP2_file2(self):
jfile = opj_data_file('input/conformance/file2.jp2')
with self.assertWarns(UserWarning):
jp2k = Jp2k(jfile)
jpdata = jp2k.read()
jpdata = jp2k[:]
self.assertEqual(jpdata.shape, (640, 480, 3))
@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] < 2,
@ -342,7 +343,7 @@ class TestSuiteWarns(MetadataBase):
jfile = opj_data_file('input/conformance/file4.jp2')
with self.assertWarns(UserWarning):
jp2k = Jp2k(jfile)
jpdata = jp2k.read()
jpdata = jp2k[:]
self.assertEqual(jpdata.shape, (512, 768))
def test_ETS_JP2_file5(self):
@ -351,35 +352,35 @@ class TestSuiteWarns(MetadataBase):
# There's a warning for an unknown compatibility entry.
# Ignore it here.
jp2k = Jp2k(jfile)
jpdata = jp2k.read()
jpdata = jp2k[:]
self.assertEqual(jpdata.shape, (512, 768, 3))
def test_ETS_JP2_file6(self):
jfile = opj_data_file('input/conformance/file6.jp2')
with self.assertWarns(UserWarning):
jp2k = Jp2k(jfile)
jpdata = jp2k.read()
jpdata = jp2k[:]
self.assertEqual(jpdata.shape, (512, 768))
def test_ETS_JP2_file7(self):
jfile = opj_data_file('input/conformance/file7.jp2')
with self.assertWarns(UserWarning):
jp2k = Jp2k(jfile)
jpdata = jp2k.read()
jpdata = jp2k[:]
self.assertEqual(jpdata.shape, (640, 480, 3))
def test_ETS_JP2_file8(self):
jfile = opj_data_file('input/conformance/file8.jp2')
with self.assertWarns(UserWarning):
jp2k = Jp2k(jfile)
jpdata = jp2k.read()
jpdata = jp2k[:]
self.assertEqual(jpdata.shape, (400, 700))
def test_ETS_JP2_file9(self):
jfile = opj_data_file('input/conformance/file9.jp2')
with self.assertWarns(UserWarning):
jp2k = Jp2k(jfile)
jpdata = jp2k.read()
jpdata = jp2k[:]
self.assertEqual(jpdata.shape, (512, 768, 3))
def test_NR_broken_jp2_dump(self):
@ -469,13 +470,13 @@ class TestSuiteWarns(MetadataBase):
jfile = opj_data_file('input/nonregression/orb-blue10-lin-jp2.jp2')
with self.assertWarns(UserWarning):
# This file has an invalid ICC profile
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
def test_NR_DEC_orb_blue_win_jp2_26_decode(self):
jfile = opj_data_file('input/nonregression/orb-blue10-win-jp2.jp2')
with self.assertWarns(UserWarning):
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
@ -590,7 +591,7 @@ class TestSuite2point0(unittest.TestCase):
def test_ETS_C1P0_p0_10_j2k(self):
jfile = opj_data_file('input/conformance/p0_10.j2k')
jp2k = Jp2k(jfile)
jpdata = jp2k.read(rlevel=0)
jpdata = jp2k[:]
pgxfile = opj_data_file('baseline/conformance/c1p0_10_0.pgx')
pgxdata = read_pgx(pgxfile)
@ -611,7 +612,7 @@ class TestSuite2point0(unittest.TestCase):
with self.assertRaises(IOError):
with self.assertWarns(UserWarning):
# Invalid marker ID.
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
@ -620,7 +621,7 @@ class TestSuite2point0(unittest.TestCase):
with self.assertRaises(IOError):
with self.assertWarns(UserWarning):
# invalid number of subbands, bad marker ID
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
@ -632,11 +633,343 @@ class TestSuite2point0(unittest.TestCase):
if glymur.version.openjpeg_version_tuple[0] < 2:
with self.assertWarns(UserWarning):
# Incorrect warning issued about tile parts.
Jp2k(jfile).read()
Jp2k(jfile)[:]
else:
Jp2k(jfile).read()
Jp2k(jfile)[:]
self.assertTrue(True)
if __name__ == "__main__":
unittest.main()
@unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
@unittest.skipIf(re.match(r'''(1|2.0.0)''',
glymur.version.openjpeg_version) is not None,
"Only supported in 2.0.1 or higher")
class TestSuite2point1(unittest.TestCase):
"""Runs tests introduced in version 2.0+ or that pass only in 2.0+"""
def setUp(self):
pass
def tearDown(self):
pass
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
def test_NR_DEC_text_GBR_jp2_29_decode(self):
jfile = opj_data_file('input/nonregression/text_GBR.jp2')
with self.assertWarns(UserWarning):
# brand is 'jp2 ', but has any icc profile.
jp2 = Jp2k(jfile)
jp2[:]
self.assertTrue(True)
def test_NR_DEC_kodak_2layers_lrcp_j2c_31_decode(self):
jfile = opj_data_file('input/nonregression/kodak_2layers_lrcp.j2c')
Jp2k(jfile)[:]
self.assertTrue(True)
def test_NR_DEC_kodak_2layers_lrcp_j2c_32_decode(self):
jfile = opj_data_file('input/nonregression/kodak_2layers_lrcp.j2c')
Jp2k(jfile)[::4, ::4]
self.assertTrue(True)
def test_NR_DEC_issue104_jpxstream_jp2_33_decode(self):
jfile = opj_data_file('input/nonregression/issue104_jpxstream.jp2')
Jp2k(jfile)[:]
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)[:]
self.assertTrue(True)
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
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 self.assertWarns(UserWarning):
# Invalid number of resolutions.
j = Jp2k(jfile)
with self.assertRaises(IOError):
j[:]
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
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 self.assertWarns(UserWarning):
# Invalid number of tiles.
j = Jp2k(jfile)
with self.assertRaises(IOError):
j[:]
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
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 self.assertWarns(UserWarning):
# Invalid subsampling value
with self.assertRaises(IOError):
Jp2k(jfile)[:]
def test_NR_DEC_file_409752_jp2_40_decode(self):
jfile = opj_data_file('input/nonregression/file409752.jp2')
with self.assertRaises(RuntimeError):
Jp2k(jfile)[:]
def test_NR_DEC_issue206_image_000_jp2_42_decode(self):
jfile = opj_data_file('input/nonregression/issue206_image-000.jp2')
Jp2k(jfile)[:]
self.assertTrue(True)
def test_NR_DEC_p1_04_j2k_57_decode(self):
jfile = opj_data_file('input/conformance/p1_04.j2k')
jp2k = Jp2k(jfile)
tdata = jp2k[896:1024, 896:1024] # last tile
odata = jp2k[:]
np.testing.assert_array_equal(tdata, odata[896:1024, 896:1024])
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
def test_NR_DEC_p1_04_j2k_57_decode_0p7_backwards_compatibility(self):
"""
0.7.x usage deprecated
"""
jfile = opj_data_file('input/conformance/p1_04.j2k')
jp2k = Jp2k(jfile)
if sys.hexversion < 0x03000000:
with warnings.catch_warnings():
# Suppress a warning due to deprecated syntax
warnings.simplefilter("ignore")
tdata = jp2k.read(tile=63) # last tile
else:
with self.assertWarns(DeprecationWarning):
tdata = jp2k.read(tile=63) # last tile
odata = jp2k[:]
np.testing.assert_array_equal(tdata, odata[896:1024, 896:1024])
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
def test_NR_DEC_p1_04_j2k_58_decode_0p7_backwards_compatibility(self):
"""
0.7.x usage deprecated
"""
jfile = opj_data_file('input/conformance/p1_04.j2k')
jp2k = Jp2k(jfile)
if sys.hexversion < 0x03000000:
with warnings.catch_warnings():
# Suppress a warning due to deprecated syntax
tdata = jp2k.read(tile=63, rlevel=2) # last tile
else:
with self.assertWarns(DeprecationWarning):
tdata = jp2k.read(tile=63, rlevel=2) # last tile
odata = jp2k[::4, ::4]
np.testing.assert_array_equal(tdata, odata[224:256, 224:256])
def test_NR_DEC_p1_04_j2k_58_decode(self):
jfile = opj_data_file('input/conformance/p1_04.j2k')
jp2k = Jp2k(jfile)
tdata = jp2k[896:1024:4, 896:1024:4] # last tile
odata = jp2k[::4, ::4]
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[128:256, 512:640] # 2nd row, 5th column
odata = jp2k[:]
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[128:256:2, 512:640:2] # 2nd row, 5th column
odata = jp2k[::2, ::2]
np.testing.assert_array_equal(tdata, odata[64:128, 256:320])
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
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 self.assertWarns(UserWarning):
# Invalid component number.
j = Jp2k(jfile)
with self.assertRaises(IOError):
j[:]
@unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
@unittest.skipIf(re.match(r'''(1|2.0.0)''',
glymur.version.openjpeg_version) is not None,
"Only supported in 2.0.1 or higher")
class TestReadArea(unittest.TestCase):
"""
Runs tests introduced in version 2.0+ or that pass only in 2.0+
Specifically for read method with area parameter.
"""
@classmethod
def setUpClass(self):
jfile = opj_data_file('input/conformance/p1_04.j2k')
self.j2k = Jp2k(jfile)
self.j2k_data = self.j2k[:]
self.j2k_half_data = self.j2k[::2, ::2]
self.j2k_quarter_data = self.j2k[::4, ::4]
jfile = opj_data_file('input/conformance/p1_06.j2k')
self.j2k_p1_06 = Jp2k(jfile)
def test_NR_DEC_p1_04_j2k_43_decode(self):
actual = self.j2k[:1024, :1024]
expected = self.j2k_data
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_44_decode(self):
actual = self.j2k[640:768, 512:640]
expected = self.j2k_data[640:768, 512:640]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_45_decode(self):
actual = self.j2k[896:1024, 896:1024]
expected = self.j2k_data[896:1024, 896:1024]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_46_decode(self):
actual = self.j2k[500:800, 100:300]
expected = self.j2k_data[500:800, 100:300]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_47_decode(self):
actual = self.j2k[520:600, 260:360]
expected = self.j2k_data[520:600, 260:360]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_48_decode(self):
actual = self.j2k[520:660, 260:360]
expected = self.j2k_data[520:660, 260:360]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_49_decode(self):
actual = self.j2k[520:600, 360:400]
expected = self.j2k_data[520:600, 360:400]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_50_decode(self):
actual = self.j2k[:1024:4, :1024:4]
expected = self.j2k_quarter_data
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_51_decode(self):
actual = self.j2k[640:768:4, 512:640:4]
expected = self.j2k_quarter_data[160:192, 128:160]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_52_decode(self):
actual = self.j2k[896:1024:4, 896:1024:4]
expected = self.j2k_quarter_data[224:352, 224:352]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_53_decode(self):
actual = self.j2k[500:800:4, 100:300:4]
expected = self.j2k_quarter_data[125:200, 25:75]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_54_decode(self):
actual = self.j2k[520:600:4, 260:360:4]
expected = self.j2k_quarter_data[130:150, 65:90]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_55_decode(self):
actual = self.j2k[520:660:4, 260:360:4]
expected = self.j2k_quarter_data[130:165, 65:90]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_56_decode(self):
actual = self.j2k[520:600:4, 360:400:4]
expected = self.j2k_quarter_data[130:150, 90:100]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_06_j2k_70_decode(self):
actual = self.j2k_p1_06[9:12:2, 9:12:2]
self.assertEqual(actual.shape, (1, 1, 3))
def test_NR_DEC_p1_06_j2k_71_decode(self):
actual = self.j2k_p1_06[10:12:2, 4:10:2]
self.assertEqual(actual.shape, (1, 3, 3))
def test_NR_DEC_p1_06_j2k_72_decode(self):
ssdata = self.j2k_p1_06[3:9:2, 3:9:2]
self.assertEqual(ssdata.shape, (3, 3, 3))
def test_NR_DEC_p1_06_j2k_73_decode(self):
ssdata = self.j2k_p1_06[4:7:2, 4:7:2]
self.assertEqual(ssdata.shape, (2, 2, 3))
def test_NR_DEC_p1_06_j2k_74_decode(self):
ssdata = self.j2k_p1_06[4:5:2, 4:5:2]
self.assertEqual(ssdata.shape, (1, 1, 3))
def test_NR_DEC_p1_06_j2k_75_decode(self):
# Image size would be 0 x 0.
with self.assertRaises((IOError, OSError)):
self.j2k_p1_06[9:12:4, 9:12:4]
def test_NR_DEC_p0_04_j2k_85_decode(self):
actual = self.j2k[:256, :256]
expected = self.j2k_data[:256, :256]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_86_decode(self):
actual = self.j2k[:128, 128:256]
expected = self.j2k_data[:128, 128:256]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_87_decode(self):
actual = self.j2k[10:200, 50:120]
expected = self.j2k_data[10:200, 50:120]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_88_decode(self):
actual = self.j2k[150:210, 10:190]
expected = self.j2k_data[150:210, 10:190]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_89_decode(self):
actual = self.j2k[80:150, 100:200]
expected = self.j2k_data[80:150, 100:200]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_90_decode(self):
actual = self.j2k[20:50, 150:200]
expected = self.j2k_data[20:50, 150:200]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_91_decode(self):
actual = self.j2k[:256:4, :256:4]
expected = self.j2k_quarter_data[0:64, 0:64]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_92_decode(self):
actual = self.j2k[:128:4, 128:256:4]
expected = self.j2k_quarter_data[:32, 32:64]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_93_decode(self):
actual = self.j2k[10:200:4, 50:120:4]
expected = self.j2k_quarter_data[3:50, 13:30]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_94_decode(self):
actual = self.j2k[150:210:4, 10:190:4]
expected = self.j2k_quarter_data[38:53, 3:48]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_95_decode(self):
actual = self.j2k[80:150:4, 100:200:4]
expected = self.j2k_quarter_data[20:38, 25:50]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_96_decode(self):
actual = self.j2k[20:50:4, 150:200:4]
expected = self.j2k_quarter_data[5:13, 38:50]
np.testing.assert_array_equal(actual, expected)

View file

@ -1,342 +0,0 @@
"""
The tests defined here roughly correspond to what is in the OpenJPEG test
suite.
"""
# Some test names correspond with openjpeg tests. Long names are ok in this
# case.
# pylint: disable=C0103
# All of these tests correspond to tests in openjpeg, so no docstring is really
# needed.
# pylint: disable=C0111
# This module is very long, cannot be helped.
# pylint: disable=C0302
# unittest fools pylint with "too many public methods"
# pylint: disable=R0904
# Some tests use numpy test infrastructure, which means the tests never
# reference "self", so pylint claims it should be a function. No, no, no.
# pylint: disable=R0201
# Many tests are pretty long and that can't be helped.
# pylint: disable=R0915
# asserWarns introduced in python 3.2 (python2.7/pylint issue)
# pylint: disable=E1101
import re
import sys
import unittest
import numpy as np
from glymur import Jp2k
import glymur
from .fixtures import OPJ_DATA_ROOT
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
from .fixtures import mse, peak_tolerance, read_pgx, opj_data_file
@unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
@unittest.skipIf(re.match(r'''(1|2.0.0)''',
glymur.version.openjpeg_version) is not None,
"Only supported in 2.0.1 or higher")
class TestSuite2point1(unittest.TestCase):
"""Runs tests introduced in version 2.0+ or that pass only in 2.0+"""
def setUp(self):
pass
def tearDown(self):
pass
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
def test_NR_DEC_text_GBR_jp2_29_decode(self):
jfile = opj_data_file('input/nonregression/text_GBR.jp2')
with self.assertWarns(UserWarning):
# brand is 'jp2 ', but has any icc profile.
jp2 = Jp2k(jfile)
jp2.read()
self.assertTrue(True)
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_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_mem_b2b86b74_2753_jp2_35_decode(self):
jfile = opj_data_file('input/nonregression/mem-b2b86b74-2753.jp2')
Jp2k(jfile).read()
self.assertTrue(True)
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
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 self.assertWarns(UserWarning):
# Invalid number of resolutions.
j = Jp2k(jfile)
with self.assertRaises(IOError):
j.read()
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
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 self.assertWarns(UserWarning):
# Invalid number of tiles.
j = Jp2k(jfile)
with self.assertRaises(IOError):
j.read()
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
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 self.assertWarns(UserWarning):
# Invalid subsampling value
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):
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_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])
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
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 self.assertWarns(UserWarning):
# Invalid component number.
j = Jp2k(jfile)
with self.assertRaises(IOError):
j.read()
@unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
@unittest.skipIf(re.match(r'''(1|2.0.0)''',
glymur.version.openjpeg_version) is not None,
"Only supported in 2.0.1 or higher")
class TestReadArea(unittest.TestCase):
"""
Runs tests introduced in version 2.0+ or that pass only in 2.0+
Specifically for read method with area parameter.
"""
@classmethod
def setUpClass(self):
jfile = opj_data_file('input/conformance/p1_04.j2k')
self.j2k = Jp2k(jfile)
self.j2k_data = self.j2k.read()
self.j2k_half_data = self.j2k.read(rlevel=1)
self.j2k_quarter_data = self.j2k.read(rlevel=2)
jfile = opj_data_file('input/conformance/p1_06.j2k')
self.j2k_p1_06 = Jp2k(jfile)
def test_NR_DEC_p1_04_j2k_43_decode(self):
actual = self.j2k.read(area=(0, 0, 1024, 1024))
expected = self.j2k_data
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_44_decode(self):
actual = self.j2k.read(area=(640, 512, 768, 640))
expected = self.j2k_data[640:768, 512:640]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_45_decode(self):
actual = self.j2k.read(area=(896, 896, 1024, 1024))
expected = self.j2k_data[896:1024, 896:1024]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_46_decode(self):
actual = self.j2k.read(area=(500, 100, 800, 300))
expected = self.j2k_data[500:800, 100:300]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_47_decode(self):
actual = self.j2k.read(area=(520, 260, 600, 360))
expected = self.j2k_data[520:600, 260:360]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_48_decode(self):
actual = self.j2k.read(area=(520, 260, 660, 360))
expected = self.j2k_data[520:660, 260:360]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_49_decode(self):
actual = self.j2k.read(area=(520, 360, 600, 400))
expected = self.j2k_data[520:600, 360:400]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_50_decode(self):
actual = self.j2k.read(area=(0, 0, 1024, 1024), rlevel=2)
expected = self.j2k_quarter_data
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_51_decode(self):
actual = self.j2k.read(area=(640, 512, 768, 640), rlevel=2)
expected = self.j2k_quarter_data[160:192, 128:160]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_52_decode(self):
actual = self.j2k.read(area=(896, 896, 1024, 1024), rlevel=2)
expected = self.j2k_quarter_data[224:352, 224:352]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_53_decode(self):
actual = self.j2k.read(area=(500, 100, 800, 300), rlevel=2)
expected = self.j2k_quarter_data[125:200, 25:75]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_54_decode(self):
actual = self.j2k.read(area=(520, 260, 600, 360), rlevel=2)
expected = self.j2k_quarter_data[130:150, 65:90]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_55_decode(self):
actual = self.j2k.read(area=(520, 260, 660, 360), rlevel=2)
expected = self.j2k_quarter_data[130:165, 65:90]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_04_j2k_56_decode(self):
actual = self.j2k.read(area=(520, 360, 600, 400), rlevel=2)
expected = self.j2k_quarter_data[130:150, 90:100]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p1_06_j2k_70_decode(self):
actual = self.j2k_p1_06.read(area=(9, 9, 12, 12), rlevel=1)
self.assertEqual(actual.shape, (1, 1, 3))
def test_NR_DEC_p1_06_j2k_71_decode(self):
actual = self.j2k_p1_06.read(area=(10, 4, 12, 10), rlevel=1)
self.assertEqual(actual.shape, (1, 3, 3))
def test_NR_DEC_p1_06_j2k_72_decode(self):
ssdata = self.j2k_p1_06.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):
ssdata = self.j2k_p1_06.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):
ssdata = self.j2k_p1_06.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.
with self.assertRaises((IOError, OSError)):
self.j2k_p1_06.read(area=(9, 9, 12, 12), rlevel=2)
def test_NR_DEC_p0_04_j2k_85_decode(self):
actual = self.j2k.read(area=(0, 0, 256, 256))
expected = self.j2k_data[:256, :256]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_86_decode(self):
actual = self.j2k.read(area=(0, 128, 128, 256))
expected = self.j2k_data[:128, 128:256]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_87_decode(self):
actual = self.j2k.read(area=(10, 50, 200, 120))
expected = self.j2k_data[10:200, 50:120]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_88_decode(self):
actual = self.j2k.read(area=(150, 10, 210, 190))
expected = self.j2k_data[150:210, 10:190]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_89_decode(self):
actual = self.j2k.read(area=(80, 100, 150, 200))
expected = self.j2k_data[80:150, 100:200]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_90_decode(self):
actual = self.j2k.read(area=(20, 150, 50, 200))
expected = self.j2k_data[20:50, 150:200]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_91_decode(self):
actual = self.j2k.read(area=(0, 0, 256, 256), rlevel=2)
expected = self.j2k_quarter_data[0:64, 0:64]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_92_decode(self):
actual = self.j2k.read(area=(0, 128, 128, 256), rlevel=2)
expected = self.j2k_quarter_data[:32, 32:64]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_93_decode(self):
actual = self.j2k.read(area=(10, 50, 200, 120), rlevel=2)
expected = self.j2k_quarter_data[3:50, 13:30]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_94_decode(self):
actual = self.j2k.read(area=(150, 10, 210, 190), rlevel=2)
expected = self.j2k_quarter_data[38:53, 3:48]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_95_decode(self):
actual = self.j2k.read(area=(80, 100, 150, 200), rlevel=2)
expected = self.j2k_quarter_data[20:38, 25:50]
np.testing.assert_array_equal(actual, expected)
def test_NR_DEC_p0_04_j2k_96_decode(self):
actual = self.j2k.read(area=(20, 150, 50, 200), rlevel=2)
expected = self.j2k_quarter_data[5:13, 38:50]
np.testing.assert_array_equal(actual, expected)

View file

@ -2847,8 +2847,7 @@ class TestSuiteWarns(MetadataBase):
relpath = 'input/nonregression/issue188_beach_64bitsbox.jp2'
jfile = opj_data_file(relpath)
with self.assertWarns(UserWarning):
j = Jp2k(jfile)
d = j.read()
d = Jp2k(jfile)[:]
self.assertTrue(True)
def test_NR_broken4_jp2_dump(self):

View file

@ -24,6 +24,7 @@ from .fixtures import OPJ_DATA_ROOT, opj_data_file, read_image
from .fixtures import NO_READ_BACKEND, NO_READ_BACKEND_MSG
from .fixtures import NO_SKIMAGE_FREEIMAGE_SUPPORT
from .fixtures import WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG
from . import fixtures
from glymur import Jp2k
import glymur
@ -31,7 +32,7 @@ import glymur
@unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_OPJ_DATA_ROOT environment variable not set")
class TestSuiteNegative(unittest.TestCase):
class TestSuiteNegativeRead(unittest.TestCase):
"""Test suite for certain negative tests from openjpeg suite."""
def setUp(self):
@ -41,33 +42,6 @@ class TestSuiteNegative(unittest.TestCase):
def tearDown(self):
pass
@unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT,
"Cannot read input image without scikit-image/freeimage")
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
def test_cinema2K_bad_frame_rate(self):
"""Cinema2k frame rate must be either 24 or 48."""
relfile = 'input/nonregression/X_5_2K_24_235_CBR_STEM24_000.tif'
infile = opj_data_file(relfile)
data = skimage.io.imread(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
with self.assertRaises(IOError):
j.write(data, cinema2k=36)
@unittest.skipIf(NO_READ_BACKEND, NO_READ_BACKEND_MSG)
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
def test_psnr_with_cratios(self):
"""Using psnr with cratios options is not allowed."""
# Not an OpenJPEG test, but close.
infile = opj_data_file('input/nonregression/Bretagne1.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
with self.assertRaises(IOError):
j.write(data, psnr=[30, 35, 40], cratios=[2, 3, 4])
def test_nr_marker_not_compliant(self):
"""non-compliant marker, should still be able to read"""
relpath = 'input/nonregression/MarkerIsNotCompliant.j2k'
@ -98,56 +72,84 @@ class TestSuiteNegative(unittest.TestCase):
jp2k.get_codestream(header_only=False)
self.assertTrue(True)
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
@unittest.skipIf(re.match("1.5|2", glymur.version.openjpeg_version) is None,
"Must have openjpeg 1.5 or higher to run")
@unittest.skipIf(os.name == "nt", fixtures.WINDOWS_TMP_FILE_MSG)
@unittest.skipIf(OPJ_DATA_ROOT is None,
"OPJ_OPJ_DATA_ROOT environment variable not set")
class TestSuiteNegativeWrite(unittest.TestCase):
"""Test suite for certain negative tests from openjpeg suite."""
def setUp(self):
self.jp2file = glymur.data.nemo()
self.j2kfile = glymur.data.goodstuff()
def tearDown(self):
pass
@unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT,
"Cannot read input image without scikit-image/freeimage")
def test_cinema2K_bad_frame_rate(self):
"""Cinema2k frame rate must be either 24 or 48."""
relfile = 'input/nonregression/X_5_2K_24_235_CBR_STEM24_000.tif'
infile = opj_data_file(relfile)
data = skimage.io.imread(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
with self.assertRaises(IOError):
j = Jp2k(tfile.name, data=data, cinema2k=36)
@unittest.skipIf(NO_READ_BACKEND, NO_READ_BACKEND_MSG)
def test_psnr_with_cratios(self):
"""Using psnr with cratios options is not allowed."""
# Not an OpenJPEG test, but close.
infile = opj_data_file('input/nonregression/Bretagne1.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
with self.assertRaises(IOError):
j = Jp2k(tfile.name,
data=data, psnr=[30, 35, 40], cratios=[2, 3, 4])
def test_code_block_dimensions(self):
"""don't allow extreme codeblock sizes"""
# opj_compress doesn't allow the dimensions of a codeblock
# to be too small or too big, so neither will we.
data = np.zeros((256, 256), dtype=np.uint8)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
# opj_compress doesn't allow code block area to exceed 4096.
with self.assertRaises(IOError):
j.write(data, cbsize=(256, 256))
j = Jp2k(tfile.name, data=data, cbsize=(256, 256))
# opj_compress doesn't allow either dimension to be less than 4.
with self.assertRaises(IOError):
j.write(data, cbsize=(2048, 2))
j = Jp2k(tfile.name, data=data, cbsize=(2048, 2))
with self.assertRaises(IOError):
j.write(data, cbsize=(2, 2048))
j = Jp2k(tfile.name, data=data, cbsize=(2, 2048))
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
def test_precinct_size_not_p2(self):
"""precinct sizes should be powers of two."""
ifile = Jp2k(self.j2kfile)
data = ifile.read(rlevel=2)
data = ifile[::4, ::4]
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
ofile = Jp2k(tfile.name, 'wb')
with self.assertRaises(IOError):
ofile.write(data, psizes=[(13, 13)])
ofile = Jp2k(tfile.name, data=data, psizes=[(13, 13)])
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
def test_cblk_size_not_power_of_two(self):
"""code block sizes should be powers of two."""
ifile = Jp2k(self.j2kfile)
data = ifile.read(rlevel=2)
data = ifile[::4, ::4]
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
ofile = Jp2k(tfile.name, 'wb')
with self.assertRaises(IOError):
ofile.write(data, cbsize=(13, 12))
ofile = Jp2k(tfile.name, data=data, cbsize=(13, 12))
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
def test_cblk_size_precinct_size(self):
"""code block sizes should never exceed half that of precinct size."""
ifile = Jp2k(self.j2kfile)
data = ifile.read(rlevel=2)
data = ifile[::4, ::4]
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
ofile = Jp2k(tfile.name, 'wb')
with self.assertRaises(IOError):
ofile.write(data,
cbsize=(64, 64),
psizes=[(64, 64)])
ofile = Jp2k(tfile.name,
data=data, cbsize=(64, 64), psizes=[(64, 64)])
if __name__ == "__main__":
unittest.main()

View file

@ -87,9 +87,9 @@ class WriteCinema(CinemaBase):
infile = opj_data_file(relfile)
data = skimage.io.imread(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
with self.assertRaises(IOError):
j.write(data, cinema2k=48, cratios=[200, 100, 50])
j = Jp2k(tfile.name, data=data,
cinema2k=48, cratios=[200, 100, 50])
def test_cinema4K_with_others(self):
"""Can't specify cinema4k with any other options."""
@ -97,9 +97,9 @@ class WriteCinema(CinemaBase):
infile = opj_data_file(relfile)
data = skimage.io.imread(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
with self.assertRaises(IOError):
j.write(data, cinema4k=True, cratios=[200, 100, 50])
j = Jp2k(tfile.name, data=data,
cinema4k=True, cratios=[200, 100, 50])
@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG)
@ -123,10 +123,9 @@ class WriteCinemaWarns(CinemaBase):
infile = opj_data_file(relfile)
data = skimage.io.imread(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
regex = 'OpenJPEG library warning:.*'
with self.assertWarnsRegex(UserWarning, re.compile(regex)):
j.write(data, cinema4k=True)
j = Jp2k(tfile.name, data=data, cinema4k=True)
codestream = j.get_codestream()
self.check_cinema4k_codestream(codestream, (4096, 2160))
@ -136,9 +135,8 @@ class WriteCinemaWarns(CinemaBase):
infile = opj_data_file(relfile)
data = skimage.io.imread(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
with self.assertWarnsRegex(UserWarning, 'OpenJPEG library warning'):
j.write(data, cinema2k=48)
j = Jp2k(tfile.name, data=data, cinema2k=48)
codestream = j.get_codestream()
self.check_cinema2k_codestream(codestream, (2048, 857))
@ -148,9 +146,8 @@ class WriteCinemaWarns(CinemaBase):
infile = opj_data_file(relfile)
data = skimage.io.imread(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
with self.assertWarnsRegex(UserWarning, 'OpenJPEG library warning'):
j.write(data, cinema2k=48)
j = Jp2k(tfile.name, data=data, cinema2k=48)
codestream = j.get_codestream()
self.check_cinema2k_codestream(codestream, (2048, 1080))
@ -160,9 +157,8 @@ class WriteCinemaWarns(CinemaBase):
infile = opj_data_file(relfile)
data = skimage.io.imread(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
with self.assertWarnsRegex(UserWarning, 'OpenJPEG library warning'):
j.write(data, cinema2k=24)
j = Jp2k(tfile.name, data=data, cinema2k=24)
codestream = j.get_codestream()
self.check_cinema2k_codestream(codestream, (2048, 1080))
@ -172,11 +168,10 @@ class WriteCinemaWarns(CinemaBase):
infile = opj_data_file(relfile)
data = skimage.io.imread(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
with self.assertWarnsRegex(UserWarning, 'OpenJPEG library warning'):
# OpenJPEG library warning: The desired maximum codestream
# size has limited at least one of the desired quality layers
j.write(data, cinema2k=24)
j = Jp2k(tfile.name, data=data, cinema2k=24)
codestream = j.get_codestream()
self.check_cinema2k_codestream(codestream, (2048, 857))
@ -186,12 +181,11 @@ class WriteCinemaWarns(CinemaBase):
infile = opj_data_file(relfile)
data = skimage.io.imread(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
regex = 'OpenJPEG library warning'
with self.assertWarnsRegex(UserWarning, regex):
# OpenJPEG library warning: The desired maximum codestream
# size has limited at least one of the desired quality layers
j.write(data, cinema2k=48)
j = Jp2k(tfile.name, data=data, cinema2k=48)
codestream = j.get_codestream()
self.check_cinema2k_codestream(codestream, (1998, 1080))
@ -221,9 +215,8 @@ class TestNegative2pointzero(unittest.TestCase):
for version in versions:
with patch('glymur.version.openjpeg_version', new=version):
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
with self.assertRaises(IOError):
j.write(data, cinema2k=48)
j = Jp2k(tfile.name, data=data, cinema2k=48)
@unittest.skipIf(re.match(r'''1.[0-4]''', openjpeg_version) is not None,
@ -249,8 +242,7 @@ class TestSuiteWrite(fixtures.MetadataBase):
expdata = np.fromfile(filename, dtype=np.uint16)
expdata.resize((2816, 2048))
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
j.write(expdata, irreversible=True)
j = Jp2k(tfile.name, data=expdata, irreversible=True)
codestream = j.get_codestream()
self.assertEqual(codestream.segment[2].spcod[8],
@ -262,8 +254,7 @@ class TestSuiteWrite(fixtures.MetadataBase):
infile = opj_data_file('input/nonregression/Bretagne1.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
j.write(data, cratios=[200, 100, 50])
j = Jp2k(tfile.name, data=data, cratios=[200, 100, 50])
# Should be three layers.
c = j.get_codestream()
@ -294,8 +285,7 @@ class TestSuiteWrite(fixtures.MetadataBase):
infile = opj_data_file('input/nonregression/Bretagne1.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
j.write(data, psnr=[30, 35, 40], numres=2)
j = Jp2k(tfile.name, data=data, psnr=[30, 35, 40], numres=2)
# Should be three layers.
codestream = j.get_codestream()
@ -326,9 +316,9 @@ class TestSuiteWrite(fixtures.MetadataBase):
infile = opj_data_file('input/nonregression/Bretagne1.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
j.write(data, psnr=[30, 35, 40], cbsize=(16, 16),
psizes=[(64, 64)])
j = Jp2k(tfile.name,
data=data,
psnr=[30, 35, 40], cbsize=(16, 16), psizes=[(64, 64)])
# Should be three layers.
codestream = j.get_codestream()
@ -361,8 +351,8 @@ class TestSuiteWrite(fixtures.MetadataBase):
infile = opj_data_file('input/nonregression/Bretagne2.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
j.write(data,
j = Jp2k(tfile.name,
data=data,
psizes=[(128, 128)] * 3,
cratios=[100, 20, 2],
tilesize=(480, 640),
@ -398,8 +388,7 @@ class TestSuiteWrite(fixtures.MetadataBase):
infile = opj_data_file('input/nonregression/Bretagne2.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
j.write(data, tilesize=(127, 127), prog="PCRL")
j = Jp2k(tfile.name, data=data, tilesize=(127, 127), prog="PCRL")
codestream = j.get_codestream()
@ -429,8 +418,7 @@ class TestSuiteWrite(fixtures.MetadataBase):
infile = opj_data_file('input/nonregression/Bretagne2.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
j.write(data, subsam=(2, 2), sop=True)
j = Jp2k(tfile.name, data=data, subsam=(2, 2), sop=True)
codestream = j.get_codestream(header_only=False)
@ -465,8 +453,7 @@ class TestSuiteWrite(fixtures.MetadataBase):
infile = opj_data_file('input/nonregression/Bretagne2.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
j.write(data, modesw=38, eph=True)
j = Jp2k(tfile.name, data=data, modesw=38, eph=True)
codestream = j.get_codestream(header_only=False)
@ -500,8 +487,8 @@ class TestSuiteWrite(fixtures.MetadataBase):
infile = opj_data_file('input/nonregression/Bretagne2.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
j.write(data, grid_offset=[300, 150], cratios=[800])
j = Jp2k(tfile.name,
data=data, grid_offset=[300, 150], cratios=[800])
codestream = j.get_codestream(header_only=False)
@ -531,8 +518,7 @@ class TestSuiteWrite(fixtures.MetadataBase):
infile = opj_data_file('input/nonregression/Cevennes1.bmp')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
j.write(data, cratios=[800])
j = Jp2k(tfile.name, data=data, cratios=[800])
codestream = j.get_codestream(header_only=False)
@ -562,8 +548,7 @@ class TestSuiteWrite(fixtures.MetadataBase):
infile = opj_data_file('input/nonregression/Cevennes2.ppm')
data = read_image(infile)
with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile:
j = Jp2k(tfile.name, 'wb')
j.write(data, cratios=[50])
j = Jp2k(tfile.name, data=data, cratios=[50])
codestream = j.get_codestream(header_only=False)
@ -592,8 +577,8 @@ class TestSuiteWrite(fixtures.MetadataBase):
"""NR-ENC-Rome.bmp-11-encode"""
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)
jp2 = Jp2k(tfile.name,
data=data, psnr=[30, 35, 50], prog='LRCP', numres=3)
ids = [box.box_id for box in jp2.box]
self.assertEqual(ids, ['jP ', 'ftyp', 'jp2h', 'jp2c'])
@ -658,8 +643,7 @@ class TestSuiteWrite(fixtures.MetadataBase):
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')
j.write(data)
j = Jp2k(tfile.name, data=data)
codestream = j.get_codestream(header_only=False)

View file

@ -107,14 +107,15 @@ class TestPrinting(unittest.TestCase):
with self.assertRaises(TypeError):
glymur.set_printoptions(hi='low')
@unittest.skipIf(re.match("1.5|2", glymur.version.openjpeg_version) is None,
"Must have openjpeg 1.5 or higher to run")
def test_asoc_label_box(self):
"""verify printing of asoc, label boxes"""
# Construct a fake file with an asoc and a label box, as
# OpenJPEG doesn't have such a file.
data = glymur.Jp2k(self.jp2file).read(rlevel=1)
data = glymur.Jp2k(self.jp2file)[::2, ::2]
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
j = glymur.Jp2k(tfile.name, 'wb')
j.write(data)
j = glymur.Jp2k(tfile.name, data=data)
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile2: