Rizin
unix-like reverse engineering framework and cli tools
lzma2_encoder.h File Reference

LZMA2 encoder. More...

#include "common.h"

Go to the source code of this file.

Macros

#define LZMA2_CHUNK_MAX   (UINT32_C(1) << 16)
 Maximum number of bytes of actual data per chunk (no headers) More...
 
#define LZMA2_UNCOMPRESSED_MAX   (UINT32_C(1) << 21)
 Maximum uncompressed size of LZMA chunk (no headers) More...
 
#define LZMA2_HEADER_MAX   6
 Maximum size of LZMA2 headers. More...
 
#define LZMA2_HEADER_UNCOMPRESSED   3
 Size of a header for uncompressed chunk. More...
 

Functions

lzma_ret lzma_lzma2_encoder_init (lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
 
uint64_t lzma_lzma2_encoder_memusage (const void *options)
 
lzma_ret lzma_lzma2_props_encode (const void *options, uint8_t *out)
 
uint64_t lzma_lzma2_block_size (const void *options)
 

Detailed Description

LZMA2 encoder.

Definition in file lzma2_encoder.h.

Macro Definition Documentation

◆ LZMA2_CHUNK_MAX

#define LZMA2_CHUNK_MAX   (UINT32_C(1) << 16)

Maximum number of bytes of actual data per chunk (no headers)

Definition at line 21 of file lzma2_encoder.h.

◆ LZMA2_HEADER_MAX

#define LZMA2_HEADER_MAX   6

Maximum size of LZMA2 headers.

Definition at line 27 of file lzma2_encoder.h.

◆ LZMA2_HEADER_UNCOMPRESSED

#define LZMA2_HEADER_UNCOMPRESSED   3

Size of a header for uncompressed chunk.

Definition at line 30 of file lzma2_encoder.h.

◆ LZMA2_UNCOMPRESSED_MAX

#define LZMA2_UNCOMPRESSED_MAX   (UINT32_C(1) << 21)

Maximum uncompressed size of LZMA chunk (no headers)

Definition at line 24 of file lzma2_encoder.h.

Function Documentation

◆ lzma_lzma2_block_size()

uint64_t lzma_lzma2_block_size ( const void *  options)

Definition at line 404 of file lzma2_encoder.c.

405 {
406  const lzma_options_lzma *const opt = options;
407 
408  // Use at least 1 MiB to keep compression ratio better.
409  return my_max((uint64_t)(opt->dict_size) * 3, UINT64_C(1) << 20);
410 }
static const char struct stat static buf struct stat static buf static vhangup int options
Definition: sflib.h:145
unsigned long uint64_t
Definition: sftypes.h:28
#define UINT64_C(val)
Options specific to the LZMA1 and LZMA2 filters.
Definition: lzma12.h:185
uint32_t dict_size
Dictionary size in bytes.
Definition: lzma12.h:217
#define my_max(x, y)
Definition: sysdefs.h:186

References lzma_options_lzma::dict_size, my_max, options, and UINT64_C.

◆ lzma_lzma2_encoder_init()

lzma_ret lzma_lzma2_encoder_init ( lzma_next_coder next,
const lzma_allocator allocator,
const lzma_filter_info filters 
)

Definition at line 359 of file lzma2_encoder.c.

361 {
362  return lzma_lz_encoder_init(
364 }
const lzma_allocator * allocator
Definition: block.h:377
const lzma_filter * filters
Definition: container.h:315
lzma_ret lzma_lz_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters, lzma_ret(*lz_init)(lzma_lz_encoder *lz, const lzma_allocator *allocator, const void *options, lzma_lz_options *lz_options))
Definition: lz_encoder.c:525
static lzma_ret lzma2_encoder_init(lzma_lz_encoder *lz, const lzma_allocator *allocator, const void *options, lzma_lz_options *lz_options)

References allocator, filters, lzma2_encoder_init(), and lzma_lz_encoder_init().

◆ lzma_lzma2_encoder_memusage()

uint64_t lzma_lzma2_encoder_memusage ( const void *  options)

Definition at line 368 of file lzma2_encoder.c.

369 {
370  const uint64_t lzma_mem = lzma_lzma_encoder_memusage(options);
371  if (lzma_mem == UINT64_MAX)
372  return UINT64_MAX;
373 
374  return sizeof(lzma_lzma2_coder) + lzma_mem;
375 }
uint64_t lzma_lzma_encoder_memusage(const void *options)
Definition: lzma_encoder.c:628
#define UINT64_MAX

References lzma_lzma_encoder_memusage(), options, and UINT64_MAX.

◆ lzma_lzma2_props_encode()

lzma_ret lzma_lzma2_props_encode ( const void *  options,
uint8_t out 
)

Definition at line 379 of file lzma2_encoder.c.

380 {
381  const lzma_options_lzma *const opt = options;
383 
384  // Round up to the next 2^n - 1 or 2^n + 2^(n - 1) - 1 depending
385  // on which one is the next:
386  --d;
387  d |= d >> 2;
388  d |= d >> 3;
389  d |= d >> 4;
390  d |= d >> 8;
391  d |= d >> 16;
392 
393  // Get the highest two bits using the proper encoding:
394  if (d == UINT32_MAX)
395  out[0] = 40;
396  else
397  out[0] = get_dist_slot(d + 1) - 24;
398 
399  return LZMA_OK;
400 }
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
static uint32_t get_dist_slot(uint32_t dist)
Definition: fastpos.h:109
#define LZMA_DICT_SIZE_MIN
Definition: lzma12.h:218
unsigned int uint32_t
Definition: sftypes.h:29
#define d(i)
Definition: sha256.c:44
#define UINT32_MAX
@ LZMA_OK
Operation completed successfully.
Definition: base.h:58

References d, lzma_options_lzma::dict_size, get_dist_slot(), LZMA_DICT_SIZE_MIN, LZMA_OK, my_max, options, out, and UINT32_MAX.