pep8 work, #67
This commit is contained in:
parent
36ea74a27e
commit
32dcb12823
1 changed files with 11 additions and 11 deletions
|
|
@ -621,21 +621,20 @@ class Jp2k(Jp2kBox):
|
||||||
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)
|
||||||
|
|
||||||
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)
|
||||||
|
|
@ -643,7 +642,7 @@ class Jp2k(Jp2kBox):
|
||||||
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]
|
||||||
if component.sgnd:
|
if component.sgnd:
|
||||||
if component.prec <= 8:
|
if component.prec <= 8:
|
||||||
|
|
@ -659,30 +658,31 @@ class Jp2k(Jp2kBox):
|
||||||
dtype = np.uint16
|
dtype = np.uint16
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("Unhandled precision, datatype")
|
raise RuntimeError("Unhandled precision, datatype")
|
||||||
|
|
||||||
nrows = image.contents.comps[0].h
|
nrows = image.contents.comps[0].h
|
||||||
ncols = image.contents.comps[0].w
|
ncols = image.contents.comps[0].w
|
||||||
ncomps = image.contents.numcomps
|
ncomps = image.contents.numcomps
|
||||||
data = np.zeros((nrows, ncols, ncomps), dtype)
|
data = np.zeros((nrows, ncols, ncomps), dtype)
|
||||||
|
|
||||||
for k in range(image.contents.numcomps):
|
for k in range(image.contents.numcomps):
|
||||||
component = image.contents.comps[k]
|
component = image.contents.comps[k]
|
||||||
nrows = component.h
|
nrows = component.h
|
||||||
ncols = component.w
|
ncols = component.w
|
||||||
|
|
||||||
if nrows == 0 or ncols == 0:
|
if nrows == 0 or ncols == 0:
|
||||||
# Letting this situation continue would segfault
|
# Letting this situation continue would segfault
|
||||||
# Python.
|
# Python.
|
||||||
msg = "Component {0} has dimensions {1} x {2}"
|
msg = "Component {0} has dimensions {1} x {2}"
|
||||||
msg = msg.format(k, nrows, ncols)
|
msg = msg.format(k, nrows, ncols)
|
||||||
raise IOError(msg)
|
raise IOError(msg)
|
||||||
|
|
||||||
addr = ctypes.addressof(component.data.contents)
|
addr = ctypes.addressof(component.data.contents)
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
warnings.simplefilter("ignore")
|
warnings.simplefilter("ignore")
|
||||||
x = np.ctypeslib.as_array( (ctypes.c_int32 * nrows * ncols).from_address(addr))
|
nelts = nrows * ncols
|
||||||
|
x = np.ctypeslib.as_array((ctypes.c_int32 * nelts).from_address(addr))
|
||||||
data[:, :, k] = np.reshape(x.astype(dtype), (nrows, ncols))
|
data[:, :, k] = np.reshape(x.astype(dtype), (nrows, ncols))
|
||||||
|
|
||||||
if data.shape[2] == 1:
|
if data.shape[2] == 1:
|
||||||
data = data.view()
|
data = data.view()
|
||||||
data.shape = data.shape[0:2]
|
data.shape = data.shape[0:2]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue