diff --git a/src/ImageProcessor/Formats/Png/PngDecoderCore.cs b/src/ImageProcessor/Formats/Png/PngDecoderCore.cs
index f1fd83ead..e1a75c825 100644
--- a/src/ImageProcessor/Formats/Png/PngDecoderCore.cs
+++ b/src/ImageProcessor/Formats/Png/PngDecoderCore.cs
@@ -176,6 +176,41 @@ namespace ImageProcessor.Formats
}
}
+ ///
+ /// Computes a simple linear function of the three neighboring pixels (left, above, upper left), then chooses
+ /// as predictor the neighboring pixel closest to the computed value.
+ ///
+ /// The left neighbour pixel.
+ /// The above neighbour pixel.
+ /// The upper left neighbour pixel.
+ ///
+ /// The .
+ ///
+ private static byte PaethPredicator(byte left, byte above, byte upperLeft)
+ {
+ byte predicator;
+
+ int p = left + above - upperLeft;
+ int pa = Math.Abs(p - left);
+ int pb = Math.Abs(p - above);
+ int pc = Math.Abs(p - upperLeft);
+
+ if (pa <= pb && pa <= pc)
+ {
+ predicator = left;
+ }
+ else if (pb <= pc)
+ {
+ predicator = above;
+ }
+ else
+ {
+ predicator = upperLeft;
+ }
+
+ return predicator;
+ }
+
///
/// Reads the data chunk containing physical dimension data.
///
@@ -289,7 +324,7 @@ namespace ImageProcessor.Formats
}
else if (filter == 4)
{
- currentScanline[column] = (byte)(currentScanline[column] + PathPredicator(a, b, c));
+ currentScanline[column] = (byte)(currentScanline[column] + PaethPredicator(a, b, c));
}
column++;
@@ -306,40 +341,6 @@ namespace ImageProcessor.Formats
}
}
- ///
- /// TODO: Document this
- ///
- /// The a.
- /// The b.
- /// The c.
- ///
- /// The .
- ///
- private static byte PathPredicator(byte a, byte b, byte c)
- {
- byte predicator;
-
- int p = a + b - c;
- int pa = Math.Abs(p - a);
- int pb = Math.Abs(p - b);
- int pc = Math.Abs(p - c);
-
- if (pa <= pb && pa <= pc)
- {
- predicator = a;
- }
- else if (pb <= pc)
- {
- predicator = b;
- }
- else
- {
- predicator = c;
- }
-
- return predicator;
- }
-
///
/// Reads a text chunk containing image properties from the data.
///