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