Browse Source

Now decodes grayscale inside the core decoder

Former-commit-id: 69bc6a527f9d013eba29649a5d6b0893cc9a1317
Former-commit-id: 0185f5dc2e1f738ce87f757c7427fdc4c6cb8335
Former-commit-id: 138fa9716bb44d037b7e5dbd014bcfbe9a8401e7
pull/1/head
James Jackson-South 10 years ago
parent
commit
e35be06e1a
  1. 2
      src/ImageProcessorCore/Formats/Bmp/BmpDecoderCore.cs
  2. 29
      src/ImageProcessorCore/Formats/Jpg/JpegConstants.cs
  3. 34
      src/ImageProcessorCore/Formats/Jpg/JpegDecoder.cs
  4. 2
      src/ImageProcessorCore/Formats/Jpg/JpegDecoderCore.cs.REMOVED.git-id
  5. 12
      tests/ImageProcessorCore.Tests/FileTestBase.cs

2
src/ImageProcessorCore/Formats/Bmp/BmpDecoderCore.cs

@ -51,7 +51,7 @@ namespace ImageProcessorCore.Formats
/// </summary>
/// <param name="image">The image, where the data should be set to.
/// Cannot be null (Nothing in Visual Basic).</param>
/// <param name="stream">The this._stream, where the image should be
/// <param name="stream">The stream, where the image should be
/// decoded from. Cannot be null (Nothing in Visual Basic).</param>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="image"/> is null.</para>

29
src/ImageProcessorCore/Formats/Jpg/JpegConstants.cs

@ -143,6 +143,24 @@ namespace ImageProcessorCore.Formats
/// </summary>
public const byte DRI = 0xdd;
/// <summary>
/// Define First Restart
/// <remarks>
/// Inserted every r macroblocks, where r is the restart interval set by a DRI marker.
/// Not used if there was no DRI marker. The low three bits of the marker code cycle in value from 0 to 7.
/// </remarks>
/// </summary>
public const byte RST0 = 0xd0;
/// <summary>
/// Define Eigth Restart
/// <remarks>
/// Inserted every r macroblocks, where r is the restart interval set by a DRI marker.
/// Not used if there was no DRI marker. The low three bits of the marker code cycle in value from 0 to 7.
/// </remarks>
/// </summary>
public const byte RST7 = 0xd7;
/// <summary>
/// Start of Scan
/// <remarks>
@ -168,6 +186,7 @@ namespace ImageProcessorCore.Formats
/// <summary>
/// Application specific marker for marking the jpeg format.
/// <see href="http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/JPEG.html"/>
/// </summary>
public const byte APP0 = 0xe0;
@ -175,6 +194,16 @@ namespace ImageProcessorCore.Formats
/// Application specific marker for marking where to store metadata.
/// </summary>
public const byte APP1 = 0xe1;
/// <summary>
/// Application specific marker used by Adobe for storing encoding information for DCT filters.
/// </summary>
public const byte APP14 = 0xee;
/// <summary>
/// Application specific marker used by GraphicConverter to store JPEG quality.
/// </summary>
public const byte APP15 = 0xef;
}
}
}

34
src/ImageProcessorCore/Formats/Jpg/JpegDecoder.cs

@ -7,7 +7,6 @@ namespace ImageProcessorCore.Formats
{
using System;
using System.IO;
using System.Threading.Tasks;
/// <summary>
/// Image decoder for generating an image out of a jpg stream.
@ -96,39 +95,6 @@ namespace ImageProcessorCore.Formats
JpegDecoderCore decoder = new JpegDecoderCore();
decoder.Decode(stream, image, false);
// TODO: When nComp is 3 we set the ImageBase pixels internally, Eventually we should
// do the same here
if (decoder.nComp == 1)
{
int pixelWidth = decoder.width;
int pixelHeight = decoder.height;
float[] pixels = new float[pixelWidth * pixelHeight * 4];
Parallel.For(
0,
pixelHeight,
y =>
{
var yoff = decoder.img1.get_row_offset(y);
for (int x = 0; x < pixelWidth; x++)
{
int offset = ((y * pixelWidth) + x) * 4;
pixels[offset + 0] = decoder.img1.pixels[yoff + x] / 255f;
pixels[offset + 1] = decoder.img1.pixels[yoff + x] / 255f;
pixels[offset + 2] = decoder.img1.pixels[yoff + x] / 255f;
pixels[offset + 3] = 1;
}
});
image.SetPixels(pixelWidth, pixelHeight, pixels);
}
else if (decoder.nComp != 3)
{
throw new NotSupportedException("JpegDecoder only supports RGB and Grayscale color spaces.");
}
}
/// <summary>

2
src/ImageProcessorCore/Formats/Jpg/JpegDecoderCore.cs.REMOVED.git-id

@ -1 +1 @@
b643c4d82973c427e30384f20fdc46b29d913782
7a5076971068e0f389da2fb1e8b25216f4049718

12
tests/ImageProcessorCore.Tests/FileTestBase.cs

@ -19,17 +19,17 @@ namespace ImageProcessorCore.Tests
/// </summary>
protected static readonly List<string> Files = new List<string>
{
//"TestImages/Formats/Jpg/Floorplan.jpeg", // Perf: Enable for local testing only
"TestImages/Formats/Jpg/Floorplan.jpeg", // Perf: Enable for local testing only
"TestImages/Formats/Jpg/Calliphora.jpg",
//"TestImages/Formats/Jpg/fb.jpg", // Perf: Enable for local testing only
//"TestImages/Formats/Jpg/progress.jpg", // Perf: Enable for local testing only
"TestImages/Formats/Jpg/fb.jpg", // Perf: Enable for local testing only
"TestImages/Formats/Jpg/progress.jpg", // Perf: Enable for local testing only
//"TestImages/Formats/Jpg/gamma_dalai_lama_gray.jpg", // Perf: Enable for local testing only
"TestImages/Formats/Bmp/Car.bmp",
//"TestImages/Formats/Bmp/Car.bmp",
// "TestImages/Formats/Bmp/neg_height.bmp", // Perf: Enable for local testing only
//"TestImages/Formats/Png/blur.png", // Perf: Enable for local testing only
//"TestImages/Formats/Png/indexed.png", // Perf: Enable for local testing only
"TestImages/Formats/Png/splash.png",
"TestImages/Formats/Gif/rings.gif",
//"TestImages/Formats/Png/splash.png",
//"TestImages/Formats/Gif/rings.gif",
//"TestImages/Formats/Gif/giphy.gif" // Perf: Enable for local testing only
};

Loading…
Cancel
Save