mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +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) {
|
match (format, data_type) {
|
||||||
(TexFormat::RGBA, TexDataType::UnsignedByte) => pixels,
|
(TexFormat::RGBA, TexDataType::UnsignedByte) => pixels,
|
||||||
(TexFormat::RGB, TexDataType::UnsignedByte) => {
|
(TexFormat::RGB, TexDataType::UnsignedByte) => {
|
||||||
// Remove alpha channel
|
for i in 0..pixel_count {
|
||||||
let mut rgb8 = Vec::<u8>::with_capacity(pixel_count * 3);
|
let rgb = {
|
||||||
for rgba8 in pixels.chunks(4) {
|
let rgb = &pixels[i * 4..i * 4 + 3];
|
||||||
rgb8.push(rgba8[0]);
|
[rgb[0], rgb[1], rgb[2]]
|
||||||
rgb8.push(rgba8[1]);
|
};
|
||||||
rgb8.push(rgba8[2]);
|
pixels[i * 3..i * 3 + 3].copy_from_slice(&rgb);
|
||||||
}
|
}
|
||||||
rgb8
|
pixels.truncate(pixel_count * 3);
|
||||||
|
pixels
|
||||||
},
|
},
|
||||||
(TexFormat::Alpha, TexDataType::UnsignedByte) => {
|
(TexFormat::Alpha, TexDataType::UnsignedByte) => {
|
||||||
for i in 0..pixel_count {
|
for i in 0..pixel_count {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue