mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Reuse input buffer for RGB/UNSIGNED_BYTE in rgba8_image_to_tex_image_data
This commit is contained in:
parent
e1486f7d71
commit
dac7740b8c
1 changed files with 8 additions and 7 deletions
|
@ -4017,14 +4017,15 @@ fn rgba8_image_to_tex_image_data(
|
|||
match (format, data_type) {
|
||||
(TexFormat::RGBA, TexDataType::UnsignedByte) => pixels,
|
||||
(TexFormat::RGB, TexDataType::UnsignedByte) => {
|
||||
// Remove alpha channel
|
||||
let mut rgb8 = Vec::<u8>::with_capacity(pixel_count * 3);
|
||||
for rgba8 in pixels.chunks(4) {
|
||||
rgb8.push(rgba8[0]);
|
||||
rgb8.push(rgba8[1]);
|
||||
rgb8.push(rgba8[2]);
|
||||
for i in 0..pixel_count {
|
||||
let rgb = {
|
||||
let rgb = &pixels[i * 4..i * 4 + 3];
|
||||
[rgb[0], rgb[1], rgb[2]]
|
||||
};
|
||||
pixels[i * 3..i * 3 + 3].copy_from_slice(&rgb);
|
||||
}
|
||||
rgb8
|
||||
pixels.truncate(pixel_count * 3);
|
||||
pixels
|
||||
},
|
||||
(TexFormat::Alpha, TexDataType::UnsignedByte) => {
|
||||
for i in 0..pixel_count {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue