Skip to main content

alpha_byte_truncating

Function alpha_byte_truncating 

Source
pub fn alpha_byte_truncating(alpha: f32) -> u8
Expand description

alpha * 255 cast to an integer: truncating, so ca 0.5 is 127.

alpha_byte_rounding is the other conversion; the two differ on a large fraction of real ca values.

use pdfrum_render::pixmap::alpha_byte_truncating;

// Truncating, so a `ca 0.5` is 127 rather than 128.
assert_eq!(alpha_byte_truncating(0.5), 127);
assert_eq!(alpha_byte_truncating(1.0), 255);