| 1 |
TIFFOpenOptions |
| 2 |
=============== |
| 3 |
|
| 4 |
Synopsis |
| 5 |
-------- |
| 6 |
|
| 7 |
.. highlight:: c |
| 8 |
|
| 9 |
:: |
| 10 |
|
| 11 |
#include <tiffio.h> |
| 12 |
|
| 13 |
.. c:type:: TIFFOpenOptions TIFFOpenOptions |
| 14 |
|
| 15 |
.. c:function:: TIFFOpenOptions* TIFFOpenOptionsAlloc(void) |
| 16 |
|
| 17 |
.. c:function:: void TIFFOpenOptionsFree(TIFFOpenOptions*) |
| 18 |
|
| 19 |
.. c:function:: void TIFFOpenOptionsSetMaxSingleMemAlloc(TIFFOpenOptions* opts, tmsize_t max_single_mem_alloc) |
| 20 |
|
| 21 |
.. c:function:: void TIFFOpenOptionsSetMaxCumulatedMemAlloc(TIFFOpenOptions* opts, tmsize_t max_cumulated_mem_alloc) |
| 22 |
|
| 23 |
.. c:function:: void TIFFOpenOptionsSetErrorHandlerExtR(TIFFOpenOptions* opts, TIFFErrorHandlerExtR handler, void* errorhandler_user_data) |
| 24 |
|
| 25 |
.. c:function:: void TIFFOpenOptionsSetWarningHandlerExtR(TIFFOpenOptions* opts, TIFFErrorHandlerExtR handler, void* warnhandler_user_data) |
| 26 |
|
| 27 |
Description |
| 28 |
----------- |
| 29 |
|
| 30 |
:c:type:`TIFFOpenOptions` is an opaque structure which can be passed |
| 31 |
to the TIFF open"Ext" functions to define some ``libtiff`` internal settings. |
| 32 |
The settings are the maximum single memory allocation limit and |
| 33 |
per-TIFF handle (re-entrant) error handler and warning handler functions. |
| 34 |
For those handler a pointer to a **custom defined data structure** *user_data* |
| 35 |
can be given along. |
| 36 |
|
| 37 |
:c:func:`TIFFOpenOptionsAlloc` allocates memory for the :c:type:`TIFFOpenOptions` |
| 38 |
opaque structure and returns a :c:type:`TIFFOpenOptions` pointer. |
| 39 |
|
| 40 |
:c:func:`TIFFOpenOptionsFree` releases the allocated memory for |
| 41 |
:c:type:`TIFFOpenOptions`. The allocated memory for :c:type:`TIFFOpenOptions` |
| 42 |
can be released straight after successful execution of the related |
| 43 |
TIFFOpen"Ext" functions like :c:func:`TIFFOpenExt`. |
| 44 |
|
| 45 |
:c:func:`TIFFOpenOptionsSetMaxSingleMemAlloc` (added in libtiff 4.5.0) sets |
| 46 |
the value for the maximum single memory limit in byte that ``libtiff`` internal |
| 47 |
memory allocation functions are allowed to request per call. |
| 48 |
|
| 49 |
.. note:: |
| 50 |
However, the ``libtiff`` external functions :c:func:`_TIFFmalloc` |
| 51 |
and :c:func:`_TIFFrealloc` **do not apply** this internal memory |
| 52 |
allocation limit set by :c:func:`TIFFOpenOptionsSetMaxSingleMemAlloc`! |
| 53 |
|
| 54 |
:c:func:`TIFFOpenOptionsSetMaxCumulatedMemAlloc` (added in libtiff 4.6.1) sets |
| 55 |
the maximum cumulated memory allocations in byte, for a given TIFF handle, |
| 56 |
that ``libtiff`` internal memory allocation functions are allowed. |
| 57 |
|
| 58 |
.. note:: |
| 59 |
However, the ``libtiff`` external functions :c:func:`_TIFFmalloc` |
| 60 |
and :c:func:`_TIFFrealloc` **do not apply** this internal memory |
| 61 |
allocation limit set by :c:func:`TIFFOpenOptionsSetMaxCumulatedMemAlloc`! |
| 62 |
|
| 63 |
:c:func:`TIFFOpenOptionsSetErrorHandlerExtR` sets the function pointer to |
| 64 |
an application-specific and per-TIFF handle (re-entrant) error handler. |
| 65 |
Furthermore, a pointer to a **custom defined data structure** *errorhandler_user_data* |
| 66 |
can be passed. This error handler is invoked through :c:func:`TIFFErrorExtR` |
| 67 |
and the *errorhandler_user_data* pointer is given along. |
| 68 |
The *errorhandler_user_data* argument may be NULL. |
| 69 |
|
| 70 |
:c:func:`TIFFOpenOptionsSetWarningHandlerExtR` works like |
| 71 |
:c:func:`TIFFOpenOptionsSetErrorHandlerExtR` but for the warning handler, |
| 72 |
which is invoked through :c:func:`TIFFWarningExtR` |
| 73 |
|
| 74 |
Example |
| 75 |
------- |
| 76 |
|
| 77 |
:: |
| 78 |
|
| 79 |
#include "tiffio.h" |
| 80 |
|
| 81 |
typedef struct MyErrorHandlerUserDataStruct |
| 82 |
{ |
| 83 |
/* ... any user data structure ... */ |
| 84 |
} MyErrorHandlerUserDataStruct; |
| 85 |
|
| 86 |
static int myErrorHandler(TIFF *tiff, void *user_data, const char *module, |
| 87 |
const char *fmt, va_list ap) |
| 88 |
{ |
| 89 |
MyErrorHandlerUserDataStruct *errorhandler_user_data = |
| 90 |
(MyErrorHandlerUserDataStruct *)user_data; |
| 91 |
/*... code of myErrorHandler ...*/ |
| 92 |
return 1; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
main() |
| 97 |
{ |
| 98 |
tmsize_t limit = (256 * 1024 * 1024); |
| 99 |
MyErrorHandlerUserDataStruct user_data = { /* ... any data ... */}; |
| 100 |
|
| 101 |
TIFFOpenOptions *opts = TIFFOpenOptionsAlloc(); |
| 102 |
TIFFOpenOptionsSetMaxSingleMemAlloc(opts, limit); |
| 103 |
TIFFOpenOptionsSetErrorHandlerExtR(opts, myErrorHandler, &user_data); |
| 104 |
TIFF *tif = TIFFOpenExt("foo.tif", "r", opts); |
| 105 |
TIFFOpenOptionsFree(opts); |
| 106 |
/* ... go on here ... */ |
| 107 |
|
| 108 |
TIFFClose(tif); |
| 109 |
} |
| 110 |
|
| 111 |
Note |
| 112 |
---- |
| 113 |
|
| 114 |
This functionality was introduced with libtiff 4.5. |
| 115 |
|
| 116 |
See also |
| 117 |
-------- |
| 118 |
|
| 119 |
:doc:`libtiff` (3tiff), |
| 120 |
:doc:`TIFFOpen` (3tiff), |
| 121 |
:doc:`TIFFError` (3tiff), |
| 122 |
:doc:`TIFFWarning` (3tiff) |