From bae30daeadd381dcc475a742af06c3908e235cd2 Mon Sep 17 00:00:00 2001 From: James South Date: Mon, 11 Apr 2016 21:31:04 +1000 Subject: [PATCH] No need for bounds check. Former-commit-id: 6004db66d17f9fc01328774b9a15e2876ae6e57a Former-commit-id: badb280bc5a2206643bf403856e98335f63c410b Former-commit-id: fd532c37d6ed95609736410b30e6b4037e1ec795 --- src/ImageProcessorCore/Samplers/Resize.cs | 61 +++++++++++------------ 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/src/ImageProcessorCore/Samplers/Resize.cs b/src/ImageProcessorCore/Samplers/Resize.cs index 275f72454..03aad0ec8 100644 --- a/src/ImageProcessorCore/Samplers/Resize.cs +++ b/src/ImageProcessorCore/Samplers/Resize.cs @@ -54,7 +54,6 @@ namespace ImageProcessorCore.Samplers int sourceBottom = source.Bounds.Bottom; int targetY = targetRectangle.Y; - int targetBottom = targetRectangle.Bottom; int startX = targetRectangle.X; int endX = targetRectangle.Right; bool compand = this.Compand; @@ -70,20 +69,18 @@ namespace ImageProcessorCore.Samplers endY, y => { - if (y >= targetY && y < targetBottom) - { - // Y coordinates of source points - int originY = (int)((y - targetY) * heightFactor); + // Y coordinates of source points + int originY = (int)((y - targetY) * heightFactor); - for (int x = startX; x < endX; x++) - { - // X coordinates of source points - int originX = (int)((x - startX) * widthFactor); + for (int x = startX; x < endX; x++) + { + // X coordinates of source points + int originX = (int)((x - startX) * widthFactor); - target[x, y] = source[originX, originY]; - } - this.OnRowProcessed(); + target[x, y] = source[originX, originY]; } + + this.OnRowProcessed(); }); // Break out now. @@ -127,32 +124,30 @@ namespace ImageProcessorCore.Samplers endY, y => { - if (y >= targetY && y < targetBottom) + Weight[] verticalValues = this.VerticalWeights[y].Values; + + for (int x = startX; x < endX; x++) { - Weight[] verticalValues = this.VerticalWeights[y].Values; + // Destination color components + Color destination = new Color(); - for (int x = startX; x < endX; x++) + foreach (Weight yw in verticalValues) { - // Destination color components - Color destination = new Color(); - - foreach (Weight yw in verticalValues) - { - int originY = yw.Index; - int originX = x; - Color sourceColor = compand ? Color.Expand(this.firstPass[originX, originY]) : this.firstPass[originX, originY]; - destination += sourceColor * yw.Value; - } - - if (compand) - { - destination = Color.Compress(destination); - } - - target[x, y] = destination; + int originY = yw.Index; + int originX = x; + Color sourceColor = compand ? Color.Expand(this.firstPass[originX, originY]) : this.firstPass[originX, originY]; + destination += sourceColor * yw.Value; } - this.OnRowProcessed(); + + if (compand) + { + destination = Color.Compress(destination); + } + + target[x, y] = destination; } + + this.OnRowProcessed(); }); }