|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Zero-heap WebP decode facade over the vendored libwebp (impl). More...
#include "ra8_webp.h"#include <limits.h>#include <stddef.h>#include <stdint.h>#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_webp_arena.h"#include "src/webp/decode.h"Go to the source code of this file.
Functions | |
| ra8_err_t | ra8_webp_get_info (const uint8_t *data, size_t size, uint32_t *out_w, uint32_t *out_h) |
| Read a WebP header's pixel dimensions without decoding the body. | |
| static ra8_err_t | internal_webp_check_output (const uint8_t *data, size_t size, size_t out_stride, size_t out_capacity, uint32_t *w, uint32_t *h) |
| Read the WebP header and validate the caller's output geometry. | |
| static ra8_err_t | internal_webp_decode_impl (const uint8_t *data, size_t size, ra8_webp_arena_t *arena, uint8_t *out_rgba, size_t out_stride, size_t out_capacity, uint32_t *out_w, uint32_t *out_h) |
Validate geometry, decode the WebP into out_rgba, and report size. | |
| ra8_err_t | ra8_webp_decode_rgba (const uint8_t *data, size_t size, ra8_webp_arena_t *arena, uint8_t *out_rgba, size_t out_stride, size_t out_capacity, uint32_t *out_w, uint32_t *out_h) |
| Decode a WebP into a caller-owned RGBA8888 buffer, heap-free. | |
Variables | |
| static const char | s_ra8_webp_tag [] = "WEBP" |
| Component tag used in validation log lines. | |
Zero-heap WebP decode facade over the vendored libwebp (impl).
See ra8_webp.h for the contract. This TU is the only first-party code that includes libwebp's public src/webp/decode.h; every consumer reaches WebP through the ra8_err_t facade here, never through libwebp directly.
[Ring 4 / WebP] {World: NS}
Definition in file ra8_webp.c.
|
static |
Read the WebP header and validate the caller's output geometry.
Fetches the image dimensions via ra8_webp_get_info(), then checks that the output buffer holds height rows of at least width * 4 bytes and that the stride fits libwebp's int parameter. Extracted from ra8_webp_decode_rgba() so the public entry stays within the NASA Rule 4 function-size budget.
| [in] | data | WebP byte buffer base. |
| [in] | size | Buffer length in bytes. |
| [in] | out_stride | Destination row stride in bytes. |
| [in] | out_capacity | Destination buffer capacity in bytes. |
| [out] | w | Decoded image width on success. |
| [out] | h | Decoded image height on success. |
| k_ra8_ok | Header valid and the output geometry fits. |
| k_ra8_err_validation_failed | Malformed WebP container. |
| k_ra8_err_not_supported | Dimension exceeds the decode cap. |
| k_ra8_err_range_check_failed | Output buffer too small, or stride > INT_MAX. |
data, w and h are non-NULL (caller-guaranteed). size describes the readable extent of data. w and h hold the image dimensions. w and h are not relied upon.Definition at line 92 of file ra8_webp.c.
References k_ra8_err_range_check_failed, k_ra8_ok, k_ra8_webp_bytes_per_px, ra8_log_error, RA8_RETURN_ON_ERROR, ra8_webp_get_info(), and s_ra8_webp_tag.
Referenced by internal_webp_decode_impl().
|
static |
Validate geometry, decode the WebP into out_rgba, and report size.
Runs the decode pipeline after the public entry has null-checked its pointers: output-geometry validation, arena-bound WebPDecodeRGBAInto(), then the optional width/height reporting. Extracted from ra8_webp_decode_rgba() so the public entry stays within the NASA Rule 4 function-size budget.
| [in] | data | WebP byte buffer base (non-NULL, caller-checked). |
| [in] | size | Buffer length in bytes. |
| [in] | arena | Bump allocator libwebp draws its scratch from (non-NULL). |
| [out] | out_rgba | Destination RGBA8888 buffer (non-NULL). |
| [in] | out_stride | Destination row stride in bytes. |
| [in] | out_capacity | Destination buffer capacity in bytes. |
| [out] | out_w | Decoded width, or NULL if unwanted. |
| [out] | out_h | Decoded height, or NULL if unwanted. |
| k_ra8_ok | Decode succeeded; out_rgba filled, sizes reported. |
| k_ra8_err_validation_failed | Malformed WebP or decode failure. |
| k_ra8_err_not_supported | Dimension exceeds the decode cap. |
| k_ra8_err_range_check_failed | Output buffer too small, or stride > INT_MAX. |
data, arena and out_rgba are non-NULL (caller-guaranteed). out_capacity describes the writable extent of out_rgba. out_rgba holds the decoded image. out_w and out_h are not written.Definition at line 145 of file ra8_webp.c.
References internal_webp_check_output(), k_ra8_err_validation_failed, k_ra8_ok, RA8_RETURN_ON_ERROR, ra8_webp_arena_bind(), ra8_webp_arena_unbind(), and s_ra8_webp_tag.
Referenced by ra8_webp_decode_rgba().
|
nodiscard |
Decode a WebP into a caller-owned RGBA8888 buffer, heap-free.
Validates the header via ra8_webp_get_info(), checks the output buffer is large enough for height * stride, binds arena as libwebp's scratch allocator, and calls WebPDecodeRGBAInto to decode straight into out_rgba. The arena supplies every internal allocation, so the decode reaches no malloc; it fully drains before this call returns. Both VP8 (lossy) and VP8L (lossless) WebP bitstreams are handled by the one codec.
| [in] | data | In-memory WebP bytes. Must be non-NULL. |
| [in] | size | Length of data in bytes. Must be non-zero. |
| [in,out] | arena | Scratch arena; reset, used, and drained here. Must be non-NULL and back at least the decode's peak scratch footprint (a few KiB for a thumbnail up to a few MiB for a full page). |
| [out] | out_rgba | Destination RGBA8888 pixels. Must be non-NULL and span at least out_capacity bytes. |
| [in] | out_stride | Destination row stride in bytes; must be at least width * k_ra8_webp_bytes_per_px and <= INT_MAX. |
| [in] | out_capacity | Size of out_rgba in bytes; must be at least height * out_stride. |
| [out] | out_w | Receives the decoded width. May be NULL. |
| [out] | out_h | Receives the decoded height. May be NULL. |
| k_ra8_ok | Decoded; out_rgba filled top-to-bottom. |
| k_ra8_err_null_ptr | data, arena or out_rgba is NULL. |
| k_ra8_err_invalid_arg | size is zero. |
| k_ra8_err_validation_failed | Not a valid WebP, or the decode failed (corrupt body or arena exhausted). |
| k_ra8_err_not_supported | A dimension exceeds k_ra8_webp_max_dim. |
| k_ra8_err_range_check_failed | out_stride / out_capacity too small, or out_stride exceeds INT_MAX. |
arena has base pointing at cap writable bytes and cap >= the decode's peak scratch footprint. out_rgba spans at least out_capacity writable bytes. out_rgba holds height rows of RGBA8888 at out_stride. arena is reset on entry; any prior contents are discarded.Definition at line 187 of file ra8_webp.c.
References internal_webp_decode_impl(), RA8_CHECK_NULL_PTR, and s_ra8_webp_tag.
Referenced by internal_decode_webp(), priv_jof_webp_transcode(), and webp_demo_decode_ok().
|
nodiscard |
Read a WebP header's pixel dimensions without decoding the body.
Wraps libwebp's WebPGetInfo. Validates the RIFF/VP8(L) container and returns the declared canvas size, rejecting a non-WebP buffer or an absurd dimension (> k_ra8_webp_max_dim per axis) so a caller can size an output buffer / arena before committing to a full decode.
| [in] | data | Pointer to the in-memory WebP bytes. Must be non-NULL. |
| [in] | size | Length of data in bytes. Must be non-zero. |
| [out] | out_w | Receives the decoded width in pixels. Must be non-NULL. |
| [out] | out_h | Receives the decoded height in pixels. Must be non-NULL. |
| k_ra8_ok | Header parsed; out_w / out_h set. |
| k_ra8_err_null_ptr | data, out_w or out_h is NULL. |
| k_ra8_err_invalid_arg | size is zero. |
| k_ra8_err_validation_failed | Not a valid WebP / non-positive dims. |
| k_ra8_err_not_supported | A dimension exceeds k_ra8_webp_max_dim. |
data points to at least size readable bytes. out_w and out_h point to writable uint32_t storage. Definition at line 33 of file ra8_webp.c.
References k_ra8_err_invalid_arg, k_ra8_err_not_supported, k_ra8_err_validation_failed, k_ra8_ok, k_ra8_webp_max_dim, RA8_CHECK_NULL_PTR, ra8_log_error, and s_ra8_webp_tag.
Referenced by internal_decode_webp(), internal_probe(), internal_probe_sniff(), internal_webp_check_output(), and priv_jof_webp_transcode().
|
static |
Component tag used in validation log lines.
Definition at line 31 of file ra8_webp.c.
Referenced by internal_webp_check_output(), internal_webp_decode_impl(), ra8_webp_decode_rgba(), and ra8_webp_get_info().