libjxl

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

encode_cxx.h (1909B)


      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 /// @addtogroup libjxl_cpp
      7 ///@{
      8 ///
      9 /// @file encode_cxx.h
     10 /// @brief C++ header-only helper for @ref encode.h.
     11 ///
     12 /// There's no binary library associated with the header since this is a header
     13 /// only library.
     14 
     15 #ifndef JXL_ENCODE_CXX_H_
     16 #define JXL_ENCODE_CXX_H_
     17 
     18 #include <jxl/encode.h>
     19 #include <jxl/memory_manager.h>
     20 
     21 #include <memory>
     22 
     23 #if !(defined(__cplusplus) || defined(c_plusplus))
     24 #error "This a C++ only header. Use jxl/encode.h from C sources."
     25 #endif
     26 
     27 /// Struct to call JxlEncoderDestroy from the JxlEncoderPtr unique_ptr.
     28 struct JxlEncoderDestroyStruct {
     29   /// Calls @ref JxlEncoderDestroy() on the passed encoder.
     30   void operator()(JxlEncoder* encoder) { JxlEncoderDestroy(encoder); }
     31 };
     32 
     33 /// std::unique_ptr<> type that calls JxlEncoderDestroy() when releasing the
     34 /// encoder.
     35 ///
     36 /// Use this helper type from C++ sources to ensure the encoder is destroyed and
     37 /// their internal resources released.
     38 typedef std::unique_ptr<JxlEncoder, JxlEncoderDestroyStruct> JxlEncoderPtr;
     39 
     40 /// Creates an instance of JxlEncoder into a JxlEncoderPtr and initializes it.
     41 ///
     42 /// This function returns a unique_ptr that will call JxlEncoderDestroy() when
     43 /// releasing the pointer. See @ref JxlEncoderCreate for details on the
     44 /// instance creation.
     45 ///
     46 /// @param memory_manager custom allocator function. It may be NULL. The memory
     47 ///        manager will be copied internally.
     48 /// @return a @c NULL JxlEncoderPtr if the instance can not be allocated or
     49 ///         initialized
     50 /// @return initialized JxlEncoderPtr instance otherwise.
     51 static inline JxlEncoderPtr JxlEncoderMake(
     52     const JxlMemoryManager* memory_manager) {
     53   return JxlEncoderPtr(JxlEncoderCreate(memory_manager));
     54 }
     55 
     56 #endif  // JXL_ENCODE_CXX_H_
     57 
     58 /// @}