Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0b9835ccd |
1 changed files with 22 additions and 20 deletions
|
|
@ -205,28 +205,30 @@ class Jp2k(Jp2kBox):
|
||||||
if self._shape is not None:
|
if self._shape is not None:
|
||||||
return self._shape
|
return self._shape
|
||||||
|
|
||||||
cstr = self.codestream
|
if self._codec_format == opj2.CODEC_J2K:
|
||||||
height = cstr.segment[1].ysiz
|
# get the image size from the codestream
|
||||||
width = cstr.segment[1].xsiz
|
cstr = self.codestream
|
||||||
num_components = len(cstr.segment[1].xrsiz)
|
height = cstr.segment[1].ysiz
|
||||||
|
width = cstr.segment[1].xsiz
|
||||||
|
num_components = len(cstr.segment[1].xrsiz)
|
||||||
|
else:
|
||||||
|
# try to get the image size from the IHDR box
|
||||||
|
jp2h = [box for box in self.box if box.box_id == 'jp2h'][0]
|
||||||
|
ihdr = [box for box in jp2h.box if box.box_id == 'ihdr'][0]
|
||||||
|
|
||||||
|
height, width = ihdr.height, ihdr.width
|
||||||
|
num_components = ihdr.num_components
|
||||||
|
|
||||||
|
if num_components == 1:
|
||||||
|
# but if there is a PCLR box, then we need to check that as
|
||||||
|
# well, as that turns a single-channel image into a
|
||||||
|
# multi-channel image
|
||||||
|
pclr = [box for box in jp2h.box if box.box_id == 'pclr']
|
||||||
|
if len(pclr) > 0:
|
||||||
|
num_components = len(pclr[0].signed)
|
||||||
|
|
||||||
# If JP2 and a palette box is present, then determine the shape from
|
|
||||||
# that.
|
|
||||||
if num_components == 1:
|
if num_components == 1:
|
||||||
if self._codec_format == opj2.CODEC_J2K:
|
self.shape = (height, width)
|
||||||
# There's no palette box or component mapping in a J2K file.
|
|
||||||
# The 3rd component in the shape would then be 1, but we'll
|
|
||||||
# ignore that.
|
|
||||||
self.shape = (height, width)
|
|
||||||
else:
|
|
||||||
jp2h = [box for box in self.box if box.box_id == 'jp2h'][0]
|
|
||||||
pclr = [box for box in jp2h.box if box.box_id == 'pclr']
|
|
||||||
if len(pclr) == 0:
|
|
||||||
# No palette box, so just one component, which we will
|
|
||||||
# ignore.
|
|
||||||
self.shape = (height, width)
|
|
||||||
else:
|
|
||||||
self.shape = (height, width, len(pclr[0].signed))
|
|
||||||
else:
|
else:
|
||||||
self.shape = (height, width, num_components)
|
self.shape = (height, width, num_components)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue