jxl.h (2239B)
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 #ifndef LIB_EXTRAS_DEC_JXL_H_ 7 #define LIB_EXTRAS_DEC_JXL_H_ 8 9 // Decodes JPEG XL images in memory. 10 11 #include <jxl/parallel_runner.h> 12 #include <jxl/types.h> 13 #include <stdint.h> 14 15 #include <limits> 16 #include <string> 17 #include <vector> 18 19 #include "lib/extras/packed_image.h" 20 21 namespace jxl { 22 namespace extras { 23 24 struct JXLDecompressParams { 25 // If empty, little endian float formats will be accepted. 26 std::vector<JxlPixelFormat> accepted_formats; 27 28 // Requested output color space description. 29 std::string color_space; 30 // If set, performs tone mapping to this intensity target luminance. 31 float display_nits = 0.0; 32 // Whether spot colors are rendered on the image. 33 bool render_spotcolors = true; 34 // Whether to keep or undo the orientation given in the header. 35 bool keep_orientation = false; 36 37 // If runner_opaque is set, the decoder uses this parallel runner. 38 JxlParallelRunner runner; 39 void* runner_opaque = nullptr; 40 41 // Whether truncated input should be treated as an error. 42 bool allow_partial_input = false; 43 44 // How many passes to decode at most. By default, decode everything. 45 uint32_t max_passes = std::numeric_limits<uint32_t>::max(); 46 47 // Alternatively, one can specify the maximum tolerable downscaling factor 48 // with respect to the full size of the image. By default, nothing less than 49 // the full size is requested. 50 size_t max_downsampling = 1; 51 52 // Whether to use the image callback or the image buffer to get the output. 53 bool use_image_callback = true; 54 // Whether to unpremultiply colors for associated alpha channels. 55 bool unpremultiply_alpha = false; 56 57 // Controls the effective bit depth of the output pixels. 58 JxlBitDepth output_bitdepth = {JXL_BIT_DEPTH_FROM_PIXEL_FORMAT, 0, 0}; 59 }; 60 61 bool DecodeImageJXL(const uint8_t* bytes, size_t bytes_size, 62 const JXLDecompressParams& dparams, size_t* decoded_bytes, 63 PackedPixelFile* ppf, 64 std::vector<uint8_t>* jpeg_bytes = nullptr); 65 66 } // namespace extras 67 } // namespace jxl 68 69 #endif // LIB_EXTRAS_DEC_JXL_H_