--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/309427be-62c6-426e-9e6e-590c25f59420n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/9bdb2f5b-6393-4b9f-b292-ef01c6cf38cbn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/9bdb2f5b-6393-4b9f-b292-ef01c6cf38cbn%40googlegroups.com.
class CustomView: NSView {
override func draw(_ dirtyRect: NSRect) {
let context = NSGraphicsContext.current!.cgContext
let rect = NSRect(x: 0, y: 0, width: 480, height: 480)
let image = NSImage(named: "Image");
image!.draw(in: rect)
context.setAlpha(0.5)
context.setBlendMode(CGBlendMode.plusDarker)
let size = rect.size.height / 2
let rectOverlay = CGRect(x: 0, y: rect.maxY - size, width: size, height: size)
NSColor.red.setFill()
rectOverlay.fill()
}
}
Hi Brian,Thanks for the example! In short, I'm trying to implement the PlusDarker blend mode, which is present in CoreGraphics. I naively ported the formula stated on the documentation straight into the shader, and it works correctly when the src color is not transparent, but not when there is transparency.
Here's a fiddle. Any tips on what I may be doing wrong?
CoreGraphics doc:The expected result should be:But, using Skia I get:In both examples, the red rect had 50% opacity.
On Wednesday, 10 November 2021 at 15:59:27 UTC+1 brian...@google.com wrote:
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/ecc5598f-7ba0-48ea-ac10-43e9e7f23e17n%40googlegroups.com.
So you may not believe me, but everything is working and what you are getting are the same two images!!!
So when you blend Red with .5 alpha and Solid White using plus-darken, you end up with a pixel that has 50% transparency (alpha = 0.5). So that is then blended with the background of the entire page. The default on fiddle is a black background, so things look darker. In the top right of Fiddle hit the "paint drop" icon to switch from dark mode to light mode. This gives a white background and your draw will look as you expect!
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/CAL_WtP46g%2BP4990M1twZEhxpSMT97ou0gO2yV4TE3gBVwLzFvg%40mail.gmail.com.