-
Notifications
You must be signed in to change notification settings - Fork 86
Open
Description
The TODO note in encode_png to eliminate the clone of the Pixmap can be addressed by adding a variant function that consumes self. Here's an example I've implemented from the outside:
pub fn into_png(mut image: MaybeFromPool<Pixmap>) -> Result<Vec<u8>, png::EncodingError> {
for pixel in image.pixels_mut() {
unsafe {
// Treat this PremultipliedColorU8 slice as a ColorU8 slice
*pixel = mem::transmute(pixel.demultiply());
}
}
let mut data = Vec::with_capacity(1024 * 1024);
{
let mut encoder = png::Encoder::new(&mut data, image.width(), image.height());
encoder.set_color(png::ColorType::Rgba);
encoder.set_depth(png::BitDepth::Eight);
let mut writer = encoder.write_header()?;
writer.write_image_data(image.data())?;
}
Ok(data)
}Metadata
Metadata
Assignees
Labels
No labels