@revizly/sharp-libvips-dev 1.0.52 → 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.
Files changed (48) hide show
  1. package/README.md +2 -0
  2. package/include/brotli/decode.h +409 -0
  3. package/include/brotli/encode.h +505 -0
  4. package/include/brotli/port.h +302 -0
  5. package/include/brotli/shared_dictionary.h +100 -0
  6. package/include/brotli/types.h +83 -0
  7. package/include/expat.h +72 -27
  8. package/include/expat_config.h +3 -7
  9. package/include/expat_external.h +3 -0
  10. package/include/glib-2.0/glib/gutils.h +1 -1
  11. package/include/harfbuzz/hb-version.h +2 -2
  12. package/include/jxl/cms.h +24 -0
  13. package/include/jxl/cms_interface.h +255 -0
  14. package/include/jxl/codestream_header.h +433 -0
  15. package/include/jxl/color_encoding.h +161 -0
  16. package/include/jxl/compressed_icc.h +75 -0
  17. package/include/jxl/decode.h +1475 -0
  18. package/include/jxl/decode_cxx.h +58 -0
  19. package/include/jxl/encode.h +1629 -0
  20. package/include/jxl/encode_cxx.h +58 -0
  21. package/include/jxl/gain_map.h +129 -0
  22. package/include/jxl/jxl_cms_export.h +42 -0
  23. package/include/jxl/jxl_export.h +42 -0
  24. package/include/jxl/jxl_threads_export.h +42 -0
  25. package/include/jxl/memory_manager.h +73 -0
  26. package/include/jxl/parallel_runner.h +164 -0
  27. package/include/jxl/resizable_parallel_runner.h +77 -0
  28. package/include/jxl/resizable_parallel_runner_cxx.h +65 -0
  29. package/include/jxl/stats.h +103 -0
  30. package/include/jxl/thread_parallel_runner.h +71 -0
  31. package/include/jxl/thread_parallel_runner_cxx.h +66 -0
  32. package/include/jxl/types.h +154 -0
  33. package/include/jxl/version.h +44 -0
  34. package/include/libheif/heif_context.h +7 -4
  35. package/include/libheif/heif_encoding.h +5 -0
  36. package/include/libheif/heif_error.h +7 -0
  37. package/include/libheif/heif_image.h +10 -0
  38. package/include/libheif/heif_tiling.h +12 -0
  39. package/include/libheif/heif_version.h +2 -2
  40. package/include/libpng16/png.h +7 -7
  41. package/include/libpng16/pngconf.h +1 -1
  42. package/include/libpng16/pnglibconf.h +1 -1
  43. package/include/png.h +7 -7
  44. package/include/pngconf.h +1 -1
  45. package/include/pnglibconf.h +1 -1
  46. package/include/vips/version.h +1 -1
  47. package/package.json +1 -1
  48. package/versions.json +8 -6
@@ -0,0 +1,1629 @@
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_encoder
8
+ * @{
9
+ * @file encode.h
10
+ * @brief Encoding API for JPEG XL.
11
+ */
12
+
13
+ #ifndef JXL_ENCODE_H_
14
+ #define JXL_ENCODE_H_
15
+
16
+ #include <jxl/cms_interface.h>
17
+ #include <jxl/codestream_header.h>
18
+ #include <jxl/color_encoding.h>
19
+ #include <jxl/jxl_export.h>
20
+ #include <jxl/memory_manager.h>
21
+ #include <jxl/parallel_runner.h>
22
+ #include <jxl/stats.h>
23
+ #include <jxl/types.h>
24
+ #include <jxl/version.h> // TODO(eustas): remove before v1.0
25
+ #include <stddef.h>
26
+ #include <stdint.h>
27
+
28
+ #ifdef __cplusplus
29
+ extern "C" {
30
+ #endif
31
+
32
+ /**
33
+ * Encoder library version.
34
+ *
35
+ * @return the encoder library version as an integer:
36
+ * MAJOR_VERSION * 1000000 + MINOR_VERSION * 1000 + PATCH_VERSION. For example,
37
+ * version 1.2.3 would return 1002003.
38
+ */
39
+ JXL_EXPORT uint32_t JxlEncoderVersion(void);
40
+
41
+ /**
42
+ * Opaque structure that holds the JPEG XL encoder.
43
+ *
44
+ * Allocated and initialized with @ref JxlEncoderCreate().
45
+ * Cleaned up and deallocated with @ref JxlEncoderDestroy().
46
+ */
47
+ typedef struct JxlEncoder JxlEncoder;
48
+
49
+ /**
50
+ * Settings and metadata for a single image frame. This includes encoder options
51
+ * for a frame such as compression quality and speed.
52
+ *
53
+ * Allocated and initialized with @ref JxlEncoderFrameSettingsCreate().
54
+ * Cleaned up and deallocated when the encoder is destroyed with
55
+ * @ref JxlEncoderDestroy().
56
+ */
57
+ typedef struct JxlEncoderFrameSettings JxlEncoderFrameSettings;
58
+
59
+ /**
60
+ * Return value for multiple encoder functions.
61
+ */
62
+ typedef enum {
63
+ /** Function call finished successfully, or encoding is finished and there is
64
+ * nothing more to be done.
65
+ */
66
+ JXL_ENC_SUCCESS = 0,
67
+
68
+ /** An error occurred, for example out of memory.
69
+ */
70
+ JXL_ENC_ERROR = 1,
71
+
72
+ /** The encoder needs more output buffer to continue encoding.
73
+ */
74
+ JXL_ENC_NEED_MORE_OUTPUT = 2,
75
+
76
+ } JxlEncoderStatus;
77
+
78
+ /**
79
+ * Error conditions:
80
+ * API usage errors have the 0x80 bit set to 1
81
+ * Other errors have the 0x80 bit set to 0
82
+ */
83
+ typedef enum {
84
+ /** No error
85
+ */
86
+ JXL_ENC_ERR_OK = 0,
87
+
88
+ /** Generic encoder error due to unspecified cause
89
+ */
90
+ JXL_ENC_ERR_GENERIC = 1,
91
+
92
+ /** Out of memory
93
+ * TODO(jon): actually catch this and return this error
94
+ */
95
+ JXL_ENC_ERR_OOM = 2,
96
+
97
+ /** JPEG bitstream reconstruction data could not be
98
+ * represented (e.g. too much tail data)
99
+ */
100
+ JXL_ENC_ERR_JBRD = 3,
101
+
102
+ /** Input is invalid (e.g. corrupt JPEG file or ICC profile)
103
+ */
104
+ JXL_ENC_ERR_BAD_INPUT = 4,
105
+
106
+ /** The encoder doesn't (yet) support this. Either no version of libjxl
107
+ * supports this, and the API is used incorrectly, or the libjxl version
108
+ * should have been checked before trying to do this.
109
+ */
110
+ JXL_ENC_ERR_NOT_SUPPORTED = 0x80,
111
+
112
+ /** The encoder API is used in an incorrect way.
113
+ * In this case, a debug build of libjxl should output a specific error
114
+ * message. (if not, please open an issue about it)
115
+ */
116
+ JXL_ENC_ERR_API_USAGE = 0x81,
117
+
118
+ } JxlEncoderError;
119
+
120
+ /**
121
+ * Id of encoder options for a frame. This includes options such as setting
122
+ * encoding effort/speed or overriding the use of certain coding tools, for this
123
+ * frame. This does not include non-frame related encoder options such as for
124
+ * boxes.
125
+ */
126
+ typedef enum {
127
+ /** Sets encoder effort/speed level without affecting decoding speed. Valid
128
+ * values are, from faster to slower speed: 1:lightning 2:thunder 3:falcon
129
+ * 4:cheetah 5:hare 6:wombat 7:squirrel 8:kitten 9:tortoise 10:glacier.
130
+ * Default: squirrel (7).
131
+ */
132
+ JXL_ENC_FRAME_SETTING_EFFORT = 0,
133
+
134
+ /** Sets the decoding speed tier for the provided options. Minimum is 0
135
+ * (slowest to decode, best quality/density), and maximum is 4 (fastest to
136
+ * decode, at the cost of some quality/density). Default is 0.
137
+ */
138
+ JXL_ENC_FRAME_SETTING_DECODING_SPEED = 1,
139
+
140
+ /** Sets resampling option. If enabled, the image is downsampled before
141
+ * compression, and upsampled to original size in the decoder. Integer option,
142
+ * use -1 for the default behavior (resampling only applied for low quality),
143
+ * 1 for no downsampling (1x1), 2 for 2x2 downsampling, 4 for 4x4
144
+ * downsampling, 8 for 8x8 downsampling.
145
+ */
146
+ JXL_ENC_FRAME_SETTING_RESAMPLING = 2,
147
+
148
+ /** Similar to ::JXL_ENC_FRAME_SETTING_RESAMPLING, but for extra channels.
149
+ * Integer option, use -1 for the default behavior (depends on encoder
150
+ * implementation), 1 for no downsampling (1x1), 2 for 2x2 downsampling, 4 for
151
+ * 4x4 downsampling, 8 for 8x8 downsampling.
152
+ */
153
+ JXL_ENC_FRAME_SETTING_EXTRA_CHANNEL_RESAMPLING = 3,
154
+
155
+ /** Indicates the frame added with @ref JxlEncoderAddImageFrame is already
156
+ * downsampled by the downsampling factor set with @ref
157
+ * JXL_ENC_FRAME_SETTING_RESAMPLING. The input frame must then be given in the
158
+ * downsampled resolution, not the full image resolution. The downsampled
159
+ * resolution is given by ceil(xsize / resampling), ceil(ysize / resampling)
160
+ * with xsize and ysize the dimensions given in the basic info, and resampling
161
+ * the factor set with ::JXL_ENC_FRAME_SETTING_RESAMPLING.
162
+ * Use 0 to disable, 1 to enable. Default value is 0.
163
+ */
164
+ JXL_ENC_FRAME_SETTING_ALREADY_DOWNSAMPLED = 4,
165
+
166
+ /** Adds noise to the image emulating photographic film noise, the higher the
167
+ * given number, the grainier the image will be. As an example, a value of 100
168
+ * gives low noise whereas a value of 3200 gives a lot of noise. The default
169
+ * value is 0.
170
+ */
171
+ JXL_ENC_FRAME_SETTING_PHOTON_NOISE = 5,
172
+
173
+ /** Enables adaptive noise generation. This setting is not recommended for
174
+ * use, please use ::JXL_ENC_FRAME_SETTING_PHOTON_NOISE instead. Use -1 for
175
+ * the default (encoder chooses), 0 to disable, 1 to enable.
176
+ */
177
+ JXL_ENC_FRAME_SETTING_NOISE = 6,
178
+
179
+ /** Enables or disables dots generation. Use -1 for the default (encoder
180
+ * chooses), 0 to disable, 1 to enable.
181
+ */
182
+ JXL_ENC_FRAME_SETTING_DOTS = 7,
183
+
184
+ /** Enables or disables patches generation. Use -1 for the default (encoder
185
+ * chooses), 0 to disable, 1 to enable.
186
+ */
187
+ JXL_ENC_FRAME_SETTING_PATCHES = 8,
188
+
189
+ /** Edge preserving filter level, -1 to 3. Use -1 for the default (encoder
190
+ * chooses), 0 to 3 to set a strength.
191
+ */
192
+ JXL_ENC_FRAME_SETTING_EPF = 9,
193
+
194
+ /** Enables or disables the gaborish filter. Use -1 for the default (encoder
195
+ * chooses), 0 to disable, 1 to enable.
196
+ */
197
+ JXL_ENC_FRAME_SETTING_GABORISH = 10,
198
+
199
+ /** Enables modular encoding. Use -1 for default (encoder
200
+ * chooses), 0 to enforce VarDCT mode (e.g. for photographic images), 1 to
201
+ * enforce modular mode (e.g. for lossless images).
202
+ */
203
+ JXL_ENC_FRAME_SETTING_MODULAR = 11,
204
+
205
+ /** Enables or disables preserving color of invisible pixels. Use -1 for the
206
+ * default (1 if lossless, 0 if lossy), 0 to disable, 1 to enable.
207
+ */
208
+ JXL_ENC_FRAME_SETTING_KEEP_INVISIBLE = 12,
209
+
210
+ /** Determines the order in which 256x256 regions are stored in the codestream
211
+ * for progressive rendering. Use -1 for the encoder
212
+ * default, 0 for scanline order, 1 for center-first order.
213
+ */
214
+ JXL_ENC_FRAME_SETTING_GROUP_ORDER = 13,
215
+
216
+ /** Determines the horizontal position of center for the center-first group
217
+ * order. Use -1 to automatically use the middle of the image, 0..xsize to
218
+ * specifically set it.
219
+ */
220
+ JXL_ENC_FRAME_SETTING_GROUP_ORDER_CENTER_X = 14,
221
+
222
+ /** Determines the center for the center-first group order. Use -1 to
223
+ * automatically use the middle of the image, 0..ysize to specifically set it.
224
+ */
225
+ JXL_ENC_FRAME_SETTING_GROUP_ORDER_CENTER_Y = 15,
226
+
227
+ /** Enables or disables progressive encoding for modular mode. Use -1 for the
228
+ * encoder default, 0 to disable, 1 to enable.
229
+ */
230
+ JXL_ENC_FRAME_SETTING_RESPONSIVE = 16,
231
+
232
+ /** Set the progressive mode for the AC coefficients of VarDCT, using spectral
233
+ * progression from the DCT coefficients. Use -1 for the encoder default, 0 to
234
+ * disable, 1 to enable.
235
+ */
236
+ JXL_ENC_FRAME_SETTING_PROGRESSIVE_AC = 17,
237
+
238
+ /** Set the progressive mode for the AC coefficients of VarDCT, using
239
+ * quantization of the least significant bits. Use -1 for the encoder default,
240
+ * 0 to disable, 1 to enable.
241
+ */
242
+ JXL_ENC_FRAME_SETTING_QPROGRESSIVE_AC = 18,
243
+
244
+ /** Set the progressive mode using lower-resolution DC images for VarDCT. Use
245
+ * -1 for the encoder default, 0 to disable, 1 to have an extra 64x64 lower
246
+ * resolution pass, 2 to have a 512x512 and 64x64 lower resolution pass.
247
+ */
248
+ JXL_ENC_FRAME_SETTING_PROGRESSIVE_DC = 19,
249
+
250
+ /** Use Global channel palette if the amount of colors is smaller than this
251
+ * percentage of range. Use 0-100 to set an explicit percentage, -1 to use the
252
+ * encoder default. Used for modular encoding.
253
+ */
254
+ JXL_ENC_FRAME_SETTING_CHANNEL_COLORS_GLOBAL_PERCENT = 20,
255
+
256
+ /** Use Local (per-group) channel palette if the amount of colors is smaller
257
+ * than this percentage of range. Use 0-100 to set an explicit percentage, -1
258
+ * to use the encoder default. Used for modular encoding.
259
+ */
260
+ JXL_ENC_FRAME_SETTING_CHANNEL_COLORS_GROUP_PERCENT = 21,
261
+
262
+ /** Use color palette if amount of colors is smaller than or equal to this
263
+ * amount, or -1 to use the encoder default. Used for modular encoding.
264
+ */
265
+ JXL_ENC_FRAME_SETTING_PALETTE_COLORS = 22,
266
+
267
+ /** Enables or disables delta palette. Use -1 for the default (encoder
268
+ * chooses), 0 to disable, 1 to enable. Used in modular mode.
269
+ */
270
+ JXL_ENC_FRAME_SETTING_LOSSY_PALETTE = 23,
271
+
272
+ /** Color transform for internal encoding: -1 = default, 0=XYB, 1=none (RGB),
273
+ * 2=YCbCr. The XYB setting performs the forward XYB transform. None and
274
+ * YCbCr both perform no transform, but YCbCr is used to indicate that the
275
+ * encoded data losslessly represents YCbCr values.
276
+ */
277
+ JXL_ENC_FRAME_SETTING_COLOR_TRANSFORM = 24,
278
+
279
+ /** Reversible color transform for modular encoding: -1=default, 0-41=RCT
280
+ * index, e.g. index 0 = none, index 6 = YCoCg.
281
+ * If this option is set to a non-default value, the RCT will be globally
282
+ * applied to the whole frame.
283
+ * The default behavior is to try several RCTs locally per modular group,
284
+ * depending on the speed and distance setting.
285
+ */
286
+ JXL_ENC_FRAME_SETTING_MODULAR_COLOR_SPACE = 25,
287
+
288
+ /** Group size for modular encoding: -1=default, 0=128, 1=256, 2=512, 3=1024.
289
+ */
290
+ JXL_ENC_FRAME_SETTING_MODULAR_GROUP_SIZE = 26,
291
+
292
+ /** Predictor for modular encoding. -1 = default, 0=zero, 1=left, 2=top,
293
+ * 3=avg0, 4=select, 5=gradient, 6=weighted, 7=topright, 8=topleft,
294
+ * 9=leftleft, 10=avg1, 11=avg2, 12=avg3, 13=toptop predictive average 14=mix
295
+ * 5 and 6, 15=mix everything.
296
+ */
297
+ JXL_ENC_FRAME_SETTING_MODULAR_PREDICTOR = 27,
298
+
299
+ /** Fraction of pixels used to learn MA trees as a percentage. -1 = default,
300
+ * 0 = no MA and fast decode, 50 = default value, 100 = all, values above
301
+ * 100 are also permitted. Higher values use more encoder memory.
302
+ */
303
+ JXL_ENC_FRAME_SETTING_MODULAR_MA_TREE_LEARNING_PERCENT = 28,
304
+
305
+ /** Number of extra (previous-channel) MA tree properties to use. -1 =
306
+ * default, 0-11 = valid values. Recommended values are in the range 0 to 3,
307
+ * or 0 to amount of channels minus 1 (including all extra channels, and
308
+ * excluding color channels when using VarDCT mode). Higher value gives slower
309
+ * encoding and slower decoding.
310
+ */
311
+ JXL_ENC_FRAME_SETTING_MODULAR_NB_PREV_CHANNELS = 29,
312
+
313
+ /** Enable or disable CFL (chroma-from-luma) for lossless JPEG recompression.
314
+ * -1 = default, 0 = disable CFL, 1 = enable CFL.
315
+ */
316
+ JXL_ENC_FRAME_SETTING_JPEG_RECON_CFL = 30,
317
+
318
+ /** Prepare the frame for indexing in the frame index box.
319
+ * 0 = ignore this frame (same as not setting a value),
320
+ * 1 = index this frame within the Frame Index Box.
321
+ * If any frames are indexed, the first frame needs to
322
+ * be indexed, too. If the first frame is not indexed, and
323
+ * a later frame is attempted to be indexed, ::JXL_ENC_ERROR will occur.
324
+ * If non-keyframes, i.e., frames with cropping, blending or patches are
325
+ * attempted to be indexed, ::JXL_ENC_ERROR will occur.
326
+ */
327
+ JXL_ENC_FRAME_INDEX_BOX = 31,
328
+
329
+ /** Sets brotli encode effort for use in JPEG recompression and
330
+ * compressed metadata boxes (brob). Can be -1 (default) or 0 (fastest) to 11
331
+ * (slowest). Default is based on the general encode effort in case of JPEG
332
+ * recompression, and 4 for brob boxes.
333
+ */
334
+ JXL_ENC_FRAME_SETTING_BROTLI_EFFORT = 32,
335
+
336
+ /** Enables or disables brotli compression of metadata boxes derived from
337
+ * a JPEG frame when using @ref JxlEncoderAddJPEGFrame. This has no effect on
338
+ * boxes added using @ref JxlEncoderAddBox. -1 = default, 0 = disable
339
+ * compression, 1 = enable compression.
340
+ */
341
+ JXL_ENC_FRAME_SETTING_JPEG_COMPRESS_BOXES = 33,
342
+
343
+ /** Control what kind of input buffering is used, when using chunked image frames.
344
+ * When using streaming input the encoder minimizes memory usage, potentially at
345
+ * a cost in compression density (though not necessarily).
346
+ * -1 = default (let the encoder decide)
347
+ * 0 = buffers everything, basically the same as non-streamed code path
348
+ (mainly for testing)
349
+ * 1 = buffers everything for images that are 2048 x 2048 or smaller, and
350
+ * uses streaming input and buffered output for larger images
351
+ * 2 = same as 1, but the threshold to use streaming input is lower
352
+ * 3 = deprecated; same as 2, but also sets output mode to 1.
353
+ *
354
+ * Output buffering is controlled via @ref JXL_ENC_FRAME_SETTING_OUTPUT_MODE.
355
+ */
356
+ JXL_ENC_FRAME_SETTING_BUFFERING = 34,
357
+
358
+ /** Keep or discard Exif metadata boxes derived from a JPEG frame when using
359
+ * @ref JxlEncoderAddJPEGFrame. This has no effect on boxes added using
360
+ * @ref JxlEncoderAddBox. When @ref JxlEncoderStoreJPEGMetadata is set to 1,
361
+ * this option cannot be set to 0. Even when Exif metadata is discarded, the
362
+ * orientation will still be applied. 0 = discard Exif metadata, 1 = keep Exif
363
+ * metadata (default).
364
+ */
365
+ JXL_ENC_FRAME_SETTING_JPEG_KEEP_EXIF = 35,
366
+
367
+ /** Keep or discard XMP metadata boxes derived from a JPEG frame when using
368
+ * @ref JxlEncoderAddJPEGFrame. This has no effect on boxes added using
369
+ * @ref JxlEncoderAddBox. When @ref JxlEncoderStoreJPEGMetadata is set to 1,
370
+ * this option cannot be set to 0. 0 = discard XMP metadata, 1 = keep XMP
371
+ * metadata (default).
372
+ */
373
+ JXL_ENC_FRAME_SETTING_JPEG_KEEP_XMP = 36,
374
+
375
+ /** Keep or discard JUMBF metadata boxes derived from a JPEG frame when using
376
+ * @ref JxlEncoderAddJPEGFrame. This has no effect on boxes added using
377
+ * @ref JxlEncoderAddBox. 0 = discard JUMBF metadata, 1 = keep JUMBF metadata
378
+ * (default).
379
+ */
380
+ JXL_ENC_FRAME_SETTING_JPEG_KEEP_JUMBF = 37,
381
+
382
+ /** If this mode is disabled, the encoder will not make any image quality
383
+ * decisions that are computed based on the full image, but stored only once
384
+ * (e.g. the X quant multiplier in the frame header). Used mainly for testing
385
+ * equivalence of streaming and non-streaming code.
386
+ * 0 = disabled, 1 = enabled (default)
387
+ */
388
+ JXL_ENC_FRAME_SETTING_USE_FULL_IMAGE_HEURISTICS = 38,
389
+
390
+ /** Disable perceptual optimizations. 0 = optimizations enabled (default), 1 =
391
+ * optimizations disabled.
392
+ */
393
+ JXL_ENC_FRAME_SETTING_DISABLE_PERCEPTUAL_HEURISTICS = 39,
394
+
395
+ /** Control how codestream bytes are written to the output. Unlike
396
+ * @ref JXL_ENC_FRAME_SETTING_BUFFERING (which controls input buffering),
397
+ * this setting controls the output ordering and memory trade-offs.
398
+ *
399
+ * Modes 1 and 2 reduce peak memory usage by avoiding buffering the output
400
+ * bitstream, but produce codestreams in an order not suitable for
401
+ * progressive decoding.
402
+ *
403
+ * -1 = default (let the encoder decide).
404
+ * 0 = buffer the output bitstream internally; write frames in normal order.
405
+ * No seeking required. The codestream can be decoded progressively.
406
+ * This is the most compatible mode.
407
+ * 1 = seek-based streaming: write group data first, then seek back to write
408
+ * the frame header and TOC. Reduces peak memory for large images.
409
+ * Requires a seekable output stream. Produces maximally compatible files.
410
+ * 2 = out-of-order jxlp streaming: each codestream section is a separate
411
+ * jxlp box written in encoding order; jxlp counters reflect codestream
412
+ * order so a decoder can reassemble a standard, progressively decodable
413
+ * codestream by sorting the boxes. Reduces peak memory without requiring
414
+ * output seeking. Requires ftyp version 1, which is not supported by
415
+ * older decoders. If mode 2 is used for any frame, it must also be used
416
+ * for the first frame (the ftyp version cannot be changed once written).
417
+ */
418
+ JXL_ENC_FRAME_SETTING_OUTPUT_MODE = 40,
419
+
420
+ /** Enum value not to be used as an option. This value is added to force the
421
+ * C compiler to have the enum to take a known size.
422
+ */
423
+ JXL_ENC_FRAME_SETTING_FILL_ENUM = 65535,
424
+
425
+ } JxlEncoderFrameSettingId;
426
+
427
+ /**
428
+ * Creates an instance of @ref JxlEncoder and initializes it.
429
+ *
430
+ * @p memory_manager will be used for all the library dynamic allocations made
431
+ * from this instance. The parameter may be NULL, in which case the default
432
+ * allocator will be used. See jpegxl/memory_manager.h for details.
433
+ *
434
+ * @param memory_manager custom allocator function. It may be NULL. The memory
435
+ * manager will be copied internally.
436
+ * @return @c NULL if the instance can not be allocated or initialized
437
+ * @return pointer to initialized @ref JxlEncoder otherwise
438
+ */
439
+ JXL_EXPORT JxlEncoder* JxlEncoderCreate(const JxlMemoryManager* memory_manager);
440
+
441
+ /**
442
+ * Re-initializes a @ref JxlEncoder instance, so it can be re-used for encoding
443
+ * another image. All state and settings are reset as if the object was
444
+ * newly created with @ref JxlEncoderCreate, but the memory manager is kept.
445
+ *
446
+ * @param enc instance to be re-initialized.
447
+ */
448
+ JXL_EXPORT void JxlEncoderReset(JxlEncoder* enc);
449
+
450
+ /**
451
+ * Deinitializes and frees a @ref JxlEncoder instance.
452
+ *
453
+ * @param enc instance to be cleaned up and deallocated.
454
+ */
455
+ JXL_EXPORT void JxlEncoderDestroy(JxlEncoder* enc);
456
+
457
+ /**
458
+ * Sets the color management system (CMS) that will be used for color conversion
459
+ * (if applicable) during encoding. May only be set before starting encoding. If
460
+ * left unset, the default CMS implementation will be used.
461
+ *
462
+ * @param enc encoder object.
463
+ * @param cms structure representing a CMS implementation. See @ref
464
+ * JxlCmsInterface for more details.
465
+ */
466
+ JXL_EXPORT void JxlEncoderSetCms(JxlEncoder* enc, JxlCmsInterface cms);
467
+
468
+ /**
469
+ * Set the parallel runner for multithreading. May only be set before starting
470
+ * encoding.
471
+ *
472
+ * @param enc encoder object.
473
+ * @param parallel_runner function pointer to runner for multithreading. It may
474
+ * be NULL to use the default, single-threaded, runner. A multithreaded
475
+ * runner should be set to reach fast performance.
476
+ * @param parallel_runner_opaque opaque pointer for parallel_runner.
477
+ * @return ::JXL_ENC_SUCCESS if the runner was set, ::JXL_ENC_ERROR
478
+ * otherwise (the previous runner remains set).
479
+ */
480
+ JXL_EXPORT JxlEncoderStatus
481
+ JxlEncoderSetParallelRunner(JxlEncoder* enc, JxlParallelRunner parallel_runner,
482
+ void* parallel_runner_opaque);
483
+
484
+ /**
485
+ * Get the (last) error code in case ::JXL_ENC_ERROR was returned.
486
+ *
487
+ * @param enc encoder object.
488
+ * @return the @ref JxlEncoderError that caused the (last) ::JXL_ENC_ERROR to
489
+ * be returned.
490
+ */
491
+ JXL_EXPORT JxlEncoderError JxlEncoderGetError(JxlEncoder* enc);
492
+
493
+ /**
494
+ * Encodes a JPEG XL file using the available bytes. @p *avail_out indicates how
495
+ * many output bytes are available, and @p *next_out points to the input bytes.
496
+ * *avail_out will be decremented by the amount of bytes that have been
497
+ * processed by the encoder and *next_out will be incremented by the same
498
+ * amount, so *next_out will now point at the amount of *avail_out unprocessed
499
+ * bytes.
500
+ *
501
+ * The returned status indicates whether the encoder needs more output bytes.
502
+ * When the return value is not ::JXL_ENC_ERROR or ::JXL_ENC_SUCCESS, the
503
+ * encoding requires more @ref JxlEncoderProcessOutput calls to continue.
504
+ *
505
+ * The caller must guarantee that *avail_out >= 32 when calling
506
+ * @ref JxlEncoderProcessOutput; otherwise, ::JXL_ENC_NEED_MORE_OUTPUT will
507
+ * be returned. It is guaranteed that, if *avail_out >= 32, at least one byte of
508
+ * output will be written.
509
+ *
510
+ * This encodes the frames and/or boxes added so far. If the last frame or last
511
+ * box has been added, @ref JxlEncoderCloseInput, @ref JxlEncoderCloseFrames
512
+ * and/or @ref JxlEncoderCloseBoxes must be called before the next
513
+ * @ref JxlEncoderProcessOutput call, or the codestream won't be encoded
514
+ * correctly.
515
+ *
516
+ * @param enc encoder object.
517
+ * @param next_out pointer to next bytes to write to.
518
+ * @param avail_out amount of bytes available starting from *next_out.
519
+ * @return ::JXL_ENC_SUCCESS when encoding finished and all events handled.
520
+ * @return ::JXL_ENC_ERROR when encoding failed, e.g. invalid input.
521
+ * @return ::JXL_ENC_NEED_MORE_OUTPUT more output buffer is necessary.
522
+ */
523
+ JXL_EXPORT JxlEncoderStatus JxlEncoderProcessOutput(JxlEncoder* enc,
524
+ uint8_t** next_out,
525
+ size_t* avail_out);
526
+
527
+ /**
528
+ * Sets the frame information for this frame to the encoder. This includes
529
+ * animation information such as frame duration to store in the frame header.
530
+ * The frame header fields represent the frame as passed to the encoder, but not
531
+ * necessarily the exact values as they will be encoded file format: the encoder
532
+ * could change crop and blending options of a frame for more efficient encoding
533
+ * or introduce additional internal frames. Animation duration and time code
534
+ * information is not altered since those are immutable metadata of the frame.
535
+ *
536
+ * It is not required to use this function, however if have_animation is set
537
+ * to true in the basic info, then this function should be used to set the
538
+ * time duration of this individual frame. By default individual frames have a
539
+ * time duration of 0, making them form a composite still. See @ref
540
+ * JxlFrameHeader for more information.
541
+ *
542
+ * This information is stored in the @ref JxlEncoderFrameSettings and so is used
543
+ * for any frame encoded with these @ref JxlEncoderFrameSettings. It is ok to
544
+ * change between @ref JxlEncoderAddImageFrame calls, each added image frame
545
+ * will have the frame header that was set in the options at the time of calling
546
+ * @ref JxlEncoderAddImageFrame.
547
+ *
548
+ * The is_last and name_length fields of the @ref JxlFrameHeader are ignored,
549
+ * use
550
+ * @ref JxlEncoderCloseFrames to indicate last frame, and @ref
551
+ * JxlEncoderSetFrameName to indicate the name and its length instead.
552
+ * Calling this function will clear any name that was previously set with @ref
553
+ * JxlEncoderSetFrameName.
554
+ *
555
+ * @param frame_settings set of options and metadata for this frame. Also
556
+ * includes reference to the encoder object.
557
+ * @param frame_header frame header data to set. Object owned by the caller and
558
+ * does not need to be kept in memory, its information is copied internally.
559
+ * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error
560
+ */
561
+ JXL_EXPORT JxlEncoderStatus
562
+ JxlEncoderSetFrameHeader(JxlEncoderFrameSettings* frame_settings,
563
+ const JxlFrameHeader* frame_header);
564
+
565
+ /**
566
+ * Sets blend info of an extra channel. The blend info of extra channels is set
567
+ * separately from that of the color channels, the color channels are set with
568
+ * @ref JxlEncoderSetFrameHeader.
569
+ *
570
+ * @param frame_settings set of options and metadata for this frame. Also
571
+ * includes reference to the encoder object.
572
+ * @param index index of the extra channel to use.
573
+ * @param blend_info blend info to set for the extra channel
574
+ * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error
575
+ */
576
+ JXL_EXPORT JxlEncoderStatus JxlEncoderSetExtraChannelBlendInfo(
577
+ JxlEncoderFrameSettings* frame_settings, size_t index,
578
+ const JxlBlendInfo* blend_info);
579
+
580
+ /**
581
+ * Sets the name of the animation frame. This function is optional, frames are
582
+ * not required to have a name. This setting is a part of the frame header, and
583
+ * the same principles as for @ref JxlEncoderSetFrameHeader apply. The
584
+ * name_length field of @ref JxlFrameHeader is ignored by the encoder, this
585
+ * function determines the name length instead as the length in bytes of the C
586
+ * string.
587
+ *
588
+ * The maximum possible name length is 1071 bytes (excluding terminating null
589
+ * character).
590
+ *
591
+ * Calling @ref JxlEncoderSetFrameHeader clears any name that was
592
+ * previously set.
593
+ *
594
+ * @param frame_settings set of options and metadata for this frame. Also
595
+ * includes reference to the encoder object.
596
+ * @param frame_name name of the next frame to be encoded, as a UTF-8 encoded C
597
+ * string (zero terminated). Owned by the caller, and copied internally.
598
+ * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error
599
+ */
600
+ JXL_EXPORT JxlEncoderStatus JxlEncoderSetFrameName(
601
+ JxlEncoderFrameSettings* frame_settings, const char* frame_name);
602
+
603
+ /**
604
+ * Sets the bit depth of the input buffer.
605
+ *
606
+ * For float pixel formats, only the default @ref
607
+ JXL_BIT_DEPTH_FROM_PIXEL_FORMAT
608
+ * setting is allowed, while for unsigned pixel formats,
609
+ * ::JXL_BIT_DEPTH_FROM_CODESTREAM setting is also allowed. See the comment
610
+ on
611
+ * @ref JxlEncoderAddImageFrame for the effects of the bit depth setting.
612
+
613
+ * @param frame_settings set of options and metadata for this frame. Also
614
+ * includes reference to the encoder object.
615
+ * @param bit_depth the bit depth setting of the pixel input
616
+ * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error
617
+ */
618
+ JXL_EXPORT JxlEncoderStatus JxlEncoderSetFrameBitDepth(
619
+ JxlEncoderFrameSettings* frame_settings, const JxlBitDepth* bit_depth);
620
+
621
+ /**
622
+ * Sets the buffer to read JPEG encoded bytes from for the next frame to encode.
623
+ *
624
+ * If @ref JxlEncoderSetBasicInfo has not yet been called, calling
625
+ * @ref JxlEncoderAddJPEGFrame will implicitly call it with the parameters of
626
+ * the added JPEG frame.
627
+ *
628
+ * If @ref JxlEncoderSetColorEncoding or @ref JxlEncoderSetICCProfile has not
629
+ * yet been called, calling @ref JxlEncoderAddJPEGFrame will implicitly call it
630
+ * with the parameters of the added JPEG frame.
631
+ *
632
+ * If the encoder is set to store JPEG reconstruction metadata using @ref
633
+ * JxlEncoderStoreJPEGMetadata and a single JPEG frame is added, it will be
634
+ * possible to losslessly reconstruct the JPEG codestream.
635
+ *
636
+ * If this is the last frame, @ref JxlEncoderCloseInput or @ref
637
+ * JxlEncoderCloseFrames must be called before the next
638
+ * @ref JxlEncoderProcessOutput call.
639
+ *
640
+ * Note, this can only be used to add JPEG frames for lossless compression. To
641
+ * encode with lossy compression, the JPEG must be decoded manually and a pixel
642
+ * buffer added using JxlEncoderAddImageFrame.
643
+ *
644
+ * @param frame_settings set of options and metadata for this frame. Also
645
+ * includes reference to the encoder object.
646
+ * @param buffer bytes to read JPEG from. Owned by the caller and its contents
647
+ * are copied internally.
648
+ * @param size size of buffer in bytes.
649
+ * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error
650
+ */
651
+ JXL_EXPORT JxlEncoderStatus
652
+ JxlEncoderAddJPEGFrame(const JxlEncoderFrameSettings* frame_settings,
653
+ const uint8_t* buffer, size_t size);
654
+
655
+ /**
656
+ * Sets the buffer to read pixels from for the next image to encode. Must call
657
+ * @ref JxlEncoderSetBasicInfo before @ref JxlEncoderAddImageFrame.
658
+ *
659
+ * Currently only some data types for pixel formats are supported:
660
+ * - ::JXL_TYPE_UINT8, with range 0..255
661
+ * - ::JXL_TYPE_UINT16, with range 0..65535
662
+ * - ::JXL_TYPE_FLOAT16, with nominal range 0..1
663
+ * - ::JXL_TYPE_FLOAT, with nominal range 0..1
664
+ *
665
+ * Note: the sample data type in pixel_format is allowed to be different from
666
+ * what is described in the @ref JxlBasicInfo. The type in pixel_format,
667
+ * together with an optional @ref JxlBitDepth parameter set by @ref
668
+ * JxlEncoderSetFrameBitDepth describes the format of the uncompressed pixel
669
+ * buffer. The bits_per_sample and exponent_bits_per_sample in the @ref
670
+ * JxlBasicInfo describes what will actually be encoded in the JPEG XL
671
+ * codestream. For example, to encode a 12-bit image, you would set
672
+ * bits_per_sample to 12, while the input frame buffer can be in the following
673
+ * formats:
674
+ * - if pixel format is in ::JXL_TYPE_UINT16 with default bit depth setting
675
+ * (i.e. ::JXL_BIT_DEPTH_FROM_PIXEL_FORMAT), input sample values are
676
+ * rescaled to 16-bit, i.e. multiplied by 65535/4095;
677
+ * - if pixel format is in ::JXL_TYPE_UINT16 with @ref
678
+ * JXL_BIT_DEPTH_FROM_CODESTREAM bit depth setting, input sample values are
679
+ * provided unscaled;
680
+ * - if pixel format is in ::JXL_TYPE_FLOAT, input sample values are
681
+ * rescaled to 0..1, i.e. multiplied by 1.f/4095.f. While it is allowed, it is
682
+ * obviously not recommended to use a pixel_format with lower precision than
683
+ * what is specified in the @ref JxlBasicInfo.
684
+ *
685
+ * We support interleaved channels as described by the @ref JxlPixelFormat
686
+ * "JxlPixelFormat":
687
+ * - single-channel data, e.g. grayscale
688
+ * - single-channel + alpha
689
+ * - trichromatic, e.g. RGB
690
+ * - trichromatic + alpha
691
+ *
692
+ * Extra channels not handled here need to be set by @ref
693
+ * JxlEncoderSetExtraChannelBuffer.
694
+ * If the image has alpha, and alpha is not passed here, it will implicitly be
695
+ * set to all-opaque (an alpha value of 1.0 everywhere).
696
+ *
697
+ * The pixels are assumed to be encoded in the original profile that is set with
698
+ * @ref JxlEncoderSetColorEncoding or @ref JxlEncoderSetICCProfile. If none of
699
+ * these functions were used, the pixels are assumed to be nonlinear sRGB for
700
+ * integer data types (::JXL_TYPE_UINT8, ::JXL_TYPE_UINT16), and linear
701
+ * sRGB for floating point data types (::JXL_TYPE_FLOAT16, @ref
702
+ * JXL_TYPE_FLOAT).
703
+ *
704
+ * Sample values in floating-point pixel formats are allowed to be outside the
705
+ * nominal range, e.g. to represent out-of-sRGB-gamut colors in the
706
+ * uses_original_profile=false case. They are however not allowed to be NaN or
707
+ * +-infinity.
708
+ *
709
+ * If this is the last frame, @ref JxlEncoderCloseInput or @ref
710
+ * JxlEncoderCloseFrames must be called before the next
711
+ * @ref JxlEncoderProcessOutput call.
712
+ *
713
+ * @param frame_settings set of options and metadata for this frame. Also
714
+ * includes reference to the encoder object.
715
+ * @param pixel_format format for pixels. Object owned by the caller and its
716
+ * contents are copied internally.
717
+ * @param buffer buffer type to input the pixel data from. Owned by the caller
718
+ * and its contents are copied internally.
719
+ * @param size size of buffer in bytes. This size should match what is implied
720
+ * by the frame dimensions and the pixel format.
721
+ * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error
722
+ */
723
+ JXL_EXPORT JxlEncoderStatus JxlEncoderAddImageFrame(
724
+ const JxlEncoderFrameSettings* frame_settings,
725
+ const JxlPixelFormat* pixel_format, const void* buffer, size_t size);
726
+
727
+ /**
728
+ * The @ref JxlEncoderOutputProcessor structure provides an interface for the
729
+ * encoder's output processing. Users of the library, who want to do streaming
730
+ * encoding, should implement the required callbacks for buffering, writing,
731
+ * seeking (if supported), and setting a finalized position during the encoding
732
+ * process.
733
+ *
734
+ * At a high level, the processor can be in one of two states:
735
+ * - With an active buffer: This indicates that a buffer has been acquired using
736
+ * `get_buffer` and encoded data can be written to it.
737
+ * - Without an active buffer: In this state, no data can be written. A new
738
+ * buffer must be acquired after releasing any previously active buffer.
739
+ *
740
+ * The library will not acquire more than one buffer at a given time.
741
+ *
742
+ * The state of the processor includes `position` and `finalized position`,
743
+ * which have the following meaning.
744
+ *
745
+ * - position: Represents the current position, in bytes, within the output
746
+ * stream where the encoded data will be written next. This position moves
747
+ * forward with each `release_buffer` call as data is written, and can also be
748
+ * adjusted through the optional seek callback, if provided. At this position
749
+ * the next write will occur.
750
+ *
751
+ * - finalized position: A position in the output stream that ensures all bytes
752
+ * before this point are finalized and won't be changed by later writes.
753
+ *
754
+ * All fields but `seek` are required, `seek` is optional and can be NULL.
755
+ */
756
+ struct JxlEncoderOutputProcessor {
757
+ /**
758
+ * Required.
759
+ * An opaque pointer that the client can use to store custom data.
760
+ * This data will be passed to the associated callback functions.
761
+ */
762
+ void* opaque;
763
+
764
+ /**
765
+ * Required.
766
+ * Acquires a buffer at the current position into which the library will write
767
+ * the output data.
768
+ *
769
+ * If the `size` argument points to 0 and the returned value is NULL, this
770
+ * will be interpreted as asking the output writing to stop. In such a case,
771
+ * the library will return an error. The client is expected to set the size of
772
+ * the returned buffer based on the suggested `size` when this function is
773
+ * called.
774
+ *
775
+ * @param opaque user supplied parameters to the callback
776
+ * @param size points to a suggested buffer size when called; must be set to
777
+ * the size of the returned buffer once the function returns.
778
+ * @return a pointer to the acquired buffer or NULL to indicate a stop
779
+ * condition.
780
+ */
781
+ void* (*get_buffer)(void* opaque, size_t* size);
782
+
783
+ /**
784
+ * Required.
785
+ * Notifies the user of library that the current buffer's data has been
786
+ * written and can be released. This function should advance the current
787
+ * position of the buffer by `written_bytes` number of bytes.
788
+ *
789
+ * @param opaque user supplied parameters to the callback
790
+ * @param written_bytes the number of bytes written to the buffer.
791
+ */
792
+ void (*release_buffer)(void* opaque, size_t written_bytes);
793
+
794
+ /**
795
+ * Optional, can be NULL
796
+ * Seeks to a specific position in the output. This function is optional and
797
+ * can be set to NULL if the output doesn't support seeking. Can only be done
798
+ * when there is no buffer. Cannot be used to seek before the finalized
799
+ * position.
800
+ *
801
+ * @param opaque user supplied parameters to the callback
802
+ * @param position the position to seek to, in bytes.
803
+ */
804
+ void (*seek)(void* opaque, uint64_t position);
805
+
806
+ /**
807
+ * Required.
808
+ * Sets a finalized position on the output data, at a specific position.
809
+ * Seeking will never request a position before the finalized position.
810
+ *
811
+ * Will only be called if there is no active buffer.
812
+ *
813
+ * @param opaque user supplied parameters to the callback
814
+ * @param finalized_position the position, in bytes, where the finalized
815
+ * position should be set.
816
+ */
817
+ void (*set_finalized_position)(void* opaque, uint64_t finalized_position);
818
+ };
819
+
820
+ /**
821
+ * Sets the output processor for the encoder. This processor determines how the
822
+ * encoder will handle buffering, writing, seeking (if supported), and
823
+ * setting a finalized position during the encoding process.
824
+ *
825
+ * This should not be used when using @ref JxlEncoderProcessOutput.
826
+ *
827
+ * @param enc encoder object.
828
+ * @param output_processor the struct containing the callbacks for managing
829
+ * output.
830
+ * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error.
831
+ */
832
+ JXL_EXPORT JxlEncoderStatus JxlEncoderSetOutputProcessor(
833
+ JxlEncoder* enc, struct JxlEncoderOutputProcessor output_processor);
834
+
835
+ /**
836
+ * Flushes any buffered input in the encoder, ensuring that all available input
837
+ * data has been processed and written to the output.
838
+ *
839
+ * This function can only be used after @ref JxlEncoderSetOutputProcessor.
840
+ * Before making the last call to @ref JxlEncoderFlushInput, users should call
841
+ * @ref JxlEncoderCloseInput to signal the end of input data.
842
+ *
843
+ * This should not be used when using @ref JxlEncoderProcessOutput.
844
+ *
845
+ * @param enc encoder object.
846
+ * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error.
847
+ */
848
+ JXL_EXPORT JxlEncoderStatus JxlEncoderFlushInput(JxlEncoder* enc);
849
+
850
+ /**
851
+ * This struct provides callback functions to pass pixel data in a streaming
852
+ * manner instead of requiring the entire frame data in memory at once.
853
+ */
854
+ struct JxlChunkedFrameInputSource {
855
+ /**
856
+ * A pointer to any user-defined data or state. This can be used to pass
857
+ * information to the callback functions.
858
+ */
859
+ void* opaque;
860
+
861
+ /**
862
+ * Get the pixel format that color channel data will be provided in.
863
+ * When called, `pixel_format` points to a suggested pixel format; if
864
+ * color channel data can be given in this pixel format, processing might
865
+ * be more efficient.
866
+ *
867
+ * This function will be called exactly once, before any call to
868
+ * get_color_channel_at.
869
+ *
870
+ * @param opaque user supplied parameters to the callback
871
+ * @param pixel_format format for pixels
872
+ */
873
+ void (*get_color_channels_pixel_format)(void* opaque,
874
+ JxlPixelFormat* pixel_format);
875
+
876
+ /**
877
+ * Callback to retrieve a rectangle of color channel data at a specific
878
+ * location. It is guaranteed that xpos and ypos are multiples of 8. xsize,
879
+ * ysize will be multiples of 8, unless the resulting rectangle would be out
880
+ * of image bounds. Moreover, xsize and ysize will be at most 2048. The
881
+ * returned data will be assumed to be in the format returned by the
882
+ * (preceding) call to get_color_channels_pixel_format, except the `align`
883
+ * parameter of the pixel format will be ignored. Instead, the `i`-th row will
884
+ * be assumed to start at position `return_value + i * *row_offset`, with the
885
+ * value of `*row_offset` decided by the callee.
886
+ *
887
+ * Note that multiple calls to `get_color_channel_data_at` may happen before a
888
+ * call to `release_buffer`.
889
+ *
890
+ * @param opaque user supplied parameters to the callback
891
+ * @param xpos horizontal position for the data.
892
+ * @param ypos vertical position for the data.
893
+ * @param xsize horizontal size of the requested rectangle of data.
894
+ * @param ysize vertical size of the requested rectangle of data.
895
+ * @param row_offset pointer to a the byte offset between consecutive rows of
896
+ * the retrieved pixel data.
897
+ * @return pointer to the retrieved pixel data.
898
+ */
899
+ const void* (*get_color_channel_data_at)(void* opaque, size_t xpos,
900
+ size_t ypos, size_t xsize,
901
+ size_t ysize, size_t* row_offset);
902
+
903
+ /**
904
+ * Get the pixel format that extra channel data will be provided in.
905
+ * When called, `pixel_format` points to a suggested pixel format; if
906
+ * extra channel data can be given in this pixel format, processing might
907
+ * be more efficient.
908
+ *
909
+ * This function will be called exactly once per index, before any call to
910
+ * get_extra_channel_data_at with that given index.
911
+ *
912
+ * @param opaque user supplied parameters to the callback
913
+ * @param ec_index zero-indexed index of the extra channel
914
+ * @param pixel_format format for extra channel data
915
+ */
916
+ void (*get_extra_channel_pixel_format)(void* opaque, size_t ec_index,
917
+ JxlPixelFormat* pixel_format);
918
+
919
+ /**
920
+ * Callback to retrieve a rectangle of extra channel `ec_index` data at a
921
+ * specific location. It is guaranteed that xpos and ypos are multiples of
922
+ * 8. xsize, ysize will be multiples of 8, unless the resulting rectangle
923
+ * would be out of image bounds. Moreover, xsize and ysize will be at most
924
+ * 2048. The returned data will be assumed to be in the format returned by the
925
+ * (preceding) call to get_extra_channels_pixel_format_at with the
926
+ * corresponding extra channel index `ec_index`, except the `align` parameter
927
+ * of the pixel format will be ignored. Instead, the `i`-th row will be
928
+ * assumed to start at position `return_value + i * *row_offset`, with the
929
+ * value of `*row_offset` decided by the callee.
930
+ *
931
+ * Note that multiple calls to `get_extra_channel_data_at` may happen before a
932
+ * call to `release_buffer`.
933
+ *
934
+ * @param opaque user supplied parameters to the callback
935
+ * @param xpos horizontal position for the data.
936
+ * @param ypos vertical position for the data.
937
+ * @param xsize horizontal size of the requested rectangle of data.
938
+ * @param ysize vertical size of the requested rectangle of data.
939
+ * @param row_offset pointer to a the byte offset between consecutive rows of
940
+ * the retrieved pixel data.
941
+ * @return pointer to the retrieved pixel data.
942
+ */
943
+ const void* (*get_extra_channel_data_at)(void* opaque, size_t ec_index,
944
+ size_t xpos, size_t ypos,
945
+ size_t xsize, size_t ysize,
946
+ size_t* row_offset);
947
+
948
+ /**
949
+ * Releases the buffer `buf` (obtained through a call to
950
+ * `get_color_channel_data_at` or `get_extra_channel_data_at`). This function
951
+ * will be called exactly once per call to `get_color_channel_data_at` or
952
+ * `get_extra_channel_data_at`.
953
+ *
954
+ * @param opaque user supplied parameters to the callback
955
+ * @param buf pointer returned by `get_color_channel_data_at` or
956
+ * `get_extra_channel_data_at`
957
+ */
958
+ void (*release_buffer)(void* opaque, const void* buf);
959
+ };
960
+
961
+ /**
962
+ * @brief Adds a frame to the encoder using a chunked input source.
963
+ *
964
+ * This function gives a way to encode a frame by providing pixel data in a
965
+ * chunked or streaming manner, which can be especially useful when dealing with
966
+ * large images that may not fit entirely in memory or when trying to optimize
967
+ * memory usage. The input data is provided through callbacks defined in the
968
+ * @ref JxlChunkedFrameInputSource struct. Once the frame data has been
969
+ * completely retrieved, this function will flush the input and close it if it
970
+ * is the last frame.
971
+ *
972
+ * @param frame_settings set of options and metadata for this frame. Also
973
+ * includes reference to the encoder object.
974
+ * @param is_last_frame indicates if this is the last frame.
975
+ * @param chunked_frame_input struct providing callback methods for retrieving
976
+ * pixel data in chunks.
977
+ *
978
+ * @return Returns a status indicating the success or failure of adding the
979
+ * frame.
980
+ */
981
+ JXL_EXPORT JxlEncoderStatus JxlEncoderAddChunkedFrame(
982
+ const JxlEncoderFrameSettings* frame_settings, JXL_BOOL is_last_frame,
983
+ struct JxlChunkedFrameInputSource chunked_frame_input);
984
+
985
+ /**
986
+ * Sets the buffer to read pixels from for an extra channel at a given index.
987
+ * The index must be smaller than the num_extra_channels in the associated
988
+ * @ref JxlBasicInfo. Must call @ref JxlEncoderSetExtraChannelInfo before @ref
989
+ * JxlEncoderSetExtraChannelBuffer.
990
+ *
991
+ * TODO(firsching): mention what data types in pixel formats are supported.
992
+ *
993
+ * It is required to call this function for every extra channel, except for the
994
+ * alpha channel if that was already set through @ref JxlEncoderAddImageFrame.
995
+ *
996
+ * @param frame_settings set of options and metadata for this frame. Also
997
+ * includes reference to the encoder object.
998
+ * @param pixel_format format for pixels. Object owned by the caller and its
999
+ * contents are copied internally. The num_channels value is ignored, since the
1000
+ * number of channels for an extra channel is always assumed to be one.
1001
+ * @param buffer buffer type to input the pixel data from. Owned by the caller
1002
+ * and its contents are copied internally.
1003
+ * @param size size of buffer in bytes. This size should match what is implied
1004
+ * by the frame dimensions and the pixel format.
1005
+ * @param index index of the extra channel to use.
1006
+ * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error
1007
+ */
1008
+ JXL_EXPORT JxlEncoderStatus JxlEncoderSetExtraChannelBuffer(
1009
+ const JxlEncoderFrameSettings* frame_settings,
1010
+ const JxlPixelFormat* pixel_format, const void* buffer, size_t size,
1011
+ uint32_t index);
1012
+
1013
+ /** Adds a metadata box to the file format. @ref JxlEncoderProcessOutput must be
1014
+ * used to effectively write the box to the output. @ref JxlEncoderUseBoxes must
1015
+ * be enabled before using this function.
1016
+ *
1017
+ * Boxes allow inserting application-specific data and metadata (Exif, XML/XMP,
1018
+ * JUMBF and user defined boxes).
1019
+ *
1020
+ * The box format follows ISO BMFF and shares features and box types with other
1021
+ * image and video formats, including the Exif, XML and JUMBF boxes. The box
1022
+ * format for JPEG XL is specified in ISO/IEC 18181-2.
1023
+ *
1024
+ * Boxes in general don't contain other boxes inside, except a JUMBF superbox.
1025
+ * Boxes follow each other sequentially and are byte-aligned. If the container
1026
+ * format is used, the JXL stream consists of concatenated boxes.
1027
+ * It is also possible to use a direct codestream without boxes, but in that
1028
+ * case metadata cannot be added.
1029
+ *
1030
+ * Each box generally has the following byte structure in the file:
1031
+ * - 4 bytes: box size including box header (Big endian. If set to 1, an
1032
+ * 8-byte 64-bit size follows instead. If set to 0, the box extends to the
1033
+ * end of the file.)
1034
+ * - 4 bytes: type, e.g. "JXL " for the signature box, "jxlc" for a codestream
1035
+ * box.
1036
+ * - N bytes: box contents.
1037
+ *
1038
+ * Only the box contents are provided to the contents argument of this function,
1039
+ * the encoder encodes the size header itself. Most boxes are written
1040
+ * automatically by the encoder as needed ("JXL ", "ftyp", "jxll", "jxlc",
1041
+ * "jxlp", "jxli", "jbrd"), and this function only needs to be called to add
1042
+ * optional metadata when encoding from pixels (using @ref
1043
+ * JxlEncoderAddImageFrame). When recompressing JPEG files (using @ref
1044
+ * JxlEncoderAddJPEGFrame), if the input JPEG contains EXIF, XMP or JUMBF
1045
+ * metadata, the corresponding boxes are already added automatically.
1046
+ *
1047
+ * Box types are given by 4 characters. The following boxes can be added with
1048
+ * this function:
1049
+ * - "Exif": a box with EXIF metadata, can be added by libjxl users, or is
1050
+ * automatically added when needed for JPEG reconstruction. The contents of
1051
+ * this box must be prepended by a 4-byte tiff header offset, which may
1052
+ * be 4 zero bytes in case the tiff header follows immediately.
1053
+ * The EXIF metadata must be in sync with what is encoded in the JPEG XL
1054
+ * codestream, specifically the image orientation. While this is not
1055
+ * recommended in practice, in case of conflicting metadata, the JPEG XL
1056
+ * codestream takes precedence.
1057
+ * - "xml ": a box with XML data, in particular XMP metadata, can be added by
1058
+ * libjxl users, or is automatically added when needed for JPEG reconstruction
1059
+ * - "jumb": a JUMBF superbox, which can contain boxes with different types of
1060
+ * metadata inside. This box type can be added by the encoder transparently,
1061
+ * and other libraries to create and handle JUMBF content exist.
1062
+ * - Application-specific boxes. Their typename should not begin with "jxl" or
1063
+ * "JXL" or conflict with other existing typenames, and they should be
1064
+ * registered with MP4RA (mp4ra.org).
1065
+ *
1066
+ * These boxes can be stored uncompressed or Brotli-compressed (using a "brob"
1067
+ * box), depending on the compress_box parameter.
1068
+ *
1069
+ * @param enc encoder object.
1070
+ * @param type the box type, e.g. "Exif" for EXIF metadata, "xml " for XMP or
1071
+ * IPTC metadata, "jumb" for JUMBF metadata.
1072
+ * @param contents the full contents of the box, for example EXIF
1073
+ * data. ISO BMFF box header must not be included, only the contents. Owned by
1074
+ * the caller and its contents are copied internally.
1075
+ * @param size size of the box contents.
1076
+ * @param compress_box Whether to compress this box as a "brob" box. Requires
1077
+ * Brotli support.
1078
+ * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error, such as
1079
+ * when using this function without @ref JxlEncoderUseContainer, or adding a box
1080
+ * type that would result in an invalid file format.
1081
+ */
1082
+ JXL_EXPORT JxlEncoderStatus JxlEncoderAddBox(JxlEncoder* enc,
1083
+ const JxlBoxType type,
1084
+ const uint8_t* contents,
1085
+ size_t size,
1086
+ JXL_BOOL compress_box);
1087
+
1088
+ /**
1089
+ * Indicates the intention to add metadata boxes. This allows @ref
1090
+ * JxlEncoderAddBox to be used. When using this function, then it is required
1091
+ * to use @ref JxlEncoderCloseBoxes at the end.
1092
+ *
1093
+ * By default the encoder assumes no metadata boxes will be added.
1094
+ *
1095
+ * This setting can only be set at the beginning, before encoding starts.
1096
+ *
1097
+ * @param enc encoder object.
1098
+ */
1099
+ JXL_EXPORT JxlEncoderStatus JxlEncoderUseBoxes(JxlEncoder* enc);
1100
+
1101
+ /**
1102
+ * Declares that no further boxes will be added with @ref JxlEncoderAddBox.
1103
+ * This function must be called after the last box is added so the encoder knows
1104
+ * the stream will be finished. It is not necessary to use this function if
1105
+ * @ref JxlEncoderUseBoxes is not used. Further frames may still be added.
1106
+ *
1107
+ * Must be called between @ref JxlEncoderAddBox of the last box
1108
+ * and the next call to @ref JxlEncoderProcessOutput, or @ref
1109
+ * JxlEncoderProcessOutput won't output the last box correctly.
1110
+ *
1111
+ * NOTE: if you don't need to close frames and boxes at separate times, you can
1112
+ * use @ref JxlEncoderCloseInput instead to close both at once.
1113
+ *
1114
+ * @param enc encoder object.
1115
+ */
1116
+ JXL_EXPORT void JxlEncoderCloseBoxes(JxlEncoder* enc);
1117
+
1118
+ /**
1119
+ * Declares that no frames will be added and @ref JxlEncoderAddImageFrame and
1120
+ * @ref JxlEncoderAddJPEGFrame won't be called anymore. Further metadata boxes
1121
+ * may still be added. This function or @ref JxlEncoderCloseInput must be called
1122
+ * after adding the last frame and the next call to
1123
+ * @ref JxlEncoderProcessOutput, or the frame won't be properly marked as last.
1124
+ *
1125
+ * NOTE: if you don't need to close frames and boxes at separate times, you can
1126
+ * use @ref JxlEncoderCloseInput instead to close both at once.
1127
+ *
1128
+ * @param enc encoder object.
1129
+ */
1130
+ JXL_EXPORT void JxlEncoderCloseFrames(JxlEncoder* enc);
1131
+
1132
+ /**
1133
+ * Closes any input to the encoder, equivalent to calling @ref
1134
+ * JxlEncoderCloseFrames as well as calling @ref JxlEncoderCloseBoxes if needed.
1135
+ * No further input of any kind may be given to the encoder, but further @ref
1136
+ * JxlEncoderProcessOutput calls should be done to create the final output.
1137
+ *
1138
+ * The requirements of both @ref JxlEncoderCloseFrames and @ref
1139
+ * JxlEncoderCloseBoxes apply to this function. Either this function or the
1140
+ * other two must be called after the final frame and/or box, and the next
1141
+ * @ref JxlEncoderProcessOutput call, or the codestream won't be encoded
1142
+ * correctly.
1143
+ *
1144
+ * @param enc encoder object.
1145
+ */
1146
+ JXL_EXPORT void JxlEncoderCloseInput(JxlEncoder* enc);
1147
+
1148
+ /**
1149
+ * Sets the original color encoding of the image encoded by this encoder. This
1150
+ * is an alternative to @ref JxlEncoderSetICCProfile and only one of these two
1151
+ * must be used. This one sets the color encoding as a @ref JxlColorEncoding,
1152
+ * while the other sets it as ICC binary data. Must be called after @ref
1153
+ * JxlEncoderSetBasicInfo.
1154
+ *
1155
+ * @param enc encoder object.
1156
+ * @param color color encoding. Object owned by the caller and its contents are
1157
+ * copied internally.
1158
+ * @return ::JXL_ENC_SUCCESS if the operation was successful, @ref
1159
+ * JXL_ENC_ERROR otherwise
1160
+ */
1161
+ JXL_EXPORT JxlEncoderStatus
1162
+ JxlEncoderSetColorEncoding(JxlEncoder* enc, const JxlColorEncoding* color);
1163
+
1164
+ /**
1165
+ * Sets the original color encoding of the image encoded by this encoder as an
1166
+ * ICC color profile. This is an alternative to @ref JxlEncoderSetColorEncoding
1167
+ * and only one of these two must be used. This one sets the color encoding as
1168
+ * ICC binary data, while the other defines it as a @ref JxlColorEncoding. Must
1169
+ * be called after @ref JxlEncoderSetBasicInfo.
1170
+ *
1171
+ * @param enc encoder object.
1172
+ * @param icc_profile bytes of the original ICC profile
1173
+ * @param size size of the icc_profile buffer in bytes
1174
+ * @return ::JXL_ENC_SUCCESS if the operation was successful, @ref
1175
+ * JXL_ENC_ERROR otherwise
1176
+ */
1177
+ JXL_EXPORT JxlEncoderStatus JxlEncoderSetICCProfile(JxlEncoder* enc,
1178
+ const uint8_t* icc_profile,
1179
+ size_t size);
1180
+
1181
+ /**
1182
+ * Initializes a @ref JxlBasicInfo struct to default values.
1183
+ * For forwards-compatibility, this function has to be called before values
1184
+ * are assigned to the struct fields.
1185
+ * The default values correspond to an 8-bit RGB image, no alpha or any
1186
+ * other extra channels.
1187
+ *
1188
+ * @param info global image metadata. Object owned by the caller.
1189
+ */
1190
+ JXL_EXPORT void JxlEncoderInitBasicInfo(JxlBasicInfo* info);
1191
+
1192
+ /**
1193
+ * Initializes a @ref JxlFrameHeader struct to default values.
1194
+ * For forwards-compatibility, this function has to be called before values
1195
+ * are assigned to the struct fields.
1196
+ * The default values correspond to a frame with no animation duration and the
1197
+ * 'replace' blend mode. After using this function, For animation duration must
1198
+ * be set, for composite still blend settings must be set.
1199
+ *
1200
+ * @param frame_header frame metadata. Object owned by the caller.
1201
+ */
1202
+ JXL_EXPORT void JxlEncoderInitFrameHeader(JxlFrameHeader* frame_header);
1203
+
1204
+ /**
1205
+ * Initializes a @ref JxlBlendInfo struct to default values.
1206
+ * For forwards-compatibility, this function has to be called before values
1207
+ * are assigned to the struct fields.
1208
+ *
1209
+ * @param blend_info blending info. Object owned by the caller.
1210
+ */
1211
+ JXL_EXPORT void JxlEncoderInitBlendInfo(JxlBlendInfo* blend_info);
1212
+
1213
+ /**
1214
+ * Sets the global metadata of the image encoded by this encoder.
1215
+ *
1216
+ * If the @ref JxlBasicInfo contains information of extra channels beyond an
1217
+ * alpha channel, then @ref JxlEncoderSetExtraChannelInfo must be called between
1218
+ * @ref JxlEncoderSetBasicInfo and @ref JxlEncoderAddImageFrame. In order to
1219
+ * indicate extra channels, the value of `info.num_extra_channels` should be set
1220
+ * to the number of extra channels, also counting the alpha channel if present.
1221
+ *
1222
+ * @param enc encoder object.
1223
+ * @param info global image metadata. Object owned by the caller and its
1224
+ * contents are copied internally.
1225
+ * @return ::JXL_ENC_SUCCESS if the operation was successful,
1226
+ * ::JXL_ENC_ERROR otherwise
1227
+ */
1228
+ JXL_EXPORT JxlEncoderStatus JxlEncoderSetBasicInfo(JxlEncoder* enc,
1229
+ const JxlBasicInfo* info);
1230
+
1231
+ /**
1232
+ * Sets the upsampling method the decoder will use in case there are frames
1233
+ * with ::JXL_ENC_FRAME_SETTING_RESAMPLING set. This is useful in combination
1234
+ * with the ::JXL_ENC_FRAME_SETTING_ALREADY_DOWNSAMPLED option, to control
1235
+ * the type of upsampling that will be used.
1236
+ *
1237
+ * @param enc encoder object.
1238
+ * @param factor upsampling factor to configure (1, 2, 4 or 8; for 1 this
1239
+ * function has no effect at all)
1240
+ * @param mode upsampling mode to use for this upsampling:
1241
+ * -1: default (good for photographic images, no signaling overhead)
1242
+ * 0: nearest neighbor (good for pixel art)
1243
+ * 1: 'pixel dots' (same as NN for 2x, diamond-shaped 'pixel dots' for 4x/8x)
1244
+ * @return ::JXL_ENC_SUCCESS if the operation was successful,
1245
+ * ::JXL_ENC_ERROR otherwise
1246
+ */
1247
+ JXL_EXPORT JxlEncoderStatus JxlEncoderSetUpsamplingMode(JxlEncoder* enc,
1248
+ int64_t factor,
1249
+ int64_t mode);
1250
+
1251
+ /**
1252
+ * Initializes a @ref JxlExtraChannelInfo struct to default values.
1253
+ * For forwards-compatibility, this function has to be called before values
1254
+ * are assigned to the struct fields.
1255
+ * The default values correspond to an 8-bit channel of the provided type.
1256
+ *
1257
+ * @param type type of the extra channel.
1258
+ * @param info global extra channel metadata. Object owned by the caller and its
1259
+ * contents are copied internally.
1260
+ */
1261
+ JXL_EXPORT void JxlEncoderInitExtraChannelInfo(JxlExtraChannelType type,
1262
+ JxlExtraChannelInfo* info);
1263
+
1264
+ /**
1265
+ * Sets information for the extra channel at the given index. The index
1266
+ * must be smaller than num_extra_channels in the associated @ref JxlBasicInfo.
1267
+ *
1268
+ * @param enc encoder object
1269
+ * @param index index of the extra channel to set.
1270
+ * @param info global extra channel metadata. Object owned by the caller and its
1271
+ * contents are copied internally.
1272
+ * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error
1273
+ */
1274
+ JXL_EXPORT JxlEncoderStatus JxlEncoderSetExtraChannelInfo(
1275
+ JxlEncoder* enc, size_t index, const JxlExtraChannelInfo* info);
1276
+
1277
+ /**
1278
+ * Sets the name for the extra channel at the given index in UTF-8. The index
1279
+ * must be smaller than the num_extra_channels in the associated @ref
1280
+ * JxlBasicInfo.
1281
+ *
1282
+ * TODO(lode): remove size parameter for consistency with
1283
+ * @ref JxlEncoderSetFrameName
1284
+ *
1285
+ * @param enc encoder object
1286
+ * @param index index of the extra channel to set.
1287
+ * @param name buffer with the name of the extra channel.
1288
+ * @param size size of the name buffer in bytes, not counting the terminating
1289
+ * character.
1290
+ * @return JXL_ENC_SUCCESS on success, JXL_ENC_ERROR on error
1291
+ */
1292
+ JXL_EXPORT JxlEncoderStatus JxlEncoderSetExtraChannelName(JxlEncoder* enc,
1293
+ size_t index,
1294
+ const char* name,
1295
+ size_t size);
1296
+
1297
+ /**
1298
+ * Sets a frame-specific option of integer type to the encoder options.
1299
+ * The @ref JxlEncoderFrameSettingId argument determines which option is set.
1300
+ *
1301
+ * @param frame_settings set of options and metadata for this frame. Also
1302
+ * includes reference to the encoder object.
1303
+ * @param option ID of the option to set.
1304
+ * @param value Integer value to set for this option.
1305
+ * @return ::JXL_ENC_SUCCESS if the operation was successful, @ref
1306
+ * JXL_ENC_ERROR in case of an error, such as invalid or unknown option id, or
1307
+ * invalid integer value for the given option. If an error is returned, the
1308
+ * state of the
1309
+ * @ref JxlEncoderFrameSettings object is still valid and is the same as before
1310
+ * this function was called.
1311
+ */
1312
+ JXL_EXPORT JxlEncoderStatus JxlEncoderFrameSettingsSetOption(
1313
+ JxlEncoderFrameSettings* frame_settings, JxlEncoderFrameSettingId option,
1314
+ int64_t value);
1315
+
1316
+ /**
1317
+ * Sets a frame-specific option of float type to the encoder options.
1318
+ * The @ref JxlEncoderFrameSettingId argument determines which option is set.
1319
+ *
1320
+ * @param frame_settings set of options and metadata for this frame. Also
1321
+ * includes reference to the encoder object.
1322
+ * @param option ID of the option to set.
1323
+ * @param value Float value to set for this option.
1324
+ * @return ::JXL_ENC_SUCCESS if the operation was successful, @ref
1325
+ * JXL_ENC_ERROR in case of an error, such as invalid or unknown option id, or
1326
+ * invalid integer value for the given option. If an error is returned, the
1327
+ * state of the
1328
+ * @ref JxlEncoderFrameSettings object is still valid and is the same as before
1329
+ * this function was called.
1330
+ */
1331
+ JXL_EXPORT JxlEncoderStatus JxlEncoderFrameSettingsSetFloatOption(
1332
+ JxlEncoderFrameSettings* frame_settings, JxlEncoderFrameSettingId option,
1333
+ float value);
1334
+
1335
+ /** Forces the encoder to use the box-based container format (BMFF) even
1336
+ * when not necessary.
1337
+ *
1338
+ * When using @ref JxlEncoderUseBoxes, @ref JxlEncoderStoreJPEGMetadata or @ref
1339
+ * JxlEncoderSetCodestreamLevel with level 10, the encoder will automatically
1340
+ * also use the container format, it is not necessary to use
1341
+ * @ref JxlEncoderUseContainer for those use cases.
1342
+ *
1343
+ * By default this setting is disabled.
1344
+ *
1345
+ * This setting can only be set at the beginning, before encoding starts.
1346
+ *
1347
+ * @param enc encoder object.
1348
+ * @param use_container true if the encoder should always output the JPEG XL
1349
+ * container format, false to only output it when necessary.
1350
+ * @return JXL_ENC_SUCCESS if the operation was successful, JXL_ENC_ERROR
1351
+ * otherwise.
1352
+ */
1353
+ JXL_EXPORT JxlEncoderStatus JxlEncoderUseContainer(JxlEncoder* enc,
1354
+ JXL_BOOL use_container);
1355
+
1356
+ /**
1357
+ * Configure the encoder to store JPEG reconstruction metadata in the JPEG XL
1358
+ * container.
1359
+ *
1360
+ * If this is set to true and a single JPEG frame is added, it will be
1361
+ * possible to losslessly reconstruct the JPEG codestream.
1362
+ *
1363
+ * This setting can only be set at the beginning, before encoding starts.
1364
+ *
1365
+ * @param enc encoder object.
1366
+ * @param store_jpeg_metadata true if the encoder should store JPEG metadata.
1367
+ * @return ::JXL_ENC_SUCCESS if the operation was successful, @ref
1368
+ * JXL_ENC_ERROR otherwise.
1369
+ */
1370
+ JXL_EXPORT JxlEncoderStatus
1371
+ JxlEncoderStoreJPEGMetadata(JxlEncoder* enc, JXL_BOOL store_jpeg_metadata);
1372
+
1373
+ /** Sets the feature level of the JPEG XL codestream. Valid values are 5 and
1374
+ * 10, or -1 (to choose automatically). Using the minimum required level, or
1375
+ * level 5 in most cases, is recommended for compatibility with all decoders.
1376
+ *
1377
+ * Level 5: for end-user image delivery, this level is the most widely
1378
+ * supported level by image decoders and the recommended level to use unless a
1379
+ * level 10 feature is absolutely necessary. Supports a maximum resolution
1380
+ * 268435456 pixels total with a maximum width or height of 262144 pixels,
1381
+ * maximum 16-bit color channel depth, maximum 120 frames per second for
1382
+ * animation, maximum ICC color profile size of 4 MiB, it allows all color
1383
+ * models and extra channel types except CMYK and the JXL_CHANNEL_BLACK
1384
+ * extra channel, and a maximum of 4 extra channels in addition to the 3 color
1385
+ * channels. It also sets boundaries to certain internally used coding tools.
1386
+ *
1387
+ * Level 10: this level removes or increases the bounds of most of the level
1388
+ * 5 limitations, allows CMYK color and up to 32 bits per color channel, but
1389
+ * may be less widely supported.
1390
+ *
1391
+ * The default value is -1. This means the encoder will automatically choose
1392
+ * between level 5 and level 10 based on what information is inside the @ref
1393
+ * JxlBasicInfo structure. Do note that some level 10 features, particularly
1394
+ * those used by animated JPEG XL codestreams, might require level 10, even
1395
+ * though the @ref JxlBasicInfo only suggests level 5. In this case, the level
1396
+ * must be explicitly set to 10, otherwise the encoder will return an error.
1397
+ * The encoder will restrict internal encoding choices to those compatible with
1398
+ * the level setting.
1399
+ *
1400
+ * This setting can only be set at the beginning, before encoding starts.
1401
+ *
1402
+ * @param enc encoder object.
1403
+ * @param level the level value to set, must be -1, 5, or 10.
1404
+ * @return ::JXL_ENC_SUCCESS if the operation was successful, @ref
1405
+ * JXL_ENC_ERROR otherwise.
1406
+ */
1407
+ JXL_EXPORT JxlEncoderStatus JxlEncoderSetCodestreamLevel(JxlEncoder* enc,
1408
+ int level);
1409
+
1410
+ /** Returns the codestream level required to support the currently configured
1411
+ * settings and basic info. This function can only be used at the beginning,
1412
+ * before encoding starts, but after setting basic info.
1413
+ *
1414
+ * This does not support per-frame settings, only global configuration, such as
1415
+ * the image dimensions, that are known at the time of writing the header of
1416
+ * the JPEG XL file.
1417
+ *
1418
+ * If this returns 5, nothing needs to be done and the codestream can be
1419
+ * compatible with any decoder. If this returns 10, @ref
1420
+ * JxlEncoderSetCodestreamLevel has to be used to set the codestream level to
1421
+ * 10, or the encoder can be configured differently to allow using the more
1422
+ * compatible level 5.
1423
+ *
1424
+ * @param enc encoder object.
1425
+ * @return -1 if no level can support the configuration (e.g. image dimensions
1426
+ * larger than even level 10 supports), 5 if level 5 is supported, 10 if setting
1427
+ * the codestream level to 10 is required.
1428
+ *
1429
+ */
1430
+ JXL_EXPORT int JxlEncoderGetRequiredCodestreamLevel(const JxlEncoder* enc);
1431
+
1432
+ /**
1433
+ * Enables lossless encoding.
1434
+ *
1435
+ * This is not an option like the others on itself, but rather while enabled it
1436
+ * overrides a set of existing options (such as distance, modular mode and
1437
+ * color transform) that enables bit-for-bit lossless encoding.
1438
+ *
1439
+ * When disabled, those options are not overridden, but since those options
1440
+ * could still have been manually set to a combination that operates losslessly,
1441
+ * using this function with lossless set to ::JXL_FALSE does not
1442
+ * guarantee lossy encoding, though the default set of options is lossy.
1443
+ *
1444
+ * @param frame_settings set of options and metadata for this frame. Also
1445
+ * includes reference to the encoder object.
1446
+ * @param lossless whether to override options for lossless mode
1447
+ * @return ::JXL_ENC_SUCCESS if the operation was successful, @ref
1448
+ * JXL_ENC_ERROR otherwise.
1449
+ */
1450
+ JXL_EXPORT JxlEncoderStatus JxlEncoderSetFrameLossless(
1451
+ JxlEncoderFrameSettings* frame_settings, JXL_BOOL lossless);
1452
+
1453
+ /**
1454
+ * Sets the distance level for lossy compression: target max butteraugli
1455
+ * distance, lower = higher quality. Range: 0 .. 25.
1456
+ * 0.0 = mathematically lossless (however, use @ref JxlEncoderSetFrameLossless
1457
+ * instead to use true lossless, as setting distance to 0 alone is not the only
1458
+ * requirement). 1.0 = visually lossless. Recommended range: 0.5 .. 3.0. Default
1459
+ * value: 1.0.
1460
+ *
1461
+ * @param frame_settings set of options and metadata for this frame. Also
1462
+ * includes reference to the encoder object.
1463
+ * @param distance the distance value to set.
1464
+ * @return ::JXL_ENC_SUCCESS if the operation was successful, @ref
1465
+ * JXL_ENC_ERROR otherwise.
1466
+ */
1467
+ JXL_EXPORT JxlEncoderStatus JxlEncoderSetFrameDistance(
1468
+ JxlEncoderFrameSettings* frame_settings, float distance);
1469
+
1470
+ /**
1471
+ * Sets the distance level for lossy compression of extra channels.
1472
+ * The distance is as in @ref JxlEncoderSetFrameDistance (lower = higher
1473
+ * quality). If not set, or if set to the special value -1, the distance that
1474
+ * was set with
1475
+ * @ref JxlEncoderSetFrameDistance will be used.
1476
+ *
1477
+ * @param frame_settings set of options and metadata for this frame. Also
1478
+ * includes reference to the encoder object.
1479
+ * @param index index of the extra channel to set a distance value for.
1480
+ * @param distance the distance value to set.
1481
+ * @return ::JXL_ENC_SUCCESS if the operation was successful, @ref
1482
+ * JXL_ENC_ERROR otherwise.
1483
+ */
1484
+ JXL_EXPORT JxlEncoderStatus JxlEncoderSetExtraChannelDistance(
1485
+ JxlEncoderFrameSettings* frame_settings, size_t index, float distance);
1486
+
1487
+ /**
1488
+ * Maps JPEG-style quality factor to distance.
1489
+ *
1490
+ * This function takes in input a JPEG-style quality factor `quality` and
1491
+ * produces as output a `distance` value suitable to be used with @ref
1492
+ * JxlEncoderSetFrameDistance and @ref JxlEncoderSetExtraChannelDistance.
1493
+ *
1494
+ * The `distance` value influences the level of compression, with lower values
1495
+ * indicating higher quality:
1496
+ * - 0.0 implies lossless compression (however, note that calling @ref
1497
+ * JxlEncoderSetFrameLossless is required).
1498
+ * - 1.0 represents a visually lossy compression, which is also the default
1499
+ * setting.
1500
+ *
1501
+ * The `quality` parameter, ranging up to 100, is inversely related to
1502
+ * 'distance':
1503
+ * - A `quality` of 100.0 maps to a `distance` of 0.0 (lossless).
1504
+ * - A `quality` of 90.0 corresponds to a `distance` of 1.0.
1505
+ *
1506
+ * Recommended Range:
1507
+ * - `distance`: 0.5 to 3.0.
1508
+ * - corresponding `quality`: approximately 96 to 68.
1509
+ *
1510
+ * Allowed Range:
1511
+ * - `distance`: 0.0 to 25.0.
1512
+ * - corresponding `quality`: 100.0 to 0.0.
1513
+ *
1514
+ * Note: the `quality` parameter has no consistent psychovisual meaning
1515
+ * across different codecs and libraries. Using the mapping defined by @ref
1516
+ * JxlEncoderDistanceFromQuality will result in a visual quality roughly
1517
+ * equivalent to what would be obtained with `libjpeg-turbo` with the same
1518
+ * `quality` parameter, but that is by no means guaranteed; do not assume that
1519
+ * the same quality value will result in similar file sizes and image quality
1520
+ * across different codecs.
1521
+ */
1522
+ JXL_EXPORT float JxlEncoderDistanceFromQuality(float quality);
1523
+
1524
+ /**
1525
+ * Create a new set of encoder options, with all values initially copied from
1526
+ * the @p source options, or set to default if @p source is NULL.
1527
+ *
1528
+ * The returned pointer is an opaque struct tied to the encoder and it will be
1529
+ * deallocated by the encoder when @ref JxlEncoderDestroy() is called. For
1530
+ * functions taking both a @ref JxlEncoder and a @ref JxlEncoderFrameSettings,
1531
+ * only @ref JxlEncoderFrameSettings created with this function for the same
1532
+ * encoder instance can be used.
1533
+ *
1534
+ * The returned value could be NULL in case of out of memory situatiton.
1535
+ *
1536
+ * @param enc encoder object.
1537
+ * @param source source options to copy initial values from, or NULL to get
1538
+ * defaults initialized to defaults.
1539
+ * @return the opaque struct pointer identifying a new set of encoder options.
1540
+ */
1541
+ JXL_EXPORT JxlEncoderFrameSettings* JxlEncoderFrameSettingsCreate(
1542
+ JxlEncoder* enc, const JxlEncoderFrameSettings* source);
1543
+
1544
+ /**
1545
+ * Sets a color encoding to be sRGB.
1546
+ *
1547
+ * @param color_encoding color encoding instance.
1548
+ * @param is_gray whether the color encoding should be gray scale or color.
1549
+ */
1550
+ JXL_EXPORT void JxlColorEncodingSetToSRGB(JxlColorEncoding* color_encoding,
1551
+ JXL_BOOL is_gray);
1552
+
1553
+ /**
1554
+ * Sets a color encoding to be linear sRGB.
1555
+ *
1556
+ * @param color_encoding color encoding instance.
1557
+ * @param is_gray whether the color encoding should be gray scale or color.
1558
+ */
1559
+ JXL_EXPORT void JxlColorEncodingSetToLinearSRGB(
1560
+ JxlColorEncoding* color_encoding, JXL_BOOL is_gray);
1561
+
1562
+ /**
1563
+ * Enables usage of expert options.
1564
+ *
1565
+ * At the moment, the only expert option is setting an effort value of 11,
1566
+ * which gives the best compression for pixel-lossless modes but is very slow.
1567
+ *
1568
+ * @param enc encoder object.
1569
+ */
1570
+ JXL_EXPORT void JxlEncoderAllowExpertOptions(JxlEncoder* enc);
1571
+
1572
+ /**
1573
+ * Function type for @ref JxlEncoderSetDebugImageCallback.
1574
+ *
1575
+ * The callback may be called simultaneously by different threads when using a
1576
+ * threaded parallel runner, on different debug images.
1577
+ *
1578
+ * @param opaque optional user data, as given to @ref
1579
+ * JxlEncoderSetDebugImageCallback.
1580
+ * @param label label of debug image, can be used in filenames
1581
+ * @param xsize width of debug image
1582
+ * @param ysize height of debug image
1583
+ * @param color color encoding of debug image
1584
+ * @param pixels pixel data of debug image as big-endian 16-bit unsigned
1585
+ * samples. The memory is not owned by the user, and is only valid during the
1586
+ * time the callback is running.
1587
+ */
1588
+ typedef void (*JxlDebugImageCallback)(void* opaque, const char* label,
1589
+ size_t xsize, size_t ysize,
1590
+ const JxlColorEncoding* color,
1591
+ const uint16_t* pixels);
1592
+
1593
+ /**
1594
+ * Sets the given debug image callback that will be used by the encoder to
1595
+ * output various debug images during encoding.
1596
+ *
1597
+ * This only has any effect if the encoder was compiled with the appropriate
1598
+ * debug build flags.
1599
+ *
1600
+ * @param frame_settings set of options and metadata for this frame. Also
1601
+ * includes reference to the encoder object.
1602
+ * @param callback used to return the debug image
1603
+ * @param opaque user supplied parameter to the image callback
1604
+ */
1605
+ JXL_EXPORT void JxlEncoderSetDebugImageCallback(
1606
+ JxlEncoderFrameSettings* frame_settings, JxlDebugImageCallback callback,
1607
+ void* opaque);
1608
+
1609
+ /**
1610
+ * Sets the given stats object for gathering various statistics during encoding.
1611
+ *
1612
+ * This only has any effect if the encoder was compiled with the appropriate
1613
+ * debug build flags.
1614
+ *
1615
+ * @param frame_settings set of options and metadata for this frame. Also
1616
+ * includes reference to the encoder object.
1617
+ * @param stats object that can be used to query the gathered stats (created
1618
+ * by @ref JxlEncoderStatsCreate)
1619
+ */
1620
+ JXL_EXPORT void JxlEncoderCollectStats(JxlEncoderFrameSettings* frame_settings,
1621
+ JxlEncoderStats* stats);
1622
+
1623
+ #ifdef __cplusplus
1624
+ }
1625
+ #endif
1626
+
1627
+ #endif /* JXL_ENCODE_H_ */
1628
+
1629
+ /** @}*/