|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Raw-DEFLATE compress / decompress over miniz, heap-free. More...
#include "ra8_compress.h"#include <stddef.h>#include <stdint.h>#include <string.h>#include "miniz.h"#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_err.h"Go to the source code of this file.
Data Structures | |
| struct | compress_ctx_t |
| Bounded output sink for the tdefl put-buffer callback. More... | |
Functions | |
| static mz_bool | internal_compress_put (const void *buf, int len, void *user) |
| tdefl put-buffer callback: append len bytes to the bounded output. | |
| static ra8_err_t | internal_ra8_compress_validate (const uint8_t *src, const uint8_t *out, const void *scratch, uint32_t scratch_len, const uint32_t *out_len) |
| Validate ra8_compress arguments before driving the compressor. | |
| static ra8_err_t | internal_ra8_compress_drive (tdefl_compressor *d, compress_ctx_t *ctx, const uint8_t *src, uint32_t src_len, int flags, uint32_t *out_len) |
| Drive the miniz tdefl engine over src into the bounded sink. | |
| ra8_err_t | ra8_compress (const uint8_t *src, uint32_t src_len, uint8_t *out, uint32_t out_cap, void *scratch, uint32_t scratch_len, uint32_t *out_len) |
| Raw-DEFLATE compress src into out. | |
| ra8_err_t | ra8_compress_zlib (const uint8_t *src, uint32_t src_len, uint8_t *out, uint32_t out_cap, void *scratch, uint32_t scratch_len, uint32_t *out_len) |
| Zlib-wrap and DEFLATE-compress one bounded byte range. | |
| ra8_err_t | ra8_decompress (const uint8_t *src, uint32_t src_len, uint8_t *out, uint32_t out_cap, uint32_t *out_len) |
| Raw-DEFLATE decompress src into out. | |
Variables | |
| static const char *const | s_tag = "ra8_compress" |
| Module log tag. | |
Raw-DEFLATE compress / decompress over miniz, heap-free.
Decompression calls tinfl_decompress_mem_to_mem (its working state lives on miniz's SOUP stack, no heap). Compression drives the low-level tdefl engine with a caller-provided tdefl_compressor scratch and a put-buffer callback that appends into the bounded output – so no allocator is touched.
Definition in file ra8_compress.c.
|
static |
tdefl put-buffer callback: append len bytes to the bounded output.
Copies into the caller buffer while space remains; on overflow it flags the context and returns false so tdefl aborts.
| [in] | buf | Bytes emitted by the compressor. |
| [in] | len | Number of bytes emitted (non-negative). |
| [in] | user | The compress_ctx_t sink. |
| MZ_TRUE | Bytes appended. |
| MZ_FALSE | Output buffer full. |
Definition at line 67 of file ra8_compress.c.
References compress_ctx_t::cap, compress_ctx_t::len, memcpy(), compress_ctx_t::out, compress_ctx_t::overflow, and RA8_INTERNAL.
Referenced by internal_ra8_compress_drive().
|
static |
Drive the miniz tdefl engine over src into the bounded sink.
Initializes the caller-provided compressor, runs a single finishing tdefl_compress_buffer pass, then maps overflow / engine status onto ra8_err_t. On success the produced length is taken from the sink.
| [in,out] | d | Caller compressor scratch, reinitialized here. |
| [in,out] | ctx | Bounded output sink (out/cap preset, len grows). |
| [in] | src | Bytes to compress. |
| [in] | src_len | Number of input bytes. |
| [in] | flags | Valid miniz tdefl_init() flags selecting raw or zlib output. |
| [out] | out_len | Compressed byte count on success. |
| k_ra8_ok | Compressed; *out_len set from the sink. |
| k_ra8_err_no_mem | out was too small for the result. |
| k_ra8_fail | The compressor reported an error. |
Definition at line 152 of file ra8_compress.c.
References internal_compress_put(), k_ra8_err_no_mem, k_ra8_fail, k_ra8_ok, compress_ctx_t::len, compress_ctx_t::overflow, and RA8_INTERNAL.
Referenced by ra8_compress(), and ra8_compress_zlib().
|
static |
Validate ra8_compress arguments before driving the compressor.
Performs the four non-NULL precondition checks and the scratch-size lower-bound check, returning the matching ra8_err_t so the public entry point stays small. Kept separate from the compress drive so the validation decisions live in one cohesive block.
| [in] | src | Bytes to compress (checked non-NULL). |
| [in] | out | Destination buffer (checked non-NULL). |
| [in] | scratch | Caller compressor scratch (checked non-NULL). |
| [in] | scratch_len | Size of scratch in bytes (checked >= minimum). |
| [in] | out_len | Result-length out-pointer (checked non-NULL). |
| k_ra8_ok | All arguments are valid. |
| k_ra8_err_null_ptr | Any pointer argument was NULL. |
| k_ra8_err_invalid_size | scratch_len is below the minimum. |
Definition at line 108 of file ra8_compress.c.
References k_ra8_compress_scratch_bytes, k_ra8_err_invalid_size, k_ra8_ok, RA8_CHECK_NULL_PTR, RA8_INTERNAL, and s_tag.
Referenced by ra8_compress(), and ra8_compress_zlib().
|
nodiscard |
Raw-DEFLATE compress src into out.
| [in] | src | Bytes to compress. |
| [in] | src_len | Number of input bytes. |
| [out] | out | Destination for the compressed stream. |
| [in] | out_cap | Capacity of out in bytes. |
| [in] | scratch | Caller buffer >= k_ra8_compress_scratch_bytes, 8-byte aligned (holds the miniz compressor). |
| [in] | scratch_len | Size of scratch in bytes. |
| [out] | out_len | Compressed byte count on success. |
| k_ra8_ok | Compressed; *out_len set. |
| k_ra8_err_null_ptr | Any pointer argument was NULL. |
| k_ra8_err_invalid_size | scratch_len is below the minimum. |
| k_ra8_err_no_mem | out was too small for the result. |
| k_ra8_fail | The compressor reported an error. |
Definition at line 173 of file ra8_compress.c.
References internal_ra8_compress_drive(), internal_ra8_compress_validate(), and k_ra8_ok.
Referenced by internal_encode_tile(), and ra8_vfs_compress_write().
|
nodiscard |
Zlib-wrap and DEFLATE-compress one bounded byte range.
Uses the same caller-owned tdefl_compressor scratch and bounded output sink as ra8_compress, but emits an RFC 1950 zlib stream (two-byte header plus Adler-32 trailer). This is the wire shape used by each independently compressed chunk in an RBKC .rabook container. Keeping the wrapper choice explicit prevents raw RFC 1951 streams from being mislabeled as zlib data.
| [in] | src | Bytes to compress. |
| [in] | src_len | Number of input bytes. |
| [out] | out | Destination for the zlib stream. |
| [in] | out_cap | Writable capacity of out. |
| [in] | scratch | Caller buffer for one tdefl_compressor. |
| [in] | scratch_len | Size of scratch in bytes. |
| [out] | out_len | Receives the complete zlib-stream length. |
| k_ra8_ok | A complete zlib stream was produced. |
| k_ra8_err_null_ptr | A required pointer was NULL. |
| k_ra8_err_invalid_size | Compressor scratch was too small. |
| k_ra8_err_no_mem | The bounded output could not hold the stream. |
| k_ra8_fail | The compressor rejected the input. |
scratch is at least k_ra8_compress_scratch_bytes and 8-byte aligned. out spans out_cap writable bytes. src. Definition at line 190 of file ra8_compress.c.
References internal_ra8_compress_drive(), internal_ra8_compress_validate(), and k_ra8_ok.
Referenced by internal_write_chunks().
|
nodiscard |
Raw-DEFLATE decompress src into out.
| [in] | src | Compressed stream (raw DEFLATE). |
| [in] | src_len | Number of input bytes. |
| [out] | out | Destination for the decompressed bytes. |
| [in] | out_cap | Capacity of out (must hold the whole result). |
| [out] | out_len | Decompressed byte count on success. |
| k_ra8_ok | Decompressed; *out_len set. |
| k_ra8_err_null_ptr | Any pointer argument was NULL. |
| k_ra8_err_no_mem | out was too small, or the stream is corrupt. |
Definition at line 208 of file ra8_compress.c.
References k_ra8_err_no_mem, k_ra8_ok, RA8_CHECK_NULL_PTR, and s_tag.
Referenced by internal_decode_stream(), and ra8_vfs_compress_read().
|
static |
Module log tag.
Definition at line 30 of file ra8_compress.c.