1 // Copyright (c) the JPEG XL Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file.
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
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"
25 #if defined(__cplusplus) || defined(c_plusplus)
29 #define jpegli_create_compress(cinfo) \
30 jpegli_CreateCompress((cinfo), JPEG_LIB_VERSION, \
31 (size_t)sizeof(struct jpeg_compress_struct))
32 void jpegli_CreateCompress(j_compress_ptr cinfo
, int version
,
35 void jpegli_stdio_dest(j_compress_ptr cinfo
, FILE* outfile
);
37 void jpegli_mem_dest(j_compress_ptr cinfo
, unsigned char** outbuffer
,
38 unsigned long* outsize
);
40 void jpegli_set_defaults(j_compress_ptr cinfo
);
42 void jpegli_default_colorspace(j_compress_ptr cinfo
);
44 void jpegli_set_colorspace(j_compress_ptr cinfo
, J_COLOR_SPACE colorspace
);
46 void jpegli_set_quality(j_compress_ptr cinfo
, int quality
,
47 boolean force_baseline
);
49 void jpegli_set_linear_quality(j_compress_ptr cinfo
, int scale_factor
,
50 boolean force_baseline
);
52 #if JPEG_LIB_VERSION >= 70
53 void jpegli_default_qtables(j_compress_ptr cinfo
, boolean force_baseline
);
56 int jpegli_quality_scaling(int quality
);
58 void jpegli_add_quant_table(j_compress_ptr cinfo
, int which_tbl
,
59 const unsigned int* basic_table
, int scale_factor
,
60 boolean force_baseline
);
62 void jpegli_simple_progression(j_compress_ptr cinfo
);
64 void jpegli_suppress_tables(j_compress_ptr cinfo
, boolean suppress
);
66 #if JPEG_LIB_VERSION >= 70
67 void jpegli_calc_jpeg_dimensions(j_compress_ptr cinfo
);
70 void jpegli_copy_critical_parameters(j_decompress_ptr srcinfo
,
71 j_compress_ptr dstinfo
);
73 void jpegli_write_m_header(j_compress_ptr cinfo
, int marker
,
74 unsigned int datalen
);
76 void jpegli_write_m_byte(j_compress_ptr cinfo
, int val
);
78 void jpegli_write_marker(j_compress_ptr cinfo
, int marker
,
79 const JOCTET
* dataptr
, unsigned int datalen
);
81 void jpegli_write_icc_profile(j_compress_ptr cinfo
, const JOCTET
* icc_data_ptr
,
82 unsigned int icc_data_len
);
84 void jpegli_start_compress(j_compress_ptr cinfo
, boolean write_all_tables
);
86 void jpegli_write_tables(j_compress_ptr cinfo
);
88 JDIMENSION
jpegli_write_scanlines(j_compress_ptr cinfo
, JSAMPARRAY scanlines
,
89 JDIMENSION num_lines
);
91 JDIMENSION
jpegli_write_raw_data(j_compress_ptr cinfo
, JSAMPIMAGE data
,
92 JDIMENSION num_lines
);
94 void jpegli_write_coefficients(j_compress_ptr cinfo
,
95 jvirt_barray_ptr
* coef_arrays
);
97 void jpegli_finish_compress(j_compress_ptr cinfo
);
99 void jpegli_abort_compress(j_compress_ptr cinfo
);
101 void jpegli_destroy_compress(j_compress_ptr cinfo
);
104 // New API functions that are not available in libjpeg
106 // NOTE: This part of the API is still experimental and will probably change in
110 // Sets the butteraugli target distance for the compressor. This may override
111 // the default quantization table indexes based on jpeg colorspace, therefore
112 // it must be called after jpegli_set_defaults() or after the last
113 // jpegli_set_colorspace() or jpegli_default_colorspace() calls.
114 void jpegli_set_distance(j_compress_ptr cinfo
, float distance
,
115 boolean force_baseline
);
117 // Returns the butteraugli target distance for the given quality parameter.
118 float jpegli_quality_to_distance(int quality
);
120 // Enables distance parameter search to meet the given psnr target.
121 void jpegli_set_psnr(j_compress_ptr cinfo
, float psnr
, float tolerance
,
122 float min_distance
, float max_distance
);
124 // Changes the default behaviour of the encoder in the selection of quantization
125 // matrices and chroma subsampling. Must be called before jpegli_set_defaults()
126 // because some default setting depend on the XYB mode.
127 void jpegli_set_xyb_mode(j_compress_ptr cinfo
);
129 // Signals to the encoder that the pixel data that will be provided later
130 // through jpegli_write_scanlines() has this transfer function. This must be
131 // called before jpegli_set_defaults() because it changes the default
132 // quantization tables.
133 void jpegli_set_cicp_transfer_function(j_compress_ptr cinfo
, int code
);
135 void jpegli_set_input_format(j_compress_ptr cinfo
, JpegliDataType data_type
,
136 JpegliEndianness endianness
);
138 // Sets whether or not the encoder uses adaptive quantization for creating more
139 // zero coefficients based on the local properties of the image.
140 // Enabled by default.
141 void jpegli_enable_adaptive_quantization(j_compress_ptr cinfo
, boolean value
);
143 // Sets the default progression parameters, where level 0 is sequential, and
144 // greater level value means more progression steps. Default is 2.
145 void jpegli_set_progressive_level(j_compress_ptr cinfo
, int level
);
147 // If this function is called before starting compression, the quality and
148 // linear quality parameters will be used to scale the standard quantization
149 // tables from Annex K of the JPEG standard. By default jpegli uses a different
150 // set of quantization tables and used different scaling parameters for DC and
151 // AC coefficients. Must be called before jpegli_set_defaults().
152 void jpegli_use_standard_quant_tables(j_compress_ptr cinfo
);
154 #if defined(__cplusplus) || defined(c_plusplus)
158 #endif // LIB_JPEGLI_ENCODE_H_