Giter Club home page Giter Club logo

Comments (4)

yjh0502 avatar yjh0502 commented on August 22, 2024

Some errors could be fixed by un-premultiplying colors from egui.

diff --git a/src/painter.rs b/src/painter.rs
index 5c07f5b..8696332 100644
--- a/src/painter.rs
+++ b/src/painter.rs
@@ -205,11 +205,19 @@ impl Painter {
 
                             pos.push(Point::new(fixed_pos.x, fixed_pos.y));
                             texs.push(Point::new(v.uv.x, v.uv.y));
+
+                            let c = v.color;
+                            let c = Color::from_argb(c.a(), c.r(), c.g(), c.b());
+                            // un-premultply color
+                            let mut cf = skia_safe::Color4f::from(c);
+                            cf.r /= cf.a;
+                            cf.g /= cf.a;
+                            cf.b /= cf.a;
                             colors.push(Color::from_argb(
-                                v.color.a(),
-                                v.color.r(),
-                                v.color.g(),
-                                v.color.b(),
+                                c.a(),
+                                (cf.r * 255.0) as u8,
+                                (cf.g * 255.0) as u8,
+                                (cf.b * 255.0) as u8,
                             ));
                         });

output

from egui_skia.

lucasmerlin avatar lucasmerlin commented on August 22, 2024

Hi! I applied your fix in #7, improving on the color test results. But as you already mentioned it's not perfect yet so I'll leave this issue open for now.
I also tested if I could get this to work by changing the type of the created skia texture but it didn't seem to make any difference.
Happy to accept a PR if someone figures out how to fix the additive blending and linear interpolation test cases!

from egui_skia.

jb55 avatar jb55 commented on August 22, 2024

The colors on rendered images are all messed up (weird pink tinge), I wonder if this is related?

from egui_skia.

jb55 avatar jb55 commented on August 22, 2024

I tried rendering a gradient texture and when I sample the color with a color picker, the red and the blue components appear to be swapped. I fixed it with this:

let scol = [0x1E, 0x55, 0xFF];
let ecol = [0xFA, 0x0D, 0xD4];

 // TODO: skia has r/b colors swapped for some reason, fix this
let start_color = Color32::from_rgb(scol[2], scol[1], scol[0]);
let end_color = Color32::from_rgb(ecol[2], ecol[1], ecol[0]);

let gradient = Gradient::linear(start_color, end_color);

before: https://cdn.jb55.com/s/0cdefad30a081797.png
after swapping r/b: https://cdn.jb55.com/s/2da42af5f9f69756.png

from egui_skia.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.