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] Watermarking regression #1310

Closed
SapientGuardian opened this issue May 27, 2020 · 7 comments
Closed

[BUG] Watermarking regression #1310

SapientGuardian opened this issue May 27, 2020 · 7 comments

Comments

@SapientGuardian
Copy link

Description

SkiaSharp 1.68.3 renders a basic watermarking pattern very poorly, as compared to 1.60.1 This may be related to #931. I was able to get closer to the old rendering by fiddling with the colorspace, but haven't been able to make it exactly right.

Code
Attached zip includes code and sample images

using System;
using System.IO;
using SkiaSharp;

namespace SkiaSharpBugDemo
{
    class Program
    {
                
        static void Main(string[] args)
        {
            using var assetStream = File.OpenRead("Resources\\testImage.jpg");
            using var assetData = SKData.Create(assetStream);
            using var codec = SKCodec.Create(assetData);
            if (codec == null)
            {
                throw new ArgumentException("Source image is corrupted or unsupported.");
            }
            
            var testImage = SKBitmap.Decode(assetData, codec.Info);
           

            using (var canvas = new SKCanvas(testImage))
            {
                var watermarkBitmap = SKBitmap.Decode("Resources\\testLogo.png");
                
                var rect = SKRect.Create(0, 0, testImage.Width, testImage.Height);
                using var shader = SKShader.CreateBitmap(watermarkBitmap, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat);
                
                var backgroundPaint = new SKPaint
                {
                    Style = SKPaintStyle.Fill,
                    Shader = shader
                };
                canvas.DrawRect(rect, backgroundPaint);

                using (FileStream fileStream = File.OpenWrite("watermarkedTestImageNew.jpg"))
                {
                    var image = SKImage.FromBitmap(testImage);
                    var stream = image.Encode(SKEncodedImageFormat.Jpeg, 98).AsStream();
                    stream.CopyTo(fileStream);
                    fileStream.Close();

                }
            }

        }
    }
}

Expected Behavior

SkiaSharp1 60 1

Actual Behavior

SkiaSharp1 68 3

Basic Information

  • Version with issue: 1.68.3
  • Last known good version: 1.60.1
  • IDE: Visual Studio
  • Platform Target Frameworks: .NET Core 3.1
    • Linux: Debian 10
    • Windows Classic: Windows 10

Screenshots

See Expected vs Actual

Reproduction Link

SkiaSharpBugDemo.zip

@SapientGuardian
Copy link
Author

@mattleibow sorry to ping you directly, but I'd really appreciate any suggestions or insights you might have on this, as I'm stuck on the old version until this is resolved.

I tried figuring out what caused the change via git bisect, but there were so many project structure changes between the two major versions that the approach proved impractical. I also tried every pre-release build of the 1.68 series I could get my hands on, and they all behaved the same way.

@mattleibow
Copy link
Contributor

Could you try the v2.80 and v2.84 preview packages. I think Google changed something in the colorspace processing either on the load or save... Not sure if it is for the better...

If you open the image in Chrome, then usually it is fine. Maybe they introduced a bug that they never spotted...

I'll try bump to the very latest Google code and we can test that, but for now, v2.84 is the most recent.

@SapientGuardian
Copy link
Author

Thanks for getting back to me. 2.80.0-preview.14 looks much closer to 1.68.3, but is still noticeably different when compared side by side. I've attached the rendering from 2.80.0-preview.14.

You mentioned a v2.84 preview package, but I didn't see that on nuget or on the public azure pipelines page. Where can I get that?

280

@mattleibow
Copy link
Contributor

mattleibow commented Jun 26, 2020

You can check the preview feed https://aka.ms/skiasharp-eap/index.json

They might have done something bad... What happens when you export as png, jpg or webp? Are they all wrong?

@SapientGuardian
Copy link
Author

Thanks. The outputs from 2.84.0-pr.1321.8 are identical to 2.80.0-preview.14. I tried saving to png, jpg, and webp, and they all looked the same. I also tried opening them in Chrome and the default Windows "Photos" viewer, and they render the same.

@SapientGuardian
Copy link
Author

Analyzing the output from 2.80, even though it is different from 1.60 I believe it to be more accurate (i.e. if I apply the watermark by hand in photoshop, it looks more like the 2.80 output than the 1.60). 1.68 was definitely broken, though. I'm going to revisit my watermarks with the 2.80 output, rather than try to get them to render like 1.60. We can call this fixed. Thanks!

@mattleibow
Copy link
Contributor

Yeah. In the 2.80 series, Google basically reworked the colorspaces. I managed to keep the .NET API the same, but much has changed under the hood. I don't think the images were even created properly previously.

@ghost ghost locked as resolved and limited conversation to collaborators Aug 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants