This commit optimizes the function used to converg rgba pixels into bgra pixels.
This commit is contained in:
parent
08f5591148
commit
77a17cde83
@ -1,7 +1,8 @@
|
|||||||
use crate::image::atlas::{self, Atlas};
|
|
||||||
use iced_native::svg;
|
use iced_native::svg;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
|
use crate::image::atlas::{self, Atlas};
|
||||||
|
|
||||||
pub enum Svg {
|
pub enum Svg {
|
||||||
Loaded(usvg::Tree),
|
Loaded(usvg::Tree),
|
||||||
NotFound,
|
NotFound,
|
||||||
@ -111,26 +112,13 @@ impl Cache {
|
|||||||
let width = img.width();
|
let width = img.width();
|
||||||
let height = img.height();
|
let height = img.height();
|
||||||
|
|
||||||
let mut rgba = img.take().into_iter();
|
let mut rgba = img.take();
|
||||||
|
rgba.chunks_exact_mut(4).for_each(|rgba| rgba.swap(0, 2));
|
||||||
// TODO: Perform conversion in the GPU
|
|
||||||
let bgra: Vec<u8> = std::iter::from_fn(move || {
|
|
||||||
use std::iter::once;
|
|
||||||
|
|
||||||
let r = rgba.next()?;
|
|
||||||
let g = rgba.next()?;
|
|
||||||
let b = rgba.next()?;
|
|
||||||
let a = rgba.next()?;
|
|
||||||
|
|
||||||
Some(once(b).chain(once(g)).chain(once(r)).chain(once(a)))
|
|
||||||
})
|
|
||||||
.flatten()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let allocation = texture_atlas.upload(
|
let allocation = texture_atlas.upload(
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
bytemuck::cast_slice(bgra.as_slice()),
|
bytemuck::cast_slice(rgba.as_slice()),
|
||||||
device,
|
device,
|
||||||
encoder,
|
encoder,
|
||||||
)?;
|
)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user