Skip to content

Commit

Permalink
Reenabled unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
bijington committed Apr 18, 2021
1 parent 9c522ab commit b3f3676
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ internal void ProcessImage(OutputImage outputImage)
Log.LogWarning("Image aspect ratio is not being maintained.");
}

using var tempBitmap = new SKBitmap(context.Size.Width, context.Size.Height);
using var canvas = new SKCanvas(tempBitmap);
using var outputBitmap = new SKBitmap(context.Size.Width, context.Size.Height);
using var canvas = new SKCanvas(outputBitmap);

canvas.Clear(backgroundColor);
canvas.Save();
Expand All @@ -68,7 +68,7 @@ internal void ProcessImage(OutputImage outputImage)
// TODO: apply padding.

using var stream = File.Create(outputImage.OutputFile);
tempBitmap.Encode(stream, SKEncodedImageFormat.Png, 100);
outputBitmap.Encode(stream, SKEncodedImageFormat.Png, 100);
}
catch (System.Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
using Xunit.Abstractions;
using Mobile.BuildTools.Models.AppIcons;
using Mobile.BuildTools.Drawing;

using SkiaSharp;

namespace Mobile.BuildTools.Tests.Fixtures.Generators
{
public class ImageResizer { }
Expand Down Expand Up @@ -170,55 +171,52 @@ public void SetsDefaultBackground()
Assert.False(outputImage.HasTransparentBackground);
}

//[Fact]
//public void SetsCustomBackground()
//{
// var config = GetConfiguration();
// var generator = new ImageResizeGenerator(config);

// var image = new OutputImage
// {
// Height = 0,
// Width = 0,
// InputFile = Path.Combine(TestConstants.ImageDirectory, "dotnetbot.png"),
// OutputFile = Path.Combine(config.IntermediateOutputPath, "dotnetbot.png"),
// OutputLink = Path.Combine("Resources", "drawable-xxxhdpi", "dotnetbot.png"),
// RequiresBackgroundColor = true,
// Scale = 1,
// ShouldBeVisible = true,
// Watermark = null,
// BackgroundColor = "#8A2BE2"
// };

// generator.ProcessImage(image);

// using var inputImage = Image.Load(image.InputFile);
// using var outputImage = Image.Load(image.OutputFile);
// using var inputClone = inputImage.CloneAs<Rgba32>();
// using var outputClone = outputImage.CloneAs<Rgba32>();

// var comparedTransparentPixel = false;
// for (var y = 0; y < inputImage.Height; ++y)
// {
// var inputPixelRowSpan = inputClone.GetPixelRowSpan(y);
// var outputPixelRowSpan = outputClone.GetPixelRowSpan(y);
// for (var x = 0; x < inputImage.Width; ++x)
// {
// var startingPixel = inputPixelRowSpan[x];
// if (startingPixel.A == 0)
// {
// comparedTransparentPixel = true;
// var pixel = outputPixelRowSpan[x];
// Assert.Equal(138, pixel.R);
// Assert.Equal(43, pixel.G);
// Assert.Equal(226, pixel.B);
// Assert.Equal(255, pixel.A);
// }
// }
// }

// Assert.True(comparedTransparentPixel);
//}
[Fact]
public void SetsCustomBackground()
{
var config = GetConfiguration();
var generator = new ImageResizeGenerator(config);

var image = new OutputImage
{
Height = 0,
Width = 0,
InputFile = Path.Combine(TestConstants.ImageDirectory, "dotnetbot.png"),
OutputFile = Path.Combine(config.IntermediateOutputPath, "dotnetbot.png"),
OutputLink = Path.Combine("Resources", "drawable-xxxhdpi", "dotnetbot.png"),
RequiresBackgroundColor = true,
Scale = 1,
ShouldBeVisible = true,
Watermark = null,
BackgroundColor = "#8A2BE2"
};

generator.ProcessImage(image);

using var inputImage = SKBitmap.Decode(image.InputFile);
using var outputImage = SKBitmap.Decode(image.OutputFile);

var comparedTransparentPixel = false;
for (var y = 0; y < inputImage.Height; ++y)
{
for (var x = 0; x < inputImage.Width; ++x)
{
if (inputImage.GetPixel(x, y).Alpha == 0)
{
comparedTransparentPixel = true;

var pixel = outputImage.GetPixel(x, y);

Assert.Equal(138, pixel.Red);
Assert.Equal(43, pixel.Green);
Assert.Equal(226, pixel.Blue);
Assert.Equal(255, pixel.Alpha);
}
}
}

Assert.True(comparedTransparentPixel);
}

[Theory]
[InlineData("Dev", 0.5)]
Expand Down

0 comments on commit b3f3676

Please sign in to comment.