tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

encode.h (6294B)


      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 #include "lib/jpegli/types.h"
     25 
     26 #ifdef __cplusplus
     27 extern "C" {
     28 #endif
     29 
     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);
     35 
     36 void jpegli_stdio_dest(j_compress_ptr cinfo, FILE* outfile);
     37 
     38 void jpegli_mem_dest(j_compress_ptr cinfo, unsigned char** outbuffer,
     39                     unsigned long* outsize /* NOLINT */);
     40 
     41 void jpegli_set_defaults(j_compress_ptr cinfo);
     42 
     43 void jpegli_default_colorspace(j_compress_ptr cinfo);
     44 
     45 void jpegli_set_colorspace(j_compress_ptr cinfo, J_COLOR_SPACE colorspace);
     46 
     47 void jpegli_set_quality(j_compress_ptr cinfo, int quality,
     48                        boolean force_baseline);
     49 
     50 void jpegli_set_linear_quality(j_compress_ptr cinfo, int scale_factor,
     51                               boolean force_baseline);
     52 
     53 #if JPEG_LIB_VERSION >= 70
     54 void jpegli_default_qtables(j_compress_ptr cinfo, boolean force_baseline);
     55 #endif
     56 
     57 int jpegli_quality_scaling(int quality);
     58 
     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);
     62 
     63 void jpegli_simple_progression(j_compress_ptr cinfo);
     64 
     65 void jpegli_suppress_tables(j_compress_ptr cinfo, boolean suppress);
     66 
     67 #if JPEG_LIB_VERSION >= 70
     68 void jpegli_calc_jpeg_dimensions(j_compress_ptr cinfo);
     69 #endif
     70 
     71 void jpegli_copy_critical_parameters(j_decompress_ptr srcinfo,
     72                                     j_compress_ptr dstinfo);
     73 
     74 void jpegli_write_m_header(j_compress_ptr cinfo, int marker,
     75                           unsigned int datalen);
     76 
     77 void jpegli_write_m_byte(j_compress_ptr cinfo, int val);
     78 
     79 void jpegli_write_marker(j_compress_ptr cinfo, int marker,
     80                         const JOCTET* dataptr, unsigned int datalen);
     81 
     82 void jpegli_write_icc_profile(j_compress_ptr cinfo, const JOCTET* icc_data_ptr,
     83                              unsigned int icc_data_len);
     84 
     85 void jpegli_start_compress(j_compress_ptr cinfo, boolean write_all_tables);
     86 
     87 void jpegli_write_tables(j_compress_ptr cinfo);
     88 
     89 JDIMENSION jpegli_write_scanlines(j_compress_ptr cinfo, JSAMPARRAY scanlines,
     90                                  JDIMENSION num_lines);
     91 
     92 JDIMENSION jpegli_write_raw_data(j_compress_ptr cinfo, JSAMPIMAGE data,
     93                                 JDIMENSION num_lines);
     94 
     95 void jpegli_write_coefficients(j_compress_ptr cinfo,
     96                               jvirt_barray_ptr* coef_arrays);
     97 
     98 void jpegli_finish_compress(j_compress_ptr cinfo);
     99 
    100 void jpegli_abort_compress(j_compress_ptr cinfo);
    101 
    102 void jpegli_destroy_compress(j_compress_ptr cinfo);
    103 
    104 //
    105 // New API functions that are not available in libjpeg
    106 //
    107 // NOTE: This part of the API is still experimental and will probably change in
    108 // the future.
    109 //
    110 
    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);
    117 
    118 // Returns the butteraugli target distance for the given quality parameter.
    119 float jpegli_quality_to_distance(int quality);
    120 
    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);
    124 
    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);
    129 
    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);
    135 
    136 void jpegli_set_input_format(j_compress_ptr cinfo, JpegliDataType data_type,
    137                             JpegliEndianness endianness);
    138 
    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);
    143 
    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);
    147 
    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);
    154 
    155 #ifdef __cplusplus
    156 }  // extern "C"
    157 #endif
    158 
    159 #endif  // LIB_JPEGLI_ENCODE_H_