/src/libjxl/lib/include/jxl/encode_cxx.h
Line | Count | Source (jump to first uncovered line) |
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_encoder |
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 | | |
20 | | #include <memory> |
21 | | |
22 | | #if !(defined(__cplusplus) || defined(c_plusplus)) |
23 | | #error "This a C++ only header. Use jxl/encode.h from C sources." |
24 | | #endif |
25 | | |
26 | | /// Struct to call JxlEncoderDestroy from the JxlEncoderPtr unique_ptr. |
27 | | struct JxlEncoderDestroyStruct { |
28 | | /// Calls @ref JxlEncoderDestroy() on the passed encoder. |
29 | 0 | void operator()(JxlEncoder* encoder) { JxlEncoderDestroy(encoder); } |
30 | | }; |
31 | | |
32 | | /// std::unique_ptr<> type that calls JxlEncoderDestroy() when releasing the |
33 | | /// encoder. |
34 | | /// |
35 | | /// Use this helper type from C++ sources to ensure the encoder is destroyed and |
36 | | /// their internal resources released. |
37 | | typedef std::unique_ptr<JxlEncoder, JxlEncoderDestroyStruct> JxlEncoderPtr; |
38 | | |
39 | | /// Creates an instance of JxlEncoder into a JxlEncoderPtr and initializes it. |
40 | | /// |
41 | | /// This function returns a unique_ptr that will call JxlEncoderDestroy() when |
42 | | /// releasing the pointer. See @ref JxlEncoderCreate for details on the |
43 | | /// instance creation. |
44 | | /// |
45 | | /// @param memory_manager custom allocator function. It may be NULL. The memory |
46 | | /// manager will be copied internally. |
47 | | /// @return a @c NULL JxlEncoderPtr if the instance can not be allocated or |
48 | | /// initialized |
49 | | /// @return initialized JxlEncoderPtr instance otherwise. |
50 | | static inline JxlEncoderPtr JxlEncoderMake( |
51 | 0 | const JxlMemoryManager* memory_manager) { |
52 | 0 | return JxlEncoderPtr(JxlEncoderCreate(memory_manager)); |
53 | 0 | } |
54 | | |
55 | | #endif // JXL_ENCODE_CXX_H_ |
56 | | |
57 | | /// @} |