Bug 1919608 – Add Nathan Barrett and Maxx Crawford as New Tab Page peers. r=thecount...
[gecko.git] / third_party / jpeg-xl / lib / jpegli / encode.h
blob54ff9d1f9eec6941d6a447b4e25e117a94c05ce8
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 // This file contains the C API of the encoder part of the libjpegli library,
7 // which is based on the C API of libjpeg, with the function names changed from
8 // jpeg_* to jpegli_*, while compressor object definitions are included directly
9 // from jpeglib.h
11 // Applications can use the libjpegli library in one of the following ways:
13 // (1) Include jpegli/encode.h and/or jpegli/decode.h, update the function
14 // names of the API and link against libjpegli.
16 // (2) Leave the application code unchanged, but replace the libjpeg.so library
17 // with the one built by this project that is API- and ABI-compatible with
18 // libjpeg-turbo's version of libjpeg.so.
20 #ifndef LIB_JPEGLI_ENCODE_H_
21 #define LIB_JPEGLI_ENCODE_H_
23 #include "lib/jpegli/common.h"
24 #include "lib/jpegli/types.h"
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
30 #define jpegli_create_compress(cinfo) \
31 jpegli_CreateCompress((cinfo), JPEG_LIB_VERSION, \
32 (size_t)sizeof(struct jpeg_compress_struct))
33 void jpegli_CreateCompress(j_compress_ptr cinfo, int version,
34 size_t structsize);
36 void jpegli_stdio_dest(j_compress_ptr cinfo, FILE* outfile);
38 void jpegli_mem_dest(j_compress_ptr cinfo, unsigned char** outbuffer,
39 unsigned long* outsize /* NOLINT */);
41 void jpegli_set_defaults(j_compress_ptr cinfo);
43 void jpegli_default_colorspace(j_compress_ptr cinfo);
45 void jpegli_set_colorspace(j_compress_ptr cinfo, J_COLOR_SPACE colorspace);
47 void jpegli_set_quality(j_compress_ptr cinfo, int quality,
48 boolean force_baseline);
50 void jpegli_set_linear_quality(j_compress_ptr cinfo, int scale_factor,
51 boolean force_baseline);
53 #if JPEG_LIB_VERSION >= 70
54 void jpegli_default_qtables(j_compress_ptr cinfo, boolean force_baseline);
55 #endif
57 int jpegli_quality_scaling(int quality);
59 void jpegli_add_quant_table(j_compress_ptr cinfo, int which_tbl,
60 const unsigned int* basic_table, int scale_factor,
61 boolean force_baseline);
63 void jpegli_simple_progression(j_compress_ptr cinfo);
65 void jpegli_suppress_tables(j_compress_ptr cinfo, boolean suppress);
67 #if JPEG_LIB_VERSION >= 70
68 void jpegli_calc_jpeg_dimensions(j_compress_ptr cinfo);
69 #endif
71 void jpegli_copy_critical_parameters(j_decompress_ptr srcinfo,
72 j_compress_ptr dstinfo);
74 void jpegli_write_m_header(j_compress_ptr cinfo, int marker,
75 unsigned int datalen);
77 void jpegli_write_m_byte(j_compress_ptr cinfo, int val);
79 void jpegli_write_marker(j_compress_ptr cinfo, int marker,
80 const JOCTET* dataptr, unsigned int datalen);
82 void jpegli_write_icc_profile(j_compress_ptr cinfo, const JOCTET* icc_data_ptr,
83 unsigned int icc_data_len);
85 void jpegli_start_compress(j_compress_ptr cinfo, boolean write_all_tables);
87 void jpegli_write_tables(j_compress_ptr cinfo);
89 JDIMENSION jpegli_write_scanlines(j_compress_ptr cinfo, JSAMPARRAY scanlines,
90 JDIMENSION num_lines);
92 JDIMENSION jpegli_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data,
93 JDIMENSION num_lines);
95 void jpegli_write_coefficients(j_compress_ptr cinfo,
96 jvirt_barray_ptr* coef_arrays);
98 void jpegli_finish_compress(j_compress_ptr cinfo);
100 void jpegli_abort_compress(j_compress_ptr cinfo);
102 void jpegli_destroy_compress(j_compress_ptr cinfo);
105 // New API functions that are not available in libjpeg
107 // NOTE: This part of the API is still experimental and will probably change in
108 // the future.
111 // Sets the butteraugli target distance for the compressor. This may override
112 // the default quantization table indexes based on jpeg colorspace, therefore
113 // it must be called after jpegli_set_defaults() or after the last
114 // jpegli_set_colorspace() or jpegli_default_colorspace() calls.
115 void jpegli_set_distance(j_compress_ptr cinfo, float distance,
116 boolean force_baseline);
118 // Returns the butteraugli target distance for the given quality parameter.
119 float jpegli_quality_to_distance(int quality);
121 // Enables distance parameter search to meet the given psnr target.
122 void jpegli_set_psnr(j_compress_ptr cinfo, float psnr, float tolerance,
123 float min_distance, float max_distance);
125 // Changes the default behaviour of the encoder in the selection of quantization
126 // matrices and chroma subsampling. Must be called before jpegli_set_defaults()
127 // because some default setting depend on the XYB mode.
128 void jpegli_set_xyb_mode(j_compress_ptr cinfo);
130 // Signals to the encoder that the pixel data that will be provided later
131 // through jpegli_write_scanlines() has this transfer function. This must be
132 // called before jpegli_set_defaults() because it changes the default
133 // quantization tables.
134 void jpegli_set_cicp_transfer_function(j_compress_ptr cinfo, int code);
136 void jpegli_set_input_format(j_compress_ptr cinfo, JpegliDataType data_type,
137 JpegliEndianness endianness);
139 // Sets whether or not the encoder uses adaptive quantization for creating more
140 // zero coefficients based on the local properties of the image.
141 // Enabled by default.
142 void jpegli_enable_adaptive_quantization(j_compress_ptr cinfo, boolean value);
144 // Sets the default progression parameters, where level 0 is sequential, and
145 // greater level value means more progression steps. Default is 2.
146 void jpegli_set_progressive_level(j_compress_ptr cinfo, int level);
148 // If this function is called before starting compression, the quality and
149 // linear quality parameters will be used to scale the standard quantization
150 // tables from Annex K of the JPEG standard. By default jpegli uses a different
151 // set of quantization tables and used different scaling parameters for DC and
152 // AC coefficients. Must be called before jpegli_set_defaults().
153 void jpegli_use_standard_quant_tables(j_compress_ptr cinfo);
155 #ifdef __cplusplus
156 } // extern "C"
157 #endif
159 #endif // LIB_JPEGLI_ENCODE_H_