Skip to content

Commit

Permalink
Added brotli enc/ and tools/ directories.
Browse files Browse the repository at this point in the history
BUG=332521

Review-Url: https://codereview.chromium.org/1956893002
Cr-Commit-Position: refs/heads/master@{#393898}
  • Loading branch information
smaier authored and Commit bot committed May 16, 2016
1 parent f2ec84d commit cdf50b7
Show file tree
Hide file tree
Showing 58 changed files with 37,761 additions and 33 deletions.
5 changes: 0 additions & 5 deletions third_party/brotli/.gitignore

This file was deleted.

67 changes: 67 additions & 0 deletions third_party/brotli/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,70 @@ source_set("brotli") {

include_dirs = [ "dec" ]
}

if (current_toolchain == host_toolchain) {
executable("bro") {
sources = [
"enc/backward_references.cc",
"enc/backward_references.h",
"enc/bit_cost.h",
"enc/block_splitter.cc",
"enc/block_splitter.h",
"enc/brotli_bit_stream.cc",
"enc/brotli_bit_stream.h",
"enc/cluster.h",
"enc/command.h",
"enc/compress_fragment.cc",
"enc/compress_fragment.h",
"enc/compress_fragment_two_pass.cc",
"enc/compress_fragment_two_pass.h",
"enc/compressor.h",
"enc/context.h",
"enc/dictionary_hash.h",
"enc/encode.cc",
"enc/encode.h",
"enc/encode_parallel.cc",
"enc/encode_parallel.h",
"enc/entropy_encode.cc",
"enc/entropy_encode.h",
"enc/entropy_encode_static.h",
"enc/fast_log.h",
"enc/find_match_length.h",
"enc/hash.h ",
"enc/histogram.cc",
"enc/histogram.h",
"enc/literal_cost.cc",
"enc/literal_cost.h",
"enc/metablock.cc",
"enc/metablock.h",
"enc/port.h ",
"enc/prefix.h",
"enc/ringbuffer.h",
"enc/static_dict.cc",
"enc/static_dict.h",
"enc/static_dict_lut.h",
"enc/streams.cc",
"enc/streams.h",
"enc/transform.h",
"enc/types.h",
"enc/utf8_util.cc",
"enc/utf8_util.h",
"enc/write_bits.h",
"tools/bro.cc",
]
deps = [
":brotli",
]

# Always build release since this is a build tool.
if (is_debug) {
configs -= [ "//build/config:debug" ]
configs += [ "//build/config:release" ]
}
if (is_posix) {
configs -= [ "//build/config/gcc:no_exceptions" ]
} else if (is_win) {
cflags_cc = [ "/EHsc" ]
}
}
}
10 changes: 6 additions & 4 deletions third_party/brotli/README.chromium
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Name: Brotli
URL: https://github.com/google/brotli
Version: 510131d1db47f91602f45b9a8d7b1ee54d12a629
Version: 45f130ac4c5d2abf13e0ed1e9a3e08369c6b9c34
License: MIT
License File: LICENSE
Security Critical: yes
Expand All @@ -11,8 +11,10 @@ byte-compression level in WOFF 2.0 font file format. This library is used
to decode WOFF 2.0 fonts.

Local Modifications:
- This only includes the dec/ directory, the README.md and the LICENSE
files, removing unneeded direcories such as encoder, tests, and tools.
- .gitignore: Added.
- This only includes the enc/, dec/ and tools/ directories, the README.md and
the LICENSE files, removing unneeded direcories such as docs, tests, and
tools.
- BUILD.gn: Added.
- brotli.gyp: Added.
- enc/static_dict_lut.h: split up into two files (enc/static_dict_lut.h,
enc/static_dict_lut2.h) to allow upload to codereview.
35 changes: 35 additions & 0 deletions third_party/brotli/brotli.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/compiled_action.gni")

# Compresses a file with brotli.
#
# Variables
# input_file: Path to input file.
# output_file: Path to output file.
#
template("compress_file_brotli") {
compiled_action(target_name) {
forward_variables_from(invoker,
[
"deps",
"testonly",
])
tool = "//third_party/brotli:bro"
inputs = [
invoker.input_file,
]
outputs = [
invoker.output_file,
]
args = [
"--force",
"--input",
rebase_path(invoker.input_file, root_build_dir),
"--output",
rebase_path(invoker.output_file, root_build_dir),
]
}
}
12 changes: 0 additions & 12 deletions third_party/brotli/dec/Makefile

This file was deleted.

21 changes: 12 additions & 9 deletions third_party/brotli/dec/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ static BROTLI_NOINLINE void InverseMoveToFrontTransform(uint8_t* v,
/* Reinitialize elements that could have been changed. */
uint32_t i = 4;
uint32_t upper_bound = state->mtf_upper_bound;
uint8_t* mtf = state->mtf;
uint8_t* mtf = &state->mtf[4]; /* Make mtf[-1] addressable. */
/* Load endian-aware constant. */
const uint8_t b0123[4] = {0, 1, 2, 3};
uint32_t pattern;
Expand All @@ -856,11 +856,11 @@ static BROTLI_NOINLINE void InverseMoveToFrontTransform(uint8_t* v,
uint8_t value = mtf[index];
upper_bound |= v[i];
v[i] = value;
mtf[-1] = value;
do {
index--;
mtf[index + 1] = mtf[index];
} while (index > 0);
mtf[0] = value;
} while (index >= 0);
}
/* Remember amount of elements to be reinitialized. */
state->mtf_upper_bound = upper_bound;
Expand Down Expand Up @@ -1279,12 +1279,6 @@ static void BROTLI_NOINLINE BrotliCalculateRingBufferSize(BrotliState* s,
}
}

/* Limit custom dictionary size to stream window size. */
if (s->custom_dict_size >= window_size) {
s->custom_dict += s->custom_dict_size - window_size;
s->custom_dict_size = window_size;
}

/* We need at least 2 bytes of ring buffer size to get the last two
bytes for context from there */
if (is_last) {
Expand Down Expand Up @@ -1900,7 +1894,13 @@ BrotliResult BrotliDecompressStream(size_t* available_in,
result = BROTLI_FAILURE();
break;
}
/* Maximum distance, see section 9.1. of the spec. */
s->max_backward_distance = (1 << s->window_bits) - 16;
/* Limit custom dictionary size. */
if (s->custom_dict_size >= s->max_backward_distance) {
s->custom_dict += s->custom_dict_size - s->max_backward_distance;
s->custom_dict_size = s->max_backward_distance;
}
s->max_backward_distance_minus_custom_dict_size =
s->max_backward_distance - s->custom_dict_size;

Expand Down Expand Up @@ -2208,6 +2208,9 @@ BrotliResult BrotliDecompressStream(size_t* available_in,

void BrotliSetCustomDictionary(
size_t size, const uint8_t* dict, BrotliState* s) {
if (size > (1u << 24)) {
return;
}
s->custom_dict = dict;
s->custom_dict_size = (int)size;
}
Expand Down
5 changes: 3 additions & 2 deletions third_party/brotli/dec/decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ BrotliResult BrotliDecompressStream(size_t* available_in,
/* Fills the new state with a dictionary for LZ77, warming up the ringbuffer,
e.g. for custom static dictionaries for data formats.
Not to be confused with the built-in transformable dictionary of Brotli.
The dictionary must exist in memory until decoding is done and is owned by
the caller. To use:
|size| should be less or equal to 2^24 (16MiB), otherwise the dictionary will
be ignored. The dictionary must exist in memory until decoding is done and
is owned by the caller. To use:
1) Allocate and initialize state with BrotliCreateState
2) Use BrotliSetCustomDictionary
3) Use BrotliDecompressStream
Expand Down
2 changes: 1 addition & 1 deletion third_party/brotli/dec/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ struct BrotliStateStruct {

/* For InverseMoveToFrontTransform */
uint32_t mtf_upper_bound;
uint8_t mtf[256];
uint8_t mtf[256 + 4];

/* For custom dictionaries */
const uint8_t* custom_dict;
Expand Down
Loading

0 comments on commit cdf50b7

Please sign in to comment.