Merge branch 'issue44' into devel

This commit is contained in:
John Evans 2013-06-14 16:33:03 -04:00
commit 32c71dfc25

View file

@ -138,7 +138,7 @@ class Jp2k(Jp2kBox):
f.seek(0)
self.box = self._parse_superbox(f)
def write(self, data, cratios=None, eph=False, psnr=None, numres=None,
def write(self, img_array, cratios=None, eph=False, psnr=None, numres=None,
cbsize=None, psizes=None, grid_offset=None, sop=False,
subsam=None, tilesize=None, prog=None, modesw=None,
colorspace=None, verbose=False):
@ -150,7 +150,7 @@ class Jp2k(Jp2kBox):
Parameters
----------
data : array
img_array : ndarray
Image data to be written to file.
callbacks : bool, optional
If true, enable default info handler such that INFO messages
@ -307,19 +307,19 @@ class Jp2k(Jp2kBox):
msg = "Cannot specify cratios and psnr together."
raise RuntimeError(msg)
if data.ndim == 2:
numrows, numcols = data.shape
data = data.reshape(numrows, numcols, 1)
elif data.ndim == 3:
if img_array.ndim == 2:
numrows, numcols = img_array.shape
img_array = img_array.reshape(numrows, numcols, 1)
elif img_array.ndim == 3:
pass
else:
msg = "{0}D imagery is not allowed.".format(data.ndim)
msg = "{0}D imagery is not allowed.".format(img_array.ndim)
raise IOError(msg)
numrows, numcols, num_comps = data.shape
numrows, numcols, num_comps = img_array.shape
if colorspace is None:
if data.shape[2] == 1 or data.shape[2] == 2:
if img_array.shape[2] == 1 or img_array.shape[2] == 2:
colorspace = opj2._CLRSPC_GRAY
else:
# No YCC unless specifically told to do so.
@ -331,15 +331,15 @@ class Jp2k(Jp2kBox):
if colorspace not in ('rgb', 'grey', 'gray'):
msg = 'Invalid colorspace "{0}"'.format(colorspace)
raise IOError(msg)
elif colorspace == 'rgb' and data.shape[2] < 3:
elif colorspace == 'rgb' and img_array.shape[2] < 3:
msg = 'RGB colorspace requires at least 3 components.'
raise IOError(msg)
else:
colorspace = _cspace_map[colorspace]
if data.dtype == np.uint8:
if img_array.dtype == np.uint8:
comp_prec = 8
elif data.dtype == np.uint16:
elif img_array.dtype == np.uint16:
comp_prec = 16
else:
raise RuntimeError("unhandled datatype")
@ -368,7 +368,7 @@ class Jp2k(Jp2kBox):
# Stage the image data to the openjpeg data structure.
for k in range(0, num_comps):
layer = np.ascontiguousarray(data[:, :, k], dtype=np.int32)
layer = np.ascontiguousarray(img_array[:, :, k], dtype=np.int32)
dest = image.contents.comps[k].data
src = layer.ctypes.data
ctypes.memmove(dest, src, layer.nbytes)
@ -419,7 +419,7 @@ class Jp2k(Jp2kBox):
Returns
-------
result : array
img_array : ndarray
The image data.
Raises
@ -451,18 +451,18 @@ class Jp2k(Jp2kBox):
msg = "Components must all have the same subsampling factors."
raise IOError(msg)
data = self._read_common(reduce=reduce,
layer=layer,
area=area,
tile=tile,
verbose=verbose,
as_bands=False)
img_array = self._read_common(reduce=reduce,
layer=layer,
area=area,
tile=tile,
verbose=verbose,
as_bands=False)
if data.shape[2] == 1:
data = data.view()
data.shape = data.shape[0:2]
if img_array.shape[2] == 1:
img_array = img_array.view()
img_array.shape = img_array.shape[0:2]
return data
return img_array
def _read_common(self, reduce=0, layer=0, area=None, tile=None,
verbose=False, as_bands=False):
@ -486,7 +486,7 @@ class Jp2k(Jp2kBox):
Returns
-------
data : list or array
img_array : ndarray
The individual image components or a single array.
"""
dparam = opj2._set_default_decoder_parameters()