Common filter related types and functions. More...
Data Structures | |
struct | lzma_filter |
Filter options. More... | |
Defines | |
#define | LZMA_FILTERS_MAX 4 |
Maximum number of filters in a chain. | |
Functions | |
lzma_bool | lzma_filter_encoder_is_supported (lzma_vli id) lzma_nothrow lzma_attr_const |
Test if the given Filter ID is supported for encoding. | |
lzma_bool | lzma_filter_decoder_is_supported (lzma_vli id) lzma_nothrow lzma_attr_const |
Test if the given Filter ID is supported for decoding. | |
lzma_ret | lzma_filters_copy (const lzma_filter *src, lzma_filter *dest, lzma_allocator *allocator) lzma_nothrow |
Copy the filters array. | |
uint64_t | lzma_raw_encoder_memusage (const lzma_filter *filters) lzma_nothrow lzma_attr_pure |
Calculate approximate memory requirements for raw encoder. | |
uint64_t | lzma_raw_decoder_memusage (const lzma_filter *filters) lzma_nothrow lzma_attr_pure |
Calculate approximate memory requirements for raw decoder. | |
lzma_ret | lzma_raw_encoder (lzma_stream *strm, const lzma_filter *filters) lzma_nothrow lzma_attr_warn_unused_result |
Initialize raw encoder. | |
lzma_ret | lzma_raw_decoder (lzma_stream *strm, const lzma_filter *filters) lzma_nothrow lzma_attr_warn_unused_result |
Initialize raw decoder. | |
lzma_ret | lzma_filters_update (lzma_stream *strm, const lzma_filter *filters) lzma_nothrow |
Update the filter chain in the encoder. | |
lzma_ret | lzma_raw_buffer_encode (const lzma_filter *filters, lzma_allocator *allocator, const uint8_t *in, size_t in_size, uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow |
Single-call raw encoder. | |
lzma_ret | lzma_raw_buffer_decode (const lzma_filter *filters, lzma_allocator *allocator, const uint8_t *in, size_t *in_pos, size_t in_size, uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow |
Single-call raw decoder. | |
lzma_ret | lzma_properties_size (uint32_t *size, const lzma_filter *filter) lzma_nothrow |
Get the size of the Filter Properties field. | |
lzma_ret | lzma_properties_encode (const lzma_filter *filter, uint8_t *props) lzma_nothrow |
Encode the Filter Properties field. | |
lzma_ret | lzma_properties_decode (lzma_filter *filter, lzma_allocator *allocator, const uint8_t *props, size_t props_size) lzma_nothrow |
Decode the Filter Properties field. | |
lzma_ret | lzma_filter_flags_size (uint32_t *size, const lzma_filter *filter) lzma_nothrow lzma_attr_warn_unused_result |
Calculate encoded size of a Filter Flags field. | |
lzma_ret | lzma_filter_flags_encode (const lzma_filter *filter, uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow lzma_attr_warn_unused_result |
Encode Filter Flags into given buffer. | |
lzma_ret | lzma_filter_flags_decode (lzma_filter *filter, lzma_allocator *allocator, const uint8_t *in, size_t *in_pos, size_t in_size) lzma_nothrow lzma_attr_warn_unused_result |
Decode Filter Flags from given buffer. |
Common filter related types and functions.
#define LZMA_FILTERS_MAX 4 |
Maximum number of filters in a chain.
A filter chain can have 1-4 filters, of which three are allowed to change the size of the data. Usually only one or two filters are needed.
Referenced by coder_add_filter(), lzma_block_header_encode(), lzma_block_header_size(), lzma_filters_copy(), lzma_filters_update(), and parse_block_header().
Test if the given Filter ID is supported for encoding.
Return true if the give Filter ID is supported for encoding by this liblzma build. Otherwise false is returned.
There is no way to list which filters are available in this particular liblzma version and build. It would be useless, because the application couldn't know what kind of options the filter would need.
Test if the given Filter ID is supported for decoding.
Return true if the give Filter ID is supported for decoding by this liblzma build. Otherwise false is returned.
lzma_ret lzma_filters_copy | ( | const lzma_filter * | src, | |
lzma_filter * | dest, | |||
lzma_allocator * | allocator | |||
) |
Copy the filters array.
Copy the Filter IDs and filter-specific options from src to dest. Up to LZMA_FILTERS_MAX filters are copied, plus the terminating .id == LZMA_VLI_UNKNOWN. Thus, dest should have at least LZMA_FILTERS_MAX + 1 elements space unless the caller knows that src is smaller than that.
Unless the filter-specific options is NULL, the Filter ID has to be supported by liblzma, because liblzma needs to know the size of every filter-specific options structure. The filter-specific options are not validated. If options is NULL, any unsupported Filter IDs are copied without returning an error.
Old filter-specific options in dest are not freed, so dest doesn't need to be initialized by the caller in any way.
If an error occurs, memory possibly already allocated by this function is always freed.
References lzma_alloc(), LZMA_FILTERS_MAX, LZMA_VLI_UNKNOWN, and options_size.
uint64_t lzma_raw_encoder_memusage | ( | const lzma_filter * | filters | ) |
Calculate approximate memory requirements for raw encoder.
This function can be used to calculate the memory requirements for Block and Stream encoders too because Block and Stream encoders don't need significantly more memory than raw encoder.
filters | Array of filters terminated with .id == LZMA_VLI_UNKNOWN. |
Referenced by lzma_easy_encoder_memusage(), and lzma_filters_update().
uint64_t lzma_raw_decoder_memusage | ( | const lzma_filter * | filters | ) |
Calculate approximate memory requirements for raw decoder.
This function can be used to calculate the memory requirements for Block and Stream decoders too because Block and Stream decoders don't need significantly more memory than raw decoder.
filters | Array of filters terminated with .id == LZMA_VLI_UNKNOWN. |
Referenced by lzma_easy_decoder_memusage(), and parse_block_header().
lzma_ret lzma_raw_encoder | ( | lzma_stream * | strm, | |
const lzma_filter * | filters | |||
) |
Initialize raw encoder.
This function may be useful when implementing custom file formats.
strm | Pointer to properly prepared lzma_stream | |
filters | Array of lzma_filter structures. The end of the array must be marked with .id = LZMA_VLI_UNKNOWN. |
The `action' with lzma_code() can be LZMA_RUN, LZMA_SYNC_FLUSH (if the filter chain supports it), or LZMA_FINISH.
References lzma_next_strm_init.
Referenced by coder_init().
lzma_ret lzma_raw_decoder | ( | lzma_stream * | strm, | |
const lzma_filter * | filters | |||
) |
Initialize raw decoder.
The initialization of raw decoder goes similarly to raw encoder.
The `action' with lzma_code() can be LZMA_RUN or LZMA_FINISH. Using LZMA_FINISH is not required, it is supported just for convenience.
References lzma_next_strm_init.
Referenced by coder_init().
lzma_ret lzma_filters_update | ( | lzma_stream * | strm, | |
const lzma_filter * | filters | |||
) |
Update the filter chain in the encoder.
This function is for advanced users only. This function has two slightly different purposes:
While rarely useful, this function may be called also when no data has been compressed yet. In that case, this function will behave as if LZMA_FULL_FLUSH (Stream encoder) or LZMA_SYNC_FLUSH (Raw or Block encoder) had been used right before calling this function.
References lzma_filter::id, LZMA_FILTERS_MAX, lzma_raw_encoder_memusage(), and LZMA_VLI_UNKNOWN.
lzma_ret lzma_raw_buffer_encode | ( | const lzma_filter * | filters, | |
lzma_allocator * | allocator, | |||
const uint8_t * | in, | |||
size_t | in_size, | |||
uint8_t * | out, | |||
size_t * | out_pos, | |||
size_t | out_size | |||
) |
Single-call raw encoder.
filters | Array of lzma_filter structures. The end of the array must be marked with .id = LZMA_VLI_UNKNOWN. | |
allocator | lzma_allocator for custom allocator functions. Set to NULL to use malloc() and free(). | |
in | Beginning of the input buffer | |
in_size | Size of the input buffer | |
out | Beginning of the output buffer | |
out_pos | The next byte will be written to out[*out_pos]. *out_pos is updated only if encoding succeeds. | |
out_size | Size of the out buffer; the first byte into which no data is written to is out[out_size]. |
References lzma_next_coder_s::code, lzma_next_coder_s::coder, LZMA_FINISH, LZMA_OK, LZMA_STREAM_END, and return_if_error.
lzma_ret lzma_raw_buffer_decode | ( | const lzma_filter * | filters, | |
lzma_allocator * | allocator, | |||
const uint8_t * | in, | |||
size_t * | in_pos, | |||
size_t | in_size, | |||
uint8_t * | out, | |||
size_t * | out_pos, | |||
size_t | out_size | |||
) |
Single-call raw decoder.
filters | Array of lzma_filter structures. The end of the array must be marked with .id = LZMA_VLI_UNKNOWN. | |
allocator | lzma_allocator for custom allocator functions. Set to NULL to use malloc() and free(). | |
in | Beginning of the input buffer | |
in_pos | The next byte will be read from in[*in_pos]. *in_pos is updated only if decoding succeeds. | |
in_size | Size of the input buffer; the first byte that won't be read is in[in_size]. | |
out | Beginning of the output buffer | |
out_pos | The next byte will be written to out[*out_pos]. *out_pos is updated only if encoding succeeds. | |
out_size | Size of the out buffer; the first byte into which no data is written to is out[out_size]. |
References lzma_next_coder_s::code, lzma_next_coder_s::coder, LZMA_FINISH, LZMA_OK, LZMA_STREAM_END, and return_if_error.
lzma_ret lzma_properties_size | ( | uint32_t * | size, | |
const lzma_filter * | filter | |||
) |
Get the size of the Filter Properties field.
This function may be useful when implementing custom file formats using the raw encoder and decoder.
size | Pointer to uint32_t to hold the size of the properties | |
filter | Filter ID and options (the size of the properties may vary depending on the options) |
References LZMA_OPTIONS_ERROR, LZMA_VLI_MAX, and lzma_filter_encoder::props_size_get.
Referenced by lzma_filter_flags_encode(), and lzma_filter_flags_size().
lzma_ret lzma_properties_encode | ( | const lzma_filter * | filter, | |
uint8_t * | props | |||
) |
Encode the Filter Properties field.
filter | Filter ID and options | |
props | Buffer to hold the encoded options. The size of buffer must have been already determined with lzma_properties_size(). |
References lzma_filter_encoder::props_encode.
Referenced by lzma_filter_flags_encode().
lzma_ret lzma_properties_decode | ( | lzma_filter * | filter, | |
lzma_allocator * | allocator, | |||
const uint8_t * | props, | |||
size_t | props_size | |||
) |
Decode the Filter Properties field.
filter | filter->id must have been set to the correct Filter ID. filter->options doesn't need to be initialized (it's not freed by this function). The decoded options will be stored to filter->options. filter->options is set to NULL if there are no properties or if an error occurs. | |
allocator | Custom memory allocator used to allocate the options. Set to NULL to use the default malloc(), and in case of an error, also free(). | |
props | Input buffer containing the properties. | |
props_size | Size of the properties. This must be the exact size; giving too much or too little input will return LZMA_OPTIONS_ERROR. |
References LZMA_OK, and lzma_filter_decoder::props_decode.
Referenced by is_format_lzma(), lzma_filter_flags_decode(), and lzmainfo().
lzma_ret lzma_filter_flags_size | ( | uint32_t * | size, | |
const lzma_filter * | filter | |||
) |
Calculate encoded size of a Filter Flags field.
Knowing the size of Filter Flags is useful to know when allocating memory to hold the encoded Filter Flags.
size | Pointer to integer to hold the calculated size | |
filter | Filter ID and associated options whose encoded size is to be calculated |
References LZMA_FILTER_RESERVED_START, lzma_properties_size(), lzma_vli_size(), and return_if_error.
Referenced by lzma_block_header_size().
lzma_ret lzma_filter_flags_encode | ( | const lzma_filter * | filter, | |
uint8_t * | out, | |||
size_t * | out_pos, | |||
size_t | out_size | |||
) |
Encode Filter Flags into given buffer.
In contrast to some functions, this doesn't allocate the needed buffer. This is due to how this function is used internally by liblzma.
filter | Filter ID and options to be encoded | |
out | Beginning of the output buffer | |
out_pos | out[*out_pos] is the next write position. This is updated by the encoder. | |
out_size | out[out_size] is the first byte to not write. |
References LZMA_FILTER_RESERVED_START, lzma_properties_encode(), lzma_properties_size(), lzma_vli_encode(), and return_if_error.
Referenced by lzma_block_header_encode().
lzma_ret lzma_filter_flags_decode | ( | lzma_filter * | filter, | |
lzma_allocator * | allocator, | |||
const uint8_t * | in, | |||
size_t * | in_pos, | |||
size_t | in_size | |||
) |
Decode Filter Flags from given buffer.
The decoded result is stored into *filter. The old value of filter->options is not free()d.
References LZMA_FILTER_RESERVED_START, lzma_properties_decode(), lzma_vli_decode(), and return_if_error.
Referenced by lzma_block_header_decode().