Expand description
Translation of src/dec/buffer_dec.c from libwebp v1.6.0.
Work package: WP12 (decoder integration).
The samples of a buffer are one PlaneStorage (ADR 0003, buffers and
planes): Internal is C’s private_memory, External the caller’s memory of
is_external_memory. A C plane pointer is NULL here when the buffer holds
no memory of its own (an empty Internal storage is C’s
private_memory == NULL) or when its region does not exist in the caller’s
storage (the C ABI gives a NULL plane no region); an empty caller slice is
a pointer to no bytes, as in C. The
member of the u union that C reads is the one that the colorspace selects;
a Rust buffer whose u holds the other member describes no valid plane, and
CheckDecBuffer rejects it (# Deviations from upstream, item 2).
C’s is_external_memory >= 2, slow external memory, is the buffer’s
slow_memory flag (ADR 0003, amended 2026-11-07).
§Deviations from upstream
Changes of representation that the ADRs allow, or behavior that the Rust side cannot reproduce exactly. Each records the reason.
- Freeing.
WebPFreeDecBufferdrops library memory;WebPInitDecBufferandWebPInitDecoderConfigdrop the old storage, where C zeroes the structure without freeing it. - Mismatched union member. A Rust buffer whose
uholds the member that the colorspace does not select reads as a zeroed member (ADR 0003), soCheckDecBufferrejects it and the incremental getters write zeros, as C does for its zeroed union before allocation. C would reinterpret arbitrary bytes of the other member; only Rust callers can build such a buffer, and the C ABI reads the member that the colorspace selects.
§Checks not applicable
These checks do not apply, or cannot be made, with the reason:
WebPGrabDecBufferhas no caller in libwebp v1.6.0 and is not exported (webpi_dec.his internal); it is translated and not compared.
Functions§
- is_
null_ plane - Whether the plane is C’s
NULLpointer (see the module documentation). - is_
valid_ colorspace - Converts to an integer to handle both the unsigned and the signed enum
cases, as C does: callers pass the colorspace as an
int(C declares the function insrc/dec/common_dec.h). - webp_
allocate_ dec_ buffer - Prepares
bufferwith the requested initial dimensionswidthandheight. If no external storage is supplied, initializes the buffer by allocating output memory and setting up the stride information. Validates the parameters. Ifoptionsis notNone, also verifies that the options’ parameters are valid and applies them to the width and height of the output buffer: cropping, scaling and the vertical flip. C returnsVP8_STATUS_INVALID_PARAMfor aNULLbuffer, which exists only at the C ABI. - webp_
avoid_ slow_ memory - Returns true if decoding will be slow with the current configuration and bitstream features: slow external memory, a premultiplied colorspace and an image with alpha.
- webp_
copy_ dec_ buffer - Copies
srcintodst, making suredstdoes not own the memory, whichsrcstill holds. No pixels are copied:dstgets a shared view of every region ofsrc, with the same plane offsets, where C copies the pointers and marksdstas external. C acceptsNULLbuffers, which exist only at the C ABI. - webp_
copy_ dec_ buffer_ pixels - Copies the pixels of
src_bufinto the preallocateddst_buf. - webp_
flip_ buffer - Flips the buffer vertically by negating the various strides. C returns
VP8_STATUS_INVALID_PARAMfor aNULLbuffer, which exists only at the C ABI. - webp_
free_ dec_ buffer - Frees any memory associated with the buffer: the memory that the buffer
allocated itself. External memory stays the caller’s, and the buffer keeps
describing it, as C keeps the plane pointers. C accepts a
NULLbuffer, which exists only at the C ABI. - webp_
grab_ dec_ buffer - Copies and transfers ownership from
srctodst(beware of the parameter order).dstreceives the storage ofsrc. In C,srckeeps pointers to the memory, now marked external; safe Rust cannot keep a second view of memory thatdstowns or borrows mutably, sosrckeeps its plane descriptions with an empty storage of the same kind. C acceptsNULLbuffers, which exist only at the C ABI. - webp_
init_ dec_ buffer_ internal - Internal, version-checked, entry point of
WebPInitDecBuffer: resets the buffer to empty unless the ABI versions are incompatible. Returns false in case of version mismatch. C also returns 0 for aNULLbuffer, which exists only at the C ABI. C zeroes the structure without freeing it; here the old storage is dropped.