starting work to allow full resolution slicing
This commit is contained in:
parent
3adb09e6f4
commit
276a74ecaa
1 changed files with 37 additions and 28 deletions
|
|
@ -770,38 +770,47 @@ class Jp2k(Jp2kBox):
|
||||||
else:
|
else:
|
||||||
raise IndexError("Illegal syntax.")
|
raise IndexError("Illegal syntax.")
|
||||||
|
|
||||||
if isinstance(pargs[0], tuple):
|
if not isinstance(pargs[0], tuple):
|
||||||
ridx = pargs[0][0]
|
msg = "Unexpected situation, slicing invoked, but not passed "
|
||||||
cidx = pargs[0][1]
|
msg += "a slice or tuple."
|
||||||
|
raise RuntimeError(msg)
|
||||||
|
|
||||||
if ((ridx.start is not None) or
|
# Assuming tuple from now on.
|
||||||
(ridx.stop is not None) or
|
ridx = pargs[0][0]
|
||||||
(cidx.start is not None) or
|
cidx = pargs[0][1]
|
||||||
(cidx.stop is not None)):
|
|
||||||
msg = "Only strides are supported when slicing a Jp2k object."
|
|
||||||
raise IndexError(msg)
|
|
||||||
|
|
||||||
if ridx.step is None and cidx.step is None:
|
if ((ridx.step is None) and (cidx.step is None)):
|
||||||
step = 1
|
# Slicing with full resolution.
|
||||||
elif ridx.step != cidx.step:
|
return self.read()[ridx, cidx]
|
||||||
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 ((ridx.start is not None) or
|
||||||
if len(pargs[0]) == 2:
|
(ridx.stop is not None) or
|
||||||
return data
|
(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 ridx.step is None and cidx.step is None:
|
||||||
if isinstance(pargs[0][2], slice):
|
step = 1
|
||||||
return data[:,:,pargs[0][2]]
|
elif ridx.step != cidx.step:
|
||||||
elif isinstance(pargs[0][2], int):
|
msg = "Row and column strides must be the same."
|
||||||
return data[:,:,pargs[0][2]]
|
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):
|
def read(self, **kwargs):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue