/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// These are slow. Gecko's gfx/2d/Swizzle.cpp has better versions pubfn premultiply(data: &mut [u8]) { for pixel in data.chunks_mut(4) { let a = pixel[3] as u32; let b = pixel[2] as u32; let g = pixel[1] as u32; let r = pixel[0] as u32;
pixel[3] = a as u8;
pixel[2] = ((r * a + 128) / 255) as u8;
pixel[1] = ((g * a + 128) / 255) as u8;
pixel[0] = ((b * a + 128) / 255) as u8;
}
}
#[allow(unused)] pubfn unpremultiply(data: &mut [u8]) { for pixel in data.chunks_mut(4) { let a = pixel[3] as u32; letmut b = pixel[2] as u32; letmut g = pixel[1] as u32; letmut r = pixel[0] as u32;
if a > 0 {
r = r * 255 / a;
g = g * 255 / a;
b = b * 255 / a;
}
pixel[3] = a as u8;
pixel[2] = r as u8;
pixel[1] = g as u8;
pixel[0] = b as u8;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.