From 85c33cc741256c1659c7fd07d4b1a28895b11938 Mon Sep 17 00:00:00 2001 From: dirk Date: Sun, 30 Oct 2016 09:21:26 +0100 Subject: [PATCH] Resolved SA1407. --- src/ImageSharp/Colors/Colorspaces/CieLab.cs | 6 +-- src/ImageSharp/Colors/Colorspaces/Cmyk.cs | 6 +-- src/ImageSharp/Formats/Jpg/Components/IDCT.cs | 38 +++++++++---------- src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs | 2 +- src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs | 24 ++++++------ .../Formats/Png/Zlib/ZlibDeflateStream.cs | 2 +- src/ImageSharp/Image/PixelAccessor.cs | 8 ++-- src/ImageSharp/Numerics/Ellipse.cs | 4 +- src/ImageSharp/Numerics/Rectangle.cs | 2 +- 9 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/ImageSharp/Colors/Colorspaces/CieLab.cs b/src/ImageSharp/Colors/Colorspaces/CieLab.cs index 73221bc311..b0c042a3c4 100644 --- a/src/ImageSharp/Colors/Colorspaces/CieLab.cs +++ b/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); diff --git a/src/ImageSharp/Colors/Colorspaces/Cmyk.cs b/src/ImageSharp/Colors/Colorspaces/Cmyk.cs index 2e32329f2b..15bea263cc 100644 --- a/src/ImageSharp/Colors/Colorspaces/Cmyk.cs +++ b/src/ImageSharp/Colors/Colorspaces/Cmyk.cs @@ -84,9 +84,9 @@ namespace ImageSharp /// 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)); diff --git a/src/ImageSharp/Formats/Jpg/Components/IDCT.cs b/src/ImageSharp/Formats/Jpg/Components/IDCT.cs index b722f36b8b..c6bc279d56 100644 --- a/src/ImageSharp/Formats/Jpg/Components/IDCT.cs +++ b/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; diff --git a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs index 4d9c684859..39a24db00a 100644 --- a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs +++ b/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); diff --git a/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs index b7259a1819..35afdd68f0 100644 --- a/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs +++ b/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 /// 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); } /// diff --git a/src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs b/src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs index cb23229fc4..2d7a70c8d1 100644 --- a/src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs +++ b/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) { diff --git a/src/ImageSharp/Image/PixelAccessor.cs b/src/ImageSharp/Image/PixelAccessor.cs index 5514aa4efa..d7e08d5daf 100644 --- a/src/ImageSharp/Image/PixelAccessor.cs +++ b/src/ImageSharp/Image/PixelAccessor.cs @@ -104,8 +104,8 @@ namespace ImageSharp /// The at the specified position. public TColor this[int x, int y] { - get { return Unsafe.Read(this.pixelsBase + (y * this.Width + x) * Unsafe.SizeOf()); } - set { Unsafe.Write(this.pixelsBase + (y * this.Width + x) * Unsafe.SizeOf(), value); } + get { return Unsafe.Read(this.pixelsBase + (((y * this.Width) + x) * Unsafe.SizeOf())); } + set { Unsafe.Write(this.pixelsBase + (((y * this.Width) + x) * Unsafe.SizeOf()), value); } } /// @@ -120,8 +120,8 @@ namespace ImageSharp public void CopyBlock(int sourceX, int sourceY, PixelAccessor target, int targetX, int targetY, int pixelCount) { int size = Unsafe.SizeOf(); - 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); diff --git a/src/ImageSharp/Numerics/Ellipse.cs b/src/ImageSharp/Numerics/Ellipse.cs index 1a89df1462..f464c4b264 100644 --- a/src/ImageSharp/Numerics/Ellipse.cs +++ b/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; } diff --git a/src/ImageSharp/Numerics/Rectangle.cs b/src/ImageSharp/Numerics/Rectangle.cs index 2c06d06f55..9ae1ba5075 100644 --- a/src/ImageSharp/Numerics/Rectangle.cs +++ b/src/ImageSharp/Numerics/Rectangle.cs @@ -236,7 +236,7 @@ namespace ImageSharp /// 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)); } ///