mirror of
https://github.com/cmclark00/retro-imager.git
synced 2025-05-20 17:05:20 +01:00
Qt/QML edition
This commit is contained in:
commit
d7b361ba44
2168 changed files with 721948 additions and 0 deletions
73
dependencies/cmliblzma/liblzma/delta/delta_common.c
vendored
Normal file
73
dependencies/cmliblzma/liblzma/delta/delta_common.c
vendored
Normal file
|
@ -0,0 +1,73 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file delta_common.c
|
||||
/// \brief Common stuff for Delta encoder and decoder
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "delta_common.h"
|
||||
#include "delta_private.h"
|
||||
|
||||
|
||||
static void
|
||||
delta_coder_end(void *coder_ptr, const lzma_allocator *allocator)
|
||||
{
|
||||
lzma_delta_coder *coder = coder_ptr;
|
||||
lzma_next_end(&coder->next, allocator);
|
||||
lzma_free(coder, allocator);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
extern lzma_ret
|
||||
lzma_delta_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
|
||||
const lzma_filter_info *filters)
|
||||
{
|
||||
// Allocate memory for the decoder if needed.
|
||||
lzma_delta_coder *coder = next->coder;
|
||||
if (coder == NULL) {
|
||||
coder = lzma_alloc(sizeof(lzma_delta_coder), allocator);
|
||||
if (coder == NULL)
|
||||
return LZMA_MEM_ERROR;
|
||||
|
||||
next->coder = coder;
|
||||
|
||||
// End function is the same for encoder and decoder.
|
||||
next->end = &delta_coder_end;
|
||||
coder->next = LZMA_NEXT_CODER_INIT;
|
||||
}
|
||||
|
||||
// Validate the options.
|
||||
if (lzma_delta_coder_memusage(filters[0].options) == UINT64_MAX)
|
||||
return LZMA_OPTIONS_ERROR;
|
||||
|
||||
// Set the delta distance.
|
||||
const lzma_options_delta *opt = filters[0].options;
|
||||
coder->distance = opt->dist;
|
||||
|
||||
// Initialize the rest of the variables.
|
||||
coder->pos = 0;
|
||||
memzero(coder->history, LZMA_DELTA_DIST_MAX);
|
||||
|
||||
// Initialize the next decoder in the chain, if any.
|
||||
return lzma_next_filter_init(&coder->next, allocator, filters + 1);
|
||||
}
|
||||
|
||||
|
||||
extern uint64_t
|
||||
lzma_delta_coder_memusage(const void *options)
|
||||
{
|
||||
const lzma_options_delta *opt = options;
|
||||
|
||||
if (opt == NULL || opt->type != LZMA_DELTA_TYPE_BYTE
|
||||
|| opt->dist < LZMA_DELTA_DIST_MIN
|
||||
|| opt->dist > LZMA_DELTA_DIST_MAX)
|
||||
return UINT64_MAX;
|
||||
|
||||
return sizeof(lzma_delta_coder);
|
||||
}
|
20
dependencies/cmliblzma/liblzma/delta/delta_common.h
vendored
Normal file
20
dependencies/cmliblzma/liblzma/delta/delta_common.h
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file delta_common.h
|
||||
/// \brief Common stuff for Delta encoder and decoder
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef LZMA_DELTA_COMMON_H
|
||||
#define LZMA_DELTA_COMMON_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
extern uint64_t lzma_delta_coder_memusage(const void *options);
|
||||
|
||||
#endif
|
78
dependencies/cmliblzma/liblzma/delta/delta_decoder.c
vendored
Normal file
78
dependencies/cmliblzma/liblzma/delta/delta_decoder.c
vendored
Normal file
|
@ -0,0 +1,78 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file delta_decoder.c
|
||||
/// \brief Delta filter decoder
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "delta_decoder.h"
|
||||
#include "delta_private.h"
|
||||
|
||||
|
||||
static void
|
||||
decode_buffer(lzma_delta_coder *coder, uint8_t *buffer, size_t size)
|
||||
{
|
||||
const size_t distance = coder->distance;
|
||||
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
buffer[i] += coder->history[(distance + coder->pos) & 0xFF];
|
||||
coder->history[coder->pos-- & 0xFF] = buffer[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static lzma_ret
|
||||
delta_decode(void *coder_ptr, const 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)
|
||||
{
|
||||
lzma_delta_coder *coder = coder_ptr;
|
||||
|
||||
assert(coder->next.code != NULL);
|
||||
|
||||
const size_t out_start = *out_pos;
|
||||
|
||||
const lzma_ret ret = coder->next.code(coder->next.coder, allocator,
|
||||
in, in_pos, in_size, out, out_pos, out_size,
|
||||
action);
|
||||
|
||||
decode_buffer(coder, out + out_start, *out_pos - out_start);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
extern lzma_ret
|
||||
lzma_delta_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
|
||||
const lzma_filter_info *filters)
|
||||
{
|
||||
next->code = &delta_decode;
|
||||
return lzma_delta_coder_init(next, allocator, filters);
|
||||
}
|
||||
|
||||
|
||||
extern lzma_ret
|
||||
lzma_delta_props_decode(void **options, const lzma_allocator *allocator,
|
||||
const uint8_t *props, size_t props_size)
|
||||
{
|
||||
if (props_size != 1)
|
||||
return LZMA_OPTIONS_ERROR;
|
||||
|
||||
lzma_options_delta *opt
|
||||
= lzma_alloc(sizeof(lzma_options_delta), allocator);
|
||||
if (opt == NULL)
|
||||
return LZMA_MEM_ERROR;
|
||||
|
||||
opt->type = LZMA_DELTA_TYPE_BYTE;
|
||||
opt->dist = props[0] + 1;
|
||||
|
||||
*options = opt;
|
||||
|
||||
return LZMA_OK;
|
||||
}
|
26
dependencies/cmliblzma/liblzma/delta/delta_decoder.h
vendored
Normal file
26
dependencies/cmliblzma/liblzma/delta/delta_decoder.h
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file delta_decoder.h
|
||||
/// \brief Delta filter decoder
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef LZMA_DELTA_DECODER_H
|
||||
#define LZMA_DELTA_DECODER_H
|
||||
|
||||
#include "delta_common.h"
|
||||
|
||||
extern lzma_ret lzma_delta_decoder_init(lzma_next_coder *next,
|
||||
const lzma_allocator *allocator,
|
||||
const lzma_filter_info *filters);
|
||||
|
||||
extern lzma_ret lzma_delta_props_decode(
|
||||
void **options, const lzma_allocator *allocator,
|
||||
const uint8_t *props, size_t props_size);
|
||||
|
||||
#endif
|
125
dependencies/cmliblzma/liblzma/delta/delta_encoder.c
vendored
Normal file
125
dependencies/cmliblzma/liblzma/delta/delta_encoder.c
vendored
Normal file
|
@ -0,0 +1,125 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file delta_encoder.c
|
||||
/// \brief Delta filter encoder
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "delta_encoder.h"
|
||||
#include "delta_private.h"
|
||||
|
||||
|
||||
/// Copies and encodes the data at the same time. This is used when Delta
|
||||
/// is the first filter in the chain (and thus the last filter in the
|
||||
/// encoder's filter stack).
|
||||
static void
|
||||
copy_and_encode(lzma_delta_coder *coder,
|
||||
const uint8_t *restrict in, uint8_t *restrict out, size_t size)
|
||||
{
|
||||
const size_t distance = coder->distance;
|
||||
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
const uint8_t tmp = coder->history[
|
||||
(distance + coder->pos) & 0xFF];
|
||||
coder->history[coder->pos-- & 0xFF] = in[i];
|
||||
out[i] = in[i] - tmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Encodes the data in place. This is used when we are the last filter
|
||||
/// in the chain (and thus non-last filter in the encoder's filter stack).
|
||||
static void
|
||||
encode_in_place(lzma_delta_coder *coder, uint8_t *buffer, size_t size)
|
||||
{
|
||||
const size_t distance = coder->distance;
|
||||
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
const uint8_t tmp = coder->history[
|
||||
(distance + coder->pos) & 0xFF];
|
||||
coder->history[coder->pos-- & 0xFF] = buffer[i];
|
||||
buffer[i] -= tmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static lzma_ret
|
||||
delta_encode(void *coder_ptr, const 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)
|
||||
{
|
||||
lzma_delta_coder *coder = coder_ptr;
|
||||
|
||||
lzma_ret ret;
|
||||
|
||||
if (coder->next.code == NULL) {
|
||||
const size_t in_avail = in_size - *in_pos;
|
||||
const size_t out_avail = out_size - *out_pos;
|
||||
const size_t size = my_min(in_avail, out_avail);
|
||||
|
||||
copy_and_encode(coder, in + *in_pos, out + *out_pos, size);
|
||||
|
||||
*in_pos += size;
|
||||
*out_pos += size;
|
||||
|
||||
ret = action != LZMA_RUN && *in_pos == in_size
|
||||
? LZMA_STREAM_END : LZMA_OK;
|
||||
|
||||
} else {
|
||||
const size_t out_start = *out_pos;
|
||||
|
||||
ret = coder->next.code(coder->next.coder, allocator,
|
||||
in, in_pos, in_size, out, out_pos, out_size,
|
||||
action);
|
||||
|
||||
encode_in_place(coder, out + out_start, *out_pos - out_start);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static lzma_ret
|
||||
delta_encoder_update(void *coder_ptr, const lzma_allocator *allocator,
|
||||
const lzma_filter *filters_null lzma_attribute((__unused__)),
|
||||
const lzma_filter *reversed_filters)
|
||||
{
|
||||
lzma_delta_coder *coder = coder_ptr;
|
||||
|
||||
// Delta doesn't and will never support changing the options in
|
||||
// the middle of encoding. If the app tries to change them, we
|
||||
// simply ignore them.
|
||||
return lzma_next_filter_update(
|
||||
&coder->next, allocator, reversed_filters + 1);
|
||||
}
|
||||
|
||||
|
||||
extern lzma_ret
|
||||
lzma_delta_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
|
||||
const lzma_filter_info *filters)
|
||||
{
|
||||
next->code = &delta_encode;
|
||||
next->update = &delta_encoder_update;
|
||||
return lzma_delta_coder_init(next, allocator, filters);
|
||||
}
|
||||
|
||||
|
||||
extern lzma_ret
|
||||
lzma_delta_props_encode(const void *options, uint8_t *out)
|
||||
{
|
||||
// The caller must have already validated the options, so it's
|
||||
// LZMA_PROG_ERROR if they are invalid.
|
||||
if (lzma_delta_coder_memusage(options) == UINT64_MAX)
|
||||
return LZMA_PROG_ERROR;
|
||||
|
||||
const lzma_options_delta *opt = options;
|
||||
out[0] = opt->dist - LZMA_DELTA_DIST_MIN;
|
||||
|
||||
return LZMA_OK;
|
||||
}
|
24
dependencies/cmliblzma/liblzma/delta/delta_encoder.h
vendored
Normal file
24
dependencies/cmliblzma/liblzma/delta/delta_encoder.h
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file delta_encoder.h
|
||||
/// \brief Delta filter encoder
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef LZMA_DELTA_ENCODER_H
|
||||
#define LZMA_DELTA_ENCODER_H
|
||||
|
||||
#include "delta_common.h"
|
||||
|
||||
extern lzma_ret lzma_delta_encoder_init(lzma_next_coder *next,
|
||||
const lzma_allocator *allocator,
|
||||
const lzma_filter_info *filters);
|
||||
|
||||
extern lzma_ret lzma_delta_props_encode(const void *options, uint8_t *out);
|
||||
|
||||
#endif
|
37
dependencies/cmliblzma/liblzma/delta/delta_private.h
vendored
Normal file
37
dependencies/cmliblzma/liblzma/delta/delta_private.h
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file delta_private.h
|
||||
/// \brief Private common stuff for Delta encoder and decoder
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef LZMA_DELTA_PRIVATE_H
|
||||
#define LZMA_DELTA_PRIVATE_H
|
||||
|
||||
#include "delta_common.h"
|
||||
|
||||
typedef struct {
|
||||
/// Next coder in the chain
|
||||
lzma_next_coder next;
|
||||
|
||||
/// Delta distance
|
||||
size_t distance;
|
||||
|
||||
/// Position in history[]
|
||||
uint8_t pos;
|
||||
|
||||
/// Buffer to hold history of the original data
|
||||
uint8_t history[LZMA_DELTA_DIST_MAX];
|
||||
} lzma_delta_coder;
|
||||
|
||||
|
||||
extern lzma_ret lzma_delta_coder_init(
|
||||
lzma_next_coder *next, const lzma_allocator *allocator,
|
||||
const lzma_filter_info *filters);
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue