pylint work, low-level library function work, #71
Change the library organization around such that the library module contents are visible, but the module is protected.
This commit is contained in:
parent
e773ec4db5
commit
4d09208f20
14 changed files with 503 additions and 510 deletions
132
glymur/jp2k.py
132
glymur/jp2k.py
|
|
@ -18,13 +18,13 @@ import numpy as np
|
||||||
from .codestream import Codestream
|
from .codestream import Codestream
|
||||||
from .core import *
|
from .core import *
|
||||||
from .jp2box import *
|
from .jp2box import *
|
||||||
from .lib import openjpeg as opj
|
from .lib import _openjpeg as _opj
|
||||||
from .lib import openjp2 as opj2
|
from .lib import _openjp2 as _opj2
|
||||||
|
|
||||||
_cspace_map = {'rgb': opj2._CLRSPC_SRGB,
|
_cspace_map = {'rgb': _opj2.CLRSPC_SRGB,
|
||||||
'gray': opj2._CLRSPC_GRAY,
|
'gray': _opj2.CLRSPC_GRAY,
|
||||||
'grey': opj2._CLRSPC_GRAY,
|
'grey': _opj2.CLRSPC_GRAY,
|
||||||
'ycc': opj2._CLRSPC_YCC}
|
'ycc': _opj2.CLRSPC_YCC}
|
||||||
|
|
||||||
# Setup the default callback handlers. See the callback functions subsection
|
# Setup the default callback handlers. See the callback functions subsection
|
||||||
# in the ctypes section of the Python documentation for a solid explanation of
|
# in the ctypes section of the Python documentation for a solid explanation of
|
||||||
|
|
@ -34,7 +34,7 @@ _CMPFUNC = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_char_p, ctypes.c_void_p)
|
||||||
|
|
||||||
def _default_error_handler(msg, client_data):
|
def _default_error_handler(msg, client_data):
|
||||||
msg = "OpenJPEG library error: {0}".format(msg.decode('utf-8').rstrip())
|
msg = "OpenJPEG library error: {0}".format(msg.decode('utf-8').rstrip())
|
||||||
opj2._set_error_message(msg)
|
_opj2.set_error_message(msg)
|
||||||
|
|
||||||
|
|
||||||
def _default_info_handler(msg, client_data):
|
def _default_info_handler(msg, client_data):
|
||||||
|
|
@ -113,12 +113,12 @@ class Jp2k(Jp2kBox):
|
||||||
buffer = f.read(2)
|
buffer = f.read(2)
|
||||||
signature, = struct.unpack('>H', buffer)
|
signature, = struct.unpack('>H', buffer)
|
||||||
if signature == 0xff4f:
|
if signature == 0xff4f:
|
||||||
self._codec_format = opj2._CODEC_J2K
|
self._codec_format = _opj2.CODEC_J2K
|
||||||
# That's it, we're done. The codestream object is only
|
# That's it, we're done. The codestream object is only
|
||||||
# produced upon explicit request.
|
# produced upon explicit request.
|
||||||
return
|
return
|
||||||
|
|
||||||
self._codec_format = opj2._CODEC_JP2
|
self._codec_format = _opj2.CODEC_JP2
|
||||||
|
|
||||||
# Should be JP2.
|
# Should be JP2.
|
||||||
# First 4 bytes should be 12, the length of the 'jP ' box.
|
# First 4 bytes should be 12, the length of the 'jP ' box.
|
||||||
|
|
@ -210,17 +210,17 @@ class Jp2k(Jp2kBox):
|
||||||
>>> j.write(data.astype(np.uint8))
|
>>> j.write(data.astype(np.uint8))
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cparams = opj2._set_default_encoder_parameters()
|
cparams = _opj2.set_default_encoder_parameters()
|
||||||
|
|
||||||
outfile = self.filename.encode()
|
outfile = self.filename.encode()
|
||||||
n = opj2._PATH_LEN - len(outfile)
|
n = _opj2.PATH_LEN - len(outfile)
|
||||||
outfile += b'0' * n
|
outfile += b'0' * n
|
||||||
cparams.outfile = outfile
|
cparams.outfile = outfile
|
||||||
|
|
||||||
if self.filename[-4:].lower() == '.jp2':
|
if self.filename[-4:].lower() == '.jp2':
|
||||||
codec_fmt = opj2._CODEC_JP2
|
codec_fmt = _opj2.CODEC_JP2
|
||||||
else:
|
else:
|
||||||
codec_fmt = opj2._CODEC_J2K
|
codec_fmt = _opj2.CODEC_J2K
|
||||||
|
|
||||||
cparams.cod_format = codec_fmt
|
cparams.cod_format = codec_fmt
|
||||||
|
|
||||||
|
|
@ -304,7 +304,7 @@ class Jp2k(Jp2kBox):
|
||||||
if tilesize is not None:
|
if tilesize is not None:
|
||||||
cparams.cp_tdx = tilesize[1]
|
cparams.cp_tdx = tilesize[1]
|
||||||
cparams.cp_tdy = tilesize[0]
|
cparams.cp_tdy = tilesize[0]
|
||||||
cparams.tile_size_on = opj2._TRUE
|
cparams.tile_size_on = _opj2.TRUE
|
||||||
|
|
||||||
if cratios is not None and psnr is not None:
|
if cratios is not None and psnr is not None:
|
||||||
msg = "Cannot specify cratios and psnr together."
|
msg = "Cannot specify cratios and psnr together."
|
||||||
|
|
@ -323,12 +323,12 @@ class Jp2k(Jp2kBox):
|
||||||
|
|
||||||
if colorspace is None:
|
if colorspace is None:
|
||||||
if img_array.shape[2] == 1 or img_array.shape[2] == 2:
|
if img_array.shape[2] == 1 or img_array.shape[2] == 2:
|
||||||
colorspace = opj2._CLRSPC_GRAY
|
colorspace = _opj2.CLRSPC_GRAY
|
||||||
else:
|
else:
|
||||||
# No YCC unless specifically told to do so.
|
# No YCC unless specifically told to do so.
|
||||||
colorspace = opj2._CLRSPC_SRGB
|
colorspace = _opj2.CLRSPC_SRGB
|
||||||
else:
|
else:
|
||||||
if codec_fmt == opj2._CODEC_J2K:
|
if codec_fmt == _opj2.CODEC_J2K:
|
||||||
raise IOError('Do not specify a colorspace with J2K.')
|
raise IOError('Do not specify a colorspace with J2K.')
|
||||||
colorspace = colorspace.lower()
|
colorspace = colorspace.lower()
|
||||||
if colorspace not in ('rgb', 'grey', 'gray'):
|
if colorspace not in ('rgb', 'grey', 'gray'):
|
||||||
|
|
@ -341,12 +341,12 @@ class Jp2k(Jp2kBox):
|
||||||
colorspace = _cspace_map[colorspace]
|
colorspace = _cspace_map[colorspace]
|
||||||
|
|
||||||
if mct is None:
|
if mct is None:
|
||||||
if colorspace == opj2._CLRSPC_SRGB:
|
if colorspace == _opj2.CLRSPC_SRGB:
|
||||||
cparams.tcp_mct = 1
|
cparams.tcp_mct = 1
|
||||||
else:
|
else:
|
||||||
cparams.tcp_mct = 0
|
cparams.tcp_mct = 0
|
||||||
else:
|
else:
|
||||||
if mct and colorspace == opj2._CLRSPC_GRAY:
|
if mct and colorspace == _opj2.CLRSPC_GRAY:
|
||||||
msg = "Cannot specify usage of the multi component transform "
|
msg = "Cannot specify usage of the multi component transform "
|
||||||
msg += "if the colorspace is gray."
|
msg += "if the colorspace is gray."
|
||||||
raise IOError(msg)
|
raise IOError(msg)
|
||||||
|
|
@ -359,7 +359,7 @@ class Jp2k(Jp2kBox):
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("unhandled datatype")
|
raise RuntimeError("unhandled datatype")
|
||||||
|
|
||||||
comptparms = (opj2._image_comptparm_t * num_comps)()
|
comptparms = (_opj2.image_comptparm_t * num_comps)()
|
||||||
for j in range(num_comps):
|
for j in range(num_comps):
|
||||||
comptparms[j].dx = cparams.subsampling_dx
|
comptparms[j].dx = cparams.subsampling_dx
|
||||||
comptparms[j].dy = cparams.subsampling_dy
|
comptparms[j].dy = cparams.subsampling_dy
|
||||||
|
|
@ -371,7 +371,7 @@ class Jp2k(Jp2kBox):
|
||||||
comptparms[j].bpp = comp_prec
|
comptparms[j].bpp = comp_prec
|
||||||
comptparms[j].sgnd = 0
|
comptparms[j].sgnd = 0
|
||||||
|
|
||||||
image = opj2._image_create(comptparms, colorspace)
|
image = _opj2.image_create(comptparms, colorspace)
|
||||||
|
|
||||||
# set image offset and reference grid
|
# set image offset and reference grid
|
||||||
image.contents.x0 = cparams.image_offset_x0
|
image.contents.x0 = cparams.image_offset_x0
|
||||||
|
|
@ -388,23 +388,23 @@ class Jp2k(Jp2kBox):
|
||||||
src = layer.ctypes.data
|
src = layer.ctypes.data
|
||||||
ctypes.memmove(dest, src, layer.nbytes)
|
ctypes.memmove(dest, src, layer.nbytes)
|
||||||
|
|
||||||
codec = opj2._create_compress(codec_fmt)
|
codec = _opj2.create_compress(codec_fmt)
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
opj2._set_info_handler(codec, _info_callback)
|
_opj2.set_info_handler(codec, _info_callback)
|
||||||
else:
|
else:
|
||||||
opj2._set_info_handler(codec, None)
|
_opj2.set_info_handler(codec, None)
|
||||||
|
|
||||||
opj2._set_warning_handler(codec, _warning_callback)
|
_opj2.set_warning_handler(codec, _warning_callback)
|
||||||
opj2._set_error_handler(codec, _error_callback)
|
_opj2.set_error_handler(codec, _error_callback)
|
||||||
opj2._setup_encoder(codec, cparams, image)
|
_opj2.setup_encoder(codec, cparams, image)
|
||||||
strm = opj2._stream_create_default_file_stream_v3(self.filename, False)
|
strm = _opj2.stream_create_default_file_stream_v3(self.filename, False)
|
||||||
opj2._start_compress(codec, image, strm)
|
_opj2.start_compress(codec, image, strm)
|
||||||
opj2._encode(codec, strm)
|
_opj2.encode(codec, strm)
|
||||||
opj2._end_compress(codec, strm)
|
_opj2.end_compress(codec, strm)
|
||||||
opj2._stream_destroy_v3(strm)
|
_opj2.stream_destroy_v3(strm)
|
||||||
opj2._destroy_codec(codec)
|
_opj2.destroy_codec(codec)
|
||||||
opj2._image_destroy(image)
|
_opj2.image_destroy(image)
|
||||||
|
|
||||||
self._parse()
|
self._parse()
|
||||||
|
|
||||||
|
|
@ -589,7 +589,7 @@ class Jp2k(Jp2kBox):
|
||||||
>>> thumbnail.shape
|
>>> thumbnail.shape
|
||||||
(728, 1296, 3)
|
(728, 1296, 3)
|
||||||
"""
|
"""
|
||||||
if opj2._OPENJP2 is not None:
|
if _opj2.OPENJP2 is not None:
|
||||||
img = self._read_openjp2(**kwargs)
|
img = self._read_openjp2(**kwargs)
|
||||||
else:
|
else:
|
||||||
img = self._read_openjpeg(**kwargs)
|
img = self._read_openjpeg(**kwargs)
|
||||||
|
|
@ -629,38 +629,38 @@ class Jp2k(Jp2kBox):
|
||||||
|
|
||||||
with ExitStack() as stack:
|
with ExitStack() as stack:
|
||||||
# Set decoding parameters.
|
# Set decoding parameters.
|
||||||
dparameters = opj.dparameters_t()
|
dparameters = _opj.dparameters_t()
|
||||||
opj._set_default_decoder_parameters(ctypes.byref(dparameters))
|
_opj.set_default_decoder_parameters(ctypes.byref(dparameters))
|
||||||
dparameters.cp_reduce = reduce
|
dparameters.cp_reduce = reduce
|
||||||
dparameters.decod_format = self._codec_format
|
dparameters.decod_format = self._codec_format
|
||||||
|
|
||||||
infile = self.filename.encode()
|
infile = self.filename.encode()
|
||||||
nelts = opj._PATH_LEN - len(infile)
|
nelts = _opj.PATH_LEN - len(infile)
|
||||||
infile += b'0' * nelts
|
infile += b'0' * nelts
|
||||||
dparameters.infile = infile
|
dparameters.infile = infile
|
||||||
|
|
||||||
dinfo = opj._create_decompress(dparameters.decod_format)
|
dinfo = _opj.create_decompress(dparameters.decod_format)
|
||||||
|
|
||||||
event_mgr = opj.event_mgr_t()
|
event_mgr = _opj.event_mgr_t()
|
||||||
info_handler = ctypes.cast(_info_callback, ctypes.c_void_p)
|
info_handler = ctypes.cast(_info_callback, ctypes.c_void_p)
|
||||||
event_mgr.info_handler = info_handler if verbose else None
|
event_mgr.info_handler = info_handler if verbose else None
|
||||||
event_mgr.warning_handler = ctypes.cast(_warning_callback,
|
event_mgr.warning_handler = ctypes.cast(_warning_callback,
|
||||||
ctypes.c_void_p)
|
ctypes.c_void_p)
|
||||||
event_mgr.error_handler = ctypes.cast(_error_callback,
|
event_mgr.error_handler = ctypes.cast(_error_callback,
|
||||||
ctypes.c_void_p)
|
ctypes.c_void_p)
|
||||||
opj._set_event_mgr(dinfo, ctypes.byref(event_mgr))
|
_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 fp:
|
with open(self.filename, 'rb') as fp:
|
||||||
src = fp.read()
|
src = fp.read()
|
||||||
cio = opj._cio_open(dinfo, src)
|
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.image_destroy, image)
|
||||||
stack.callback(opj._destroy_decompress, dinfo)
|
stack.callback(_opj.destroy_decompress, dinfo)
|
||||||
stack.callback(opj._cio_close, cio)
|
stack.callback(_opj.cio_close, cio)
|
||||||
|
|
||||||
ncomps = image.contents.numcomps
|
ncomps = image.contents.numcomps
|
||||||
component = image.contents.comps[0]
|
component = image.contents.comps[0]
|
||||||
|
|
@ -784,10 +784,10 @@ class Jp2k(Jp2kBox):
|
||||||
img_array : ndarray
|
img_array : ndarray
|
||||||
The individual image components or a single array.
|
The individual image components or a single array.
|
||||||
"""
|
"""
|
||||||
dparam = opj2._set_default_decoder_parameters()
|
dparam = _opj2.set_default_decoder_parameters()
|
||||||
|
|
||||||
infile = self.filename.encode()
|
infile = self.filename.encode()
|
||||||
nelts = opj2._PATH_LEN - len(infile)
|
nelts = _opj2.PATH_LEN - len(infile)
|
||||||
infile += b'0' * nelts
|
infile += b'0' * nelts
|
||||||
dparam.infile = infile
|
dparam.infile = infile
|
||||||
|
|
||||||
|
|
@ -820,31 +820,31 @@ class Jp2k(Jp2kBox):
|
||||||
dparam.nb_tile_to_decode = 1
|
dparam.nb_tile_to_decode = 1
|
||||||
|
|
||||||
with ExitStack() as stack:
|
with ExitStack() as stack:
|
||||||
stream = opj2._stream_create_default_file_stream_v3(self.filename,
|
stream = _opj2.stream_create_default_file_stream_v3(self.filename,
|
||||||
True)
|
True)
|
||||||
stack.callback(opj2._stream_destroy_v3, stream)
|
stack.callback(_opj2.stream_destroy_v3, stream)
|
||||||
codec = opj2._create_decompress(self._codec_format)
|
codec = _opj2.create_decompress(self._codec_format)
|
||||||
stack.callback(opj2._destroy_codec, codec)
|
stack.callback(_opj2.destroy_codec, codec)
|
||||||
|
|
||||||
opj2._set_error_handler(codec, _error_callback)
|
_opj2.set_error_handler(codec, _error_callback)
|
||||||
opj2._set_warning_handler(codec, _warning_callback)
|
_opj2.set_warning_handler(codec, _warning_callback)
|
||||||
if verbose:
|
if verbose:
|
||||||
opj2._set_info_handler(codec, _info_callback)
|
_opj2.set_info_handler(codec, _info_callback)
|
||||||
else:
|
else:
|
||||||
opj2._set_info_handler(codec, None)
|
_opj2.set_info_handler(codec, None)
|
||||||
|
|
||||||
opj2._setup_decoder(codec, dparam)
|
_opj2.setup_decoder(codec, dparam)
|
||||||
image = opj2._read_header(stream, codec)
|
image = _opj2.read_header(stream, codec)
|
||||||
stack.callback(opj2._image_destroy, image)
|
stack.callback(_opj2.image_destroy, image)
|
||||||
|
|
||||||
if dparam.nb_tile_to_decode:
|
if dparam.nb_tile_to_decode:
|
||||||
opj2._get_decoded_tile(codec, stream, image, dparam.tile_index)
|
_opj2.get_decoded_tile(codec, stream, image, dparam.tile_index)
|
||||||
else:
|
else:
|
||||||
opj2._set_decode_area(codec, image,
|
_opj2.set_decode_area(codec, image,
|
||||||
dparam.DA_x0, dparam.DA_y0,
|
dparam.DA_x0, dparam.DA_y0,
|
||||||
dparam.DA_x1, dparam.DA_y1)
|
dparam.DA_x1, dparam.DA_y1)
|
||||||
opj2._decode(codec, stream, image)
|
_opj2.decode(codec, stream, image)
|
||||||
opj2._end_decompress(codec, stream)
|
_opj2.end_decompress(codec, stream)
|
||||||
|
|
||||||
component = image.contents.comps[0]
|
component = image.contents.comps[0]
|
||||||
if component.sgnd:
|
if component.sgnd:
|
||||||
|
|
@ -937,7 +937,7 @@ class Jp2k(Jp2kBox):
|
||||||
NotImplementedError
|
NotImplementedError
|
||||||
If the openjp2 library is not available.
|
If the openjp2 library is not available.
|
||||||
"""
|
"""
|
||||||
if opj2._OPENJP2 is None:
|
if _opj2.OPENJP2 is None:
|
||||||
msg = "Requires openjp2 library."
|
msg = "Requires openjp2 library."
|
||||||
raise NotImplementedError(msg)
|
raise NotImplementedError(msg)
|
||||||
|
|
||||||
|
|
@ -986,7 +986,7 @@ class Jp2k(Jp2kBox):
|
||||||
If the file is JPX with more than one codestream.
|
If the file is JPX with more than one codestream.
|
||||||
"""
|
"""
|
||||||
with open(self.filename, 'rb') as fp:
|
with open(self.filename, 'rb') as fp:
|
||||||
if self._codec_format == opj2._CODEC_J2K:
|
if self._codec_format == _opj2.CODEC_J2K:
|
||||||
codestream = Codestream(fp, header_only=header_only)
|
codestream = Codestream(fp, header_only=header_only)
|
||||||
else:
|
else:
|
||||||
box = [x for x in self.box if x.box_id == 'jp2c']
|
box = [x for x in self.box if x.box_id == 'jp2c']
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
"""This package organizes individual libraries employed by glymur."""
|
"""This package organizes individual libraries employed by glymur."""
|
||||||
from . import openjp2
|
from . import openjp2 as _openjp2
|
||||||
from . import openjpeg
|
from . import openjpeg as _openjpeg
|
||||||
#from . import test
|
#from . import test
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -9,14 +9,14 @@ import os
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
path = os.path.join('C:\\', 'Program files', 'OpenJPEG 1.5',
|
path = os.path.join('C:\\', 'Program files', 'OpenJPEG 1.5',
|
||||||
'bin', 'openjpeg.dll')
|
'bin', 'openjpeg.dll')
|
||||||
_OPENJPEG = ctypes.windll.LoadLibrary(path)
|
OPENJPEG = ctypes.windll.LoadLibrary(path)
|
||||||
else:
|
else:
|
||||||
if platform.system() == 'Darwin':
|
if platform.system() == 'Darwin':
|
||||||
_OPENJPEG = ctypes.CDLL('/opt/local/lib/libopenjpeg.dylib')
|
OPENJPEG = ctypes.CDLL('/opt/local/lib/libopenjpeg.dylib')
|
||||||
elif platform.system() == 'Linux':
|
elif platform.system() == 'Linux':
|
||||||
_OPENJPEG = ctypes.CDLL(find_library('openjpeg'))
|
OPENJPEG = ctypes.CDLL(find_library('openjpeg'))
|
||||||
|
|
||||||
_PATH_LEN = 4096 # maximum allowed size for filenames
|
PATH_LEN = 4096 # maximum allowed size for filenames
|
||||||
|
|
||||||
|
|
||||||
class event_mgr_t(ctypes.Structure):
|
class event_mgr_t(ctypes.Structure):
|
||||||
|
|
@ -68,9 +68,9 @@ class dparameters_t(ctypes.Structure):
|
||||||
# cp_layer: the maximum number of quality layers to decode
|
# cp_layer: the maximum number of quality layers to decode
|
||||||
("cp_layer", ctypes.c_int),
|
("cp_layer", ctypes.c_int),
|
||||||
# infile: input file name
|
# infile: input file name
|
||||||
("infile", ctypes.c_char * _PATH_LEN),
|
("infile", ctypes.c_char * PATH_LEN),
|
||||||
# outfile: output file name
|
# outfile: output file name
|
||||||
("outfile", ctypes.c_char * _PATH_LEN),
|
("outfile", ctypes.c_char * PATH_LEN),
|
||||||
# decod_format: input file format 0: J2K, 1: JP2, 2: JPT
|
# decod_format: input file format 0: J2K, 1: JP2, 2: JPT
|
||||||
("decod_format", ctypes.c_int),
|
("decod_format", ctypes.c_int),
|
||||||
# cod_format: output file format 0: PGX, 1: PxM, 2: BMP
|
# cod_format: output file format 0: PGX, 1: PxM, 2: BMP
|
||||||
|
|
@ -115,75 +115,75 @@ class image_t(ctypes.Structure):
|
||||||
("icc_profile_buf", ctypes.c_char_p),
|
("icc_profile_buf", ctypes.c_char_p),
|
||||||
("icc_profile_len", ctypes.c_int)]
|
("icc_profile_len", ctypes.c_int)]
|
||||||
|
|
||||||
def _cio_open(cinfo, src):
|
def cio_open(cinfo, src):
|
||||||
"""Wrapper for openjpeg library function opj_cio_open."""
|
"""Wrapper for openjpeg library function opj_cio_open."""
|
||||||
argtypes = [ctypes.POINTER(common_struct_t), ctypes.c_char_p, ctypes.c_int]
|
argtypes = [ctypes.POINTER(common_struct_t), ctypes.c_char_p, ctypes.c_int]
|
||||||
_OPENJPEG.opj_cio_open.argtypes = argtypes
|
OPENJPEG.opj_cio_open.argtypes = argtypes
|
||||||
_OPENJPEG.opj_cio_open.restype = ctypes.POINTER(cio_t)
|
OPENJPEG.opj_cio_open.restype = ctypes.POINTER(cio_t)
|
||||||
|
|
||||||
cio = _OPENJPEG.opj_cio_open(ctypes.cast(cinfo, ctypes.POINTER(common_struct_t)),
|
cio = OPENJPEG.opj_cio_open(ctypes.cast(cinfo, ctypes.POINTER(common_struct_t)),
|
||||||
src, len(src))
|
src, len(src))
|
||||||
return cio
|
return cio
|
||||||
|
|
||||||
def _cio_close(cio):
|
def cio_close(cio):
|
||||||
"""Wraps openjpeg library function cio_close.
|
"""Wraps openjpeg library function cio_close.
|
||||||
"""
|
"""
|
||||||
_OPENJPEG.opj_cio_close.argtypes = [ctypes.POINTER(cio_t)]
|
OPENJPEG.opj_cio_close.argtypes = [ctypes.POINTER(cio_t)]
|
||||||
_OPENJPEG.opj_cio_close(cio)
|
OPENJPEG.opj_cio_close(cio)
|
||||||
|
|
||||||
def _create_decompress(fmt):
|
def create_decompress(fmt):
|
||||||
"""Wraps openjpeg library function opj_create_decompress.
|
"""Wraps openjpeg library function opj_create_decompress.
|
||||||
"""
|
"""
|
||||||
_OPENJPEG.opj_create_decompress.argtypes = [ctypes.c_int]
|
OPENJPEG.opj_create_decompress.argtypes = [ctypes.c_int]
|
||||||
_OPENJPEG.opj_create_decompress.restype = ctypes.POINTER(dinfo_t)
|
OPENJPEG.opj_create_decompress.restype = ctypes.POINTER(dinfo_t)
|
||||||
dinfo = _OPENJPEG.opj_create_decompress(fmt)
|
dinfo = OPENJPEG.opj_create_decompress(fmt)
|
||||||
return dinfo
|
return dinfo
|
||||||
|
|
||||||
def _decode(dinfo, cio):
|
def decode(dinfo, cio):
|
||||||
"""Wrapper for opj_decode.
|
"""Wrapper for opj_decode.
|
||||||
"""
|
"""
|
||||||
argtypes = [ctypes.POINTER(dinfo_t), ctypes.POINTER(cio_t)]
|
argtypes = [ctypes.POINTER(dinfo_t), ctypes.POINTER(cio_t)]
|
||||||
_OPENJPEG.opj_decode.argtypes = argtypes
|
OPENJPEG.opj_decode.argtypes = argtypes
|
||||||
_OPENJPEG.opj_decode.restype = ctypes.POINTER(image_t)
|
OPENJPEG.opj_decode.restype = ctypes.POINTER(image_t)
|
||||||
image = _OPENJPEG.opj_decode(dinfo, cio)
|
image = OPENJPEG.opj_decode(dinfo, cio)
|
||||||
return image
|
return image
|
||||||
|
|
||||||
def _destroy_decompress(dinfo):
|
def destroy_decompress(dinfo):
|
||||||
"""Wraps openjpeg library function opj_destroy_decompress."""
|
"""Wraps openjpeg library function opj_destroy_decompress."""
|
||||||
_OPENJPEG.opj_destroy_decompress.argtypes = [ctypes.POINTER(dinfo_t)]
|
OPENJPEG.opj_destroy_decompress.argtypes = [ctypes.POINTER(dinfo_t)]
|
||||||
_OPENJPEG.opj_destroy_decompress(dinfo)
|
OPENJPEG.opj_destroy_decompress(dinfo)
|
||||||
|
|
||||||
def _image_destroy(image):
|
def image_destroy(image):
|
||||||
"""Wraps openjpeg library function opj_image_destroy."""
|
"""Wraps openjpeg library function opj_image_destroy."""
|
||||||
_OPENJPEG.opj_image_destroy.argtypes = [ctypes.POINTER(image_t)]
|
OPENJPEG.opj_image_destroy.argtypes = [ctypes.POINTER(image_t)]
|
||||||
_OPENJPEG.opj_image_destroy(image)
|
OPENJPEG.opj_image_destroy(image)
|
||||||
|
|
||||||
def _set_default_decoder_parameters(dparams_p):
|
def set_default_decoder_parameters(dparams_p):
|
||||||
"""Wrapper for opj_set_default_decoder_parameters.
|
"""Wrapper for opj_set_default_decoder_parameters.
|
||||||
"""
|
"""
|
||||||
argtypes = [ctypes.POINTER(dparameters_t)]
|
argtypes = [ctypes.POINTER(dparameters_t)]
|
||||||
_OPENJPEG.opj_set_default_decoder_parameters.argtypes = argtypes
|
OPENJPEG.opj_set_default_decoder_parameters.argtypes = argtypes
|
||||||
_OPENJPEG.opj_set_default_decoder_parameters(dparams_p)
|
OPENJPEG.opj_set_default_decoder_parameters(dparams_p)
|
||||||
|
|
||||||
|
|
||||||
def _set_event_mgr(dinfo, event_mgr, context=None):
|
def set_event_mgr(dinfo, event_mgr, context=None):
|
||||||
"""Wrapper for openjpeg library function opj_set_event_mgr.
|
"""Wrapper for openjpeg library function opj_set_event_mgr.
|
||||||
"""
|
"""
|
||||||
argtypes = [ctypes.POINTER(common_struct_t),
|
argtypes = [ctypes.POINTER(common_struct_t),
|
||||||
ctypes.POINTER(event_mgr_t),
|
ctypes.POINTER(event_mgr_t),
|
||||||
ctypes.c_void_p]
|
ctypes.c_void_p]
|
||||||
_OPENJPEG.opj_set_event_mgr(ctypes.cast(dinfo,
|
OPENJPEG.opj_set_event_mgr(ctypes.cast(dinfo,
|
||||||
ctypes.POINTER(common_struct_t)),
|
ctypes.POINTER(common_struct_t)),
|
||||||
event_mgr, context)
|
event_mgr, context)
|
||||||
|
|
||||||
def _setup_decoder(dinfo, dparams):
|
def setup_decoder(dinfo, dparams):
|
||||||
"""Wrapper for openjpeg library function opj_setup_decoder."""
|
"""Wrapper for openjpeg library function opj_setup_decoder."""
|
||||||
argtypes = [ctypes.POINTER(dinfo_t), ctypes.POINTER(dparameters_t)]
|
argtypes = [ctypes.POINTER(dinfo_t), ctypes.POINTER(dparameters_t)]
|
||||||
_OPENJPEG.opj_setup_decoder.argtypes = argtypes
|
OPENJPEG.opj_setup_decoder.argtypes = argtypes
|
||||||
_OPENJPEG.opj_setup_decoder(dinfo, dparams)
|
OPENJPEG.opj_setup_decoder(dinfo, dparams)
|
||||||
|
|
||||||
def _version():
|
def version():
|
||||||
"""Wrapper for opj_version library routine."""
|
"""Wrapper for opj_version library routine."""
|
||||||
_OPENJPEG.opj_version.restype = ctypes.c_char_p
|
OPENJPEG.opj_version.restype = ctypes.c_char_p
|
||||||
v = _OPENJPEG.opj_version()
|
v = OPENJPEG.opj_version()
|
||||||
return v.decode('utf-8')
|
return v.decode('utf-8')
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,7 @@ import numpy as np
|
||||||
import glymur
|
import glymur
|
||||||
|
|
||||||
|
|
||||||
def load_tests(loader, tests, ignore):
|
@unittest.skipIf(glymur.lib._openjp2.OPENJP2 is None,
|
||||||
if glymur.lib.openjp2._OPENJP2 is not None:
|
|
||||||
tests.addTests(doctest.DocTestSuite('glymur.lib.openjp2'))
|
|
||||||
return tests
|
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(glymur.lib.openjp2._OPENJP2 is None,
|
|
||||||
"Missing openjp2 library.")
|
"Missing openjp2 library.")
|
||||||
class TestOpenJP2(unittest.TestCase):
|
class TestOpenJP2(unittest.TestCase):
|
||||||
|
|
||||||
|
|
@ -29,7 +23,7 @@ class TestOpenJP2(unittest.TestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_set_default_encoder_parameters(self):
|
def test_set_default_encoder_parameters(self):
|
||||||
cparams = glymur.lib.openjp2._set_default_encoder_parameters()
|
cparams = glymur.lib._openjp2.set_default_encoder_parameters()
|
||||||
|
|
||||||
self.assertEqual(cparams.res_spec, 0)
|
self.assertEqual(cparams.res_spec, 0)
|
||||||
self.assertEqual(cparams.cblockw_init, 64)
|
self.assertEqual(cparams.cblockw_init, 64)
|
||||||
|
|
@ -38,7 +32,7 @@ class TestOpenJP2(unittest.TestCase):
|
||||||
self.assertEqual(cparams.subsampling_dx, 1)
|
self.assertEqual(cparams.subsampling_dx, 1)
|
||||||
self.assertEqual(cparams.subsampling_dy, 1)
|
self.assertEqual(cparams.subsampling_dy, 1)
|
||||||
self.assertEqual(cparams.mode, 0)
|
self.assertEqual(cparams.mode, 0)
|
||||||
self.assertEqual(cparams.prog_order, glymur.lib.openjp2.LRCP)
|
self.assertEqual(cparams.prog_order, glymur.lib._openjp2.LRCP)
|
||||||
self.assertEqual(cparams.roi_shift, 0)
|
self.assertEqual(cparams.roi_shift, 0)
|
||||||
self.assertEqual(cparams.cp_tx0, 0)
|
self.assertEqual(cparams.cp_tx0, 0)
|
||||||
self.assertEqual(cparams.cp_ty0, 0)
|
self.assertEqual(cparams.cp_ty0, 0)
|
||||||
|
|
@ -46,7 +40,7 @@ class TestOpenJP2(unittest.TestCase):
|
||||||
self.assertEqual(cparams.irreversible, 0)
|
self.assertEqual(cparams.irreversible, 0)
|
||||||
|
|
||||||
def test_set_default_decoder_parameters(self):
|
def test_set_default_decoder_parameters(self):
|
||||||
dparams = glymur.lib.openjp2._set_default_decoder_parameters()
|
dparams = glymur.lib._openjp2.set_default_decoder_parameters()
|
||||||
|
|
||||||
self.assertEqual(dparams.DA_x0, 0)
|
self.assertEqual(dparams.DA_x0, 0)
|
||||||
self.assertEqual(dparams.DA_y0, 0)
|
self.assertEqual(dparams.DA_y0, 0)
|
||||||
|
|
@ -55,34 +49,34 @@ class TestOpenJP2(unittest.TestCase):
|
||||||
|
|
||||||
def tile_macro(self, codec, stream, imagep, tidx):
|
def tile_macro(self, codec, stream, imagep, tidx):
|
||||||
# called only by j2k_random_tile_access
|
# called only by j2k_random_tile_access
|
||||||
glymur.lib.openjp2._get_decoded_tile(codec, stream, imagep, tidx)
|
glymur.lib._openjp2.get_decoded_tile(codec, stream, imagep, tidx)
|
||||||
for j in range(imagep.contents.numcomps):
|
for j in range(imagep.contents.numcomps):
|
||||||
self.assertIsNotNone(imagep.contents.comps[j].data)
|
self.assertIsNotNone(imagep.contents.comps[j].data)
|
||||||
|
|
||||||
def j2k_random_tile_access(self, filename, codec_format=None):
|
def j2k_random_tile_access(self, filename, codec_format=None):
|
||||||
# called by the test_rtaX methods
|
# called by the test_rtaX methods
|
||||||
dparam = glymur.lib.openjp2._set_default_decoder_parameters()
|
dparam = glymur.lib._openjp2.set_default_decoder_parameters()
|
||||||
|
|
||||||
infile = filename.encode()
|
infile = filename.encode()
|
||||||
nelts = glymur.lib.openjp2._PATH_LEN - len(infile)
|
nelts = glymur.lib._openjp2.PATH_LEN - len(infile)
|
||||||
infile += b'0' * nelts
|
infile += b'0' * nelts
|
||||||
dparam.infile = infile
|
dparam.infile = infile
|
||||||
|
|
||||||
dparam.decod_format = codec_format
|
dparam.decod_format = codec_format
|
||||||
|
|
||||||
codec = glymur.lib.openjp2._create_decompress(codec_format)
|
codec = glymur.lib._openjp2.create_decompress(codec_format)
|
||||||
|
|
||||||
glymur.lib.openjp2._set_info_handler(codec, None)
|
glymur.lib._openjp2.set_info_handler(codec, None)
|
||||||
glymur.lib.openjp2._set_warning_handler(codec, None)
|
glymur.lib._openjp2.set_warning_handler(codec, None)
|
||||||
glymur.lib.openjp2._set_error_handler(codec, None)
|
glymur.lib._openjp2.set_error_handler(codec, None)
|
||||||
|
|
||||||
x = (filename, True)
|
x = (filename, True)
|
||||||
stream = glymur.lib.openjp2._stream_create_default_file_stream_v3(*x)
|
stream = glymur.lib._openjp2.stream_create_default_file_stream_v3(*x)
|
||||||
|
|
||||||
glymur.lib.openjp2._setup_decoder(codec, dparam)
|
glymur.lib._openjp2.setup_decoder(codec, dparam)
|
||||||
image = glymur.lib.openjp2._read_header(stream, codec)
|
image = glymur.lib._openjp2.read_header(stream, codec)
|
||||||
|
|
||||||
cstr_info = glymur.lib.openjp2._get_cstr_info(codec)
|
cstr_info = glymur.lib._openjp2.get_cstr_info(codec)
|
||||||
|
|
||||||
tile_ul = 0
|
tile_ul = 0
|
||||||
tile_ur = cstr_info.contents.tw - 1
|
tile_ur = cstr_info.contents.tw - 1
|
||||||
|
|
@ -94,18 +88,18 @@ class TestOpenJP2(unittest.TestCase):
|
||||||
self.tile_macro(codec, stream, image, tile_lr)
|
self.tile_macro(codec, stream, image, tile_lr)
|
||||||
self.tile_macro(codec, stream, image, tile_ll)
|
self.tile_macro(codec, stream, image, tile_ll)
|
||||||
|
|
||||||
glymur.lib.openjp2._destroy_cstr_info(cstr_info)
|
glymur.lib._openjp2.destroy_cstr_info(cstr_info)
|
||||||
|
|
||||||
glymur.lib.openjp2._end_decompress(codec, stream)
|
glymur.lib._openjp2.end_decompress(codec, stream)
|
||||||
glymur.lib.openjp2._destroy_codec(codec)
|
glymur.lib._openjp2.destroy_codec(codec)
|
||||||
glymur.lib.openjp2._stream_destroy_v3(stream)
|
glymur.lib._openjp2.stream_destroy_v3(stream)
|
||||||
glymur.lib.openjp2._image_destroy(image)
|
glymur.lib._openjp2.image_destroy(image)
|
||||||
|
|
||||||
def tile_decoder(self, x0=None, y0=None, x1=None, y1=None, filename=None,
|
def tile_decoder(self, x0=None, y0=None, x1=None, y1=None, filename=None,
|
||||||
codec_format=None):
|
codec_format=None):
|
||||||
x = (filename, True)
|
x = (filename, True)
|
||||||
stream = glymur.lib.openjp2._stream_create_default_file_stream_v3(*x)
|
stream = glymur.lib._openjp2.stream_create_default_file_stream_v3(*x)
|
||||||
dparam = glymur.lib.openjp2._set_default_decoder_parameters()
|
dparam = glymur.lib._openjp2.set_default_decoder_parameters()
|
||||||
|
|
||||||
dparam.decod_format = codec_format
|
dparam.decod_format = codec_format
|
||||||
|
|
||||||
|
|
@ -115,30 +109,30 @@ class TestOpenJP2(unittest.TestCase):
|
||||||
# do not use resolution reductions.
|
# do not use resolution reductions.
|
||||||
dparam.cp_reduce = 0
|
dparam.cp_reduce = 0
|
||||||
|
|
||||||
codec = glymur.lib.openjp2._create_decompress(codec_format)
|
codec = glymur.lib._openjp2.create_decompress(codec_format)
|
||||||
|
|
||||||
glymur.lib.openjp2._set_info_handler(codec, None)
|
glymur.lib._openjp2.set_info_handler(codec, None)
|
||||||
glymur.lib.openjp2._set_warning_handler(codec, None)
|
glymur.lib._openjp2.set_warning_handler(codec, None)
|
||||||
glymur.lib.openjp2._set_error_handler(codec, None)
|
glymur.lib._openjp2.set_error_handler(codec, None)
|
||||||
|
|
||||||
glymur.lib.openjp2._setup_decoder(codec, dparam)
|
glymur.lib._openjp2.setup_decoder(codec, dparam)
|
||||||
image = glymur.lib.openjp2._read_header(stream, codec)
|
image = glymur.lib._openjp2.read_header(stream, codec)
|
||||||
glymur.lib.openjp2._set_decode_area(codec, image, x0, y0, x1, y1)
|
glymur.lib._openjp2.set_decode_area(codec, image, x0, y0, x1, y1)
|
||||||
|
|
||||||
data = np.zeros((1150, 2048, 3), dtype=np.uint8)
|
data = np.zeros((1150, 2048, 3), dtype=np.uint8)
|
||||||
while True:
|
while True:
|
||||||
rargs = glymur.lib.openjp2._read_tile_header(codec, stream)
|
rargs = glymur.lib._openjp2.read_tile_header(codec, stream)
|
||||||
tidx = rargs[0]
|
tidx = rargs[0]
|
||||||
sz = rargs[1]
|
sz = rargs[1]
|
||||||
go_on = rargs[-1]
|
go_on = rargs[-1]
|
||||||
if not go_on:
|
if not go_on:
|
||||||
break
|
break
|
||||||
glymur.lib.openjp2._decode_tile_data(codec, tidx, data, sz, stream)
|
glymur.lib._openjp2.decode_tile_data(codec, tidx, data, sz, stream)
|
||||||
|
|
||||||
glymur.lib.openjp2._end_decompress(codec, stream)
|
glymur.lib._openjp2.end_decompress(codec, stream)
|
||||||
glymur.lib.openjp2._destroy_codec(codec)
|
glymur.lib._openjp2.destroy_codec(codec)
|
||||||
glymur.lib.openjp2._stream_destroy_v3(stream)
|
glymur.lib._openjp2.stream_destroy_v3(stream)
|
||||||
glymur.lib.openjp2._image_destroy(image)
|
glymur.lib._openjp2.image_destroy(image)
|
||||||
|
|
||||||
def tile_encoder(self, num_comps=None, tile_width=None, tile_height=None,
|
def tile_encoder(self, num_comps=None, tile_width=None, tile_height=None,
|
||||||
filename=None, codec=None, comp_prec=None,
|
filename=None, codec=None, comp_prec=None,
|
||||||
|
|
@ -150,7 +144,7 @@ class TestOpenJP2(unittest.TestCase):
|
||||||
data = np.random.random((tile_height, tile_width, num_comps))
|
data = np.random.random((tile_height, tile_width, num_comps))
|
||||||
data = (data * 255).astype(np.uint8)
|
data = (data * 255).astype(np.uint8)
|
||||||
|
|
||||||
l_param = glymur.lib.openjp2._set_default_encoder_parameters()
|
l_param = glymur.lib._openjp2.set_default_encoder_parameters()
|
||||||
|
|
||||||
l_param.tcp_numlayers = 1
|
l_param.tcp_numlayers = 1
|
||||||
l_param.cp_fixed_quality = 1
|
l_param.cp_fixed_quality = 1
|
||||||
|
|
@ -170,9 +164,9 @@ class TestOpenJP2(unittest.TestCase):
|
||||||
|
|
||||||
l_param.numresolution = 6
|
l_param.numresolution = 6
|
||||||
|
|
||||||
l_param.prog_order = glymur.lib.openjp2.LRCP
|
l_param.prog_order = glymur.lib._openjp2.LRCP
|
||||||
|
|
||||||
l_params = (glymur.lib.openjp2._image_comptparm_t * num_comps)()
|
l_params = (glymur.lib._openjp2.image_comptparm_t * num_comps)()
|
||||||
for j in range(num_comps):
|
for j in range(num_comps):
|
||||||
l_params[j].dx = 1
|
l_params[j].dx = 1
|
||||||
l_params[j].dy = 1
|
l_params[j].dy = 1
|
||||||
|
|
@ -183,38 +177,38 @@ class TestOpenJP2(unittest.TestCase):
|
||||||
l_params[j].x0 = 0
|
l_params[j].x0 = 0
|
||||||
l_params[j].y0 = 0
|
l_params[j].y0 = 0
|
||||||
|
|
||||||
codec = glymur.lib.openjp2._create_compress(codec)
|
codec = glymur.lib._openjp2.create_compress(codec)
|
||||||
|
|
||||||
glymur.lib.openjp2._set_info_handler(codec, None)
|
glymur.lib._openjp2.set_info_handler(codec, None)
|
||||||
glymur.lib.openjp2._set_warning_handler(codec, None)
|
glymur.lib._openjp2.set_warning_handler(codec, None)
|
||||||
glymur.lib.openjp2._set_error_handler(codec, None)
|
glymur.lib._openjp2.set_error_handler(codec, None)
|
||||||
|
|
||||||
cspace = glymur.lib.openjp2._CLRSPC_SRGB
|
cspace = glymur.lib._openjp2.CLRSPC_SRGB
|
||||||
l_image = glymur.lib.openjp2._image_tile_create(l_params, cspace)
|
l_image = glymur.lib._openjp2.image_tile_create(l_params, cspace)
|
||||||
|
|
||||||
l_image.contents.x0 = 0
|
l_image.contents.x0 = 0
|
||||||
l_image.contents.y0 = 0
|
l_image.contents.y0 = 0
|
||||||
l_image.contents.x1 = image_width
|
l_image.contents.x1 = image_width
|
||||||
l_image.contents.y1 = image_height
|
l_image.contents.y1 = image_height
|
||||||
l_image.contents.color_space = glymur.lib.openjp2._CLRSPC_SRGB
|
l_image.contents.color_space = glymur.lib._openjp2.CLRSPC_SRGB
|
||||||
|
|
||||||
glymur.lib.openjp2._setup_encoder(codec, l_param, l_image)
|
glymur.lib._openjp2.setup_encoder(codec, l_param, l_image)
|
||||||
|
|
||||||
x = (filename, False)
|
x = (filename, False)
|
||||||
stream = glymur.lib.openjp2._stream_create_default_file_stream_v3(*x)
|
stream = glymur.lib._openjp2.stream_create_default_file_stream_v3(*x)
|
||||||
glymur.lib.openjp2._start_compress(codec, l_image, stream)
|
glymur.lib._openjp2.start_compress(codec, l_image, stream)
|
||||||
|
|
||||||
for j in np.arange(num_tiles):
|
for j in np.arange(num_tiles):
|
||||||
glymur.lib.openjp2._write_tile(codec, j, data, tile_size, stream)
|
glymur.lib._openjp2.write_tile(codec, j, data, tile_size, stream)
|
||||||
|
|
||||||
glymur.lib.openjp2._end_compress(codec, stream)
|
glymur.lib._openjp2.end_compress(codec, stream)
|
||||||
glymur.lib.openjp2._stream_destroy_v3(stream)
|
glymur.lib._openjp2.stream_destroy_v3(stream)
|
||||||
glymur.lib.openjp2._destroy_codec(codec)
|
glymur.lib._openjp2.destroy_codec(codec)
|
||||||
glymur.lib.openjp2._image_destroy(l_image)
|
glymur.lib._openjp2.image_destroy(l_image)
|
||||||
|
|
||||||
def tte0_setup(self, filename):
|
def tte0_setup(self, filename):
|
||||||
kwargs = {'filename': filename,
|
kwargs = {'filename': filename,
|
||||||
'codec': glymur.lib.openjp2._CODEC_J2K,
|
'codec': glymur.lib._openjp2.CODEC_J2K,
|
||||||
'comp_prec': 8,
|
'comp_prec': 8,
|
||||||
'irreversible': 1,
|
'irreversible': 1,
|
||||||
'num_comps': 3,
|
'num_comps': 3,
|
||||||
|
|
@ -241,12 +235,12 @@ class TestOpenJP2(unittest.TestCase):
|
||||||
'x1': 1000,
|
'x1': 1000,
|
||||||
'y1': 1000,
|
'y1': 1000,
|
||||||
'filename': tfile.name,
|
'filename': tfile.name,
|
||||||
'codec_format': glymur.lib.openjp2._CODEC_J2K}
|
'codec_format': glymur.lib._openjp2.CODEC_J2K}
|
||||||
self.tile_decoder(**kwargs)
|
self.tile_decoder(**kwargs)
|
||||||
|
|
||||||
def tte1_setup(self, filename):
|
def tte1_setup(self, filename):
|
||||||
kwargs = {'filename': filename,
|
kwargs = {'filename': filename,
|
||||||
'codec': glymur.lib.openjp2._CODEC_J2K,
|
'codec': glymur.lib._openjp2.CODEC_J2K,
|
||||||
'comp_prec': 8,
|
'comp_prec': 8,
|
||||||
'irreversible': 1,
|
'irreversible': 1,
|
||||||
'num_comps': 3,
|
'num_comps': 3,
|
||||||
|
|
@ -273,7 +267,7 @@ class TestOpenJP2(unittest.TestCase):
|
||||||
'x1': 128,
|
'x1': 128,
|
||||||
'y1': 128,
|
'y1': 128,
|
||||||
'filename': tfile.name,
|
'filename': tfile.name,
|
||||||
'codec_format': glymur.lib.openjp2._CODEC_J2K}
|
'codec_format': glymur.lib._openjp2.CODEC_J2K}
|
||||||
self.tile_decoder(**kwargs)
|
self.tile_decoder(**kwargs)
|
||||||
|
|
||||||
def test_rta1(self):
|
def test_rta1(self):
|
||||||
|
|
@ -281,12 +275,12 @@ class TestOpenJP2(unittest.TestCase):
|
||||||
# Runs test designated rta1 in OpenJPEG test suite.
|
# Runs test designated rta1 in OpenJPEG test suite.
|
||||||
self.tte1_setup(tfile.name)
|
self.tte1_setup(tfile.name)
|
||||||
|
|
||||||
kwargs = {'codec_format': glymur.lib.openjp2._CODEC_J2K}
|
kwargs = {'codec_format': glymur.lib._openjp2.CODEC_J2K}
|
||||||
self.j2k_random_tile_access(tfile.name, **kwargs)
|
self.j2k_random_tile_access(tfile.name, **kwargs)
|
||||||
|
|
||||||
def tte2_setup(self, filename):
|
def tte2_setup(self, filename):
|
||||||
kwargs = {'filename': filename,
|
kwargs = {'filename': filename,
|
||||||
'codec': glymur.lib.openjp2._CODEC_JP2,
|
'codec': glymur.lib._openjp2.CODEC_JP2,
|
||||||
'comp_prec': 8,
|
'comp_prec': 8,
|
||||||
'irreversible': 1,
|
'irreversible': 1,
|
||||||
'num_comps': 3,
|
'num_comps': 3,
|
||||||
|
|
@ -312,7 +306,7 @@ class TestOpenJP2(unittest.TestCase):
|
||||||
'x1': 128,
|
'x1': 128,
|
||||||
'y1': 128,
|
'y1': 128,
|
||||||
'filename': tfile.name,
|
'filename': tfile.name,
|
||||||
'codec_format': glymur.lib.openjp2._CODEC_JP2}
|
'codec_format': glymur.lib._openjp2.CODEC_JP2}
|
||||||
self.tile_decoder(**kwargs)
|
self.tile_decoder(**kwargs)
|
||||||
|
|
||||||
def test_rta2(self):
|
def test_rta2(self):
|
||||||
|
|
@ -320,12 +314,12 @@ class TestOpenJP2(unittest.TestCase):
|
||||||
# Runs test designated rta2 in OpenJPEG test suite.
|
# Runs test designated rta2 in OpenJPEG test suite.
|
||||||
self.tte2_setup(tfile.name)
|
self.tte2_setup(tfile.name)
|
||||||
|
|
||||||
kwargs = {'codec_format': glymur.lib.openjp2._CODEC_JP2}
|
kwargs = {'codec_format': glymur.lib._openjp2.CODEC_JP2}
|
||||||
self.j2k_random_tile_access(tfile.name, **kwargs)
|
self.j2k_random_tile_access(tfile.name, **kwargs)
|
||||||
|
|
||||||
def tte3_setup(self, filename):
|
def tte3_setup(self, filename):
|
||||||
kwargs = {'filename': filename,
|
kwargs = {'filename': filename,
|
||||||
'codec': glymur.lib.openjp2._CODEC_J2K,
|
'codec': glymur.lib._openjp2.CODEC_J2K,
|
||||||
'comp_prec': 8,
|
'comp_prec': 8,
|
||||||
'irreversible': 1,
|
'irreversible': 1,
|
||||||
'num_comps': 1,
|
'num_comps': 1,
|
||||||
|
|
@ -345,12 +339,12 @@ class TestOpenJP2(unittest.TestCase):
|
||||||
with tempfile.NamedTemporaryFile(suffix=".j2k") as tfile:
|
with tempfile.NamedTemporaryFile(suffix=".j2k") as tfile:
|
||||||
self.tte3_setup(tfile.name)
|
self.tte3_setup(tfile.name)
|
||||||
|
|
||||||
kwargs = {'codec_format': glymur.lib.openjp2._CODEC_J2K}
|
kwargs = {'codec_format': glymur.lib._openjp2.CODEC_J2K}
|
||||||
self.j2k_random_tile_access(tfile.name, **kwargs)
|
self.j2k_random_tile_access(tfile.name, **kwargs)
|
||||||
|
|
||||||
def tte4_setup(self, filename):
|
def tte4_setup(self, filename):
|
||||||
kwargs = {'filename': filename,
|
kwargs = {'filename': filename,
|
||||||
'codec': glymur.lib.openjp2._CODEC_J2K,
|
'codec': glymur.lib._openjp2.CODEC_J2K,
|
||||||
'comp_prec': 8,
|
'comp_prec': 8,
|
||||||
'irreversible': 0,
|
'irreversible': 0,
|
||||||
'num_comps': 1,
|
'num_comps': 1,
|
||||||
|
|
@ -370,12 +364,12 @@ class TestOpenJP2(unittest.TestCase):
|
||||||
with tempfile.NamedTemporaryFile(suffix=".j2k") as tfile:
|
with tempfile.NamedTemporaryFile(suffix=".j2k") as tfile:
|
||||||
self.tte4_setup(tfile.name)
|
self.tte4_setup(tfile.name)
|
||||||
|
|
||||||
kwargs = {'codec_format': glymur.lib.openjp2._CODEC_J2K}
|
kwargs = {'codec_format': glymur.lib._openjp2.CODEC_J2K}
|
||||||
self.j2k_random_tile_access(tfile.name, **kwargs)
|
self.j2k_random_tile_access(tfile.name, **kwargs)
|
||||||
|
|
||||||
def tte5_setup(self, filename):
|
def tte5_setup(self, filename):
|
||||||
kwargs = {'filename': filename,
|
kwargs = {'filename': filename,
|
||||||
'codec': glymur.lib.openjp2._CODEC_J2K,
|
'codec': glymur.lib._openjp2.CODEC_J2K,
|
||||||
'comp_prec': 8,
|
'comp_prec': 8,
|
||||||
'irreversible': 0,
|
'irreversible': 0,
|
||||||
'num_comps': 1,
|
'num_comps': 1,
|
||||||
|
|
@ -395,7 +389,7 @@ class TestOpenJP2(unittest.TestCase):
|
||||||
with tempfile.NamedTemporaryFile(suffix=".j2k") as tfile:
|
with tempfile.NamedTemporaryFile(suffix=".j2k") as tfile:
|
||||||
self.tte5_setup(tfile.name)
|
self.tte5_setup(tfile.name)
|
||||||
|
|
||||||
kwargs = {'codec_format': glymur.lib.openjp2._CODEC_J2K}
|
kwargs = {'codec_format': glymur.lib._openjp2.CODEC_J2K}
|
||||||
self.j2k_random_tile_access(tfile.name, **kwargs)
|
self.j2k_random_tile_access(tfile.name, **kwargs)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import unittest
|
||||||
|
|
||||||
import glymur
|
import glymur
|
||||||
|
|
||||||
@unittest.skipIf(glymur.lib.openjpeg._OPENJPEG is None,
|
@unittest.skipIf(glymur.lib._openjpeg.OPENJPEG is None,
|
||||||
"Missing openjpeg library.")
|
"Missing openjpeg library.")
|
||||||
class TestOpenJPEG(unittest.TestCase):
|
class TestOpenJPEG(unittest.TestCase):
|
||||||
|
|
||||||
|
|
@ -14,15 +14,15 @@ class TestOpenJPEG(unittest.TestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_version(self):
|
def test_version(self):
|
||||||
v = glymur.lib.openjpeg._version()
|
v = glymur.lib._openjpeg.version()
|
||||||
parts = v.split('.')
|
parts = v.split('.')
|
||||||
self.assertEqual(parts[0], '1')
|
self.assertEqual(parts[0], '1')
|
||||||
self.assertEqual(parts[1], '5')
|
self.assertEqual(parts[1], '5')
|
||||||
|
|
||||||
def test_set_default_decoder_parameters(self):
|
def test_set_default_decoder_parameters(self):
|
||||||
# Verify that we properly set the default decode parameters.
|
# Verify that we properly set the default decode parameters.
|
||||||
dp = glymur.lib.openjpeg.dparameters_t()
|
dp = glymur.lib._openjpeg.dparameters_t()
|
||||||
glymur.lib.openjpeg._set_default_decoder_parameters(ctypes.byref(dp))
|
glymur.lib._openjpeg.set_default_decoder_parameters(ctypes.byref(dp))
|
||||||
|
|
||||||
self.assertEqual(dp.cp_reduce, 0)
|
self.assertEqual(dp.cp_reduce, 0)
|
||||||
self.assertEqual(dp.cp_layer, 0)
|
self.assertEqual(dp.cp_layer, 0)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ else:
|
||||||
import glymur
|
import glymur
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(glymur.lib.openjp2._OPENJP2 is None,
|
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||||
"Missing openjp2 library.")
|
"Missing openjp2 library.")
|
||||||
class TestCallbacks(unittest.TestCase):
|
class TestCallbacks(unittest.TestCase):
|
||||||
|
|
||||||
|
|
@ -60,7 +60,7 @@ class TestCallbacks(unittest.TestCase):
|
||||||
self.assertEqual(actual, expected)
|
self.assertEqual(actual, expected)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(glymur.lib.openjp2._OPENJPEG is None,
|
@unittest.skipIf(glymur.lib.openjp2.OPENJPEG is None,
|
||||||
"Missing openjpeg library.")
|
"Missing openjpeg library.")
|
||||||
class TestCallbacks15(unittest.TestCase):
|
class TestCallbacks15(unittest.TestCase):
|
||||||
"""This test suite is for OpenJPEG 1.5.1 properties.
|
"""This test suite is for OpenJPEG 1.5.1 properties.
|
||||||
|
|
@ -69,13 +69,13 @@ class TestCallbacks15(unittest.TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
# Monkey patch the package so as to use OPENJPEG instead of OPENJP2
|
# Monkey patch the package so as to use OPENJPEG instead of OPENJP2
|
||||||
cls.openjp2 = glymur.lib.openjp2._OPENJP2
|
cls.openjp2 = glymur.lib.openjp2.OPENJP2
|
||||||
glymur.lib.openjp2._OPENJP2 = None
|
glymur.lib.openjp2.OPENJP2 = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
# Restore OPENJP2
|
# Restore OPENJP2
|
||||||
glymur.lib.openjp2._OPENJP2 = cls.openjp2
|
glymur.lib.openjp2.OPENJP2 = cls.openjp2
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
# Save sys.stdout.
|
# Save sys.stdout.
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ from glymur.lib import openjp2 as opj2
|
||||||
|
|
||||||
|
|
||||||
@unittest.skip("Cannot work when both OPENJPEG and OPENJP2 are both present.")
|
@unittest.skip("Cannot work when both OPENJPEG and OPENJP2 are both present.")
|
||||||
@unittest.skipIf(glymur.lib.openjp2._OPENJP2 is None,
|
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||||
"Needs openjp2 library first before these tests make sense.")
|
"Needs openjp2 library first before these tests make sense.")
|
||||||
@unittest.skipIf(sys.hexversion < 0x03020000,
|
@unittest.skipIf(sys.hexversion < 0x03020000,
|
||||||
"Uses features introduced in 3.2.")
|
"Uses features introduced in 3.2.")
|
||||||
|
|
@ -55,7 +55,7 @@ class TestSuite(unittest.TestCase):
|
||||||
filename = os.path.join(configdir, 'glymurrc')
|
filename = os.path.join(configdir, 'glymurrc')
|
||||||
with open(filename, 'wb') as tfile:
|
with open(filename, 'wb') as tfile:
|
||||||
tfile.write('[library]\n'.encode())
|
tfile.write('[library]\n'.encode())
|
||||||
libloc = glymur.lib.openjp2._OPENJP2._name
|
libloc = glymur.lib.openjp2.OPENJP2._name
|
||||||
line = 'openjp2: {0}\n'.format(libloc)
|
line = 'openjp2: {0}\n'.format(libloc)
|
||||||
tfile.write(line.encode())
|
tfile.write(line.encode())
|
||||||
tfile.flush()
|
tfile.flush()
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ def load_tests(loader, tests, ignore):
|
||||||
return tests
|
return tests
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(glymur.lib.openjp2._OPENJP2 is None,
|
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||||
"Missing openjp2 library.")
|
"Missing openjp2 library.")
|
||||||
class TestChannelDefinition(unittest.TestCase):
|
class TestChannelDefinition(unittest.TestCase):
|
||||||
|
|
||||||
|
|
@ -409,7 +409,7 @@ class TestColourSpecificationBox(unittest.TestCase):
|
||||||
approximation=approx)
|
approximation=approx)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(glymur.lib.openjp2._OPENJP2 is None,
|
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||||
"Missing openjp2 library.")
|
"Missing openjp2 library.")
|
||||||
class TestJp2Boxes(unittest.TestCase):
|
class TestJp2Boxes(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,12 +33,12 @@ except:
|
||||||
|
|
||||||
# Doc tests should be run as well.
|
# Doc tests should be run as well.
|
||||||
def load_tests(loader, tests, ignore):
|
def load_tests(loader, tests, ignore):
|
||||||
if glymur.lib.openjp2._OPENJP2 is not None:
|
if glymur.lib.openjp2.OPENJP2 is not None:
|
||||||
tests.addTests(doctest.DocTestSuite('glymur.jp2k'))
|
tests.addTests(doctest.DocTestSuite('glymur.jp2k'))
|
||||||
return tests
|
return tests
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(glymur.lib.openjp2._OPENJP2 is None,
|
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||||
"Missing openjp2 library.")
|
"Missing openjp2 library.")
|
||||||
class TestJp2k(unittest.TestCase):
|
class TestJp2k(unittest.TestCase):
|
||||||
|
|
||||||
|
|
@ -648,20 +648,20 @@ class TestJp2k(unittest.TestCase):
|
||||||
self.assertFalse('Make' in exif['Image'].keys())
|
self.assertFalse('Make' in exif['Image'].keys())
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(glymur.lib.openjpeg._OPENJPEG is None,
|
@unittest.skipIf(glymur.lib.openjpeg.OPENJPEG is None,
|
||||||
"Missing openjpeg library.")
|
"Missing openjpeg library.")
|
||||||
class TestJp2k15(unittest.TestCase):
|
class TestJp2k15(unittest.TestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
# Monkey patch the package so as to use OPENJPEG instead of OPENJP2
|
# Monkey patch the package so as to use OPENJPEG instead of OPENJP2
|
||||||
cls.openjp2 = glymur.lib.openjp2._OPENJP2
|
cls.openjp2 = glymur.lib.openjp2.OPENJP2
|
||||||
glymur.lib.openjp2._OPENJP2 = None
|
glymur.lib.openjp2.OPENJP2 = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
# Restore OPENJP2
|
# Restore OPENJP2
|
||||||
glymur.lib.openjp2._OPENJP2 = cls.openjp2
|
glymur.lib.openjp2.OPENJP2 = cls.openjp2
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.jp2file = glymur.data.nemo()
|
self.jp2file = glymur.data.nemo()
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ except:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(glymur.lib.openjp2._OPENJP2 is None,
|
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||||
"Missing openjp2 library.")
|
"Missing openjp2 library.")
|
||||||
@unittest.skipIf(data_root is None,
|
@unittest.skipIf(data_root is None,
|
||||||
"OPJ_DATA_ROOT environment variable not set")
|
"OPJ_DATA_ROOT environment variable not set")
|
||||||
|
|
@ -7333,7 +7333,7 @@ class TestSuiteDump(unittest.TestCase):
|
||||||
[8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10])
|
[8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10])
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(glymur.lib.openjpeg._OPENJPEG is None,
|
@unittest.skipIf(glymur.lib.openjpeg.OPENJPEG is None,
|
||||||
"Missing openjpeg library.")
|
"Missing openjpeg library.")
|
||||||
@unittest.skipIf(data_root is None,
|
@unittest.skipIf(data_root is None,
|
||||||
"OPJ_DATA_ROOT environment variable not set")
|
"OPJ_DATA_ROOT environment variable not set")
|
||||||
|
|
@ -7343,13 +7343,13 @@ class TestSuite15(unittest.TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
# Monkey patch the package so as to use OPENJPEG instead of OPENJP2
|
# Monkey patch the package so as to use OPENJPEG instead of OPENJP2
|
||||||
cls.openjp2 = glymur.lib.openjp2._OPENJP2
|
cls.openjp2 = glymur.lib.openjp2.OPENJP2
|
||||||
glymur.lib.openjp2._OPENJP2 = None
|
glymur.lib.openjp2.OPENJP2 = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
# Restore OPENJP2
|
# Restore OPENJP2
|
||||||
glymur.lib.openjp2._OPENJP2 = cls.openjp2
|
glymur.lib.openjp2.OPENJP2 = cls.openjp2
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ def read_image(infile):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(glymur.lib.openjp2._OPENJP2 is None,
|
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||||
"Missing openjp2 library.")
|
"Missing openjp2 library.")
|
||||||
@unittest.skipIf(no_read_backend, no_read_backend_msg)
|
@unittest.skipIf(no_read_backend, no_read_backend_msg)
|
||||||
@unittest.skipIf(data_root is None,
|
@unittest.skipIf(data_root is None,
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ def read_image(infile):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(glymur.lib.openjp2._OPENJP2 is None,
|
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||||
"Missing openjp2 library.")
|
"Missing openjp2 library.")
|
||||||
@unittest.skipIf(no_read_backend, no_read_backend_msg)
|
@unittest.skipIf(no_read_backend, no_read_backend_msg)
|
||||||
@unittest.skipIf(data_root is None,
|
@unittest.skipIf(data_root is None,
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ except:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(glymur.lib.openjp2._OPENJP2 is None,
|
@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None,
|
||||||
"Missing openjp2 library.")
|
"Missing openjp2 library.")
|
||||||
class TestPrintingNeedsLib(unittest.TestCase):
|
class TestPrintingNeedsLib(unittest.TestCase):
|
||||||
"""These tests require the library, mostly in order to just setup the test.
|
"""These tests require the library, mostly in order to just setup the test.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue