Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert non-generic decode to use RGba32 and add comments
  • Loading branch information
JimBobSquarePants committed Dec 13, 2019
commit 563c34bd6d3d07a16447c8a5483b52497c2d8748
7 changes: 3 additions & 4 deletions src/ImageSharp/Formats/IImageDecoder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System.IO;
Expand All @@ -17,17 +17,16 @@ public interface IImageDecoder
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="configuration">The configuration for the image.</param>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param>
/// <returns>The decoded image of a given pixel type.</returns>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream)
where TPixel : struct, IPixel<TPixel>;

/// <summary>
/// Decodes the image from the specified stream to an <see cref="Image"/>.
/// The decoder is free to choose the pixel type.
/// </summary>
/// <param name="configuration">The configuration for the image.</param>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param>
/// <returns>The decoded image of a pixel type chosen by the decoder.</returns>
/// <returns>The <see cref="Image"/> in <see cref="Rgba32"/> pixel format.</returns>
Image Decode(Configuration configuration, Stream stream);
}
}
9 changes: 1 addition & 8 deletions src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream)

/// <inheritdoc />
public Image Decode(Configuration configuration, Stream stream)
{
Guard.NotNull(stream, nameof(stream));

using (var decoder = new JpegDecoderCore(configuration, this))
{
return decoder.Decode(stream);
}
}
=> this.Decode<Rgba32>(configuration, stream);

/// <inheritdoc/>
public IImageInfo Identify(Configuration configuration, Stream stream)
Expand Down
16 changes: 0 additions & 16 deletions src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,6 @@ public static JpegFileMarker FindNextFileMarker(byte[] marker, DoubleBufferedStr
return new JpegFileMarker(marker[1], stream.Position - 2, true);
}

/// <summary>
/// Decodes the image from the specified <see cref="Stream"/> and sets the data to image.
/// </summary>
/// <param name="stream">The stream, where the image should be.</param>
/// <returns>The decoded image.</returns>
public Image Decode(Stream stream)
{
this.ParseStream(stream);
this.InitExifProfile();
this.InitIccProfile();
this.InitDerivedMetadataProperties();
return this.ColorSpace == JpegColorSpace.Grayscale
? (Image)this.PostProcessIntoImage<L8>()
: this.PostProcessIntoImage<Rgb24>();
}

/// <summary>
/// Decodes the image from the specified <see cref="Stream"/> and sets the data to image.
/// </summary>
Expand Down
30 changes: 15 additions & 15 deletions src/ImageSharp/Image.FromBytes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public static unsafe Image<TPixel> Load<TPixel>(
/// </summary>
/// <param name="data">The byte array containing image data.</param>
/// <param name="format">The detected format.</param>
/// <returns>A new <see cref="Image"/>.</returns>
/// <returns>The <see cref="Image"/> in <see cref="Rgba32"/> pixel format.</returns>
public static Image Load(byte[] data, out IImageFormat format) =>
Load(Configuration.Default, data, out format);

Expand All @@ -279,24 +279,24 @@ public static Image Load(byte[] data, out IImageFormat format) =>
/// </summary>
/// <param name="data">The byte array containing encoded image data.</param>
/// <param name="decoder">The decoder.</param>
/// <returns>A new <see cref="Image"/>.</returns>
/// <returns>The <see cref="Image"/> in <see cref="Rgba32"/> pixel format.</returns>
public static Image Load(byte[] data, IImageDecoder decoder) => Load(Configuration.Default, data, decoder);

/// <summary>
/// Load a new instance of <see cref="Image{Rgba32}"/> from the given encoded byte array.
/// Load a new instance of <see cref="Image"/> from the given encoded byte array.
/// </summary>
/// <param name="config">The config for the decoder.</param>
/// <param name="data">The byte array containing encoded image data.</param>
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
/// <returns>The <see cref="Image"/> in <see cref="Rgba32"/> pixel format.</returns>
public static Image Load(Configuration config, byte[] data) => Load(config, data, out _);

/// <summary>
/// Load a new instance of <see cref="Image{Rgba32}"/> from the given encoded byte array.
/// Load a new instance of <see cref="Image"/> from the given encoded byte array.
/// </summary>
/// <param name="config">The config for the decoder.</param>
/// <param name="data">The byte array containing image data.</param>
/// <param name="decoder">The decoder.</param>
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
/// <returns>The <see cref="Image"/> in <see cref="Rgba32"/> pixel format.</returns>
public static Image Load(Configuration config, byte[] data, IImageDecoder decoder)
{
using (var stream = new MemoryStream(data))
Expand All @@ -306,12 +306,12 @@ public static Image Load(Configuration config, byte[] data, IImageDecoder decode
}

/// <summary>
/// Load a new instance of <see cref="Image{Rgba32}"/> from the given encoded byte array.
/// Load a new instance of <see cref="Image"/> from the given encoded byte array.
/// </summary>
/// <param name="config">The config for the decoder.</param>
/// <param name="data">The byte array containing image data.</param>
/// <param name="format">The mime type of the decoded image.</param>
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
/// <returns>The <see cref="Image"/> in <see cref="Rgba32"/> pixel format.</returns>
public static Image Load(Configuration config, byte[] data, out IImageFormat format)
{
using (var stream = new MemoryStream(data))
Expand All @@ -321,18 +321,18 @@ public static Image Load(Configuration config, byte[] data, out IImageFormat for
}

/// <summary>
/// Load a new instance of <see cref="Image{Rgba32}"/> from the given encoded byte span.
/// Load a new instance of <see cref="Image"/> from the given encoded byte span.
/// </summary>
/// <param name="data">The byte span containing image data.</param>
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
/// <returns>The <see cref="Image"/> in <see cref="Rgba32"/> pixel format.</returns>
public static Image Load(ReadOnlySpan<byte> data) => Load(Configuration.Default, data);

/// <summary>
/// Load a new instance of <see cref="Image"/> from the given encoded byte span.
/// </summary>
/// <param name="data">The byte span containing image data.</param>
/// <param name="decoder">The decoder.</param>
/// <returns>A new <see cref="Image"/>.</returns>
/// <returns>The <see cref="Image"/> in <see cref="Rgba32"/> pixel format.</returns>
public static Image Load(ReadOnlySpan<byte> data, IImageDecoder decoder) =>
Load(Configuration.Default, data, decoder);

Expand All @@ -341,7 +341,7 @@ public static Image Load(ReadOnlySpan<byte> data, IImageDecoder decoder) =>
/// </summary>
/// <param name="data">The byte span containing image data.</param>
/// <param name="format">The detected format.</param>
/// <returns>A new <see cref="Image"/>.</returns>
/// <returns>The <see cref="Image"/> in <see cref="Rgba32"/> pixel format.</returns>
public static Image Load(ReadOnlySpan<byte> data, out IImageFormat format) =>
Load(Configuration.Default, data, out format);

Expand All @@ -350,7 +350,7 @@ public static Image Load(ReadOnlySpan<byte> data, out IImageFormat format) =>
/// </summary>
/// <param name="config">The configuration options.</param>
/// <param name="data">The byte span containing image data.</param>
/// <returns>A new <see cref="Image"/>.</returns>
/// <returns>The <see cref="Image"/> in <see cref="Rgba32"/> pixel format.</returns>
public static Image Load(Configuration config, ReadOnlySpan<byte> data) => Load(config, data, out _);

/// <summary>
Expand All @@ -359,7 +359,7 @@ public static Image Load(ReadOnlySpan<byte> data, out IImageFormat format) =>
/// <param name="config">The Configuration.</param>
/// <param name="data">The byte span containing image data.</param>
/// <param name="decoder">The decoder.</param>
/// <returns>A new <see cref="Image"/>.</returns>
/// <returns>The <see cref="Image"/> in <see cref="Rgba32"/> pixel format.</returns>
public static unsafe Image Load(
Configuration config,
ReadOnlySpan<byte> data,
Expand All @@ -380,7 +380,7 @@ public static unsafe Image Load(
/// <param name="config">The configuration options.</param>
/// <param name="data">The byte span containing image data.</param>
/// <param name="format">The <see cref="IImageFormat"/> of the decoded image.</param>>
/// <returns>A new <see cref="Image"/>.</returns>
/// <returns>The <see cref="Image"/> in <see cref="Rgba32"/> pixel format.</returns>
public static unsafe Image Load(
Configuration config,
ReadOnlySpan<byte> data,
Expand Down
22 changes: 11 additions & 11 deletions src/ImageSharp/Image.FromFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System;
Expand Down Expand Up @@ -39,17 +39,17 @@ public static IImageFormat DetectFormat(Configuration config, string filePath)
}

/// <summary>
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given file.
/// Create a new instance of the <see cref="Image"/> class from the given file.
/// </summary>
/// <param name="path">The file path to the image.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
/// <returns>The <see cref="Image"/> in <see cref="Rgba32"/> pixel format.</returns>
public static Image Load(string path) => Load(Configuration.Default, path);

/// <summary>
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given file.
/// Create a new instance of the <see cref="Image"/> class from the given file.
/// </summary>
/// <param name="path">The file path to the image.</param>
/// <param name="format">The mime type of the decoded image.</param>
Expand All @@ -60,26 +60,26 @@ public static IImageFormat DetectFormat(Configuration config, string filePath)
public static Image Load(string path, out IImageFormat format) => Load(Configuration.Default, path, out format);

/// <summary>
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given file.
/// Create a new instance of the <see cref="Image"/> class from the given file.
/// </summary>
/// <param name="config">The config for the decoder.</param>
/// <param name="path">The file path to the image.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
/// <returns>The <see cref="Image"/> in <see cref="Rgba32"/> pixel format.</returns>
public static Image Load(Configuration config, string path) => Load(config, path, out _);

/// <summary>
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given file.
/// Create a new instance of the <see cref="Image"/> class from the given file.
/// </summary>
/// <param name="config">The Configuration.</param>
/// <param name="path">The file path to the image.</param>
/// <param name="decoder">The decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
/// <returns>The <see cref="Image"/> in <see cref="Rgba32"/> pixel format.</returns>
public static Image Load(Configuration config, string path, IImageDecoder decoder)
{
using (Stream stream = config.FileSystem.OpenRead(path))
Expand All @@ -89,14 +89,14 @@ public static Image Load(Configuration config, string path, IImageDecoder decode
}

/// <summary>
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given file.
/// Create a new instance of the <see cref="Image"/> class from the given file.
/// </summary>
/// <param name="path">The file path to the image.</param>
/// <param name="decoder">The decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
/// <returns>The <see cref="Image"/> in <see cref="Rgba32"/> pixel format.</returns>
public static Image Load(string path, IImageDecoder decoder) => Load(Configuration.Default, path, decoder);

/// <summary>
Expand Down Expand Up @@ -224,4 +224,4 @@ public static Image<TPixel> Load<TPixel>(Configuration config, string path, IIma
}
}
}
}
}
6 changes: 3 additions & 3 deletions src/ImageSharp/Image.FromStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static IImageInfo Identify(Configuration config, Stream stream, out IImag
/// <param name="format">The format type of the decoded image.</param>
/// <exception cref="NotSupportedException">Thrown if the stream is not readable.</exception>
/// <exception cref="UnknownImageFormatException">Image cannot be loaded.</exception>
/// <returns>A new <see cref="Image"/>.</returns>>
/// <returns>The <see cref="Image"/> in <see cref="Rgba32"/> pixel format.</returns>
public static Image Load(Stream stream, out IImageFormat format) => Load(Configuration.Default, stream, out format);

/// <summary>
Expand All @@ -90,7 +90,7 @@ public static IImageInfo Identify(Configuration config, Stream stream, out IImag
/// <param name="stream">The stream containing image information.</param>
/// <exception cref="NotSupportedException">Thrown if the stream is not readable.</exception>
/// <exception cref="UnknownImageFormatException">Image cannot be loaded.</exception>
/// <returns>A new <see cref="Image"/>.</returns>>
/// <returns>The <see cref="Image"/> in <see cref="Rgba32"/> pixel format.</returns>
public static Image Load(Stream stream) => Load(Configuration.Default, stream);

/// <summary>
Expand All @@ -101,7 +101,7 @@ public static IImageInfo Identify(Configuration config, Stream stream, out IImag
/// <param name="decoder">The decoder.</param>
/// <exception cref="NotSupportedException">Thrown if the stream is not readable.</exception>
/// <exception cref="UnknownImageFormatException">Image cannot be loaded.</exception>
/// <returns>A new <see cref="Image"/>.</returns>>
/// <returns>The <see cref="Image"/> in <see cref="Rgba32"/> pixel format.</returns>
public static Image Load(Stream stream, IImageDecoder decoder) => Load(Configuration.Default, stream, decoder);

/// <summary>
Expand Down