gpui: Fix SVG color render, when color have alpha (#20537)

Release Notes:

- N/A


## Demo

- [Source
SVG](https://github.com/user-attachments/assets/1c681e01-baba-4613-a3e7-ea5cb3015406)
click here open in browser.

| Before | After |
| --- | --- |
| <img width="1212" alt="image"
src="https://github.com/user-attachments/assets/ba323b13-538b-4a34-bb64-9dcf490aface">
| <img width="1212" alt="image"
src="https://github.com/user-attachments/assets/4635926a-843e-426d-89a1-4e9b4f4cc37e">
|

---------

Co-authored-by: Floyd Wang <gassnake999@gmail.com>
This commit is contained in:
Jason Lee 2024-11-16 22:53:57 +08:00 committed by GitHub
parent 65a9c8d994
commit 932c7e23c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 17 deletions

View file

@ -1,8 +1,8 @@
use crate::{
px, AbsoluteLength, AnyElement, AppContext, Asset, AssetLogger, Bounds, DefiniteLength,
Element, ElementId, GlobalElementId, Hitbox, Image, InteractiveElement, Interactivity,
IntoElement, LayoutId, Length, ObjectFit, Pixels, RenderImage, Resource, SharedString,
SharedUri, StyleRefinement, Styled, SvgSize, Task, WindowContext,
px, swap_rgba_pa_to_bgra, AbsoluteLength, AnyElement, AppContext, Asset, AssetLogger, Bounds,
DefiniteLength, Element, ElementId, GlobalElementId, Hitbox, Image, InteractiveElement,
Interactivity, IntoElement, LayoutId, Length, ObjectFit, Pixels, RenderImage, Resource,
SharedString, SharedUri, StyleRefinement, Styled, SvgSize, Task, WindowContext,
};
use anyhow::{anyhow, Result};
@ -564,9 +564,8 @@ impl Asset for ImageAssetLoader {
let mut buffer =
ImageBuffer::from_raw(pixmap.width(), pixmap.height(), pixmap.take()).unwrap();
// Convert from RGBA to BGRA.
for pixel in buffer.chunks_exact_mut(4) {
pixel.swap(0, 2);
swap_rgba_pa_to_bgra(pixel);
}
RenderImage::new(SmallVec::from_elem(Frame::new(buffer), 1))