libjxl

FORK: libjxl patches used on blog
git clone https://git.neptards.moe/blog/libjxl.git
Log | Files | Refs | Submodules | README | LICENSE

encode_internal.h (4433B)


      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_JPEGLI_ENCODE_INTERNAL_H_
      7 #define LIB_JPEGLI_ENCODE_INTERNAL_H_
      8 
      9 #include <stdint.h>
     10 
     11 #include "lib/jpegli/bit_writer.h"
     12 #include "lib/jpegli/common.h"
     13 #include "lib/jpegli/common_internal.h"
     14 #include "lib/jpegli/encode.h"
     15 
     16 namespace jpegli {
     17 
     18 constexpr unsigned char kICCSignature[12] = {
     19     0x49, 0x43, 0x43, 0x5F, 0x50, 0x52, 0x4F, 0x46, 0x49, 0x4C, 0x45, 0x00};
     20 constexpr int kICCMarker = JPEG_APP0 + 2;
     21 
     22 constexpr int kDefaultProgressiveLevel = 0;
     23 
     24 typedef int16_t coeff_t;
     25 
     26 struct HuffmanCodeTable {
     27   int depth[256];
     28   int code[256];
     29 };
     30 
     31 struct Token {
     32   uint8_t context;
     33   uint8_t symbol;
     34   uint16_t bits;
     35   Token(int c, int s, int b) : context(c), symbol(s), bits(b) {}
     36 };
     37 
     38 struct TokenArray {
     39   Token* tokens;
     40   size_t num_tokens;
     41 };
     42 
     43 struct RefToken {
     44   uint8_t symbol;
     45   uint8_t refbits;
     46 };
     47 
     48 struct ScanTokenInfo {
     49   RefToken* tokens;
     50   size_t num_tokens;
     51   uint8_t* refbits;
     52   uint16_t* eobruns;
     53   size_t* restarts;
     54   size_t num_restarts;
     55   size_t num_nonzeros;
     56   size_t num_future_nonzeros;
     57   size_t token_offset;
     58   size_t restart_interval;
     59   size_t MCUs_per_row;
     60   size_t MCU_rows_in_scan;
     61   size_t blocks_in_MCU;
     62   size_t num_blocks;
     63 };
     64 
     65 }  // namespace jpegli
     66 
     67 struct jpeg_comp_master {
     68   jpegli::RowBuffer<float> input_buffer[jpegli::kMaxComponents];
     69   jpegli::RowBuffer<float>* smooth_input[jpegli::kMaxComponents];
     70   jpegli::RowBuffer<float>* raw_data[jpegli::kMaxComponents];
     71   bool force_baseline;
     72   bool xyb_mode;
     73   uint8_t cicp_transfer_function;
     74   bool use_std_tables;
     75   bool use_adaptive_quantization;
     76   int progressive_level;
     77   size_t xsize_blocks;
     78   size_t ysize_blocks;
     79   size_t blocks_per_iMCU_row;
     80   jpegli::ScanTokenInfo* scan_token_info;
     81   JpegliDataType data_type;
     82   JpegliEndianness endianness;
     83   void (*input_method)(const uint8_t* row_in, size_t len,
     84                        float* row_out[jpegli::kMaxComponents]);
     85   void (*color_transform)(float* row[jpegli::kMaxComponents], size_t len);
     86   void (*downsample_method[jpegli::kMaxComponents])(
     87       float* rows_in[MAX_SAMP_FACTOR], size_t len, float* row_out);
     88   float* quant_mul[jpegli::kMaxComponents];
     89   float* zero_bias_offset[jpegli::kMaxComponents];
     90   float* zero_bias_mul[jpegli::kMaxComponents];
     91   int h_factor[jpegli::kMaxComponents];
     92   int v_factor[jpegli::kMaxComponents];
     93   // Array of Huffman tables that will be encoded in one or more DHT segments.
     94   // In progressive mode we compute all Huffman tables that will be used in any
     95   // of the scans, thus we can have more than 4 tables here.
     96   JHUFF_TBL* huffman_tables;
     97   size_t num_huffman_tables;
     98   // Array of num_huffman_tables slot ids, where the ith element is the slot id
     99   // of the ith Huffman table, as it appears in the DHT segment. The range of
    100   // the slot ids is 0..3 for DC and 16..19 for AC Huffman codes.
    101   uint8_t* slot_id_map;
    102   // Maps context ids to an index in the huffman_tables array. Each component in
    103   // each scan has a DC and AC context id, which are defined as follows:
    104   //   - DC context id is the component index (relative to cinfo->comp_info) of
    105   //     the scan component
    106   //   - AC context ids start at 4 and are increased for each component of each
    107   //     scan that have AC components (i.e. Se > 0)
    108   uint8_t* context_map;
    109   size_t num_contexts;
    110   // Array of cinfo->num_scans context ids, where the ith element is the context
    111   // id of the first AC component of the ith scan.
    112   uint8_t* ac_ctx_offset;
    113   // Array of num_huffman tables derived coding tables.
    114   jpegli::HuffmanCodeTable* coding_tables;
    115   float* diff_buffer;
    116   jpegli::RowBuffer<float> fuzzy_erosion_tmp;
    117   jpegli::RowBuffer<float> pre_erosion;
    118   jpegli::RowBuffer<float> quant_field;
    119   jvirt_barray_ptr* coeff_buffers;
    120   size_t next_input_row;
    121   size_t next_iMCU_row;
    122   size_t next_dht_index;
    123   size_t last_restart_interval;
    124   JCOEF last_dc_coeff[MAX_COMPS_IN_SCAN];
    125   jpegli::JpegBitWriter bw;
    126   float* dct_buffer;
    127   int32_t* block_tmp;
    128   jpegli::TokenArray* token_arrays;
    129   size_t cur_token_array;
    130   jpegli::Token* next_token;
    131   size_t num_tokens;
    132   size_t total_num_tokens;
    133   jpegli::RefToken* next_refinement_token;
    134   uint8_t* next_refinement_bit;
    135   float psnr_target;
    136   float psnr_tolerance;
    137   float min_distance;
    138   float max_distance;
    139 };
    140 
    141 #endif  // LIB_JPEGLI_ENCODE_INTERNAL_H_