Coverage Report

Created: 2025-07-23 08:18

/work/include/jasper/jas_init.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2001-2002 Michael David Adams.
3
 * All rights reserved.
4
 */
5
6
/* __START_OF_JASPER_LICENSE__
7
 * 
8
 * JasPer License Version 2.0
9
 * 
10
 * Copyright (c) 2001-2006 Michael David Adams
11
 * Copyright (c) 1999-2000 Image Power, Inc.
12
 * Copyright (c) 1999-2000 The University of British Columbia
13
 * 
14
 * All rights reserved.
15
 * 
16
 * Permission is hereby granted, free of charge, to any person (the
17
 * "User") obtaining a copy of this software and associated documentation
18
 * files (the "Software"), to deal in the Software without restriction,
19
 * including without limitation the rights to use, copy, modify, merge,
20
 * publish, distribute, and/or sell copies of the Software, and to permit
21
 * persons to whom the Software is furnished to do so, subject to the
22
 * following conditions:
23
 * 
24
 * 1.  The above copyright notices and this permission notice (which
25
 * includes the disclaimer below) shall be included in all copies or
26
 * substantial portions of the Software.
27
 * 
28
 * 2.  The name of a copyright holder shall not be used to endorse or
29
 * promote products derived from the Software without specific prior
30
 * written permission.
31
 * 
32
 * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
33
 * LICENSE.  NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
34
 * THIS DISCLAIMER.  THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
35
 * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
36
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
37
 * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  IN NO
38
 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
39
 * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
40
 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
41
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
42
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.  NO ASSURANCES ARE
43
 * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
44
 * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
45
 * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
46
 * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
47
 * PROPERTY RIGHTS OR OTHERWISE.  AS A CONDITION TO EXERCISING THE RIGHTS
48
 * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
49
 * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY.  THE SOFTWARE
50
 * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
51
 * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
52
 * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
53
 * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
54
 * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
55
 * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
56
 * RISK ACTIVITIES").  THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
57
 * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
58
 * 
59
 * __END_OF_JASPER_LICENSE__
60
 */
61
62
/*!
63
 * @file jas_init.h
64
 * @brief JasPer Initialization/Cleanup Code
65
 */
66
67
#ifndef JAS_INIT_H
68
#define JAS_INIT_H
69
70
/* The configuration header file should be included first. */
71
#include <jasper/jas_config.h>
72
73
#include "jasper/jas_malloc.h"
74
#include "jasper/jas_image.h"
75
#include "jasper/jas_log.h"
76
77
#include <stdarg.h>
78
79
#ifdef __cplusplus
80
extern "C" {
81
#endif
82
83
/*!
84
 * @addtogroup module_init
85
 * @{
86
 */
87
88
#if defined(JAS_FOR_INTERNAL_USE_ONLY)
89
/*
90
Per-thread library context.
91
*/
92
typedef struct {
93
94
  /*
95
  The level of debugging checks/output enabled by the library.
96
  A larger value corresponds to a greater level of debugging checks/output.
97
  */
98
  int debug_level;
99
100
  /*
101
  The function used to output error/warning/informational messages.
102
  int (*vlogmsgf)(jas_logtype_t type, const char *format, va_list ap);
103
  */
104
  jas_vlogmsgf_t *vlogmsgf;
105
106
  /*
107
  The image format information to be used to populate the image format
108
  table.
109
  */
110
  size_t image_numfmts;
111
  jas_image_fmtinfo_t image_fmtinfos[JAS_IMAGE_MAXFMTS];
112
113
  /* The maximum number of samples allowable in an image to be decoded. */
114
  size_t dec_default_max_samples;
115
116
} jas_ctx_t;
117
#endif
118
119
/*!
120
@brief
121
An opaque handle type used to represent a JasPer library context.
122
*/
123
typedef void *jas_context_t;
124
125
/******************************************************************************\
126
* Library Run-Time Configuration.
127
\******************************************************************************/
128
129
/*!
130
@brief
131
Configure the JasPer library with the default configuration settings.
132
133
@details
134
This function configures the JasPer library with the default configuration
135
settings.
136
These settings may be change via the @c jas_conf_* family of function
137
prior to invoking jas_init_library().
138
139
@warning
140
Configuration, initialization, and cleanup of the library must be performed
141
on the same thread.
142
*/
143
JAS_EXPORT
144
void jas_conf_clear(void);
145
146
/*!
147
@brief Set the multithreading flag for the library.
148
149
@details
150
*/
151
JAS_EXPORT
152
void jas_conf_set_multithread(int multithread);
153
154
/*!
155
@brief Set the memory allocator to be used by the library.
156
157
@details
158
The object referenced by @c allocator must have a live at least
159
until jas_cleanup() is invoked.
160
How the memory in which @c *allocator reside is allocated is the
161
responsibility of the caller.
162
*/
163
JAS_EXPORT
164
void jas_conf_set_allocator(jas_allocator_t *allocator);
165
166
/*!
167
@brief Set the initial debug level for the library.
168
169
@details
170
*/
171
JAS_EXPORT
172
void jas_conf_set_debug_level(int debug_level);
173
174
/*!
175
@brief
176
Set the maximum amount of memory that can be used by the library
177
(assuming the allocator wrapper is not disabled).
178
179
@details
180
181
@warning
182
It is strongly recommended that the memory usage limit not be set to an
183
excessively large value, as this poses security risks (e.g., decoding a
184
malicious image file could exhaust all virtual memory and effectively
185
crash the system).
186
*/
187
JAS_EXPORT
188
void jas_conf_set_max_mem_usage(size_t max_mem);
189
190
/*!
191
@brief
192
Set the default value for the maximum number of samples that is
193
allowed in an image to be decoded.
194
195
@details
196
*/
197
JAS_EXPORT
198
void jas_conf_set_dec_default_max_samples(size_t max_samples);
199
200
/*!
201
@brief
202
Set the function used by the library to output error, warning, and
203
informational messages.
204
205
@details
206
*/
207
JAS_EXPORT
208
void jas_conf_set_vlogmsgf(jas_vlogmsgf_t *func);
209
210
/******************************************************************************\
211
* Library Initialization and Cleanup.
212
\******************************************************************************/
213
214
/*!
215
@brief
216
Initialize the JasPer library with the current configuration settings.
217
218
@details
219
The library must be configured by invoking the jas_conf_clear() function
220
prior to calling jas_init_library().
221
222
@returns
223
If the initialization of the library is successful, zero is returned;
224
otherwise, a nonzero value is returned.
225
226
@warning
227
The jas_init_library() function does NOT synchronize with the
228
jas_conf_clear() function.
229
Configuration, initialization, and cleanup of the library must be
230
performed on the same thread.
231
*/
232
JAS_EXPORT
233
int jas_init_library(void);
234
235
/*!
236
@brief
237
Perform clean up for the JasPer library.
238
239
@details
240
At the point when this function is called, all threads that have called
241
jas_init_thread() must have called jas_cleanup_thread().
242
243
@returns
244
If the operation is successful, zero is returned.
245
Otherwise, a nonzero value is returned.
246
*/
247
JAS_EXPORT
248
int jas_cleanup_library(void);
249
250
/******************************************************************************\
251
* Thread Initialization and Cleanup.
252
\******************************************************************************/
253
254
/*!
255
@brief
256
Perform per-thread initialization for the JasPer library.
257
258
@details
259
The library must be initialized by invoking the jas_init_library() function
260
prior to calling jas_init_thread().
261
262
@warning
263
The jas_init_thread() function can only be invoked in a single thread
264
unless the run-time configuration has enabled multithreading via
265
jas_set_multithread().
266
*/
267
JAS_EXPORT
268
int jas_init_thread(void);
269
270
/*!
271
@brief
272
Perform per-thread cleanup for the JasPer library.
273
274
@details
275
*/
276
JAS_EXPORT
277
int jas_cleanup_thread(void);
278
279
/******************************************************************************\
280
* Legacy Initialization and Cleanup Functions.
281
\******************************************************************************/
282
283
/*!
284
@brief
285
Configure and initialize the JasPer library using the default
286
configuration settings.
287
288
@details
289
The jas_init() function initializes the JasPer library.
290
The library must be initialized before most code in the library can be used.
291
292
The jas_init() function exists only for reasons of backward compatibility
293
with earlier versions of the library.
294
It is recommended that this function not be used.
295
Instead, the jas_conf_clear() and jas_init_library() functions should be used
296
to configure and initialize the library.
297
298
@returns
299
If the library is successfully initialized, zero is returned;
300
otherwise, a nonzero value is returned.
301
302
@warning
303
Configuration, initialization, and cleanup of the library must be performed
304
on the same thread.
305
306
@deprecated
307
This function is deprecated.
308
*/
309
JAS_EXPORT
310
int jas_init(void);
311
312
/*!
313
@brief
314
Perform any clean up for the JasPer library.
315
316
@details
317
This function performs any clean up for the JasPer library.
318
319
@warning
320
Configuration, initialization, and cleanup of the library must be performed
321
on the same thread.
322
323
@deprecated
324
This function is deprecated.
325
*/
326
JAS_EXPORT
327
void jas_cleanup(void);
328
329
/******************************************************************************\
330
* Context Management
331
\******************************************************************************/
332
333
/*!
334
@brief
335
Create a context.
336
337
@details
338
*/
339
JAS_EXPORT
340
jas_context_t jas_context_create(void);
341
342
/*!
343
@brief
344
Destroy a context.
345
346
@details
347
The context being destroyed must not be the current context.
348
*/
349
JAS_EXPORT
350
void jas_context_destroy(jas_context_t context);
351
352
/*!
353
@brief
354
Get the current context for the calling thread.
355
356
@details
357
*/
358
JAS_EXPORT
359
jas_context_t jas_get_default_context(void);
360
361
/*!
362
@brief
363
Get the current context for the calling thread.
364
365
@details
366
*/
367
JAS_EXPORT
368
jas_context_t jas_get_context(void);
369
370
/*!
371
@brief
372
Set the current context for the calling thread.
373
374
@details
375
*/
376
JAS_EXPORT
377
void jas_set_context(jas_context_t context);
378
379
/******************************************************************************\
380
* Getting/Setting Context Properties
381
\******************************************************************************/
382
383
/* This function is only for internal use by the library. */
384
JAS_EXPORT
385
int jas_get_debug_level_internal(void);
386
387
/* This function is only for internal use by the library. */
388
JAS_EXPORT
389
size_t jas_get_dec_default_max_samples_internal(void);
390
391
/* This function is only for internal use by the library. */
392
JAS_EXPORT
393
jas_vlogmsgf_t *jas_get_vlogmsgf_internal(void);
394
395
#if defined(JAS_FOR_INTERNAL_USE_ONLY)
396
#if defined(JAS_HAVE_THREAD_LOCAL)
397
extern _Thread_local jas_ctx_t *jas_cur_ctx;
398
#endif
399
400
/* This function is only for internal use by the library. */
401
jas_ctx_t *jas_get_ctx_internal(void);
402
403
/* This function is only for internal use by the library. */
404
static inline jas_ctx_t *jas_get_ctx(void)
405
{
406
#if defined(JAS_HAVE_THREAD_LOCAL)
407
  return jas_cur_ctx ? jas_cur_ctx : jas_get_ctx_internal();
408
#else
409
  return JAS_CAST(jas_ctx_t *, jas_get_ctx_internal());
410
#endif
411
}
412
#endif
413
414
/*!
415
@brief
416
Set the debug level for a particular context.
417
418
@details
419
*/
420
JAS_EXPORT
421
void jas_set_debug_level(int debug_level);
422
423
/*!
424
@brief
425
Get the debug level for a particular context.
426
427
@details
428
*/
429
static inline int jas_get_debug_level(void)
430
0
{
431
0
#if defined(JAS_FOR_INTERNAL_USE_ONLY)
432
0
  jas_ctx_t *ctx = jas_get_ctx();
433
0
  return ctx->debug_level;
434
0
#else
435
0
  return jas_get_debug_level_internal();
436
0
#endif
437
0
}
438
439
/*!
440
@brief
441
Set the default maximum number of samples that a decoder is permitted to
442
process.
443
444
@details
445
*/
446
JAS_EXPORT
447
void jas_set_dec_default_max_samples(size_t max_samples);
448
449
/*!
450
@brief
451
Get the default maximum number of samples that a decoder is permitted to
452
process.
453
454
@details
455
*/
456
static inline size_t jas_get_dec_default_max_samples(void)
457
0
{
458
0
#if defined(JAS_FOR_INTERNAL_USE_ONLY)
459
0
  jas_ctx_t *ctx = jas_get_ctx();
460
0
  return ctx->dec_default_max_samples;
461
0
#else
462
0
  return jas_get_dec_default_max_samples_internal();
463
0
#endif
464
0
}
465
466
/*!
467
@brief
468
Set the function to be used for log messages.
469
470
@details
471
*/
472
JAS_EXPORT
473
void jas_set_vlogmsgf(jas_vlogmsgf_t *func);
474
475
/*!
476
@brief
477
Get the function to be used for log messages.
478
479
@details
480
*/
481
static inline
482
jas_vlogmsgf_t *jas_get_vlogmsgf(void)
483
0
{
484
0
#if defined(JAS_FOR_INTERNAL_USE_ONLY)
485
0
  jas_ctx_t *ctx = jas_get_ctx();
486
0
  return ctx->vlogmsgf;
487
0
#else
488
0
  return jas_get_vlogmsgf_internal();
489
0
#endif
490
0
}
491
492
/*!
493
 * @}
494
 */
495
496
#ifdef __cplusplus
497
}
498
#endif
499
500
#endif