Glymur 0.14.6__py3-none-any.whl → 0.14.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
glymur/jp2box.py CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  References
4
4
  ----------
5
- .. [JP2K15444-1i] International Organization for Standardication. ISO/IEC
5
+ .. [JP2K15444-1i] International Organization for Standardization. ISO/IEC
6
6
  15444-1:2004 - Information technology -- JPEG 2000 image coding system:
7
7
  Core coding system
8
8
 
9
- .. [JP2K15444-2m] International Organization for Standardication. ISO/IEC
9
+ .. [JP2K15444-2m] International Organization for Standardization. ISO/IEC
10
10
  15444-2:2004 - Information technology -- JPEG 2000 image coding system:
11
11
  Extensions
12
12
  """
@@ -1065,7 +1065,7 @@ class ContiguousCodestreamBox(Jp2kBox):
1065
1065
  offset=-1
1066
1066
  ):
1067
1067
  super().__init__()
1068
- self._codestream = codestream
1068
+ self.codestream = codestream
1069
1069
  self.length = length
1070
1070
  self.offset = offset
1071
1071
  self.main_header_offset = main_header_offset
@@ -1073,24 +1073,6 @@ class ContiguousCodestreamBox(Jp2kBox):
1073
1073
  # The filename can be set if lazy loading is desired.
1074
1074
  self._filename = None
1075
1075
 
1076
- @property
1077
- def codestream(self):
1078
- if get_option("parse.full_codestream") is True:
1079
- header_only = False
1080
- else:
1081
- header_only = True
1082
- if self._codestream is None:
1083
- if self._filename is not None:
1084
- with open(self._filename, "rb") as fptr:
1085
- fptr.seek(self.main_header_offset)
1086
- self._codestream = Codestream(
1087
- fptr,
1088
- self.length,
1089
- header_only=header_only
1090
- )
1091
-
1092
- return self._codestream
1093
-
1094
1076
  def __repr__(self):
1095
1077
  msg = "glymur.jp2box.ContiguousCodeStreamBox"
1096
1078
  msg += f"(codestream={repr(self.codestream)})"
@@ -1134,7 +1116,7 @@ class ContiguousCodestreamBox(Jp2kBox):
1134
1116
  if get_option("parse.full_codestream"):
1135
1117
  codestream = Codestream(fptr, length, header_only=False)
1136
1118
  else:
1137
- codestream = None
1119
+ codestream = Codestream(fptr, length, header_only=True)
1138
1120
  box = cls(
1139
1121
  codestream,
1140
1122
  main_header_offset=main_header_offset,
@@ -3555,7 +3537,7 @@ class UUIDBox(Jp2kBox):
3555
3537
 
3556
3538
  References
3557
3539
  ----------
3558
- .. [XMP] International Organization for Standardication. ISO/IEC
3540
+ .. [XMP] International Organization for Standardization. ISO/IEC
3559
3541
  16684-1:2012 - Graphic technology -- Extensible metadata platform (XMP)
3560
3542
  specification -- Part 1: Data model, serialization and core properties
3561
3543
  """
glymur/jp2k.py CHANGED
@@ -1079,8 +1079,9 @@ class Jp2k(Jp2kr):
1079
1079
  else:
1080
1080
  numrows, numcols, num_comps = self.shape
1081
1081
 
1082
- for k in range(num_comps):
1083
- self._validate_nonzero_image_size(numrows, numcols, k)
1082
+ if 0 in imgdata.shape:
1083
+ msg = f"The image has invalid dimensions, {imgdata.shape}."
1084
+ raise InvalidJp2kError(msg)
1084
1085
 
1085
1086
  # set image offset and reference grid
1086
1087
  image.contents.x0 = self._cparams.image_offset_x0
glymur/jp2kr.py CHANGED
@@ -455,6 +455,13 @@ class Jp2kr(Jp2kBox):
455
455
  # boxes) here.
456
456
  fptr.seek(0)
457
457
  self.box = self.parse_superbox(fptr)
458
+
459
+ # Set the codestream property if it is there. Do this now because
460
+ # the validation process would otherwise cause another file-open to
461
+ # occur and re-parse the codestream (if it exists).
462
+ jp2c = next(filter(lambda x: x.box_id == 'jp2c', self.box), None)
463
+ self._codestream = jp2c.codestream if jp2c is not None else None
464
+
458
465
  self._validate()
459
466
 
460
467
  self._parse_count += 1
@@ -926,7 +933,14 @@ class Jp2kr(Jp2kBox):
926
933
  for k in range(raw_image.contents.numcomps):
927
934
  component = raw_image.contents.comps[k]
928
935
 
929
- self._validate_nonzero_image_size(nrows[k], ncols[k], k)
936
+ # validate the image size
937
+ if nrows[k] == 0 or ncols[k] == 0:
938
+ # Letting this situation continue would segfault openjpeg.
939
+ msg = (
940
+ f"Component {k} has invalid dimensions, "
941
+ f"{nrows[k]} x {ncols[k]}"
942
+ )
943
+ raise InvalidJp2kError(msg)
930
944
 
931
945
  addr = ctypes.addressof(component.data.contents)
932
946
  with warnings.catch_warnings():
@@ -984,10 +998,6 @@ class Jp2kr(Jp2kBox):
984
998
  def get_codestream(self, header_only=True):
985
999
  """Retrieve codestream.
986
1000
 
987
- This differs from the codestream property in that segment
988
- metadata that lies past the end of the codestream header
989
- can be retrieved.
990
-
991
1001
  Parameters
992
1002
  ----------
993
1003
  header_only : bool, optional
@@ -1023,50 +1033,37 @@ class Jp2kr(Jp2kBox):
1023
1033
 
1024
1034
  # if it's just a raw codestream file, it's easy
1025
1035
  if self._codec_format == opj2.CODEC_J2K:
1026
- return self._get_codestream(fptr, self.length, header_only)
1027
-
1028
- # continue assuming JP2, must seek to the JP2C box and past its
1029
- # header
1030
- box = next(filter(lambda x: x.box_id == "jp2c", self.box), None)
1031
-
1032
- fptr.seek(box.offset)
1033
- read_buffer = fptr.read(8)
1034
- (box_length, _) = struct.unpack(">I4s", read_buffer)
1035
- if box_length == 0:
1036
- # The length of the box is presumed to last until the end
1037
- # of the file. Compute the effective length of the box.
1038
- box_length = self.path.stat().st_size - fptr.tell() + 8
1039
- elif box_length == 1:
1040
- # Seek past the XL field.
1041
- read_buffer = fptr.read(8)
1042
- (box_length,) = struct.unpack(">Q", read_buffer)
1043
-
1044
- return self._get_codestream(fptr, box_length - 8, header_only)
1045
-
1046
- def _get_codestream(self, fptr, length, header_only):
1047
- """
1048
- Parsing errors can make for confusing errors sometimes, so catch any
1049
- such error and add context to it.
1050
- """
1036
+ length = self.length
1037
+ else:
1051
1038
 
1052
- try:
1053
- codestream = Codestream(fptr, length, header_only=header_only)
1054
- except Exception:
1055
- _, value, traceback = sys.exc_info()
1056
- msg = (
1057
- f"The file is invalid "
1058
- f'because the codestream could not be parsed: "{value}"'
1059
- )
1060
- raise InvalidJp2kError(msg).with_traceback(traceback)
1061
- else:
1062
- return codestream
1039
+ # continue assuming JP2, must seek to the JP2C box and past its
1040
+ # header
1041
+ box = next(
1042
+ filter(lambda x: x.box_id == "jp2c", self.box),
1043
+ None
1044
+ )
1063
1045
 
1064
- def _validate_nonzero_image_size(self, nrows, ncols, component_index):
1065
- """The image cannot have area of zero."""
1066
- if nrows == 0 or ncols == 0:
1067
- # Letting this situation continue would segfault openjpeg.
1068
- msg = (
1069
- f"Component {component_index} has dimensions "
1070
- f"{nrows} x {ncols}"
1071
- )
1072
- raise InvalidJp2kError(msg)
1046
+ fptr.seek(box.offset)
1047
+ read_buffer = fptr.read(8)
1048
+ (box_length, _) = struct.unpack(">I4s", read_buffer)
1049
+ if box_length == 0:
1050
+ # The length of the box is presumed to last until the end
1051
+ # of the file. Compute the effective length of the box.
1052
+ box_length = self.path.stat().st_size - fptr.tell() + 8
1053
+ elif box_length == 1:
1054
+ # Seek past the XL field.
1055
+ read_buffer = fptr.read(8)
1056
+ (box_length,) = struct.unpack(">Q", read_buffer)
1057
+ length = box_length - 8
1058
+
1059
+ try:
1060
+ codestream = Codestream(fptr, length, header_only=header_only)
1061
+ except Exception:
1062
+ _, value, traceback = sys.exc_info()
1063
+ msg = (
1064
+ f"The file is invalid "
1065
+ f'because the codestream could not be parsed: "{value}"'
1066
+ )
1067
+ raise InvalidJp2kError(msg).with_traceback(traceback)
1068
+ else:
1069
+ return codestream
glymur/version.py CHANGED
@@ -20,7 +20,7 @@ from .lib import _tiff as tiff
20
20
 
21
21
  # Do not change the format of this next line! Doing so risks breaking
22
22
  # setup.py
23
- version = "0.14.6"
23
+ version = "0.14.7"
24
24
 
25
25
  version_tuple = parse(version).release
26
26
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Glymur
3
- Version: 0.14.6
3
+ Version: 0.14.7
4
4
  Summary: Read and write JPEG 2000 files
5
5
  Author-email: John Evans <jevans667cc@proton.me>
6
6
  License-Expression: MIT
@@ -5,13 +5,13 @@ glymur/codestream.py,sha256=JQUVS8nENdf-rgMDuGwsrg0UakhN_kIShfZEzIV7IT4,62695
5
5
  glymur/command_line.py,sha256=3Wngx3wfAvP2PEf4-XRbmm43Bz8zywIL3Gd-6k-wMvY,11485
6
6
  glymur/config.py,sha256=lVunNA-A475BX27L_qmrec_lm1InzHuL4_jkG8v_1FA,4140
7
7
  glymur/core.py,sha256=O07TfaRW2YmurkFMiurl0DkDSGB0slDAAzP83K1HPFA,3613
8
- glymur/jp2box.py,sha256=hkhs_rE0yYpgnl4cvt4KXGJzzXfJ_HLBL74TvkZpoN4,113853
9
- glymur/jp2k.py,sha256=NaFzpuj4Ul4anfu4eZfjR0E1zRdG4ugeUp-nzMxHdQc,56963
10
- glymur/jp2kr.py,sha256=wlJhQZIRX3x-Fmo2WAFxOaZCu7RThBDFojNWT3Angmw,35399
8
+ glymur/jp2box.py,sha256=5VezBboJI49H40M_1KV_3cu_taxeuEjoNm0YGUQy2D0,113303
9
+ glymur/jp2k.py,sha256=cxdL_QSsSHT2se4qNLsOGIIEw0WmN_8IyVeRUKahNLU,57004
10
+ glymur/jp2kr.py,sha256=OnR38RyKcYVQz78ob3bYpAD2mB-e19kpDxGcT3xRiIc,35398
11
11
  glymur/jpeg.py,sha256=PSsyv4ZQTMXGQnpX9Y5-JGxHa0t6QZPZvd5BsnOhahQ,5560
12
12
  glymur/options.py,sha256=avZ2ba6yoLWZZ2J8-BI1h0k5Jy1bW0SuRq5guj3yNlo,4372
13
13
  glymur/tiff.py,sha256=tLFBuKlMxbMPphAZ-RWLQMWC0lYzB0cJVQmBlGRYpbo,29552
14
- glymur/version.py,sha256=dsLz3wcVE-F8qfNHrwJJe4_A-PeWXTDddSoyS7efwwo,990
14
+ glymur/version.py,sha256=G19wF2_mAikSgdeBIFXb3wSDtvwXBUng3Ch_VkEw2J4,990
15
15
  glymur/data/__init__.py,sha256=n2KZrHV15it7Wu4YCaBLXui1ZleQ30dnZ92dyP6q05k,955
16
16
  glymur/data/goodstuff.j2k,sha256=xKQG68KMu33gYjRUDTQvam1Cue2tdio85rNp5J-rYZE,115220
17
17
  glymur/data/heliov.jpx,sha256=KXnYdBZgl25jcGLu-m-QfhuP9pqUXV0Hp9HHEdJqr34,1399071
@@ -20,9 +20,9 @@ glymur/lib/__init__.py,sha256=JnM9oPfcZhBDLKo7_yLS-lIRQ1wXb1N9hKKQ-G7vYVk,127
20
20
  glymur/lib/_tiff.py,sha256=t8XfgwX2jX0qSU8RuTkNvWLe2390Bp7TiVlr8K2Ku68,51828
21
21
  glymur/lib/openjp2.py,sha256=0UWPp2mto8G43yRUhGfpcS1RV6l3ac1YQrlVyBhxvjs,44064
22
22
  glymur/lib/tiff.py,sha256=H9hgYh-gBx8LFec4LYReQOpscY51hpK6TIU27-zY8gg,260
23
- glymur-0.14.6.dist-info/licenses/LICENSE.txt,sha256=G9pvBgkJdPTtZqQmoRyIgAydtic1ZwWtOWBea9VMW7I,1077
24
- glymur-0.14.6.dist-info/METADATA,sha256=_KCznTi6Xi4MP_Q0ffQ6sZ_w65Kl39lYNv8pjpN1g_M,1325
25
- glymur-0.14.6.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
26
- glymur-0.14.6.dist-info/entry_points.txt,sha256=v_9O2V_6M5ir6_nYmtkpgY9QvN1H-CMVg6tKqcUN4v0,133
27
- glymur-0.14.6.dist-info/top_level.txt,sha256=D0SvtBUoPxOs40OTRW3l-kjGFHM6VrXS8yZPK5Fx2wY,7
28
- glymur-0.14.6.dist-info/RECORD,,
23
+ glymur-0.14.7.dist-info/licenses/LICENSE.txt,sha256=G9pvBgkJdPTtZqQmoRyIgAydtic1ZwWtOWBea9VMW7I,1077
24
+ glymur-0.14.7.dist-info/METADATA,sha256=8Zw_svII010xmqkbpp8eaIb2LGSKdJ5ZeR-W1Fvp5sQ,1325
25
+ glymur-0.14.7.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
26
+ glymur-0.14.7.dist-info/entry_points.txt,sha256=v_9O2V_6M5ir6_nYmtkpgY9QvN1H-CMVg6tKqcUN4v0,133
27
+ glymur-0.14.7.dist-info/top_level.txt,sha256=D0SvtBUoPxOs40OTRW3l-kjGFHM6VrXS8yZPK5Fx2wY,7
28
+ glymur-0.14.7.dist-info/RECORD,,