pep8 work

This commit is contained in:
jevans 2014-12-22 23:20:48 -05:00 • committed by John Evans
commit 13cc6aa7e5
19 changed files with 822 additions and 925 deletions

View file

@ -2,3 +2,5 @@
from . import openjp2 as openjp2
from . import openjpeg as openjpeg
from . import c
__all__ = [openjp2, openjpeg, c]

View file

@ -19,18 +19,21 @@ else:
from configparser import NoOptionError
# default library locations for MacPorts
_macports_default_location = {
'openjp2': '/opt/local/lib/libopenjp2.dylib',
'openjpeg': '/opt/local/lib/libopenjpeg.dylib'
}
_macports_default_location = {'openjp2': '/opt/local/lib/libopenjp2.dylib',
'openjpeg': '/opt/local/lib/libopenjpeg.dylib'}
# default library locations on Windows
_windows_default_location = {
'openjp2': os.path.join('C:\\', 'Program files', 'OpenJPEG 2.0',
'bin', 'openjp2.dll'),
'openjpeg': os.path.join('C:\\', 'Program files', 'OpenJPEG 1.5',
'bin', 'openjpeg.dll')
}
_windows_default_location = {'openjp2': os.path.join('C:\\',
'Program files',
'OpenJPEG 2.0',
'bin',
'openjp2.dll'),
'openjpeg': os.path.join('C:\\',
'Program files',
'OpenJPEG 1.5',
'bin',
'openjpeg.dll')}
def glymurrc_fname():
"""Return the path to the configuration file.
@ -55,8 +58,9 @@ def glymurrc_fname():
# didn't find a configuration file.
return None
def load_openjpeg_library(libname):
path = read_config_file(libname)
if path is not None:
return load_library_handle(path)
@ -79,13 +83,15 @@ def load_openjpeg_library(libname):
return load_library_handle(path)
def load_library_handle(path):
"""Load the library, return the ctypes handle."""
if path is None or path in ['None', 'none']:
# Either could not find a library via ctypes or user-configuration-file,
# or we could not find it in any of the default locations, or possibly
# the user intentionally does not want one of the libraries to load.
# Either could not find a library via ctypes or
# user-configuration-file, or we could not find it in any of the
# default locations, or possibly the user intentionally does not want
# one of the libraries to load.
return None
try:
@ -94,10 +100,10 @@ def load_library_handle(path):
else:
opj_lib = ctypes.CDLL(path)
except (TypeError, OSError):
msg = 'The library specified by configuration file at {0} could not be '
msg += 'loaded.'
warnings.warn(msg.format(path), UserWarning)
opj_lib = None
msg = 'The library specified by configuration file at {0} could not '
msg += 'be loaded.'
warnings.warn(msg.format(path), UserWarning)
opj_lib = None
return opj_lib
@ -130,6 +136,7 @@ def read_config_file(libname):
path = None
return path
def glymur_config():
"""
Try to ascertain locations of openjp2, openjpeg libraries.
@ -147,6 +154,7 @@ def glymur_config():
warnings.warn(msg)
return tuple(lst)
def get_configdir():
"""Return string representing the configuration directory.

View file

@ -410,7 +410,6 @@ class CompressionParametersType(ctypes.Structure):
for j in range(self.numpocs):
msg += " [#{0}]:".format(j)
msg += " {0}".format(str(self.poc[j]))
msg += textwrap.indent(textstr, ' ' * 12)
elif field_name in ['tcp_rates', 'tcp_distoratio']:
lst = []
@ -740,28 +739,6 @@ def encode(codec, stream):
OPENJP2.opj_encode(codec, stream)
def get_cstr_info(codec):
"""get the codestream information from the codec
Wraps the openjp2 library function opj_get_cstr_info.
Parameters
----------
codec : CODEC_TYPE
The jpeg2000 codec.
Returns
-------
cstr_info_p : CodestreamInfoV2
Reference to codestream information.
"""
OPENJP2.opj_get_cstr_info.argtypes = [CODEC_TYPE]
OPENJP2.opj_get_cstr_info.restype = ctypes.POINTER(CodestreamInfoV2)
cstr_info_p = OPENJP2.opj_get_cstr_info(codec)
return cstr_info_p
def get_decoded_tile(codec, stream, imagep, tile_index):
"""get the decoded tile from the codec
@ -792,23 +769,6 @@ def get_decoded_tile(codec, stream, imagep, tile_index):
OPENJP2.opj_get_decoded_tile(codec, stream, imagep, tile_index)
def destroy_cstr_info(cstr_info_p):
"""destroy codestream information after compression or decompression
Wraps the openjp2 library function opj_destroy_cstr_info.
Parameters
----------
cstr_info_p : CodestreamInfoV2 pointer
Pointer to codestream info structure.
"""
ARGTYPES = [ctypes.POINTER(ctypes.POINTER(CodestreamInfoV2))]
OPENJP2.opj_destroy_cstr_info.argtypes = ARGTYPES
OPENJP2.opj_destroy_cstr_info.restype = ctypes.c_void_p
OPENJP2.opj_destroy_cstr_info(ctypes.byref(cstr_info_p))
def end_compress(codec, stream):
"""End of compressing the current image.

View file

@ -6,8 +6,6 @@
import ctypes
import sys
import numpy as np
from .config import glymur_config
_, OPENJPEG = glymur_config()
@ -364,9 +362,9 @@ class DecompressionParametersType(ctypes.Structure):
class ImageComptParmType(ctypes.Structure):
"""Component parameters structure used by the opj_image_create function.
"""
_fields_ = [# XRsiz: horizontal separation of a sample of ith component
_fields_ = [("dx", ctypes.c_int),
# XRsiz: horizontal separation of a sample of ith component
# with respect to the reference grid
("dx", ctypes.c_int),
# YRsiz: vertical separation of a sample of ith component with
# respect to the reference grid */
@ -527,50 +525,6 @@ def destroy_decompress(dinfo):
OPENJPEG.opj_destroy_decompress(dinfo)
def image_cmptparm_t_from_np(np_image):
"""Return appropriate image_cmptparm_t based on given numpy array.
"""
try:
num_comps = np_image.shape[2]
except IndexError:
num_comps = 1
cmpt_parm_array_t = ImageCmptparmType * num_comps
tarr = cmpt_parm_array_t()
if np_image.dtype == np.uint8:
prec = 8
bpp = 8
sgnd = 0
elif np_image.dtype == np.int8:
prec = 8
bpp = 8
sgnd = 1
elif np_image.dtype == np.uint16:
prec = 16
bpp = 16
sgnd = 0
elif np_image.dtype == np.int16:
prec = 16
bpp = 16
sgnd = 1
else:
raise(TypeError("unhandled"))
for j in range(0, num_comps):
tarr[j].dx = 1
tarr[j].dy = 1
tarr[j].w = np_image.shape[1]
tarr[j].h = np_image.shape[0]
tarr[j].x0 = 0
tarr[j].y0 = 0
tarr[j].prec = prec
tarr[j].bpp = bpp
tarr[j].sgnd = sgnd
return(tarr)
def image_create(cmptparms, cspace):
"""Wrapper for openjpeg library function opj_image_create.
"""