-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Add option to force compressed data to be byte aligned #49
Draft
ryancdotorg
wants to merge
6
commits into
dropbox:master
Choose a base branch
from
ryancdotorg:bytealign
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0e9d03c
bytealign mode: basic functionality
ryancdotorg 2877641
don't emit empty penultimate metadata block unless needed
ryancdotorg 34182ee
byte aligning the start of an appendable is pointless
ryancdotorg c44ecc7
add option for bare stream
ryancdotorg 0f746e5
no bytealign unless catable, appendable, or bare
ryancdotorg df6a88e
try to plumb ffi apis
ryancdotorg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,8 @@ use super::block_split::BlockSplit; | |
use super::brotli_bit_stream::{BrotliBuildAndStoreHuffmanTreeFast, BrotliStoreHuffmanTree, | ||
BrotliStoreMetaBlock, BrotliStoreMetaBlockFast, | ||
BrotliStoreMetaBlockTrivial, BrotliStoreUncompressedMetaBlock, | ||
BrotliWriteEmptyLastMetaBlock, BrotliWriteMetadataMetaBlock, | ||
BrotliWriteEmptyLastMetaBlock, | ||
BrotliWritePaddingMetaBlock, BrotliWriteMetadataMetaBlock, | ||
MetaBlockSplit, RecoderState, JumpToByteBoundary}; | ||
|
||
use enc::input_pair::InputReferenceMut; | ||
|
@@ -340,6 +341,17 @@ value: u32) -> i32 { | |
params.favor_cpu_efficiency = value != 0; | ||
return 1i32; | ||
} | ||
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_BYTE_ALIGN as (i32) { | ||
params.byte_align = value != 0; | ||
return 1i32; | ||
} | ||
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_BARE_STREAM as (i32) { | ||
params.bare_stream = value != 0; | ||
if !params.byte_align { | ||
params.byte_align = value != 0; | ||
} | ||
return 1i32; | ||
} | ||
0i32 | ||
} | ||
|
||
|
@@ -397,6 +409,8 @@ pub fn BrotliEncoderInitParams() -> BrotliEncoderParams { | |
cdf_adaptation_detection: 0, | ||
prior_bitmask_detection: 0, | ||
literal_adaptation: [(0,0);4], | ||
byte_align: false, | ||
bare_stream: false, | ||
catable: false, | ||
use_dictionary: true, | ||
appendable: false, | ||
|
@@ -621,7 +635,12 @@ pub fn SanitizeParams(params: &mut BrotliEncoderParams) { | |
} | ||
} | ||
if params.catable { | ||
params.appendable = true; | ||
params.appendable = true; | ||
} | ||
if params.bare_stream { | ||
params.byte_align = true; | ||
} else if !params.appendable { | ||
params.byte_align = false; | ||
} | ||
} | ||
|
||
|
@@ -721,7 +740,9 @@ fn EnsureInitialized<Alloc: BrotliAlloc> | |
if (*s).params.quality == 0i32 || (*s).params.quality == 1i32 { | ||
lgwin = brotli_max_int(lgwin, 18i32); | ||
} | ||
EncodeWindowBits(lgwin, s.params.large_window, &mut (*s).last_bytes_, &mut (*s).last_bytes_bits_); | ||
if !((*s).params.catable && (*s).params.bare_stream) { | ||
EncodeWindowBits(lgwin, s.params.large_window, &mut (*s).last_bytes_, &mut (*s).last_bytes_bits_); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to do |
||
} | ||
} | ||
if (*s).params.quality == 0i32 { | ||
InitCommandPrefixCodes(&mut (*s).cmd_depths_[..], | ||
|
@@ -1948,6 +1969,15 @@ fn DecideOverLiteralContextModeling(input: &[u8], | |
literal_context_map); | ||
} | ||
} | ||
fn WriteEmptyLastBlocksInternal(params: &BrotliEncoderParams, storage_ix: &mut usize, storage: &mut [u8]) { | ||
// insert empty block for byte alignment if required | ||
if params.byte_align { | ||
BrotliWritePaddingMetaBlock(storage_ix, storage); | ||
} | ||
if !params.bare_stream { | ||
BrotliWriteEmptyLastMetaBlock(storage_ix, storage) | ||
} | ||
} | ||
fn WriteMetaBlockInternal<Alloc: BrotliAlloc, | ||
Cb> | ||
(alloc: &mut Alloc, | ||
|
@@ -1975,7 +2005,7 @@ fn WriteMetaBlockInternal<Alloc: BrotliAlloc, | |
&mut [interface::StaticCommand], | ||
interface::InputPair, &mut Alloc) { | ||
let actual_is_last = is_last; | ||
if params.appendable { | ||
if params.appendable || params.byte_align { | ||
is_last = 0; | ||
} else { | ||
assert_eq!(params.catable, false); // Sanitize Params senforces this constraint | ||
|
@@ -1986,8 +2016,7 @@ fn WriteMetaBlockInternal<Alloc: BrotliAlloc, | |
let literal_context_lut = BROTLI_CONTEXT_LUT(literal_context_mode); | ||
let mut block_params = params.clone(); | ||
if bytes == 0usize { | ||
BrotliWriteBits(2usize, 3, storage_ix, storage); | ||
*storage_ix = (*storage_ix).wrapping_add(7u32 as (usize)) & !7u32 as (usize); | ||
WriteEmptyLastBlocksInternal(params, storage_ix, storage); | ||
return; | ||
} | ||
if ShouldCompress(data, | ||
|
@@ -2010,7 +2039,7 @@ fn WriteMetaBlockInternal<Alloc: BrotliAlloc, | |
false, | ||
cb); | ||
if actual_is_last != is_last { | ||
BrotliWriteEmptyLastMetaBlock(storage_ix, storage) | ||
WriteEmptyLastBlocksInternal(params, storage_ix, storage); | ||
} | ||
return; | ||
} | ||
|
@@ -2150,7 +2179,7 @@ fn WriteMetaBlockInternal<Alloc: BrotliAlloc, | |
cb); | ||
} | ||
if actual_is_last != is_last { | ||
BrotliWriteEmptyLastMetaBlock(storage_ix, storage) | ||
WriteEmptyLastBlocksInternal(params, storage_ix, storage); | ||
} | ||
} | ||
|
||
|
@@ -2247,6 +2276,10 @@ fn EncodeData<Alloc: BrotliAlloc, | |
*out_size = catable_header_size; | ||
s.is_first_mb = IsFirst::HeaderWritten; | ||
} | ||
// fixup for empty stream - note: catable is always appendable | ||
if bytes == 0 && s.params.byte_align && s.params.appendable && !s.params.catable { | ||
BrotliWritePaddingMetaBlock(&mut storage_ix, (*s).storage_.slice_mut()); | ||
} | ||
} | ||
if let IsFirst::BothCatableBytesWritten = s.is_first_mb { | ||
// nothing to do here, move along | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
if p == BrotliEncoderParameter::BROTLI_PARAM_BYTE_ALIGN
should compile on rust 1.12? (I know that the rest of the code in this function uses the other convention, but from what I understand, this is all machine generated, and not how you'd naturally write the code).