-
-
Notifications
You must be signed in to change notification settings - Fork 891
API proposal: Pixel-agnostic Image base class #897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ad13132
make Image an abstract class
antonfirsov 2afa97b
drop StyleCop
antonfirsov 916e31c
define IImageVisitor
antonfirsov 2f79561
pixel agnostic Mutate/Clone defined
antonfirsov e590d0f
pixel-agnostic ResizeProcessor
antonfirsov 83ab056
pixel-agnostic decoder API
antonfirsov 84874d6
refactor FilterProcessor stuff
antonfirsov 3f42b58
remove trailing whitespace
antonfirsov e6fad9b
more cleanup
antonfirsov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| // Copyright (c) Six Labors and contributors. | ||
| // Licensed under the Apache License, Version 2.0. | ||
|
|
||
| using System.IO; | ||
|
|
||
| using SixLabors.ImageSharp.Advanced; | ||
| using SixLabors.ImageSharp.Formats; | ||
| using SixLabors.ImageSharp.Metadata; | ||
| using SixLabors.ImageSharp.PixelFormats; | ||
|
|
||
| namespace SixLabors.ImageSharp | ||
| { | ||
| internal interface IImageVisitor | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move this. |
||
| { | ||
| void Visit<TPixel>(Image<TPixel> image) | ||
| where TPixel : struct, IPixel<TPixel>; | ||
| } | ||
|
|
||
| public abstract partial class Image : IImage, IConfigurable | ||
| { | ||
| protected readonly Configuration configuration; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| /// <inheritdoc/> | ||
| public PixelTypeInfo PixelType { get; } | ||
|
|
||
| /// <inheritdoc /> | ||
| public abstract int Width { get; } | ||
|
|
||
| /// <inheritdoc /> | ||
| public abstract int Height { get; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public ImageMetadata Metadata { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the pixel buffer. | ||
| /// </summary> | ||
| Configuration IConfigurable.Configuration => this.configuration; | ||
|
|
||
| protected Image(Configuration configuration, PixelTypeInfo pixelType, ImageMetadata metadata) | ||
| { | ||
| this.configuration = configuration ?? Configuration.Default; | ||
| this.PixelType = pixelType; | ||
| this.Metadata = metadata ?? new ImageMetadata(); | ||
| } | ||
|
|
||
| public abstract void Dispose(); | ||
|
|
||
| internal abstract void AcceptVisitor(IImageVisitor visitor); | ||
|
|
||
| /// <summary> | ||
| /// Saves the image to the given stream using the given image encoder. | ||
| /// </summary> | ||
| /// <param name="stream">The stream to save the image to.</param> | ||
| /// <param name="encoder">The encoder to save the image with.</param> | ||
| /// <exception cref="System.ArgumentNullException">Thrown if the stream or encoder is null.</exception> | ||
| public void Save(Stream stream, IImageEncoder encoder) | ||
| { | ||
| Guard.NotNull(stream, nameof(stream)); | ||
| Guard.NotNull(encoder, nameof(encoder)); | ||
|
|
||
| EncodeVisitor visitor = new EncodeVisitor(encoder, stream); | ||
| this.AcceptVisitor(visitor); | ||
| } | ||
|
|
||
| class EncodeVisitor : IImageVisitor | ||
| { | ||
| private readonly IImageEncoder encoder; | ||
|
|
||
| private readonly Stream stream; | ||
|
|
||
| public EncodeVisitor(IImageEncoder encoder, Stream stream) | ||
| { | ||
| this.encoder = encoder; | ||
| this.stream = stream; | ||
| } | ||
|
|
||
| public void Visit<TPixel>(Image<TPixel> image) | ||
| where TPixel : struct, IPixel<TPixel> | ||
| { | ||
| this.encoder.Encode(image, this.stream); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will become
Rgb24yes?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will delegate into a method of
JpegDecoderCorewhich can then decide what pixel type to use in the resultingImage<T>. For grayscale jpegs we can returnImage<Gray8>(if worth).Designing the code sharing between the specialized (generic) and the "native pixel type" (non-generic) methods is an interesting question. Probably even more challenging for
PngDecoder.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. Thinking about it shouldn’t be too bad for png either.