tor-browser

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

decode_internal.h (4593B)


      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_DECODE_INTERNAL_H_
      7 #define LIB_JPEGLI_DECODE_INTERNAL_H_
      8 
      9 #include <sys/types.h>
     10 
     11 #include <cstdint>
     12 #include <vector>
     13 
     14 #include "lib/jpegli/common.h"
     15 #include "lib/jpegli/common_internal.h"
     16 #include "lib/jpegli/huffman.h"
     17 #include "lib/jpegli/types.h"
     18 
     19 namespace jpegli {
     20 
     21 static constexpr int kNeedMoreInput = 100;
     22 static constexpr int kHandleRestart = 101;
     23 static constexpr int kHandleMarkerProcessor = 102;
     24 static constexpr int kProcessNextMarker = 103;
     25 static constexpr size_t kAllHuffLutSize = NUM_HUFF_TBLS * kJpegHuffmanLutSize;
     26 
     27 typedef int16_t coeff_t;
     28 
     29 // State of the decoder that has to be saved before decoding one MCU in case
     30 // we run out of the bitstream.
     31 struct MCUCodingState {
     32  coeff_t last_dc_coeff[kMaxComponents];
     33  int eobrun;
     34  coeff_t coeffs[D_MAX_BLOCKS_IN_MCU * DCTSIZE2];
     35 };
     36 
     37 }  // namespace jpegli
     38 
     39 // Use this forward-declared libjpeg struct to hold all our private variables.
     40 // TODO(szabadka) Remove variables that have a corresponding version in cinfo.
     41 struct jpeg_decomp_master {
     42  //
     43  // Input handling state.
     44  //
     45  std::vector<uint8_t> input_buffer_;
     46  size_t input_buffer_pos_;
     47  // Number of bits after codestream_pos_ that were already processed.
     48  size_t codestream_bits_ahead_;
     49 
     50  // Coefficient buffers
     51  jvirt_barray_ptr* coef_arrays;
     52  JBLOCKARRAY coeff_rows[jpegli::kMaxComponents];
     53 
     54  bool streaming_mode_;
     55 
     56  //
     57  // Marker data processing state.
     58  //
     59  bool found_soi_;
     60  bool found_dri_;
     61  bool found_sof_;
     62  bool found_sos_;
     63  bool found_eoi_;
     64 
     65  // Whether this jpeg has multiple scans (progressive or non-interleaved
     66  // sequential).
     67  bool is_multiscan_;
     68 
     69  size_t icc_index_;
     70  size_t icc_total_;
     71  std::vector<uint8_t> icc_profile_;
     72  jpegli::HuffmanTableEntry dc_huff_lut_[jpegli::kAllHuffLutSize];
     73  jpegli::HuffmanTableEntry ac_huff_lut_[jpegli::kAllHuffLutSize];
     74  uint8_t markers_to_save_[32];
     75  jpeg_marker_parser_method app_marker_parsers[16];
     76  jpeg_marker_parser_method com_marker_parser;
     77 
     78  // Fields defined by SOF marker.
     79  size_t iMCU_cols_;
     80  int h_factor[jpegli::kMaxComponents];
     81  int v_factor[jpegli::kMaxComponents];
     82 
     83  // Initialized at start of frame.
     84  uint16_t scan_progression_[jpegli::kMaxComponents][DCTSIZE2];
     85 
     86  //
     87  // Per scan state.
     88  //
     89  size_t scan_mcu_row_;
     90  size_t scan_mcu_col_;
     91  size_t mcu_rows_per_iMCU_row_;
     92  jpegli::coeff_t last_dc_coeff_[jpegli::kMaxComponents];
     93  int eobrun_;
     94  int restarts_to_go_;
     95  int next_restart_marker_;
     96 
     97  jpegli::MCUCodingState mcu_;
     98 
     99  //
    100  // Rendering state.
    101  //
    102  int output_passes_done_;
    103  JpegliDataType output_data_type_ = JPEGLI_TYPE_UINT8;
    104  size_t xoffset_;
    105  bool swap_endianness_ = false;
    106  bool need_context_rows_;
    107  bool regenerate_inverse_colormap_;
    108  bool apply_smoothing;
    109 
    110  int min_scaled_dct_size;
    111  int scaled_dct_size[jpegli::kMaxComponents];
    112 
    113  size_t raw_height_[jpegli::kMaxComponents];
    114  jpegli::RowBuffer<float> raw_output_[jpegli::kMaxComponents];
    115  jpegli::RowBuffer<float> render_output_[jpegli::kMaxComponents];
    116 
    117  void (*inverse_transform[jpegli::kMaxComponents])(
    118      const int16_t* JXL_RESTRICT qblock, const float* JXL_RESTRICT dequant,
    119      const float* JXL_RESTRICT biases, float* JXL_RESTRICT scratch_space,
    120      float* JXL_RESTRICT output, size_t output_stride, size_t dctsize);
    121 
    122  void (*color_transform)(float* row[jpegli::kMaxComponents], size_t len);
    123 
    124  float* idct_scratch_;
    125  float* upsample_scratch_;
    126  uint8_t* output_scratch_;
    127  int16_t* smoothing_scratch_;
    128  float* dequant_;
    129  // 1 = 1pass, 2 = 2pass, 3 = external
    130  int quant_mode_;
    131  int quant_pass_;
    132  int num_colors_[jpegli::kMaxComponents];
    133  uint8_t* colormap_lut_;
    134  uint8_t* pixels_;
    135  JSAMPARRAY scanlines_;
    136  std::vector<std::vector<uint8_t>> candidate_lists_;
    137  float* dither_[jpegli::kMaxComponents];
    138  float* error_row_[2 * jpegli::kMaxComponents];
    139  size_t dither_size_;
    140  size_t dither_mask_;
    141 
    142  // Per channel and per frequency statistics about the number of nonzeros and
    143  // the sum of coefficient absolute values, used in dequantization bias
    144  // computation.
    145  int* nonzeros_;
    146  int* sumabs_;
    147  size_t num_processed_blocks_[jpegli::kMaxComponents];
    148  float* biases_;
    149 #define SAVED_COEFS 10
    150  // This holds the coef_bits of the scan before the current scan,
    151  // i.e. the bottom half when rendering incomplete scans.
    152  int (*coef_bits_latch)[SAVED_COEFS];
    153  int (*prev_coef_bits_latch)[SAVED_COEFS];
    154 };
    155 
    156 #endif  // LIB_JPEGLI_DECODE_INTERNAL_H_