@revizly/sharp-libvips-dev 1.0.53 → 1.0.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/include/brotli/decode.h +409 -0
- package/include/brotli/encode.h +505 -0
- package/include/brotli/port.h +302 -0
- package/include/brotli/shared_dictionary.h +100 -0
- package/include/brotli/types.h +83 -0
- package/include/jxl/cms.h +24 -0
- package/include/jxl/cms_interface.h +255 -0
- package/include/jxl/codestream_header.h +433 -0
- package/include/jxl/color_encoding.h +161 -0
- package/include/jxl/compressed_icc.h +75 -0
- package/include/jxl/decode.h +1475 -0
- package/include/jxl/decode_cxx.h +58 -0
- package/include/jxl/encode.h +1629 -0
- package/include/jxl/encode_cxx.h +58 -0
- package/include/jxl/gain_map.h +129 -0
- package/include/jxl/jxl_cms_export.h +42 -0
- package/include/jxl/jxl_export.h +42 -0
- package/include/jxl/jxl_threads_export.h +42 -0
- package/include/jxl/memory_manager.h +73 -0
- package/include/jxl/parallel_runner.h +164 -0
- package/include/jxl/resizable_parallel_runner.h +77 -0
- package/include/jxl/resizable_parallel_runner_cxx.h +65 -0
- package/include/jxl/stats.h +103 -0
- package/include/jxl/thread_parallel_runner.h +71 -0
- package/include/jxl/thread_parallel_runner_cxx.h +66 -0
- package/include/jxl/types.h +154 -0
- package/include/jxl/version.h +44 -0
- package/include/vips/version.h +1 -1
- package/package.json +1 -1
- package/versions.json +2 -0
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
#ifndef __cplusplus
|
|
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
|
+
/// @}
|
|
@@ -0,0 +1,129 @@
|
|
|
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_metadata
|
|
8
|
+
* @{
|
|
9
|
+
* @file gain_map.h
|
|
10
|
+
* @brief Utility functions to manipulate jhgm (gain map) boxes.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
#ifndef JXL_GAIN_MAP_H_
|
|
14
|
+
#define JXL_GAIN_MAP_H_
|
|
15
|
+
|
|
16
|
+
#include <jxl/color_encoding.h>
|
|
17
|
+
#include <jxl/jxl_export.h>
|
|
18
|
+
#include <jxl/types.h>
|
|
19
|
+
|
|
20
|
+
#ifdef __cplusplus
|
|
21
|
+
extern "C" {
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Gain map bundle
|
|
26
|
+
*
|
|
27
|
+
* This structure is used to serialize gain map data to and from an input
|
|
28
|
+
* buffer. It holds pointers to sections within the buffer, and different parts
|
|
29
|
+
* of the gain map data such as metadata, ICC profile data, and the gain map
|
|
30
|
+
* itself.
|
|
31
|
+
*
|
|
32
|
+
* The pointers in this structure do not take ownership of the memory they point
|
|
33
|
+
* to. Instead, they reference specific locations within the provided buffer. It
|
|
34
|
+
* is the caller's responsibility to ensure that the buffer remains valid and is
|
|
35
|
+
* not deallocated as long as these pointers are in use. The structure should be
|
|
36
|
+
* considered as providing a view into the buffer, not as an owner of the data.
|
|
37
|
+
*/
|
|
38
|
+
typedef struct {
|
|
39
|
+
/** Version number of the gain map bundle. */
|
|
40
|
+
uint8_t jhgm_version;
|
|
41
|
+
/** Size of the gain map metadata in bytes. */
|
|
42
|
+
uint16_t gain_map_metadata_size;
|
|
43
|
+
/** Pointer to the gain map metadata, which is a binary
|
|
44
|
+
* blob following ISO 21496-1. This pointer references data within the input
|
|
45
|
+
* buffer. */
|
|
46
|
+
const uint8_t* gain_map_metadata;
|
|
47
|
+
/** Indicates whether a color encoding is present. */
|
|
48
|
+
JXL_BOOL has_color_encoding;
|
|
49
|
+
/** If has_color_encoding is true, this field contains the
|
|
50
|
+
* uncompressed color encoding data. */
|
|
51
|
+
JxlColorEncoding color_encoding;
|
|
52
|
+
/** Size of the alternative ICC profile in bytes (compressed
|
|
53
|
+
* size). */
|
|
54
|
+
uint32_t alt_icc_size;
|
|
55
|
+
/** Pointer to the compressed ICC profile. This pointer references
|
|
56
|
+
* data within the input buffer. */
|
|
57
|
+
const uint8_t* alt_icc;
|
|
58
|
+
/** Size of the gain map in bytes. */
|
|
59
|
+
uint32_t gain_map_size;
|
|
60
|
+
/** Pointer to the gain map data, which is a JPEG XL naked
|
|
61
|
+
* codestream. This pointer references data within the input buffer.*/
|
|
62
|
+
const uint8_t* gain_map;
|
|
63
|
+
} JxlGainMapBundle;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Calculates the total size required to serialize the gain map bundle into a
|
|
67
|
+
* binary buffer. This function accounts for all the necessary space to
|
|
68
|
+
* serialize fields such as gain map metadata, color encoding, compressed ICC
|
|
69
|
+
* profile data, and the gain map itself.
|
|
70
|
+
*
|
|
71
|
+
* @param[in] map_bundle Pointer to the JxlGainMapBundle containing all
|
|
72
|
+
* necessary data to compute the size.
|
|
73
|
+
* @param[out] bundle_size The size in bytes required to serialize the bundle.
|
|
74
|
+
* @return Whether setting the size was successful.
|
|
75
|
+
*/
|
|
76
|
+
JXL_EXPORT JXL_BOOL JxlGainMapGetBundleSize(const JxlGainMapBundle* map_bundle,
|
|
77
|
+
size_t* bundle_size);
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Serializes the gain map bundle into a preallocated buffer. The function
|
|
81
|
+
* ensures that all parts of the bundle such as metadata, color encoding,
|
|
82
|
+
* compressed ICC profile, and the gain map are correctly encoded into the
|
|
83
|
+
* buffer. First call `JxlGainMapGetBundleSize` to get the size needed for
|
|
84
|
+
* the buffer.
|
|
85
|
+
*
|
|
86
|
+
* @param[in] map_bundle Pointer to the `JxlGainMapBundle` to serialize.
|
|
87
|
+
* @param[out] output_buffer Pointer to the buffer where the serialized data
|
|
88
|
+
* will be written.
|
|
89
|
+
* @param[in] output_buffer_size The size of the output buffer in bytes. Must be
|
|
90
|
+
* large enough to hold the entire serialized data.
|
|
91
|
+
* @param[out] bytes_written The number of bytes written to the output buffer.
|
|
92
|
+
* @return Whether writing the bundle was successful.
|
|
93
|
+
*/
|
|
94
|
+
JXL_EXPORT JXL_BOOL JxlGainMapWriteBundle(const JxlGainMapBundle* map_bundle,
|
|
95
|
+
uint8_t* output_buffer,
|
|
96
|
+
size_t output_buffer_size,
|
|
97
|
+
size_t* bytes_written);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Deserializes a gain map bundle from a provided buffer and populates a
|
|
101
|
+
* `JxlGainMapBundle` structure with the data extracted. This function assumes
|
|
102
|
+
* the buffer contains a valid serialized gain map bundle. After successful
|
|
103
|
+
* execution, the `JxlGainMapBundle` structure will reference three different
|
|
104
|
+
* sections within the buffer:
|
|
105
|
+
* - gain_map_metadata
|
|
106
|
+
* - alt_icc
|
|
107
|
+
* - gain_map
|
|
108
|
+
* These sections will be accompanied by their respective sizes. Users must
|
|
109
|
+
* ensure that the buffer remains valid as long as these pointers are in use.
|
|
110
|
+
* @param[in,out] map_bundle Pointer to a preallocated `JxlGainMapBundle` where
|
|
111
|
+
* the deserialized data will be stored.
|
|
112
|
+
* @param[in] input_buffer Pointer to the buffer containing the serialized gain
|
|
113
|
+
* map bundle data.
|
|
114
|
+
* @param[in] input_buffer_size The size of the input buffer in bytes.
|
|
115
|
+
* @param[out] bytes_read The number of bytes read from the input buffer.
|
|
116
|
+
* @return Whether reading the bundle was successful.
|
|
117
|
+
*/
|
|
118
|
+
JXL_EXPORT JXL_BOOL JxlGainMapReadBundle(JxlGainMapBundle* map_bundle,
|
|
119
|
+
const uint8_t* input_buffer,
|
|
120
|
+
size_t input_buffer_size,
|
|
121
|
+
size_t* bytes_read);
|
|
122
|
+
|
|
123
|
+
#ifdef __cplusplus
|
|
124
|
+
}
|
|
125
|
+
#endif
|
|
126
|
+
|
|
127
|
+
#endif /* JXL_GAIN_MAP_H_ */
|
|
128
|
+
|
|
129
|
+
/** @} */
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
#ifndef JXL_CMS_EXPORT_H
|
|
3
|
+
#define JXL_CMS_EXPORT_H
|
|
4
|
+
|
|
5
|
+
#ifdef JXL_CMS_STATIC_DEFINE
|
|
6
|
+
# define JXL_CMS_EXPORT
|
|
7
|
+
# define JXL_CMS_NO_EXPORT
|
|
8
|
+
#else
|
|
9
|
+
# ifndef JXL_CMS_EXPORT
|
|
10
|
+
# ifdef jxl_cms_EXPORTS
|
|
11
|
+
/* We are building this library */
|
|
12
|
+
# define JXL_CMS_EXPORT
|
|
13
|
+
# else
|
|
14
|
+
/* We are using this library */
|
|
15
|
+
# define JXL_CMS_EXPORT
|
|
16
|
+
# endif
|
|
17
|
+
# endif
|
|
18
|
+
|
|
19
|
+
# ifndef JXL_CMS_NO_EXPORT
|
|
20
|
+
# define JXL_CMS_NO_EXPORT
|
|
21
|
+
# endif
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
#ifndef JXL_CMS_DEPRECATED
|
|
25
|
+
# define JXL_CMS_DEPRECATED __attribute__ ((__deprecated__))
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
#ifndef JXL_CMS_DEPRECATED_EXPORT
|
|
29
|
+
# define JXL_CMS_DEPRECATED_EXPORT JXL_CMS_EXPORT JXL_CMS_DEPRECATED
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
#ifndef JXL_CMS_DEPRECATED_NO_EXPORT
|
|
33
|
+
# define JXL_CMS_DEPRECATED_NO_EXPORT JXL_CMS_NO_EXPORT JXL_CMS_DEPRECATED
|
|
34
|
+
#endif
|
|
35
|
+
|
|
36
|
+
#if 0 /* DEFINE_NO_DEPRECATED */
|
|
37
|
+
# ifndef JXL_CMS_NO_DEPRECATED
|
|
38
|
+
# define JXL_CMS_NO_DEPRECATED
|
|
39
|
+
# endif
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
#endif /* JXL_CMS_EXPORT_H */
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
#ifndef JXL_EXPORT_H
|
|
3
|
+
#define JXL_EXPORT_H
|
|
4
|
+
|
|
5
|
+
#ifdef JXL_STATIC_DEFINE
|
|
6
|
+
# define JXL_EXPORT
|
|
7
|
+
# define JXL_NO_EXPORT
|
|
8
|
+
#else
|
|
9
|
+
# ifndef JXL_EXPORT
|
|
10
|
+
# ifdef JXL_INTERNAL_LIBRARY_BUILD
|
|
11
|
+
/* We are building this library */
|
|
12
|
+
# define JXL_EXPORT __attribute__((visibility("default")))
|
|
13
|
+
# else
|
|
14
|
+
/* We are using this library */
|
|
15
|
+
# define JXL_EXPORT __attribute__((visibility("default")))
|
|
16
|
+
# endif
|
|
17
|
+
# endif
|
|
18
|
+
|
|
19
|
+
# ifndef JXL_NO_EXPORT
|
|
20
|
+
# define JXL_NO_EXPORT __attribute__((visibility("hidden")))
|
|
21
|
+
# endif
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
#ifndef JXL_DEPRECATED
|
|
25
|
+
# define JXL_DEPRECATED __attribute__ ((__deprecated__))
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
#ifndef JXL_DEPRECATED_EXPORT
|
|
29
|
+
# define JXL_DEPRECATED_EXPORT JXL_EXPORT JXL_DEPRECATED
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
#ifndef JXL_DEPRECATED_NO_EXPORT
|
|
33
|
+
# define JXL_DEPRECATED_NO_EXPORT JXL_NO_EXPORT JXL_DEPRECATED
|
|
34
|
+
#endif
|
|
35
|
+
|
|
36
|
+
#if 0 /* DEFINE_NO_DEPRECATED */
|
|
37
|
+
# ifndef JXL_NO_DEPRECATED
|
|
38
|
+
# define JXL_NO_DEPRECATED
|
|
39
|
+
# endif
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
#endif /* JXL_EXPORT_H */
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
#ifndef JXL_THREADS_EXPORT_H
|
|
3
|
+
#define JXL_THREADS_EXPORT_H
|
|
4
|
+
|
|
5
|
+
#ifdef JXL_THREADS_STATIC_DEFINE
|
|
6
|
+
# define JXL_THREADS_EXPORT
|
|
7
|
+
# define JXL_THREADS_NO_EXPORT
|
|
8
|
+
#else
|
|
9
|
+
# ifndef JXL_THREADS_EXPORT
|
|
10
|
+
# ifdef JXL_THREADS_INTERNAL_LIBRARY_BUILD
|
|
11
|
+
/* We are building this library */
|
|
12
|
+
# define JXL_THREADS_EXPORT
|
|
13
|
+
# else
|
|
14
|
+
/* We are using this library */
|
|
15
|
+
# define JXL_THREADS_EXPORT
|
|
16
|
+
# endif
|
|
17
|
+
# endif
|
|
18
|
+
|
|
19
|
+
# ifndef JXL_THREADS_NO_EXPORT
|
|
20
|
+
# define JXL_THREADS_NO_EXPORT
|
|
21
|
+
# endif
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
#ifndef JXL_THREADS_DEPRECATED
|
|
25
|
+
# define JXL_THREADS_DEPRECATED __attribute__ ((__deprecated__))
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
#ifndef JXL_THREADS_DEPRECATED_EXPORT
|
|
29
|
+
# define JXL_THREADS_DEPRECATED_EXPORT JXL_THREADS_EXPORT JXL_THREADS_DEPRECATED
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
#ifndef JXL_THREADS_DEPRECATED_NO_EXPORT
|
|
33
|
+
# define JXL_THREADS_DEPRECATED_NO_EXPORT JXL_THREADS_NO_EXPORT JXL_THREADS_DEPRECATED
|
|
34
|
+
#endif
|
|
35
|
+
|
|
36
|
+
#if 0 /* DEFINE_NO_DEPRECATED */
|
|
37
|
+
# ifndef JXL_THREADS_NO_DEPRECATED
|
|
38
|
+
# define JXL_THREADS_NO_DEPRECATED
|
|
39
|
+
# endif
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
#endif /* JXL_THREADS_EXPORT_H */
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
#ifdef __cplusplus
|
|
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, otherwise with the
|
|
59
|
+
* standard malloc/free. */
|
|
60
|
+
jpegxl_alloc_func alloc;
|
|
61
|
+
/** Free function matching the alloc() member. */
|
|
62
|
+
jpegxl_free_func free;
|
|
63
|
+
|
|
64
|
+
/* TODO(deymo): Add cache-aligned alloc/free functions here. */
|
|
65
|
+
} JxlMemoryManager;
|
|
66
|
+
|
|
67
|
+
#ifdef __cplusplus
|
|
68
|
+
}
|
|
69
|
+
#endif
|
|
70
|
+
|
|
71
|
+
#endif /* JXL_MEMORY_MANAGER_H_ */
|
|
72
|
+
|
|
73
|
+
/** @}*/
|
|
@@ -0,0 +1,164 @@
|
|
|
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_threads
|
|
8
|
+
* @{
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @file parallel_runner.h
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** API for running data operations in parallel in a multi-threaded environment.
|
|
15
|
+
* This module allows the JPEG XL caller to define their own way of creating and
|
|
16
|
+
* assigning threads.
|
|
17
|
+
*
|
|
18
|
+
* The JxlParallelRunner function type defines a parallel data processing
|
|
19
|
+
* runner that may be implemented by the caller to allow the library to process
|
|
20
|
+
* in multiple threads. The multi-threaded processing in this library only
|
|
21
|
+
* requires to run the same function over each number of a range, possibly
|
|
22
|
+
* running each call in a different thread. The JPEG XL caller is responsible
|
|
23
|
+
* for implementing this logic using the thread APIs available in their system.
|
|
24
|
+
* For convenience, a C++ implementation based on std::thread is provided in
|
|
25
|
+
* jpegxl/parallel_runner_thread.h (part of the jpegxl_threads library).
|
|
26
|
+
*
|
|
27
|
+
* Thread pools usually store small numbers of heterogeneous tasks in a queue.
|
|
28
|
+
* When tasks are identical or differ only by an integer input parameter, it is
|
|
29
|
+
* much faster to store just one function of an integer parameter and call it
|
|
30
|
+
* for each value. Conventional vector-of-tasks can be run in parallel using a
|
|
31
|
+
* lambda function adapter that simply calls task_funcs[task].
|
|
32
|
+
*
|
|
33
|
+
* If no multi-threading is desired, a @c NULL value of JxlParallelRunner
|
|
34
|
+
* will use an internal implementation without multi-threading.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
#ifndef JXL_PARALLEL_RUNNER_H_
|
|
38
|
+
#define JXL_PARALLEL_RUNNER_H_
|
|
39
|
+
|
|
40
|
+
#include <stddef.h>
|
|
41
|
+
#include <stdint.h>
|
|
42
|
+
|
|
43
|
+
#ifdef __cplusplus
|
|
44
|
+
extern "C" {
|
|
45
|
+
#endif
|
|
46
|
+
|
|
47
|
+
/** Return code used in the JxlParallel* functions as return value. A value
|
|
48
|
+
* of ::JXL_PARALLEL_RET_SUCCESS means success and any other value means error.
|
|
49
|
+
* The special value ::JXL_PARALLEL_RET_RUNNER_ERROR can be used by the runner
|
|
50
|
+
* to indicate any other error.
|
|
51
|
+
*/
|
|
52
|
+
typedef int JxlParallelRetCode;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Code returned by the @ref JxlParallelRunInit function to indicate success.
|
|
56
|
+
*/
|
|
57
|
+
#define JXL_PARALLEL_RET_SUCCESS (0)
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Code returned by the @ref JxlParallelRunInit function to indicate a general
|
|
61
|
+
* error.
|
|
62
|
+
*/
|
|
63
|
+
#define JXL_PARALLEL_RET_RUNNER_ERROR (-1)
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Parallel run initialization callback. See @ref JxlParallelRunner for details.
|
|
67
|
+
*
|
|
68
|
+
* This function MUST be called by the JxlParallelRunner only once, on the
|
|
69
|
+
* same thread that called @ref JxlParallelRunner, before any parallel
|
|
70
|
+
* execution. The purpose of this call is to provide the maximum number of
|
|
71
|
+
* threads that the
|
|
72
|
+
* @ref JxlParallelRunner will use, which can be used by JPEG XL to allocate
|
|
73
|
+
* per-thread storage if needed.
|
|
74
|
+
*
|
|
75
|
+
* @param jpegxl_opaque the @p jpegxl_opaque handle provided to
|
|
76
|
+
* @ref JxlParallelRunner() must be passed here.
|
|
77
|
+
* @param num_threads the maximum number of threads. This value must be
|
|
78
|
+
* positive.
|
|
79
|
+
* @return 0 if the initialization process was successful.
|
|
80
|
+
* @return an error code if there was an error, which should be returned by
|
|
81
|
+
* @ref JxlParallelRunner().
|
|
82
|
+
*/
|
|
83
|
+
typedef JxlParallelRetCode (*JxlParallelRunInit)(void* jpegxl_opaque,
|
|
84
|
+
size_t num_threads);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Parallel run data processing callback. See @ref JxlParallelRunner for
|
|
88
|
+
* details.
|
|
89
|
+
*
|
|
90
|
+
* This function MUST be called once for every number in the range [start_range,
|
|
91
|
+
* end_range) (including start_range but not including end_range) passing this
|
|
92
|
+
* number as the @p value. Calls for different value may be executed from
|
|
93
|
+
* different threads in parallel.
|
|
94
|
+
*
|
|
95
|
+
* @param jpegxl_opaque the @p jpegxl_opaque handle provided to
|
|
96
|
+
* @ref JxlParallelRunner() must be passed here.
|
|
97
|
+
* @param value the number in the range [start_range, end_range) of the call.
|
|
98
|
+
* @param thread_id the thread number where this function is being called from.
|
|
99
|
+
* This must be lower than the @p num_threads value passed to
|
|
100
|
+
* @ref JxlParallelRunInit.
|
|
101
|
+
*/
|
|
102
|
+
typedef void (*JxlParallelRunFunction)(void* jpegxl_opaque, uint32_t value,
|
|
103
|
+
size_t thread_id);
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* JxlParallelRunner function type. A parallel runner implementation can be
|
|
107
|
+
* provided by a JPEG XL caller to allow running computations in multiple
|
|
108
|
+
* threads. This function must call the initialization function @p init in the
|
|
109
|
+
* same thread that called it and then call the passed @p func once for every
|
|
110
|
+
* number in the range [start_range, end_range) (including start_range but not
|
|
111
|
+
* including end_range) possibly from different multiple threads in parallel.
|
|
112
|
+
*
|
|
113
|
+
* The @ref JxlParallelRunner function does not need to be re-entrant. This
|
|
114
|
+
* means that the same @ref JxlParallelRunner function with the same
|
|
115
|
+
* runner_opaque provided parameter will not be called from the library from
|
|
116
|
+
* either @p init or
|
|
117
|
+
* @p func in the same decoder or encoder instance. However, a single decoding
|
|
118
|
+
* or encoding instance may call the provided @ref JxlParallelRunner multiple
|
|
119
|
+
* times for different parts of the decoding or encoding process.
|
|
120
|
+
*
|
|
121
|
+
* @return 0 if the @p init call succeeded (returned 0) and no other error
|
|
122
|
+
* occurred in the runner code.
|
|
123
|
+
* @return JXL_PARALLEL_RET_RUNNER_ERROR if an error occurred in the runner
|
|
124
|
+
* code, for example, setting up the threads.
|
|
125
|
+
* @return the return value of @p init() if non-zero.
|
|
126
|
+
*/
|
|
127
|
+
typedef JxlParallelRetCode (*JxlParallelRunner)(
|
|
128
|
+
void* runner_opaque, void* jpegxl_opaque, JxlParallelRunInit init,
|
|
129
|
+
JxlParallelRunFunction func, uint32_t start_range, uint32_t end_range);
|
|
130
|
+
|
|
131
|
+
/* The following is an example of a @ref JxlParallelRunner that doesn't use any
|
|
132
|
+
* multi-threading. Note that this implementation doesn't store any state
|
|
133
|
+
* between multiple calls of the ExampleSequentialRunner function, so the
|
|
134
|
+
* runner_opaque value is not used.
|
|
135
|
+
|
|
136
|
+
JxlParallelRetCode ExampleSequentialRunner(void* runner_opaque,
|
|
137
|
+
void* jpegxl_opaque,
|
|
138
|
+
JxlParallelRunInit init,
|
|
139
|
+
JxlParallelRunFunction func,
|
|
140
|
+
uint32_t start_range,
|
|
141
|
+
uint32_t end_range) {
|
|
142
|
+
// We only use one thread (the currently running thread).
|
|
143
|
+
JxlParallelRetCode init_ret = (*init)(jpegxl_opaque, 1);
|
|
144
|
+
if (init_ret != 0) return init_ret;
|
|
145
|
+
|
|
146
|
+
// In case of other initialization error (for example when initializing the
|
|
147
|
+
// threads) one can return JXL_PARALLEL_RET_RUNNER_ERROR.
|
|
148
|
+
|
|
149
|
+
for (uint32_t i = start_range; i < end_range; i++) {
|
|
150
|
+
// Every call is in the thread number 0. These don't need to be in any
|
|
151
|
+
// order.
|
|
152
|
+
(*func)(jpegxl_opaque, i, 0);
|
|
153
|
+
}
|
|
154
|
+
return JXL_PARALLEL_RET_SUCCESS;
|
|
155
|
+
}
|
|
156
|
+
*/
|
|
157
|
+
|
|
158
|
+
#ifdef __cplusplus
|
|
159
|
+
}
|
|
160
|
+
#endif
|
|
161
|
+
|
|
162
|
+
#endif /* JXL_PARALLEL_RUNNER_H_ */
|
|
163
|
+
|
|
164
|
+
/** @}*/
|
|
@@ -0,0 +1,77 @@
|
|
|
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_threads
|
|
8
|
+
* @{
|
|
9
|
+
* @file resizable_parallel_runner.h
|
|
10
|
+
* @brief implementation using std::thread of a resizeable ::JxlParallelRunner.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** Implementation of JxlParallelRunner than can be used to enable
|
|
14
|
+
* multithreading when using the JPEG XL library. This uses std::thread
|
|
15
|
+
* internally and related synchronization functions. The number of threads
|
|
16
|
+
* created can be changed after creation of the thread pool; the threads
|
|
17
|
+
* (including the main thread) are re-used for every
|
|
18
|
+
* ResizableParallelRunner::Runner call. Only one concurrent
|
|
19
|
+
* @ref JxlResizableParallelRunner call per instance is allowed at a time.
|
|
20
|
+
*
|
|
21
|
+
* This is a scalable, lower-overhead thread pool runner, especially suitable
|
|
22
|
+
* for data-parallel computations in the fork-join model, where clients need to
|
|
23
|
+
* know when all tasks have completed.
|
|
24
|
+
*
|
|
25
|
+
* Compared to the implementation in @ref thread_parallel_runner.h, this
|
|
26
|
+
* implementation is tuned for execution on lower-powered systems, including
|
|
27
|
+
* for example ARM CPUs with big.LITTLE computation models.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
#ifndef JXL_RESIZABLE_PARALLEL_RUNNER_H_
|
|
31
|
+
#define JXL_RESIZABLE_PARALLEL_RUNNER_H_
|
|
32
|
+
|
|
33
|
+
#include <jxl/jxl_threads_export.h>
|
|
34
|
+
#include <jxl/memory_manager.h>
|
|
35
|
+
#include <jxl/parallel_runner.h>
|
|
36
|
+
#include <stddef.h>
|
|
37
|
+
#include <stdint.h>
|
|
38
|
+
#include <stdlib.h>
|
|
39
|
+
|
|
40
|
+
#ifdef __cplusplus
|
|
41
|
+
extern "C" {
|
|
42
|
+
#endif
|
|
43
|
+
|
|
44
|
+
/** Parallel runner internally using std::thread. Use as @ref JxlParallelRunner.
|
|
45
|
+
*/
|
|
46
|
+
JXL_THREADS_EXPORT JxlParallelRetCode JxlResizableParallelRunner(
|
|
47
|
+
void* runner_opaque, void* jpegxl_opaque, JxlParallelRunInit init,
|
|
48
|
+
JxlParallelRunFunction func, uint32_t start_range, uint32_t end_range);
|
|
49
|
+
|
|
50
|
+
/** Creates the runner for @ref JxlResizableParallelRunner. Use as the opaque
|
|
51
|
+
* runner. The runner will execute tasks on the calling thread until
|
|
52
|
+
* @ref JxlResizableParallelRunnerSetThreads is called.
|
|
53
|
+
*/
|
|
54
|
+
JXL_THREADS_EXPORT void* JxlResizableParallelRunnerCreate(
|
|
55
|
+
const JxlMemoryManager* memory_manager);
|
|
56
|
+
|
|
57
|
+
/** Changes the number of threads for @ref JxlResizableParallelRunner.
|
|
58
|
+
*/
|
|
59
|
+
JXL_THREADS_EXPORT void JxlResizableParallelRunnerSetThreads(
|
|
60
|
+
void* runner_opaque, size_t num_threads);
|
|
61
|
+
|
|
62
|
+
/** Suggests a number of threads to use for an image of given size.
|
|
63
|
+
*/
|
|
64
|
+
JXL_THREADS_EXPORT uint32_t
|
|
65
|
+
JxlResizableParallelRunnerSuggestThreads(uint64_t xsize, uint64_t ysize);
|
|
66
|
+
|
|
67
|
+
/** Destroys the runner created by @ref JxlResizableParallelRunnerCreate.
|
|
68
|
+
*/
|
|
69
|
+
JXL_THREADS_EXPORT void JxlResizableParallelRunnerDestroy(void* runner_opaque);
|
|
70
|
+
|
|
71
|
+
#ifdef __cplusplus
|
|
72
|
+
}
|
|
73
|
+
#endif
|
|
74
|
+
|
|
75
|
+
#endif /* JXL_RESIZABLE_PARALLEL_RUNNER_H_ */
|
|
76
|
+
|
|
77
|
+
/** @}*/
|