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:
@@ -1,7 +1,8 @@
|
||||
use crate::{
|
||||
point, px, size, Bounds, DevicePixels, Font, FontFallbacks, FontFeatures, FontId, FontMetrics,
|
||||
FontRun, FontStyle, FontWeight, GlyphId, LineLayout, Pixels, PlatformTextSystem, Point,
|
||||
RenderGlyphParams, Result, ShapedGlyph, ShapedRun, SharedString, Size, SUBPIXEL_VARIANTS,
|
||||
point, px, size, swap_rgba_pa_to_bgra, Bounds, DevicePixels, Font, FontFallbacks, FontFeatures,
|
||||
FontId, FontMetrics, FontRun, FontStyle, FontWeight, GlyphId, LineLayout, Pixels,
|
||||
PlatformTextSystem, Point, RenderGlyphParams, Result, ShapedGlyph, ShapedRun, SharedString,
|
||||
Size, SUBPIXEL_VARIANTS,
|
||||
};
|
||||
use anyhow::anyhow;
|
||||
use cocoa::appkit::CGFloat;
|
||||
@@ -418,11 +419,7 @@ impl MacTextSystemState {
|
||||
if params.is_emoji {
|
||||
// Convert from RGBA with premultiplied alpha to BGRA with straight alpha.
|
||||
for pixel in bytes.chunks_exact_mut(4) {
|
||||
pixel.swap(0, 2);
|
||||
let a = pixel[3] as f32 / 255.;
|
||||
pixel[0] = (pixel[0] as f32 / a) as u8;
|
||||
pixel[1] = (pixel[1] as f32 / a) as u8;
|
||||
pixel[2] = (pixel[2] as f32 / a) as u8;
|
||||
swap_rgba_pa_to_bgra(pixel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user