Glymur 0.13.6__py3-none-any.whl → 0.13.8__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/lib/openjp2.py CHANGED
@@ -13,12 +13,12 @@ import numpy as np
13
13
  # Local imports
14
14
  from ..config import glymur_config
15
15
 
16
- OPENJP2 = glymur_config('openjp2')
16
+ OPENJP2 = glymur_config("openjp2")
17
17
 
18
18
 
19
19
  class OpenJPEGLibraryError(IOError):
20
- """Issue when the OpenJPEG library signals an error.
21
- """
20
+ """Issue when the OpenJPEG library signals an error."""
21
+
22
22
  pass
23
23
 
24
24
 
@@ -30,10 +30,10 @@ def version():
30
30
  return "0.0.0"
31
31
 
32
32
  v = OPENJP2.opj_version()
33
- return v.decode('utf-8')
33
+ return v.decode("utf-8")
34
34
 
35
35
 
36
- _MAJOR, _MINOR, _PATCH = [int(x) for x in version().split('.')]
36
+ _MAJOR, _MINOR, _PATCH = [int(x) for x in version().split(".")]
37
37
 
38
38
  ERROR_MSG_LST = queue.Queue()
39
39
 
@@ -47,7 +47,7 @@ STREAM_TYPE_P = ctypes.c_void_p
47
47
 
48
48
  PATH_LEN = 4096
49
49
  J2K_MAXRLVLS = 33
50
- J2K_MAXBANDS = (3 * J2K_MAXRLVLS - 2)
50
+ J2K_MAXBANDS = 3 * J2K_MAXRLVLS - 2
51
51
 
52
52
  JPWL_MAX_NO_TILESPECS = 16
53
53
 
@@ -76,65 +76,56 @@ class PocType(ctypes.Structure):
76
76
 
77
77
  Corresponds to poc_t type in openjp2 headers.
78
78
  """
79
+
79
80
  # Resolution num start, Component num start, given by POC
80
81
  _fields_ = [
81
- ("resno0", ctypes.c_uint32), # noqa
82
- ("compno0", ctypes.c_uint32), # noqa
83
-
82
+ ("resno0", ctypes.c_uint32), # noqa
83
+ ("compno0", ctypes.c_uint32), # noqa
84
84
  # Layer num end,Resolution num end, Component num end, given by POC
85
- ("layno1", ctypes.c_uint32), # noqa
86
- ("resno1", ctypes.c_uint32), # noqa
87
- ("compno1", ctypes.c_uint32), # noqa
88
-
85
+ ("layno1", ctypes.c_uint32), # noqa
86
+ ("resno1", ctypes.c_uint32), # noqa
87
+ ("compno1", ctypes.c_uint32), # noqa
89
88
  # Layer num start,Precinct num start, Precinct num end
90
- ("layno0", ctypes.c_uint32), # noqa
91
- ("precno0", ctypes.c_uint32), # noqa
92
- ("precno1", ctypes.c_uint32), # noqa
93
-
89
+ ("layno0", ctypes.c_uint32), # noqa
90
+ ("precno0", ctypes.c_uint32), # noqa
91
+ ("precno1", ctypes.c_uint32), # noqa
94
92
  # Progression order enum
95
- ("prg1", PROG_ORDER_TYPE), # noqa
96
- ("prg", PROG_ORDER_TYPE), # noqa
97
-
93
+ ("prg1", PROG_ORDER_TYPE), # noqa
94
+ ("prg", PROG_ORDER_TYPE), # noqa
98
95
  # Progression order string
99
- ("progorder", ctypes.c_char * 5), # noqa
100
-
96
+ ("progorder", ctypes.c_char * 5), # noqa
101
97
  # Tile number
102
- ("tile", ctypes.c_uint32), # noqa
103
-
98
+ ("tile", ctypes.c_uint32), # noqa
104
99
  # Start and end values for Tile width and height*
105
- ("tx0", ctypes.c_int32), # noqa
106
- ("tx1", ctypes.c_int32), # noqa
107
- ("ty0", ctypes.c_int32), # noqa
108
- ("ty1", ctypes.c_int32), # noqa
109
-
100
+ ("tx0", ctypes.c_int32), # noqa
101
+ ("tx1", ctypes.c_int32), # noqa
102
+ ("ty0", ctypes.c_int32), # noqa
103
+ ("ty1", ctypes.c_int32), # noqa
110
104
  # Start value, initialised in pi_initialise_encode
111
- ("layS", ctypes.c_uint32), # noqa
112
- ("resS", ctypes.c_uint32), # noqa
113
- ("compS", ctypes.c_uint32), # noqa
114
- ("prcS", ctypes.c_uint32), # noqa
115
-
105
+ ("layS", ctypes.c_uint32), # noqa
106
+ ("resS", ctypes.c_uint32), # noqa
107
+ ("compS", ctypes.c_uint32), # noqa
108
+ ("prcS", ctypes.c_uint32), # noqa
116
109
  # End value, initialised in pi_initialise_encode
117
- ("layE", ctypes.c_uint32), # noqa
118
- ("resE", ctypes.c_uint32), # noqa
119
- ("compE", ctypes.c_uint32), # noqa
120
- ("prcE", ctypes.c_uint32), # noqa
121
-
110
+ ("layE", ctypes.c_uint32), # noqa
111
+ ("resE", ctypes.c_uint32), # noqa
112
+ ("compE", ctypes.c_uint32), # noqa
113
+ ("prcE", ctypes.c_uint32), # noqa
122
114
  # Start and end values of Tile width and height, initialised in
123
115
  # pi_initialise_encode
124
- ("txS", ctypes.c_uint32), # noqa
125
- ("txE", ctypes.c_uint32), # noqa
126
- ("tyS", ctypes.c_uint32), # noqa
127
- ("tyE", ctypes.c_uint32), # noqa
128
- ("dx", ctypes.c_uint32), # noqa
129
- ("dy", ctypes.c_uint32), # noqa
130
-
116
+ ("txS", ctypes.c_uint32), # noqa
117
+ ("txE", ctypes.c_uint32), # noqa
118
+ ("tyS", ctypes.c_uint32), # noqa
119
+ ("tyE", ctypes.c_uint32), # noqa
120
+ ("dx", ctypes.c_uint32), # noqa
121
+ ("dy", ctypes.c_uint32), # noqa
131
122
  # Temporary values for Tile parts, initialised in pi_create_encode
132
- ("lay_t", ctypes.c_uint32), # noqa
133
- ("res_t", ctypes.c_uint32), # noqa
134
- ("comp_t", ctypes.c_uint32), # noqa
135
- ("prec_t", ctypes.c_uint32), # noqa
136
- ("tx0_t", ctypes.c_uint32), # noqa
137
- ("ty0_t", ctypes.c_uint32), # noqa
123
+ ("lay_t", ctypes.c_uint32), # noqa
124
+ ("res_t", ctypes.c_uint32), # noqa
125
+ ("comp_t", ctypes.c_uint32), # noqa
126
+ ("prec_t", ctypes.c_uint32), # noqa
127
+ ("tx0_t", ctypes.c_uint32), # noqa
128
+ ("ty0_t", ctypes.c_uint32), # noqa
138
129
  ]
139
130
 
140
131
  def __str__(self):
@@ -149,6 +140,7 @@ class DecompressionParametersType(ctypes.Structure):
149
140
 
150
141
  Corresponds to dparameters_t type in openjp2 headers.
151
142
  """
143
+
152
144
  _fields_ = [
153
145
  # Set the number of highest resolutio levels to be discarded. The
154
146
  # image resolution is effectively divided by 2 to the power of
@@ -157,54 +149,42 @@ class DecompressionParametersType(ctypes.Structure):
157
149
  # zero, then the original dimension is divided by 2^(reduce). If
158
150
  # equal to zero or not used, the image is decoded to the full
159
151
  # resolution.
160
- ("cp_reduce", ctypes.c_uint32), # noqa
161
-
152
+ ("cp_reduce", ctypes.c_uint32), # noqa
162
153
  # Set the maximum number of quality layers to decode. If there are
163
154
  # fewer quality layers than the specified number, all the quality
164
155
  # layers are decoded.
165
156
  #
166
157
  # If != 0, then only the first cp_layer layers are decoded.
167
158
  # If == 0 or not used, all the quality layers are decoded.
168
- ("cp_layer", ctypes.c_uint32), # noqa
169
-
159
+ ("cp_layer", ctypes.c_uint32), # noqa
170
160
  # input file name
171
- ("infile", ctypes.c_char * PATH_LEN), # noqa
172
-
161
+ ("infile", ctypes.c_char * PATH_LEN), # noqa
173
162
  # output file name
174
- ("outfile", ctypes.c_char * PATH_LEN), # noqa
175
-
163
+ ("outfile", ctypes.c_char * PATH_LEN), # noqa
176
164
  # input file format 0: PGX, 1: PxM, 2: BMP 3:TIF
177
165
  # output file format 0: J2K, 1: JP2, 2: JPT
178
- ("decod_format", ctypes.c_int), # noqa
179
- ("cod_format", ctypes.c_int), # noqa
180
-
166
+ ("decod_format", ctypes.c_int), # noqa
167
+ ("cod_format", ctypes.c_int), # noqa
181
168
  # Decoding area left and right boundary.
182
169
  # Decoding area upper and lower boundary.
183
- ("DA_x0", ctypes.c_uint32), # noqa
184
- ("DA_x1", ctypes.c_uint32), # noqa
185
- ("DA_y0", ctypes.c_uint32), # noqa
186
- ("DA_y1", ctypes.c_uint32), # noqa
187
-
170
+ ("DA_x0", ctypes.c_uint32), # noqa
171
+ ("DA_x1", ctypes.c_uint32), # noqa
172
+ ("DA_y0", ctypes.c_uint32), # noqa
173
+ ("DA_y1", ctypes.c_uint32), # noqa
188
174
  # verbose mode
189
- ("m_verbose", BOOL_TYPE), # noqa
190
-
175
+ ("m_verbose", BOOL_TYPE), # noqa
191
176
  # tile number of the decoded tile
192
- ("tile_index", ctypes.c_uint32), # noqa
193
-
177
+ ("tile_index", ctypes.c_uint32), # noqa
194
178
  # number of tiles to decode
195
- ("nb_tile_to_decode", ctypes.c_uint32), # noqa
196
-
179
+ ("nb_tile_to_decode", ctypes.c_uint32), # noqa
197
180
  # activates the JPWL correction capabilities
198
- ("jpwl_correct", BOOL_TYPE), # noqa
199
-
181
+ ("jpwl_correct", BOOL_TYPE), # noqa
200
182
  # activates the JPWL correction capabilities
201
- ("jpwl_exp_comps", ctypes.c_int32), # noqa
202
-
183
+ ("jpwl_exp_comps", ctypes.c_int32), # noqa
203
184
  # maximum number of tiles
204
- ("jpwl_max_tiles", ctypes.c_int32), # noqa
205
-
185
+ ("jpwl_max_tiles", ctypes.c_int32), # noqa
206
186
  # maximum number of tiles
207
- ("flags", ctypes.c_uint32), # noqa
187
+ ("flags", ctypes.c_uint32), # noqa
208
188
  ]
209
189
 
210
190
  def __str__(self):
@@ -219,179 +199,128 @@ class CompressionParametersType(ctypes.Structure):
219
199
 
220
200
  Corresponds to cparameters_t type in openjp2 headers.
221
201
  """
202
+
222
203
  _fields_ = [
223
204
  # size of tile:
224
205
  # tile_size_on = false (not in argument) or
225
206
  # = true (in argument)
226
- ("tile_size_on", BOOL_TYPE), # noqa
227
-
207
+ ("tile_size_on", BOOL_TYPE), # noqa
228
208
  # XTOsiz, YTOsiz
229
- ("cp_tx0", ctypes.c_int), # noqa
230
- ("cp_ty0", ctypes.c_int), # noqa
231
-
209
+ ("cp_tx0", ctypes.c_int), # noqa
210
+ ("cp_ty0", ctypes.c_int), # noqa
232
211
  # XTsiz, YTsiz
233
- ("cp_tdx", ctypes.c_int), # noqa
234
- ("cp_tdy", ctypes.c_int), # noqa
235
-
212
+ ("cp_tdx", ctypes.c_int), # noqa
213
+ ("cp_tdy", ctypes.c_int), # noqa
236
214
  # allocation by rate/distortion
237
- ("cp_disto_alloc", ctypes.c_int), # noqa
238
-
215
+ ("cp_disto_alloc", ctypes.c_int), # noqa
239
216
  # allocation by fixed layer
240
- ("cp_fixed_alloc", ctypes.c_int), # noqa
241
-
217
+ ("cp_fixed_alloc", ctypes.c_int), # noqa
242
218
  # add fixed_quality
243
219
  ("cp_fixed_quality", ctypes.c_int), # noqa
244
-
245
220
  # fixed layer
246
- ("cp_matrice", ctypes.c_void_p), # noqa
247
-
221
+ ("cp_matrice", ctypes.c_void_p), # noqa
248
222
  # comment for coding
249
- ("cp_comment", ctypes.c_char_p), # noqa
250
-
223
+ ("cp_comment", ctypes.c_char_p), # noqa
251
224
  # csty : coding style
252
- ("csty", ctypes.c_int), # noqa
253
-
225
+ ("csty", ctypes.c_int), # noqa
254
226
  # progression order (default OPJ_LRCP)
255
- ("prog_order", ctypes.c_int), # noqa
256
-
227
+ ("prog_order", ctypes.c_int), # noqa
257
228
  # progression order changes
258
- ("poc", PocType * 32), # noqa
259
-
229
+ ("poc", PocType * 32), # noqa
260
230
  # number of progression order changes (POC), default to 0
261
- ("numpocs", ctypes.c_uint), # noqa
262
-
231
+ ("numpocs", ctypes.c_uint), # noqa
263
232
  # number of layers
264
- ("tcp_numlayers", ctypes.c_int), # noqa
265
-
233
+ ("tcp_numlayers", ctypes.c_int), # noqa
266
234
  # rates of layers
267
- ("tcp_rates", ctypes.c_float * 100), # noqa
268
-
235
+ ("tcp_rates", ctypes.c_float * 100), # noqa
269
236
  # different psnr for successive layers
270
- ("tcp_distoratio", ctypes.c_float * 100), # noqa
271
-
237
+ ("tcp_distoratio", ctypes.c_float * 100), # noqa
272
238
  # number of resolutions
273
- ("numresolution", ctypes.c_int), # noqa
274
-
239
+ ("numresolution", ctypes.c_int), # noqa
275
240
  # initial code block width, default to 64
276
- ("cblockw_init", ctypes.c_int), # noqa
277
-
241
+ ("cblockw_init", ctypes.c_int), # noqa
278
242
  # initial code block height, default to 64
279
- ("cblockh_init", ctypes.c_int), # noqa
280
-
243
+ ("cblockh_init", ctypes.c_int), # noqa
281
244
  # mode switch (cblk_style)
282
- ("mode", ctypes.c_int), # noqa
283
-
245
+ ("mode", ctypes.c_int), # noqa
284
246
  # 1 : use the irreversible DWT 9-7
285
247
  # 0 : use lossless compression (default)
286
- ("irreversible", ctypes.c_int), # noqa
287
-
248
+ ("irreversible", ctypes.c_int), # noqa
288
249
  # region of interest: affected component in [0..3], -1 means no ROI
289
- ("roi_compno", ctypes.c_int), # noqa
290
-
250
+ ("roi_compno", ctypes.c_int), # noqa
291
251
  # region of interest: upshift value
292
- ("roi_shift", ctypes.c_int), # noqa
293
-
252
+ ("roi_shift", ctypes.c_int), # noqa
294
253
  # number of precinct size specifications
295
- ("res_spec", ctypes.c_int), # noqa
296
-
254
+ ("res_spec", ctypes.c_int), # noqa
297
255
  # initial precinct width
298
- ("prcw_init", ctypes.c_int * J2K_MAXRLVLS), # noqa
299
-
256
+ ("prcw_init", ctypes.c_int * J2K_MAXRLVLS), # noqa
300
257
  # initial precinct height
301
- ("prch_init", ctypes.c_int * J2K_MAXRLVLS), # noqa
302
-
258
+ ("prch_init", ctypes.c_int * J2K_MAXRLVLS), # noqa
303
259
  # input file name
304
- ("infile", ctypes.c_char * PATH_LEN), # noqa
305
-
260
+ ("infile", ctypes.c_char * PATH_LEN), # noqa
306
261
  # output file name
307
- ("outfile", ctypes.c_char * PATH_LEN), # noqa
308
-
262
+ ("outfile", ctypes.c_char * PATH_LEN), # noqa
309
263
  # DEPRECATED.
310
- ("index_on", ctypes.c_int), # noqa
311
-
264
+ ("index_on", ctypes.c_int), # noqa
312
265
  # DEPRECATED.
313
- ("index", ctypes.c_char * PATH_LEN), # noqa
314
-
266
+ ("index", ctypes.c_char * PATH_LEN), # noqa
315
267
  # subimage encoding: origin image offset in x direction
316
268
  # subimage encoding: origin image offset in y direction
317
- ("image_offset_x0", ctypes.c_int), # noqa
318
- ("image_offset_y0", ctypes.c_int), # noqa
319
-
269
+ ("image_offset_x0", ctypes.c_int), # noqa
270
+ ("image_offset_y0", ctypes.c_int), # noqa
320
271
  # subsampling value for dx
321
272
  # subsampling value for dy
322
- ("subsampling_dx", ctypes.c_int), # noqa
323
- ("subsampling_dy", ctypes.c_int), # noqa
324
-
273
+ ("subsampling_dx", ctypes.c_int), # noqa
274
+ ("subsampling_dy", ctypes.c_int), # noqa
325
275
  # input file format 0: PGX, 1: PxM, 2: BMP 3:TIF
326
276
  # output file format 0: J2K, 1: JP2, 2: JPT
327
- ("decod_format", ctypes.c_int), # noqa
328
- ("cod_format", ctypes.c_int), # noqa
329
-
277
+ ("decod_format", ctypes.c_int), # noqa
278
+ ("cod_format", ctypes.c_int), # noqa
330
279
  # JPWL encoding parameters
331
280
  # enables writing of EPC in MH, thus activating JPWL
332
- ("jpwl_epc_on", BOOL_TYPE), # noqa
333
-
281
+ ("jpwl_epc_on", BOOL_TYPE), # noqa
334
282
  # error protection method for MH (0,1,16,32,37-128)
335
- ("jpwl_hprot_mh", ctypes.c_int), # noqa
336
-
283
+ ("jpwl_hprot_mh", ctypes.c_int), # noqa
337
284
  # tile number of header protection specification (>=0)
338
285
  ("jpwl_hprot_tph_tileno", ctypes.c_int * JPWL_MAX_NO_TILESPECS), # noqa
339
-
340
286
  # error protection methods for TPHs (0,1,16,32,37-128)
341
- ("jpwl_hprot_tph", ctypes.c_int * JPWL_MAX_NO_TILESPECS), # noqa
342
-
287
+ ("jpwl_hprot_tph", ctypes.c_int * JPWL_MAX_NO_TILESPECS), # noqa
343
288
  # tile number of packet protection specification (>=0)
344
- ("jpwl_pprot_tileno", ctypes.c_int * JPWL_MAX_NO_TILESPECS), # noqa
345
-
289
+ ("jpwl_pprot_tileno", ctypes.c_int * JPWL_MAX_NO_TILESPECS), # noqa
346
290
  # packet number of packet protection specification (>=0)
347
- ("jpwl_pprot_packno", ctypes.c_int * JPWL_MAX_NO_TILESPECS), # noqa
348
-
291
+ ("jpwl_pprot_packno", ctypes.c_int * JPWL_MAX_NO_TILESPECS), # noqa
349
292
  # error protection methods for packets (0,1,16,32,37-128)
350
- ("jpwl_pprot", ctypes.c_int * JPWL_MAX_NO_TILESPECS), # noqa
351
-
293
+ ("jpwl_pprot", ctypes.c_int * JPWL_MAX_NO_TILESPECS), # noqa
352
294
  # enables writing of ESD, (0=no/1/2 bytes)
353
- ("jpwl_sens_size", ctypes.c_int), # noqa
354
-
295
+ ("jpwl_sens_size", ctypes.c_int), # noqa
355
296
  # sensitivity addressing size (0=auto/2/4 bytes)
356
- ("jpwl_sens_addr", ctypes.c_int), # noqa
357
-
297
+ ("jpwl_sens_addr", ctypes.c_int), # noqa
358
298
  # sensitivity range (0-3)
359
- ("jpwl_sens_range", ctypes.c_int), # noqa
360
-
299
+ ("jpwl_sens_range", ctypes.c_int), # noqa
361
300
  # sensitivity method for MH (-1=no,0-7)
362
- ("jpwl_sens_mh", ctypes.c_int), # noqa
363
-
301
+ ("jpwl_sens_mh", ctypes.c_int), # noqa
364
302
  # tile number of sensitivity specification (>=0)
365
303
  ("jpwl_sens_tph_tileno", ctypes.c_int * JPWL_MAX_NO_TILESPECS), # noqa
366
-
367
304
  # sensitivity methods for TPHs (-1=no,0-7)
368
- ("jpwl_sens_tph", ctypes.c_int * JPWL_MAX_NO_TILESPECS), # noqa
369
-
305
+ ("jpwl_sens_tph", ctypes.c_int * JPWL_MAX_NO_TILESPECS), # noqa
370
306
  # Digital Cinema compliance 0-not compliant, 1-compliant
371
- ("cp_cinema", CINEMA_MODE_TYPE), # noqa
372
-
307
+ ("cp_cinema", CINEMA_MODE_TYPE), # noqa
373
308
  # Maximum rate for each component.
374
309
  # If == 0, component size limitation is not considered
375
- ("max_comp_size", ctypes.c_int), # noqa
376
-
310
+ ("max_comp_size", ctypes.c_int), # noqa
377
311
  # Profile name
378
- ("cp_rsiz", RSIZ_CAPABILITIES_TYPE), # noqa
379
-
312
+ ("cp_rsiz", RSIZ_CAPABILITIES_TYPE), # noqa
380
313
  # Tile part generation
381
- ("tp_on", ctypes.c_uint8), # noqa
382
-
314
+ ("tp_on", ctypes.c_uint8), # noqa
383
315
  # Flag for Tile part generation
384
- ("tp_flag", ctypes.c_uint8), # noqa
385
-
316
+ ("tp_flag", ctypes.c_uint8), # noqa
386
317
  # MCT (multiple component transform)
387
- ("tcp_mct", ctypes.c_uint8), # noqa
388
-
318
+ ("tcp_mct", ctypes.c_uint8), # noqa
389
319
  # Enable JPIP indexing
390
- ("jpip_on", BOOL_TYPE), # noqa
391
-
320
+ ("jpip_on", BOOL_TYPE), # noqa
392
321
  # Naive implementation of MCT restricted to a single reversible array
393
322
  # based encoding without offset concerning all the components.
394
- ("mct_data", ctypes.c_void_p), # noqa
323
+ ("mct_data", ctypes.c_void_p), # noqa
395
324
  ]
396
325
 
397
326
  if _MAJOR >= 2 and _MINOR >= 1:
@@ -409,19 +338,19 @@ class CompressionParametersType(ctypes.Structure):
409
338
  msg = f"{self.__class__}:\n"
410
339
  for field_name, _ in self._fields_:
411
340
 
412
- if field_name == 'poc':
341
+ if field_name == "poc":
413
342
  msg += f" numpocs: {self.numpocs}\n"
414
343
 
415
- elif field_name in ['tcp_rates', 'tcp_distoratio']:
344
+ elif field_name in ["tcp_rates", "tcp_distoratio"]:
416
345
  lst = []
417
346
  arr = getattr(self, field_name)
418
347
  lst = [arr[j] for j in range(self.tcp_numlayers)]
419
348
  msg += f" {field_name}: {lst}\n"
420
349
 
421
- elif field_name in ['prcw_init', 'prch_init']:
350
+ elif field_name in ["prcw_init", "prch_init"]:
422
351
  pass
423
352
 
424
- elif field_name == 'res_spec':
353
+ elif field_name == "res_spec":
425
354
  prcw_init = [self.prcw_init[j] for j in range(self.res_spec)]
426
355
  prch_init = [self.prch_init[j] for j in range(self.res_spec)]
427
356
  msg += f" res_spec: {self.res_spec}\n"
@@ -429,9 +358,14 @@ class CompressionParametersType(ctypes.Structure):
429
358
  msg += f" prcw_init: {prcw_init}\n"
430
359
 
431
360
  elif field_name in [
432
- 'jpwl_hprot_tph_tileno', 'jpwl_hprot_tph',
433
- 'jpwl_pprot_tileno', 'jpwl_pprot_packno', 'jpwl_pprot',
434
- 'jpwl_sens_tph_tileno', 'jpwl_sens_tph']:
361
+ "jpwl_hprot_tph_tileno",
362
+ "jpwl_hprot_tph",
363
+ "jpwl_pprot_tileno",
364
+ "jpwl_pprot_packno",
365
+ "jpwl_pprot",
366
+ "jpwl_sens_tph_tileno",
367
+ "jpwl_sens_tph",
368
+ ]:
435
369
  arr = getattr(self, field_name)
436
370
  lst = [arr[j] for j in range(JPWL_MAX_NO_TILESPECS)]
437
371
  msg += f" {field_name}: {lst}\n"
@@ -446,38 +380,31 @@ class ImageCompType(ctypes.Structure):
446
380
 
447
381
  Corresponds to image_comp_t type in openjp2 headers.
448
382
  """
383
+
449
384
  _fields_ = [
450
385
  # XRsiz, YRsiz: horizontal, vertical separation of ith component with
451
386
  # respect to the reference grid
452
- ("dx", ctypes.c_uint32), # noqa
453
- ("dy", ctypes.c_uint32), # noqa
454
-
387
+ ("dx", ctypes.c_uint32), # noqa
388
+ ("dy", ctypes.c_uint32), # noqa
455
389
  # data width and height
456
- ("w", ctypes.c_uint32), # noqa
457
- ("h", ctypes.c_uint32), # noqa
458
-
390
+ ("w", ctypes.c_uint32), # noqa
391
+ ("h", ctypes.c_uint32), # noqa
459
392
  # x, y component offset compared to the whole image
460
- ("x0", ctypes.c_uint32), # noqa
461
- ("y0", ctypes.c_uint32), # noqa
462
-
393
+ ("x0", ctypes.c_uint32), # noqa
394
+ ("y0", ctypes.c_uint32), # noqa
463
395
  # component depth in bits
464
- ("prec", ctypes.c_uint32), # noqa
465
-
396
+ ("prec", ctypes.c_uint32), # noqa
466
397
  # component depth in bits
467
- ("bpp", ctypes.c_uint32), # noqa
468
-
398
+ ("bpp", ctypes.c_uint32), # noqa
469
399
  # signed (1) or unsigned (0)
470
- ("sgnd", ctypes.c_uint32), # noqa
471
-
400
+ ("sgnd", ctypes.c_uint32), # noqa
472
401
  # number of decoded resolution
473
- ("resno_decoded", ctypes.c_uint32), # noqa
474
-
402
+ ("resno_decoded", ctypes.c_uint32), # noqa
475
403
  # number of division by 2 of the out image component as compared to the
476
404
  # original size of the image
477
- ("factor", ctypes.c_uint32), # noqa
478
-
405
+ ("factor", ctypes.c_uint32), # noqa
479
406
  # image component data
480
- ("data", ctypes.POINTER(ctypes.c_int32)), # noqa
407
+ ("data", ctypes.POINTER(ctypes.c_int32)), # noqa
481
408
  ]
482
409
 
483
410
  if _MAJOR >= 2 and _MINOR >= 1:
@@ -495,28 +422,23 @@ class ImageType(ctypes.Structure):
495
422
 
496
423
  Corresponds to image_t type in openjp2 headers.
497
424
  """
425
+
498
426
  _fields_ = [
499
427
  # XOsiz, YOsiz: horizontal and vertical offset from the origin of the
500
428
  # reference grid to the left side of the image area
501
- ("x0", ctypes.c_uint32), # noqa
502
- ("y0", ctypes.c_uint32), # noqa
503
-
429
+ ("x0", ctypes.c_uint32), # noqa
430
+ ("y0", ctypes.c_uint32), # noqa
504
431
  # Xsiz, Ysiz: width and height of the reference grid.
505
- ("x1", ctypes.c_uint32), # noqa
506
- ("y1", ctypes.c_uint32), # noqa
507
-
432
+ ("x1", ctypes.c_uint32), # noqa
433
+ ("y1", ctypes.c_uint32), # noqa
508
434
  # number of components in the image
509
- ("numcomps", ctypes.c_uint32), # noqa
510
-
435
+ ("numcomps", ctypes.c_uint32), # noqa
511
436
  # color space: should be sRGB, greyscale, or YUV
512
- ("color_space", COLOR_SPACE_TYPE), # noqa
513
-
437
+ ("color_space", COLOR_SPACE_TYPE), # noqa
514
438
  # image components
515
- ("comps", ctypes.POINTER(ImageCompType)), # noqa
516
-
439
+ ("comps", ctypes.POINTER(ImageCompType)), # noqa
517
440
  # restricted ICC profile buffer
518
441
  ("icc_profile_buf", ctypes.POINTER(ctypes.c_uint8)),
519
-
520
442
  # restricted ICC profile buffer length
521
443
  ("icc_profile_len", ctypes.c_uint32),
522
444
  ]
@@ -529,7 +451,7 @@ class ImageType(ctypes.Structure):
529
451
  msg += f" numcomps: {self.numcomps}\n"
530
452
  for j in range(self.numcomps): # pragma: no cover
531
453
  msg += f" comps[#{j}]:\n"
532
- msg += textwrap.indent(str(self.comps[j]), ' ' * 12)
454
+ msg += textwrap.indent(str(self.comps[j]), " " * 12)
533
455
 
534
456
  elif field_name == "comps":
535
457
  # handled above
@@ -546,26 +468,22 @@ class ImageComptParmType(ctypes.Structure):
546
468
 
547
469
  Corresponds to image_comptparm_t type in openjp2 headers.
548
470
  """
471
+
549
472
  _fields_ = [
550
473
  # XRsiz, YRsiz: horizontal, vertical separation of a sample of ith
551
474
  # component with respect to the reference grid
552
- ("dx", ctypes.c_uint32), # noqa
553
- ("dy", ctypes.c_uint32), # noqa
554
-
475
+ ("dx", ctypes.c_uint32), # noqa
476
+ ("dy", ctypes.c_uint32), # noqa
555
477
  # data width, height
556
- ("w", ctypes.c_uint32), # noqa
557
- ("h", ctypes.c_uint32), # noqa
558
-
478
+ ("w", ctypes.c_uint32), # noqa
479
+ ("h", ctypes.c_uint32), # noqa
559
480
  # x, y component offset compared to the whole image
560
- ("x0", ctypes.c_uint32), # noqa
561
- ("y0", ctypes.c_uint32), # noqa
562
-
481
+ ("x0", ctypes.c_uint32), # noqa
482
+ ("y0", ctypes.c_uint32), # noqa
563
483
  # precision
564
484
  ("prec", ctypes.c_uint32),
565
-
566
485
  # image depth in bits
567
- ("bpp", ctypes.c_uint32), # noqa
568
-
486
+ ("bpp", ctypes.c_uint32), # noqa
569
487
  # signed (1) / unsigned (0)
570
488
  ("sgnd", ctypes.c_uint32),
571
489
  ]
@@ -587,7 +505,7 @@ def check_error(status):
587
505
  lst = []
588
506
  while ERROR_MSG_LST.qsize() > 0:
589
507
  lst.append(ERROR_MSG_LST.get())
590
- msg = '\n'.join(lst)
508
+ msg = "\n".join(lst)
591
509
  raise OpenJPEGLibraryError(msg)
592
510
 
593
511
 
@@ -691,17 +609,13 @@ def decode_tile_data(codec, tidx, data, data_size, stream):
691
609
  ctypes.c_uint32,
692
610
  ctypes.POINTER(ctypes.c_uint8),
693
611
  ctypes.c_uint32,
694
- STREAM_TYPE_P
612
+ STREAM_TYPE_P,
695
613
  ]
696
614
  OPENJP2.opj_decode_tile_data.restype = check_error
697
615
 
698
616
  datap = data.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8))
699
617
  OPENJP2.opj_decode_tile_data(
700
- codec,
701
- ctypes.c_uint32(tidx),
702
- datap,
703
- ctypes.c_uint32(data_size),
704
- stream
618
+ codec, ctypes.c_uint32(tidx), datap, ctypes.c_uint32(data_size), stream
705
619
  )
706
620
 
707
621
 
@@ -789,7 +703,7 @@ def get_decoded_tile(codec, stream, imagep, tile_index):
789
703
  CODEC_TYPE,
790
704
  STREAM_TYPE_P,
791
705
  ctypes.POINTER(ImageType),
792
- ctypes.c_uint32
706
+ ctypes.c_uint32,
793
707
  ]
794
708
  OPENJP2.opj_get_decoded_tile.restype = check_error
795
709
 
@@ -903,15 +817,11 @@ def image_create(comptparms, clrspc):
903
817
  OPENJP2.opj_image_create.argtypes = [
904
818
  ctypes.c_uint32,
905
819
  ctypes.POINTER(ImageComptParmType),
906
- COLOR_SPACE_TYPE
820
+ COLOR_SPACE_TYPE,
907
821
  ]
908
822
  OPENJP2.opj_image_create.restype = ctypes.POINTER(ImageType)
909
823
 
910
- image = OPENJP2.opj_image_create(
911
- len(comptparms),
912
- comptparms,
913
- clrspc
914
- )
824
+ image = OPENJP2.opj_image_create(len(comptparms), comptparms, clrspc)
915
825
  return image
916
826
 
917
827
 
@@ -940,11 +850,7 @@ def image_tile_create(comptparms, clrspc):
940
850
  OPENJP2.opj_image_tile_create.argtypes = ARGTYPES
941
851
  OPENJP2.opj_image_tile_create.restype = ctypes.POINTER(ImageType)
942
852
 
943
- image = OPENJP2.opj_image_tile_create(
944
- len(comptparms),
945
- comptparms,
946
- clrspc
947
- )
853
+ image = OPENJP2.opj_image_tile_create(len(comptparms), comptparms, clrspc)
948
854
  return image
949
855
 
950
856
 
@@ -963,10 +869,7 @@ def encoder_set_extra_options(codec, plt=False, tlm=False):
963
869
  tlm : bool
964
870
  If True, TLM segments will be generated.
965
871
  """
966
- ARGTYPES = [
967
- CODEC_TYPE,
968
- ctypes.POINTER(ctypes.c_char_p)
969
- ]
872
+ ARGTYPES = [CODEC_TYPE, ctypes.POINTER(ctypes.c_char_p)]
970
873
  OPENJP2.opj_encoder_set_extra_options.argtypes = ARGTYPES
971
874
  OPENJP2.opj_encoder_set_extra_options.restype = check_error
972
875
 
@@ -976,9 +879,9 @@ def encoder_set_extra_options(codec, plt=False, tlm=False):
976
879
  arr = (ctypes.c_char_p * 3)()
977
880
  arr[0] = arr[1] = arr[2] = None
978
881
 
979
- arr[0] = 'PLT=YES'.encode('utf-8') if plt else 'PLT=NO'.encode('utf-8')
980
- if version() >= '2.5.0':
981
- arr[1] = 'TLM=YES'.encode('utf-8') if tlm else 'TLM=NO'.encode('utf-8')
882
+ arr[0] = "PLT=YES".encode("utf-8") if plt else "PLT=NO".encode("utf-8")
883
+ if version() >= "2.5.0":
884
+ arr[1] = "TLM=YES".encode("utf-8") if tlm else "TLM=NO".encode("utf-8")
982
885
 
983
886
  OPENJP2.opj_encoder_set_extra_options(codec, arr)
984
887
 
@@ -1060,7 +963,7 @@ def read_tile_header(codec, stream):
1060
963
  ctypes.POINTER(ctypes.c_int32),
1061
964
  ctypes.POINTER(ctypes.c_int32),
1062
965
  ctypes.POINTER(ctypes.c_uint32),
1063
- ctypes.POINTER(BOOL_TYPE)
966
+ ctypes.POINTER(BOOL_TYPE),
1064
967
  ]
1065
968
  OPENJP2.opj_read_tile_header.argtypes = ARGTYPES
1066
969
  OPENJP2.opj_read_tile_header.restype = check_error
@@ -1083,7 +986,7 @@ def read_tile_header(codec, stream):
1083
986
  ctypes.byref(col1),
1084
987
  ctypes.byref(row1),
1085
988
  ctypes.byref(ncomps),
1086
- ctypes.byref(go_on)
989
+ ctypes.byref(go_on),
1087
990
  )
1088
991
  go_on = bool(go_on.value)
1089
992
  return (
@@ -1094,7 +997,7 @@ def read_tile_header(codec, stream):
1094
997
  col1.value,
1095
998
  row1.value,
1096
999
  ncomps.value,
1097
- go_on
1000
+ go_on,
1098
1001
  )
1099
1002
 
1100
1003
 
@@ -1126,16 +1029,17 @@ def set_decode_area(codec, image, start_x=0, start_y=0, end_x=0, end_y=0):
1126
1029
  ctypes.c_int32,
1127
1030
  ctypes.c_int32,
1128
1031
  ctypes.c_int32,
1129
- ctypes.c_int32
1032
+ ctypes.c_int32,
1130
1033
  ]
1131
1034
  OPENJP2.opj_set_decode_area.restype = check_error
1132
1035
 
1133
1036
  OPENJP2.opj_set_decode_area(
1134
- codec, image,
1037
+ codec,
1038
+ image,
1135
1039
  ctypes.c_int32(start_x),
1136
1040
  ctypes.c_int32(start_y),
1137
1041
  ctypes.c_int32(end_x),
1138
- ctypes.c_int32(end_y)
1042
+ ctypes.c_int32(end_y),
1139
1043
  )
1140
1044
 
1141
1045
 
@@ -1163,7 +1067,7 @@ def set_decoded_components(codec, comp_indices):
1163
1067
  CODEC_TYPE,
1164
1068
  ctypes.c_uint32,
1165
1069
  ctypes.POINTER(ctypes.c_uint32),
1166
- ctypes.c_int32
1070
+ ctypes.c_int32,
1167
1071
  ]
1168
1072
  OPENJP2.opj_set_decoded_components.restype = check_error
1169
1073
 
@@ -1174,7 +1078,10 @@ def set_decoded_components(codec, comp_indices):
1174
1078
  apply_color_xforms = ctypes.c_int32(0)
1175
1079
 
1176
1080
  OPENJP2.opj_set_decoded_components(
1177
- codec, ncomps, indices_p, apply_color_xforms
1081
+ codec,
1082
+ ncomps,
1083
+ indices_p,
1084
+ apply_color_xforms
1178
1085
  )
1179
1086
 
1180
1087
 
@@ -1258,7 +1165,7 @@ def set_error_handler(codec, handler, data=None):
1258
1165
  OPENJP2.opj_set_error_handler.argtypes = [
1259
1166
  CODEC_TYPE,
1260
1167
  ctypes.c_void_p,
1261
- ctypes.c_void_p
1168
+ ctypes.c_void_p,
1262
1169
  ]
1263
1170
  OPENJP2.opj_set_error_handler.restype = check_error
1264
1171
  OPENJP2.opj_set_error_handler(codec, handler, data)
@@ -1284,7 +1191,9 @@ def set_info_handler(codec, handler, data=None):
1284
1191
  If the OpenJPEG library routine opj_set_info_handler fails.
1285
1192
  """
1286
1193
  OPENJP2.opj_set_info_handler.argtypes = [
1287
- CODEC_TYPE, ctypes.c_void_p, ctypes.c_void_p
1194
+ CODEC_TYPE,
1195
+ ctypes.c_void_p,
1196
+ ctypes.c_void_p,
1288
1197
  ]
1289
1198
  OPENJP2.opj_set_info_handler.restype = check_error
1290
1199
  OPENJP2.opj_set_info_handler(codec, handler, data)
@@ -1310,7 +1219,9 @@ def set_warning_handler(codec, handler, data=None):
1310
1219
  If the OpenJPEG library routine opj_set_warning_handler fails.
1311
1220
  """
1312
1221
  OPENJP2.opj_set_warning_handler.argtypes = [
1313
- CODEC_TYPE, ctypes.c_void_p, ctypes.c_void_p
1222
+ CODEC_TYPE,
1223
+ ctypes.c_void_p,
1224
+ ctypes.c_void_p,
1314
1225
  ]
1315
1226
  OPENJP2.opj_set_warning_handler.restype = check_error
1316
1227
 
@@ -1364,7 +1275,7 @@ def setup_encoder(codec, cparams, image):
1364
1275
  ARGTYPES = [
1365
1276
  CODEC_TYPE,
1366
1277
  ctypes.POINTER(CompressionParametersType),
1367
- ctypes.POINTER(ImageType)
1278
+ ctypes.POINTER(ImageType),
1368
1279
  ]
1369
1280
  OPENJP2.opj_setup_encoder.argtypes = ARGTYPES
1370
1281
  OPENJP2.opj_setup_encoder.restype = check_error
@@ -1391,7 +1302,9 @@ def start_compress(codec, image, stream):
1391
1302
  If the OpenJPEG library routine opj_start_compress fails.
1392
1303
  """
1393
1304
  OPENJP2.opj_start_compress.argtypes = [
1394
- CODEC_TYPE, ctypes.POINTER(ImageType), STREAM_TYPE_P
1305
+ CODEC_TYPE,
1306
+ ctypes.POINTER(ImageType),
1307
+ STREAM_TYPE_P,
1395
1308
  ]
1396
1309
  OPENJP2.opj_start_compress.restype = check_error
1397
1310
 
@@ -1478,7 +1391,7 @@ def write_tile(codec, tile_index, data, *pargs):
1478
1391
  ctypes.c_uint32,
1479
1392
  ctypes.POINTER(ctypes.c_uint8),
1480
1393
  ctypes.c_uint32,
1481
- STREAM_TYPE_P
1394
+ STREAM_TYPE_P,
1482
1395
  ]
1483
1396
  OPENJP2.opj_write_tile.restype = check_error
1484
1397
 
@@ -1488,7 +1401,7 @@ def write_tile(codec, tile_index, data, *pargs):
1488
1401
  ctypes.c_uint32(int(tile_index)),
1489
1402
  datap,
1490
1403
  ctypes.c_uint32(int(data_size)),
1491
- stream
1404
+ stream,
1492
1405
  )
1493
1406
 
1494
1407
 
@@ -1505,18 +1418,18 @@ _CMPFUNC = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_char_p, ctypes.c_void_p)
1505
1418
 
1506
1419
  def _default_error_handler(msg, _):
1507
1420
  """Default error handler callback for libopenjp2."""
1508
- msg = "OpenJPEG library error: {0}".format(msg.decode('utf-8').rstrip())
1421
+ msg = "OpenJPEG library error: {0}".format(msg.decode("utf-8").rstrip())
1509
1422
  set_error_message(msg)
1510
1423
 
1511
1424
 
1512
1425
  def _default_info_handler(msg, _):
1513
1426
  """Default info handler callback."""
1514
- print("[INFO] {0}".format(msg.decode('utf-8').rstrip()))
1427
+ print("[INFO] {0}".format(msg.decode("utf-8").rstrip()))
1515
1428
 
1516
1429
 
1517
1430
  def _default_warning_handler(library_msg, _):
1518
1431
  """Default warning handler callback."""
1519
- library_msg = library_msg.decode('utf-8').rstrip()
1432
+ library_msg = library_msg.decode("utf-8").rstrip()
1520
1433
  msg = "OpenJPEG library warning: {0}".format(library_msg)
1521
1434
  warnings.warn(msg, UserWarning)
1522
1435