pub fn encode(
pixels: &[u8],
total_pixels: u32,
mode: EncodeMode,
) -> Result<Option<(u8, Vec<u8>)>>Expand description
Encode a layer mask, choosing the tag per mode.
Returns None for an all-black layer, which is stored as the empty-layer
form with no bytes at all.
The returned bytes are the mask data a layer stores: the tag, then the stream. The tag is returned alongside them so a caller can log or branch on the choice, not so it can be re-prepended.
The mask is walked run by run as it is encoded, so no vector of runs is built
for it; encode_runs is the same encoder for a caller who already holds the
runs.