Esempio n. 1
0
static void
squash_density_stream_init (SquashDensityStream* stream,
                            SquashCodec* codec,
                            SquashStreamType stream_type,
                            SquashOptions* options,
                            SquashDestroyNotify destroy_notify) {
  squash_stream_init ((SquashStream*) stream, codec, stream_type, (SquashOptions*) options, destroy_notify);

  stream->stream = density_stream_create (NULL, NULL);
  stream->next = SQUASH_DENSITY_ACTION_INIT;

  stream->buffer_size = 0;
  stream->buffer_pos = 0;
  stream->buffer_active = false;

  stream->input_buffer_size = 0;
  stream->input_buffer_active = false;

  stream->active_input_size = 0;

  stream->output_invalid = false;
}
Esempio n. 2
0
#include "buffer.h"

DENSITY_FORCE_INLINE density_buffer_processing_result density_buffer_return_processing_result(density_stream* stream, DENSITY_BUFFER_STATE state) {
    density_buffer_processing_result result;
    result.state = state;
    DENSITY_MEMCPY(&result.bytesRead, stream->totalBytesRead, sizeof(uint64_t));
    DENSITY_MEMCPY(&result.bytesWritten, stream->totalBytesWritten, sizeof(uint64_t));
    density_stream_destroy(stream);

    return result;
}

DENSITY_WINDOWS_EXPORT DENSITY_FORCE_INLINE density_buffer_processing_result density_buffer_compress(const uint8_t *DENSITY_RESTRICT input_buffer, const uint_fast64_t input_size, uint8_t *DENSITY_RESTRICT output_buffer, const uint_fast64_t output_size, const DENSITY_COMPRESSION_MODE compression_mode, const DENSITY_BLOCK_TYPE block_type, void *(*mem_alloc)(size_t), void (*mem_free)(void *)) {
    DENSITY_STREAM_STATE streamState;
    density_stream* stream = density_stream_create(mem_alloc, mem_free);

    streamState = density_stream_prepare(stream, input_buffer, input_size, output_buffer, output_size);
    if(streamState)
        return density_buffer_return_processing_result(stream, DENSITY_BUFFER_STATE_ERROR_DURING_PROCESSING);

    streamState = density_stream_compress_init(stream, compression_mode, block_type);
    switch(streamState) {
        case DENSITY_STREAM_STATE_READY:
            break;
        case DENSITY_STREAM_STATE_ERROR_OUTPUT_BUFFER_TOO_SMALL:
            return density_buffer_return_processing_result(stream, DENSITY_BUFFER_STATE_ERROR_OUTPUT_BUFFER_TOO_SMALL);
        default:
            return density_buffer_return_processing_result(stream, DENSITY_BUFFER_STATE_ERROR_DURING_PROCESSING);
    }