starting work to allow full resolution slicing

This commit is contained in:
John Evans 2014-09-12 10:06:09 -04:00
commit 276a74ecaa

View file

@ -770,38 +770,47 @@ class Jp2k(Jp2kBox):
else:
raise IndexError("Illegal syntax.")
if isinstance(pargs[0], tuple):
ridx = pargs[0][0]
cidx = pargs[0][1]
if not isinstance(pargs[0], tuple):
msg = "Unexpected situation, slicing invoked, but not passed "
msg += "a slice or tuple."
raise RuntimeError(msg)
if ((ridx.start is not None) or
(ridx.stop is not None) or
(cidx.start is not None) or
(cidx.stop is not None)):
msg = "Only strides are supported when slicing a Jp2k object."
raise IndexError(msg)
# Assuming tuple from now on.
ridx = pargs[0][0]
cidx = pargs[0][1]
if ridx.step is None and cidx.step is None:
step = 1
elif ridx.step != cidx.step:
msg = "Row and column strides must be the same."
raise IndexError(msg)
else:
step = ridx.step
if np.log2(step) != np.floor(np.log2(step)):
msg = "Row and column strides must be powers of 2."
raise IndexError(msg)
if ((ridx.step is None) and (cidx.step is None)):
# Slicing with full resolution.
return self.read()[ridx, cidx]
data = self.read(rlevel=np.int(np.log2(step)))
if len(pargs[0]) == 2:
return data
if ((ridx.start is not None) or
(ridx.stop is not None) or
(cidx.start is not None) or
(cidx.stop is not None)):
msg = "Only strides are supported when slicing a Jp2k object."
raise IndexError(msg)
# Ok, 3 arguments in pargs.
if isinstance(pargs[0][2], slice):
return data[:,:,pargs[0][2]]
elif isinstance(pargs[0][2], int):
return data[:,:,pargs[0][2]]
if ridx.step is None and cidx.step is None:
step = 1
elif ridx.step != cidx.step:
msg = "Row and column strides must be the same."
raise IndexError(msg)
else:
step = ridx.step
if np.log2(step) != np.floor(np.log2(step)):
msg = "Row and column strides must be powers of 2."
raise IndexError(msg)
data = self.read(rlevel=np.int(np.log2(step)))
if len(pargs[0]) == 2:
return data
# Ok, 3 arguments in pargs.
if isinstance(pargs[0][2], slice):
return data[:,:,pargs[0][2]]
elif isinstance(pargs[0][2], int):
return data[:,:,pargs[0][2]]
def read(self, **kwargs):