126fa459cSmrg/* Copyright 2015 Google Inc. All Rights Reserved.
226fa459cSmrg
326fa459cSmrg   Distributed under MIT license.
426fa459cSmrg   See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
526fa459cSmrg*/
626fa459cSmrg
726fa459cSmrg/* Function for fast encoding of an input fragment, independently from the input
826fa459cSmrg   history. This function uses two-pass processing: in the first pass we save
926fa459cSmrg   the found backward matches and literal bytes into a buffer, and in the
1026fa459cSmrg   second pass we emit them into the bit stream using prefix codes built based
1126fa459cSmrg   on the actual command and literal byte histograms. */
1226fa459cSmrg
1326fa459cSmrg#ifndef BROTLI_ENC_COMPRESS_FRAGMENT_TWO_PASS_H_
1426fa459cSmrg#define BROTLI_ENC_COMPRESS_FRAGMENT_TWO_PASS_H_
1526fa459cSmrg
1626fa459cSmrg#include "../common/platform.h"
1726fa459cSmrg#include <brotli/types.h>
1826fa459cSmrg#include "./memory.h"
1926fa459cSmrg
2026fa459cSmrg#if defined(__cplusplus) || defined(c_plusplus)
2126fa459cSmrgextern "C" {
2226fa459cSmrg#endif
2326fa459cSmrg
2426fa459cSmrgstatic const size_t kCompressFragmentTwoPassBlockSize = 1 << 17;
2526fa459cSmrg
2626fa459cSmrg/* Compresses "input" string to the "*storage" buffer as one or more complete
2726fa459cSmrg   meta-blocks, and updates the "*storage_ix" bit position.
2826fa459cSmrg
2926fa459cSmrg   If "is_last" is 1, emits an additional empty last meta-block.
3026fa459cSmrg
3126fa459cSmrg   REQUIRES: "input_size" is greater than zero, or "is_last" is 1.
3226fa459cSmrg   REQUIRES: "input_size" is less or equal to maximal metablock size (1 << 24).
3326fa459cSmrg   REQUIRES: "command_buf" and "literal_buf" point to at least
3426fa459cSmrg              kCompressFragmentTwoPassBlockSize long arrays.
3526fa459cSmrg   REQUIRES: All elements in "table[0..table_size-1]" are initialized to zero.
3626fa459cSmrg   REQUIRES: "table_size" is a power of two
3726fa459cSmrg   OUTPUT: maximal copy distance <= |input_size|
3826fa459cSmrg   OUTPUT: maximal copy distance <= BROTLI_MAX_BACKWARD_LIMIT(18) */
3926fa459cSmrgBROTLI_INTERNAL void BrotliCompressFragmentTwoPass(MemoryManager* m,
4026fa459cSmrg                                                   const uint8_t* input,
4126fa459cSmrg                                                   size_t input_size,
4226fa459cSmrg                                                   BROTLI_BOOL is_last,
4326fa459cSmrg                                                   uint32_t* command_buf,
4426fa459cSmrg                                                   uint8_t* literal_buf,
4526fa459cSmrg                                                   int* table,
4626fa459cSmrg                                                   size_t table_size,
4726fa459cSmrg                                                   size_t* storage_ix,
4826fa459cSmrg                                                   uint8_t* storage);
4926fa459cSmrg
5026fa459cSmrg#if defined(__cplusplus) || defined(c_plusplus)
5126fa459cSmrg}  /* extern "C" */
5226fa459cSmrg#endif
5326fa459cSmrg
5426fa459cSmrg#endif  /* BROTLI_ENC_COMPRESS_FRAGMENT_TWO_PASS_H_ */
55