openexr_base.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. ** SPDX-License-Identifier: BSD-3-Clause
  3. ** Copyright Contributors to the OpenEXR Project.
  4. */
  5. #ifndef OPENEXR_BASE_H
  6. #define OPENEXR_BASE_H
  7. #include "openexr_conf.h"
  8. #include <stddef.h>
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /** @file */
  13. /** @brief Retrieve the current library version. The @p extra string is for
  14. * custom installs, and is a static string, do not free the returned
  15. * pointer.
  16. */
  17. EXR_EXPORT void
  18. exr_get_library_version (int* maj, int* min, int* patch, const char** extra);
  19. /**
  20. * @defgroup SafetyChecks Controls for internal safety checks
  21. * @{
  22. */
  23. /** @brief Limit the size of image allowed to be parsed or created by
  24. * the library.
  25. *
  26. * This is used as a safety check against corrupt files, but can also
  27. * serve to avoid potential issues on machines which have very
  28. * constrained RAM.
  29. *
  30. * These values are among the only globals in the core layer of
  31. * OpenEXR. The intended use is for applications to define a global
  32. * default, which will be combined with the values provided to the
  33. * individual context creation routine. The values are used to check
  34. * against parsed header values. This adds some level of safety from
  35. * memory overruns where a corrupt file given to the system may cause
  36. * a large allocation to happen, enabling buffer overruns or other
  37. * potential security issue.
  38. *
  39. * These global values are combined with the values in
  40. * \ref exr_context_initializer_t using the following rules:
  41. *
  42. * 1. negative values are ignored.
  43. *
  44. * 2. if either value has a positive (non-zero) value, and the other
  45. * has 0, the positive value is preferred.
  46. *
  47. * 3. If both are positive (non-zero), the minimum value is used.
  48. *
  49. * 4. If both values are 0, this disables the constrained size checks.
  50. *
  51. * This function does not fail.
  52. */
  53. EXR_EXPORT void exr_set_default_maximum_image_size (int w, int h);
  54. /** @brief Retrieve the global default maximum image size.
  55. *
  56. * This function does not fail.
  57. */
  58. EXR_EXPORT void exr_get_default_maximum_image_size (int* w, int* h);
  59. /** @brief Limit the size of an image tile allowed to be parsed or
  60. * created by the library.
  61. *
  62. * Similar to image size, this places constraints on the maximum tile
  63. * size as a safety check against bad file data
  64. *
  65. * This is used as a safety check against corrupt files, but can also
  66. * serve to avoid potential issues on machines which have very
  67. * constrained RAM
  68. *
  69. * These values are among the only globals in the core layer of
  70. * OpenEXR. The intended use is for applications to define a global
  71. * default, which will be combined with the values provided to the
  72. * individual context creation routine. The values are used to check
  73. * against parsed header values. This adds some level of safety from
  74. * memory overruns where a corrupt file given to the system may cause
  75. * a large allocation to happen, enabling buffer overruns or other
  76. * potential security issue.
  77. *
  78. * These global values are combined with the values in
  79. * \ref exr_context_initializer_t using the following rules:
  80. *
  81. * 1. negative values are ignored.
  82. *
  83. * 2. if either value has a positive (non-zero) value, and the other
  84. * has 0, the positive value is preferred.
  85. *
  86. * 3. If both are positive (non-zero), the minimum value is used.
  87. *
  88. * 4. If both values are 0, this disables the constrained size checks.
  89. *
  90. * This function does not fail.
  91. */
  92. EXR_EXPORT void exr_set_default_maximum_tile_size (int w, int h);
  93. /** @brief Retrieve the global maximum tile size.
  94. *
  95. * This function does not fail.
  96. */
  97. EXR_EXPORT void exr_get_default_maximum_tile_size (int* w, int* h);
  98. /** @} */
  99. /**
  100. * @defgroup CompressionDefaults Provides default compression settings
  101. * @{
  102. */
  103. /** @brief Assigns a default zip compression level.
  104. *
  105. * This value may be controlled separately on each part, but this
  106. * global control determines the initial value.
  107. */
  108. EXR_EXPORT void exr_set_default_zip_compression_level (int l);
  109. /** @brief Retrieve the global default zip compression value
  110. */
  111. EXR_EXPORT void exr_get_default_zip_compression_level (int* l);
  112. /** @brief Assigns a default DWA compression quality level.
  113. *
  114. * This value may be controlled separately on each part, but this
  115. * global control determines the initial value.
  116. */
  117. EXR_EXPORT void exr_set_default_dwa_compression_quality (float q);
  118. /** @brief Retrieve the global default dwa compression quality
  119. */
  120. EXR_EXPORT void exr_get_default_dwa_compression_quality (float* q);
  121. /** @} */
  122. /**
  123. * @defgroup MemoryAllocators Provides global control over memory allocators
  124. * @{
  125. */
  126. /** @brief Function pointer used to hold a malloc-like routine.
  127. *
  128. * Providing these to a context will override what memory is used to
  129. * allocate the context itself, as well as any allocations which
  130. * happen during processing of a file or stream. This can be used by
  131. * systems which provide rich malloc tracking routines to override the
  132. * internal allocations performed by the library.
  133. *
  134. * This function is expected to allocate and return a new memory
  135. * handle, or `NULL` if allocation failed (which the library will then
  136. * handle and return an out-of-memory error).
  137. *
  138. * If one is provided, both should be provided.
  139. * @sa exr_memory_free_func_t
  140. */
  141. typedef void* (*exr_memory_allocation_func_t) (size_t bytes);
  142. /** @brief Function pointer used to hold a free-like routine.
  143. *
  144. * Providing these to a context will override what memory is used to
  145. * allocate the context itself, as well as any allocations which
  146. * happen during processing of a file or stream. This can be used by
  147. * systems which provide rich malloc tracking routines to override the
  148. * internal allocations performed by the library.
  149. *
  150. * This function is expected to return memory to the system, ala free
  151. * from the C library.
  152. *
  153. * If providing one, probably need to provide both routines.
  154. * @sa exr_memory_allocation_func_t
  155. */
  156. typedef void (*exr_memory_free_func_t) (void* ptr);
  157. /** @brief Allow the user to override default allocator used internal
  158. * allocations necessary for files, attributes, and other temporary
  159. * memory.
  160. *
  161. * These routines may be overridden when creating a specific context,
  162. * however this provides global defaults such that the default can be
  163. * applied.
  164. *
  165. * If either pointer is 0, the appropriate malloc/free routine will be
  166. * substituted.
  167. *
  168. * This function does not fail.
  169. */
  170. EXR_EXPORT void exr_set_default_memory_routines (
  171. exr_memory_allocation_func_t alloc_func, exr_memory_free_func_t free_func);
  172. /** @} */
  173. #ifdef __cplusplus
  174. } /* extern "C" */
  175. #endif
  176. #endif /* OPENEXR_BASE_H */