mirror of
https://github.com/google/brotli.git
synced 2024-11-21 19:20:09 +00:00
Fix Microsoft VisualStudio build of brotli
- Move all variable declarations to the beginning of the block - #ifdef-out read/write calls
This commit is contained in:
parent
c23cb1e83d
commit
354349d7ae
@ -149,8 +149,9 @@ static BROTLI_INLINE void BrotliFillBitWindow(BrotliBitReader* const br) {
|
||||
// Requires that n_bits is positive.
|
||||
static BROTLI_INLINE uint32_t BrotliReadBits(
|
||||
BrotliBitReader* const br, int n_bits) {
|
||||
uint32_t val;
|
||||
BrotliFillBitWindow(br);
|
||||
const uint32_t val = (uint32_t)(br->val_ >> br->bit_pos_) & kBitMask[n_bits];
|
||||
val = (uint32_t)(br->val_ >> br->bit_pos_) & kBitMask[n_bits];
|
||||
#ifdef BROTLI_DECODE_DEBUG
|
||||
printf("[BrotliReadBits] %010ld %2d val: %6x\n",
|
||||
(br->pos_ << 3) + br->bit_pos_ - 64, n_bits, val);
|
||||
|
34
dec/decode.c
34
dec/decode.c
@ -84,14 +84,15 @@ static void DecodeMetaBlockLength(BrotliBitReader* br,
|
||||
size_t* meta_block_length,
|
||||
int* input_end,
|
||||
int* is_uncompressed) {
|
||||
int size_nibbles;
|
||||
int i;
|
||||
*input_end = BrotliReadBits(br, 1);
|
||||
*meta_block_length = 0;
|
||||
*is_uncompressed = 0;
|
||||
if (*input_end && BrotliReadBits(br, 1)) {
|
||||
return;
|
||||
}
|
||||
int size_nibbles = BrotliReadBits(br, 2) + 4;
|
||||
int i;
|
||||
size_nibbles = BrotliReadBits(br, 2) + 4;
|
||||
for (i = 0; i < size_nibbles; ++i) {
|
||||
*meta_block_length |= BrotliReadBits(br, 4) << (i * 4);
|
||||
}
|
||||
@ -104,13 +105,17 @@ static void DecodeMetaBlockLength(BrotliBitReader* br,
|
||||
// Decodes the next Huffman code from bit-stream.
|
||||
static BROTLI_INLINE int ReadSymbol(const HuffmanTree* tree,
|
||||
BrotliBitReader* br) {
|
||||
uint32_t bits;
|
||||
int bitpos;
|
||||
int lut_ix;
|
||||
int lut_bits;
|
||||
const HuffmanTreeNode* node = tree->root_;
|
||||
BrotliFillBitWindow(br);
|
||||
uint32_t bits = BrotliPrefetchBits(br);
|
||||
int bitpos = br->bit_pos_;
|
||||
bits = BrotliPrefetchBits(br);
|
||||
bitpos = br->bit_pos_;
|
||||
// Check if we find the bit combination from the Huffman lookup table.
|
||||
const int lut_ix = bits & (HUFF_LUT - 1);
|
||||
const int lut_bits = tree->lut_bits_[lut_ix];
|
||||
lut_ix = bits & (HUFF_LUT - 1);
|
||||
lut_bits = tree->lut_bits_[lut_ix];
|
||||
if (lut_bits <= HUFF_LUT_BITS) {
|
||||
BrotliSetBitPos(br, bitpos + lut_bits);
|
||||
return tree->lut_symbol_[lut_ix];
|
||||
@ -587,13 +592,13 @@ int BrotliDecompressedSize(size_t encoded_size,
|
||||
BrotliMemInput memin;
|
||||
BrotliInput input = BrotliInitMemInput(encoded_buffer, encoded_size, &memin);
|
||||
BrotliBitReader br;
|
||||
size_t meta_block_len;
|
||||
int input_end;
|
||||
int is_uncompressed;
|
||||
if (!BrotliInitBitReader(&br, input)) {
|
||||
return 0;
|
||||
}
|
||||
DecodeWindowBits(&br);
|
||||
size_t meta_block_len;
|
||||
int input_end;
|
||||
int is_uncompressed;
|
||||
DecodeMetaBlockLength(&br, &meta_block_len, &input_end, &is_uncompressed);
|
||||
if (!input_end) {
|
||||
return 0;
|
||||
@ -636,6 +641,10 @@ int BrotliDecompress(BrotliInput input, BrotliOutput output) {
|
||||
HuffmanTreeGroup hgroup[3];
|
||||
BrotliBitReader br;
|
||||
|
||||
static const int kRingBufferWriteAheadSlack = 16;
|
||||
|
||||
static const int kMaxDictionaryWordLength = 0;
|
||||
|
||||
if (!BrotliInitBitReader(&br, input)) {
|
||||
return 0;
|
||||
}
|
||||
@ -644,10 +653,6 @@ int BrotliDecompress(BrotliInput input, BrotliOutput output) {
|
||||
window_bits = DecodeWindowBits(&br);
|
||||
max_backward_distance = (1 << window_bits) - 16;
|
||||
|
||||
static const int kRingBufferWriteAheadSlack = 16;
|
||||
|
||||
static const int kMaxDictionaryWordLength = 0;
|
||||
|
||||
ringbuffer_size = 1 << window_bits;
|
||||
ringbuffer_mask = ringbuffer_size - 1;
|
||||
ringbuffer = (uint8_t*)malloc(ringbuffer_size +
|
||||
@ -848,6 +853,7 @@ int BrotliDecompress(BrotliInput input, BrotliOutput output) {
|
||||
if (pos == meta_block_end_pos) break;
|
||||
|
||||
if (distance_code < 0) {
|
||||
uint8_t context;
|
||||
if (!BrotliReadMoreInput(&br)) {
|
||||
printf("[BrotliDecompress] Unexpected end of input.\n");
|
||||
ok = 0;
|
||||
@ -862,7 +868,7 @@ int BrotliDecompress(BrotliInput input, BrotliOutput output) {
|
||||
dist_context_map_slice = dist_context_map + dist_context_offset;
|
||||
}
|
||||
--block_length[2];
|
||||
uint8_t context = copy_length > 4 ? 3 : copy_length - 2;
|
||||
context = copy_length > 4 ? 3 : copy_length - 2;
|
||||
dist_htree_index = dist_context_map_slice[context];
|
||||
distance_code = ReadCopyDistance(&hgroup[2].htrees[dist_htree_index],
|
||||
num_direct_distance_codes,
|
||||
|
@ -154,8 +154,9 @@ static int TreeAddSymbol(HuffmanTree* const tree,
|
||||
int i = 1 << (HUFF_LUT_BITS - code_length);
|
||||
base_code = ReverseBitsShort(code, code_length);
|
||||
do {
|
||||
int idx;
|
||||
--i;
|
||||
const int idx = base_code | (i << code_length);
|
||||
idx = base_code | (i << code_length);
|
||||
tree->lut_symbol_[idx] = (int16_t)symbol;
|
||||
tree->lut_bits_[idx] = code_length;
|
||||
} while (i > 0);
|
||||
|
@ -15,7 +15,9 @@
|
||||
// Functions for streaming input and output.
|
||||
|
||||
#include <string.h>
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "./streams.h"
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
@ -37,10 +39,10 @@ int BrotliMemInputFunction(void* data, uint8_t* buf, size_t count) {
|
||||
|
||||
BrotliInput BrotliInitMemInput(const uint8_t* buffer, size_t length,
|
||||
BrotliMemInput* mem_input) {
|
||||
BrotliInput input;
|
||||
mem_input->buffer = buffer;
|
||||
mem_input->length = length;
|
||||
mem_input->pos = 0;
|
||||
BrotliInput input;
|
||||
input.cb_ = &BrotliMemInputFunction;
|
||||
input.data_ = mem_input;
|
||||
return input;
|
||||
@ -58,17 +60,21 @@ int BrotliMemOutputFunction(void* data, const uint8_t* buf, size_t count) {
|
||||
|
||||
BrotliOutput BrotliInitMemOutput(uint8_t* buffer, size_t length,
|
||||
BrotliMemOutput* mem_output) {
|
||||
BrotliOutput output;
|
||||
mem_output->buffer = buffer;
|
||||
mem_output->length = length;
|
||||
mem_output->pos = 0;
|
||||
BrotliOutput output;
|
||||
output.cb_ = &BrotliMemOutputFunction;
|
||||
output.data_ = mem_output;
|
||||
return output;
|
||||
}
|
||||
|
||||
int BrotliStdinInputFunction(void* data, uint8_t* buf, size_t count) {
|
||||
#ifndef _WIN32
|
||||
return read(STDIN_FILENO, buf, count);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
BrotliInput BrotliStdinInput() {
|
||||
@ -79,7 +85,11 @@ BrotliInput BrotliStdinInput() {
|
||||
}
|
||||
|
||||
int BrotliStdoutOutputFunction(void* data, const uint8_t* buf, size_t count) {
|
||||
#ifndef _WIN32
|
||||
return write(STDOUT_FILENO, buf, count);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
BrotliOutput BrotliStdoutOutput() {
|
||||
|
Loading…
Reference in New Issue
Block a user