Browse Source

Merge branch 'master' into curtis/optimize-solid-fill-region

pull/765/head
James Jackson-South 7 years ago
committed by GitHub
parent
commit
b778340bd2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs
  2. 8
      src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToHunterLabConverter.cs
  3. 9
      src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HunterLabToCieXyzConverter.cs
  4. 7
      src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
  5. 6
      src/ImageSharp/Formats/Gif/LzwEncoder.cs
  6. 9
      src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs
  7. 3
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
  8. 7
      src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
  9. 4
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  10. 3
      src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
  11. 5
      src/ImageSharp/Image.FromBytes.cs
  12. 6
      src/ImageSharp/Processing/Processors/Quantization/FrameQuantizerBase{TPixel}.cs
  13. 12
      src/ImageSharp/Processing/ResizeHelper.cs

4
src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs

@ -139,10 +139,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text
fistRow = -startY;
}
int end = operation.Map.Height;
int maxHeight = source.Height - startY;
end = Math.Min(end, maxHeight);
int end = Math.Min(operation.Map.Height, maxHeight);
for (int row = fistRow; row < end; row++)
{

8
src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToHunterLabConverter.cs

@ -45,9 +45,11 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
float ka = ComputeKa(this.HunterLabWhitePoint);
float kb = ComputeKb(this.HunterLabWhitePoint);
float l = 100 * MathF.Sqrt(y / yn);
float a = ka * (((x / xn) - (y / yn)) / MathF.Sqrt(y / yn));
float b = kb * (((y / yn) - (z / zn)) / MathF.Sqrt(y / yn));
float yByYn = y / yn;
float sqrtYbyYn = MathF.Sqrt(yByYn);
float l = 100 * sqrtYbyYn;
float a = ka * (((x / xn) - yByYn) / sqrtYbyYn);
float b = kb * ((yByYn - (z / zn)) / sqrtYbyYn);
if (float.IsNaN(a))
{

9
src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/HunterLabToCieXyzConverter.cs

@ -26,9 +26,12 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
float ka = ComputeKa(input.WhitePoint);
float kb = ComputeKb(input.WhitePoint);
float y = ImageMaths.Pow2(l / 100F) * yn;
float x = (((a / ka) * MathF.Sqrt(y / yn)) + (y / yn)) * xn;
float z = (((b / kb) * MathF.Sqrt(y / yn)) - (y / yn)) * (-zn);
float pow = ImageMaths.Pow2(l / 100F);
float sqrtPow = MathF.Sqrt(pow);
float y = pow * yn;
float x = (((a / ka) * sqrtPow) + pow) * xn;
float z = (((b / kb) * sqrtPow) - pow) * (-zn);
return new CieXyz(x, y, z);
}

7
src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs

@ -310,9 +310,12 @@ namespace SixLabors.ImageSharp.Formats.Bmp
}
else
{
for (int i = 0; i < cmd[0]; i++)
int max = count + cmd[0]; // as we start at the current count in the following loop, max is count + cmd[0]
byte cmd1 = cmd[1]; // store the value to avoid the repeated indexer access inside the loop
for (; count < max; count++)
{
buffer[count++] = cmd[1];
buffer[count] = cmd1;
}
}
}

6
src/ImageSharp/Formats/Gif/LzwEncoder.cs

@ -309,10 +309,10 @@ namespace SixLabors.ImageSharp.Formats.Gif
// Non-empty slot
if (Unsafe.Add(ref hashTableRef, i) >= 0)
{
int disp = hsizeReg - i;
if (i == 0)
int disp = 1;
if (i != 0)
{
disp = 1;
disp = hsizeReg - i;
}
do

9
src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs

@ -543,15 +543,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
var sb = new StringBuilder();
sb.Append('[');
for (int i = 0; i < Size; i++)
for (int i = 0; i < Size - 1; i++)
{
sb.Append(this[i]);
if (i < Size - 1)
{
sb.Append(',');
}
sb.Append(',');
}
sb.Append(this[Size - 1]);
sb.Append(']');
return sb.ToString();
}

3
src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

@ -856,10 +856,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
private void ProcessStartOfScanMarker()
{
int selectorsCount = this.InputStream.ReadByte();
int componentIndex = -1;
for (int i = 0; i < selectorsCount; i++)
{
componentIndex = -1;
int componentIndex = -1;
int selector = this.InputStream.ReadByte();
for (int j = 0; j < this.Frame.ComponentIds.Length; j++)

7
src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs

@ -822,11 +822,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
{
for (int i = 0; i < componentCount; i++)
{
this.buffer[(3 * i) + 6] = (byte)(i + 1);
int i3 = 3 * i;
this.buffer[i3 + 6] = (byte)(i + 1);
// We use 4:2:0 chroma subsampling by default.
this.buffer[(3 * i) + 7] = subsamples[i];
this.buffer[(3 * i) + 8] = chroma[i];
this.buffer[i3 + 7] = subsamples[i];
this.buffer[i3 + 8] = chroma[i];
}
}

4
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -896,9 +896,9 @@ namespace SixLabors.ImageSharp.Formats.Png
ref byte sourceRef = ref MemoryMarshal.GetReference(source);
ref byte resultRef = ref MemoryMarshal.GetReference(result);
byte mask = (byte)(0xFF >> (8 - bits));
byte shift0 = (byte)(8 - bits);
int shift = 8 - bits;
byte mask = (byte)(0xFF >> shift);
byte shift0 = (byte)shift;
int v = 0;
int resultOffset = 0;

3
src/ImageSharp/Formats/Png/PngScanlineProcessor.cs

@ -190,12 +190,11 @@ namespace SixLabors.ImageSharp.Formats.Png
else
{
Rgba32 rgba32 = default;
int bps = bytesPerSample;
for (int x = 0; x < header.Width; x++)
{
int offset = x * bytesPerPixel;
byte luminance = Unsafe.Add(ref scanlineSpanRef, offset);
byte alpha = Unsafe.Add(ref scanlineSpanRef, offset + bps);
byte alpha = Unsafe.Add(ref scanlineSpanRef, offset + bytesPerSample);
rgba32.R = luminance;
rgba32.G = luminance;

5
src/ImageSharp/Image.FromBytes.cs

@ -198,18 +198,17 @@ namespace SixLabors.ImageSharp
return null;
}
IImageFormat format = default;
foreach (IImageFormatDetector detector in config.ImageFormatsManager.FormatDetectors)
{
IImageFormat f = detector.DetectFormat(data);
if (f != null)
{
format = f;
return f;
}
}
return format;
return default;
}
/// <summary>

6
src/ImageSharp/Processing/Processors/Quantization/FrameQuantizerBase{TPixel}.cs

@ -139,8 +139,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
protected byte GetTransparentIndex()
{
// Transparent pixels are much more likely to be found at the end of a palette.
int index = this.paletteVector.Length - 1;
for (int i = this.paletteVector.Length - 1; i >= 0; i--)
int paletteVectorLengthMinus1 = this.paletteVector.Length - 1;
int index = paletteVectorLengthMinus1;
for (int i = paletteVectorLengthMinus1; i >= 0; i--)
{
ref Vector4 candidate = ref this.paletteVector[i];
if (candidate.Equals(default))

12
src/ImageSharp/Processing/ResizeHelper.cs

@ -333,25 +333,21 @@ namespace SixLabors.ImageSharp.Processing
return (new Size(sourceWidth, sourceWidth), new Rectangle(0, 0, sourceWidth, sourceHeight));
}
// Fractional variants for preserving aspect ratio.
float percentHeight = MathF.Abs(height / (float)sourceHeight);
float percentWidth = MathF.Abs(width / (float)sourceWidth);
float sourceRatio = (float)sourceHeight / sourceWidth;
// Find the shortest distance to go.
int widthDiff = sourceWidth - width;
int heightDiff = sourceHeight - height;
if (widthDiff < heightDiff)
{
float sourceRatio = (float)sourceHeight / sourceWidth;
destinationHeight = (int)MathF.Round(width * sourceRatio);
height = destinationHeight;
destinationWidth = width;
}
else if (widthDiff > heightDiff)
{
destinationWidth = (int)MathF.Round(height / sourceRatio);
float sourceRatioInverse = (float)sourceWidth / sourceHeight;
destinationWidth = (int)MathF.Round(height * sourceRatioInverse);
destinationHeight = height;
width = destinationWidth;
}
@ -360,12 +356,14 @@ namespace SixLabors.ImageSharp.Processing
if (height > width)
{
destinationWidth = width;
float percentWidth = MathF.Abs(width / (float)sourceWidth);
destinationHeight = (int)MathF.Round(sourceHeight * percentWidth);
height = destinationHeight;
}
else
{
destinationHeight = height;
float percentHeight = MathF.Abs(height / (float)sourceHeight);
destinationWidth = (int)MathF.Round(sourceWidth * percentHeight);
width = destinationWidth;
}

Loading…
Cancel
Save