#include <brotli/decode.h>
#include <stdlib.h>
#include <string.h>
#include "../common/constants.h"
#include "../common/context.h"
#include "../common/dictionary.h"
#include "../common/platform.h"
#include "../common/shared_dictionary_internal.h"
#include "../common/transform.h"
#include "../common/version.h"
#include "bit_reader.h"
#include "huffman.h"
#include "prefix.h"
#include "state.h"
#if defined(BROTLI_TARGET_NEON)
#include <arm_neon.h>
#endif
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
#define BROTLI_FAILURE(CODE) …
#define BROTLI_LOG_UINT(name) …
#define BROTLI_LOG_ARRAY_INDEX(array_name, idx) …
#define HUFFMAN_TABLE_BITS …
#define HUFFMAN_TABLE_MASK …
static const brotli_reg_t kRingBufferWriteAheadSlack = …;
static const uint8_t kCodeLengthCodeOrder[BROTLI_CODE_LENGTH_CODES] = …;
static const uint8_t kCodeLengthPrefixLength[16] = …;
static const uint8_t kCodeLengthPrefixValue[16] = …;
BROTLI_BOOL BrotliDecoderSetParameter(
BrotliDecoderState* state, BrotliDecoderParameter p, uint32_t value) { … }
BrotliDecoderState* BrotliDecoderCreateInstance(
brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque) { … }
void BrotliDecoderDestroyInstance(BrotliDecoderState* state) { … }
static BROTLI_NOINLINE BrotliDecoderResult SaveErrorCode(
BrotliDecoderState* s, BrotliDecoderErrorCode e, size_t consumed_input) { … }
static BrotliDecoderErrorCode DecodeWindowBits(BrotliDecoderState* s,
BrotliBitReader* br) { … }
static BROTLI_INLINE void memmove16(uint8_t* dst, uint8_t* src) { … }
static BROTLI_NOINLINE BrotliDecoderErrorCode DecodeVarLenUint8(
BrotliDecoderState* s, BrotliBitReader* br, brotli_reg_t* value) { … }
static BrotliDecoderErrorCode BROTLI_NOINLINE DecodeMetaBlockLength(
BrotliDecoderState* s, BrotliBitReader* br) { … }
static BROTLI_INLINE brotli_reg_t DecodeSymbol(brotli_reg_t bits,
const HuffmanCode* table,
BrotliBitReader* br) { … }
static BROTLI_INLINE brotli_reg_t ReadSymbol(const HuffmanCode* table,
BrotliBitReader* br) { … }
static BROTLI_NOINLINE BROTLI_BOOL SafeDecodeSymbol(
const HuffmanCode* table, BrotliBitReader* br, brotli_reg_t* result) { … }
static BROTLI_INLINE BROTLI_BOOL SafeReadSymbol(
const HuffmanCode* table, BrotliBitReader* br, brotli_reg_t* result) { … }
static BROTLI_INLINE void PreloadSymbol(int safe,
const HuffmanCode* table,
BrotliBitReader* br,
brotli_reg_t* bits,
brotli_reg_t* value) { … }
static BROTLI_INLINE brotli_reg_t ReadPreloadedSymbol(const HuffmanCode* table,
BrotliBitReader* br,
brotli_reg_t* bits,
brotli_reg_t* value) { … }
static BROTLI_INLINE brotli_reg_t Log2Floor(brotli_reg_t x) { … }
static BrotliDecoderErrorCode ReadSimpleHuffmanSymbols(
brotli_reg_t alphabet_size_max, brotli_reg_t alphabet_size_limit,
BrotliDecoderState* s) { … }
static BROTLI_INLINE void ProcessSingleCodeLength(brotli_reg_t code_len,
brotli_reg_t* symbol, brotli_reg_t* repeat, brotli_reg_t* space,
brotli_reg_t* prev_code_len, uint16_t* symbol_lists,
uint16_t* code_length_histo, int* next_symbol) { … }
static BROTLI_INLINE void ProcessRepeatedCodeLength(brotli_reg_t code_len,
brotli_reg_t repeat_delta, brotli_reg_t alphabet_size, brotli_reg_t* symbol,
brotli_reg_t* repeat, brotli_reg_t* space, brotli_reg_t* prev_code_len,
brotli_reg_t* repeat_code_len, uint16_t* symbol_lists,
uint16_t* code_length_histo, int* next_symbol) { … }
static BrotliDecoderErrorCode ReadSymbolCodeLengths(
brotli_reg_t alphabet_size, BrotliDecoderState* s) { … }
static BrotliDecoderErrorCode SafeReadSymbolCodeLengths(
brotli_reg_t alphabet_size, BrotliDecoderState* s) { … }
static BrotliDecoderErrorCode ReadCodeLengthCodeLengths(BrotliDecoderState* s) { … }
static BrotliDecoderErrorCode ReadHuffmanCode(brotli_reg_t alphabet_size_max,
brotli_reg_t alphabet_size_limit,
HuffmanCode* table,
brotli_reg_t* opt_table_size,
BrotliDecoderState* s) { … }
static BROTLI_INLINE brotli_reg_t ReadBlockLength(const HuffmanCode* table,
BrotliBitReader* br) { … }
static BROTLI_INLINE BROTLI_BOOL SafeReadBlockLength(
BrotliDecoderState* s, brotli_reg_t* result, const HuffmanCode* table,
BrotliBitReader* br) { … }
static BROTLI_NOINLINE void InverseMoveToFrontTransform(
uint8_t* v, brotli_reg_t v_len, BrotliDecoderState* state) { … }
static BrotliDecoderErrorCode HuffmanTreeGroupDecode(
HuffmanTreeGroup* group, BrotliDecoderState* s) { … }
static BrotliDecoderErrorCode DecodeContextMap(brotli_reg_t context_map_size,
brotli_reg_t* num_htrees,
uint8_t** context_map_arg,
BrotliDecoderState* s) { … }
static BROTLI_INLINE BROTLI_BOOL DecodeBlockTypeAndLength(
int safe, BrotliDecoderState* s, int tree_type) { … }
static BROTLI_INLINE void DetectTrivialLiteralBlockTypes(
BrotliDecoderState* s) { … }
static BROTLI_INLINE void PrepareLiteralDecoding(BrotliDecoderState* s) { … }
static BROTLI_INLINE BROTLI_BOOL DecodeLiteralBlockSwitchInternal(
int safe, BrotliDecoderState* s) { … }
static void BROTLI_NOINLINE DecodeLiteralBlockSwitch(BrotliDecoderState* s) { … }
static BROTLI_BOOL BROTLI_NOINLINE SafeDecodeLiteralBlockSwitch(
BrotliDecoderState* s) { … }
static BROTLI_INLINE BROTLI_BOOL DecodeCommandBlockSwitchInternal(
int safe, BrotliDecoderState* s) { … }
static void BROTLI_NOINLINE DecodeCommandBlockSwitch(BrotliDecoderState* s) { … }
static BROTLI_BOOL BROTLI_NOINLINE SafeDecodeCommandBlockSwitch(
BrotliDecoderState* s) { … }
static BROTLI_INLINE BROTLI_BOOL DecodeDistanceBlockSwitchInternal(
int safe, BrotliDecoderState* s) { … }
static void BROTLI_NOINLINE DecodeDistanceBlockSwitch(BrotliDecoderState* s) { … }
static BROTLI_BOOL BROTLI_NOINLINE SafeDecodeDistanceBlockSwitch(
BrotliDecoderState* s) { … }
static size_t UnwrittenBytes(const BrotliDecoderState* s, BROTLI_BOOL wrap) { … }
static BrotliDecoderErrorCode BROTLI_NOINLINE WriteRingBuffer(
BrotliDecoderState* s, size_t* available_out, uint8_t** next_out,
size_t* total_out, BROTLI_BOOL force) { … }
static void BROTLI_NOINLINE WrapRingBuffer(BrotliDecoderState* s) { … }
static BROTLI_BOOL BROTLI_NOINLINE BrotliEnsureRingBuffer(
BrotliDecoderState* s) { … }
static BrotliDecoderErrorCode BROTLI_NOINLINE
SkipMetadataBlock(BrotliDecoderState* s) { … }
static BrotliDecoderErrorCode BROTLI_NOINLINE CopyUncompressedBlockToOutput(
size_t* available_out, uint8_t** next_out, size_t* total_out,
BrotliDecoderState* s) { … }
static BROTLI_BOOL AttachCompoundDictionary(
BrotliDecoderState* state, const uint8_t* data, size_t size) { … }
static void EnsureCoumpoundDictionaryInitialized(BrotliDecoderState* state) { … }
static BROTLI_BOOL InitializeCompoundDictionaryCopy(BrotliDecoderState* s,
int address, int length) { … }
static int GetCompoundDictionarySize(BrotliDecoderState* s) { … }
static int CopyFromCompoundDictionary(BrotliDecoderState* s, int pos) { … }
BROTLI_BOOL BrotliDecoderAttachDictionary(
BrotliDecoderState* state, BrotliSharedDictionaryType type,
size_t data_size, const uint8_t data[BROTLI_ARRAY_PARAM(data_size)]) { … }
static void BROTLI_NOINLINE BrotliCalculateRingBufferSize(
BrotliDecoderState* s) { … }
static BrotliDecoderErrorCode ReadContextModes(BrotliDecoderState* s) { … }
static BROTLI_INLINE void TakeDistanceFromRingBuffer(BrotliDecoderState* s) { … }
static BROTLI_INLINE BROTLI_BOOL SafeReadBits(
BrotliBitReader* const br, brotli_reg_t n_bits, brotli_reg_t* val) { … }
static BROTLI_INLINE BROTLI_BOOL SafeReadBits32(
BrotliBitReader* const br, brotli_reg_t n_bits, brotli_reg_t* val) { … }
static void CalculateDistanceLut(BrotliDecoderState* s) { … }
static BROTLI_INLINE BROTLI_BOOL ReadDistanceInternal(
int safe, BrotliDecoderState* s, BrotliBitReader* br) { … }
static BROTLI_INLINE void ReadDistance(
BrotliDecoderState* s, BrotliBitReader* br) { … }
static BROTLI_INLINE BROTLI_BOOL SafeReadDistance(
BrotliDecoderState* s, BrotliBitReader* br) { … }
static BROTLI_INLINE BROTLI_BOOL ReadCommandInternal(
int safe, BrotliDecoderState* s, BrotliBitReader* br, int* insert_length) { … }
static BROTLI_INLINE void ReadCommand(
BrotliDecoderState* s, BrotliBitReader* br, int* insert_length) { … }
static BROTLI_INLINE BROTLI_BOOL SafeReadCommand(
BrotliDecoderState* s, BrotliBitReader* br, int* insert_length) { … }
static BROTLI_INLINE BROTLI_BOOL CheckInputAmount(
int safe, BrotliBitReader* const br) { … }
#define BROTLI_SAFE …
static BROTLI_INLINE BrotliDecoderErrorCode ProcessCommandsInternal(
int safe, BrotliDecoderState* s) { … }
#undef BROTLI_SAFE
static BROTLI_NOINLINE BrotliDecoderErrorCode ProcessCommands(
BrotliDecoderState* s) { … }
static BROTLI_NOINLINE BrotliDecoderErrorCode SafeProcessCommands(
BrotliDecoderState* s) { … }
BrotliDecoderResult BrotliDecoderDecompress(
size_t encoded_size,
const uint8_t encoded_buffer[BROTLI_ARRAY_PARAM(encoded_size)],
size_t* decoded_size,
uint8_t decoded_buffer[BROTLI_ARRAY_PARAM(*decoded_size)]) { … }
BrotliDecoderResult BrotliDecoderDecompressStream(
BrotliDecoderState* s, size_t* available_in, const uint8_t** next_in,
size_t* available_out, uint8_t** next_out, size_t* total_out) { … }
BROTLI_BOOL BrotliDecoderHasMoreOutput(const BrotliDecoderState* s) { … }
const uint8_t* BrotliDecoderTakeOutput(BrotliDecoderState* s, size_t* size) { … }
BROTLI_BOOL BrotliDecoderIsUsed(const BrotliDecoderState* s) { … }
BROTLI_BOOL BrotliDecoderIsFinished(const BrotliDecoderState* s) { … }
BrotliDecoderErrorCode BrotliDecoderGetErrorCode(const BrotliDecoderState* s) { … }
const char* BrotliDecoderErrorString(BrotliDecoderErrorCode c) { … }
uint32_t BrotliDecoderVersion(void) { … }
void BrotliDecoderSetMetadataCallbacks(
BrotliDecoderState* state,
brotli_decoder_metadata_start_func start_func,
brotli_decoder_metadata_chunk_func chunk_func, void* opaque) { … }
#if defined(BROTLI_TEST)
BROTLI_BOOL SafeReadSymbolForTest(
const HuffmanCode*, BrotliBitReader*, brotli_reg_t*);
BROTLI_BOOL SafeReadSymbolForTest(
const HuffmanCode* table, BrotliBitReader* br, brotli_reg_t* result) {
return SafeReadSymbol(table, br, result);
}
void InverseMoveToFrontTransformForTest(
uint8_t*, brotli_reg_t, BrotliDecoderState*);
void InverseMoveToFrontTransformForTest(
uint8_t* v, brotli_reg_t l, BrotliDecoderState* s) {
InverseMoveToFrontTransform(v, l, s);
}
#endif
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif