encode.h (69933B)
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 #if defined(__cplusplus) || defined(c_plusplus) 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 JxlEncoderStruct 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 JxlEncoderFrameSettingsStruct 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 buffering is used, when using chunked image frames. 344 * -1 = default (let the encoder decide) 345 * 0 = buffers everything, basically the same as non-streamed code path 346 (mainly for testing) 347 * 1 = buffers everything for images that are smaller than 2048 x 2048, and 348 * uses streaming input and output for larger images 349 * 2 = uses streaming input and output for all images that are larger than 350 * one group, i.e. 256 x 256 pixels by default 351 * 3 = currently same as 2 352 * 353 * When using streaming input and output the encoder minimizes memory usage at 354 * the cost of compression density. Also note that images produced with 355 * streaming mode might not be progressively decodeable. 356 */ 357 JXL_ENC_FRAME_SETTING_BUFFERING = 34, 358 359 /** Keep or discard Exif metadata boxes derived from a JPEG frame when using 360 * @ref JxlEncoderAddJPEGFrame. This has no effect on boxes added using 361 * @ref JxlEncoderAddBox. When @ref JxlEncoderStoreJPEGMetadata is set to 1, 362 * this option cannot be set to 0. Even when Exif metadata is discarded, the 363 * orientation will still be applied. 0 = discard Exif metadata, 1 = keep Exif 364 * metadata (default). 365 */ 366 JXL_ENC_FRAME_SETTING_JPEG_KEEP_EXIF = 35, 367 368 /** Keep or discard XMP metadata boxes derived from a JPEG frame when using 369 * @ref JxlEncoderAddJPEGFrame. This has no effect on boxes added using 370 * @ref JxlEncoderAddBox. When @ref JxlEncoderStoreJPEGMetadata is set to 1, 371 * this option cannot be set to 0. 0 = discard XMP metadata, 1 = keep XMP 372 * metadata (default). 373 */ 374 JXL_ENC_FRAME_SETTING_JPEG_KEEP_XMP = 36, 375 376 /** Keep or discard JUMBF metadata boxes derived from a JPEG frame when using 377 * @ref JxlEncoderAddJPEGFrame. This has no effect on boxes added using 378 * @ref JxlEncoderAddBox. 0 = discard JUMBF metadata, 1 = keep JUMBF metadata 379 * (default). 380 */ 381 JXL_ENC_FRAME_SETTING_JPEG_KEEP_JUMBF = 37, 382 383 /** If this mode is disabled, the encoder will not make any image quality 384 * decisions that are computed based on the full image, but stored only once 385 * (e.g. the X quant multiplier in the frame header). Used mainly for testing 386 * equivalence of streaming and non-streaming code. 387 * 0 = disabled, 1 = enabled (default) 388 */ 389 JXL_ENC_FRAME_SETTING_USE_FULL_IMAGE_HEURISTICS = 38, 390 391 /** Enum value not to be used as an option. This value is added to force the 392 * C compiler to have the enum to take a known size. 393 */ 394 JXL_ENC_FRAME_SETTING_FILL_ENUM = 65535, 395 396 } JxlEncoderFrameSettingId; 397 398 /** 399 * Creates an instance of @ref JxlEncoder and initializes it. 400 * 401 * @p memory_manager will be used for all the library dynamic allocations made 402 * from this instance. The parameter may be NULL, in which case the default 403 * allocator will be used. See jpegxl/memory_manager.h for details. 404 * 405 * @param memory_manager custom allocator function. It may be NULL. The memory 406 * manager will be copied internally. 407 * @return @c NULL if the instance can not be allocated or initialized 408 * @return pointer to initialized @ref JxlEncoder otherwise 409 */ 410 JXL_EXPORT JxlEncoder* JxlEncoderCreate(const JxlMemoryManager* memory_manager); 411 412 /** 413 * Re-initializes a @ref JxlEncoder instance, so it can be re-used for encoding 414 * another image. All state and settings are reset as if the object was 415 * newly created with @ref JxlEncoderCreate, but the memory manager is kept. 416 * 417 * @param enc instance to be re-initialized. 418 */ 419 JXL_EXPORT void JxlEncoderReset(JxlEncoder* enc); 420 421 /** 422 * Deinitializes and frees a @ref JxlEncoder instance. 423 * 424 * @param enc instance to be cleaned up and deallocated. 425 */ 426 JXL_EXPORT void JxlEncoderDestroy(JxlEncoder* enc); 427 428 /** 429 * Sets the color management system (CMS) that will be used for color conversion 430 * (if applicable) during encoding. May only be set before starting encoding. If 431 * left unset, the default CMS implementation will be used. 432 * 433 * @param enc encoder object. 434 * @param cms structure representing a CMS implementation. See @ref 435 * JxlCmsInterface for more details. 436 */ 437 JXL_EXPORT void JxlEncoderSetCms(JxlEncoder* enc, JxlCmsInterface cms); 438 439 /** 440 * Set the parallel runner for multithreading. May only be set before starting 441 * encoding. 442 * 443 * @param enc encoder object. 444 * @param parallel_runner function pointer to runner for multithreading. It may 445 * be NULL to use the default, single-threaded, runner. A multithreaded 446 * runner should be set to reach fast performance. 447 * @param parallel_runner_opaque opaque pointer for parallel_runner. 448 * @return ::JXL_ENC_SUCCESS if the runner was set, ::JXL_ENC_ERROR 449 * otherwise (the previous runner remains set). 450 */ 451 JXL_EXPORT JxlEncoderStatus 452 JxlEncoderSetParallelRunner(JxlEncoder* enc, JxlParallelRunner parallel_runner, 453 void* parallel_runner_opaque); 454 455 /** 456 * Get the (last) error code in case ::JXL_ENC_ERROR was returned. 457 * 458 * @param enc encoder object. 459 * @return the @ref JxlEncoderError that caused the (last) ::JXL_ENC_ERROR to 460 * be returned. 461 */ 462 JXL_EXPORT JxlEncoderError JxlEncoderGetError(JxlEncoder* enc); 463 464 /** 465 * Encodes a JPEG XL file using the available bytes. @p *avail_out indicates how 466 * many output bytes are available, and @p *next_out points to the input bytes. 467 * *avail_out will be decremented by the amount of bytes that have been 468 * processed by the encoder and *next_out will be incremented by the same 469 * amount, so *next_out will now point at the amount of *avail_out unprocessed 470 * bytes. 471 * 472 * The returned status indicates whether the encoder needs more output bytes. 473 * When the return value is not ::JXL_ENC_ERROR or ::JXL_ENC_SUCCESS, the 474 * encoding requires more @ref JxlEncoderProcessOutput calls to continue. 475 * 476 * The caller must guarantee that *avail_out >= 32 when calling 477 * @ref JxlEncoderProcessOutput; otherwise, ::JXL_ENC_NEED_MORE_OUTPUT will 478 * be returned. It is guaranteed that, if *avail_out >= 32, at least one byte of 479 * output will be written. 480 * 481 * This encodes the frames and/or boxes added so far. If the last frame or last 482 * box has been added, @ref JxlEncoderCloseInput, @ref JxlEncoderCloseFrames 483 * and/or @ref JxlEncoderCloseBoxes must be called before the next 484 * @ref JxlEncoderProcessOutput call, or the codestream won't be encoded 485 * correctly. 486 * 487 * @param enc encoder object. 488 * @param next_out pointer to next bytes to write to. 489 * @param avail_out amount of bytes available starting from *next_out. 490 * @return ::JXL_ENC_SUCCESS when encoding finished and all events handled. 491 * @return ::JXL_ENC_ERROR when encoding failed, e.g. invalid input. 492 * @return ::JXL_ENC_NEED_MORE_OUTPUT more output buffer is necessary. 493 */ 494 JXL_EXPORT JxlEncoderStatus JxlEncoderProcessOutput(JxlEncoder* enc, 495 uint8_t** next_out, 496 size_t* avail_out); 497 498 /** 499 * Sets the frame information for this frame to the encoder. This includes 500 * animation information such as frame duration to store in the frame header. 501 * The frame header fields represent the frame as passed to the encoder, but not 502 * necessarily the exact values as they will be encoded file format: the encoder 503 * could change crop and blending options of a frame for more efficient encoding 504 * or introduce additional internal frames. Animation duration and time code 505 * information is not altered since those are immutable metadata of the frame. 506 * 507 * It is not required to use this function, however if have_animation is set 508 * to true in the basic info, then this function should be used to set the 509 * time duration of this individual frame. By default individual frames have a 510 * time duration of 0, making them form a composite still. See @ref 511 * JxlFrameHeader for more information. 512 * 513 * This information is stored in the @ref JxlEncoderFrameSettings and so is used 514 * for any frame encoded with these @ref JxlEncoderFrameSettings. It is ok to 515 * change between @ref JxlEncoderAddImageFrame calls, each added image frame 516 * will have the frame header that was set in the options at the time of calling 517 * @ref JxlEncoderAddImageFrame. 518 * 519 * The is_last and name_length fields of the @ref JxlFrameHeader are ignored, 520 * use 521 * @ref JxlEncoderCloseFrames to indicate last frame, and @ref 522 * JxlEncoderSetFrameName to indicate the name and its length instead. 523 * Calling this function will clear any name that was previously set with @ref 524 * JxlEncoderSetFrameName. 525 * 526 * @param frame_settings set of options and metadata for this frame. Also 527 * includes reference to the encoder object. 528 * @param frame_header frame header data to set. Object owned by the caller and 529 * does not need to be kept in memory, its information is copied internally. 530 * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error 531 */ 532 JXL_EXPORT JxlEncoderStatus 533 JxlEncoderSetFrameHeader(JxlEncoderFrameSettings* frame_settings, 534 const JxlFrameHeader* frame_header); 535 536 /** 537 * Sets blend info of an extra channel. The blend info of extra channels is set 538 * separately from that of the color channels, the color channels are set with 539 * @ref JxlEncoderSetFrameHeader. 540 * 541 * @param frame_settings set of options and metadata for this frame. Also 542 * includes reference to the encoder object. 543 * @param index index of the extra channel to use. 544 * @param blend_info blend info to set for the extra channel 545 * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error 546 */ 547 JXL_EXPORT JxlEncoderStatus JxlEncoderSetExtraChannelBlendInfo( 548 JxlEncoderFrameSettings* frame_settings, size_t index, 549 const JxlBlendInfo* blend_info); 550 551 /** 552 * Sets the name of the animation frame. This function is optional, frames are 553 * not required to have a name. This setting is a part of the frame header, and 554 * the same principles as for @ref JxlEncoderSetFrameHeader apply. The 555 * name_length field of @ref JxlFrameHeader is ignored by the encoder, this 556 * function determines the name length instead as the length in bytes of the C 557 * string. 558 * 559 * The maximum possible name length is 1071 bytes (excluding terminating null 560 * character). 561 * 562 * Calling @ref JxlEncoderSetFrameHeader clears any name that was 563 * previously set. 564 * 565 * @param frame_settings set of options and metadata for this frame. Also 566 * includes reference to the encoder object. 567 * @param frame_name name of the next frame to be encoded, as a UTF-8 encoded C 568 * string (zero terminated). Owned by the caller, and copied internally. 569 * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error 570 */ 571 JXL_EXPORT JxlEncoderStatus JxlEncoderSetFrameName( 572 JxlEncoderFrameSettings* frame_settings, const char* frame_name); 573 574 /** 575 * Sets the bit depth of the input buffer. 576 * 577 * For float pixel formats, only the default @ref 578 JXL_BIT_DEPTH_FROM_PIXEL_FORMAT 579 * setting is allowed, while for unsigned pixel formats, 580 * ::JXL_BIT_DEPTH_FROM_CODESTREAM setting is also allowed. See the comment 581 on 582 * @ref JxlEncoderAddImageFrame for the effects of the bit depth setting. 583 584 * @param frame_settings set of options and metadata for this frame. Also 585 * includes reference to the encoder object. 586 * @param bit_depth the bit depth setting of the pixel input 587 * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error 588 */ 589 JXL_EXPORT JxlEncoderStatus JxlEncoderSetFrameBitDepth( 590 JxlEncoderFrameSettings* frame_settings, const JxlBitDepth* bit_depth); 591 592 /** 593 * Sets the buffer to read JPEG encoded bytes from for the next frame to encode. 594 * 595 * If @ref JxlEncoderSetBasicInfo has not yet been called, calling 596 * @ref JxlEncoderAddJPEGFrame will implicitly call it with the parameters of 597 * the added JPEG frame. 598 * 599 * If @ref JxlEncoderSetColorEncoding or @ref JxlEncoderSetICCProfile has not 600 * yet been called, calling @ref JxlEncoderAddJPEGFrame will implicitly call it 601 * with the parameters of the added JPEG frame. 602 * 603 * If the encoder is set to store JPEG reconstruction metadata using @ref 604 * JxlEncoderStoreJPEGMetadata and a single JPEG frame is added, it will be 605 * possible to losslessly reconstruct the JPEG codestream. 606 * 607 * If this is the last frame, @ref JxlEncoderCloseInput or @ref 608 * JxlEncoderCloseFrames must be called before the next 609 * @ref JxlEncoderProcessOutput call. 610 * 611 * Note, this can only be used to add JPEG frames for lossless compression. To 612 * encode with lossy compression, the JPEG must be decoded manually and a pixel 613 * buffer added using JxlEncoderAddImageFrame. 614 * 615 * @param frame_settings set of options and metadata for this frame. Also 616 * includes reference to the encoder object. 617 * @param buffer bytes to read JPEG from. Owned by the caller and its contents 618 * are copied internally. 619 * @param size size of buffer in bytes. 620 * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error 621 */ 622 JXL_EXPORT JxlEncoderStatus 623 JxlEncoderAddJPEGFrame(const JxlEncoderFrameSettings* frame_settings, 624 const uint8_t* buffer, size_t size); 625 626 /** 627 * Sets the buffer to read pixels from for the next image to encode. Must call 628 * @ref JxlEncoderSetBasicInfo before @ref JxlEncoderAddImageFrame. 629 * 630 * Currently only some data types for pixel formats are supported: 631 * - ::JXL_TYPE_UINT8, with range 0..255 632 * - ::JXL_TYPE_UINT16, with range 0..65535 633 * - ::JXL_TYPE_FLOAT16, with nominal range 0..1 634 * - ::JXL_TYPE_FLOAT, with nominal range 0..1 635 * 636 * Note: the sample data type in pixel_format is allowed to be different from 637 * what is described in the @ref JxlBasicInfo. The type in pixel_format, 638 * together with an optional @ref JxlBitDepth parameter set by @ref 639 * JxlEncoderSetFrameBitDepth describes the format of the uncompressed pixel 640 * buffer. The bits_per_sample and exponent_bits_per_sample in the @ref 641 * JxlBasicInfo describes what will actually be encoded in the JPEG XL 642 * codestream. For example, to encode a 12-bit image, you would set 643 * bits_per_sample to 12, while the input frame buffer can be in the following 644 * formats: 645 * - if pixel format is in ::JXL_TYPE_UINT16 with default bit depth setting 646 * (i.e. ::JXL_BIT_DEPTH_FROM_PIXEL_FORMAT), input sample values are 647 * rescaled to 16-bit, i.e. multiplied by 65535/4095; 648 * - if pixel format is in ::JXL_TYPE_UINT16 with @ref 649 * JXL_BIT_DEPTH_FROM_CODESTREAM bit depth setting, input sample values are 650 * provided unscaled; 651 * - if pixel format is in ::JXL_TYPE_FLOAT, input sample values are 652 * rescaled to 0..1, i.e. multiplied by 1.f/4095.f. While it is allowed, it is 653 * obviously not recommended to use a pixel_format with lower precision than 654 * what is specified in the @ref JxlBasicInfo. 655 * 656 * We support interleaved channels as described by the @ref JxlPixelFormat 657 * "JxlPixelFormat": 658 * - single-channel data, e.g. grayscale 659 * - single-channel + alpha 660 * - trichromatic, e.g. RGB 661 * - trichromatic + alpha 662 * 663 * Extra channels not handled here need to be set by @ref 664 * JxlEncoderSetExtraChannelBuffer. 665 * If the image has alpha, and alpha is not passed here, it will implicitly be 666 * set to all-opaque (an alpha value of 1.0 everywhere). 667 * 668 * The pixels are assumed to be encoded in the original profile that is set with 669 * @ref JxlEncoderSetColorEncoding or @ref JxlEncoderSetICCProfile. If none of 670 * these functions were used, the pixels are assumed to be nonlinear sRGB for 671 * integer data types (::JXL_TYPE_UINT8, ::JXL_TYPE_UINT16), and linear 672 * sRGB for floating point data types (::JXL_TYPE_FLOAT16, @ref 673 * JXL_TYPE_FLOAT). 674 * 675 * Sample values in floating-point pixel formats are allowed to be outside the 676 * nominal range, e.g. to represent out-of-sRGB-gamut colors in the 677 * uses_original_profile=false case. They are however not allowed to be NaN or 678 * +-infinity. 679 * 680 * If this is the last frame, @ref JxlEncoderCloseInput or @ref 681 * JxlEncoderCloseFrames must be called before the next 682 * @ref JxlEncoderProcessOutput call. 683 * 684 * @param frame_settings set of options and metadata for this frame. Also 685 * includes reference to the encoder object. 686 * @param pixel_format format for pixels. Object owned by the caller and its 687 * contents are copied internally. 688 * @param buffer buffer type to input the pixel data from. Owned by the caller 689 * and its contents are copied internally. 690 * @param size size of buffer in bytes. This size should match what is implied 691 * by the frame dimensions and the pixel format. 692 * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error 693 */ 694 JXL_EXPORT JxlEncoderStatus JxlEncoderAddImageFrame( 695 const JxlEncoderFrameSettings* frame_settings, 696 const JxlPixelFormat* pixel_format, const void* buffer, size_t size); 697 698 /** 699 * The @ref JxlEncoderOutputProcessor structure provides an interface for the 700 * encoder's output processing. Users of the library, who want to do streaming 701 * encoding, should implement the required callbacks for buffering, writing, 702 * seeking (if supported), and setting a finalized position during the encoding 703 * process. 704 * 705 * At a high level, the processor can be in one of two states: 706 * - With an active buffer: This indicates that a buffer has been acquired using 707 * `get_buffer` and encoded data can be written to it. 708 * - Without an active buffer: In this state, no data can be written. A new 709 * buffer must be acquired after releasing any previously active buffer. 710 * 711 * The library will not acquire more than one buffer at a given time. 712 * 713 * The state of the processor includes `position` and `finalized position`, 714 * which have the following meaning. 715 * 716 * - position: Represents the current position, in bytes, within the output 717 * stream where the encoded data will be written next. This position moves 718 * forward with each `release_buffer` call as data is written, and can also be 719 * adjusted through the optional seek callback, if provided. At this position 720 * the next write will occur. 721 * 722 * - finalized position: A position in the output stream that ensures all bytes 723 * before this point are finalized and won't be changed by later writes. 724 * 725 * All fields but `seek` are required, `seek` is optional and can be NULL. 726 */ 727 struct JxlEncoderOutputProcessor { 728 /** 729 * Required. 730 * An opaque pointer that the client can use to store custom data. 731 * This data will be passed to the associated callback functions. 732 */ 733 void* opaque; 734 735 /** 736 * Required. 737 * Acquires a buffer at the current position into which the library will write 738 * the output data. 739 * 740 * If the `size` argument points to 0 and the returned value is NULL, this 741 * will be interpreted as asking the output writing to stop. In such a case, 742 * the library will return an error. The client is expected to set the size of 743 * the returned buffer based on the suggested `size` when this function is 744 * called. 745 * 746 * @param opaque user supplied parameters to the callback 747 * @param size points to a suggested buffer size when called; must be set to 748 * the size of the returned buffer once the function returns. 749 * @return a pointer to the acquired buffer or NULL to indicate a stop 750 * condition. 751 */ 752 void* (*get_buffer)(void* opaque, size_t* size); 753 754 /** 755 * Required. 756 * Notifies the user of library that the current buffer's data has been 757 * written and can be released. This function should advance the current 758 * position of the buffer by `written_bytes` number of bytes. 759 * 760 * @param opaque user supplied parameters to the callback 761 * @param written_bytes the number of bytes written to the buffer. 762 */ 763 void (*release_buffer)(void* opaque, size_t written_bytes); 764 765 /** 766 * Optional, can be NULL 767 * Seeks to a specific position in the output. This function is optional and 768 * can be set to NULL if the output doesn't support seeking. Can only be done 769 * when there is no buffer. Cannot be used to seek before the finalized 770 * position. 771 * 772 * @param opaque user supplied parameters to the callback 773 * @param position the position to seek to, in bytes. 774 */ 775 void (*seek)(void* opaque, uint64_t position); 776 777 /** 778 * Required. 779 * Sets a finalized position on the output data, at a specific position. 780 * Seeking will never request a position before the finalized position. 781 * 782 * Will only be called if there is no active buffer. 783 * 784 * @param opaque user supplied parameters to the callback 785 * @param finalized_position the position, in bytes, where the finalized 786 * position should be set. 787 */ 788 void (*set_finalized_position)(void* opaque, uint64_t finalized_position); 789 }; 790 791 /** 792 * Sets the output processor for the encoder. This processor determines how the 793 * encoder will handle buffering, writing, seeking (if supported), and 794 * setting a finalized position during the encoding process. 795 * 796 * This should not be used when using @ref JxlEncoderProcessOutput. 797 * 798 * @param enc encoder object. 799 * @param output_processor the struct containing the callbacks for managing 800 * output. 801 * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error. 802 */ 803 JXL_EXPORT JxlEncoderStatus JxlEncoderSetOutputProcessor( 804 JxlEncoder* enc, struct JxlEncoderOutputProcessor output_processor); 805 806 /** 807 * Flushes any buffered input in the encoder, ensuring that all available input 808 * data has been processed and written to the output. 809 * 810 * This function can only be used after @ref JxlEncoderSetOutputProcessor. 811 * Before making the last call to @ref JxlEncoderFlushInput, users should call 812 * @ref JxlEncoderCloseInput to signal the end of input data. 813 * 814 * This should not be used when using @ref JxlEncoderProcessOutput. 815 * 816 * @param enc encoder object. 817 * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error. 818 */ 819 JXL_EXPORT JxlEncoderStatus JxlEncoderFlushInput(JxlEncoder* enc); 820 821 /** 822 * This struct provides callback functions to pass pixel data in a streaming 823 * manner instead of requiring the entire frame data in memory at once. 824 */ 825 struct JxlChunkedFrameInputSource { 826 /** 827 * A pointer to any user-defined data or state. This can be used to pass 828 * information to the callback functions. 829 */ 830 void* opaque; 831 832 /** 833 * Get the pixel format that color channel data will be provided in. 834 * When called, `pixel_format` points to a suggested pixel format; if 835 * color channel data can be given in this pixel format, processing might 836 * be more efficient. 837 * 838 * This function will be called exactly once, before any call to 839 * get_color_channel_at. 840 * 841 * @param opaque user supplied parameters to the callback 842 * @param pixel_format format for pixels 843 */ 844 void (*get_color_channels_pixel_format)(void* opaque, 845 JxlPixelFormat* pixel_format); 846 847 /** 848 * Callback to retrieve a rectangle of color channel data at a specific 849 * location. It is guaranteed that xpos and ypos are multiples of 8. xsize, 850 * ysize will be multiples of 8, unless the resulting rectangle would be out 851 * of image bounds. Moreover, xsize and ysize will be at most 2048. The 852 * returned data will be assumed to be in the format returned by the 853 * (preceding) call to get_color_channels_pixel_format, except the `align` 854 * parameter of the pixel format will be ignored. Instead, the `i`-th row will 855 * be assumed to start at position `return_value + i * *row_offset`, with the 856 * value of `*row_offset` decided by the callee. 857 * 858 * Note that multiple calls to `get_color_channel_data_at` may happen before a 859 * call to `release_buffer`. 860 * 861 * @param opaque user supplied parameters to the callback 862 * @param xpos horizontal position for the data. 863 * @param ypos vertical position for the data. 864 * @param xsize horizontal size of the requested rectangle of data. 865 * @param ysize vertical size of the requested rectangle of data. 866 * @param row_offset pointer to a the byte offset between consecutive rows of 867 * the retrieved pixel data. 868 * @return pointer to the retrieved pixel data. 869 */ 870 const void* (*get_color_channel_data_at)(void* opaque, size_t xpos, 871 size_t ypos, size_t xsize, 872 size_t ysize, size_t* row_offset); 873 874 /** 875 * Get the pixel format that extra channel data will be provided in. 876 * When called, `pixel_format` points to a suggested pixel format; if 877 * extra channel data can be given in this pixel format, processing might 878 * be more efficient. 879 * 880 * This function will be called exactly once per index, before any call to 881 * get_extra_channel_data_at with that given index. 882 * 883 * @param opaque user supplied parameters to the callback 884 * @param ec_index zero-indexed index of the extra channel 885 * @param pixel_format format for extra channel data 886 */ 887 void (*get_extra_channel_pixel_format)(void* opaque, size_t ec_index, 888 JxlPixelFormat* pixel_format); 889 890 /** 891 * Callback to retrieve a rectangle of extra channel `ec_index` data at a 892 * specific location. It is guaranteed that xpos and ypos are multiples of 893 * 8. xsize, ysize will be multiples of 8, unless the resulting rectangle 894 * would be out of image bounds. Moreover, xsize and ysize will be at most 895 * 2048. The returned data will be assumed to be in the format returned by the 896 * (preceding) call to get_extra_channels_pixel_format_at with the 897 * corresponding extra channel index `ec_index`, except the `align` parameter 898 * of the pixel format will be ignored. Instead, the `i`-th row will be 899 * assumed to start at position `return_value + i * *row_offset`, with the 900 * value of `*row_offset` decided by the callee. 901 * 902 * Note that multiple calls to `get_extra_channel_data_at` may happen before a 903 * call to `release_buffer`. 904 * 905 * @param opaque user supplied parameters to the callback 906 * @param xpos horizontal position for the data. 907 * @param ypos vertical position for the data. 908 * @param xsize horizontal size of the requested rectangle of data. 909 * @param ysize vertical size of the requested rectangle of data. 910 * @param row_offset pointer to a the byte offset between consecutive rows of 911 * the retrieved pixel data. 912 * @return pointer to the retrieved pixel data. 913 */ 914 const void* (*get_extra_channel_data_at)(void* opaque, size_t ec_index, 915 size_t xpos, size_t ypos, 916 size_t xsize, size_t ysize, 917 size_t* row_offset); 918 919 /** 920 * Releases the buffer `buf` (obtained through a call to 921 * `get_color_channel_data_at` or `get_extra_channel_data_at`). This function 922 * will be called exactly once per call to `get_color_channel_data_at` or 923 * `get_extra_channel_data_at`. 924 * 925 * @param opaque user supplied parameters to the callback 926 * @param buf pointer returned by `get_color_channel_data_at` or 927 * `get_extra_channel_data_at` 928 */ 929 void (*release_buffer)(void* opaque, const void* buf); 930 }; 931 932 /** 933 * @brief Adds a frame to the encoder using a chunked input source. 934 * 935 * This function gives a way to encode a frame by providing pixel data in a 936 * chunked or streaming manner, which can be especially useful when dealing with 937 * large images that may not fit entirely in memory or when trying to optimize 938 * memory usage. The input data is provided through callbacks defined in the 939 * @ref JxlChunkedFrameInputSource struct. Once the frame data has been 940 * completely retrieved, this function will flush the input and close it if it 941 * is the last frame. 942 * 943 * @param frame_settings set of options and metadata for this frame. Also 944 * includes reference to the encoder object. 945 * @param is_last_frame indicates if this is the last frame. 946 * @param chunked_frame_input struct providing callback methods for retrieving 947 * pixel data in chunks. 948 * 949 * @return Returns a status indicating the success or failure of adding the 950 * frame. 951 */ 952 JXL_EXPORT JxlEncoderStatus JxlEncoderAddChunkedFrame( 953 const JxlEncoderFrameSettings* frame_settings, JXL_BOOL is_last_frame, 954 struct JxlChunkedFrameInputSource chunked_frame_input); 955 956 /** 957 * Sets the buffer to read pixels from for an extra channel at a given index. 958 * The index must be smaller than the num_extra_channels in the associated 959 * @ref JxlBasicInfo. Must call @ref JxlEncoderSetExtraChannelInfo before @ref 960 * JxlEncoderSetExtraChannelBuffer. 961 * 962 * TODO(firsching): mention what data types in pixel formats are supported. 963 * 964 * It is required to call this function for every extra channel, except for the 965 * alpha channel if that was already set through @ref JxlEncoderAddImageFrame. 966 * 967 * @param frame_settings set of options and metadata for this frame. Also 968 * includes reference to the encoder object. 969 * @param pixel_format format for pixels. Object owned by the caller and its 970 * contents are copied internally. The num_channels value is ignored, since the 971 * number of channels for an extra channel is always assumed to be one. 972 * @param buffer buffer type to input the pixel data from. Owned by the caller 973 * and its contents are copied internally. 974 * @param size size of buffer in bytes. This size should match what is implied 975 * by the frame dimensions and the pixel format. 976 * @param index index of the extra channel to use. 977 * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error 978 */ 979 JXL_EXPORT JxlEncoderStatus JxlEncoderSetExtraChannelBuffer( 980 const JxlEncoderFrameSettings* frame_settings, 981 const JxlPixelFormat* pixel_format, const void* buffer, size_t size, 982 uint32_t index); 983 984 /** Adds a metadata box to the file format. @ref JxlEncoderProcessOutput must be 985 * used to effectively write the box to the output. @ref JxlEncoderUseBoxes must 986 * be enabled before using this function. 987 * 988 * Boxes allow inserting application-specific data and metadata (Exif, XML/XMP, 989 * JUMBF and user defined boxes). 990 * 991 * The box format follows ISO BMFF and shares features and box types with other 992 * image and video formats, including the Exif, XML and JUMBF boxes. The box 993 * format for JPEG XL is specified in ISO/IEC 18181-2. 994 * 995 * Boxes in general don't contain other boxes inside, except a JUMBF superbox. 996 * Boxes follow each other sequentially and are byte-aligned. If the container 997 * format is used, the JXL stream consists of concatenated boxes. 998 * It is also possible to use a direct codestream without boxes, but in that 999 * case metadata cannot be added. 1000 * 1001 * Each box generally has the following byte structure in the file: 1002 * - 4 bytes: box size including box header (Big endian. If set to 0, an 1003 * 8-byte 64-bit size follows instead). 1004 * - 4 bytes: type, e.g. "JXL " for the signature box, "jxlc" for a codestream 1005 * box. 1006 * - N bytes: box contents. 1007 * 1008 * Only the box contents are provided to the contents argument of this function, 1009 * the encoder encodes the size header itself. Most boxes are written 1010 * automatically by the encoder as needed ("JXL ", "ftyp", "jxll", "jxlc", 1011 * "jxlp", "jxli", "jbrd"), and this function only needs to be called to add 1012 * optional metadata when encoding from pixels (using @ref 1013 * JxlEncoderAddImageFrame). When recompressing JPEG files (using @ref 1014 * JxlEncoderAddJPEGFrame), if the input JPEG contains EXIF, XMP or JUMBF 1015 * metadata, the corresponding boxes are already added automatically. 1016 * 1017 * Box types are given by 4 characters. The following boxes can be added with 1018 * this function: 1019 * - "Exif": a box with EXIF metadata, can be added by libjxl users, or is 1020 * automatically added when needed for JPEG reconstruction. The contents of 1021 * this box must be prepended by a 4-byte tiff header offset, which may 1022 * be 4 zero bytes in case the tiff header follows immediately. 1023 * The EXIF metadata must be in sync with what is encoded in the JPEG XL 1024 * codestream, specifically the image orientation. While this is not 1025 * recommended in practice, in case of conflicting metadata, the JPEG XL 1026 * codestream takes precedence. 1027 * - "xml ": a box with XML data, in particular XMP metadata, can be added by 1028 * libjxl users, or is automatically added when needed for JPEG reconstruction 1029 * - "jumb": a JUMBF superbox, which can contain boxes with different types of 1030 * metadata inside. This box type can be added by the encoder transparently, 1031 * and other libraries to create and handle JUMBF content exist. 1032 * - Application-specific boxes. Their typename should not begin with "jxl" or 1033 * "JXL" or conflict with other existing typenames, and they should be 1034 * registered with MP4RA (mp4ra.org). 1035 * 1036 * These boxes can be stored uncompressed or Brotli-compressed (using a "brob" 1037 * box), depending on the compress_box parameter. 1038 * 1039 * @param enc encoder object. 1040 * @param type the box type, e.g. "Exif" for EXIF metadata, "xml " for XMP or 1041 * IPTC metadata, "jumb" for JUMBF metadata. 1042 * @param contents the full contents of the box, for example EXIF 1043 * data. ISO BMFF box header must not be included, only the contents. Owned by 1044 * the caller and its contents are copied internally. 1045 * @param size size of the box contents. 1046 * @param compress_box Whether to compress this box as a "brob" box. Requires 1047 * Brotli support. 1048 * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error, such as 1049 * when using this function without @ref JxlEncoderUseContainer, or adding a box 1050 * type that would result in an invalid file format. 1051 */ 1052 JXL_EXPORT JxlEncoderStatus JxlEncoderAddBox(JxlEncoder* enc, 1053 const JxlBoxType type, 1054 const uint8_t* contents, 1055 size_t size, 1056 JXL_BOOL compress_box); 1057 1058 /** 1059 * Indicates the intention to add metadata boxes. This allows @ref 1060 * JxlEncoderAddBox to be used. When using this function, then it is required 1061 * to use @ref JxlEncoderCloseBoxes at the end. 1062 * 1063 * By default the encoder assumes no metadata boxes will be added. 1064 * 1065 * This setting can only be set at the beginning, before encoding starts. 1066 * 1067 * @param enc encoder object. 1068 */ 1069 JXL_EXPORT JxlEncoderStatus JxlEncoderUseBoxes(JxlEncoder* enc); 1070 1071 /** 1072 * Declares that no further boxes will be added with @ref JxlEncoderAddBox. 1073 * This function must be called after the last box is added so the encoder knows 1074 * the stream will be finished. It is not necessary to use this function if 1075 * @ref JxlEncoderUseBoxes is not used. Further frames may still be added. 1076 * 1077 * Must be called between @ref JxlEncoderAddBox of the last box 1078 * and the next call to @ref JxlEncoderProcessOutput, or @ref 1079 * JxlEncoderProcessOutput won't output the last box correctly. 1080 * 1081 * NOTE: if you don't need to close frames and boxes at separate times, you can 1082 * use @ref JxlEncoderCloseInput instead to close both at once. 1083 * 1084 * @param enc encoder object. 1085 */ 1086 JXL_EXPORT void JxlEncoderCloseBoxes(JxlEncoder* enc); 1087 1088 /** 1089 * Declares that no frames will be added and @ref JxlEncoderAddImageFrame and 1090 * @ref JxlEncoderAddJPEGFrame won't be called anymore. Further metadata boxes 1091 * may still be added. This function or @ref JxlEncoderCloseInput must be called 1092 * after adding the last frame and the next call to 1093 * @ref JxlEncoderProcessOutput, or the frame won't be properly marked as last. 1094 * 1095 * NOTE: if you don't need to close frames and boxes at separate times, you can 1096 * use @ref JxlEncoderCloseInput instead to close both at once. 1097 * 1098 * @param enc encoder object. 1099 */ 1100 JXL_EXPORT void JxlEncoderCloseFrames(JxlEncoder* enc); 1101 1102 /** 1103 * Closes any input to the encoder, equivalent to calling @ref 1104 * JxlEncoderCloseFrames as well as calling @ref JxlEncoderCloseBoxes if needed. 1105 * No further input of any kind may be given to the encoder, but further @ref 1106 * JxlEncoderProcessOutput calls should be done to create the final output. 1107 * 1108 * The requirements of both @ref JxlEncoderCloseFrames and @ref 1109 * JxlEncoderCloseBoxes apply to this function. Either this function or the 1110 * other two must be called after the final frame and/or box, and the next 1111 * @ref JxlEncoderProcessOutput call, or the codestream won't be encoded 1112 * correctly. 1113 * 1114 * @param enc encoder object. 1115 */ 1116 JXL_EXPORT void JxlEncoderCloseInput(JxlEncoder* enc); 1117 1118 /** 1119 * Sets the original color encoding of the image encoded by this encoder. This 1120 * is an alternative to @ref JxlEncoderSetICCProfile and only one of these two 1121 * must be used. This one sets the color encoding as a @ref JxlColorEncoding, 1122 * while the other sets it as ICC binary data. Must be called after @ref 1123 * JxlEncoderSetBasicInfo. 1124 * 1125 * @param enc encoder object. 1126 * @param color color encoding. Object owned by the caller and its contents are 1127 * copied internally. 1128 * @return ::JXL_ENC_SUCCESS if the operation was successful, @ref 1129 * JXL_ENC_ERROR otherwise 1130 */ 1131 JXL_EXPORT JxlEncoderStatus 1132 JxlEncoderSetColorEncoding(JxlEncoder* enc, const JxlColorEncoding* color); 1133 1134 /** 1135 * Sets the original color encoding of the image encoded by this encoder as an 1136 * ICC color profile. This is an alternative to @ref JxlEncoderSetColorEncoding 1137 * and only one of these two must be used. This one sets the color encoding as 1138 * ICC binary data, while the other defines it as a @ref JxlColorEncoding. Must 1139 * be called after @ref JxlEncoderSetBasicInfo. 1140 * 1141 * @param enc encoder object. 1142 * @param icc_profile bytes of the original ICC profile 1143 * @param size size of the icc_profile buffer in bytes 1144 * @return ::JXL_ENC_SUCCESS if the operation was successful, @ref 1145 * JXL_ENC_ERROR otherwise 1146 */ 1147 JXL_EXPORT JxlEncoderStatus JxlEncoderSetICCProfile(JxlEncoder* enc, 1148 const uint8_t* icc_profile, 1149 size_t size); 1150 1151 /** 1152 * Initializes a @ref JxlBasicInfo struct to default values. 1153 * For forwards-compatibility, this function has to be called before values 1154 * are assigned to the struct fields. 1155 * The default values correspond to an 8-bit RGB image, no alpha or any 1156 * other extra channels. 1157 * 1158 * @param info global image metadata. Object owned by the caller. 1159 */ 1160 JXL_EXPORT void JxlEncoderInitBasicInfo(JxlBasicInfo* info); 1161 1162 /** 1163 * Initializes a @ref JxlFrameHeader struct to default values. 1164 * For forwards-compatibility, this function has to be called before values 1165 * are assigned to the struct fields. 1166 * The default values correspond to a frame with no animation duration and the 1167 * 'replace' blend mode. After using this function, For animation duration must 1168 * be set, for composite still blend settings must be set. 1169 * 1170 * @param frame_header frame metadata. Object owned by the caller. 1171 */ 1172 JXL_EXPORT void JxlEncoderInitFrameHeader(JxlFrameHeader* frame_header); 1173 1174 /** 1175 * Initializes a @ref JxlBlendInfo struct to default values. 1176 * For forwards-compatibility, this function has to be called before values 1177 * are assigned to the struct fields. 1178 * 1179 * @param blend_info blending info. Object owned by the caller. 1180 */ 1181 JXL_EXPORT void JxlEncoderInitBlendInfo(JxlBlendInfo* blend_info); 1182 1183 /** 1184 * Sets the global metadata of the image encoded by this encoder. 1185 * 1186 * If the @ref JxlBasicInfo contains information of extra channels beyond an 1187 * alpha channel, then @ref JxlEncoderSetExtraChannelInfo must be called between 1188 * @ref JxlEncoderSetBasicInfo and @ref JxlEncoderAddImageFrame. In order to 1189 * indicate extra channels, the value of `info.num_extra_channels` should be set 1190 * to the number of extra channels, also counting the alpha channel if present. 1191 * 1192 * @param enc encoder object. 1193 * @param info global image metadata. Object owned by the caller and its 1194 * contents are copied internally. 1195 * @return ::JXL_ENC_SUCCESS if the operation was successful, 1196 * ::JXL_ENC_ERROR otherwise 1197 */ 1198 JXL_EXPORT JxlEncoderStatus JxlEncoderSetBasicInfo(JxlEncoder* enc, 1199 const JxlBasicInfo* info); 1200 1201 /** 1202 * Sets the upsampling method the decoder will use in case there are frames 1203 * with ::JXL_ENC_FRAME_SETTING_RESAMPLING set. This is useful in combination 1204 * with the ::JXL_ENC_FRAME_SETTING_ALREADY_DOWNSAMPLED option, to control 1205 * the type of upsampling that will be used. 1206 * 1207 * @param enc encoder object. 1208 * @param factor upsampling factor to configure (1, 2, 4 or 8; for 1 this 1209 * function has no effect at all) 1210 * @param mode upsampling mode to use for this upsampling: 1211 * -1: default (good for photographic images, no signaling overhead) 1212 * 0: nearest neighbor (good for pixel art) 1213 * 1: 'pixel dots' (same as NN for 2x, diamond-shaped 'pixel dots' for 4x/8x) 1214 * @return ::JXL_ENC_SUCCESS if the operation was successful, 1215 * ::JXL_ENC_ERROR otherwise 1216 */ 1217 JXL_EXPORT JxlEncoderStatus JxlEncoderSetUpsamplingMode(JxlEncoder* enc, 1218 int64_t factor, 1219 int64_t mode); 1220 1221 /** 1222 * Initializes a @ref JxlExtraChannelInfo struct to default values. 1223 * For forwards-compatibility, this function has to be called before values 1224 * are assigned to the struct fields. 1225 * The default values correspond to an 8-bit channel of the provided type. 1226 * 1227 * @param type type of the extra channel. 1228 * @param info global extra channel metadata. Object owned by the caller and its 1229 * contents are copied internally. 1230 */ 1231 JXL_EXPORT void JxlEncoderInitExtraChannelInfo(JxlExtraChannelType type, 1232 JxlExtraChannelInfo* info); 1233 1234 /** 1235 * Sets information for the extra channel at the given index. The index 1236 * must be smaller than num_extra_channels in the associated @ref JxlBasicInfo. 1237 * 1238 * @param enc encoder object 1239 * @param index index of the extra channel to set. 1240 * @param info global extra channel metadata. Object owned by the caller and its 1241 * contents are copied internally. 1242 * @return ::JXL_ENC_SUCCESS on success, ::JXL_ENC_ERROR on error 1243 */ 1244 JXL_EXPORT JxlEncoderStatus JxlEncoderSetExtraChannelInfo( 1245 JxlEncoder* enc, size_t index, const JxlExtraChannelInfo* info); 1246 1247 /** 1248 * Sets the name for the extra channel at the given index in UTF-8. The index 1249 * must be smaller than the num_extra_channels in the associated @ref 1250 * JxlBasicInfo. 1251 * 1252 * TODO(lode): remove size parameter for consistency with 1253 * @ref JxlEncoderSetFrameName 1254 * 1255 * @param enc encoder object 1256 * @param index index of the extra channel to set. 1257 * @param name buffer with the name of the extra channel. 1258 * @param size size of the name buffer in bytes, not counting the terminating 1259 * character. 1260 * @return JXL_ENC_SUCCESS on success, JXL_ENC_ERROR on error 1261 */ 1262 JXL_EXPORT JxlEncoderStatus JxlEncoderSetExtraChannelName(JxlEncoder* enc, 1263 size_t index, 1264 const char* name, 1265 size_t size); 1266 1267 /** 1268 * Sets a frame-specific option of integer type to the encoder options. 1269 * The @ref JxlEncoderFrameSettingId argument determines which option is set. 1270 * 1271 * @param frame_settings set of options and metadata for this frame. Also 1272 * includes reference to the encoder object. 1273 * @param option ID of the option to set. 1274 * @param value Integer value to set for this option. 1275 * @return ::JXL_ENC_SUCCESS if the operation was successful, @ref 1276 * JXL_ENC_ERROR in case of an error, such as invalid or unknown option id, or 1277 * invalid integer value for the given option. If an error is returned, the 1278 * state of the 1279 * @ref JxlEncoderFrameSettings object is still valid and is the same as before 1280 * this function was called. 1281 */ 1282 JXL_EXPORT JxlEncoderStatus JxlEncoderFrameSettingsSetOption( 1283 JxlEncoderFrameSettings* frame_settings, JxlEncoderFrameSettingId option, 1284 int64_t value); 1285 1286 /** 1287 * Sets a frame-specific option of float type to the encoder options. 1288 * The @ref JxlEncoderFrameSettingId argument determines which option is set. 1289 * 1290 * @param frame_settings set of options and metadata for this frame. Also 1291 * includes reference to the encoder object. 1292 * @param option ID of the option to set. 1293 * @param value Float value to set for this option. 1294 * @return ::JXL_ENC_SUCCESS if the operation was successful, @ref 1295 * JXL_ENC_ERROR in case of an error, such as invalid or unknown option id, or 1296 * invalid integer value for the given option. If an error is returned, the 1297 * state of the 1298 * @ref JxlEncoderFrameSettings object is still valid and is the same as before 1299 * this function was called. 1300 */ 1301 JXL_EXPORT JxlEncoderStatus JxlEncoderFrameSettingsSetFloatOption( 1302 JxlEncoderFrameSettings* frame_settings, JxlEncoderFrameSettingId option, 1303 float value); 1304 1305 /** Forces the encoder to use the box-based container format (BMFF) even 1306 * when not necessary. 1307 * 1308 * When using @ref JxlEncoderUseBoxes, @ref JxlEncoderStoreJPEGMetadata or @ref 1309 * JxlEncoderSetCodestreamLevel with level 10, the encoder will automatically 1310 * also use the container format, it is not necessary to use 1311 * @ref JxlEncoderUseContainer for those use cases. 1312 * 1313 * By default this setting is disabled. 1314 * 1315 * This setting can only be set at the beginning, before encoding starts. 1316 * 1317 * @param enc encoder object. 1318 * @param use_container true if the encoder should always output the JPEG XL 1319 * container format, false to only output it when necessary. 1320 * @return JXL_ENC_SUCCESS if the operation was successful, JXL_ENC_ERROR 1321 * otherwise. 1322 */ 1323 JXL_EXPORT JxlEncoderStatus JxlEncoderUseContainer(JxlEncoder* enc, 1324 JXL_BOOL use_container); 1325 1326 /** 1327 * Configure the encoder to store JPEG reconstruction metadata in the JPEG XL 1328 * container. 1329 * 1330 * If this is set to true and a single JPEG frame is added, it will be 1331 * possible to losslessly reconstruct the JPEG codestream. 1332 * 1333 * This setting can only be set at the beginning, before encoding starts. 1334 * 1335 * @param enc encoder object. 1336 * @param store_jpeg_metadata true if the encoder should store JPEG metadata. 1337 * @return ::JXL_ENC_SUCCESS if the operation was successful, @ref 1338 * JXL_ENC_ERROR otherwise. 1339 */ 1340 JXL_EXPORT JxlEncoderStatus 1341 JxlEncoderStoreJPEGMetadata(JxlEncoder* enc, JXL_BOOL store_jpeg_metadata); 1342 1343 /** Sets the feature level of the JPEG XL codestream. Valid values are 5 and 1344 * 10, or -1 (to choose automatically). Using the minimum required level, or 1345 * level 5 in most cases, is recommended for compatibility with all decoders. 1346 * 1347 * Level 5: for end-user image delivery, this level is the most widely 1348 * supported level by image decoders and the recommended level to use unless a 1349 * level 10 feature is absolutely necessary. Supports a maximum resolution 1350 * 268435456 pixels total with a maximum width or height of 262144 pixels, 1351 * maximum 16-bit color channel depth, maximum 120 frames per second for 1352 * animation, maximum ICC color profile size of 4 MiB, it allows all color 1353 * models and extra channel types except CMYK and the JXL_CHANNEL_BLACK 1354 * extra channel, and a maximum of 4 extra channels in addition to the 3 color 1355 * channels. It also sets boundaries to certain internally used coding tools. 1356 * 1357 * Level 10: this level removes or increases the bounds of most of the level 1358 * 5 limitations, allows CMYK color and up to 32 bits per color channel, but 1359 * may be less widely supported. 1360 * 1361 * The default value is -1. This means the encoder will automatically choose 1362 * between level 5 and level 10 based on what information is inside the @ref 1363 * JxlBasicInfo structure. Do note that some level 10 features, particularly 1364 * those used by animated JPEG XL codestreams, might require level 10, even 1365 * though the @ref JxlBasicInfo only suggests level 5. In this case, the level 1366 * must be explicitly set to 10, otherwise the encoder will return an error. 1367 * The encoder will restrict internal encoding choices to those compatible with 1368 * the level setting. 1369 * 1370 * This setting can only be set at the beginning, before encoding starts. 1371 * 1372 * @param enc encoder object. 1373 * @param level the level value to set, must be -1, 5, or 10. 1374 * @return ::JXL_ENC_SUCCESS if the operation was successful, @ref 1375 * JXL_ENC_ERROR otherwise. 1376 */ 1377 JXL_EXPORT JxlEncoderStatus JxlEncoderSetCodestreamLevel(JxlEncoder* enc, 1378 int level); 1379 1380 /** Returns the codestream level required to support the currently configured 1381 * settings and basic info. This function can only be used at the beginning, 1382 * before encoding starts, but after setting basic info. 1383 * 1384 * This does not support per-frame settings, only global configuration, such as 1385 * the image dimensions, that are known at the time of writing the header of 1386 * the JPEG XL file. 1387 * 1388 * If this returns 5, nothing needs to be done and the codestream can be 1389 * compatible with any decoder. If this returns 10, @ref 1390 * JxlEncoderSetCodestreamLevel has to be used to set the codestream level to 1391 * 10, or the encoder can be configured differently to allow using the more 1392 * compatible level 5. 1393 * 1394 * @param enc encoder object. 1395 * @return -1 if no level can support the configuration (e.g. image dimensions 1396 * larger than even level 10 supports), 5 if level 5 is supported, 10 if setting 1397 * the codestream level to 10 is required. 1398 * 1399 */ 1400 JXL_EXPORT int JxlEncoderGetRequiredCodestreamLevel(const JxlEncoder* enc); 1401 1402 /** 1403 * Enables lossless encoding. 1404 * 1405 * This is not an option like the others on itself, but rather while enabled it 1406 * overrides a set of existing options (such as distance, modular mode and 1407 * color transform) that enables bit-for-bit lossless encoding. 1408 * 1409 * When disabled, those options are not overridden, but since those options 1410 * could still have been manually set to a combination that operates losslessly, 1411 * using this function with lossless set to ::JXL_FALSE does not 1412 * guarantee lossy encoding, though the default set of options is lossy. 1413 * 1414 * @param frame_settings set of options and metadata for this frame. Also 1415 * includes reference to the encoder object. 1416 * @param lossless whether to override options for lossless mode 1417 * @return ::JXL_ENC_SUCCESS if the operation was successful, @ref 1418 * JXL_ENC_ERROR otherwise. 1419 */ 1420 JXL_EXPORT JxlEncoderStatus JxlEncoderSetFrameLossless( 1421 JxlEncoderFrameSettings* frame_settings, JXL_BOOL lossless); 1422 1423 /** 1424 * Sets the distance level for lossy compression: target max butteraugli 1425 * distance, lower = higher quality. Range: 0 .. 25. 1426 * 0.0 = mathematically lossless (however, use @ref JxlEncoderSetFrameLossless 1427 * instead to use true lossless, as setting distance to 0 alone is not the only 1428 * requirement). 1.0 = visually lossless. Recommended range: 0.5 .. 3.0. Default 1429 * value: 1.0. 1430 * 1431 * @param frame_settings set of options and metadata for this frame. Also 1432 * includes reference to the encoder object. 1433 * @param distance the distance value to set. 1434 * @return ::JXL_ENC_SUCCESS if the operation was successful, @ref 1435 * JXL_ENC_ERROR otherwise. 1436 */ 1437 JXL_EXPORT JxlEncoderStatus JxlEncoderSetFrameDistance( 1438 JxlEncoderFrameSettings* frame_settings, float distance); 1439 1440 /** 1441 * Sets the distance level for lossy compression of extra channels. 1442 * The distance is as in @ref JxlEncoderSetFrameDistance (lower = higher 1443 * quality). If not set, or if set to the special value -1, the distance that 1444 * was set with 1445 * @ref JxlEncoderSetFrameDistance will be used. 1446 * 1447 * @param frame_settings set of options and metadata for this frame. Also 1448 * includes reference to the encoder object. 1449 * @param index index of the extra channel to set a distance value for. 1450 * @param distance the distance value to set. 1451 * @return ::JXL_ENC_SUCCESS if the operation was successful, @ref 1452 * JXL_ENC_ERROR otherwise. 1453 */ 1454 JXL_EXPORT JxlEncoderStatus JxlEncoderSetExtraChannelDistance( 1455 JxlEncoderFrameSettings* frame_settings, size_t index, float distance); 1456 1457 /** 1458 * Maps JPEG-style quality factor to distance. 1459 * 1460 * This function takes in input a JPEG-style quality factor `quality` and 1461 * produces as output a `distance` value suitable to be used with @ref 1462 * JxlEncoderSetFrameDistance and @ref JxlEncoderSetExtraChannelDistance. 1463 * 1464 * The `distance` value influences the level of compression, with lower values 1465 * indicating higher quality: 1466 * - 0.0 implies lossless compression (however, note that calling @ref 1467 * JxlEncoderSetFrameLossless is required). 1468 * - 1.0 represents a visually lossy compression, which is also the default 1469 * setting. 1470 * 1471 * The `quality` parameter, ranging up to 100, is inversely related to 1472 * 'distance': 1473 * - A `quality` of 100.0 maps to a `distance` of 0.0 (lossless). 1474 * - A `quality` of 90.0 corresponds to a `distance` of 1.0. 1475 * 1476 * Recommended Range: 1477 * - `distance`: 0.5 to 3.0. 1478 * - corresponding `quality`: approximately 96 to 68. 1479 * 1480 * Allowed Range: 1481 * - `distance`: 0.0 to 25.0. 1482 * - corresponding `quality`: 100.0 to 0.0. 1483 * 1484 * Note: the `quality` parameter has no consistent psychovisual meaning 1485 * across different codecs and libraries. Using the mapping defined by @ref 1486 * JxlEncoderDistanceFromQuality will result in a visual quality roughly 1487 * equivalent to what would be obtained with `libjpeg-turbo` with the same 1488 * `quality` parameter, but that is by no means guaranteed; do not assume that 1489 * the same quality value will result in similar file sizes and image quality 1490 * across different codecs. 1491 */ 1492 JXL_EXPORT float JxlEncoderDistanceFromQuality(float quality); 1493 1494 /** 1495 * Create a new set of encoder options, with all values initially copied from 1496 * the @p source options, or set to default if @p source is NULL. 1497 * 1498 * The returned pointer is an opaque struct tied to the encoder and it will be 1499 * deallocated by the encoder when @ref JxlEncoderDestroy() is called. For 1500 * functions taking both a @ref JxlEncoder and a @ref JxlEncoderFrameSettings, 1501 * only @ref JxlEncoderFrameSettings created with this function for the same 1502 * encoder instance can be used. 1503 * 1504 * @param enc encoder object. 1505 * @param source source options to copy initial values from, or NULL to get 1506 * defaults initialized to defaults. 1507 * @return the opaque struct pointer identifying a new set of encoder options. 1508 */ 1509 JXL_EXPORT JxlEncoderFrameSettings* JxlEncoderFrameSettingsCreate( 1510 JxlEncoder* enc, const JxlEncoderFrameSettings* source); 1511 1512 /** 1513 * Sets a color encoding to be sRGB. 1514 * 1515 * @param color_encoding color encoding instance. 1516 * @param is_gray whether the color encoding should be gray scale or color. 1517 */ 1518 JXL_EXPORT void JxlColorEncodingSetToSRGB(JxlColorEncoding* color_encoding, 1519 JXL_BOOL is_gray); 1520 1521 /** 1522 * Sets a color encoding to be linear sRGB. 1523 * 1524 * @param color_encoding color encoding instance. 1525 * @param is_gray whether the color encoding should be gray scale or color. 1526 */ 1527 JXL_EXPORT void JxlColorEncodingSetToLinearSRGB( 1528 JxlColorEncoding* color_encoding, JXL_BOOL is_gray); 1529 1530 /** 1531 * Enables usage of expert options. 1532 * 1533 * At the moment, the only expert option is setting an effort value of 11, 1534 * which gives the best compression for pixel-lossless modes but is very slow. 1535 * 1536 * @param enc encoder object. 1537 */ 1538 JXL_EXPORT void JxlEncoderAllowExpertOptions(JxlEncoder* enc); 1539 1540 /** 1541 * Function type for @ref JxlEncoderSetDebugImageCallback. 1542 * 1543 * The callback may be called simultaneously by different threads when using a 1544 * threaded parallel runner, on different debug images. 1545 * 1546 * @param opaque optional user data, as given to @ref 1547 * JxlEncoderSetDebugImageCallback. 1548 * @param label label of debug image, can be used in filenames 1549 * @param xsize width of debug image 1550 * @param ysize height of debug image 1551 * @param color color encoding of debug image 1552 * @param pixels pixel data of debug image as big-endian 16-bit unsigned 1553 * samples. The memory is not owned by the user, and is only valid during the 1554 * time the callback is running. 1555 */ 1556 typedef void (*JxlDebugImageCallback)(void* opaque, const char* label, 1557 size_t xsize, size_t ysize, 1558 const JxlColorEncoding* color, 1559 const uint16_t* pixels); 1560 1561 /** 1562 * Sets the given debug image callback that will be used by the encoder to 1563 * output various debug images during encoding. 1564 * 1565 * This only has any effect if the encoder was compiled with the appropriate 1566 * debug build flags. 1567 * 1568 * @param frame_settings set of options and metadata for this frame. Also 1569 * includes reference to the encoder object. 1570 * @param callback used to return the debug image 1571 * @param opaque user supplied parameter to the image callback 1572 */ 1573 JXL_EXPORT void JxlEncoderSetDebugImageCallback( 1574 JxlEncoderFrameSettings* frame_settings, JxlDebugImageCallback callback, 1575 void* opaque); 1576 1577 /** 1578 * Sets the given stats object for gathering various statistics during encoding. 1579 * 1580 * This only has any effect if the encoder was compiled with the appropriate 1581 * debug build flags. 1582 * 1583 * @param frame_settings set of options and metadata for this frame. Also 1584 * includes reference to the encoder object. 1585 * @param stats object that can be used to query the gathered stats (created 1586 * by @ref JxlEncoderStatsCreate) 1587 */ 1588 JXL_EXPORT void JxlEncoderCollectStats(JxlEncoderFrameSettings* frame_settings, 1589 JxlEncoderStats* stats); 1590 1591 #if defined(__cplusplus) || defined(c_plusplus) 1592 } 1593 #endif 1594 1595 #endif /* JXL_ENCODE_H_ */ 1596 1597 /** @}*/