Browse Source

add skeleton for Color type

af/merge-core
Anton Firszov 7 years ago
parent
commit
2e402ba35d
  1. 42
      src/ImageSharp/Color.cs
  2. 15
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs
  3. 4
      tests/ImageSharp.Benchmarks/Codecs/GetSetPixel.cs
  4. 2
      tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs
  5. 2
      tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs
  6. 2
      tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs
  7. 2
      tests/ImageSharp.Benchmarks/Drawing/DrawTextOutline.cs
  8. 2
      tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs
  9. 10
      tests/ImageSharp.Tests/ColorTests.cs

42
src/ImageSharp/Color.cs

@ -0,0 +1,42 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp
{
public struct Color
{
private Rgba64 data;
public Color(Rgba64 pixel)
{
this.data = pixel;
}
public Color(Rgba32 pixel)
{
this.data = default;
this.data.FromRgba32(pixel);
}
public Color(Vector4 vector)
{
this.data = default;
this.data.FromVector4(vector);
}
public static Color FromRgba(byte r, byte g, byte b, byte a) => new Color(new Rgba32(r, g, b, a));
public static Color FromRgba(ushort r, ushort g, ushort b, ushort a) => new Color(new Rgba64(r, g, b, a));
public TPixel ToPixel<TPixel>()
where TPixel : struct, IPixel<TPixel>
{
TPixel pixel = default;
pixel.FromRgba64(this.data);
return pixel;
}
}
}

15
src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs

@ -54,6 +54,21 @@ namespace SixLabors.ImageSharp.PixelFormats
this.A = a;
}
/// <summary>
/// Initializes a new instance of the <see cref="Rgba64"/> struct.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param>
public Rgba64(byte r, byte g, byte b, byte a)
{
this.R = r;
this.G = g;
this.B = b;
this.A = a;
}
/// <summary>
/// Gets or sets the RGB components of this struct as <see cref="Rgb48"/>
/// </summary>

4
tests/ImageSharp.Benchmarks/Codecs/GetSetPixel.cs

@ -10,11 +10,11 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs
public class GetSetPixel : BenchmarkBase
{
[Benchmark(Baseline = true, Description = "System.Drawing GetSet pixel")]
public Color ResizeSystemDrawing()
public System.Drawing.Color ResizeSystemDrawing()
{
using (var source = new Bitmap(400, 400))
{
source.SetPixel(200, 200, Color.White);
source.SetPixel(200, 200, System.Drawing.Color.White);
return source.GetPixel(200, 200);
}
}

2
tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs

@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.Benchmarks
graphics.InterpolationMode = InterpolationMode.Default;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (var pen = new Pen(Color.HotPink, 10))
using (var pen = new Pen(System.Drawing.Color.HotPink, 10))
{
graphics.DrawBeziers(pen, new[] {
new PointF(10, 500),

2
tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs

@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Benchmarks
graphics.InterpolationMode = InterpolationMode.Default;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (var pen = new Pen(Color.HotPink, 10))
using (var pen = new Pen(System.Drawing.Color.HotPink, 10))
{
graphics.DrawLines(pen, new[] {
new PointF(10, 10),

2
tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs

@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Benchmarks
{
graphics.InterpolationMode = InterpolationMode.Default;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (var pen = new Pen(Color.HotPink, 10))
using (var pen = new Pen(System.Drawing.Color.HotPink, 10))
{
graphics.DrawPolygon(pen, new[] {
new PointF(10, 10),

2
tests/ImageSharp.Benchmarks/Drawing/DrawTextOutline.cs

@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.Benchmarks
{
graphics.InterpolationMode = InterpolationMode.Default;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (var pen = new Pen(Color.HotPink, 10))
using (var pen = new Pen(System.Drawing.Color.HotPink, 10))
using (var font = new Font("Arial", 12, GraphicsUnit.Point))
using (var gp = new GraphicsPath())
{

2
tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs

@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Benchmarks
{
graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (var brush = new HatchBrush(HatchStyle.BackwardDiagonal, Color.HotPink))
using (var brush = new HatchBrush(HatchStyle.BackwardDiagonal, System.Drawing.Color.HotPink))
{
graphics.FillRectangle(brush, new Rectangle(0, 0, 800, 800)); // can't find a way to flood fill with a brush
}

10
tests/ImageSharp.Tests/ColorTests.cs

@ -0,0 +1,10 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Tests
{
public class ColorTests
{
}
}
Loading…
Cancel
Save