Browse Source

Merge remote-tracking branch 'refs/remotes/origin/master' into feature/icc

pull/144/head
James Jackson-South 9 years ago
parent
commit
447d19600f
  1. 4
      src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
  2. 3
      src/ImageSharp.Drawing/Text/DrawText.cs
  3. 102
      src/ImageSharp.Drawing/Text/TextGraphicsOptions.cs
  4. 24
      src/ImageSharp/Common/Helpers/ImageMaths.cs
  5. 2
      src/ImageSharp/PixelFormats/Alpha8.cs
  6. 2
      src/ImageSharp/PixelFormats/Argb32.cs
  7. 2
      src/ImageSharp/PixelFormats/Bgr565.cs
  8. 2
      src/ImageSharp/PixelFormats/Bgra4444.cs
  9. 3
      src/ImageSharp/PixelFormats/Bgra5551.cs
  10. 2
      src/ImageSharp/PixelFormats/Byte4.cs
  11. 2
      src/ImageSharp/PixelFormats/HalfSingle.cs
  12. 2
      src/ImageSharp/PixelFormats/HalfVector2.cs
  13. 2
      src/ImageSharp/PixelFormats/HalfVector4.cs
  14. 2
      src/ImageSharp/PixelFormats/NormalizedByte2.cs
  15. 2
      src/ImageSharp/PixelFormats/NormalizedByte4.cs
  16. 2
      src/ImageSharp/PixelFormats/NormalizedShort2.cs
  17. 2
      src/ImageSharp/PixelFormats/NormalizedShort4.cs
  18. 2
      src/ImageSharp/PixelFormats/Rg32.cs
  19. 2
      src/ImageSharp/PixelFormats/Rgba1010102.cs
  20. 2
      src/ImageSharp/PixelFormats/Rgba32.cs
  21. 2
      src/ImageSharp/PixelFormats/Rgba64.cs
  22. 2
      src/ImageSharp/PixelFormats/RgbaVector.cs
  23. 2
      src/ImageSharp/PixelFormats/Short2.cs
  24. 2
      src/ImageSharp/PixelFormats/Short4.cs

4
src/ImageSharp.Drawing/ImageSharp.Drawing.csproj

@ -39,8 +39,8 @@
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta001">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="SixLabors.Fonts" Version="0.1.0-alpha0008" />
<PackageReference Include="SixLabors.Shapes" Version="0.1.0-alpha0011" />
<PackageReference Include="SixLabors.Fonts" Version="0.1.0-alpha0010" />
<PackageReference Include="SixLabors.Shapes" Version="0.1.0-alpha0012" />
</ItemGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>..\..\ImageSharp.ruleset</CodeAnalysisRuleSet>

3
src/ImageSharp.Drawing/Text/DrawText.cs

@ -181,7 +181,8 @@ namespace ImageSharp
{
ApplyKerning = options.ApplyKerning,
TabWidth = options.TabWidth,
WrappingWidth = options.WrapTextWidth
WrappingWidth = options.WrapTextWidth,
Alignment = options.TextAlignment
};
renderer.RenderText(text, style);

102
src/ImageSharp.Drawing/Text/TextGraphicsOptions.cs

@ -2,9 +2,11 @@
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing
{
using ImageSharp.PixelFormats;
using SixLabors.Fonts;
/// <summary>
/// Options for influencing the drawing functions.
/// </summary>
@ -15,50 +17,94 @@ namespace ImageSharp.Drawing
/// </summary>
public static readonly TextGraphicsOptions Default = new TextGraphicsOptions(true);
private float? blendPercentage;
private int? antialiasSubpixelDepth;
private bool? antialias;
private bool? applyKerning;
private float? tabWidth;
private PixelBlenderMode blenderMode;
private bool? useImageResolution;
private float wrapTextWidth;
private SixLabors.Fonts.TextAlignment? textAlignment;
/// <summary>
/// Initializes a new instance of the <see cref="TextGraphicsOptions" /> struct.
/// </summary>
/// <param name="enableAntialiasing">If set to <c>true</c> [enable antialiasing].</param>
public TextGraphicsOptions(bool enableAntialiasing)
{
this.applyKerning = true;
this.tabWidth = 4;
this.useImageResolution = false;
this.wrapTextWidth = 0;
this.textAlignment = SixLabors.Fonts.TextAlignment.Left;
this.antialiasSubpixelDepth = 16;
this.blenderMode = PixelBlenderMode.Normal;
this.blendPercentage = 1;
this.antialias = enableAntialiasing;
}
/// <summary>
/// Gets or sets a value indicating whether antialiasing should be applied.
/// </summary>
public bool Antialias { get => this.antialias ?? true; set => this.antialias = value; }
/// <summary>
/// Gets or sets a value indicating the number of subpixels to use while rendering with antialiasing enabled.
/// </summary>
public int AntialiasSubpixelDepth { get => this.antialiasSubpixelDepth ?? 16; set => this.antialiasSubpixelDepth = value; }
/// <summary>
/// Whether antialiasing should be applied.
/// Gets or sets a value indicating the blending percentage to apply to the drawing operation
/// </summary>
public bool Antialias;
public float BlendPercentage { get => (this.blendPercentage ?? 1).Clamp(0, 1); set => this.blendPercentage = value; }
// In the future we could expose a PixelBlender<TPixel> directly on here
// or some forms of PixelBlender factory for each pixel type. Will need
// some API thought post V1.
/// <summary>
/// The number of subpixels to use while rendering with antialiasing enabled.
/// Gets or sets a value indicating the blending percentage to apply to the drawing operation
/// </summary>
public int AntialiasSubpixelDepth;
public PixelBlenderMode BlenderMode { get => this.blenderMode; set => this.blenderMode = value; }
/// <summary>
/// Whether the text should be drawing with kerning enabled.
/// Gets or sets a value indicating whether the text should be drawing with kerning enabled.
/// </summary>
public bool ApplyKerning;
public bool ApplyKerning { get => this.applyKerning ?? true; set => this.applyKerning = value; }
/// <summary>
/// The number of space widths a tab should lock to.
/// Gets or sets a value indicating the number of space widths a tab should lock to.
/// </summary>
public float TabWidth;
public float TabWidth { get => this.tabWidth ?? 4; set => this.tabWidth = value; }
/// <summary>
/// Flag weather to use the current image resultion to for point size scaling.
/// Gets or sets a value indicating whether to use the current image resultion to for point size scaling.
/// If this is [false] the text renders at 72dpi otherwise it renders at Image resolution
/// </summary>
public bool UseImageResolution;
public bool UseImageResolution { get => this.useImageResolution ?? false; set => this.useImageResolution = value; }
/// <summary>
/// If greater than zero determine the width at which text should wrap.
/// Gets or sets a value indicating if greater than zero determine the width at which text should wrap.
/// </summary>
public float WrapTextWidth;
public float WrapTextWidth { get => this.wrapTextWidth; set => this.wrapTextWidth = value; }
/// <summary>
/// Initializes a new instance of the <see cref="TextGraphicsOptions" /> struct.
/// Gets or sets a value indicating how to align the text relative to the rendering space.
/// If <see cref="WrapTextWidth"/> is greater than zero it will align relative to the space
/// defined by the location and width, if <see cref="WrapTextWidth"/> equals zero, and thus
/// wrapping disabled, then the alignment is relative to the drawing location.
/// </summary>
/// <param name="enableAntialiasing">If set to <c>true</c> [enable antialiasing].</param>
public TextGraphicsOptions(bool enableAntialiasing)
{
this.Antialias = enableAntialiasing;
this.ApplyKerning = true;
this.TabWidth = 4;
this.AntialiasSubpixelDepth = 16;
this.UseImageResolution = false;
this.WrapTextWidth = 0;
}
public TextAlignment TextAlignment { get => this.textAlignment ?? TextAlignment.Left; set => this.textAlignment = value; }
/// <summary>
/// Performs an implicit conversion from <see cref="GraphicsOptions"/> to <see cref="TextGraphicsOptions"/>.
@ -71,7 +117,9 @@ namespace ImageSharp.Drawing
{
return new TextGraphicsOptions(options.Antialias)
{
AntialiasSubpixelDepth = options.AntialiasSubpixelDepth
AntialiasSubpixelDepth = options.AntialiasSubpixelDepth,
blendPercentage = options.BlendPercentage,
blenderMode = options.BlenderMode
};
}
@ -86,7 +134,9 @@ namespace ImageSharp.Drawing
{
return new GraphicsOptions(options.Antialias)
{
AntialiasSubpixelDepth = options.AntialiasSubpixelDepth
AntialiasSubpixelDepth = options.AntialiasSubpixelDepth,
BlenderMode = options.BlenderMode,
BlendPercentage = options.BlendPercentage
};
}
}

24
src/ImageSharp/Common/Helpers/ImageMaths.cs

@ -182,7 +182,7 @@ namespace ImageSharp
break;
}
Func<PixelAccessor<TPixel>, int> getMinY = pixels =>
int GetMinY(PixelAccessor<TPixel> pixels)
{
for (int y = 0; y < height; y++)
{
@ -196,9 +196,9 @@ namespace ImageSharp
}
return 0;
};
}
Func<PixelAccessor<TPixel>, int> getMaxY = pixels =>
int GetMaxY(PixelAccessor<TPixel> pixels)
{
for (int y = height - 1; y > -1; y--)
{
@ -212,9 +212,9 @@ namespace ImageSharp
}
return height;
};
}
Func<PixelAccessor<TPixel>, int> getMinX = pixels =>
int GetMinX(PixelAccessor<TPixel> pixels)
{
for (int x = 0; x < width; x++)
{
@ -228,9 +228,9 @@ namespace ImageSharp
}
return 0;
};
}
Func<PixelAccessor<TPixel>, int> getMaxX = pixels =>
int GetMaxX(PixelAccessor<TPixel> pixels)
{
for (int x = width - 1; x > -1; x--)
{
@ -244,14 +244,14 @@ namespace ImageSharp
}
return height;
};
}
using (PixelAccessor<TPixel> bitmapPixels = bitmap.Lock())
{
topLeft.Y = getMinY(bitmapPixels);
topLeft.X = getMinX(bitmapPixels);
bottomRight.Y = (getMaxY(bitmapPixels) + 1).Clamp(0, height);
bottomRight.X = (getMaxX(bitmapPixels) + 1).Clamp(0, width);
topLeft.Y = GetMinY(bitmapPixels);
topLeft.X = GetMinX(bitmapPixels);
bottomRight.Y = (GetMaxY(bitmapPixels) + 1).Clamp(0, height);
bottomRight.X = (GetMaxX(bitmapPixels) + 1).Clamp(0, width);
}
return GetBoundingRectangle(topLeft, bottomRight);

2
src/ImageSharp/PixelFormats/Alpha8.cs

@ -11,7 +11,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Packed pixel type containing a single 8 bit normalized W values.
/// <para>
/// Ranges from &lt;0, 0, 0, 0&gt; to &lt;0, 0, 0, 1&gt; in vector form.
/// </para>
/// </summary>
public struct Alpha8 : IPixel<Alpha8>, IPackedVector<byte>
{

2
src/ImageSharp/PixelFormats/Argb32.cs

@ -11,7 +11,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
/// The color components are stored in alpha, red, green, and blue order.
/// <para>
/// Ranges from &lt;0, 0, 0, 0&gt; to &lt;1, 1, 1, 1&gt; in vector form.
/// </para>
/// </summary>
/// <remarks>
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,

2
src/ImageSharp/PixelFormats/Bgr565.cs

@ -11,7 +11,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Packed pixel type containing unsigned normalized values ranging from 0 to 1. The x and z components use 5 bits, and the y component uses 6 bits.
/// <para>
/// Ranges from &lt;0, 0, 0, 1&gt; to &lt;1, 1, 1, 1&gt; in vector form.
/// </para>
/// </summary>
public struct Bgr565 : IPixel<Bgr565>, IPackedVector<ushort>
{

2
src/ImageSharp/PixelFormats/Bgra4444.cs

@ -11,7 +11,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Packed pixel type containing unsigned normalized values, ranging from 0 to 1, using 4 bits each for x, y, z, and w.
/// <para>
/// Ranges from &lt;0, 0, 0, 0&gt; to &lt;1, 1, 1, 1&gt; in vector form.
/// </para>
/// </summary>
public struct Bgra4444 : IPixel<Bgra4444>, IPackedVector<ushort>
{

3
src/ImageSharp/PixelFormats/Bgra5551.cs

@ -11,6 +11,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Packed pixel type containing unsigned normalized values ranging from 0 to 1. The x , y and z components use 5 bits, and the w component uses 1 bit.
/// <para>
/// Ranges from &lt;0, 0, 0, 0&gt; to &lt;1, 1, 1, 1&gt; in vector form.
/// </para>
/// </summary>
public struct Bgra5551 : IPixel<Bgra5551>, IPackedVector<ushort>
{

2
src/ImageSharp/PixelFormats/Byte4.cs

@ -11,7 +11,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Packed pixel type containing four 8-bit unsigned integer values, ranging from 0 to 255.
/// <para>
/// Ranges from &lt;0, 0, 0, 0&gt; to &lt;1, 1, 1, 1&gt; in vector form.
/// </para>
/// </summary>
public struct Byte4 : IPixel<Byte4>, IPackedVector<uint>
{

2
src/ImageSharp/PixelFormats/HalfSingle.cs

@ -10,7 +10,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Packed pixel type containing a single 16 bit floating point value.
/// <para>
/// Ranges from &lt;0, 0, 0, 1&gt; to &lt;1, 0, 0, 1&gt; in vector form.
/// </para>
/// </summary>
public struct HalfSingle : IPixel<HalfSingle>, IPackedVector<ushort>
{

2
src/ImageSharp/PixelFormats/HalfVector2.cs

@ -10,7 +10,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Packed pixel type containing two 16-bit floating-point values.
/// <para>
/// Ranges from &lt;0, 0, 0, 1&gt; to &lt;1, 0, 0, 1&gt; in vector form.
/// </para>
/// </summary>
public struct HalfVector2 : IPixel<HalfVector2>, IPackedVector<uint>
{

2
src/ImageSharp/PixelFormats/HalfVector4.cs

@ -10,7 +10,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Packed pixel type containing four 16-bit floating-point values.
/// <para>
/// Ranges from &lt;0, 0, 0, 0&gt; to &lt;1, 1, 1, 1&gt; in vector form.
/// </para>
/// </summary>
public struct HalfVector4 : IPixel<HalfVector4>, IPackedVector<ulong>
{

2
src/ImageSharp/PixelFormats/NormalizedByte2.cs

@ -11,7 +11,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Packed packed pixel type containing two 8-bit signed normalized values, ranging from −1 to 1.
/// <para>
/// Ranges from &lt;-1, -1, 0, 1&gt; to &lt;1, 1, 0, 1&gt; in vector form.
/// </para>
/// </summary>
public struct NormalizedByte2 : IPixel<NormalizedByte2>, IPackedVector<ushort>
{

2
src/ImageSharp/PixelFormats/NormalizedByte4.cs

@ -11,7 +11,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Packed pixel type containing four 8-bit signed normalized values, ranging from −1 to 1.
/// <para>
/// Ranges from &lt;-1, -1, -1, -1&gt; to &lt;1, 1, 1, 1&gt; in vector form.
/// </para>
/// </summary>
public struct NormalizedByte4 : IPixel<NormalizedByte4>, IPackedVector<uint>
{

2
src/ImageSharp/PixelFormats/NormalizedShort2.cs

@ -10,7 +10,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Packed pixel type containing two 16-bit signed normalized values, ranging from −1 to 1.
/// <para>
/// Ranges from &lt;-1, -1, 0, 1&gt; to &lt;1, 1, 0, 1&gt; in vector form.
/// </para>
/// </summary>
public struct NormalizedShort2 : IPixel<NormalizedShort2>, IPackedVector<uint>
{

2
src/ImageSharp/PixelFormats/NormalizedShort4.cs

@ -10,7 +10,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Packed pixel type containing four 16-bit signed normalized values, ranging from −1 to 1.
/// <para>
/// Ranges from &lt;-1, -1, -1, -1&gt; to &lt;1, 1, 1, 1&gt; in vector form.
/// </para>
/// </summary>
public struct NormalizedShort4 : IPixel<NormalizedShort4>, IPackedVector<ulong>
{

2
src/ImageSharp/PixelFormats/Rg32.cs

@ -11,7 +11,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Packed pixel type containing two 16-bit unsigned normalized values ranging from 0 to 1.
/// <para>
/// Ranges from &lt;0, 0, 0, 1&gt; to &lt;1, 1, 0, 1&gt; in vector form.
/// </para>
/// </summary>
public struct Rg32 : IPixel<Rg32>, IPackedVector<uint>
{

2
src/ImageSharp/PixelFormats/Rgba1010102.cs

@ -12,7 +12,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Packed vector type containing unsigned normalized values ranging from 0 to 1.
/// The x, y and z components use 10 bits, and the w component uses 2 bits.
/// <para>
/// Ranges from &lt;0, 0, 0, 0&gt; to &lt;1, 1, 1, 1&gt; in vector form.
/// </para>
/// </summary>
public struct Rgba1010102 : IPixel<Rgba1010102>, IPackedVector<uint>
{

2
src/ImageSharp/PixelFormats/Rgba32.cs

@ -14,7 +14,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
/// The color components are stored in red, green, blue, and alpha order.
/// <para>
/// Ranges from &lt;0, 0, 0, 0&gt; to &lt;1, 1, 1, 1&gt; in vector form.
/// </para>
/// </summary>
/// <remarks>
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,

2
src/ImageSharp/PixelFormats/Rgba64.cs

@ -11,7 +11,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Packed pixel type containing four 16-bit unsigned normalized values ranging from 0 to 1.
/// <para>
/// Ranges from &lt;0, 0, 0, 0&gt; to &lt;1, 1, 1, 1&gt; in vector form.
/// </para>
/// </summary>
public struct Rgba64 : IPixel<Rgba64>, IPackedVector<ulong>
{

2
src/ImageSharp/PixelFormats/RgbaVector.cs

@ -11,7 +11,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Unpacked pixel type containing four 16-bit floating-point values typically ranging from 0 to 1.
/// The color components are stored in red, green, blue, and alpha order.
/// <para>
/// Ranges from &lt;0, 0, 0, 0&gt; to &lt;1, 1, 1, 1&gt; in vector form.
/// </para>
/// </summary>
/// <remarks>
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,

2
src/ImageSharp/PixelFormats/Short2.cs

@ -11,7 +11,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Packed pixel type containing two 16-bit signed integer values.
/// <para>
/// Ranges from &lt;-32767, -32767, 0, 1&gt; to &lt;32767, 32767, 0, 1&gt; in vector form.
/// </para>
/// </summary>
public struct Short2 : IPixel<Short2>, IPackedVector<uint>
{

2
src/ImageSharp/PixelFormats/Short4.cs

@ -11,7 +11,9 @@ namespace ImageSharp.PixelFormats
/// <summary>
/// Packed pixel type containing four 16-bit signed integer values.
/// <para>
/// Ranges from &lt;-37267, -37267, -37267, -37267&gt; to &lt;37267, 37267, 37267, 37267&gt; in vector form.
/// </para>
/// </summary>
public struct Short4 : IPixel<Short4>, IPackedVector<ulong>
{

Loading…
Cancel
Save