Add Lian Li SL-INF wireless tools and SignalRGB plugin
Proof-of-concept tools for the UNI FAN SL-INF Wireless kit (SLV3 TX/RX dongles 0416:8040/8041): a Python scan/colour script, tinyuz helpers, a JavaScript tinyuz encoder, the SignalRGB plugin and tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
35240e5dfc
13 files changed
+971
No files matched your search
@@ -0,0 +1,86 @@
|
||||
// C wrapper around tinyuz compression for Rust FFI.
|
||||
// Provides a simple memory-to-memory compression API.
|
||||
//
|
||||
// MIT License — wraps tinyuz (https://github.com/sisong/tinyuz)
|
||||
|
||||
#include "tinyuz/compress/tuz_enc.h"
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
struct MemStreamInput {
|
||||
const unsigned char* data;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
struct MemStreamOutput {
|
||||
unsigned char* buf;
|
||||
size_t capacity;
|
||||
size_t written;
|
||||
};
|
||||
|
||||
static hpatch_BOOL mem_read(const hpatch_TStreamInput* stream,
|
||||
hpatch_StreamPos_t readFromPos,
|
||||
unsigned char* out_data,
|
||||
unsigned char* out_data_end) {
|
||||
auto* ms = (const MemStreamInput*)stream->streamImport;
|
||||
size_t len = (size_t)(out_data_end - out_data);
|
||||
if (readFromPos + len > ms->size) return hpatch_FALSE;
|
||||
memcpy(out_data, ms->data + readFromPos, len);
|
||||
return hpatch_TRUE;
|
||||
}
|
||||
|
||||
static hpatch_BOOL mem_write(const hpatch_TStreamOutput* stream,
|
||||
hpatch_StreamPos_t writeToPos,
|
||||
const unsigned char* data,
|
||||
const unsigned char* data_end) {
|
||||
auto* ms = (MemStreamOutput*)stream->streamImport;
|
||||
size_t len = (size_t)(data_end - data);
|
||||
if (writeToPos + len > ms->capacity) return hpatch_FALSE;
|
||||
memcpy(ms->buf + writeToPos, data, len);
|
||||
size_t end = (size_t)writeToPos + len;
|
||||
if (end > ms->written) ms->written = end;
|
||||
return hpatch_TRUE;
|
||||
}
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
/// Compress `input` using tinyuz with the given dictionary size.
|
||||
///
|
||||
/// Returns the compressed size on success, or 0 on failure.
|
||||
/// `output` must be at least `tuz_maxCompressedSize(input_len)` bytes.
|
||||
size_t tuz_compress_mem(const unsigned char* input, size_t input_len,
|
||||
unsigned char* output, size_t output_capacity,
|
||||
size_t dict_size) {
|
||||
MemStreamInput in_mem = { input, input_len };
|
||||
MemStreamOutput out_mem = { output, output_capacity, 0 };
|
||||
|
||||
hpatch_TStreamInput in_stream;
|
||||
memset(&in_stream, 0, sizeof(in_stream));
|
||||
in_stream.streamImport = (void*)&in_mem;
|
||||
in_stream.streamSize = input_len;
|
||||
in_stream.read = mem_read;
|
||||
|
||||
hpatch_TStreamOutput out_stream;
|
||||
memset(&out_stream, 0, sizeof(out_stream));
|
||||
out_stream.streamImport = (void*)&out_mem;
|
||||
out_stream.streamSize = output_capacity;
|
||||
out_stream.read_writed = nullptr;
|
||||
out_stream.write = mem_write;
|
||||
|
||||
tuz_TCompressProps props = tuz_kDefaultCompressProps;
|
||||
props.dictSize = dict_size;
|
||||
props.threadNum = 1;
|
||||
|
||||
hpatch_StreamPos_t result = tuz_compress(&out_stream, &in_stream, &props);
|
||||
if (result == 0 || result > output_capacity) return 0;
|
||||
return (size_t)result;
|
||||
}
|
||||
|
||||
/// Returns the maximum compressed output size for a given input length.
|
||||
size_t tuz_max_compressed_size(size_t input_len) {
|
||||
return (size_t)tuz_maxCompressedSize(input_len);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
@@ -0,0 +1,25 @@
|
||||
// tuzc: compress stdin with tinyuz (4 KB dict) to stdout; verifies by round-trip.
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#include "tinyuz/decompress/tuz_dec.h"
|
||||
extern "C" size_t tuz_compress_mem(const unsigned char*, size_t, unsigned char*, size_t, size_t);
|
||||
extern "C" size_t tuz_max_compressed_size(size_t);
|
||||
int main() {
|
||||
_setmode(_fileno(stdin), _O_BINARY);
|
||||
_setmode(_fileno(stdout), _O_BINARY);
|
||||
std::vector<unsigned char> in;
|
||||
int c;
|
||||
while ((c = getchar()) != EOF) in.push_back((unsigned char)c);
|
||||
if (in.empty()) return 2;
|
||||
std::vector<unsigned char> out(tuz_max_compressed_size(in.size()));
|
||||
size_t n = tuz_compress_mem(in.data(), in.size(), out.data(), out.size(), 4096);
|
||||
if (n == 0) return 3;
|
||||
std::vector<unsigned char> back(in.size());
|
||||
tuz_size_t back_size = (tuz_size_t)back.size();
|
||||
if (tuz_decompress_mem(out.data(), n, back.data(), &back_size) != tuz_STREAM_END
|
||||
|| back_size != in.size() || back != in) return 4;
|
||||
fwrite(out.data(), 1, n, stdout);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// tuzd <expected_size>: decompress stdin with the reference tinyuz decoder to stdout.
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#include "tinyuz/decompress/tuz_dec.h"
|
||||
int main(int argc, char** argv) {
|
||||
static unsigned char in[65536], out[65536];
|
||||
_setmode(_fileno(stdin), _O_BINARY);
|
||||
_setmode(_fileno(stdout), _O_BINARY);
|
||||
size_t n = fread(in, 1, sizeof(in), stdin);
|
||||
tuz_size_t size = (tuz_size_t)atoi(argv[1]);
|
||||
tuz_TResult r = tuz_decompress_mem(in, (tuz_size_t)n, out, &size);
|
||||
if (r != tuz_STREAM_END) { fprintf(stderr, "decode result %d\n", (int)r); return 1; }
|
||||
fwrite(out, 1, size, stdout);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user