libjxl

FORK: libjxl patches used on blog
git clone https://git.neptards.moe/blog/libjxl.git
Log | Files | Refs | Submodules | README | LICENSE

memory_manager.h (2121B)


      1 /* Copyright (c) the JPEG XL Project Authors. All rights reserved.
      2  *
      3  * Use of this source code is governed by a BSD-style
      4  * license that can be found in the LICENSE file.
      5  */
      6 
      7 /** @addtogroup libjxl_common
      8  * @{
      9  * @file memory_manager.h
     10  * @brief Abstraction functions used by JPEG XL to allocate memory.
     11  */
     12 
     13 #ifndef JXL_MEMORY_MANAGER_H_
     14 #define JXL_MEMORY_MANAGER_H_
     15 
     16 #include <stddef.h>
     17 
     18 #if defined(__cplusplus) || defined(c_plusplus)
     19 extern "C" {
     20 #endif
     21 
     22 /**
     23  * Allocating function for a memory region of a given size.
     24  *
     25  * Allocates a contiguous memory region of size @p size bytes. The returned
     26  * memory may not be aligned to a specific size or initialized at all.
     27  *
     28  * @param opaque custom memory manager handle provided by the caller.
     29  * @param size in bytes of the requested memory region.
     30  * @return @c NULL if the memory can not be allocated,
     31  * @return pointer to the memory otherwise.
     32  */
     33 typedef void* (*jpegxl_alloc_func)(void* opaque, size_t size);
     34 
     35 /**
     36  * Deallocating function pointer type.
     37  *
     38  * This function @b MUST do nothing if @p address is @c NULL.
     39  *
     40  * @param opaque custom memory manager handle provided by the caller.
     41  * @param address memory region pointer returned by ::jpegxl_alloc_func, or @c
     42  * NULL.
     43  */
     44 typedef void (*jpegxl_free_func)(void* opaque, void* address);
     45 
     46 /**
     47  * Memory Manager struct.
     48  * These functions, when provided by the caller, will be used to handle memory
     49  * allocations.
     50  */
     51 typedef struct JxlMemoryManagerStruct {
     52   /** The opaque pointer that will be passed as the first parameter to all the
     53    * functions in this struct. */
     54   void* opaque;
     55 
     56   /** Memory allocation function. This can be NULL if and only if also the
     57    * free() member in this class is NULL. All dynamic memory will be allocated
     58    * and freed with these functions if they are not NULL. */
     59   jpegxl_alloc_func alloc;
     60   /** Free function matching the alloc() member. */
     61   jpegxl_free_func free;
     62 
     63   /* TODO(deymo): Add cache-aligned alloc/free functions here. */
     64 } JxlMemoryManager;
     65 
     66 #if defined(__cplusplus) || defined(c_plusplus)
     67 }
     68 #endif
     69 
     70 #endif /* JXL_MEMORY_MANAGER_H_ */
     71 
     72 /** @}*/