#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 uint32_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) { … }
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, uint32_t* value) { … }
static BrotliDecoderErrorCode BROTLI_NOINLINE DecodeMetaBlockLength(
BrotliDecoderState* s, BrotliBitReader* br) { … }
static BROTLI_INLINE uint32_t DecodeSymbol(uint32_t bits,
const HuffmanCode* table,
BrotliBitReader* br) { … }
static BROTLI_INLINE uint32_t ReadSymbol(const HuffmanCode* table,
BrotliBitReader* br) { … }
static BROTLI_NOINLINE BROTLI_BOOL SafeDecodeSymbol(
const HuffmanCode* table, BrotliBitReader* br, uint32_t* result) { … }
static BROTLI_INLINE BROTLI_BOOL SafeReadSymbol(
const HuffmanCode* table, BrotliBitReader* br, uint32_t* result) { … }
static BROTLI_INLINE void PreloadSymbol(int safe,
const HuffmanCode* table,
BrotliBitReader* br,
uint32_t* bits,
uint32_t* value) { … }
static BROTLI_INLINE uint32_t ReadPreloadedSymbol(const HuffmanCode* table,
BrotliBitReader* br,
uint32_t* bits,
uint32_t* value) { … }
static BROTLI_INLINE uint32_t Log2Floor(uint32_t x) { … }
static BrotliDecoderErrorCode ReadSimpleHuffmanSymbols(
uint32_t alphabet_size_max, uint32_t alphabet_size_limit,
BrotliDecoderState* s) { … }
static BROTLI_INLINE void ProcessSingleCodeLength(uint32_t code_len,
uint32_t* symbol, uint32_t* repeat, uint32_t* space,
uint32_t* prev_code_len, uint16_t* symbol_lists,
uint16_t* code_length_histo, int* next_symbol) { … }
static BROTLI_INLINE void ProcessRepeatedCodeLength(uint32_t code_len,
uint32_t repeat_delta, uint32_t alphabet_size, uint32_t* symbol,
uint32_t* repeat, uint32_t* space, uint32_t* prev_code_len,
uint32_t* repeat_code_len, uint16_t* symbol_lists,
uint16_t* code_length_histo, int* next_symbol) { … }
static BrotliDecoderErrorCode ReadSymbolCodeLengths(
uint32_t alphabet_size, BrotliDecoderState* s) { … }
static BrotliDecoderErrorCode SafeReadSymbolCodeLengths(
uint32_t alphabet_size, BrotliDecoderState* s) { … }
static BrotliDecoderErrorCode ReadCodeLengthCodeLengths(BrotliDecoderState* s) { … }
static BrotliDecoderErrorCode ReadHuffmanCode(uint32_t alphabet_size_max,
uint32_t alphabet_size_limit,
HuffmanCode* table,
uint32_t* opt_table_size,
BrotliDecoderState* s) { … }
static BROTLI_INLINE uint32_t ReadBlockLength(const HuffmanCode* table,
BrotliBitReader* br) { … }
static BROTLI_INLINE BROTLI_BOOL SafeReadBlockLength(
BrotliDecoderState* s, uint32_t* result, const HuffmanCode* table,
BrotliBitReader* br) { … }
static BROTLI_NOINLINE void InverseMoveToFrontTransform(
uint8_t* v, uint32_t v_len, BrotliDecoderState* state) { … }
static BrotliDecoderErrorCode HuffmanTreeGroupDecode(
HuffmanTreeGroup* group, BrotliDecoderState* s) { … }
static BrotliDecoderErrorCode DecodeContextMap(uint32_t context_map_size,
uint32_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 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, uint32_t n_bits, uint32_t* val) { … }
static BROTLI_INLINE BROTLI_BOOL SafeReadBits32(
BrotliBitReader* const br, uint32_t n_bits, uint32_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, size_t num) { … }
#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() { … }
#if defined(BROTLI_TEST)
BROTLI_BOOL SafeReadSymbolForTest(
const HuffmanCode*, BrotliBitReader*, uint32_t*);
BROTLI_BOOL SafeReadSymbolForTest(
const HuffmanCode* table, BrotliBitReader* br, uint32_t* result) {
return SafeReadSymbol(table, br, result);
}
void InverseMoveToFrontTransformForTest(
uint8_t*, uint32_t, BrotliDecoderState*);
void InverseMoveToFrontTransformForTest(
uint8_t* v, uint32_t l, BrotliDecoderState* s) {
InverseMoveToFrontTransform(v, l, s);
}
#endif
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif