Browse Source

Resolved SA1407.

af/merge-core
dirk 10 years ago
parent
commit
85c33cc741
  1. 6
      src/ImageSharp/Colors/Colorspaces/CieLab.cs
  2. 6
      src/ImageSharp/Colors/Colorspaces/Cmyk.cs
  3. 38
      src/ImageSharp/Formats/Jpg/Components/IDCT.cs
  4. 2
      src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs
  5. 24
      src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs
  6. 2
      src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs
  7. 8
      src/ImageSharp/Image/PixelAccessor.cs
  8. 4
      src/ImageSharp/Numerics/Ellipse.cs
  9. 2
      src/ImageSharp/Numerics/Rectangle.cs

6
src/ImageSharp/Colors/Colorspaces/CieLab.cs

@ -89,9 +89,9 @@ namespace ImageSharp
//y /= 1F;
z /= 1.08883F;
x = x > 0.008856F ? (float)Math.Pow(x, 0.3333333F) : (903.3F * x + 16F) / 116F;
y = y > 0.008856F ? (float)Math.Pow(y, 0.3333333F) : (903.3F * y + 16F) / 116F;
z = z > 0.008856F ? (float)Math.Pow(z, 0.3333333F) : (903.3F * z + 16F) / 116F;
x = x > 0.008856F ? (float)Math.Pow(x, 0.3333333F) : ((903.3F * x) + 16F) / 116F;
y = y > 0.008856F ? (float)Math.Pow(y, 0.3333333F) : ((903.3F * y) + 16F) / 116F;
z = z > 0.008856F ? (float)Math.Pow(z, 0.3333333F) : ((903.3F * z) + 16F) / 116F;
float l = Math.Max(0, (116F * y) - 16F);
float a = 500F * (x - y);

6
src/ImageSharp/Colors/Colorspaces/Cmyk.cs

@ -84,9 +84,9 @@ namespace ImageSharp
/// </returns>
public static implicit operator Cmyk(Color color)
{
float c = 1f - color.R / 255F;
float m = 1f - color.G / 255F;
float y = 1f - color.B / 255F;
float c = 1f - (color.R / 255F);
float m = 1f - (color.G / 255F);
float y = 1f - (color.B / 255F);
float k = Math.Min(c, Math.Min(m, y));

38
src/ImageSharp/Formats/Jpg/Components/IDCT.cs

@ -68,18 +68,18 @@ namespace ImageSharp.Formats
// Stage 1.
int x8 = w7 * (x4 + x5);
x4 = x8 + w1mw7 * x4;
x5 = x8 - w1pw7 * x5;
x4 = x8 + (w1mw7 * x4);
x5 = x8 - (w1pw7 * x5);
x8 = w3 * (x6 + x7);
x6 = x8 - w3mw5 * x6;
x7 = x8 - w3pw5 * x7;
x6 = x8 - (w3mw5 * x6);
x7 = x8 - (w3pw5 * x7);
// Stage 2.
x8 = x0 + x1;
x0 -= x1;
x1 = w6 * (x3 + x2);
x2 = x1 - w2pw6 * x2;
x3 = x1 + w2mw6 * x3;
x2 = x1 - (w2pw6 * x2);
x3 = x1 + (w2mw6 * x3);
x1 = x4 + x6;
x4 -= x6;
x6 = x5 + x7;
@ -90,8 +90,8 @@ namespace ImageSharp.Formats
x8 -= x3;
x3 = x0 + x2;
x0 -= x2;
x2 = (r2 * (x4 + x5) + 128) >> 8;
x4 = (r2 * (x4 - x5) + 128) >> 8;
x2 = ((r2 * (x4 + x5)) + 128) >> 8;
x4 = ((r2 * (x4 - x5)) + 128) >> 8;
// Stage 4.
src[y8 + 0] = (x7 + x1) >> 8;
@ -122,19 +122,19 @@ namespace ImageSharp.Formats
int y7 = src[24 + x];
// Stage 1.
int y8 = w7 * (y4 + y5) + 4;
y4 = (y8 + w1mw7 * y4) >> 3;
y5 = (y8 - w1pw7 * y5) >> 3;
y8 = w3 * (y6 + y7) + 4;
y6 = (y8 - w3mw5 * y6) >> 3;
y7 = (y8 - w3pw5 * y7) >> 3;
int y8 = (w7 * (y4 + y5)) + 4;
y4 = (y8 + (w1mw7 * y4)) >> 3;
y5 = (y8 - (w1pw7 * y5)) >> 3;
y8 = (w3 * (y6 + y7)) + 4;
y6 = (y8 - (w3mw5 * y6)) >> 3;
y7 = (y8 - (w3pw5 * y7)) >> 3;
// Stage 2.
y8 = y0 + y1;
y0 -= y1;
y1 = w6 * (y3 + y2) + 4;
y2 = (y1 - w2pw6 * y2) >> 3;
y3 = (y1 + w2mw6 * y3) >> 3;
y1 = (w6 * (y3 + y2)) + 4;
y2 = (y1 - (w2pw6 * y2)) >> 3;
y3 = (y1 + (w2mw6 * y3)) >> 3;
y1 = y4 + y6;
y4 -= y6;
y6 = y5 + y7;
@ -145,8 +145,8 @@ namespace ImageSharp.Formats
y8 -= y3;
y3 = y0 + y2;
y0 -= y2;
y2 = (r2 * (y4 + y5) + 128) >> 8;
y4 = (r2 * (y4 - y5) + 128) >> 8;
y2 = ((r2 * (y4 + y5)) + 128) >> 8;
y4 = ((r2 * (y4 - y5)) + 128) >> 8;
// Stage 4.
src[x] = (y7 + y1) >> 14;

2
src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs

@ -1265,7 +1265,7 @@ namespace ImageSharp.Formats
// Implicit casting FTW
Color color = new YCbCr(yy, cb, cr);
int keyline = 255 - this.blackPixels[y * this.blackStride + x];
int keyline = 255 - this.blackPixels[(y * this.blackStride) + x];
Color final = new Cmyk(color.R / 255F, color.G / 255F, color.B / 255F, keyline / 255F);
TColor packed = default(TColor);

24
src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs

@ -309,10 +309,10 @@ namespace ImageSharp.Formats
// Emit the DC delta.
int dc = Round(block[0], 8 * this.quant[(int)index][0]);
this.EmitHuffRLE((HuffIndex)(2 * (int)index + 0), 0, dc - prevDC);
this.EmitHuffRLE((HuffIndex)((2 * (int)index) + 0), 0, dc - prevDC);
// Emit the AC components.
var h = (HuffIndex)(2 * (int)index + 1);
var h = (HuffIndex)((2 * (int)index) + 1);
int runLength = 0;
for (int zig = 1; zig < Block.BlockSize; zig++)
@ -376,9 +376,9 @@ namespace ImageSharp.Formats
{
for (int x = 0; x < 4; x++)
{
int j = 16 * y + 2 * x;
int j = (16 * y) + (2 * x);
int sum = source[i][j] + source[i][j + 1] + source[i][j + 8] + source[i][j + 9];
destination[8 * y + x + dstOff] = (sum + 2) / 4;
destination[(8 * y) + x + dstOff] = (sum + 2) / 4;
}
}
}
@ -468,7 +468,7 @@ namespace ImageSharp.Formats
}
else
{
scale = 200 - quality * 2;
scale = 200 - (quality * 2);
}
// Initialize the quantization tables.
@ -477,7 +477,7 @@ namespace ImageSharp.Formats
for (int j = 0; j < Block.BlockSize; j++)
{
int x = this.unscaledQuant[i, j];
x = (x * scale + 50) / 100;
x = ((x * scale) + 50) / 100;
if (x < 1) x = 1;
if (x > 255) x = 255;
this.quant[i][j] = (byte)x;
@ -611,7 +611,7 @@ namespace ImageSharp.Formats
/// </summary>
private void WriteDQT()
{
int markerlen = 2 + NQuantIndex * (1 + Block.BlockSize);
int markerlen = 2 + (NQuantIndex * (1 + Block.BlockSize));
this.WriteMarkerHeader(JpegConstants.Markers.DQT, markerlen);
for (int i = 0; i < NQuantIndex; i++)
{
@ -643,7 +643,7 @@ namespace ImageSharp.Formats
}
// Length (high byte, low byte), 8 + components * 3.
int markerlen = 8 + 3 * componentCount;
int markerlen = 8 + (3 * componentCount);
this.WriteMarkerHeader(JpegConstants.Markers.SOF0, markerlen);
this.buffer[0] = 8; // Data Precision. 8 for now, 12 and 16 bit jpegs not supported
this.buffer[1] = (byte)(height >> 8);
@ -663,15 +663,15 @@ namespace ImageSharp.Formats
{
for (int i = 0; i < componentCount; i++)
{
this.buffer[3 * i + 6] = (byte)(i + 1);
this.buffer[(3 * i) + 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[(3 * i) + 7] = subsamples[i];
this.buffer[(3 * i) + 8] = chroma[i];
}
}
this.outputStream.Write(this.buffer, 0, 3 * (componentCount - 1) + 9);
this.outputStream.Write(this.buffer, 0, (3 * (componentCount - 1)) + 9);
}
/// <summary>

2
src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs

@ -78,7 +78,7 @@ namespace ImageSharp.Formats
}
// Just in case
flg -= (cmf * 256 + flg) % 31;
flg -= ((cmf * 256) + flg) % 31;
if (flg < 0)
{

8
src/ImageSharp/Image/PixelAccessor.cs

@ -104,8 +104,8 @@ namespace ImageSharp
/// <returns>The <see cref="TColor"/> at the specified position.</returns>
public TColor this[int x, int y]
{
get { return Unsafe.Read<TColor>(this.pixelsBase + (y * this.Width + x) * Unsafe.SizeOf<TColor>()); }
set { Unsafe.Write(this.pixelsBase + (y * this.Width + x) * Unsafe.SizeOf<TColor>(), value); }
get { return Unsafe.Read<TColor>(this.pixelsBase + (((y * this.Width) + x) * Unsafe.SizeOf<TColor>())); }
set { Unsafe.Write(this.pixelsBase + (((y * this.Width) + x) * Unsafe.SizeOf<TColor>()), value); }
}
/// <summary>
@ -120,8 +120,8 @@ namespace ImageSharp
public void CopyBlock(int sourceX, int sourceY, PixelAccessor<TColor, TPacked> target, int targetX, int targetY, int pixelCount)
{
int size = Unsafe.SizeOf<TColor>();
byte* sourcePtr = this.pixelsBase + (sourceY * this.Width + sourceX) * size;
byte* targetPtr = target.pixelsBase + (targetY * target.Width + targetX) * size;
byte* sourcePtr = this.pixelsBase + (((sourceY * this.Width) + sourceX) * size);
byte* targetPtr = target.pixelsBase + (((targetY * target.Width) + targetX) * size);
uint byteCount = (uint)(pixelCount * size);
Unsafe.CopyBlock(targetPtr, sourcePtr, byteCount);

4
src/ImageSharp/Numerics/Ellipse.cs

@ -109,8 +109,8 @@ namespace ImageSharp
int nX = normalized.X;
int nY = normalized.Y;
return (double)(nX * nX) / (this.RadiusX * this.RadiusX)
+ (double)(nY * nY) / (this.RadiusY * this.RadiusY)
return ((double)(nX * nX) / (this.RadiusX * this.RadiusX))
+ ((double)(nY * nY) / (this.RadiusY * this.RadiusY))
<= 1.0;
}

2
src/ImageSharp/Numerics/Rectangle.cs

@ -236,7 +236,7 @@ namespace ImageSharp
/// <returns><see cref="Point"/></returns>
public static Point Center(Rectangle rectangle)
{
return new Point(rectangle.Left + rectangle.Width / 2, rectangle.Top + rectangle.Height / 2);
return new Point(rectangle.Left + (rectangle.Width / 2), rectangle.Top + (rectangle.Height / 2));
}
/// <inheritdoc/>

Loading…
Cancel
Save