Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Bug with SKBlendMode.SrcOver #2754

Open
1 task done
TomQv opened this issue Feb 13, 2024 · 0 comments
Open
1 task done

[BUG] Bug with SKBlendMode.SrcOver #2754

TomQv opened this issue Feb 13, 2024 · 0 comments
Labels

Comments

@TomQv
Copy link

TomQv commented Feb 13, 2024

Description

When drawing on an empty canvas with a half transparent color, then the resulting color is not identically to the paint anymore.
Example:

  • background cleared with rgba(0,0,0,0)
  • paint with color rgba(0,0,255,128), blue with 50% alpha, SKBlendMode.SrcOver
  • result is rgba(0,0,128,128), so the blue was changed from 255 to 128

Code

var size = 32;
var buffer = new byte[size * size * 4];
var pinnedbuffer = GCHandle.Alloc(buffer, GCHandleType.Pinned);
var pointer = pinnedbuffer.AddrOfPinnedObject();

var imageinfo = new SKImageInfo(size, size, SKColorType.Rgba8888 , SKAlphaType.Premul);
using (var surface = SKSurface.Create(imageinfo, pointer))  
{
    var blendmodes = Enum.GetValues(typeof(SKBlendMode));
    var color = new SKColor(0, 0, 255, 128);

    foreach (var blendmode in blendmodes)
    {
        surface.Canvas.Clear(new SKColor(0, 0, 0, 0));
        var paint = new SKPaint
        {
            Style = SKPaintStyle.Fill,
            Color = color,
            BlendMode = (SKBlendMode)blendmode
        };
        surface.Canvas.DrawRect(0, 0, size, size, paint);

        // check first pixel
        var r = buffer[0];
        var g = buffer[1];
        var b = buffer[2];
        var a = buffer[3];
        //Debug.WriteLine(string.Format("alpha={0} blue={1} mode={2}", a, b, blendmode.ToString()));
        if (a == color.Alpha  && b == color.Blue )
        {
            // ok
        }
    }            
}

Expected Behavior

Drawing with source rgba(0,0,255,128) with SrcOver on an emtpy canvas destination rgba(0,0,0,0) should result in unchanged color.

Actual Behavior

Its not, result is rgba(0,0,128,128) instead of rgba(0,0,255,128).

I actually tried all SKBlendmodes, but none of them is producing the expected behaviour.

Version of SkiaSharp

2.88.3 (Current)

Last Known Good Version of SkiaSharp

Other (Please indicate in the description)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Windows

Platform / Operating System Version

Windows

Devices

No response

Relevant Screenshots

No response

Relevant Log Output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@TomQv TomQv added the type/bug label Feb 13, 2024
@TomQv TomQv changed the title [BUG] <title>Bug with SKBlendMode.SrcOver [BUG] Bug with SKBlendMode.SrcOver Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Ready For Work
Development

No branches or pull requests

1 participant