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