encode.h (6309B)
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 10 // 11 // Applications can use the libjpegli library in one of the following ways: 12 // 13 // (1) Include jpegli/encode.h and/or jpegli/decode.h, update the function 14 // names of the API and link against libjpegli. 15 // 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. 19 20 #ifndef LIB_JPEGLI_ENCODE_H_ 21 #define LIB_JPEGLI_ENCODE_H_ 22 23 #include "lib/jpegli/common.h" 24 25 #if defined(__cplusplus) || defined(c_plusplus) 26 extern "C" { 27 #endif 28 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, 33 size_t structsize); 34 35 void jpegli_stdio_dest(j_compress_ptr cinfo, FILE* outfile); 36 37 void jpegli_mem_dest(j_compress_ptr cinfo, unsigned char** outbuffer, 38 unsigned long* outsize); 39 40 void jpegli_set_defaults(j_compress_ptr cinfo); 41 42 void jpegli_default_colorspace(j_compress_ptr cinfo); 43 44 void jpegli_set_colorspace(j_compress_ptr cinfo, J_COLOR_SPACE colorspace); 45 46 void jpegli_set_quality(j_compress_ptr cinfo, int quality, 47 boolean force_baseline); 48 49 void jpegli_set_linear_quality(j_compress_ptr cinfo, int scale_factor, 50 boolean force_baseline); 51 52 #if JPEG_LIB_VERSION >= 70 53 void jpegli_default_qtables(j_compress_ptr cinfo, boolean force_baseline); 54 #endif 55 56 int jpegli_quality_scaling(int quality); 57 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); 61 62 void jpegli_simple_progression(j_compress_ptr cinfo); 63 64 void jpegli_suppress_tables(j_compress_ptr cinfo, boolean suppress); 65 66 #if JPEG_LIB_VERSION >= 70 67 void jpegli_calc_jpeg_dimensions(j_compress_ptr cinfo); 68 #endif 69 70 void jpegli_copy_critical_parameters(j_decompress_ptr srcinfo, 71 j_compress_ptr dstinfo); 72 73 void jpegli_write_m_header(j_compress_ptr cinfo, int marker, 74 unsigned int datalen); 75 76 void jpegli_write_m_byte(j_compress_ptr cinfo, int val); 77 78 void jpegli_write_marker(j_compress_ptr cinfo, int marker, 79 const JOCTET* dataptr, unsigned int datalen); 80 81 void jpegli_write_icc_profile(j_compress_ptr cinfo, const JOCTET* icc_data_ptr, 82 unsigned int icc_data_len); 83 84 void jpegli_start_compress(j_compress_ptr cinfo, boolean write_all_tables); 85 86 void jpegli_write_tables(j_compress_ptr cinfo); 87 88 JDIMENSION jpegli_write_scanlines(j_compress_ptr cinfo, JSAMPARRAY scanlines, 89 JDIMENSION num_lines); 90 91 JDIMENSION jpegli_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data, 92 JDIMENSION num_lines); 93 94 void jpegli_write_coefficients(j_compress_ptr cinfo, 95 jvirt_barray_ptr* coef_arrays); 96 97 void jpegli_finish_compress(j_compress_ptr cinfo); 98 99 void jpegli_abort_compress(j_compress_ptr cinfo); 100 101 void jpegli_destroy_compress(j_compress_ptr cinfo); 102 103 // 104 // New API functions that are not available in libjpeg 105 // 106 // NOTE: This part of the API is still experimental and will probably change in 107 // the future. 108 // 109 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); 116 117 // Returns the butteraugli target distance for the given quality parameter. 118 float jpegli_quality_to_distance(int quality); 119 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); 123 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); 128 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); 134 135 void jpegli_set_input_format(j_compress_ptr cinfo, JpegliDataType data_type, 136 JpegliEndianness endianness); 137 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); 142 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); 146 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); 153 154 #if defined(__cplusplus) || defined(c_plusplus) 155 } // extern "C" 156 #endif 157 158 #endif // LIB_JPEGLI_ENCODE_H_