Repository navigation
Refactored the decoder and encoder options. - #113
Conversation
Codecov Report
@@ Coverage Diff @@
## master #113 +/- ##
=========================================
+ Coverage 88.12% 88.2% +0.07%
=========================================
Files 429 441 +12
Lines 20042 20364 +322
Branches 1431 1448 +17
=========================================
+ Hits 17663 17963 +300
- Misses 1972 1995 +23
+ Partials 407 406 -1
Continue to review full report at Codecov.
|
JimBobSquarePants
left a comment
There was a problem hiding this comment.
This is a great addition, really cleaning the the mess that was the codec options!
Just a few questions and a minor XML comment change.
| /// <returns>The options for the <see cref="BmpEncoder"/>.</returns> | ||
| internal static IBmpEncoderOptions Create(IEncoderOptions options) | ||
| { | ||
| IBmpEncoderOptions bmpOptions = options as IBmpEncoderOptions; |
There was a problem hiding this comment.
Couldn't this be
return options as IBmpEncoderOptions ?? new BmpEncoderOptions(options);
There was a problem hiding this comment.
Yeah I could and should have done that.
| /// <summary> | ||
| /// Gets the default encoding to use when reading comments. | ||
| /// </summary> | ||
| public static Encoding DefaultEncoding { get; } = Encoding.GetEncoding("ASCII"); |
There was a problem hiding this comment.
Amazed that the specs don't restrict this. Good catch.
| /// </summary> | ||
| /// <param name="options">The decoder options.</param> | ||
| public GifDecoderCore(IGifDecoderOptions options) | ||
| { |
There was a problem hiding this comment.
When is it possible to call new GifDecoderCore(null) ?
There was a problem hiding this comment.
This will happen when you call the constructor of Image without options (options=null). The GifDecoder will just forward the value.
| /// </summary> | ||
| /// <typeparam name="TColor">The pixel format.</typeparam> | ||
| /// <param name="image">The <see cref="ImageBase{TColor}"/> to be encoded.</param> | ||
| /// <param name="writer">The stream to write to.</param> |
| /// <summary> | ||
| /// Gets or sets the transparency threshold. | ||
| /// </summary> | ||
| public byte Threshold { get; set; } = 128; |
There was a problem hiding this comment.
Thinking about that we should probably reduce the value now we have dithering. Our output should be much cleaner. Do you know of any other encoders that offer this option? We should follow the most common default.
There was a problem hiding this comment.
I can take a look at what we do inside ImageMagick but I think we always use dithering.
| => source.Save(stream, new GifEncoder { Quality = quality }); | ||
| { | ||
| GifEncoder encoder = new GifEncoder(); | ||
| encoder.Encode(source, stream, options); |
There was a problem hiding this comment.
Well that answers my question earlier 😄
| /// <value>The quality of the jpg image from 0 to 100.</value> | ||
| public int Quality | ||
| /// <inheritdoc/> | ||
| public void Encode<TColor>(Image<TColor> image, Stream stream, IEncoderOptions options) |
| } | ||
| quality = quality.Clamp(1, 100); | ||
|
|
||
| this.outputStream = stream; |
There was a problem hiding this comment.
I think we have that marked as 80 and below for 420 in the quality XML comments, 91 is the correct value for switching so we should say 90.
There was a problem hiding this comment.
I updated the comments.
| /// index must be between 0 and 100 (compression from max to min). | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// If the quality is less than or equal to 80, the subsampling ratio will switch to <see cref="JpegSubsample.Ratio420"/> |
There was a problem hiding this comment.
Yup, should be 90 here.
There was a problem hiding this comment.
Fixed and removed the remarks from the interface.
| } | ||
|
|
||
| if (this.Quantizer == null) | ||
| if (this.quantizer == null) |
There was a problem hiding this comment.
Is this something we should be handling in the options?
There was a problem hiding this comment.
Yeah IPngEncoderOptions.Quantizer is not used in PngEncoderCore!
There was a problem hiding this comment.
It looks like a mistake that I forgot to use the quantizer from the options. Thanks @antonfirsov! I could not set it inside the options due to the {TColor} restriction.
|
Well done, seems OK to me! |
|
My only concern is the usage of optional arguments. We shouldn't be using them on out public API's it makes them a lot harder to version in the future. See this blog post for details http://haacked.com/archive/2010/08/10/versioning-issues-with-optional-arguments.aspx/ I understand there are more instances of this thru-out the codebase so its probably not worth bothering to fix it in this PR and we should instead creating a separate issue/PR fixing them all. Apart from the optional arguments this looks good to me. |
|
I also prefer to use overloads instead of optional arguments. The current code base already uses a lot of optional arguments so that is why I used that. I can change it inside this pull request to use overloads instead of optional arguments. Your thought @JimBobSquarePants? |
|
Just pushed the last change. I think we are ready to merge. |
9db6823 to
a739109
Compare
tocsoft
left a comment
There was a problem hiding this comment.
much better with the overloads instead of the optional args. 👍
a739109 to
ffe7f96
Compare
|
We should probably create a new issue/pull request to remove all the optional arguments. |
|
I've added an issue to track the required work. |
|
Great. @dlemstra do you want to do the honours? |
Prerequisites
Description
This pull requests adds the features requested in #26:
This was already changed in my previous pull request (#99):
This pull request also adds support for skipping reading/writing metadata as requested in #11.
Fixes #26
Fixes #11