Donner 0.5.1
Embeddable browser-grade SVG2 engine
Loading...
Searching...
No Matches
PixelFormatUtils.h File Reference

Shared RGBA8 pixel-format conversion helpers used across Donner's renderer backends and the compositor. Split out from FilterGraphExecutor.h and CompositorController.cc so that callers which don't otherwise depend on the filter graph or the compositor can still premul / unpremul without pulling those in. More...

#include <cstdint>
#include <span>
#include <vector>
Include dependency graph for PixelFormatUtils.h:
This graph shows which files directly or indirectly include this file:

Namespaces

namespace  donner
 Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css.
namespace  donner::svg
 Donner SVG library, which can load, manipulate and render SVG files.

Functions

std::vector< std::uint8_t > donner::svg::PremultiplyRgba (std::span< const std::uint8_t > rgbaPixels)
 Convert tightly-packed straight-alpha RGBA8 to premultiplied RGBA8.
void donner::svg::UnpremultiplyRgbaInPlace (std::vector< std::uint8_t > &rgba)
 Convert tightly-packed premultiplied RGBA8 to straight-alpha RGBA8, in place. Fully-opaque pixels (alpha == 255) are unchanged; fully-transparent pixels (alpha == 0) become (0, 0, 0, 0).
std::vector< std::uint8_t > donner::svg::UnpremultiplyRgba (std::span< const std::uint8_t > rgbaPixels)
 Non-mutating variant of UnpremultiplyRgbaInPlace that allocates. Prefer the in-place form on hot paths; use this when the caller needs to preserve the input.

Detailed Description

Shared RGBA8 pixel-format conversion helpers used across Donner's renderer backends and the compositor. Split out from FilterGraphExecutor.h and CompositorController.cc so that callers which don't otherwise depend on the filter graph or the compositor can still premul / unpremul without pulling those in.

Byte layout: tightly packed RGBA, 4 bytes/pixel. rgba.size() % 4 must be 0; unaligned tails are ignored (matches the pre-split behavior of every caller that had its own local copy).

Rounding convention: integer round-half-up in both directions, so a round-trip premul → unpremul is bit-identical for every well-formed premul input (i.e., r ≤ a, g ≤ a, b ≤ a). If a caller has out-of-range premul input, that is a bug upstream; these helpers will clamp to 255 without corrupting alpha.