2008-01-22 21:49:24 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2009-02-17 09:43:00 +01:00
|
|
|
/// \file easy_encoder.c
|
|
|
|
/// \brief Easy .xz Stream encoder initialization
|
2008-01-22 21:49:24 +01:00
|
|
|
//
|
2009-04-13 10:27:40 +02:00
|
|
|
// Author: Lasse Collin
|
2008-01-22 21:49:24 +01:00
|
|
|
//
|
2009-04-13 10:27:40 +02:00
|
|
|
// This file has been put into the public domain.
|
|
|
|
// You can do whatever you want with this file.
|
2008-01-22 21:49:24 +01:00
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-02-17 09:43:00 +01:00
|
|
|
#include "easy_preset.h"
|
2008-06-18 17:02:10 +02:00
|
|
|
#include "stream_encoder.h"
|
2008-01-22 21:49:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
struct lzma_coder_s {
|
2008-06-18 17:02:10 +02:00
|
|
|
lzma_next_coder stream_encoder;
|
2009-02-17 09:43:00 +01:00
|
|
|
lzma_options_easy opt_easy;
|
2008-01-22 21:49:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static lzma_ret
|
|
|
|
easy_encode(lzma_coder *coder, lzma_allocator *allocator,
|
|
|
|
const uint8_t *restrict in, size_t *restrict in_pos,
|
|
|
|
size_t in_size, uint8_t *restrict out,
|
|
|
|
size_t *restrict out_pos, size_t out_size, lzma_action action)
|
|
|
|
{
|
2008-06-18 17:02:10 +02:00
|
|
|
return coder->stream_encoder.code(
|
|
|
|
coder->stream_encoder.coder, allocator,
|
2008-01-22 21:49:24 +01:00
|
|
|
in, in_pos, in_size, out, out_pos, out_size, action);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
easy_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
|
|
|
|
{
|
2008-08-28 21:53:15 +02:00
|
|
|
lzma_next_end(&coder->stream_encoder, allocator);
|
2008-01-22 21:49:24 +01:00
|
|
|
lzma_free(coder, allocator);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static lzma_ret
|
|
|
|
easy_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
|
2008-12-27 18:27:49 +01:00
|
|
|
uint32_t preset, lzma_check check)
|
2008-01-22 21:49:24 +01:00
|
|
|
{
|
2009-04-28 22:08:32 +02:00
|
|
|
lzma_next_coder_init(&easy_encoder_init, next, allocator);
|
2008-08-28 21:53:15 +02:00
|
|
|
|
2008-01-22 21:49:24 +01:00
|
|
|
if (next->coder == NULL) {
|
|
|
|
next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
|
|
|
|
if (next->coder == NULL)
|
|
|
|
return LZMA_MEM_ERROR;
|
|
|
|
|
|
|
|
next->code = &easy_encode;
|
|
|
|
next->end = &easy_encoder_end;
|
|
|
|
|
2008-06-18 17:02:10 +02:00
|
|
|
next->coder->stream_encoder = LZMA_NEXT_CODER_INIT;
|
2008-01-22 21:49:24 +01:00
|
|
|
}
|
|
|
|
|
2009-02-17 09:43:00 +01:00
|
|
|
if (lzma_easy_preset(&next->coder->opt_easy, preset))
|
2008-09-13 11:10:43 +02:00
|
|
|
return LZMA_OPTIONS_ERROR;
|
2008-01-22 21:49:24 +01:00
|
|
|
|
2008-06-18 17:02:10 +02:00
|
|
|
return lzma_stream_encoder_init(&next->coder->stream_encoder,
|
2009-02-17 09:43:00 +01:00
|
|
|
allocator, next->coder->opt_easy.filters, check);
|
2008-01-22 21:49:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-02 19:14:03 +01:00
|
|
|
extern LZMA_API(lzma_ret)
|
2008-12-27 18:27:49 +01:00
|
|
|
lzma_easy_encoder(lzma_stream *strm, uint32_t preset, lzma_check check)
|
2008-01-22 21:49:24 +01:00
|
|
|
{
|
2008-12-27 18:27:49 +01:00
|
|
|
lzma_next_strm_init(easy_encoder_init, strm, preset, check);
|
2008-01-22 21:49:24 +01:00
|
|
|
|
|
|
|
strm->internal->supported_actions[LZMA_RUN] = true;
|
|
|
|
strm->internal->supported_actions[LZMA_SYNC_FLUSH] = true;
|
|
|
|
strm->internal->supported_actions[LZMA_FULL_FLUSH] = true;
|
|
|
|
strm->internal->supported_actions[LZMA_FINISH] = true;
|
|
|
|
|
|
|
|
return LZMA_OK;
|
|
|
|
}
|