Browse Source

Paeth not path.

Former-commit-id: 5c2c29290830adcf780e277b98c8bc630916809a
Former-commit-id: 74f68b461a5f7e63f8aec37d842111cdeb2e1999
Former-commit-id: 49c02df29574979d58e64c4145bbfd1e027c18c3
pull/17/head
James Jackson-South 11 years ago
parent
commit
d3377d5c6b
  1. 71
      src/ImageProcessor/Formats/Png/PngDecoderCore.cs

71
src/ImageProcessor/Formats/Png/PngDecoderCore.cs

@ -176,6 +176,41 @@ namespace ImageProcessor.Formats
}
}
/// <summary>
/// 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.
/// </summary>
/// <param name="left">The left neighbour pixel.</param>
/// <param name="above">The above neighbour pixel.</param>
/// <param name="upperLeft">The upper left neighbour pixel.</param>
/// <returns>
/// The <see cref="byte"/>.
/// </returns>
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;
}
/// <summary>
/// Reads the data chunk containing physical dimension data.
/// </summary>
@ -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
}
}
/// <summary>
/// TODO: Document this
/// </summary>
/// <param name="a">The a.</param>
/// <param name="b">The b.</param>
/// <param name="c">The c.</param>
/// <returns>
/// The <see cref="byte"/>.
/// </returns>
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;
}
/// <summary>
/// Reads a text chunk containing image properties from the data.
/// </summary>

Loading…
Cancel
Save